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 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 | #ifdef HAVE_CONFIG_H |
---|
18 | #include <config.h> |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <gconf/gconf-client.h> |
---|
22 | #include <panel-applet.h> |
---|
23 | #include <panel-applet-gconf.h> |
---|
24 | #include <gconf/gconf.h> |
---|
25 | #include <gconf/gconf-client.h> |
---|
26 | |
---|
27 | #include "drivemount.h" |
---|
28 | #include "properties.h" |
---|
29 | |
---|
30 | #define NEVER_SENSITIVE "never_sensitive" |
---|
31 | |
---|
32 | typedef struct _ResponseWidgets |
---|
33 | { |
---|
34 | DriveData *dd; |
---|
35 | GtkWidget *mount_entry; |
---|
36 | GtkWidget *update_spin; |
---|
37 | GtkWidget *omenu; |
---|
38 | GtkWidget *icon_entry_in; |
---|
39 | GtkWidget *icon_entry_out; |
---|
40 | GtkWidget *scale_toggle; |
---|
41 | GtkWidget *eject_toggle; |
---|
42 | GtkWidget *automount_toggle; |
---|
43 | } ResponseWidgets; |
---|
44 | |
---|
45 | static void handle_response_cb(GtkDialog *dialog, gint response, ResponseWidgets *widgets); |
---|
46 | static void set_widget_sensitivity_false_cb(GtkWidget *widget, GtkWidget *target); |
---|
47 | static void set_widget_sensitivity_true_cb(GtkWidget *widget, GtkWidget *target); |
---|
48 | static gchar *remove_level_from_path(const gchar *path); |
---|
49 | static void sync_mount_base(DriveData *dd); |
---|
50 | |
---|
51 | /* set sensitive and setup NEVER_SENSITIVE appropriately */ |
---|
52 | static void |
---|
53 | hard_set_sensitive (GtkWidget *w, gboolean sensitivity) |
---|
54 | { |
---|
55 | gtk_widget_set_sensitive (w, sensitivity); |
---|
56 | g_object_set_data (G_OBJECT (w), NEVER_SENSITIVE, |
---|
57 | GINT_TO_POINTER ( ! sensitivity)); |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | /* set sensitive, but always insensitive if NEVER_SENSITIVE is set */ |
---|
62 | static void |
---|
63 | soft_set_sensitive (GtkWidget *w, gboolean sensitivity) |
---|
64 | { |
---|
65 | if (g_object_get_data (G_OBJECT (w), NEVER_SENSITIVE)) |
---|
66 | gtk_widget_set_sensitive (w, FALSE); |
---|
67 | else |
---|
68 | gtk_widget_set_sensitive (w, sensitivity); |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | static gboolean |
---|
73 | key_writable (PanelApplet *applet, const char *key) |
---|
74 | { |
---|
75 | gboolean writable; |
---|
76 | char *fullkey; |
---|
77 | static GConfClient *client = NULL; |
---|
78 | if (client == NULL) |
---|
79 | client = gconf_client_get_default (); |
---|
80 | |
---|
81 | fullkey = panel_applet_gconf_get_full_key (applet, key); |
---|
82 | |
---|
83 | writable = gconf_client_key_is_writable (client, fullkey, NULL); |
---|
84 | |
---|
85 | g_free (fullkey); |
---|
86 | |
---|
87 | return writable; |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | void |
---|
92 | properties_load(DriveData *dd) |
---|
93 | { |
---|
94 | GConfClient *client; |
---|
95 | gchar *key; |
---|
96 | GError *error = NULL; |
---|
97 | |
---|
98 | client = gconf_client_get_default (); |
---|
99 | key = panel_applet_get_preferences_key (PANEL_APPLET (dd->applet)); |
---|
100 | |
---|
101 | if (gconf_client_dir_exists (client, key, NULL)) { |
---|
102 | dd->interval = panel_applet_gconf_get_int(PANEL_APPLET(dd->applet), "interval", &error); |
---|
103 | if (error) { |
---|
104 | g_print ("%s \n", error->message); |
---|
105 | g_error_free (error); |
---|
106 | error = NULL; |
---|
107 | } |
---|
108 | dd->interval = MAX (dd->interval, 1); |
---|
109 | dd->device_pixmap = panel_applet_gconf_get_int(PANEL_APPLET(dd->applet), "pixmap", NULL); |
---|
110 | dd->device_pixmap = MIN (dd->device_pixmap, icon_list_count - 1); |
---|
111 | dd->scale_applet = panel_applet_gconf_get_bool(PANEL_APPLET(dd->applet), "scale", NULL); |
---|
112 | dd->auto_eject = panel_applet_gconf_get_bool(PANEL_APPLET(dd->applet), "auto_eject", NULL); |
---|
113 | dd->mount_point = panel_applet_gconf_get_string(PANEL_APPLET(dd->applet), "mount_point", NULL); |
---|
114 | if (!dd->mount_point) |
---|
115 | dd->mount_point = g_strdup ("/mnt/floppy"); |
---|
116 | dd->autofs_friendly = panel_applet_gconf_get_bool(PANEL_APPLET(dd->applet), "autofs_friendly", NULL); |
---|
117 | dd->custom_icon_in = panel_applet_gconf_get_string(PANEL_APPLET(dd->applet), "custom_icon_mounted", NULL); |
---|
118 | dd->custom_icon_out = panel_applet_gconf_get_string(PANEL_APPLET(dd->applet), "custom_icon_unmounted", NULL); |
---|
119 | } else { |
---|
120 | dd->mount_point = g_strdup("/mnt/floppy"); |
---|
121 | dd->interval = 10; |
---|
122 | } |
---|
123 | g_object_unref (G_OBJECT (client)); |
---|
124 | g_free (key); |
---|
125 | sync_mount_base(dd); |
---|
126 | } |
---|
127 | |
---|
128 | static void |
---|
129 | cb_mount_activate (GtkEditable *entry, gpointer data) |
---|
130 | { |
---|
131 | DriveData *dd = data; |
---|
132 | gchar *text; |
---|
133 | |
---|
134 | text = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1); |
---|
135 | |
---|
136 | if (!text) |
---|
137 | return; |
---|
138 | |
---|
139 | if (dd->mount_point) { |
---|
140 | if (!g_ascii_strcasecmp (text, dd->mount_point)) { |
---|
141 | g_free (text); |
---|
142 | return; |
---|
143 | } |
---|
144 | |
---|
145 | g_free(dd->mount_point); |
---|
146 | dd->mount_point = g_strdup(text); |
---|
147 | |
---|
148 | } |
---|
149 | else |
---|
150 | dd->mount_point = g_strdup(text); |
---|
151 | |
---|
152 | sync_mount_base (dd); |
---|
153 | redraw_pixmap (dd); |
---|
154 | panel_applet_gconf_set_string(PANEL_APPLET(dd->applet), "mount_point", |
---|
155 | dd->mount_point, NULL); |
---|
156 | g_free (text); |
---|
157 | |
---|
158 | } |
---|
159 | |
---|
160 | static gboolean |
---|
161 | cb_mount_focus_out (GtkWidget *widget, GdkEventFocus *event, gpointer data) |
---|
162 | { |
---|
163 | DriveData *dd = data; |
---|
164 | |
---|
165 | cb_mount_activate (GTK_EDITABLE (widget), dd); |
---|
166 | |
---|
167 | return FALSE; |
---|
168 | |
---|
169 | } |
---|
170 | |
---|
171 | static void |
---|
172 | spin_changed (GtkWidget *button, GdkEventFocus *event, gpointer data) |
---|
173 | { |
---|
174 | DriveData *dd = data; |
---|
175 | |
---|
176 | dd->interval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON (button)); |
---|
177 | |
---|
178 | start_callback_update(dd); |
---|
179 | panel_applet_gconf_set_int(PANEL_APPLET(dd->applet), "interval", |
---|
180 | dd->interval, NULL); |
---|
181 | |
---|
182 | |
---|
183 | } |
---|
184 | |
---|
185 | static void |
---|
186 | scale_toggled (GtkToggleButton *button, gpointer data) |
---|
187 | { |
---|
188 | DriveData *dd = data; |
---|
189 | |
---|
190 | dd->scale_applet = gtk_toggle_button_get_active (button); |
---|
191 | redraw_pixmap(dd); |
---|
192 | panel_applet_gconf_set_bool(PANEL_APPLET(dd->applet), "scale", |
---|
193 | dd->scale_applet, NULL); |
---|
194 | |
---|
195 | } |
---|
196 | |
---|
197 | static void |
---|
198 | eject_toggled (GtkToggleButton *button, gpointer data) |
---|
199 | { |
---|
200 | DriveData *dd = data; |
---|
201 | |
---|
202 | dd->auto_eject = gtk_toggle_button_get_active (button); |
---|
203 | panel_applet_gconf_set_bool(PANEL_APPLET(dd->applet), "auto_eject", |
---|
204 | dd->auto_eject, NULL); |
---|
205 | |
---|
206 | } |
---|
207 | |
---|
208 | static void |
---|
209 | automount_toggled (GtkToggleButton *button, gpointer data) |
---|
210 | { |
---|
211 | DriveData *dd = data; |
---|
212 | |
---|
213 | dd->autofs_friendly = gtk_toggle_button_get_active (button); |
---|
214 | panel_applet_gconf_set_bool(PANEL_APPLET(dd->applet), "autofs_friendly", |
---|
215 | dd->autofs_friendly, NULL); |
---|
216 | |
---|
217 | } |
---|
218 | |
---|
219 | static void |
---|
220 | omenu_changed (GtkOptionMenu *menu, gpointer data) |
---|
221 | { |
---|
222 | DriveData *dd = data; |
---|
223 | gint num; |
---|
224 | |
---|
225 | num = gtk_option_menu_get_history (menu); |
---|
226 | dd->device_pixmap = num < icon_list_count ? num : -1; |
---|
227 | panel_applet_gconf_set_int(PANEL_APPLET(dd->applet), "pixmap", |
---|
228 | dd->device_pixmap, NULL); |
---|
229 | redraw_pixmap(dd); |
---|
230 | |
---|
231 | } |
---|
232 | |
---|
233 | static void |
---|
234 | mount_icon_changed (GnomeIconEntry *entry, gpointer data) |
---|
235 | { |
---|
236 | DriveData *dd = data; |
---|
237 | gchar *temp; |
---|
238 | |
---|
239 | temp = gnome_icon_entry_get_filename(entry); |
---|
240 | |
---|
241 | if (!temp) |
---|
242 | return; |
---|
243 | |
---|
244 | if(dd->custom_icon_in) |
---|
245 | g_free(dd->custom_icon_in); |
---|
246 | dd->custom_icon_in = temp; |
---|
247 | |
---|
248 | dd->device_pixmap = -1; |
---|
249 | redraw_pixmap(dd); |
---|
250 | panel_applet_gconf_set_string(PANEL_APPLET(dd->applet), "custom_icon_mounted", |
---|
251 | dd->custom_icon_in, NULL); |
---|
252 | |
---|
253 | } |
---|
254 | |
---|
255 | static void |
---|
256 | unmount_icon_changed (GnomeIconEntry *entry, gpointer data) |
---|
257 | { |
---|
258 | DriveData *dd = data; |
---|
259 | gchar *temp; |
---|
260 | |
---|
261 | temp = gnome_icon_entry_get_filename(entry); |
---|
262 | |
---|
263 | if (!temp) |
---|
264 | return; |
---|
265 | |
---|
266 | if(dd->custom_icon_out) |
---|
267 | g_free(dd->custom_icon_out); |
---|
268 | dd->custom_icon_out = temp; |
---|
269 | |
---|
270 | dd->device_pixmap = -1; |
---|
271 | redraw_pixmap(dd); |
---|
272 | panel_applet_gconf_set_string(PANEL_APPLET(dd->applet), "custom_icon_unmounted", |
---|
273 | dd->custom_icon_out, NULL); |
---|
274 | |
---|
275 | } |
---|
276 | |
---|
277 | static GtkWidget * |
---|
278 | create_hig_catagory (GtkWidget *main_box, gchar *title) |
---|
279 | { |
---|
280 | GtkWidget *vbox, *vbox2, *hbox; |
---|
281 | GtkWidget *label; |
---|
282 | gchar *tmp; |
---|
283 | |
---|
284 | vbox = gtk_vbox_new (FALSE, 6); |
---|
285 | gtk_box_pack_start (GTK_BOX (main_box), vbox, FALSE, FALSE, 0); |
---|
286 | |
---|
287 | tmp = g_strdup_printf ("<b>%s</b>", title); |
---|
288 | label = gtk_label_new (NULL); |
---|
289 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
---|
290 | gtk_label_set_markup (GTK_LABEL (label), tmp); |
---|
291 | g_free (tmp); |
---|
292 | gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, FALSE, 0); |
---|
293 | |
---|
294 | hbox = gtk_hbox_new (FALSE, 0); |
---|
295 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); |
---|
296 | |
---|
297 | label = gtk_label_new (" "); |
---|
298 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); |
---|
299 | |
---|
300 | vbox2 = gtk_vbox_new (FALSE, 6); |
---|
301 | gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0); |
---|
302 | |
---|
303 | return vbox2; |
---|
304 | |
---|
305 | } |
---|
306 | |
---|
307 | void |
---|
308 | properties_show (BonoboUIComponent *uic, |
---|
309 | DriveData *dd, |
---|
310 | const char *verb) |
---|
311 | { |
---|
312 | GtkWidget *dialog; |
---|
313 | GtkWidget *box; |
---|
314 | GtkWidget *frame; |
---|
315 | GtkWidget *hbox, *hbox2; |
---|
316 | GtkWidget *vbox, *vbox1; |
---|
317 | GtkWidget *fbox; |
---|
318 | GtkWidget *label; |
---|
319 | GtkWidget *menu; |
---|
320 | GtkWidget *item; |
---|
321 | GtkWidget *entry; |
---|
322 | ResponseWidgets *widgets; |
---|
323 | GtkSizeGroup *size; |
---|
324 | gint response; |
---|
325 | |
---|
326 | if (dd->prop_dialog != NULL) { |
---|
327 | gtk_window_set_screen (GTK_WINDOW (dd->prop_dialog), |
---|
328 | gtk_widget_get_screen (GTK_WIDGET (dd->applet))); |
---|
329 | |
---|
330 | gtk_window_present (GTK_WINDOW (dd->prop_dialog)); |
---|
331 | |
---|
332 | return; |
---|
333 | } |
---|
334 | |
---|
335 | widgets = g_new0(ResponseWidgets, 1); |
---|
336 | dialog = gtk_dialog_new_with_buttons(_("Disk Mounter Preferences"), NULL, |
---|
337 | GTK_DIALOG_DESTROY_WITH_PARENT, |
---|
338 | GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
---|
339 | GTK_STOCK_HELP, GTK_RESPONSE_HELP, |
---|
340 | NULL); |
---|
341 | gtk_window_set_screen (GTK_WINDOW (dialog), |
---|
342 | gtk_widget_get_screen (dd->applet)); |
---|
343 | gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); |
---|
344 | gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); |
---|
345 | gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); |
---|
346 | gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); |
---|
347 | |
---|
348 | box = GTK_DIALOG(dialog)->vbox; |
---|
349 | gtk_box_set_spacing (GTK_BOX (box), 2); |
---|
350 | |
---|
351 | size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); |
---|
352 | |
---|
353 | vbox = gtk_vbox_new(FALSE, 18); |
---|
354 | gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); |
---|
355 | gtk_box_pack_start (GTK_BOX (box), vbox, FALSE, FALSE, 0); |
---|
356 | gtk_widget_show(vbox); |
---|
357 | |
---|
358 | vbox1 = create_hig_catagory (vbox, _("General")); |
---|
359 | |
---|
360 | hbox = gtk_hbox_new(FALSE, 12); |
---|
361 | gtk_box_pack_start(GTK_BOX(vbox1), hbox, FALSE, FALSE, 0); |
---|
362 | gtk_widget_show(hbox); |
---|
363 | |
---|
364 | label = gtk_label_new_with_mnemonic(_("_Mount directory:")); |
---|
365 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
---|
366 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
---|
367 | gtk_widget_show(label); |
---|
368 | gtk_size_group_add_widget (size, label); |
---|
369 | |
---|
370 | widgets->mount_entry = gnome_file_entry_new ("drivemountentry", _("Select Mount Directory")); |
---|
371 | gtk_label_set_mnemonic_widget (GTK_LABEL (label), widgets->mount_entry); |
---|
372 | gnome_file_entry_set_filename (GNOME_FILE_ENTRY (widgets->mount_entry), |
---|
373 | dd->mount_point); |
---|
374 | gnome_file_entry_set_default_path (GNOME_FILE_ENTRY (widgets->mount_entry), "/mnt/"); |
---|
375 | gnome_file_entry_set_directory_entry(GNOME_FILE_ENTRY (widgets->mount_entry), TRUE); |
---|
376 | entry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (widgets->mount_entry)); |
---|
377 | gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE); |
---|
378 | gtk_box_pack_start(GTK_BOX(hbox), widgets->mount_entry , TRUE, TRUE, 0); |
---|
379 | gtk_widget_show(widgets->mount_entry); |
---|
380 | g_signal_connect (G_OBJECT (entry), "changed", |
---|
381 | G_CALLBACK (cb_mount_activate), dd); |
---|
382 | |
---|
383 | if ( ! key_writable (PANEL_APPLET (dd->applet), "mount_point")) { |
---|
384 | hard_set_sensitive (label, FALSE); |
---|
385 | hard_set_sensitive (widgets->mount_entry, FALSE); |
---|
386 | } |
---|
387 | |
---|
388 | hbox = gtk_hbox_new(FALSE, 12); |
---|
389 | gtk_box_pack_start(GTK_BOX(vbox1), hbox, FALSE, FALSE, 0); |
---|
390 | gtk_widget_show(hbox); |
---|
391 | |
---|
392 | label = gtk_label_new_with_mnemonic (_("_Update interval:")); |
---|
393 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
---|
394 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
---|
395 | gtk_widget_show(label); |
---|
396 | gtk_size_group_add_widget (size, label); |
---|
397 | |
---|
398 | hbox2 = gtk_hbox_new(FALSE, 6); |
---|
399 | gtk_box_pack_start(GTK_BOX(hbox), hbox2, FALSE, FALSE, 0); |
---|
400 | gtk_widget_show(hbox2); |
---|
401 | |
---|
402 | widgets->update_spin = gtk_spin_button_new(GTK_ADJUSTMENT(gtk_adjustment_new(dd->interval, 1.0, 300.0, 5, 1, 1)), 1, 0); |
---|
403 | gtk_label_set_mnemonic_widget (GTK_LABEL (label), widgets->update_spin); |
---|
404 | gtk_box_pack_start(GTK_BOX(hbox2), widgets->update_spin, FALSE, FALSE, 0); |
---|
405 | gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(widgets->update_spin),GTK_UPDATE_ALWAYS); |
---|
406 | gtk_widget_show(widgets->update_spin); |
---|
407 | g_signal_connect (G_OBJECT (widgets->update_spin), "focus_out_event", |
---|
408 | G_CALLBACK (spin_changed), dd); |
---|
409 | |
---|
410 | if ( ! key_writable (PANEL_APPLET (dd->applet), "interval")) { |
---|
411 | hard_set_sensitive (label, FALSE); |
---|
412 | hard_set_sensitive (widgets->update_spin, FALSE); |
---|
413 | } |
---|
414 | |
---|
415 | label = gtk_label_new_with_mnemonic (_("seconds")); |
---|
416 | gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0); |
---|
417 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
---|
418 | gtk_widget_show (label); |
---|
419 | |
---|
420 | if ( ! key_writable (PANEL_APPLET (dd->applet), "interval")) { |
---|
421 | hard_set_sensitive (label, FALSE); |
---|
422 | } |
---|
423 | |
---|
424 | hbox = gtk_hbox_new(FALSE, 12); |
---|
425 | gtk_box_pack_start(GTK_BOX(vbox1), hbox, FALSE, FALSE, 0); |
---|
426 | gtk_widget_show(hbox); |
---|
427 | |
---|
428 | label = gtk_label_new_with_mnemonic(_("_Icon:")); |
---|
429 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
---|
430 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
---|
431 | gtk_widget_show(label); |
---|
432 | gtk_size_group_add_widget (size, label); |
---|
433 | |
---|
434 | widgets->omenu = gtk_option_menu_new (); |
---|
435 | gtk_label_set_mnemonic_widget (GTK_LABEL (label), widgets->omenu); |
---|
436 | gtk_box_pack_start(GTK_BOX(hbox), widgets->omenu, TRUE, TRUE, 0); |
---|
437 | gtk_widget_show(widgets->omenu); |
---|
438 | menu = gtk_menu_new(); |
---|
439 | gtk_option_menu_set_menu(GTK_OPTION_MENU(widgets->omenu), menu); |
---|
440 | |
---|
441 | if ( ! key_writable (PANEL_APPLET (dd->applet), "pixmap")) { |
---|
442 | hard_set_sensitive (label, FALSE); |
---|
443 | hard_set_sensitive (widgets->omenu, FALSE); |
---|
444 | } else { |
---|
445 | g_signal_connect (G_OBJECT (widgets->omenu), "changed", |
---|
446 | G_CALLBACK (omenu_changed), dd); |
---|
447 | } |
---|
448 | |
---|
449 | /* This must be created before the menu items, so we can pass it to a callback */ |
---|
450 | fbox = gtk_vbox_new(FALSE, GNOME_PAD_SMALL); |
---|
451 | gtk_box_pack_start(GTK_BOX(vbox1), fbox, FALSE, FALSE, 0); |
---|
452 | gtk_widget_show(fbox); |
---|
453 | |
---|
454 | item = gtk_menu_item_new_with_label(_("Floppy")); |
---|
455 | gtk_menu_append (GTK_MENU (menu), item); |
---|
456 | g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(set_widget_sensitivity_false_cb), fbox); |
---|
457 | item = gtk_menu_item_new_with_label(_("CD-ROM")); |
---|
458 | gtk_menu_append (GTK_MENU (menu), item); |
---|
459 | g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(set_widget_sensitivity_false_cb), fbox); |
---|
460 | item = gtk_menu_item_new_with_label(_("CD Recorder")); |
---|
461 | gtk_menu_append (GTK_MENU (menu), item); |
---|
462 | g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(set_widget_sensitivity_false_cb), fbox); |
---|
463 | item = gtk_menu_item_new_with_label(_("Zip Drive")); |
---|
464 | gtk_menu_append (GTK_MENU (menu), item); |
---|
465 | g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(set_widget_sensitivity_false_cb), fbox); |
---|
466 | item = gtk_menu_item_new_with_label(_("Hard Disk")); |
---|
467 | gtk_menu_append (GTK_MENU (menu), item); |
---|
468 | g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(set_widget_sensitivity_false_cb), fbox); |
---|
469 | item = gtk_menu_item_new_with_label(_("Jaz Drive")); |
---|
470 | gtk_menu_append (GTK_MENU (menu), item); |
---|
471 | g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(set_widget_sensitivity_false_cb), fbox); |
---|
472 | item = gtk_menu_item_new_with_label(_("USB Stick")); |
---|
473 | gtk_menu_append (GTK_MENU (menu), item); |
---|
474 | g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(set_widget_sensitivity_false_cb), fbox); |
---|
475 | item = gtk_menu_item_new_with_label(_("Custom")); |
---|
476 | gtk_menu_append (GTK_MENU (menu), item); |
---|
477 | g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(set_widget_sensitivity_true_cb), fbox); |
---|
478 | |
---|
479 | if (dd->device_pixmap == -1) |
---|
480 | gtk_option_menu_set_history(GTK_OPTION_MENU(widgets->omenu), icon_list_count); |
---|
481 | else |
---|
482 | gtk_option_menu_set_history(GTK_OPTION_MENU(widgets->omenu), dd->device_pixmap); |
---|
483 | |
---|
484 | hbox = gtk_hbox_new(FALSE, 12); |
---|
485 | gtk_box_pack_start(GTK_BOX(fbox), hbox, FALSE, FALSE, 0); |
---|
486 | gtk_widget_show(hbox); |
---|
487 | |
---|
488 | label = gtk_label_new_with_mnemonic(NULL); |
---|
489 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
---|
490 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
---|
491 | gtk_widget_show(label); |
---|
492 | gtk_size_group_add_widget (size, label); |
---|
493 | |
---|
494 | widgets->icon_entry_in = gnome_icon_entry_new("drivemount-applet-id-in", _("Select icon for mounted")); |
---|
495 | gnome_icon_entry_set_filename(GNOME_ICON_ENTRY(widgets->icon_entry_in), dd->custom_icon_in); |
---|
496 | gtk_box_pack_end(GTK_BOX(hbox), widgets->icon_entry_in, FALSE, FALSE, 0); |
---|
497 | gtk_widget_show(widgets->icon_entry_in); |
---|
498 | g_signal_connect (G_OBJECT (widgets->icon_entry_in), "changed", |
---|
499 | G_CALLBACK (mount_icon_changed), dd); |
---|
500 | |
---|
501 | label = gtk_label_new_with_mnemonic(_("Moun_ted icon:")); |
---|
502 | gtk_label_set_mnemonic_widget (GTK_LABEL (label), widgets->icon_entry_in); |
---|
503 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
---|
504 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
---|
505 | gtk_widget_show(label); |
---|
506 | |
---|
507 | if ( ! key_writable (PANEL_APPLET (dd->applet), "custom_icon_mounted")) { |
---|
508 | hard_set_sensitive (label, FALSE); |
---|
509 | hard_set_sensitive (widgets->icon_entry_in, FALSE); |
---|
510 | } |
---|
511 | |
---|
512 | hbox = gtk_hbox_new(FALSE, 12); |
---|
513 | gtk_box_pack_start(GTK_BOX(fbox), hbox, FALSE, FALSE, 0); |
---|
514 | gtk_widget_show(hbox); |
---|
515 | |
---|
516 | label = gtk_label_new_with_mnemonic(NULL); |
---|
517 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
---|
518 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
---|
519 | gtk_widget_show(label); |
---|
520 | gtk_size_group_add_widget (size, label); |
---|
521 | |
---|
522 | widgets->icon_entry_out = gnome_icon_entry_new("drivemount-applet-id-out", _("Select icon for unmounted")); |
---|
523 | gnome_icon_entry_set_filename(GNOME_ICON_ENTRY(widgets->icon_entry_out), dd->custom_icon_out); |
---|
524 | gtk_box_pack_end(GTK_BOX(hbox), widgets->icon_entry_out, FALSE, FALSE, 0); |
---|
525 | gtk_widget_show(widgets->icon_entry_out); |
---|
526 | g_signal_connect (G_OBJECT (widgets->icon_entry_out), "changed", |
---|
527 | G_CALLBACK (unmount_icon_changed), dd); |
---|
528 | |
---|
529 | label = gtk_label_new_with_mnemonic(_("Unmou_nted icon:")); |
---|
530 | gtk_label_set_mnemonic_widget (GTK_LABEL (label), widgets->icon_entry_out); |
---|
531 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
---|
532 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
---|
533 | gtk_widget_show(label); |
---|
534 | |
---|
535 | if ( ! key_writable (PANEL_APPLET (dd->applet), "custom_icon_unmounted")) { |
---|
536 | hard_set_sensitive (label, FALSE); |
---|
537 | hard_set_sensitive (widgets->icon_entry_out, FALSE); |
---|
538 | } |
---|
539 | |
---|
540 | if(dd->device_pixmap < 0) |
---|
541 | soft_set_sensitive(fbox, TRUE); |
---|
542 | else |
---|
543 | soft_set_sensitive(fbox, FALSE); |
---|
544 | #if 0 |
---|
545 | widgets->scale_toggle = gtk_check_button_new_with_mnemonic (_("_Scale size to panel")); |
---|
546 | gtk_box_pack_start(GTK_BOX(vbox1), widgets->scale_toggle, FALSE, FALSE, 0); |
---|
547 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->scale_toggle), dd->scale_applet); |
---|
548 | gtk_widget_show(widgets->scale_toggle); |
---|
549 | g_signal_connect (G_OBJECT (widgets->scale_toggle), "toggled", |
---|
550 | G_CALLBACK (scale_toggled), dd); |
---|
551 | #endif |
---|
552 | widgets->eject_toggle = gtk_check_button_new_with_mnemonic (_("_Eject disk when unmounted")); |
---|
553 | gtk_box_pack_start(GTK_BOX(vbox1), widgets->eject_toggle, FALSE, FALSE, 0); |
---|
554 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->eject_toggle), dd->auto_eject); |
---|
555 | gtk_widget_show(widgets->eject_toggle); |
---|
556 | g_signal_connect (G_OBJECT (widgets->eject_toggle), "toggled", |
---|
557 | G_CALLBACK (eject_toggled), dd); |
---|
558 | |
---|
559 | if ( ! key_writable (PANEL_APPLET (dd->applet), "auto_eject")) |
---|
560 | hard_set_sensitive (widgets->eject_toggle, FALSE); |
---|
561 | |
---|
562 | widgets->automount_toggle = gtk_check_button_new_with_mnemonic (_("Use _automount-friendly status test")); |
---|
563 | gtk_box_pack_start(GTK_BOX(vbox1), widgets->automount_toggle, FALSE, FALSE, 0); |
---|
564 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->automount_toggle), dd->autofs_friendly); |
---|
565 | gtk_widget_show(widgets->automount_toggle); |
---|
566 | g_signal_connect (G_OBJECT (widgets->automount_toggle), "toggled", |
---|
567 | G_CALLBACK (automount_toggled), dd); |
---|
568 | gtk_widget_show_all(vbox); |
---|
569 | |
---|
570 | if ( ! key_writable (PANEL_APPLET (dd->applet), "autofs_friendly")) |
---|
571 | hard_set_sensitive (widgets->automount_toggle, FALSE); |
---|
572 | |
---|
573 | widgets->dd = dd; |
---|
574 | g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(handle_response_cb), widgets); |
---|
575 | |
---|
576 | dd->prop_dialog = dialog; |
---|
577 | |
---|
578 | gtk_widget_show_all(dialog); |
---|
579 | } |
---|
580 | |
---|
581 | static void |
---|
582 | help_cb (GtkDialog *dialog) |
---|
583 | { |
---|
584 | GError *error = NULL; |
---|
585 | static GnomeProgram *applet_program = NULL; |
---|
586 | |
---|
587 | if (!applet_program) { |
---|
588 | int argc = 1; |
---|
589 | char *argv[2] = { "drivemount" }; |
---|
590 | applet_program = gnome_program_init ("drivemount", VERSION, |
---|
591 | LIBGNOME_MODULE, argc, argv, |
---|
592 | GNOME_PROGRAM_STANDARD_PROPERTIES, NULL); |
---|
593 | } |
---|
594 | |
---|
595 | gnome_help_display_desktop_on_screen ( |
---|
596 | applet_program, "drivemount", "drivemount", "drivemountapplet-prefs", |
---|
597 | gtk_widget_get_screen (GTK_WIDGET (dialog)), |
---|
598 | &error); |
---|
599 | |
---|
600 | if (error) { |
---|
601 | GtkWidget *error_dialog; |
---|
602 | char *msg; |
---|
603 | |
---|
604 | msg = g_strdup_printf (_("There was an error displaying help: %s"), |
---|
605 | error->message); |
---|
606 | error_dialog = hig_dialog_new (NULL /* parent */, |
---|
607 | GTK_DIALOG_DESTROY_WITH_PARENT, |
---|
608 | GTK_MESSAGE_ERROR, |
---|
609 | GTK_BUTTONS_OK, |
---|
610 | _("Error displaying help"), |
---|
611 | msg); |
---|
612 | g_free (msg); |
---|
613 | |
---|
614 | g_signal_connect (error_dialog, "response", |
---|
615 | G_CALLBACK (gtk_widget_destroy), |
---|
616 | NULL); |
---|
617 | |
---|
618 | gtk_window_set_resizable (GTK_WINDOW (error_dialog), FALSE); |
---|
619 | gtk_window_set_screen (GTK_WINDOW (error_dialog), |
---|
620 | gtk_widget_get_screen (GTK_WIDGET (dialog))); |
---|
621 | gtk_widget_show (error_dialog); |
---|
622 | g_error_free (error); |
---|
623 | } |
---|
624 | } |
---|
625 | |
---|
626 | static void |
---|
627 | handle_response_cb(GtkDialog *dialog, gint response, ResponseWidgets *widgets) |
---|
628 | { |
---|
629 | if (response == GTK_RESPONSE_HELP) { |
---|
630 | help_cb (dialog); |
---|
631 | return; |
---|
632 | } |
---|
633 | |
---|
634 | gtk_widget_destroy(GTK_WIDGET(dialog)); |
---|
635 | |
---|
636 | widgets->dd->prop_dialog = NULL; |
---|
637 | |
---|
638 | g_free(widgets); |
---|
639 | } |
---|
640 | |
---|
641 | static void |
---|
642 | set_widget_sensitivity_false_cb(GtkWidget *widget, GtkWidget *target) |
---|
643 | { |
---|
644 | soft_set_sensitive(target, FALSE); |
---|
645 | } |
---|
646 | |
---|
647 | static void |
---|
648 | set_widget_sensitivity_true_cb(GtkWidget *widget, GtkWidget *target) |
---|
649 | { |
---|
650 | soft_set_sensitive(target, TRUE); |
---|
651 | } |
---|
652 | |
---|
653 | static gchar * |
---|
654 | remove_level_from_path(const gchar *path) |
---|
655 | { |
---|
656 | gchar *new_path; |
---|
657 | const gchar *ptr; |
---|
658 | gint p; |
---|
659 | |
---|
660 | if (!path) return NULL; |
---|
661 | |
---|
662 | p = strlen(path) - 1; |
---|
663 | if (p < 0) return NULL; |
---|
664 | |
---|
665 | ptr = path; |
---|
666 | while(ptr[p] != '/' && p > 0) p--; |
---|
667 | |
---|
668 | if (p == 0 && ptr[p] == '/') p++; |
---|
669 | new_path = g_strndup(path, (guint)p); |
---|
670 | return new_path; |
---|
671 | } |
---|
672 | |
---|
673 | static void |
---|
674 | sync_mount_base(DriveData *dd) |
---|
675 | { |
---|
676 | g_free(dd->mount_base); |
---|
677 | dd->mount_base = remove_level_from_path(dd->mount_point); |
---|
678 | } |
---|