]> www.fi.muni.cz Git - evince.git/blob - cut-n-paste/recent-files/egg-recent-view-uimanager.c
Fix printing with poppler splash backend. Fixes bug #489774.
[evince.git] / cut-n-paste / recent-files / egg-recent-view-uimanager.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /*
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17  *
18  * Authors:
19  *   James Willcox <jwillcox@cs.indiana.edu>
20  *   Paolo Bacchilega <paobac@cvs.gnome.org>
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <gtk/gtk.h>
31 #include <libgnomevfs/gnome-vfs.h>
32 #ifndef USE_STABLE_LIBGNOMEUI
33 #include <libgnomeui/gnome-icon-theme.h>
34 #endif
35 #include <gconf/gconf-client.h>
36 #include "egg-recent-model.h"
37 #include "egg-recent-view.h"
38 #include "egg-recent-view-uimanager.h"
39 #include "egg-recent-util.h"
40 #include "egg-recent-item.h"
41
42 #define EGG_RECENT_NAME_PREFIX "EggRecentAction"
43 #define EGG_RECENT_ACTION "EggRecentFile"
44 #define EGG_RECENT_SEPARATOR (NULL)
45
46 #ifndef EGG_COMPILATION
47 #include <glib/gi18n.h>
48 #else
49 #define _(x) (x)
50 #define N_(x) (x)
51 #endif
52
53 #define DEFAULT_LABEL_WIDTH_CHARS 30
54
55 struct _EggRecentViewUIManager {
56         GObject         parent_instance;
57
58         GCallback       action_callback;
59         gpointer        action_user_data;
60
61         gboolean        leading_sep;
62         gboolean        trailing_sep;
63
64         GtkUIManager   *uimanager;
65         GtkActionGroup *action_group;
66         guint           merge_id;
67         gulong          changed_cb_id;
68
69         gchar          *path;
70
71         gboolean        show_icons;
72         gboolean        show_numbers;
73 #ifndef USE_STABLE_LIBGNOMEUI
74         GnomeIconTheme *theme;
75 #endif
76
77         EggUIManagerTooltipFunc tooltip_func;
78         gpointer        tooltip_func_data;
79
80         EggRecentModel *model;
81         GConfClient    *client;
82         GtkIconSize     icon_size;
83
84         gint            label_width;
85 };
86
87
88 struct _EggRecentViewUIManagerMenuData {
89         EggRecentViewUIManager *view;
90         EggRecentItem *item;
91 };
92
93 typedef struct _EggRecentViewUIManagerMenuData EggRecentViewUIManagerMenuData;
94
95 enum {
96         ACTIVATE,
97         LAST_SIGNAL
98 };
99
100 /* GObject properties */
101 enum {
102         PROP_BOGUS,
103         PROP_UIMANAGER,
104         PROP_PATH,
105         PROP_SHOW_ICONS,
106         PROP_SHOW_NUMBERS,
107         PROP_LABEL_WIDTH
108 };
109
110 static guint view_signals[LAST_SIGNAL] = { 0 };
111
112 static void
113 connect_proxy_cb (GtkActionGroup         *action_group,
114                   GtkAction              *action,
115                   GtkWidget              *proxy,
116                   EggRecentViewUIManager *view)
117 {
118         if (GTK_IS_MENU_ITEM (proxy))
119         {
120                 GtkWidget *label;
121
122                 label = GTK_BIN (proxy)->child;
123
124                 gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
125                 gtk_label_set_max_width_chars (GTK_LABEL (label), view->label_width);
126         }
127 }
128
129 static void
130 egg_recent_view_uimanager_clear (EggRecentViewUIManager *view)
131 {
132         if (view->merge_id != 0) {
133                 gtk_ui_manager_remove_ui (view->uimanager, view->merge_id);
134                 view->merge_id = 0;
135         }
136
137         if (view->action_group != NULL) {
138                 gtk_ui_manager_remove_action_group (view->uimanager, view->action_group);
139                 g_object_unref (view->action_group);
140                 view->action_group = NULL;
141         }
142
143         gtk_ui_manager_ensure_update (view->uimanager);
144 }
145
146 static void
147 egg_recent_view_uimanager_set_list (EggRecentViewUIManager *view, GList *list)
148 {
149         GList  *scan;
150         guint   index = 1;
151
152         g_return_if_fail (view);
153
154         egg_recent_view_uimanager_clear (view);
155
156         if (view->merge_id == 0)
157                 view->merge_id = gtk_ui_manager_new_merge_id (view->uimanager);
158
159         if (view->action_group == NULL) {
160                 gchar *group = g_strdup_printf ("EggRecentActions%u", 
161                                                 view->merge_id);
162                 view->action_group = gtk_action_group_new (group);
163                 g_signal_connect (view->action_group, "connect-proxy",
164                                   G_CALLBACK (connect_proxy_cb), view);
165                 gtk_ui_manager_insert_action_group (view->uimanager,
166                                                     view->action_group, -1);
167                 g_free (group);
168         }
169
170         if (view->leading_sep) {
171                 gchar *action = g_strdup_printf ("EggRecentLeadingSeparator%u",
172                                                  view->merge_id);
173                 gtk_ui_manager_add_ui (view->uimanager, 
174                                        view->merge_id, 
175                                        view->path,
176                                        action,
177                                        EGG_RECENT_SEPARATOR,
178                                        GTK_UI_MANAGER_AUTO, 
179                                        FALSE);
180                 g_free (action);
181         }
182
183         for (scan = list; scan; scan = scan->next, index++) {
184                 EggRecentItem *item = scan->data;
185                 GtkAction     *action;
186                 gchar         *name;
187                 gchar         *uri;
188                 gchar         *basename;
189                 gchar         *escaped;
190                 gchar         *label;
191                 gchar         *tooltip = NULL;
192
193                 uri = egg_recent_item_get_uri_for_display (item);
194                 if (uri == NULL)
195                         continue;
196
197                 name = g_strdup_printf (EGG_RECENT_NAME_PREFIX"%u-%u", 
198                                         view->merge_id,
199                                         index);
200
201                 if (view->tooltip_func != NULL)
202                         tooltip = (*view->tooltip_func) (item, view->tooltip_func_data);
203
204                 if (!tooltip)
205                         tooltip = g_strdup_printf (_("Open “%s”"), uri);
206
207                 basename = egg_recent_item_get_short_name (item);
208                 escaped = egg_recent_util_escape_underlines (basename);
209                 g_free (basename);
210                 g_free (uri);
211
212                 if (view->show_numbers) {
213                         if (index >= 10)
214                                 label = g_strdup_printf ("%d.  %s", 
215                                                          index, 
216                                                          escaped);
217                         else
218                                 label = g_strdup_printf ("_%d.  %s", 
219                                                          index, 
220                                                          escaped);
221                         g_free (escaped);
222                 } else 
223                         label = escaped;
224
225                 action = g_object_new (GTK_TYPE_ACTION,
226                                        "name", name,
227                                        "label", label,
228                                        (view->show_icons)? "stock_id": NULL, 
229                                        GTK_STOCK_OPEN,
230                                        NULL);
231                 if (tooltip != NULL) {
232                         g_object_set (action, "tooltip", tooltip, NULL);
233                         g_free (tooltip);
234                 }
235                 egg_recent_item_ref (item);
236                 g_object_set_data_full (G_OBJECT (action), 
237                                         "egg_recent_uri", 
238                                         item, 
239                                         (GFreeFunc) egg_recent_item_unref);
240
241                 if (view->action_callback != NULL) {
242                         GClosure *closure;
243                         closure = g_cclosure_new (view->action_callback, view->action_user_data, NULL);
244                         g_signal_connect_closure (action, "activate", closure, FALSE);
245                 }
246
247                 gtk_action_group_add_action (view->action_group, action);
248                 g_object_unref (action);
249
250                 gtk_ui_manager_add_ui (view->uimanager, 
251                                        view->merge_id, 
252                                        view->path,
253                                        name,
254                                        name,
255                                        GTK_UI_MANAGER_AUTO, 
256                                        FALSE);
257
258                 g_free (name);
259                 g_free (label);
260         }
261
262         if (view->trailing_sep) {
263                 gchar *action = g_strdup_printf ("EggRecentTrailingSeparator%u",
264                                                 view->merge_id);
265                 gtk_ui_manager_add_ui (view->uimanager, 
266                                        view->merge_id, 
267                                        view->path,
268                                        action,
269                                        EGG_RECENT_SEPARATOR,
270                                        GTK_UI_MANAGER_AUTO, 
271                                        FALSE);
272                 g_free (action);
273         }
274 }
275
276 static void
277 egg_recent_view_uimanager_set_empty_list (EggRecentViewUIManager *view)
278 {
279         gboolean   is_embedded;
280
281         g_return_if_fail (view);
282
283         egg_recent_view_uimanager_clear (view);
284
285         if (view->merge_id == 0)
286                 view->merge_id = gtk_ui_manager_new_merge_id (view->uimanager);
287
288         if (view->action_group == NULL) {
289                 gchar *group = g_strdup_printf ("EggRecentActions%u", 
290                                                 view->merge_id);
291                 view->action_group = gtk_action_group_new (group);
292                 g_signal_connect (view->action_group, "connect-proxy",
293                                   G_CALLBACK (connect_proxy_cb), view);
294                 gtk_ui_manager_insert_action_group (view->uimanager,
295                                                     view->action_group, -1);
296                 g_free (group);
297         }
298
299         if (view->leading_sep) {
300                 gchar *sep_action = g_strdup_printf ("EggRecentLeadingSeparator%u",
301                                                      view->merge_id);
302                 gtk_ui_manager_add_ui (view->uimanager, 
303                                        view->merge_id, 
304                                        view->path,
305                                        sep_action,
306                                        EGG_RECENT_SEPARATOR,
307                                        GTK_UI_MANAGER_AUTO, 
308                                        FALSE);
309                 g_free (sep_action);
310         }
311
312         is_embedded = (view->leading_sep && view->trailing_sep);
313
314         if (is_embedded) {
315                 GtkAction *action;
316                 gchar     *name;
317
318                 name = g_strdup_printf (EGG_RECENT_NAME_PREFIX "%u-0", view->merge_id);
319
320                 action = g_object_new (GTK_TYPE_ACTION,
321                                        "name", name,
322                                        "label", _("Empty"),
323                                        "sensitive", FALSE,
324                                        NULL);
325                 
326                 gtk_action_group_add_action (view->action_group, action);
327                 g_object_unref (action);
328
329                 gtk_ui_manager_add_ui (view->uimanager, 
330                                        view->merge_id, 
331                                        view->path,
332                                        name,
333                                        name,
334                                        GTK_UI_MANAGER_AUTO, 
335                                        FALSE);
336
337                 g_free (name);
338         }
339
340         if (view->trailing_sep) {
341                 gchar *sep_action = g_strdup_printf ("EggRecentTrailingSeparator%u",
342                                                      view->merge_id);
343                 gtk_ui_manager_add_ui (view->uimanager, 
344                                        view->merge_id, 
345                                        view->path,
346                                        sep_action,
347                                        EGG_RECENT_SEPARATOR,
348                                        GTK_UI_MANAGER_AUTO, 
349                                        FALSE);
350                 g_free (sep_action);
351         }
352 }
353
354 static void
355 model_changed_cb (EggRecentModel         *model,  
356                   GList                  *list, 
357                   EggRecentViewUIManager *view)
358 {
359         if (list != NULL)
360                 egg_recent_view_uimanager_set_list (view, list);
361         else
362                 egg_recent_view_uimanager_set_empty_list (view);
363
364         gtk_ui_manager_ensure_update (view->uimanager);
365 }
366
367 static EggRecentModel *
368 egg_recent_view_uimanager_get_model (EggRecentView *view_parent)
369 {
370         EggRecentViewUIManager *view;
371         
372         g_return_val_if_fail (view_parent != NULL, NULL);
373         view = EGG_RECENT_VIEW_UIMANAGER (view_parent);
374         return view->model;
375 }
376
377 static void
378 egg_recent_view_uimanager_set_model (EggRecentView  *view_parent,
379                                      EggRecentModel *model)
380 {
381         EggRecentViewUIManager *view;
382         
383         g_return_if_fail (view_parent != NULL);
384         view = EGG_RECENT_VIEW_UIMANAGER (view_parent);
385
386         if (view->model != NULL) {
387                 if (view->changed_cb_id != 0)
388                         g_signal_handler_disconnect (G_OBJECT (view->model),
389                                                      view->changed_cb_id);
390                 g_object_unref (view->model);
391         }
392         
393         view->model = model;
394         g_object_ref (view->model);
395
396         view->changed_cb_id = g_signal_connect_object (G_OBJECT (model),
397                                                        "changed",
398                                                        G_CALLBACK (model_changed_cb),
399                                                        view, 0);
400
401         egg_recent_model_changed (view->model);
402 }
403
404 void
405 egg_recent_view_uimanager_set_leading_sep (EggRecentViewUIManager *view, 
406                                            gboolean                val)
407 {
408         view->leading_sep = val;
409         egg_recent_view_uimanager_clear (view);
410         if (view->model)
411                 egg_recent_model_changed (view->model);
412 }
413
414 void
415 egg_recent_view_uimanager_set_trailing_sep (EggRecentViewUIManager *view,
416                                             gboolean                val)
417 {
418         view->trailing_sep = val;
419         egg_recent_view_uimanager_clear (view);
420         if (view->model)
421                 egg_recent_model_changed (view->model);
422 }
423
424 static void
425 egg_recent_view_uimanager_set_property (GObject      *object,
426                                         guint         prop_id,
427                                         const GValue *value,
428                                         GParamSpec   *pspec)
429 {
430         EggRecentViewUIManager *view = EGG_RECENT_VIEW_UIMANAGER (object);
431
432         switch (prop_id) {
433         case PROP_UIMANAGER:
434                 egg_recent_view_uimanager_set_uimanager (view, (GtkUIManager*)g_value_get_object (value));
435                 break;
436         case PROP_PATH:
437                 egg_recent_view_uimanager_set_path (view, g_value_get_string (value));
438                 break;
439         case PROP_SHOW_ICONS:
440                 egg_recent_view_uimanager_show_icons (view, g_value_get_boolean (value));
441                 break;
442         case PROP_SHOW_NUMBERS:
443                 egg_recent_view_uimanager_show_numbers (view, g_value_get_boolean (value));
444                 break;
445         case PROP_LABEL_WIDTH:
446                 egg_recent_view_uimanager_set_label_width (view, g_value_get_int (value));
447                 break;
448         default:
449                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
450                 break;
451         }
452 }
453
454 static void
455 egg_recent_view_uimanager_get_property (GObject    *object,
456                                         guint       prop_id,
457                                         GValue     *value,
458                                         GParamSpec *pspec)
459 {
460         EggRecentViewUIManager *view = EGG_RECENT_VIEW_UIMANAGER (object);
461
462         switch (prop_id) {
463         case PROP_UIMANAGER:
464                 g_value_set_object (value, view->uimanager);
465                 break;
466         case PROP_PATH:
467                 g_value_set_string (value, view->path);
468                 break;
469         case PROP_SHOW_ICONS:
470                 g_value_set_boolean (value, view->show_icons);
471                 break;
472         case PROP_SHOW_NUMBERS:
473                 g_value_set_boolean (value, view->show_numbers);
474                 break;
475         case PROP_LABEL_WIDTH:
476                 g_value_set_int (value, view->label_width);
477                 break;
478         default:
479                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
480                 break;
481         }
482 }
483
484 static void
485 egg_recent_view_uimanager_finalize (GObject *object)
486 {
487         EggRecentViewUIManager *view = EGG_RECENT_VIEW_UIMANAGER (object);
488
489         if (view->changed_cb_id != 0) {
490                 g_signal_handler_disconnect (G_OBJECT (view->model),
491                                              view->changed_cb_id);
492                 view->changed_cb_id = 0;
493         }
494
495         g_free (view->path);
496
497         egg_recent_view_uimanager_clear (view);
498
499         if (view->action_group != NULL) {
500                 g_object_unref (view->action_group);
501                 view->action_group = NULL;
502         }
503
504         if (view->uimanager != NULL) {
505                 g_object_unref (view->uimanager);
506                 view->uimanager = NULL;
507         }
508
509         if (view->model != NULL) {
510                 g_object_unref (view->model);
511                 view->model = NULL;
512         }
513
514 #ifndef USE_STABLE_LIBGNOMEUI
515         if (view->theme != NULL) {
516                 g_object_unref (view->theme);
517                 view->theme = NULL;
518         }
519 #endif
520
521         if (view->client != NULL) {
522                 g_object_unref (view->client);
523                 view->client = NULL;
524         }
525
526         G_OBJECT_CLASS (egg_recent_view_uimanager_parent_class)->finalize (object);
527 }
528
529 static void
530 egg_recent_view_uimanager_class_init (EggRecentViewUIManagerClass * klass)
531 {
532         GObjectClass *object_class;
533
534         object_class = G_OBJECT_CLASS (klass);
535
536         object_class->set_property = egg_recent_view_uimanager_set_property;
537         object_class->get_property = egg_recent_view_uimanager_get_property;
538         object_class->finalize     = egg_recent_view_uimanager_finalize;
539
540         view_signals[ACTIVATE] = g_signal_new ("activate",
541                                                G_OBJECT_CLASS_TYPE (object_class),
542                                                G_SIGNAL_RUN_LAST,
543                                                G_STRUCT_OFFSET (EggRecentViewUIManagerClass, activate),
544                                                NULL, NULL,
545                                                g_cclosure_marshal_VOID__BOXED,
546                                                G_TYPE_NONE, 1,
547                                                EGG_TYPE_RECENT_ITEM);
548
549         g_object_class_install_property (object_class,
550                                          PROP_UIMANAGER,
551                                          g_param_spec_object ("uimanager",
552                                                               "UI Manager",
553                                                               "The UI manager this object will use to update.the UI",
554                                                               GTK_TYPE_UI_MANAGER,
555                                                               G_PARAM_READWRITE));
556         g_object_class_install_property (object_class,
557                                          PROP_PATH,
558                                          g_param_spec_string ("path",
559                                                               "Path",
560                                                               "The UI path this object will update.",
561                                                               NULL,
562                                                               G_PARAM_READWRITE));
563         g_object_class_install_property (object_class,
564                                          PROP_SHOW_ICONS,
565                                          g_param_spec_boolean ("show-icons",
566                                                                "Show Icons",
567                                                                "Whether or not to show icons",
568                                                                FALSE,
569                                                                G_PARAM_READWRITE));
570         
571         g_object_class_install_property (object_class,
572                                          PROP_SHOW_NUMBERS,
573                                          g_param_spec_boolean ("show-numbers",
574                                                                "Show Numbers",
575                                                                "Whether or not to show numbers",
576                                                                TRUE,
577                                                                G_PARAM_READWRITE));
578         g_object_class_install_property (object_class,
579                                          PROP_LABEL_WIDTH,
580                                          g_param_spec_int ("label-width",
581                                                            "Label Width",
582                                                            "The desired width of the menu label, in characters",
583                                                            -1,
584                                                            G_MAXINT,
585                                                            DEFAULT_LABEL_WIDTH_CHARS,
586                                                            G_PARAM_READWRITE));
587         
588
589         klass->activate = NULL;
590 }
591
592 static void
593 egg_recent_view_init (EggRecentViewClass *iface)
594 {
595         iface->do_get_model = egg_recent_view_uimanager_get_model;
596         iface->do_set_model = egg_recent_view_uimanager_set_model;
597 }
598
599 static void
600 show_menus_changed_cb (GConfClient            *client,
601                        guint                   cnxn_id,
602                        GConfEntry             *entry,
603                        EggRecentViewUIManager *view)
604 {
605         GConfValue *value;
606
607         value = gconf_entry_get_value (entry);
608         g_return_if_fail (value->type == GCONF_VALUE_BOOL);
609
610         egg_recent_view_uimanager_show_icons (view, gconf_value_get_bool (value));
611 }
612
613 #ifndef USE_STABLE_LIBGNOMEUI
614 static void
615 theme_changed_cb (GnomeIconTheme         *theme, 
616                   EggRecentViewUIManager *view)
617 {
618         if (view->model != NULL)
619                 egg_recent_model_changed (view->model);
620 }
621 #endif
622
623 static void
624 egg_recent_view_uimanager_init (EggRecentViewUIManager * view)
625 {
626         view->client = gconf_client_get_default ();
627
628         view->show_icons = gconf_client_get_bool (view->client,
629                                                   "/desktop/gnome/interface/menus_have_icons",
630                                                   NULL);
631         
632         gconf_client_add_dir (view->client, "/desktop/gnome/interface",
633                               GCONF_CLIENT_PRELOAD_NONE,
634                               NULL);
635         gconf_client_notify_add (view->client,
636                                  "/desktop/gnome/interface/menus_have_icons",
637                                  (GConfClientNotifyFunc)show_menus_changed_cb,
638                                  view, NULL, NULL);
639
640
641         view->leading_sep = FALSE;
642         view->trailing_sep = FALSE;
643         view->show_numbers = TRUE;
644
645         view->uimanager = NULL;
646         view->action_group = NULL;
647         view->merge_id = 0;
648         view->changed_cb_id = 0;
649
650         view->path = NULL;
651
652 #ifndef USE_STABLE_LIBGNOMEUI
653         view->theme = gnome_icon_theme_new ();
654         gnome_icon_theme_set_allow_svg (view->theme, TRUE);
655         g_signal_connect_object (view->theme, "changed",
656                                  G_CALLBACK (theme_changed_cb), view, 0);
657 #endif
658
659         view->tooltip_func = NULL;
660         view->tooltip_func_data = NULL;
661
662         view->icon_size = GTK_ICON_SIZE_MENU;
663         view->label_width = DEFAULT_LABEL_WIDTH_CHARS;
664 }
665
666 void
667 egg_recent_view_uimanager_set_icon_size (EggRecentViewUIManager *view,
668                                          GtkIconSize             icon_size)
669 {
670         if (view->icon_size != icon_size) {
671                 view->icon_size = icon_size;
672                 egg_recent_model_changed (view->model);
673         } else {
674                 view->icon_size = icon_size;
675         }
676 }
677
678 GtkIconSize
679 egg_recent_view_uimanager_get_icon_size (EggRecentViewUIManager *view)
680 {
681         return view->icon_size;
682 }
683
684 void
685 egg_recent_view_uimanager_show_icons (EggRecentViewUIManager *view,
686                                       gboolean                show)
687 {
688         view->show_icons = show;
689         if (view->model != NULL)
690                 egg_recent_model_changed (view->model);
691 }
692
693 void
694 egg_recent_view_uimanager_show_numbers (EggRecentViewUIManager *view, 
695                                         gboolean                show)
696 {
697         view->show_numbers = show;
698         if (view->model != NULL)
699                 egg_recent_model_changed (view->model);
700 }
701
702 void
703 egg_recent_view_uimanager_set_tooltip_func (EggRecentViewUIManager   *view,
704                                             EggUIManagerTooltipFunc   func,
705                                             gpointer                  user_data)
706 {
707         view->tooltip_func = func;
708         view->tooltip_func_data = user_data;
709         if (view->model)
710                 egg_recent_model_changed (view->model);
711 }
712
713 /**
714  * egg_recent_view_uimanager_set_uimanager:
715  * @view: A EggRecentViewUIManager object.
716  * @uimanager: The ui manager used to put the menu items in.
717  *
718  * Use this function to change the ui manager used to update the menu.
719  *
720  */
721 void
722 egg_recent_view_uimanager_set_uimanager (EggRecentViewUIManager *view,
723                                          GtkUIManager           *uimanager)
724 {
725         g_return_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view));
726         g_return_if_fail (uimanager != NULL);
727
728         if (view->uimanager != NULL)
729                 g_object_unref (view->uimanager);
730         view->uimanager = uimanager;
731         g_object_ref (view->uimanager);
732 }
733
734 /**
735  * egg_recent_view_uimanager_get_uimanager:
736  * @view: A EggRecentViewUIManager object.
737  *
738  */
739 GtkUIManager*
740 egg_recent_view_uimanager_get_uimanager (EggRecentViewUIManager *view)
741 {
742         g_return_val_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view), NULL);
743         return view->uimanager;
744 }
745
746 /**
747  * egg_recent_view_uimanager_set_path:
748  * @view: A EggRecentViewUIManager object.
749  * @path: The path to put the menu items in.
750  *
751  * Use this function to change the path where the recent
752  * documents appear in.
753  *
754  */
755 void
756 egg_recent_view_uimanager_set_path (EggRecentViewUIManager *view,
757                                     const gchar            *path)
758 {
759         g_return_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view));
760         g_return_if_fail (path);
761
762         g_free (view->path);
763         view->path = g_strdup (path);
764 }
765
766 /**
767  * egg_recent_view_uimanager_get_path:
768  * @view: A EggRecentViewUIManager object.
769  *
770  */
771 G_CONST_RETURN gchar*
772 egg_recent_view_uimanager_get_path (EggRecentViewUIManager *view)
773 {
774         g_return_val_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view), NULL);
775         return view->path;
776 }
777
778 void
779 egg_recent_view_uimanager_set_label_width (EggRecentViewUIManager *view,
780                                            gint                    chars)
781 {
782         g_return_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view));
783         view->label_width = chars;
784 }
785
786 gint
787 egg_recent_view_uimanager_get_label_width (EggRecentViewUIManager *view)
788 {
789         g_return_val_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view), DEFAULT_LABEL_WIDTH_CHARS);
790         return view->label_width;
791 }
792
793 void
794 egg_recent_view_uimanager_set_action_func (EggRecentViewUIManager   *view,
795                                            GCallback                 callback,
796                                            gpointer                  user_data)
797 {
798         g_return_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view));
799         view->action_callback = callback;
800         view->action_user_data = user_data;
801 }
802
803 /**
804  * egg_recent_view_uimanager_new:
805  * @appname: The name of your application.
806  * @limit:  The maximum number of items allowed.
807  *
808  * This creates a new EggRecentViewUIManager object.
809  *
810  * Returns: a EggRecentViewUIManager object
811  */
812 EggRecentViewUIManager *
813 egg_recent_view_uimanager_new (GtkUIManager  *uimanager,
814                                const gchar   *path,
815                                GCallback      callback,
816                                gpointer       user_data)
817 {
818         GObject *view;
819
820         g_return_val_if_fail (uimanager, NULL);
821         g_return_val_if_fail (path, NULL);
822
823         view = g_object_new (egg_recent_view_uimanager_get_type (),
824                              "uimanager", uimanager,
825                              "path", path,
826                              NULL);
827
828         g_return_val_if_fail (view, NULL);
829         
830         egg_recent_view_uimanager_set_action_func (EGG_RECENT_VIEW_UIMANAGER (view),
831                                                    callback,
832                                                    user_data);
833
834         return EGG_RECENT_VIEW_UIMANAGER (view);
835 }
836
837 GType
838 egg_recent_view_uimanager_get_type (void)
839 {
840         static GType egg_recent_view_uimanager_type = 0;
841
842         if(!egg_recent_view_uimanager_type) {
843                 const GTypeInfo egg_recent_view_uimanager_info = {
844                         sizeof (EggRecentViewUIManagerClass),
845                         NULL, /* base init */
846                         NULL, /* base finalize */
847                         (GClassInitFunc)egg_recent_view_uimanager_class_init, /* class init */
848                         NULL, /* class finalize */
849                         NULL, /* class data */
850                         sizeof (EggRecentViewUIManager),
851                         0,
852                         (GInstanceInitFunc) egg_recent_view_uimanager_init
853                 };
854
855                 const GInterfaceInfo view_info =
856                 {
857                         (GInterfaceInitFunc) egg_recent_view_init,
858                         NULL,
859                         NULL
860                 };
861
862                 egg_recent_view_uimanager_type = g_type_register_static (G_TYPE_OBJECT,
863                                                                          "EggRecentViewUIManager",
864                                                                          &egg_recent_view_uimanager_info, 0);
865                 g_type_add_interface_static (egg_recent_view_uimanager_type,
866                                              EGG_TYPE_RECENT_VIEW,
867                                              &view_info);
868         }
869
870         return egg_recent_view_uimanager_type;
871 }
872
873 EggRecentItem*
874 egg_recent_view_uimanager_get_item (EggRecentViewUIManager   *view,
875                                     GtkAction                *action)
876 {
877         return g_object_get_data (G_OBJECT(action), "egg_recent_uri");
878 }