]> git.sur5r.net Git - glabels/blob - glabels2/src/ui.c
Added FileProperties dialog.
[glabels] / glabels2 / src / ui.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  ui.c:  GLabels ui module
5  *
6  *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (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 USA
21  */
22 #include <config.h>
23
24 #include "gnome-recent-view.h"
25 #include <gconf/gconf-client.h>
26
27 #include "ui.h"
28 #include "commands.h"
29 #include "tools.h"
30 #include "recent.h" 
31 #include "file.h"
32 #include "prefs.h"
33
34 #include "debug.h"
35
36 /*==========================================================================*/
37 /* Private macros and constants.                                            */
38 /*==========================================================================*/
39 #define GLABELS_UI_XML GLABELS_UI_DIR "glabels-ui.xml"
40
41 /*==========================================================================*/
42 /* Private types.                                                           */
43 /*==========================================================================*/
44
45
46 /*==========================================================================*/
47 /* Private globals                                                          */
48 /*==========================================================================*/
49
50 static BonoboUIVerb gl_ui_verbs [] = {
51         BONOBO_UI_VERB ("FileNew",               gl_cmd_file_new),
52         BONOBO_UI_VERB ("FileProperties",        gl_cmd_file_properties),
53         BONOBO_UI_VERB ("FileOpen",              gl_cmd_file_open),
54         BONOBO_UI_VERB ("FileSave",              gl_cmd_file_save),
55         BONOBO_UI_VERB ("FileSaveAs",            gl_cmd_file_save_as),
56         BONOBO_UI_VERB ("FilePrint",             gl_cmd_file_print),
57         BONOBO_UI_VERB ("FileClose",             gl_cmd_file_close),
58         BONOBO_UI_VERB ("FileExit",              gl_cmd_file_exit),
59         BONOBO_UI_VERB ("EditCut",               gl_cmd_edit_cut),
60         BONOBO_UI_VERB ("EditCopy",              gl_cmd_edit_copy),
61         BONOBO_UI_VERB ("EditPaste",             gl_cmd_edit_paste),
62         BONOBO_UI_VERB ("EditDelete",            gl_cmd_edit_delete),
63         BONOBO_UI_VERB ("EditSelectAll",         gl_cmd_edit_select_all),
64         BONOBO_UI_VERB ("EditUnSelectAll",       gl_cmd_edit_unselect_all),
65         BONOBO_UI_VERB ("ToolsArrow",            gl_tools_arrow),
66         BONOBO_UI_VERB ("ToolsText",             gl_tools_text),
67         BONOBO_UI_VERB ("ToolsBox",              gl_tools_box),
68         BONOBO_UI_VERB ("ToolsLine",             gl_tools_line),
69         BONOBO_UI_VERB ("ToolsEllipse",          gl_tools_ellipse),
70         BONOBO_UI_VERB ("ToolsImage",            gl_tools_image),
71         BONOBO_UI_VERB ("ToolsBarcode",          gl_tools_barcode),
72         BONOBO_UI_VERB ("ToolsZoomIn",           gl_tools_zoomin),
73         BONOBO_UI_VERB ("ToolsZoomOut",          gl_tools_zoomout),
74         BONOBO_UI_VERB ("ToolsZoom1to1",         gl_tools_zoom1to1),
75         BONOBO_UI_VERB ("ToolsMergeProperties",  gl_tools_merge_properties),
76         BONOBO_UI_VERB ("ToolsObjectProperties", gl_tools_object_properties),
77         BONOBO_UI_VERB ("ToolsRaiseObjects",     gl_tools_raise_objects),
78         BONOBO_UI_VERB ("ToolsLowerObjects",     gl_tools_lower_objects),
79         BONOBO_UI_VERB ("ToolsRotateLeft",       gl_tools_rotate_objects_left),
80         BONOBO_UI_VERB ("ToolsRotateRight",      gl_tools_rotate_objects_right),
81         BONOBO_UI_VERB ("ToolsFlipHorizontal",   gl_tools_flip_objects_horiz),
82         BONOBO_UI_VERB ("ToolsFlipVertical",     gl_tools_flip_objects_vert),
83         BONOBO_UI_VERB ("ToolsAlignLeft",        gl_tools_align_objects_left),
84         BONOBO_UI_VERB ("ToolsAlignRight",       gl_tools_align_objects_right),
85         BONOBO_UI_VERB ("ToolsAlignHCenter",     gl_tools_align_objects_hcenter),
86         BONOBO_UI_VERB ("ToolsAlignTop",         gl_tools_align_objects_top),
87         BONOBO_UI_VERB ("ToolsAlignBottom",      gl_tools_align_objects_bottom),
88         BONOBO_UI_VERB ("ToolsAlignVCenter",     gl_tools_align_objects_vcenter),
89         BONOBO_UI_VERB ("ToolsCenterHorizontal", gl_tools_center_objects_horiz),
90         BONOBO_UI_VERB ("ToolsCenterVertical",   gl_tools_center_objects_vert),
91         BONOBO_UI_VERB ("SettingsPreferences",   gl_cmd_settings_preferences),
92         BONOBO_UI_VERB ("HelpContents",          gl_cmd_help_contents),
93         BONOBO_UI_VERB ("About",                 gl_cmd_help_about),
94
95         BONOBO_UI_VERB_END
96 };
97
98 static gchar* doc_verbs [] = {
99         "/commands/FileProperties",
100         "/commands/FileSave",
101         "/commands/FileSaveAs",
102         "/commands/FilePrint",
103         "/commands/FilePrintPreview",
104         "/commands/FileClose",
105         "/commands/FileCloseAll",
106         "/commands/EditUndo",
107         "/commands/EditRedo",
108         "/commands/EditCut",
109         "/commands/EditCopy",
110         "/commands/EditPaste",
111         "/commands/EditDelete",
112         "/commands/EditSelectAll",
113         "/commands/EditUnSelectAll",
114         "/commands/ToolsArrow",
115         "/commands/ToolsText",
116         "/commands/ToolsLine",
117         "/commands/ToolsBox",
118         "/commands/ToolsEllipse",
119         "/commands/ToolsImage",
120         "/commands/ToolsBarcode",
121         "/commands/ToolsZoomIn",
122         "/commands/ToolsZoomOut",
123         "/commands/ToolsZoom1to1",
124         "/commands/ToolsMergeProperties",
125         "/commands/ToolsObjectProperties",
126         "/commands/ToolsRaiseObjects",
127         "/commands/ToolsLowerObjects",
128         "/commands/ToolsRotateLeft",
129         "/commands/ToolsRotateRight",
130         "/commands/ToolsFlipHorizontal",
131         "/commands/ToolsFlipVertical",
132         "/commands/ToolsAlignLeft",
133         "/commands/ToolsAlignRight",
134         "/commands/ToolsAlignHCenter",
135         "/commands/ToolsAlignTop",
136         "/commands/ToolsAlignBottom",
137         "/commands/ToolsAlignVCenter",
138         "/commands/ToolsCenterHorizontal",
139         "/commands/ToolsCenterVertical",
140         "/menu/Objects/CreateObjects",
141         "/menu/Objects/Order",
142         "/menu/Objects/RotateFlip",
143         "/menu/Objects/AlignHoriz",
144         "/menu/Objects/AlignVert",
145         "/commands/ViewGrid",
146         "/commands/ViewMarkup",
147
148         NULL
149 };
150
151 static gchar* doc_modified_verbs [] = {
152         "/commands/FileSave",
153
154         NULL
155 };
156
157 static gchar* selection_verbs [] = {
158         "/commands/EditCut",
159         "/commands/EditCopy",
160         "/commands/EditDelete",
161         "/commands/EditUnSelectAll",
162         "/commands/ToolsRaiseObjects",
163         "/commands/ToolsLowerObjects",
164         "/commands/ToolsRotateLeft",
165         "/commands/ToolsRotateRight",
166         "/commands/ToolsFlipHorizontal",
167         "/commands/ToolsFlipVertical",
168         "/commands/ToolsCenterHorizontal",
169         "/commands/ToolsCenterVertical",
170         "/menu/Objects/Order",
171         "/menu/Objects/RotateFlip",
172         "/menu/Objects/AlignHoriz",
173         "/menu/Objects/AlignVert",
174
175         NULL
176 };
177
178 static gchar* atomic_selection_verbs [] = {
179         "/commands/ToolsObjectProperties",
180
181         NULL
182 };
183
184 static gchar* multi_selection_verbs [] = {
185         "/commands/ToolsAlignLeft",
186         "/commands/ToolsAlignRight",
187         "/commands/ToolsAlignHCenter",
188         "/commands/ToolsAlignTop",
189         "/commands/ToolsAlignBottom",
190         "/commands/ToolsAlignVCenter",
191
192         NULL
193 };
194
195
196 /*==========================================================================*/
197 /* Local function prototypes                                                */
198 /*==========================================================================*/
199
200 static void view_menu_item_toggled_cb     (BonoboUIComponent           *ui_component,
201                                            const char                  *path,
202                                            Bonobo_UIComponent_EventType type,
203                                            const char                  *state,
204                                            BonoboWindow                *win);
205
206 static void set_app_main_toolbar_style    (BonoboUIComponent           *ui_component);
207
208 static void set_app_drawing_toolbar_style (BonoboUIComponent           *ui_component);
209
210 static void set_view_style                (BonoboUIComponent           *ui_component);
211
212 static void set_verb_sensitive            (BonoboUIComponent           *ui_component,
213                                            gchar                       *cname,
214                                            gboolean                     sensitive);
215
216 static void set_verb_list_sensitive       (BonoboUIComponent           *ui_component,
217                                            gchar                      **vlist,
218                                            gboolean                     sensitive);
219
220 static void set_verb_state                (BonoboUIComponent           *ui_component,
221                                            gchar                       *cname,
222                                            gboolean                     state);
223
224
225 \f
226 /*****************************************************************************/
227 /* Initialize UI component for given window.                                 */
228 /*****************************************************************************/
229 void
230 gl_ui_init (BonoboUIComponent *ui_component,
231             BonoboWindow      *win,
232             GtkWidget         *cursor_info_frame,
233             GtkWidget         *zoom_info_frame)
234 {
235         GnomeRecentView  *recent_view;
236         GnomeRecentModel *recent_model;
237         BonoboControl    *control;
238
239         gl_debug (DEBUG_UI, "START");
240
241         gl_debug (DEBUG_UI, "window = %p", win);
242
243         g_return_if_fail (ui_component != NULL);
244
245         bonobo_ui_engine_config_set_path (bonobo_window_get_ui_engine (win),
246                                           "/glabels/UIConfig/kvps");
247         gl_debug (DEBUG_UI, "Path set");
248
249         bonobo_ui_util_set_ui (ui_component,
250                                "", GLABELS_UI_XML, "gLabels", NULL);
251         gl_debug (DEBUG_UI, "UI set");
252
253         bonobo_ui_component_add_verb_list_with_data(ui_component,
254                                                     gl_ui_verbs, win);
255         gl_debug (DEBUG_UI, "verb list added");
256
257         /* Set the toolbar style according to prefs */
258         set_app_main_toolbar_style (ui_component);
259                 
260         /* Add listener for the view menu */
261         bonobo_ui_component_add_listener (ui_component, "ViewMainToolbar", 
262                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
263                         (gpointer)win);
264
265         bonobo_ui_component_add_listener (ui_component, "MainToolbarSystem", 
266                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
267                         (gpointer)win);
268         bonobo_ui_component_add_listener (ui_component, "MainToolbarIcon", 
269                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
270                         (gpointer)win);
271         bonobo_ui_component_add_listener (ui_component, "MainToolbarIconText", 
272                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
273                         (gpointer)win);
274         bonobo_ui_component_add_listener (ui_component, "MainToolbarTooltips", 
275                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
276                         (gpointer)win);
277
278         /* Set the toolbar style according to prefs */
279         set_app_drawing_toolbar_style (ui_component);
280                 
281         /* Add listener for the view menu */
282         bonobo_ui_component_add_listener (ui_component, "ViewDrawingToolbar", 
283                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
284                         (gpointer)win);
285
286         bonobo_ui_component_add_listener (ui_component, "DrawingToolbarSystem", 
287                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
288                         (gpointer)win);
289         bonobo_ui_component_add_listener (ui_component, "DrawingToolbarIcon", 
290                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
291                         (gpointer)win);
292         bonobo_ui_component_add_listener (ui_component, "DrawingToolbarIconText", 
293                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
294                         (gpointer)win);
295         bonobo_ui_component_add_listener (ui_component, "DrawingToolbarTooltips", 
296                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
297                         (gpointer)win);
298
299
300         /* Set view grid and markup visibility according to prefs */
301         set_view_style (ui_component);
302                 
303         /* Add listener for the view grid & markup */
304         bonobo_ui_component_add_listener (ui_component, "ViewGrid", 
305                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
306                         (gpointer)win);
307         bonobo_ui_component_add_listener (ui_component, "ViewMarkup", 
308                         (BonoboUIListenerFn)view_menu_item_toggled_cb, 
309                         (gpointer)win);
310
311         set_verb_list_sensitive (ui_component, doc_verbs, FALSE);
312
313         /* Status bar */
314         bonobo_ui_component_set_prop (ui_component,
315                                       "/status", "hidden", "0", NULL);
316
317         control = bonobo_control_new (cursor_info_frame);
318         bonobo_ui_component_object_set (ui_component,
319                                         "/status/Cursor", BONOBO_OBJREF (control), NULL);
320         bonobo_object_unref (BONOBO_OBJECT (control));
321         bonobo_ui_component_set_prop (ui_component,
322                                       "/status/Cursor", "hidden", "0", NULL);
323
324         control = bonobo_control_new (zoom_info_frame);
325         bonobo_ui_component_object_set (ui_component,
326                                         "/status/Zoom", BONOBO_OBJREF (control), NULL);
327         bonobo_object_unref (BONOBO_OBJECT (control));
328         bonobo_ui_component_set_prop (ui_component,
329                                       "/status/Zoom", "hidden", "0", NULL);
330
331
332         /* add a GeditRecentView object */
333         recent_model = gl_recent_get_model ();
334         recent_view  =
335                 GNOME_RECENT_VIEW (gnome_recent_view_bonobo_new (ui_component,
336                                                                  "/menu/File/Recents"));
337         gnome_recent_view_set_model (recent_view, recent_model);
338         
339         g_signal_connect (G_OBJECT (recent_view), "activate",
340                           G_CALLBACK (gl_file_open_recent), win);
341
342         gl_debug (DEBUG_UI, "END");
343 }
344
345 /*****************************************************************************/
346 /* Update all verbs of given UI component.                                   */
347 /*****************************************************************************/
348 void
349 gl_ui_update_all (BonoboUIComponent *ui_component,
350                   glView            *view)
351 {
352         glLabel *label;
353
354         gl_debug (DEBUG_UI, "START");
355
356         bonobo_ui_component_freeze (ui_component, NULL);
357
358         set_verb_list_sensitive (ui_component, doc_verbs, TRUE);
359
360         label = view->label;
361         g_return_if_fail (label != NULL);
362
363         set_verb_sensitive (ui_component, "/commands/EditUndo",
364                             gl_label_can_undo (label));
365         set_verb_sensitive (ui_component, "/commands/EditRedo",
366                             gl_label_can_redo (label));
367
368         set_verb_list_sensitive (ui_component, 
369                                  doc_modified_verbs,
370                                  gl_label_is_modified (label));
371
372         set_verb_sensitive (ui_component, "/commands/ToolsZoomIn",
373                             !gl_view_is_zoom_max (view));
374         set_verb_sensitive (ui_component, "/commands/ToolsZoomOut",
375                             !gl_view_is_zoom_min (view));
376
377         set_verb_list_sensitive (ui_component,
378                                  selection_verbs,
379                                  !gl_view_is_selection_empty (view));
380
381         set_verb_list_sensitive (ui_component,
382                                  atomic_selection_verbs,
383                                  gl_view_is_selection_atomic (view));
384
385         set_verb_list_sensitive (ui_component,
386                                  multi_selection_verbs,
387                                  !gl_view_is_selection_empty (view)
388                                  && !gl_view_is_selection_atomic (view));
389
390         bonobo_ui_component_thaw (ui_component, NULL);
391
392         gl_debug (DEBUG_UI, "END");
393 }
394
395 /*****************************************************************************/
396 /* Update all verbs of given UI component to "no document" state.            */
397 /*****************************************************************************/
398 void
399 gl_ui_update_nodoc (BonoboUIComponent *ui_component)
400 {
401         gl_debug (DEBUG_UI, "START");
402
403         bonobo_ui_component_freeze (ui_component, NULL);
404         
405         set_verb_list_sensitive (ui_component, doc_verbs, FALSE);
406
407         bonobo_ui_component_thaw (ui_component, NULL);
408
409         gl_debug (DEBUG_UI, "END");
410 }
411
412 /*****************************************************************************/
413 /* Update label modified verbs of given UI component.                        */
414 /*****************************************************************************/
415 void
416 gl_ui_update_modified_verbs (BonoboUIComponent *ui_component,
417                              glLabel           *label)
418 {
419         gl_debug (DEBUG_UI, "START");
420
421         bonobo_ui_component_freeze (ui_component, NULL);
422
423         set_verb_list_sensitive (ui_component, 
424                                  doc_modified_verbs,
425                                  gl_label_is_modified (label));
426
427         bonobo_ui_component_thaw (ui_component, NULL);
428
429         gl_debug (DEBUG_UI, "END");
430 }
431
432 /*****************************************************************************/
433 /* Update verbs associated with selection state of given UI component.       */
434 /*****************************************************************************/
435 void
436 gl_ui_update_selection_verbs (BonoboUIComponent *ui_component,
437                               glView            *view)
438 {
439         gl_debug (DEBUG_UI, "START");
440
441         bonobo_ui_component_freeze (ui_component, NULL);
442
443         set_verb_list_sensitive (ui_component,
444                                  selection_verbs,
445                                  !gl_view_is_selection_empty (view));
446
447         set_verb_list_sensitive (ui_component,
448                                  atomic_selection_verbs,
449                                  gl_view_is_selection_atomic (view));
450
451         set_verb_list_sensitive (ui_component,
452                                  multi_selection_verbs,
453                                  !gl_view_is_selection_empty (view)
454                                  && !gl_view_is_selection_atomic (view));
455
456         bonobo_ui_component_thaw (ui_component, NULL);
457
458         gl_debug (DEBUG_UI, "END");
459 }
460
461 /*****************************************************************************/
462 /* Update verbs associated with zoom level of given UI component.            */
463 /*****************************************************************************/
464 void
465 gl_ui_update_zoom_verbs (BonoboUIComponent *ui_component,
466                          glView            *view)
467 {
468         gl_debug (DEBUG_UI, "START");
469
470         bonobo_ui_component_freeze (ui_component, NULL);
471
472         set_verb_sensitive (ui_component, "/commands/ToolsZoomIn",
473                             !gl_view_is_zoom_max (view));
474         set_verb_sensitive (ui_component, "/commands/ToolsZoomOut",
475                             !gl_view_is_zoom_min (view));
476
477         bonobo_ui_component_thaw (ui_component, NULL);
478
479         gl_debug (DEBUG_UI, "END");
480 }
481
482 /*****************************************************************************/
483 /* Update undo/redo verbs of given UI component.                             */
484 /*****************************************************************************/
485 void
486 gl_ui_update_undo_redo_verbs (BonoboUIComponent *ui_component,
487                               glLabel           *label)
488 {
489         gl_debug (DEBUG_UI, "START");
490
491         bonobo_ui_component_freeze (ui_component, NULL);
492
493         set_verb_sensitive (ui_component,
494                             "/commands/EditUndo", gl_label_can_undo (label));
495
496         set_verb_sensitive (ui_component,
497                             "/commands/EditRedo", gl_label_can_redo (label));
498
499         bonobo_ui_component_thaw (ui_component, NULL);
500
501         gl_debug (DEBUG_UI, "END");
502 }
503
504 /*---------------------------------------------------------------------------*/
505 /* PRIVATE.  View menu item toggled callback.                                */
506 /*---------------------------------------------------------------------------*/
507 static void
508 view_menu_item_toggled_cb (BonoboUIComponent           *ui_component,
509                            const char                  *path,
510                            Bonobo_UIComponent_EventType type,
511                            const char                  *state,
512                            BonoboWindow                *win)
513 {
514         gboolean s;
515
516         gl_debug (DEBUG_UI, "");
517
518         s = (strcmp (state, "1") == 0);
519
520         if (strcmp (path, "ViewMainToolbar") == 0)
521         {
522                 gl_prefs->main_toolbar_visible = s;
523                 set_app_main_toolbar_style (ui_component);
524                 gl_prefs_save_settings ();
525
526                 return;
527         }
528
529         if (s && (strcmp (path, "MainToolbarSystem") == 0))
530         {               
531                 gl_prefs->main_toolbar_buttons_style = GL_TOOLBAR_SYSTEM;
532                 set_app_main_toolbar_style (ui_component);
533                 gl_prefs_save_settings ();
534
535                 return;
536         }
537
538         if (s && (strcmp (path, "MainToolbarIcon") == 0))
539         {               
540                 gl_prefs->main_toolbar_buttons_style = GL_TOOLBAR_ICONS;
541                 set_app_main_toolbar_style (ui_component);
542                 gl_prefs_save_settings ();
543
544                 return;
545         }
546
547         if (s && (strcmp (path, "MainToolbarIconText") == 0))
548         {               
549                 gl_prefs->main_toolbar_buttons_style = GL_TOOLBAR_ICONS_AND_TEXT;
550                 set_app_main_toolbar_style (ui_component);
551                 gl_prefs_save_settings ();
552
553                 return;
554         }
555
556         if (strcmp (path, "MainToolbarTooltips") == 0)
557         {
558                 gl_prefs->main_toolbar_view_tooltips = s;
559                 set_app_main_toolbar_style (ui_component);
560                 gl_prefs_save_settings ();
561
562                 return;
563         }
564
565         if (strcmp (path, "ViewDrawingToolbar") == 0)
566         {
567                 gl_prefs->drawing_toolbar_visible = s;
568                 set_app_drawing_toolbar_style (ui_component);
569                 gl_prefs_save_settings ();
570
571                 return;
572         }
573
574         if (s && (strcmp (path, "DrawingToolbarSystem") == 0))
575         {               
576                 gl_prefs->drawing_toolbar_buttons_style = GL_TOOLBAR_SYSTEM;
577                 set_app_drawing_toolbar_style (ui_component);
578                 gl_prefs_save_settings ();
579
580                 return;
581         }
582
583         if (s && (strcmp (path, "DrawingToolbarIcon") == 0))
584         {               
585                 gl_prefs->drawing_toolbar_buttons_style = GL_TOOLBAR_ICONS;
586                 set_app_drawing_toolbar_style (ui_component);
587                 gl_prefs_save_settings ();
588
589                 return;
590         }
591
592         if (s && (strcmp (path, "DrawingToolbarIconText") == 0))
593         {               
594                 gl_prefs->drawing_toolbar_buttons_style = GL_TOOLBAR_ICONS_AND_TEXT;
595                 set_app_drawing_toolbar_style (ui_component);
596                 gl_prefs_save_settings ();
597
598                 return;
599         }
600
601         if (strcmp (path, "DrawingToolbarTooltips") == 0)
602         {
603                 gl_prefs->drawing_toolbar_view_tooltips = s;
604                 set_app_drawing_toolbar_style (ui_component);
605                 gl_prefs_save_settings ();
606
607                 return;
608         }
609
610         if (strcmp (path, "ViewGrid") == 0)
611         {
612                 gl_prefs->grid_visible = s;
613                 if (s) {
614                         gl_view_show_grid (GL_VIEW(GL_WINDOW(win)->view));
615                 } else {
616                         gl_view_hide_grid (GL_VIEW(GL_WINDOW(win)->view));
617                 }
618                 gl_prefs_save_settings ();
619
620                 return;
621         }
622
623         if (strcmp (path, "ViewMarkup") == 0)
624         {
625                 gl_prefs->markup_visible = s;
626                 if (s) {
627                         gl_view_show_markup (GL_VIEW(GL_WINDOW(win)->view));
628                 } else {
629                         gl_view_hide_markup (GL_VIEW(GL_WINDOW(win)->view));
630                 }
631                 gl_prefs_save_settings ();
632
633                 return;
634         }
635
636 }
637
638 /*---------------------------------------------------------------------------*/
639 /* PRIVATE.  Set main toolbar style.                                         */
640 /*---------------------------------------------------------------------------*/
641 static void
642 set_app_main_toolbar_style (BonoboUIComponent *ui_component)
643 {
644         GConfClient *client;
645         gboolean labels;
646
647         gl_debug (DEBUG_UI, "START");
648
649         g_return_if_fail (BONOBO_IS_UI_COMPONENT (ui_component));
650                         
651         bonobo_ui_component_freeze (ui_component, NULL);
652
653         /* Updated view menu */
654         set_verb_state (ui_component, 
655                         "/commands/ViewMainToolbar",
656                         gl_prefs->main_toolbar_visible);
657
658         set_verb_sensitive (ui_component, 
659                             "/commands/MainToolbarSystem",
660                             gl_prefs->main_toolbar_visible);
661         set_verb_sensitive (ui_component, 
662                             "/commands/MainToolbarIcon",
663                             gl_prefs->main_toolbar_visible);
664         set_verb_sensitive (ui_component, 
665                             "/commands/MainToolbarIconText",
666                             gl_prefs->main_toolbar_visible);
667         set_verb_sensitive (ui_component, 
668                             "/commands/MainToolbarTooltips",
669                             gl_prefs->main_toolbar_visible);
670
671         set_verb_state (ui_component, 
672                         "/commands/MainToolbarSystem",
673                         gl_prefs->main_toolbar_buttons_style == GL_TOOLBAR_SYSTEM);
674
675         set_verb_state (ui_component, 
676                         "/commands/MainToolbarIcon",
677                         gl_prefs->main_toolbar_buttons_style == GL_TOOLBAR_ICONS);
678
679         set_verb_state (ui_component, 
680                         "/commands/MainToolbarIconText",
681                         gl_prefs->main_toolbar_buttons_style == GL_TOOLBAR_ICONS_AND_TEXT);
682
683         set_verb_state (ui_component, 
684                         "/commands/MainToolbarTooltips",
685                         gl_prefs->main_toolbar_view_tooltips);
686
687         
688         /* Actually update main_toolbar style */
689         bonobo_ui_component_set_prop (
690                 ui_component, "/MainToolbar",
691                 "tips", gl_prefs->main_toolbar_view_tooltips ? "1" : "0",
692                 NULL);
693         
694         switch (gl_prefs->main_toolbar_buttons_style)
695         {
696                 case GL_TOOLBAR_SYSTEM:
697                                                 
698                         client = gconf_client_get_default ();
699                         if (client == NULL) 
700                                 goto error;
701
702                         labels = gconf_client_get_bool (client, 
703                                         "/desktop/gnome/interface/toolbar-labels", NULL);
704
705                         g_object_unref (G_OBJECT (client));
706                         
707                         if (labels)
708                         {                       
709                                 bonobo_ui_component_set_prop (
710                                         ui_component, "/MainToolbar", "look", "both", NULL);
711                         
712                         }
713                         else
714                         {
715                                 bonobo_ui_component_set_prop (
716                                         ui_component, "/MainToolbar", "look", "icons", NULL);
717                         }
718         
719                         break;
720                         
721                 case GL_TOOLBAR_ICONS:
722                         bonobo_ui_component_set_prop (
723                                 ui_component, "/MainToolbar", "look", "icon", NULL);
724                         
725                         break;
726                         
727                 case GL_TOOLBAR_ICONS_AND_TEXT:
728                         bonobo_ui_component_set_prop (
729                                 ui_component, "/MainToolbar", "look", "both", NULL);
730                         
731                         break;
732                 default:
733                         goto error;
734                         break;
735         }
736         
737         bonobo_ui_component_set_prop (
738                         ui_component, "/MainToolbar",
739                         "hidden", gl_prefs->main_toolbar_visible ? "0":"1", NULL);
740
741  error:
742         bonobo_ui_component_thaw (ui_component, NULL);
743
744         gl_debug (DEBUG_UI, "END");
745 }
746
747
748 /*---------------------------------------------------------------------------*/
749 /* PRIVATE.  Set drawing toolbar style.                                      */
750 /*---------------------------------------------------------------------------*/
751 static void
752 set_app_drawing_toolbar_style (BonoboUIComponent *ui_component)
753 {
754         GConfClient *client;
755         gboolean labels;
756
757         gl_debug (DEBUG_UI, "START");
758
759         g_return_if_fail (BONOBO_IS_UI_COMPONENT(ui_component));
760                         
761         bonobo_ui_component_freeze (ui_component, NULL);
762
763         /* Updated view menu */
764         set_verb_state (ui_component, 
765                         "/commands/ViewDrawingToolbar",
766                         gl_prefs->drawing_toolbar_visible);
767
768         set_verb_sensitive (ui_component, 
769                             "/commands/DrawingToolbarSystem",
770                             gl_prefs->drawing_toolbar_visible);
771         set_verb_sensitive (ui_component, 
772                             "/commands/DrawingToolbarIcon",
773                             gl_prefs->drawing_toolbar_visible);
774         set_verb_sensitive (ui_component, 
775                             "/commands/DrawingToolbarIconText",
776                             gl_prefs->drawing_toolbar_visible);
777         set_verb_sensitive (ui_component, 
778                             "/commands/DrawingToolbarTooltips",
779                             gl_prefs->drawing_toolbar_visible);
780
781         set_verb_state (
782                 ui_component, 
783                 "/commands/DrawingToolbarSystem",
784                 gl_prefs->drawing_toolbar_buttons_style == GL_TOOLBAR_SYSTEM);
785
786         set_verb_state (
787                 ui_component, 
788                 "/commands/DrawingToolbarIcon",
789                 gl_prefs->drawing_toolbar_buttons_style == GL_TOOLBAR_ICONS);
790
791         set_verb_state (
792                 ui_component, 
793                 "/commands/DrawingToolbarIconText",
794                 gl_prefs->drawing_toolbar_buttons_style == GL_TOOLBAR_ICONS_AND_TEXT);
795
796         set_verb_state (ui_component, 
797                         "/commands/DrawingToolbarTooltips",
798                         gl_prefs->drawing_toolbar_view_tooltips);
799
800         
801         /* Actually update drawing_toolbar style */
802         bonobo_ui_component_set_prop (
803                 ui_component, "/DrawingToolbar",
804                 "tips", gl_prefs->drawing_toolbar_view_tooltips ? "1" : "0",
805                 NULL);
806         
807         switch (gl_prefs->drawing_toolbar_buttons_style)
808         {
809                 case GL_TOOLBAR_SYSTEM:
810                                                 
811                         client = gconf_client_get_default ();
812                         if (client == NULL) 
813                                 goto error;
814
815                         labels = gconf_client_get_bool (client, 
816                                         "/desktop/gnome/interface/toolbar-labels", NULL);
817
818                         g_object_unref (G_OBJECT (client));
819                         
820                         if (labels)
821                         {                       
822                                 bonobo_ui_component_set_prop (
823                                         ui_component, "/DrawingToolbar", "look", "both", NULL);
824                         
825                         }
826                         else
827                         {
828                                 bonobo_ui_component_set_prop (
829                                         ui_component, "/DrawingToolbar", "look", "icons", NULL);
830                         }
831         
832                         break;
833                         
834                 case GL_TOOLBAR_ICONS:
835                         bonobo_ui_component_set_prop (
836                                 ui_component, "/DrawingToolbar", "look", "icon", NULL);
837                         
838                         break;
839                         
840                 case GL_TOOLBAR_ICONS_AND_TEXT:
841                         bonobo_ui_component_set_prop (
842                                 ui_component, "/DrawingToolbar", "look", "both", NULL);
843                         
844                         break;
845                 default:
846                         goto error;
847                         break;
848         }
849         
850         bonobo_ui_component_set_prop (
851                         ui_component, "/DrawingToolbar",
852                         "hidden", gl_prefs->drawing_toolbar_visible ? "0":"1", NULL);
853
854  error:
855         bonobo_ui_component_thaw (ui_component, NULL);
856
857         gl_debug (DEBUG_UI, "END");
858 }
859
860 /*---------------------------------------------------------------------------*/
861 /* PRIVATE.  Set visibility of grid and markup.                              */
862 /*---------------------------------------------------------------------------*/
863 static void
864 set_view_style (BonoboUIComponent *ui_component)
865 {
866         GConfClient *client;
867         gboolean labels;
868
869         gl_debug (DEBUG_UI, "START");
870
871         g_return_if_fail (BONOBO_IS_UI_COMPONENT(ui_component));
872                         
873         bonobo_ui_component_freeze (ui_component, NULL);
874
875         set_verb_state (ui_component, 
876                         "/commands/ViewGrid",
877                         gl_prefs->grid_visible);
878
879         set_verb_state (ui_component, 
880                         "/commands/ViewMarkup",
881                         gl_prefs->markup_visible);
882
883  error:
884         bonobo_ui_component_thaw (ui_component, NULL);
885
886         gl_debug (DEBUG_UI, "END");
887 }
888
889
890 /*---------------------------------------------------------------------------*/
891 /* Set sensitivity of verb.                                                  */
892 /*---------------------------------------------------------------------------*/
893 static void
894 set_verb_sensitive (BonoboUIComponent  *ui_component,
895                     gchar              *cname,
896                     gboolean            sensitive)
897 {
898         gl_debug (DEBUG_UI, "START");
899
900         g_return_if_fail (cname != NULL);
901         g_return_if_fail (BONOBO_IS_UI_COMPONENT (ui_component));
902
903         bonobo_ui_component_set_prop (ui_component,
904                                       cname,
905                                       "sensitive",
906                                       sensitive ? "1" : "0",
907                                       NULL);
908
909         gl_debug (DEBUG_UI, "END");
910 }
911
912 /*---------------------------------------------------------------------------*/
913 /* Set sensitivity of a list of verbs.                                       */
914 /*---------------------------------------------------------------------------*/
915 static void
916 set_verb_list_sensitive (BonoboUIComponent   *ui_component,
917                          gchar              **vlist,
918                          gboolean             sensitive)
919 {
920         gl_debug (DEBUG_UI, "START");
921
922         g_return_if_fail (vlist != NULL);
923         g_return_if_fail (BONOBO_IS_UI_COMPONENT (ui_component));
924
925         for ( ; *vlist; ++vlist)
926         {
927                 bonobo_ui_component_set_prop (ui_component,
928                                               *vlist,
929                                               "sensitive",
930                                               sensitive ? "1" : "0",
931                                               NULL);
932         }
933
934         gl_debug (DEBUG_UI, "END");
935 }
936
937 /*---------------------------------------------------------------------------*/
938 /* Set state of a verb.                                                      */
939 /*---------------------------------------------------------------------------*/
940 static void
941 set_verb_state (BonoboUIComponent   *ui_component,
942                 gchar               *cname,
943                 gboolean             state)
944 {
945         gl_debug (DEBUG_UI, "START");
946
947         g_return_if_fail (cname != NULL);
948         g_return_if_fail (BONOBO_IS_UI_COMPONENT (ui_component));
949
950         bonobo_ui_component_set_prop (ui_component,
951                                       cname,
952                                       "state",
953                                       state ? "1" : "0",
954                                       NULL);
955
956         gl_debug (DEBUG_UI, "END");
957 }
958