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 | static void |
---|
33 | CappletAddAvailablePluginFunc (const char *fullPath, |
---|
34 | GSwitchItPluginManagerRecord * rec, |
---|
35 | GSwitchItPluginsCapplet * gswic) |
---|
36 | { |
---|
37 | GtkListStore *availablePluginsModel; |
---|
38 | GtkTreeIter iter; |
---|
39 | const GSwitchItPlugin *plugin = rec->plugin; |
---|
40 | |
---|
41 | if (NULL != |
---|
42 | g_slist_find_custom (gswic->appletConfig.enabledPlugins, |
---|
43 | fullPath, (GCompareFunc) strcmp)) |
---|
44 | return; |
---|
45 | |
---|
46 | availablePluginsModel = |
---|
47 | GTK_LIST_STORE (g_object_get_data (G_OBJECT (gswic->capplet), |
---|
48 | "gswitchit_plugins_add.availablePluginsModel")); |
---|
49 | if (availablePluginsModel == NULL) |
---|
50 | return; |
---|
51 | |
---|
52 | if (plugin != NULL) { |
---|
53 | gtk_list_store_append (availablePluginsModel, &iter); |
---|
54 | gtk_list_store_set (availablePluginsModel, &iter, |
---|
55 | NAME_COLUMN, plugin->name, |
---|
56 | FULLPATH_COLUMN, fullPath, -1); |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | static void |
---|
61 | CappletFillAvailablePluginList (GtkTreeView * |
---|
62 | availablePluginsList, |
---|
63 | GSwitchItPluginsCapplet * gswic) |
---|
64 | { |
---|
65 | GtkListStore *availablePluginsModel = |
---|
66 | GTK_LIST_STORE (gtk_tree_view_get_model |
---|
67 | (GTK_TREE_VIEW (availablePluginsList))); |
---|
68 | GSList *pluginPathNode = gswic->appletConfig.enabledPlugins; |
---|
69 | GHashTable *allPluginRecs = gswic->pluginManager.allPluginRecs; |
---|
70 | |
---|
71 | gtk_list_store_clear (availablePluginsModel); |
---|
72 | if (allPluginRecs == NULL) |
---|
73 | return; |
---|
74 | |
---|
75 | g_object_set_data (G_OBJECT (gswic->capplet), |
---|
76 | "gswitchit_plugins_add.availablePluginsModel", |
---|
77 | availablePluginsModel); |
---|
78 | g_hash_table_foreach (allPluginRecs, |
---|
79 | (GHFunc) CappletAddAvailablePluginFunc, |
---|
80 | gswic); |
---|
81 | g_object_set_data (G_OBJECT (gswic->capplet), |
---|
82 | "gswitchit_plugins_add.availablePluginsModel", |
---|
83 | NULL); |
---|
84 | pluginPathNode = g_slist_next (pluginPathNode); |
---|
85 | } |
---|
86 | |
---|
87 | static void |
---|
88 | CappletAvailablePluginsSelectionChanged (GtkTreeSelection * |
---|
89 | selection, |
---|
90 | GSwitchItPluginsCapplet * gswic) |
---|
91 | { |
---|
92 | GtkWidget *availablePluginsList = |
---|
93 | GTK_WIDGET (gtk_tree_selection_get_tree_view (selection)); |
---|
94 | gboolean isAnythingSelected = FALSE; |
---|
95 | GtkWidget *lblDescription = |
---|
96 | GTK_WIDGET (g_object_get_data (G_OBJECT (gswic->capplet), |
---|
97 | "gswitchit_plugins_add.lblDescription")); |
---|
98 | |
---|
99 | char *fullPath = |
---|
100 | CappletGetSelectedPluginPath (GTK_TREE_VIEW |
---|
101 | (availablePluginsList), |
---|
102 | gswic); |
---|
103 | isAnythingSelected = fullPath != NULL; |
---|
104 | gtk_label_set_text (GTK_LABEL (lblDescription), |
---|
105 | g_strconcat ("<small><i>", _("No description."), "</i></small>", NULL)); |
---|
106 | gtk_label_set_use_markup (GTK_LABEL (lblDescription), TRUE); |
---|
107 | |
---|
108 | if (fullPath != NULL) { |
---|
109 | const GSwitchItPlugin *plugin = |
---|
110 | GSwitchItPluginManagerGetPlugin (&gswic->pluginManager, |
---|
111 | fullPath); |
---|
112 | if (plugin != NULL && plugin->description != NULL) |
---|
113 | gtk_label_set_text (GTK_LABEL (lblDescription), |
---|
114 | g_strconcat ("<small><i>", |
---|
115 | plugin->description, |
---|
116 | "</i></small>", NULL)); |
---|
117 | gtk_label_set_use_markup (GTK_LABEL (lblDescription), TRUE); |
---|
118 | } |
---|
119 | gtk_widget_set_sensitive (GTK_WIDGET |
---|
120 | (g_object_get_data |
---|
121 | (G_OBJECT (gswic->capplet), |
---|
122 | "gswitchit_plugins_add.btnOK")), |
---|
123 | isAnythingSelected); |
---|
124 | } |
---|
125 | |
---|
126 | void |
---|
127 | CappletEnablePlugin (GtkWidget * btnAdd, GSwitchItPluginsCapplet * gswic) |
---|
128 | { |
---|
129 | GladeXML *data = glade_xml_new (GLADE_DIR "/gswitchit-plugins.glade", "gswitchit_plugins_add", NULL); // default domain! |
---|
130 | GtkWidget *popup = |
---|
131 | glade_xml_get_widget (data, "gswitchit_plugins_add"); |
---|
132 | GtkWidget *availablePluginsList; |
---|
133 | GtkTreeModel *availablePluginsModel; |
---|
134 | GtkCellRenderer *renderer = |
---|
135 | GTK_CELL_RENDERER (gtk_cell_renderer_text_new ()); |
---|
136 | GtkTreeViewColumn *column = |
---|
137 | gtk_tree_view_column_new_with_attributes (NULL, |
---|
138 | renderer, |
---|
139 | "text", |
---|
140 | 0, |
---|
141 | NULL); |
---|
142 | GtkTreeSelection *selection; |
---|
143 | gint response; |
---|
144 | availablePluginsList = glade_xml_get_widget (data, "allPlugins"); |
---|
145 | availablePluginsModel = |
---|
146 | GTK_TREE_MODEL (gtk_list_store_new |
---|
147 | (2, G_TYPE_STRING, G_TYPE_STRING)); |
---|
148 | gtk_tree_view_set_model (GTK_TREE_VIEW (availablePluginsList), |
---|
149 | availablePluginsModel); |
---|
150 | gtk_tree_view_append_column (GTK_TREE_VIEW (availablePluginsList), |
---|
151 | column); |
---|
152 | selection = |
---|
153 | gtk_tree_view_get_selection (GTK_TREE_VIEW |
---|
154 | (availablePluginsList)); |
---|
155 | gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); |
---|
156 | CappletFillAvailablePluginList (GTK_TREE_VIEW |
---|
157 | (availablePluginsList), gswic); |
---|
158 | g_signal_connect (G_OBJECT (selection), "changed", |
---|
159 | G_CALLBACK |
---|
160 | (CappletAvailablePluginsSelectionChanged), |
---|
161 | gswic); |
---|
162 | g_object_set_data (G_OBJECT (gswic->capplet), |
---|
163 | "gswitchit_plugins_add.btnOK", |
---|
164 | glade_xml_get_widget (data, "btnOK")); |
---|
165 | g_object_set_data (G_OBJECT (gswic->capplet), |
---|
166 | "gswitchit_plugins_add.lblDescription", |
---|
167 | glade_xml_get_widget (data, "lblDescription")); |
---|
168 | CappletAvailablePluginsSelectionChanged (selection, gswic); |
---|
169 | response = gtk_dialog_run (GTK_DIALOG (popup)); |
---|
170 | g_object_set_data (G_OBJECT (gswic->capplet), |
---|
171 | "gswitchit_plugins_add.lblDescription", NULL); |
---|
172 | g_object_set_data (G_OBJECT (gswic->capplet), |
---|
173 | "gswitchit_plugins_add.btnOK", NULL); |
---|
174 | gtk_widget_hide_all (popup); |
---|
175 | if (response == GTK_RESPONSE_OK) { |
---|
176 | char *fullPath = |
---|
177 | CappletGetSelectedPluginPath (GTK_TREE_VIEW |
---|
178 | (availablePluginsList), |
---|
179 | gswic); |
---|
180 | if (fullPath != NULL) { |
---|
181 | GSwitchItPluginManagerEnablePlugin (&gswic-> |
---|
182 | pluginManager, |
---|
183 | &gswic-> |
---|
184 | appletConfig. |
---|
185 | enabledPlugins, |
---|
186 | fullPath); |
---|
187 | CappletFillActivePluginList (gswic); |
---|
188 | g_free (fullPath); |
---|
189 | GSwitchItAppletConfigSave (&gswic->appletConfig, |
---|
190 | &gswic->xkbConfig); |
---|
191 | } |
---|
192 | } |
---|
193 | gtk_widget_destroy (popup); |
---|
194 | } |
---|