1 | /* gnome-panel-preferences: crapplet for global panel properties |
---|
2 | * |
---|
3 | * Copyright (C) 1999 Free Software Foundation |
---|
4 | * Copyright (C) 2000 Helix Code, Inc. |
---|
5 | * Copyright (C) 2000 Eazel, Inc. |
---|
6 | * Copyright (C) 2002 Sun Microsystems Inc. |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License as |
---|
10 | * published by the Free Software Foundation; either version 2 of the |
---|
11 | * License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
21 | * USA |
---|
22 | * |
---|
23 | * Authors: George Lebl <jirka@5z.com> |
---|
24 | * Jacob Berkman <jacob@helixcode.com> |
---|
25 | * Mark McLoughlin <mark@skynet.ie> |
---|
26 | */ |
---|
27 | |
---|
28 | #include <config.h> |
---|
29 | #include <string.h> |
---|
30 | |
---|
31 | #include <libgnome/libgnome.h> |
---|
32 | #include <libgnomeui/libgnomeui.h> |
---|
33 | #include <glade/glade.h> |
---|
34 | #include <gconf/gconf-client.h> |
---|
35 | |
---|
36 | #include "panel-gconf.h" |
---|
37 | #include "panel-types.h" |
---|
38 | |
---|
39 | #define GLADE_FILE GLADEDIR "/gnome-panel-preferences.glade" |
---|
40 | |
---|
41 | static GConfEnumStringPair global_properties_speed_type_enum_map [] = { |
---|
42 | { PANEL_SPEED_SLOW, "panel-speed-slow" }, |
---|
43 | { PANEL_SPEED_MEDIUM, "panel-speed-medium" }, |
---|
44 | { PANEL_SPEED_FAST, "panel-speed-fast" }, |
---|
45 | }; |
---|
46 | |
---|
47 | /* Hooked up by glade */ |
---|
48 | void preferences_response (GtkWindow *window, |
---|
49 | int button, |
---|
50 | gpointer data); |
---|
51 | |
---|
52 | static void |
---|
53 | update_sensitive_for_checkbox (GladeXML *gui, |
---|
54 | char *key, |
---|
55 | int checked) |
---|
56 | { |
---|
57 | GtkWidget *associate = NULL; |
---|
58 | |
---|
59 | if (!strcmp (key, "enable_animations")) |
---|
60 | associate = glade_xml_get_widget (gui, "panel_animation_hbox"); |
---|
61 | |
---|
62 | if (associate) |
---|
63 | gtk_widget_set_sensitive (associate, checked); |
---|
64 | } |
---|
65 | |
---|
66 | static void |
---|
67 | bool_value_changed_notify (GConfClient *client, |
---|
68 | guint cnxn_id, |
---|
69 | GConfEntry *entry, |
---|
70 | GtkToggleButton *toggle) |
---|
71 | { |
---|
72 | gboolean value; |
---|
73 | |
---|
74 | if (!entry->value || entry->value->type != GCONF_VALUE_BOOL) |
---|
75 | return; |
---|
76 | |
---|
77 | value = gconf_value_get_bool (entry->value); |
---|
78 | |
---|
79 | if (gtk_toggle_button_get_active (toggle) != value) { |
---|
80 | char *basename; |
---|
81 | |
---|
82 | gtk_toggle_button_set_active (toggle, value); |
---|
83 | |
---|
84 | basename = g_path_get_basename (gconf_entry_get_key (entry)); |
---|
85 | update_sensitive_for_checkbox ( |
---|
86 | g_object_get_data (G_OBJECT (toggle), "glade-xml"), |
---|
87 | basename, value); |
---|
88 | g_free (basename); |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | static void |
---|
93 | checkbox_clicked (GtkWidget *widget, |
---|
94 | char *key) |
---|
95 | { |
---|
96 | GConfClient *client; |
---|
97 | int checked; |
---|
98 | |
---|
99 | client = gconf_client_get_default (); |
---|
100 | |
---|
101 | checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); |
---|
102 | |
---|
103 | gconf_client_set_bool (client, |
---|
104 | panel_gconf_global_key (key), |
---|
105 | checked, NULL); |
---|
106 | |
---|
107 | update_sensitive_for_checkbox ( |
---|
108 | g_object_get_data (G_OBJECT (widget), "glade-xml"), |
---|
109 | key, checked); |
---|
110 | |
---|
111 | g_object_unref (client); |
---|
112 | } |
---|
113 | |
---|
114 | static void |
---|
115 | load_checkboxes (GladeXML *gui, |
---|
116 | GConfClient *client) |
---|
117 | { |
---|
118 | static char *checkboxes [] = { |
---|
119 | "drawer_autoclose", |
---|
120 | "enable_animations", |
---|
121 | NULL |
---|
122 | }; |
---|
123 | int i; |
---|
124 | |
---|
125 | for (i = 0; checkboxes [i]; i++) { |
---|
126 | GtkWidget *checkbox; |
---|
127 | const char *key; |
---|
128 | int checked; |
---|
129 | |
---|
130 | checkbox = glade_xml_get_widget (gui, checkboxes [i]); |
---|
131 | g_object_set_data (G_OBJECT (checkbox), "glade-xml", gui); |
---|
132 | |
---|
133 | key = panel_gconf_global_key (checkboxes [i]); |
---|
134 | |
---|
135 | gconf_client_notify_add ( |
---|
136 | client, key, |
---|
137 | (GConfClientNotifyFunc) bool_value_changed_notify, |
---|
138 | checkbox, NULL, NULL); |
---|
139 | |
---|
140 | checked = gconf_client_get_bool (client, key, NULL); |
---|
141 | |
---|
142 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbox), checked); |
---|
143 | |
---|
144 | g_signal_connect (checkbox, "clicked", |
---|
145 | G_CALLBACK (checkbox_clicked), checkboxes [i]); |
---|
146 | update_sensitive_for_checkbox (gui, checkboxes [i], checked); |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | static void |
---|
151 | animation_menu_changed (GtkWidget *widget) |
---|
152 | { |
---|
153 | GConfClient *client; |
---|
154 | |
---|
155 | client = gconf_client_get_default (); |
---|
156 | |
---|
157 | gconf_client_set_string (client, |
---|
158 | panel_gconf_global_key ("panel_animation_speed"), |
---|
159 | gconf_enum_to_string (global_properties_speed_type_enum_map, |
---|
160 | gtk_option_menu_get_history (GTK_OPTION_MENU (widget))), |
---|
161 | NULL); |
---|
162 | |
---|
163 | g_object_unref (client); |
---|
164 | } |
---|
165 | |
---|
166 | static void |
---|
167 | enum_value_changed_notify (GConfClient *client, |
---|
168 | guint cnxn_id, |
---|
169 | GConfEntry *entry, |
---|
170 | GtkOptionMenu *option) |
---|
171 | { |
---|
172 | const char *value; |
---|
173 | int speed = PANEL_SPEED_SLOW; |
---|
174 | |
---|
175 | if (!entry->value || entry->value->type != GCONF_VALUE_STRING) |
---|
176 | return; |
---|
177 | |
---|
178 | value = gconf_value_get_string (entry->value); |
---|
179 | |
---|
180 | gconf_string_to_enum ( |
---|
181 | global_properties_speed_type_enum_map, value, &speed); |
---|
182 | |
---|
183 | if (gtk_option_menu_get_history (GTK_OPTION_MENU (option)) != speed) |
---|
184 | gtk_option_menu_set_history (GTK_OPTION_MENU (option), speed); |
---|
185 | } |
---|
186 | |
---|
187 | static void |
---|
188 | load_animation_menu (GladeXML *gui, |
---|
189 | GConfClient *client) |
---|
190 | { |
---|
191 | GtkWidget *option; |
---|
192 | char *tmpstr; |
---|
193 | int speed = PANEL_SPEED_SLOW; |
---|
194 | const char *key; |
---|
195 | |
---|
196 | option = glade_xml_get_widget (gui, "panel_animation_speed"); |
---|
197 | |
---|
198 | key = panel_gconf_global_key ("panel_animation_speed"); |
---|
199 | |
---|
200 | gconf_client_notify_add ( |
---|
201 | client, key, |
---|
202 | (GConfClientNotifyFunc) enum_value_changed_notify, |
---|
203 | option, NULL, NULL); |
---|
204 | |
---|
205 | tmpstr = gconf_client_get_string (client, key, NULL); |
---|
206 | gconf_string_to_enum ( |
---|
207 | global_properties_speed_type_enum_map, tmpstr, &speed); |
---|
208 | g_free (tmpstr); |
---|
209 | |
---|
210 | gtk_option_menu_set_history (GTK_OPTION_MENU (option), speed); |
---|
211 | |
---|
212 | g_signal_connect (option, "changed", |
---|
213 | G_CALLBACK (animation_menu_changed), NULL); |
---|
214 | } |
---|
215 | |
---|
216 | static void |
---|
217 | load_config_into_gui (GladeXML *gui) |
---|
218 | { |
---|
219 | GConfClient *client; |
---|
220 | GError *error = NULL; |
---|
221 | |
---|
222 | client = gconf_client_get_default (); |
---|
223 | |
---|
224 | gconf_client_add_dir (client, "/apps/panel/global", |
---|
225 | GCONF_CLIENT_PRELOAD_NONE, &error); |
---|
226 | if (error) { |
---|
227 | g_warning ("Failed to monitor '/apps/panel/global': %s", error->message); |
---|
228 | g_error_free (error); |
---|
229 | } |
---|
230 | |
---|
231 | load_checkboxes (gui, client); |
---|
232 | load_animation_menu (gui, client); |
---|
233 | |
---|
234 | g_object_unref (client); |
---|
235 | } |
---|
236 | |
---|
237 | void |
---|
238 | preferences_response (GtkWindow *window, |
---|
239 | int button, |
---|
240 | gpointer data) |
---|
241 | { |
---|
242 | GError *error = NULL; |
---|
243 | |
---|
244 | switch (button) { |
---|
245 | case GTK_RESPONSE_CLOSE: |
---|
246 | gtk_main_quit (); |
---|
247 | break; |
---|
248 | |
---|
249 | case GTK_RESPONSE_HELP: |
---|
250 | gnome_help_display_desktop (NULL, "user-guide", |
---|
251 | "wgoscustlookandfeel.xml", "goscustdesk-10", &error); |
---|
252 | if (error) { |
---|
253 | GtkWidget *dialog; |
---|
254 | |
---|
255 | dialog = gtk_message_dialog_new (window, |
---|
256 | GTK_DIALOG_DESTROY_WITH_PARENT, |
---|
257 | GTK_MESSAGE_ERROR, |
---|
258 | GTK_BUTTONS_CLOSE, |
---|
259 | _("There was an error displaying help: \n%s"), |
---|
260 | error->message); |
---|
261 | |
---|
262 | g_signal_connect (G_OBJECT (dialog), "response", |
---|
263 | G_CALLBACK (gtk_widget_destroy), |
---|
264 | NULL); |
---|
265 | |
---|
266 | gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); |
---|
267 | gtk_widget_show (dialog); |
---|
268 | g_error_free (error); |
---|
269 | } |
---|
270 | |
---|
271 | break; |
---|
272 | |
---|
273 | default: |
---|
274 | break; |
---|
275 | } |
---|
276 | } |
---|
277 | |
---|
278 | static void |
---|
279 | error_dialog (const char *message) |
---|
280 | { |
---|
281 | GtkWidget *dialog; |
---|
282 | |
---|
283 | dialog = gtk_message_dialog_new (NULL, 0, |
---|
284 | GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, |
---|
285 | message); |
---|
286 | |
---|
287 | g_signal_connect (dialog, "response", |
---|
288 | G_CALLBACK (gtk_widget_destroy), NULL); |
---|
289 | g_signal_connect (dialog, "destroy", |
---|
290 | G_CALLBACK (gtk_main_quit), NULL); |
---|
291 | gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); |
---|
292 | gtk_widget_show (dialog); |
---|
293 | |
---|
294 | } |
---|
295 | |
---|
296 | static gboolean |
---|
297 | check_lockdown (void) |
---|
298 | { |
---|
299 | GConfClient *client; |
---|
300 | gboolean locked_down; |
---|
301 | |
---|
302 | client = gconf_client_get_default (); |
---|
303 | |
---|
304 | locked_down = gconf_client_get_bool ( |
---|
305 | client, panel_gconf_global_key ("lock-down"), NULL); |
---|
306 | if (locked_down) |
---|
307 | error_dialog (_("The system administrator has disallowed\n" |
---|
308 | "modification of the panel configuration")); |
---|
309 | |
---|
310 | g_object_unref (client); |
---|
311 | |
---|
312 | return locked_down; |
---|
313 | } |
---|
314 | |
---|
315 | int |
---|
316 | main (int argc, char **argv) |
---|
317 | { |
---|
318 | GladeXML *gui = NULL; |
---|
319 | |
---|
320 | bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); |
---|
321 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
---|
322 | textdomain (GETTEXT_PACKAGE); |
---|
323 | |
---|
324 | gnome_program_init ("gnome-panel-preferences", VERSION, |
---|
325 | LIBGNOMEUI_MODULE, argc, argv, |
---|
326 | GNOME_PROGRAM_STANDARD_PROPERTIES, NULL); |
---|
327 | |
---|
328 | if (!check_lockdown ()) { |
---|
329 | GtkWidget *dialog; |
---|
330 | char *panel_icon; |
---|
331 | |
---|
332 | gui = glade_xml_new ( |
---|
333 | GLADE_FILE, "gnome_panel_preferences_dialog", NULL); |
---|
334 | if (!gui) { |
---|
335 | char *error; |
---|
336 | |
---|
337 | error = g_strdup_printf (_("Error loading glade file %s"), GLADE_FILE); |
---|
338 | error_dialog (error); |
---|
339 | g_free (error); |
---|
340 | |
---|
341 | gtk_main (); |
---|
342 | } |
---|
343 | |
---|
344 | glade_xml_signal_autoconnect (gui); |
---|
345 | |
---|
346 | dialog = glade_xml_get_widget ( |
---|
347 | gui, "gnome_panel_preferences_dialog"); |
---|
348 | |
---|
349 | load_config_into_gui (gui); |
---|
350 | |
---|
351 | panel_icon = gnome_program_locate_file ( |
---|
352 | NULL, GNOME_FILE_DOMAIN_PIXMAP, |
---|
353 | "gnome-panel.png", TRUE, NULL); |
---|
354 | if (panel_icon) { |
---|
355 | gnome_window_icon_set_from_file ( |
---|
356 | GTK_WINDOW (dialog), panel_icon); |
---|
357 | g_free (panel_icon); |
---|
358 | } |
---|
359 | |
---|
360 | gtk_widget_show (dialog); |
---|
361 | } |
---|
362 | |
---|
363 | gtk_main (); |
---|
364 | |
---|
365 | if (gui) |
---|
366 | g_object_unref (gui); |
---|
367 | |
---|
368 | return 0; |
---|
369 | } |
---|