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