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 <sys/stat.h> |
---|
20 | |
---|
21 | #include <gdk/gdkx.h> |
---|
22 | #include <gnome.h> |
---|
23 | #include <glade/glade.h> |
---|
24 | #include <libbonobo.h> |
---|
25 | |
---|
26 | #include <libxklavier/xklavier.h> |
---|
27 | #include <libxklavier/xklavier_config.h> |
---|
28 | |
---|
29 | #include <libgswitchit/gswitchit_util.h> |
---|
30 | |
---|
31 | #include "gswitchit-applet.h" |
---|
32 | |
---|
33 | #define GLADE_DATA_PROP "gladeData" |
---|
34 | |
---|
35 | #define CappletGetGladeWidget( sia, name ) \ |
---|
36 | glade_xml_get_widget( \ |
---|
37 | GLADE_XML( g_object_get_data( G_OBJECT( (sia)->propsDialog ), \ |
---|
38 | GLADE_DATA_PROP ) ), \ |
---|
39 | name ) |
---|
40 | |
---|
41 | static GtkWidget * |
---|
42 | create_hig_catagory (GtkWidget *main_box, const char *title) |
---|
43 | { |
---|
44 | GtkWidget *vbox, *vbox2, *hbox; |
---|
45 | GtkWidget *label; |
---|
46 | gchar *tmp; |
---|
47 | |
---|
48 | vbox = gtk_vbox_new (FALSE, 6); |
---|
49 | gtk_box_pack_start (GTK_BOX (main_box), vbox, FALSE, FALSE, 0); |
---|
50 | |
---|
51 | tmp = g_strdup_printf ("<b>%s</b>", title); |
---|
52 | label = gtk_label_new (NULL); |
---|
53 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
---|
54 | gtk_label_set_markup (GTK_LABEL (label), tmp); |
---|
55 | g_free (tmp); |
---|
56 | gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, FALSE, 0); |
---|
57 | |
---|
58 | hbox = gtk_hbox_new (FALSE, 0); |
---|
59 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); |
---|
60 | |
---|
61 | label = gtk_label_new (" "); |
---|
62 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); |
---|
63 | |
---|
64 | vbox2 = gtk_vbox_new (FALSE, 6); |
---|
65 | gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0); |
---|
66 | |
---|
67 | return vbox2; |
---|
68 | } |
---|
69 | |
---|
70 | static void |
---|
71 | CappletUI2Config (GSwitchItApplet * sia) |
---|
72 | { |
---|
73 | int i = XklGetNumGroups (); |
---|
74 | int mask = 1 << (i - 1); |
---|
75 | |
---|
76 | for (; --i >= 0; mask >>= 1) { |
---|
77 | char sz[30]; |
---|
78 | GtkWidget *sec; |
---|
79 | |
---|
80 | g_snprintf (sz, sizeof (sz), "secondary.%d", i); |
---|
81 | sec = GTK_WIDGET (gtk_object_get_data |
---|
82 | (GTK_OBJECT (sia->propsDialog), sz)); |
---|
83 | |
---|
84 | if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (sec))) |
---|
85 | sia->appletConfig.secondaryGroupsMask |= mask; |
---|
86 | else |
---|
87 | sia->appletConfig.secondaryGroupsMask &= ~mask; |
---|
88 | } |
---|
89 | |
---|
90 | sia->appletConfig.groupPerApp = |
---|
91 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON |
---|
92 | (CappletGetGladeWidget (sia, |
---|
93 | "groupPerApp"))); |
---|
94 | |
---|
95 | sia->appletConfig.handleIndicators = |
---|
96 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON |
---|
97 | (CappletGetGladeWidget (sia, |
---|
98 | "handleIndicators"))); |
---|
99 | |
---|
100 | sia->appletConfig.showFlags = |
---|
101 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON |
---|
102 | (CappletGetGladeWidget (sia, |
---|
103 | "showFlags"))); |
---|
104 | |
---|
105 | sia->appletConfig.defaultGroup = |
---|
106 | GPOINTER_TO_INT (gtk_object_get_data |
---|
107 | (GTK_OBJECT |
---|
108 | (gtk_menu_get_active |
---|
109 | (GTK_MENU |
---|
110 | (gtk_option_menu_get_menu |
---|
111 | (GTK_OPTION_MENU |
---|
112 | (CappletGetGladeWidget |
---|
113 | (sia, "defaultGroupsOMenu")))))), |
---|
114 | "group")); |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | static void |
---|
119 | CappletCommitConfig (GtkWidget * w, GSwitchItApplet * sia) |
---|
120 | { |
---|
121 | CappletUI2Config (sia); |
---|
122 | GSwitchItAppletConfigSave (&sia->appletConfig, &sia->xkbConfig); |
---|
123 | } |
---|
124 | |
---|
125 | static void |
---|
126 | CappletGroupPerWindowChanged (GtkWidget * w, GSwitchItApplet * sia) |
---|
127 | { |
---|
128 | GtkWidget *handleIndicators; |
---|
129 | |
---|
130 | CappletCommitConfig (w, sia); |
---|
131 | |
---|
132 | handleIndicators = CappletGetGladeWidget (sia, "handleIndicators"); |
---|
133 | gtk_widget_set_sensitive (handleIndicators, |
---|
134 | sia->appletConfig.groupPerApp); |
---|
135 | } |
---|
136 | |
---|
137 | static void |
---|
138 | CappletShowFlagsChanged (GtkWidget * w, GSwitchItApplet * sia) |
---|
139 | { |
---|
140 | CappletCommitConfig (w, sia); |
---|
141 | } |
---|
142 | |
---|
143 | static void |
---|
144 | CappletSecChanged (GtkWidget * w, GSwitchItApplet * sia) |
---|
145 | { |
---|
146 | CappletCommitConfig (w, sia); |
---|
147 | |
---|
148 | if ((sia->appletConfig.secondaryGroupsMask + 1) == (1 << XklGetNumGroups ())) // all secondaries? |
---|
149 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), |
---|
150 | FALSE); |
---|
151 | } |
---|
152 | |
---|
153 | static void |
---|
154 | CappletResponse (GtkDialog * capplet, gint id, GSwitchItApplet * sia) |
---|
155 | { |
---|
156 | if (id == GTK_RESPONSE_HELP) { |
---|
157 | GSwitchItHelp (GTK_WIDGET (sia->propsDialog), |
---|
158 | "gswitchit-applet-prefs"); |
---|
159 | return; |
---|
160 | } |
---|
161 | gtk_widget_destroy (GTK_WIDGET (capplet)); |
---|
162 | sia->propsDialog = NULL; |
---|
163 | } |
---|
164 | |
---|
165 | void |
---|
166 | GSwitchItAppletPropsCreate (GSwitchItApplet * sia) |
---|
167 | { |
---|
168 | GladeXML *data; |
---|
169 | GtkWidget *capplet; |
---|
170 | |
---|
171 | GtkWidget *groupPerApp; |
---|
172 | GtkWidget *handleIndicators; |
---|
173 | GtkWidget *showFlags; |
---|
174 | GtkWidget *menuItem; |
---|
175 | GtkWidget *vboxFlags; |
---|
176 | GtkWidget *defaultGroupsOMenu; |
---|
177 | GtkWidget *defaultGroupsMenu; |
---|
178 | int i; |
---|
179 | GtkTooltips *tooltips; |
---|
180 | const char *groupName, *iconFile; |
---|
181 | GroupDescriptionsBuffer groupNames; |
---|
182 | |
---|
183 | const char *secondaryTooltip = |
---|
184 | _ |
---|
185 | ("Make the layout accessible from the applet popup menu ONLY.\n" |
---|
186 | "No way to switch to this layout using the keyboard."); |
---|
187 | |
---|
188 | data = glade_xml_new (GLADE_DIR "/gswitchit-properties.glade", "gswitchit_capplet", NULL); // default domain! |
---|
189 | XklDebug (125, "data: %p\n", data); |
---|
190 | |
---|
191 | sia->propsDialog = capplet = |
---|
192 | glade_xml_get_widget (data, "gswitchit_capplet"); |
---|
193 | |
---|
194 | iconFile = gnome_program_locate_file (NULL, |
---|
195 | GNOME_FILE_DOMAIN_PIXMAP, |
---|
196 | "gswitchit-properties-capplet.png", |
---|
197 | TRUE, NULL); |
---|
198 | if (iconFile != NULL) |
---|
199 | gtk_window_set_icon_from_file (GTK_WINDOW (capplet), |
---|
200 | iconFile, NULL); |
---|
201 | |
---|
202 | gtk_object_set_data (GTK_OBJECT (capplet), GLADE_DATA_PROP, data); |
---|
203 | |
---|
204 | gtk_dialog_set_default_response (GTK_DIALOG (capplet), |
---|
205 | GTK_RESPONSE_CLOSE); |
---|
206 | |
---|
207 | g_signal_connect_swapped (GTK_OBJECT (capplet), "destroy", |
---|
208 | G_CALLBACK (g_object_unref), data); |
---|
209 | |
---|
210 | groupPerApp = glade_xml_get_widget (data, "groupPerApp"); |
---|
211 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (groupPerApp), |
---|
212 | sia->appletConfig.groupPerApp); |
---|
213 | |
---|
214 | tooltips = gtk_tooltips_data_get (groupPerApp)->tooltips; |
---|
215 | |
---|
216 | g_signal_connect (G_OBJECT (groupPerApp), |
---|
217 | "toggled", |
---|
218 | G_CALLBACK (CappletGroupPerWindowChanged), sia); |
---|
219 | |
---|
220 | showFlags = glade_xml_get_widget (data, "showFlags"); |
---|
221 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (showFlags), |
---|
222 | sia->appletConfig.showFlags); |
---|
223 | g_signal_connect (G_OBJECT (showFlags), |
---|
224 | "toggled", G_CALLBACK (CappletShowFlagsChanged), |
---|
225 | sia); |
---|
226 | |
---|
227 | handleIndicators = glade_xml_get_widget (data, "handleIndicators"); |
---|
228 | |
---|
229 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (handleIndicators), |
---|
230 | sia->appletConfig.handleIndicators); |
---|
231 | |
---|
232 | g_signal_connect (GTK_OBJECT (handleIndicators), |
---|
233 | "toggled", G_CALLBACK (CappletCommitConfig), |
---|
234 | sia); |
---|
235 | |
---|
236 | vboxFlags = glade_xml_get_widget (data, "gswitchit_capplet_vbox"); |
---|
237 | |
---|
238 | GSwitchItAppletConfigLoadGroupDescriptionsUtf8 (&sia->appletConfig, |
---|
239 | groupNames); |
---|
240 | groupName = (const char *) groupNames; |
---|
241 | for (i = 0; i < XklGetNumGroups (); |
---|
242 | i++, groupName += sizeof (groupNames[0])) { |
---|
243 | gchar sz[30]; |
---|
244 | GtkWidget *secondary; |
---|
245 | GtkWidget *frameFlag; |
---|
246 | GtkWidget *vboxPerGroup; |
---|
247 | |
---|
248 | frameFlag = create_hig_catagory (vboxFlags, groupName); |
---|
249 | g_snprintf (sz, sizeof (sz), "frameFlag.%d", i); |
---|
250 | gtk_widget_set_name (frameFlag, sz); |
---|
251 | gtk_object_set_data (GTK_OBJECT (capplet), sz, frameFlag); |
---|
252 | //gtk_widget_show( frameFlag ); |
---|
253 | |
---|
254 | vboxPerGroup = gtk_vbox_new (FALSE, 0); |
---|
255 | g_snprintf (sz, sizeof (sz), "vboxPerGroup.%d", i); |
---|
256 | gtk_widget_set_name (vboxPerGroup, sz); |
---|
257 | gtk_object_set_data (GTK_OBJECT (capplet), sz, |
---|
258 | vboxPerGroup); |
---|
259 | |
---|
260 | secondary = |
---|
261 | gtk_check_button_new_with_mnemonic (_ |
---|
262 | ("_Exclude from keyboard switching")); |
---|
263 | g_snprintf (sz, sizeof (sz), "secondary.%d", i); |
---|
264 | gtk_widget_set_name (secondary, sz); |
---|
265 | gtk_object_set_data (GTK_OBJECT (capplet), sz, secondary); |
---|
266 | |
---|
267 | gtk_object_set_data (GTK_OBJECT (secondary), |
---|
268 | "idx", GINT_TO_POINTER (i)); |
---|
269 | |
---|
270 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON |
---|
271 | (secondary), |
---|
272 | (sia->appletConfig. |
---|
273 | secondaryGroupsMask & (1 << |
---|
274 | i)) |
---|
275 | != 0); |
---|
276 | gtk_tooltips_set_tip (tooltips, secondary, |
---|
277 | secondaryTooltip, secondaryTooltip); |
---|
278 | |
---|
279 | gtk_box_pack_start (GTK_BOX (vboxPerGroup), secondary, |
---|
280 | FALSE, FALSE, 0); |
---|
281 | gtk_container_add (GTK_CONTAINER (frameFlag), |
---|
282 | vboxPerGroup); |
---|
283 | |
---|
284 | g_signal_connect (GTK_OBJECT (secondary), "toggled", |
---|
285 | G_CALLBACK (CappletSecChanged), sia); |
---|
286 | } |
---|
287 | |
---|
288 | defaultGroupsMenu = gtk_menu_new (); |
---|
289 | |
---|
290 | gtk_object_set_data (GTK_OBJECT (capplet), "defaultGroupsMenu", |
---|
291 | defaultGroupsMenu); |
---|
292 | |
---|
293 | menuItem = gtk_menu_item_new_with_label (_("Not used")); |
---|
294 | gtk_object_set_data (GTK_OBJECT (menuItem), "group", |
---|
295 | GINT_TO_POINTER (-1)); |
---|
296 | g_signal_connect (GTK_OBJECT (menuItem), "activate", |
---|
297 | G_CALLBACK (CappletCommitConfig), sia); |
---|
298 | |
---|
299 | gtk_menu_shell_append (GTK_MENU_SHELL (defaultGroupsMenu), |
---|
300 | menuItem); |
---|
301 | gtk_widget_show (menuItem); |
---|
302 | groupName = (const char *) groupNames; |
---|
303 | for (i = 0; i < XklGetNumGroups (); |
---|
304 | i++, groupName += sizeof (groupNames[0])) { |
---|
305 | menuItem = gtk_menu_item_new_with_label (groupName); |
---|
306 | gtk_object_set_data (GTK_OBJECT (menuItem), "group", |
---|
307 | GINT_TO_POINTER (i)); |
---|
308 | g_signal_connect (GTK_OBJECT (menuItem), "activate", |
---|
309 | G_CALLBACK (CappletCommitConfig), sia); |
---|
310 | gtk_menu_shell_append (GTK_MENU_SHELL (defaultGroupsMenu), |
---|
311 | menuItem); |
---|
312 | gtk_widget_show (menuItem); |
---|
313 | } |
---|
314 | |
---|
315 | defaultGroupsOMenu = |
---|
316 | glade_xml_get_widget (data, "defaultGroupsOMenu"); |
---|
317 | gtk_option_menu_set_menu (GTK_OPTION_MENU (defaultGroupsOMenu), |
---|
318 | defaultGroupsMenu); |
---|
319 | // initial value - ( group no + 1 ) |
---|
320 | gtk_option_menu_set_history (GTK_OPTION_MENU (defaultGroupsOMenu), |
---|
321 | (sia->appletConfig.defaultGroup < |
---|
322 | XklGetNumGroups ())? sia-> |
---|
323 | appletConfig.defaultGroup + 1 : 0); |
---|
324 | |
---|
325 | g_signal_connect (G_OBJECT (capplet), "response", |
---|
326 | G_CALLBACK (CappletResponse), sia); |
---|
327 | |
---|
328 | CappletGroupPerWindowChanged (groupPerApp, sia); |
---|
329 | CappletShowFlagsChanged (showFlags, sia); |
---|
330 | |
---|
331 | gtk_window_set_screen (GTK_WINDOW (capplet), |
---|
332 | gtk_widget_get_screen (GTK_WIDGET (sia->applet))); |
---|
333 | |
---|
334 | gtk_widget_show_all (capplet); |
---|
335 | #ifndef ENABLE_FLAGS |
---|
336 | gtk_widget_hide (showFlags); |
---|
337 | #endif |
---|
338 | |
---|
339 | } |
---|