[20909] | 1 | /* |
---|
| 2 | * This program is free software; you can redistribute it and/or modify |
---|
| 3 | * it under the terms of the GNU General Public License as published by |
---|
| 4 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 5 | * (at your option) any later version. |
---|
| 6 | * |
---|
| 7 | * This program is distributed in the hope that it will be useful, |
---|
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 10 | * GNU Library General Public License for more details. |
---|
| 11 | * |
---|
| 12 | * You should have received a copy of the GNU General Public License |
---|
| 13 | * along with this program; if not, write to the Free Software |
---|
| 14 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #include <config.h> |
---|
| 18 | |
---|
| 19 | #include <string.h> |
---|
| 20 | #include <sys/stat.h> |
---|
| 21 | |
---|
| 22 | #include <gdk/gdkx.h> |
---|
| 23 | #include <gnome.h> |
---|
| 24 | #include <glade/glade.h> |
---|
| 25 | #include <libbonobo.h> |
---|
| 26 | |
---|
| 27 | #include <libxklavier/xklavier.h> |
---|
| 28 | #include <libxklavier/xklavier_config.h> |
---|
| 29 | |
---|
| 30 | #include "gswitchit-plugins.h" |
---|
| 31 | |
---|
| 32 | extern void |
---|
| 33 | CappletFillActivePluginList (GSwitchItPluginsCapplet * gswic) |
---|
| 34 | { |
---|
| 35 | GtkWidget *activePlugins = |
---|
| 36 | CappletGetGladeWidget (gswic, "activePlugins"); |
---|
| 37 | GtkListStore *activePluginsModel = |
---|
| 38 | GTK_LIST_STORE (gtk_tree_view_get_model |
---|
| 39 | (GTK_TREE_VIEW (activePlugins))); |
---|
| 40 | GSList *pluginPathNode = gswic->appletConfig.enabledPlugins; |
---|
| 41 | GHashTable *allPluginRecs = gswic->pluginManager.allPluginRecs; |
---|
| 42 | |
---|
| 43 | gtk_list_store_clear (activePluginsModel); |
---|
| 44 | if (allPluginRecs == NULL) |
---|
| 45 | return; |
---|
| 46 | |
---|
| 47 | while (pluginPathNode != NULL) { |
---|
| 48 | GtkTreeIter iter; |
---|
| 49 | const char *fullPath = (const char *) pluginPathNode->data; |
---|
| 50 | const GSwitchItPlugin *plugin = |
---|
| 51 | GSwitchItPluginManagerGetPlugin (&gswic->pluginManager, |
---|
| 52 | fullPath); |
---|
| 53 | if (plugin != NULL) { |
---|
| 54 | gtk_list_store_append (activePluginsModel, &iter); |
---|
| 55 | gtk_list_store_set (activePluginsModel, &iter, |
---|
| 56 | NAME_COLUMN, plugin->name, |
---|
| 57 | FULLPATH_COLUMN, fullPath, -1); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | pluginPathNode = g_slist_next (pluginPathNode); |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | static char * |
---|
| 65 | CappletGetSelectedActivePluginPath (GSwitchItPluginsCapplet * gswic) |
---|
| 66 | { |
---|
| 67 | GtkTreeView *pluginsList = |
---|
| 68 | GTK_TREE_VIEW (CappletGetGladeWidget (gswic, "activePlugins")); |
---|
| 69 | return CappletGetSelectedPluginPath (pluginsList, gswic); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | char * |
---|
| 73 | CappletGetSelectedPluginPath (GtkTreeView * pluginsList, |
---|
| 74 | GSwitchItPluginsCapplet * gswic) |
---|
| 75 | { |
---|
| 76 | GtkTreeModel *model = |
---|
| 77 | gtk_tree_view_get_model (GTK_TREE_VIEW (pluginsList)); |
---|
| 78 | GtkTreeSelection *selection = |
---|
| 79 | gtk_tree_view_get_selection (GTK_TREE_VIEW (pluginsList)); |
---|
| 80 | GtkTreeIter selectedIter; |
---|
| 81 | |
---|
| 82 | if (gtk_tree_selection_get_selected |
---|
| 83 | (selection, NULL, &selectedIter)) { |
---|
| 84 | char *fullPath = NULL; |
---|
| 85 | |
---|
| 86 | gtk_tree_model_get (model, &selectedIter, |
---|
| 87 | FULLPATH_COLUMN, &fullPath, -1); |
---|
| 88 | return fullPath; |
---|
| 89 | } |
---|
| 90 | return NULL; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | static void |
---|
| 94 | CappletActivePluginsSelectionChanged (GtkTreeSelection * |
---|
| 95 | selection, |
---|
| 96 | GSwitchItPluginsCapplet * gswic) |
---|
| 97 | { |
---|
| 98 | GtkWidget *activePlugins = |
---|
| 99 | CappletGetGladeWidget (gswic, "activePlugins"); |
---|
| 100 | GtkTreeModel *model = |
---|
| 101 | gtk_tree_view_get_model (GTK_TREE_VIEW (activePlugins)); |
---|
| 102 | GtkTreeIter selectedIter; |
---|
| 103 | gboolean isAnythingSelected = FALSE; |
---|
| 104 | gboolean isFirstSelected = FALSE; |
---|
| 105 | gboolean isLastSelected = FALSE; |
---|
| 106 | gboolean hasConfigurationUi = FALSE; |
---|
| 107 | GtkWidget *btnRemove = CappletGetGladeWidget (gswic, "btnRemove"); |
---|
| 108 | GtkWidget *btnUp = CappletGetGladeWidget (gswic, "btnUp"); |
---|
| 109 | GtkWidget *btnDown = CappletGetGladeWidget (gswic, "btnDown"); |
---|
| 110 | GtkWidget *btnProperties = |
---|
| 111 | CappletGetGladeWidget (gswic, "btnProperties"); |
---|
| 112 | GtkWidget *lblDescription = |
---|
| 113 | CappletGetGladeWidget (gswic, "lblDescription"); |
---|
| 114 | |
---|
| 115 | gtk_label_set_text (GTK_LABEL (lblDescription), |
---|
| 116 | g_strconcat ("<small><i>", |
---|
| 117 | _("No description."), |
---|
| 118 | "</i></small>", NULL)); |
---|
| 119 | gtk_label_set_use_markup (GTK_LABEL (lblDescription), TRUE); |
---|
| 120 | |
---|
| 121 | if (gtk_tree_selection_get_selected |
---|
| 122 | (selection, NULL, &selectedIter)) { |
---|
| 123 | int counter = gtk_tree_model_iter_n_children (model, NULL); |
---|
| 124 | GtkTreePath *treePath = |
---|
| 125 | gtk_tree_model_get_path (model, &selectedIter); |
---|
| 126 | gint *indices = gtk_tree_path_get_indices (treePath); |
---|
| 127 | char *fullPath = |
---|
| 128 | CappletGetSelectedActivePluginPath (gswic); |
---|
| 129 | const GSwitchItPlugin *plugin = |
---|
| 130 | GSwitchItPluginManagerGetPlugin (&gswic->pluginManager, |
---|
| 131 | fullPath); |
---|
| 132 | |
---|
| 133 | isAnythingSelected = TRUE; |
---|
| 134 | |
---|
| 135 | isFirstSelected = indices[0] == 0; |
---|
| 136 | isLastSelected = indices[0] == counter - 1; |
---|
| 137 | |
---|
| 138 | if (plugin != NULL) { |
---|
| 139 | hasConfigurationUi = |
---|
| 140 | (plugin->configurePropertiesCallback != NULL); |
---|
| 141 | gtk_label_set_text (GTK_LABEL (lblDescription), |
---|
| 142 | g_strconcat ("<small><i>", |
---|
| 143 | plugin-> |
---|
| 144 | description, |
---|
| 145 | "</i></small>", |
---|
| 146 | NULL)); |
---|
| 147 | gtk_label_set_use_markup (GTK_LABEL |
---|
| 148 | (lblDescription), TRUE); |
---|
| 149 | } |
---|
| 150 | g_free (fullPath); |
---|
| 151 | |
---|
| 152 | gtk_tree_path_free (treePath); |
---|
| 153 | } |
---|
| 154 | gtk_widget_set_sensitive (btnRemove, isAnythingSelected); |
---|
| 155 | gtk_widget_set_sensitive (btnUp, isAnythingSelected |
---|
| 156 | && !isFirstSelected); |
---|
| 157 | gtk_widget_set_sensitive (btnDown, isAnythingSelected |
---|
| 158 | && !isLastSelected); |
---|
| 159 | gtk_widget_set_sensitive (btnProperties, isAnythingSelected |
---|
| 160 | && hasConfigurationUi); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | static void |
---|
| 164 | CappletPromotePlugin (GtkWidget * btnUp, GSwitchItPluginsCapplet * gswic) |
---|
| 165 | { |
---|
| 166 | char *fullPath = CappletGetSelectedActivePluginPath (gswic); |
---|
| 167 | if (fullPath != NULL) { |
---|
| 168 | GSwitchItPluginManagerPromotePlugin (&gswic->pluginManager, |
---|
| 169 | gswic->appletConfig. |
---|
| 170 | enabledPlugins, |
---|
| 171 | fullPath); |
---|
| 172 | g_free (fullPath); |
---|
| 173 | CappletFillActivePluginList (gswic); |
---|
| 174 | GSwitchItAppletConfigSave (&gswic->appletConfig, |
---|
| 175 | &gswic->xkbConfig); |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | static void |
---|
| 180 | CappletDemotePlugin (GtkWidget * btnUp, GSwitchItPluginsCapplet * gswic) |
---|
| 181 | { |
---|
| 182 | char *fullPath = CappletGetSelectedActivePluginPath (gswic); |
---|
| 183 | if (fullPath != NULL) { |
---|
| 184 | GSwitchItPluginManagerDemotePlugin (&gswic->pluginManager, |
---|
| 185 | gswic->appletConfig. |
---|
| 186 | enabledPlugins, |
---|
| 187 | fullPath); |
---|
| 188 | g_free (fullPath); |
---|
| 189 | CappletFillActivePluginList (gswic); |
---|
| 190 | GSwitchItAppletConfigSave (&gswic->appletConfig, |
---|
| 191 | &gswic->xkbConfig); |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | static void |
---|
| 196 | CappletDisablePlugin (GtkWidget * btnRemove, |
---|
| 197 | GSwitchItPluginsCapplet * gswic) |
---|
| 198 | { |
---|
| 199 | char *fullPath = CappletGetSelectedActivePluginPath (gswic); |
---|
| 200 | if (fullPath != NULL) { |
---|
| 201 | GSwitchItPluginManagerDisablePlugin (&gswic->pluginManager, |
---|
| 202 | &gswic->appletConfig. |
---|
| 203 | enabledPlugins, |
---|
| 204 | fullPath); |
---|
| 205 | g_free (fullPath); |
---|
| 206 | CappletFillActivePluginList (gswic); |
---|
| 207 | GSwitchItAppletConfigSave (&gswic->appletConfig, |
---|
| 208 | &gswic->xkbConfig); |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | static void |
---|
| 213 | CappletConfigurePlugin (GtkWidget * btnRemove, |
---|
| 214 | GSwitchItPluginsCapplet * gswic) |
---|
| 215 | { |
---|
| 216 | char *fullPath = CappletGetSelectedActivePluginPath (gswic); |
---|
| 217 | if (fullPath != NULL) { |
---|
| 218 | GSwitchItPluginManagerConfigurePlugin (&gswic-> |
---|
| 219 | pluginManager, |
---|
| 220 | &gswic-> |
---|
| 221 | pluginContainer, |
---|
| 222 | fullPath, |
---|
| 223 | GTK_WINDOW (gswic-> |
---|
| 224 | capplet)); |
---|
| 225 | g_free (fullPath); |
---|
| 226 | } |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | static void |
---|
| 230 | CappletResponse (GtkDialog * dialog, gint response) |
---|
| 231 | { |
---|
| 232 | if (response == GTK_RESPONSE_HELP) { |
---|
| 233 | GSwitchItHelp (GTK_WIDGET (dialog), |
---|
[21372] | 234 | "gswitchit-applet-plugins"); |
---|
[20909] | 235 | return; |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | bonobo_main_quit (); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | static void |
---|
| 242 | CappletSetup (GSwitchItPluginsCapplet * gswic) |
---|
| 243 | { |
---|
| 244 | GladeXML *data; |
---|
| 245 | GtkWidget *capplet; |
---|
| 246 | GtkWidget *activePlugins; |
---|
| 247 | GtkTreeModel *activePluginsModel; |
---|
| 248 | GtkCellRenderer *renderer = |
---|
| 249 | GTK_CELL_RENDERER (gtk_cell_renderer_text_new ()); |
---|
| 250 | GtkTreeViewColumn *column = |
---|
| 251 | gtk_tree_view_column_new_with_attributes (NULL, renderer, |
---|
| 252 | "text", 0, |
---|
| 253 | NULL); |
---|
| 254 | GtkTreeSelection *selection; |
---|
| 255 | const char *iconFile; |
---|
| 256 | glade_gnome_init (); |
---|
| 257 | data = glade_xml_new (GLADE_DIR "/gswitchit-plugins.glade", "gswitchit_plugins", NULL); // default domain! |
---|
| 258 | gswic->capplet = capplet = |
---|
| 259 | glade_xml_get_widget (data, "gswitchit_plugins"); |
---|
| 260 | iconFile = gnome_program_locate_file (NULL, |
---|
| 261 | GNOME_FILE_DOMAIN_PIXMAP, |
---|
| 262 | "gswitchit-properties-capplet.png", |
---|
| 263 | TRUE, NULL); |
---|
| 264 | if (iconFile != NULL) |
---|
| 265 | gtk_window_set_icon_from_file (GTK_WINDOW (capplet), |
---|
| 266 | iconFile, NULL); |
---|
| 267 | gtk_object_set_data (GTK_OBJECT (capplet), "gladeData", data); |
---|
| 268 | g_signal_connect_swapped (GTK_OBJECT (capplet), |
---|
| 269 | "destroy", G_CALLBACK (g_object_unref), |
---|
| 270 | data); |
---|
| 271 | g_signal_connect (G_OBJECT (capplet), "unrealize", |
---|
| 272 | G_CALLBACK (bonobo_main_quit), data); |
---|
| 273 | |
---|
| 274 | g_signal_connect (GTK_OBJECT (capplet), |
---|
| 275 | "response", G_CALLBACK (CappletResponse), NULL); |
---|
| 276 | |
---|
| 277 | glade_xml_signal_connect_data (data, "on_btnUp_clicked", |
---|
| 278 | GTK_SIGNAL_FUNC |
---|
| 279 | (CappletPromotePlugin), gswic); |
---|
| 280 | glade_xml_signal_connect_data (data, |
---|
| 281 | "on_btnDown_clicked", |
---|
| 282 | GTK_SIGNAL_FUNC |
---|
| 283 | (CappletDemotePlugin), gswic); |
---|
| 284 | glade_xml_signal_connect_data (data, |
---|
| 285 | "on_btnAdd_clicked", |
---|
| 286 | GTK_SIGNAL_FUNC |
---|
| 287 | (CappletEnablePlugin), gswic); |
---|
| 288 | glade_xml_signal_connect_data (data, |
---|
| 289 | "on_btnRemove_clicked", |
---|
| 290 | GTK_SIGNAL_FUNC |
---|
| 291 | (CappletDisablePlugin), gswic); |
---|
| 292 | glade_xml_signal_connect_data (data, |
---|
| 293 | "on_btnProperties_clicked", |
---|
| 294 | GTK_SIGNAL_FUNC |
---|
| 295 | (CappletConfigurePlugin), gswic); |
---|
| 296 | |
---|
| 297 | activePlugins = CappletGetGladeWidget (gswic, "activePlugins"); |
---|
| 298 | activePluginsModel = |
---|
| 299 | GTK_TREE_MODEL (gtk_list_store_new |
---|
| 300 | (2, G_TYPE_STRING, G_TYPE_STRING)); |
---|
| 301 | gtk_tree_view_set_model (GTK_TREE_VIEW (activePlugins), |
---|
| 302 | activePluginsModel); |
---|
| 303 | gtk_tree_view_append_column (GTK_TREE_VIEW (activePlugins), |
---|
| 304 | column); |
---|
| 305 | selection = |
---|
| 306 | gtk_tree_view_get_selection (GTK_TREE_VIEW (activePlugins)); |
---|
| 307 | gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); |
---|
| 308 | g_signal_connect (G_OBJECT (selection), "changed", |
---|
| 309 | G_CALLBACK |
---|
| 310 | (CappletActivePluginsSelectionChanged), gswic); |
---|
| 311 | CappletFillActivePluginList (gswic); |
---|
| 312 | CappletActivePluginsSelectionChanged (selection, gswic); |
---|
| 313 | gtk_widget_show_all (capplet); |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | int |
---|
| 317 | main (int argc, char **argv) |
---|
| 318 | { |
---|
| 319 | GSwitchItPluginsCapplet gswic; |
---|
| 320 | GError *gconf_error = NULL; |
---|
| 321 | GConfClient *confClient; |
---|
| 322 | |
---|
[21372] | 323 | bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); |
---|
[20909] | 324 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
---|
[21372] | 325 | textdomain (GETTEXT_PACKAGE); |
---|
[20909] | 326 | memset (&gswic, 0, sizeof (gswic)); |
---|
[21372] | 327 | gnome_program_init ("gswitchit", VERSION, |
---|
[20909] | 328 | LIBGNOMEUI_MODULE, argc, argv, |
---|
| 329 | GNOME_PROGRAM_STANDARD_PROPERTIES, NULL); |
---|
| 330 | if (!gconf_init (argc, argv, &gconf_error)) { |
---|
| 331 | g_warning (_("Failed to init GConf: %s\n"), |
---|
| 332 | gconf_error->message); |
---|
| 333 | g_error_free (gconf_error); |
---|
| 334 | return 1; |
---|
| 335 | } |
---|
| 336 | gconf_error = NULL; |
---|
| 337 | //GSwitchItInstallGlibLogAppender( ); |
---|
| 338 | XklInit (GDK_DISPLAY ()); |
---|
| 339 | XklConfigInit (); |
---|
| 340 | XklConfigLoadRegistry (); |
---|
| 341 | |
---|
| 342 | confClient = gconf_client_get_default (); |
---|
| 343 | GSwitchItPluginContainerInit (&gswic.pluginContainer, confClient); |
---|
| 344 | g_object_unref (confClient); |
---|
| 345 | |
---|
| 346 | GSwitchItXkbConfigInit (&gswic.xkbConfig, confClient); |
---|
| 347 | GSwitchItAppletConfigInit (&gswic.appletConfig, confClient); |
---|
| 348 | GSwitchItPluginManagerInit (&gswic.pluginManager); |
---|
| 349 | GSwitchItXkbConfigLoad (&gswic.xkbConfig); |
---|
| 350 | GSwitchItAppletConfigLoad (&gswic.appletConfig); |
---|
| 351 | if (gswic.appletConfig.debugLevel != -1) |
---|
| 352 | XklSetDebugLevel (gswic.appletConfig.debugLevel); |
---|
| 353 | CappletSetup (&gswic); |
---|
| 354 | bonobo_main (); |
---|
| 355 | GSwitchItPluginManagerTerm (&gswic.pluginManager); |
---|
| 356 | GSwitchItAppletConfigTerm (&gswic.appletConfig); |
---|
| 357 | GSwitchItXkbConfigTerm (&gswic.xkbConfig); |
---|
| 358 | GSwitchItPluginContainerTerm (&gswic.pluginContainer); |
---|
| 359 | XklConfigFreeRegistry (); |
---|
| 360 | XklConfigTerm (); |
---|
| 361 | XklTerm (); |
---|
| 362 | return 0; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | // functions just for plugins - otherwise ldd is not happy |
---|
| 366 | void |
---|
| 367 | GSwitchItPluginContainerReinitUi (GSwitchItPluginContainer * pc) |
---|
| 368 | { |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | void |
---|
| 372 | GSwitchItPluginLoadLocalizedGroupNames (GSwitchItPluginContainer |
---|
| 373 | * pc, |
---|
| 374 | const GroupDescriptionsBuffer |
---|
| 375 | ** outDescr) |
---|
| 376 | { |
---|
| 377 | static GroupDescriptionsBuffer namesToFill; |
---|
| 378 | GSwitchItAppletConfigLoadGroupDescriptionsUtf8 (& |
---|
| 379 | (((GSwitchItPluginsCapplet *) pc)->appletConfig), namesToFill); |
---|
| 380 | *outDescr = (const GroupDescriptionsBuffer *) (&namesToFill); |
---|
| 381 | } |
---|