]> www.fi.muni.cz Git - evince.git/commitdiff
Removed EggRecentViewGtk
authorNickolay V. Shmyrev <nshmyrev@src.gnome.org>
Sun, 19 Jun 2005 17:36:16 +0000 (17:36 +0000)
committerNickolay V. Shmyrev <nshmyrev@src.gnome.org>
Sun, 19 Jun 2005 17:36:16 +0000 (17:36 +0000)
* cut-n-paste/recent-files/Makefile.am:
* cut-n-paste/recent-files/egg-recent-view-gtk.c:
* cut-n-paste/recent-files/egg-recent-view-gtk.h:

Removed EggRecentViewGtk

* cut-n-paste/recent-files/egg-recent-view-uimanager.c:
* cut-n-paste/recent-files/egg-recent-view-uimanager.h:
* shell/ev-window.c: (ev_window_cmd_recent_file_activate),
(ev_window_setup_recent):

Use ViewUIManager instead of ViewGtk. Less leaks, more compatibility
with other projects

ChangeLog
cut-n-paste/recent-files/Makefile.am
cut-n-paste/recent-files/egg-recent-view-gtk.c [deleted file]
cut-n-paste/recent-files/egg-recent-view-gtk.h [deleted file]
cut-n-paste/recent-files/egg-recent-view-uimanager.c [new file with mode: 0644]
cut-n-paste/recent-files/egg-recent-view-uimanager.h [new file with mode: 0644]
shell/ev-window.c

index 9e1b7941b097da5ee1cd083e6d6eef8f8f4f1504..fc26f9005f2b6ce864c4dde4652f06e3e452c3b3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2005-06-19  Nickolay V. Shmyrev  <nshmyrev@yandex.ru>
+
+       * cut-n-paste/recent-files/Makefile.am:
+       * cut-n-paste/recent-files/egg-recent-view-gtk.c:
+       * cut-n-paste/recent-files/egg-recent-view-gtk.h:
+       
+       Removed EggRecentViewGtk
+       
+       * cut-n-paste/recent-files/egg-recent-view-uimanager.c:
+       * cut-n-paste/recent-files/egg-recent-view-uimanager.h:
+       * shell/ev-window.c: (ev_window_cmd_recent_file_activate),
+       (ev_window_setup_recent):
+       
+       Use ViewUIManager instead of ViewGtk. Less leaks, more compatibility
+        with other projects
+
 2005-06-19  Nickolay V. Shmyrev  <nshmyrev@yandex.ru>
 
        * cut-n-paste/recent-files/egg-recent-view-gtk.c:
index bd05134b97f3a33158c36d308f682ce9cf6df385..82b5a7807218d5c1fe6fdae76b0ecdf5bd6f7141 100644 (file)
@@ -14,8 +14,8 @@ EGG_FILES =                           \
         egg-recent-item.h              \
         egg-recent-view.c              \
         egg-recent-view.h              \
-        egg-recent-view-gtk.c          \
-        egg-recent-view-gtk.h          \
+        egg-recent-view-uimanager.c    \
+        egg-recent-view-uimanager.h    \
         egg-recent-util.c              \
        egg-recent-util.h
 
diff --git a/cut-n-paste/recent-files/egg-recent-view-gtk.c b/cut-n-paste/recent-files/egg-recent-view-gtk.c
deleted file mode 100644 (file)
index 36acf63..0000000
+++ /dev/null
@@ -1,868 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
- *
- * Authors:
- *   James Willcox <jwillcox@cs.indiana.edu>
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <gtk/gtk.h>
-#include <libgnomevfs/gnome-vfs.h>
-#ifndef USE_STABLE_LIBGNOMEUI
-#include <libgnomeui/gnome-icon-theme.h>
-#endif
-#include <gconf/gconf-client.h>
-#include "egg-recent-model.h"
-#include "egg-recent-view.h"
-#include "egg-recent-view-gtk.h"
-#include "egg-recent-util.h"
-#include "egg-recent-item.h"
-
-#define DEFAULT_LABEL_WIDTH 30
-
-struct _EggRecentViewGtk {
-       GObject parent_instance;        /* We emit signals */
-
-       GtkWidget *menu;
-       GtkWidget *start_menu_item;
-
-       gboolean leading_sep;
-       gboolean trailing_sep;
-
-       gulong changed_cb_id;
-
-       gchar *uid;
-
-       gboolean show_icons;
-       gboolean show_numbers;
-#ifndef USE_STABLE_LIBGNOMEUI
-       GnomeIconTheme *theme;
-#endif
-
-       GtkTooltips *tooltips;
-       EggRecentViewGtkTooltipFunc tooltip_func;
-       gpointer tooltip_func_data;
-
-       EggRecentModel *model;
-       GConfClient *client;
-       GtkIconSize icon_size;
-
-       gint label_width;
-};
-
-
-
-struct _EggRecentViewGtkMenuData {
-       EggRecentViewGtk *view;
-       EggRecentItem *item;
-};
-
-typedef struct _EggRecentViewGtkMenuData EggRecentViewGtkMenuData;
-
-enum {
-       ACTIVATE,
-       LAST_SIGNAL
-};
-
-/* GObject properties */
-enum {
-       PROP_BOGUS,
-       PROP_MENU,
-       PROP_START_MENU_ITEM,
-       PROP_SHOW_ICONS,
-       PROP_SHOW_NUMBERS,
-       PROP_LABEL_WIDTH
-};
-
-static guint view_signals[LAST_SIGNAL] = { 0 };
-
-
-static void
-egg_recent_view_gtk_clear (EggRecentViewGtk *view)
-{
-       GList *menu_children;
-       GList *p;
-       GObject *menu_item;
-       gint *menu_data=NULL;
-
-       if (view->menu == NULL)
-               return;
-
-       menu_children = gtk_container_get_children (GTK_CONTAINER (view->menu));
-
-       p = menu_children;
-       while (p != NULL) {
-               menu_item = (GObject *)p->data;
-
-               menu_data = (gint *)g_object_get_data (menu_item,
-                                                      view->uid);
-       
-               if (menu_data) {
-                       gtk_container_remove (GTK_CONTAINER (view->menu),
-                                            GTK_WIDGET (menu_item));
-
-               }
-               
-               p = p->next;
-       }
-}
-
-
-static gint
-egg_recent_view_gtk_find_menu_offset (EggRecentViewGtk *view)
-{
-       gint i;
-       GList *menu_children;
-       GList *p;
-       GtkWidget *menu_item;
-       gint menu_loc=-1;
-
-       g_return_val_if_fail (view, 0);
-
-       menu_children = GTK_MENU_SHELL (view->menu)->children;
-
-       i = 0;
-       p = menu_children;
-       while (p != NULL) {
-               menu_item = (GtkWidget *)p->data;
-
-               if (menu_item == view->start_menu_item) {
-                       menu_loc = i;
-                       break;
-               }
-
-               p = p->next;
-               i++;
-       }
-
-       return menu_loc;
-}
-
-static void
-egg_recent_view_gtk_menu_cb (GtkWidget *menu, gpointer data)
-{
-       EggRecentViewGtkMenuData *md = (EggRecentViewGtkMenuData *) data;
-       EggRecentItem *item;
-
-       g_return_if_fail (md);
-       g_return_if_fail (md->item);
-       g_return_if_fail (md->view);
-       g_return_if_fail (EGG_IS_RECENT_VIEW_GTK (md->view));
-
-       item = md->item;
-       
-       egg_recent_item_ref (item);
-       
-       g_signal_emit (G_OBJECT(md->view), view_signals[ACTIVATE], 0,
-                      item);
-
-       egg_recent_item_unref (item);
-}
-
-static void
-egg_recent_view_gtk_destroy_cb (gpointer data, GClosure *closure)
-{
-       EggRecentViewGtkMenuData *md = data;
-
-       egg_recent_item_unref (md->item);
-       g_free (md);
-}
-
-static GtkWidget *
-egg_recent_view_gtk_new_separator (EggRecentViewGtk *view)
-{
-       GtkWidget *retval;
-
-       g_return_val_if_fail (view, NULL);
-       
-       retval = gtk_separator_menu_item_new ();
-
-       /*
-        * this is a tag so we can distinguish our menu items
-        * from others that may be in the menu.
-        */
-       g_object_set_data (G_OBJECT (retval),
-                          view->uid,
-                          GINT_TO_POINTER (1));
-
-
-       gtk_widget_show (retval);
-
-       return retval;
-}
-
-static GtkWidget *
-egg_recent_view_gtk_new_menu_item (EggRecentViewGtk *view,
-                                  EggRecentItem *item,
-                                  gint index)
-{
-       GtkWidget *menu_item;
-       EggRecentViewGtkMenuData *md;
-       gchar *mime_type;
-       GtkWidget *image;
-       GtkWidget *label;
-       GdkPixbuf *pixbuf;
-       gchar *text;
-       gchar *short_name;
-       gchar *escaped;
-
-       g_return_val_if_fail (view, NULL);
-       g_return_val_if_fail (item, NULL);
-
-       short_name = egg_recent_item_get_short_name (item);
-       if (!short_name)
-               return NULL;
-
-       escaped = egg_recent_util_escape_underlines (short_name);
-       g_free (short_name);
-
-       if (view->show_numbers) {
-               /* avoid having conflicting mnemonics */
-               if (index >= 10)
-                       text = g_strdup_printf ("%d.  %s", index,
-                                               escaped);
-               else
-                       text = g_strdup_printf ("_%d.  %s", index,
-                                               escaped);
-               g_free (escaped);
-       } else {
-               text = escaped;
-       }
-
-       mime_type = egg_recent_item_get_mime_type (item);
-#ifndef USE_STABLE_LIBGNOMEUI
-       {
-               int width, height;
-               gchar *uri;
-
-               gtk_icon_size_lookup_for_settings
-                       (gtk_widget_get_settings (view->menu),
-                        view->icon_size,
-                        &width, &height);
-
-               uri = egg_recent_item_get_uri (item);
-               pixbuf = egg_recent_util_get_icon (view->theme, uri,
-                                                  mime_type,
-                                                  height);
-               g_free (uri);
-       }
-#else
-       pixbuf = NULL;
-#endif
-       image = gtk_image_new_from_pixbuf (pixbuf);
-       if (pixbuf)
-               g_object_unref (pixbuf);
-
-       if (view->show_icons)
-               gtk_widget_show (image);
-
-       menu_item = gtk_image_menu_item_new_with_mnemonic (text);
-       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item),
-                                      image);
-
-       label = GTK_BIN (menu_item)->child;
-       gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
-       gtk_label_set_max_width_chars (GTK_LABEL (label), view->label_width);
-
-       md = g_new0 (EggRecentViewGtkMenuData, 1);
-       md->view = view;
-       md->item = egg_recent_item_ref (item);
-
-       g_signal_connect_data (G_OBJECT (menu_item), "activate",
-                              G_CALLBACK (egg_recent_view_gtk_menu_cb),
-                              md,
-                              (GClosureNotify)egg_recent_view_gtk_destroy_cb,
-                              0);
-
-       g_free (mime_type);
-       g_free (text);
-
-       /*
-        * this is a tag so we can distinguish our menu items
-        * from others that may be in the menu.
-        */
-       g_object_set_data (G_OBJECT (menu_item),
-                          view->uid,
-                          GINT_TO_POINTER (1));
-
-
-       gtk_widget_show (menu_item);
-
-       return menu_item;
-}
-
-static void
-egg_recent_view_gtk_add_to_menu (EggRecentViewGtk *view,
-                                EggRecentItem *item,
-                                gint display,
-                                gint index)
-{
-       GtkWidget *menu_item;
-       gint menu_offset;
-       
-       g_return_if_fail (view);
-       g_return_if_fail (view->menu);
-
-       menu_offset = egg_recent_view_gtk_find_menu_offset (view);
-
-       if (item != NULL)
-               menu_item = egg_recent_view_gtk_new_menu_item (view, item, display);
-       else
-               menu_item = egg_recent_view_gtk_new_separator (view);
-
-       if (view->tooltip_func != NULL && menu_item != NULL) {
-               view->tooltip_func (view->tooltips, menu_item,
-                                   item, view->tooltip_func_data);
-       }
-       
-       if (menu_item)
-               gtk_menu_shell_insert (GTK_MENU_SHELL (view->menu), menu_item,
-                              menu_offset+index);
-}
-
-static void
-egg_recent_view_gtk_set_list (EggRecentViewGtk *view, GList *list)
-{
-       EggRecentItem *item;
-       GList *p;
-       gint display=1;
-       gint index=1;
-
-       if (view->menu == NULL)
-               return;
-
-       egg_recent_view_gtk_clear (view);
-
-       if (view->leading_sep) {
-               egg_recent_view_gtk_add_to_menu (view, NULL, display, index);
-               index++;
-       }
-
-       p = list;
-       while (p != NULL) {
-               item = (EggRecentItem *)p->data;
-
-               egg_recent_view_gtk_add_to_menu (view, item, display, index);
-
-               p = p->next;
-               display++;
-               index++;
-       }
-
-       if (view->trailing_sep)
-               egg_recent_view_gtk_add_to_menu (view, NULL, display, index);
-}
-
-static void
-model_changed_cb (EggRecentModel *model, GList *list, EggRecentViewGtk *view)
-{
-       if (list != NULL)
-               egg_recent_view_gtk_set_list (view, list);
-       else
-               egg_recent_view_gtk_clear (view);
-}
-
-static EggRecentModel *
-egg_recent_view_gtk_get_model (EggRecentView *view_parent)
-{
-       EggRecentViewGtk *view;
-       
-       g_return_val_if_fail (view_parent != NULL, NULL);
-       view = EGG_RECENT_VIEW_GTK (view_parent);
-       return view->model;
-}
-
-static void
-egg_recent_view_gtk_set_model (EggRecentView *view_parent,
-                                EggRecentModel *model)
-{
-       EggRecentViewGtk *view;
-       
-       g_return_if_fail (view_parent != NULL);
-       view = EGG_RECENT_VIEW_GTK (view_parent);
-
-       if (view->model != NULL) {
-               g_object_unref (view->model);
-               g_signal_handler_disconnect (G_OBJECT (model),
-                                            view->changed_cb_id);
-       }
-       
-       view->model = model;
-       g_object_ref (view->model);
-
-       view->changed_cb_id = g_signal_connect_object (G_OBJECT (model),
-                                               "changed",
-                                               G_CALLBACK (model_changed_cb),
-                                               view, 0);
-
-       egg_recent_model_changed (view->model);
-}
-
-void
-egg_recent_view_gtk_set_leading_sep (EggRecentViewGtk *view, gboolean val)
-{
-       view->leading_sep = val;
-
-       egg_recent_view_gtk_clear (view);
-
-       if (view->model)
-               egg_recent_model_changed (view->model);
-}
-
-void
-egg_recent_view_gtk_set_trailing_sep (EggRecentViewGtk *view, gboolean val)
-{
-       view->trailing_sep = val;
-
-       egg_recent_view_gtk_clear (view);
-
-       if (view->model)
-               egg_recent_model_changed (view->model);
-}
-
-static void
-egg_recent_view_gtk_set_property (GObject *object,
-                          guint prop_id,
-                          const GValue *value,
-                          GParamSpec *pspec)
-{
-       EggRecentViewGtk *view = EGG_RECENT_VIEW_GTK (object);
-
-       switch (prop_id)
-       {
-               case PROP_MENU:
-                       egg_recent_view_gtk_set_menu (view,
-                                              GTK_WIDGET (g_value_get_object (value)));
-               break;
-               case PROP_START_MENU_ITEM:
-                       egg_recent_view_gtk_set_start_menu_item (view,
-                                       g_value_get_object (value));
-               break;
-               case PROP_SHOW_ICONS:
-                       egg_recent_view_gtk_show_icons (view,
-                                       g_value_get_boolean (value));
-               break;
-               case PROP_SHOW_NUMBERS:
-                       egg_recent_view_gtk_show_numbers (view,
-                                       g_value_get_boolean (value));
-               break;
-               case PROP_LABEL_WIDTH:
-                       egg_recent_view_gtk_set_label_width (view,
-                                       g_value_get_int (value));
-               break;
-               default:
-                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-               break;
-       }
-}
-
-static void
-egg_recent_view_gtk_get_property (GObject *object,
-                          guint prop_id,
-                          GValue *value,
-                          GParamSpec *pspec)
-{
-       EggRecentViewGtk *view = EGG_RECENT_VIEW_GTK (object);
-
-       switch (prop_id)
-       {
-               case PROP_MENU:
-                       g_value_set_object (value, view->menu);
-               break;
-               case PROP_START_MENU_ITEM:
-                       g_value_set_object (value, view->start_menu_item);
-               break;
-               case PROP_SHOW_ICONS:
-                       g_value_set_boolean (value, view->show_icons);
-               break;
-               case PROP_SHOW_NUMBERS:
-                       g_value_set_boolean (value, view->show_numbers);
-               break;
-               case PROP_LABEL_WIDTH:
-                       g_value_set_int (value, view->label_width);
-               break;
-               default:
-                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-               break;
-       }
-}
-
-static void
-egg_recent_view_gtk_finalize (GObject *object)
-{
-       EggRecentViewGtk *view = EGG_RECENT_VIEW_GTK (object);
-
-       g_signal_handler_disconnect (G_OBJECT (view->model),
-                                    view->changed_cb_id);
-
-       g_free (view->uid);
-
-       g_object_unref (view->model);
-#ifndef USE_STABLE_LIBGNOMEUI
-       g_object_unref (view->theme);
-#endif
-       g_object_unref (view->client);
-
-       g_object_unref (view->tooltips);
-       
-       egg_recent_view_gtk_clear (view);
-}
-
-static void
-egg_recent_view_gtk_class_init (EggRecentViewGtkClass * klass)
-{
-       GObjectClass *object_class;
-
-       object_class = G_OBJECT_CLASS (klass);
-
-       object_class->set_property = egg_recent_view_gtk_set_property;
-       object_class->get_property = egg_recent_view_gtk_get_property;
-       object_class->finalize     = egg_recent_view_gtk_finalize;
-
-       view_signals[ACTIVATE] = g_signal_new ("activate",
-                       G_OBJECT_CLASS_TYPE (object_class),
-                       G_SIGNAL_RUN_LAST,
-                       G_STRUCT_OFFSET (EggRecentViewGtkClass, activate),
-                       NULL, NULL,
-                       g_cclosure_marshal_VOID__BOXED,
-                       G_TYPE_NONE, 1,
-                       EGG_TYPE_RECENT_ITEM);
-
-       g_object_class_install_property (object_class,
-                                        PROP_MENU,
-                                        g_param_spec_object ("menu",
-                                                             "Menu",
-                                                             "The GtkMenuShell this object will update.",
-                                                             gtk_menu_get_type(),
-                                                             G_PARAM_READWRITE));
-       g_object_class_install_property (object_class,
-                                        PROP_START_MENU_ITEM,
-                                        g_param_spec_object ("start-menu-item",
-                                                             "Start Menu Item",
-                                                             "The menu item that precedes where are menu items will go",
-                                                             gtk_menu_item_get_type (),
-                                                             G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_SHOW_ICONS,
-                                        g_param_spec_boolean ("show-icons",
-                                          "Show Icons",
-                                          "Whether or not to show icons",
-                                          FALSE,
-                                          G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_SHOW_NUMBERS,
-                                        g_param_spec_boolean ("show-numbers",
-                                          "Show Numbers",
-                                          "Whether or not to show numbers",
-                                          TRUE,
-                                          G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_LABEL_WIDTH,
-                                        g_param_spec_int ("label-width",
-                                          "Label Width",
-                                          "The desired width of the menu label, in characters",
-                                          -1,
-                                          G_MAXINT,
-                                          DEFAULT_LABEL_WIDTH,
-                                          G_PARAM_READWRITE));
-
-       klass->activate = NULL;
-}
-
-static void
-egg_recent_view_init (EggRecentViewClass *iface)
-{
-       iface->do_get_model = egg_recent_view_gtk_get_model;
-       iface->do_set_model = egg_recent_view_gtk_set_model;
-}
-
-static void
-show_menus_changed_cb (GConfClient *client,
-                      guint cnxn_id,
-                      GConfEntry *entry,
-                      EggRecentViewGtk *view)
-{
-       GConfValue *value;
-
-       value = gconf_entry_get_value (entry);
-
-       g_return_if_fail (value->type == GCONF_VALUE_BOOL);
-
-       egg_recent_view_gtk_show_icons (view,
-                               gconf_value_get_bool (value));
-
-}
-
-#ifndef USE_STABLE_LIBGNOMEUI
-static void
-theme_changed_cb (GnomeIconTheme *theme, EggRecentViewGtk *view)
-{
-       if (view->model != NULL)
-               egg_recent_model_changed (view->model);
-}
-#endif
-
-static void
-egg_recent_view_gtk_init (EggRecentViewGtk * view)
-{
-       view->client = gconf_client_get_default ();
-
-       view->show_icons =
-               gconf_client_get_bool (view->client,
-                       "/desktop/gnome/interface/menus_have_icons",
-                       NULL);
-
-       gconf_client_add_dir (view->client, "/desktop/gnome/interface",
-                             GCONF_CLIENT_PRELOAD_NONE,
-                             NULL);
-       gconf_client_notify_add (view->client,
-                       "/desktop/gnome/interface/menus_have_icons",
-                       (GConfClientNotifyFunc)show_menus_changed_cb,
-                       view, NULL, NULL);
-
-
-       view->leading_sep = FALSE;
-       view->trailing_sep = FALSE;
-
-       view->uid = egg_recent_util_get_unique_id ();
-#ifndef USE_STABLE_LIBGNOMEUI
-       view->theme = gnome_icon_theme_new ();
-       gnome_icon_theme_set_allow_svg (view->theme, TRUE);
-       g_signal_connect_object (view->theme, "changed",
-                                G_CALLBACK (theme_changed_cb), view, 0);
-#endif
-       view->tooltips = gtk_tooltips_new ();
-       g_object_ref (view->tooltips);
-       gtk_object_sink (GTK_OBJECT (view->tooltips));
-       view->tooltip_func = NULL;
-       view->tooltip_func_data = NULL;
-
-       view->icon_size = GTK_ICON_SIZE_MENU;
-
-       view->label_width = DEFAULT_LABEL_WIDTH;
-}
-
-void
-egg_recent_view_gtk_set_icon_size (EggRecentViewGtk *view,
-                                  GtkIconSize icon_size)
-{
-       if (view->icon_size != icon_size) {
-               view->icon_size = icon_size;
-               egg_recent_model_changed (view->model);
-       } else {
-               view->icon_size = icon_size;
-       }
-}
-
-GtkIconSize
-egg_recent_view_gtk_get_icon_size (EggRecentViewGtk *view)
-{
-       return view->icon_size;
-}
-
-void
-egg_recent_view_gtk_show_icons (EggRecentViewGtk *view, gboolean show)
-{
-       view->show_icons = show;
-
-       if (view->model)
-               egg_recent_model_changed (view->model);
-}
-
-void
-egg_recent_view_gtk_show_numbers (EggRecentViewGtk *view, gboolean show)
-{
-       view->show_numbers = show;
-
-       if (view->model)
-               egg_recent_model_changed (view->model);
-}
-
-void
-egg_recent_view_gtk_set_tooltip_func (EggRecentViewGtk *view,
-                                     EggRecentViewGtkTooltipFunc func,
-                                     gpointer user_data)
-{
-       view->tooltip_func = func;
-       view->tooltip_func_data = user_data;
-       
-       if (view->model)
-               egg_recent_model_changed (view->model);
-}
-
-void
-egg_recent_view_gtk_set_label_width (EggRecentViewGtk *view,
-                                    gint              chars)
-{
-       g_return_if_fail (EGG_IS_RECENT_VIEW_GTK (view));
-
-       view->label_width = chars;
-}
-
-gint
-egg_recent_view_gtk_get_label_width (EggRecentViewGtk *view)
-{
-       g_return_val_if_fail (EGG_IS_RECENT_VIEW_GTK (view), -1);
-
-       return view->label_width;
-}
-
-/**
- * egg_recent_view_gtk_set_menu:
- * @view: A EggRecentViewGtk object.
- * @menu: The GtkMenuShell to put the menu items in.
- *
- * Use this function to change the GtkMenuShell that the recent
- * documents appear in.
- *
- */
-void
-egg_recent_view_gtk_set_menu (EggRecentViewGtk *view,
-                               GtkWidget *menu)
-{
-       g_return_if_fail (view);
-       g_return_if_fail (EGG_IS_RECENT_VIEW_GTK (view));
-
-       if (view->menu != NULL)
-               g_object_remove_weak_pointer (G_OBJECT (view->menu),
-                                             (gpointer *) &view->menu);
-       
-       view->menu = menu;
-
-       if (view->menu != NULL)
-               g_object_add_weak_pointer (G_OBJECT (view->menu),
-                                          (gpointer *) &view->menu);
-}
-
-/**
- * egg_recent_view_gtk_set_start_menu_item:
- * @view: A EggRecentViewGtk object.
- * @start_menu_item: The menu item that appears just before where our menu
- * items should appear
- *
- */
-void
-egg_recent_view_gtk_set_start_menu_item (EggRecentViewGtk *view,
-                                        GtkWidget *menu_item)
-{
-       g_return_if_fail (view);
-       g_return_if_fail (EGG_IS_RECENT_VIEW_GTK (view));
-       
-       view->start_menu_item = menu_item;
-}
-
-/**
- * egg_recent_view_gtk_get_menu:
- * @view: A EggRecentViewGtk object.
- *
- */
-GtkWidget *
-egg_recent_view_gtk_get_menu (EggRecentViewGtk *view)
-{
-       return view->menu;
-}
-
-/**
- * egg_recent_view_gtk_get_start_menu_item
- * @view: A EggRecentViewGtk object.
- *
- */
-GtkWidget *
-egg_recent_view_gtk_get_start_menu_item (EggRecentViewGtk *view)
-{
-       return view->start_menu_item;
-}
-
-
-/**
- * egg_recent_view_gtk_new:
- * @appname: The name of your application.
- * @limit:  The maximum number of items allowed.
- *
- * This creates a new EggRecentViewGtk object.
- *
- * Returns: a EggRecentViewGtk object
- */
-EggRecentViewGtk *
-egg_recent_view_gtk_new (GtkWidget *menu, GtkWidget *start_menu_item)
-{
-       EggRecentViewGtk *view;
-
-       g_return_val_if_fail (menu, NULL);
-
-       view = EGG_RECENT_VIEW_GTK (g_object_new (egg_recent_view_gtk_get_type (),
-                                          "start-menu-item",
-                                          start_menu_item,
-                                          "menu", menu,
-                                          "show-numbers", TRUE, NULL));
-
-       g_return_val_if_fail (view, NULL);
-       
-       return view;
-}
-
-/**
- * egg_recent_view_gtk_get_type:
- *
- * This returns a GType representing a EggRecentViewGtk object.
- *
- * Returns: a GType
- */
-GType
-egg_recent_view_gtk_get_type (void)
-{
-       static GType egg_recent_view_gtk_type = 0;
-
-       if(!egg_recent_view_gtk_type) {
-               static const GTypeInfo egg_recent_view_gtk_info = {
-                       sizeof (EggRecentViewGtkClass),
-                       NULL, /* base init */
-                       NULL, /* base finalize */
-                       (GClassInitFunc)egg_recent_view_gtk_class_init, /* class init */
-                       NULL, /* class finalize */
-                       NULL, /* class data */
-                       sizeof (EggRecentViewGtk),
-                       0,
-                       (GInstanceInitFunc) egg_recent_view_gtk_init
-               };
-
-               static const GInterfaceInfo view_info =
-               {
-                       (GInterfaceInitFunc) egg_recent_view_init,
-                       NULL,
-                       NULL
-               };
-
-               egg_recent_view_gtk_type = g_type_register_static (G_TYPE_OBJECT,
-                                                       "EggRecentViewGtk",
-                                                       &egg_recent_view_gtk_info, 0);
-               g_type_add_interface_static (egg_recent_view_gtk_type,
-                                            EGG_TYPE_RECENT_VIEW,
-                                            &view_info);
-       }
-
-       return egg_recent_view_gtk_type;
-}
-
diff --git a/cut-n-paste/recent-files/egg-recent-view-gtk.h b/cut-n-paste/recent-files/egg-recent-view-gtk.h
deleted file mode 100644 (file)
index 287f3e0..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-#ifndef __EGG_RECENT_VIEW_GTK_H__
-#define __EGG_RECENT_VIEW_GTK_H__
-
-G_BEGIN_DECLS
-
-#include <gtk/gtk.h>
-#include "egg-recent-item.h"
-
-#define EGG_RECENT_VIEW_GTK(obj)               G_TYPE_CHECK_INSTANCE_CAST (obj, egg_recent_view_gtk_get_type (), EggRecentViewGtk)
-#define EGG_RECENT_VIEW_GTK_CLASS(klass)       G_TYPE_CHECK_CLASS_CAST (klass, egg_recent_view_gtk_get_type (), EggRecentViewGtkClass)
-#define EGG_IS_RECENT_VIEW_GTK(obj)            G_TYPE_CHECK_INSTANCE_TYPE (obj, egg_recent_view_gtk_get_type ())
-
-typedef void (*EggRecentViewGtkTooltipFunc) (GtkTooltips *tooltips,
-                                            GtkWidget *menu,
-                                            EggRecentItem *item,
-                                            gpointer user_data);
-
-typedef struct _EggRecentViewGtk EggRecentViewGtk;
-
-typedef struct _EggRecentViewGtkClass EggRecentViewGtkClass;
-
-struct _EggRecentViewGtkClass {
-       GObjectClass parent_class;
-       
-       void (*activate) (EggRecentViewGtk *view, EggRecentItem *item);
-};
-
-GType        egg_recent_view_gtk_get_type (void);
-
-EggRecentViewGtk * egg_recent_view_gtk_new (GtkWidget *menu,
-                                           GtkWidget *start_menu_item);
-
-void egg_recent_view_gtk_set_menu            (EggRecentViewGtk *view,
-                                               GtkWidget *menu);
-GtkWidget * egg_recent_view_gtk_get_menu     (EggRecentViewGtk *view);
-
-
-void egg_recent_view_gtk_set_start_menu_item (EggRecentViewGtk *view,
-                                             GtkWidget *menu_item);
-GtkWidget *egg_recent_view_gtk_get_start_menu_item     (EggRecentViewGtk *view);
-
-void egg_recent_view_gtk_set_leading_sep     (EggRecentViewGtk *view,
-                                               gboolean val);
-
-void egg_recent_view_gtk_set_trailing_sep    (EggRecentViewGtk *view,
-                                               gboolean val);
-
-void egg_recent_view_gtk_show_icons          (EggRecentViewGtk *view,
-                                             gboolean show);
-void egg_recent_view_gtk_show_numbers        (EggRecentViewGtk *view,
-                                             gboolean show);
-
-void egg_recent_view_gtk_set_tooltip_func    (EggRecentViewGtk *view,
-                                             EggRecentViewGtkTooltipFunc func,
-                                             gpointer user_data);
-
-void egg_recent_view_gtk_set_icon_size       (EggRecentViewGtk *view,
-                                             GtkIconSize icon_size);
-GtkIconSize egg_recent_view_gtk_get_icon_size (EggRecentViewGtk *view);
-
-void egg_recent_view_gtk_set_label_width    (EggRecentViewGtk *view,
-                                            gint              chars);
-gint egg_recent_view_gtk_get_label_width    (EggRecentViewGtk *view);
-
-G_END_DECLS
-
-#endif /* __EGG_RECENT_VIEW_GTK_H__ */
diff --git a/cut-n-paste/recent-files/egg-recent-view-uimanager.c b/cut-n-paste/recent-files/egg-recent-view-uimanager.c
new file mode 100644 (file)
index 0000000..1ae6f3e
--- /dev/null
@@ -0,0 +1,746 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ *   James Willcox <jwillcox@cs.indiana.edu>
+ *   Paolo Bacchilega <paobac@cvs.gnome.org>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <gtk/gtk.h>
+#include <libgnomevfs/gnome-vfs.h>
+#ifndef USE_STABLE_LIBGNOMEUI
+#include <libgnomeui/gnome-icon-theme.h>
+#endif
+#include <gconf/gconf-client.h>
+#include "egg-recent-model.h"
+#include "egg-recent-view.h"
+#include "egg-recent-view-uimanager.h"
+#include "egg-recent-util.h"
+#include "egg-recent-item.h"
+
+#define EGG_RECENT_NAME_PREFIX "EggRecentAction"
+#define EGG_RECENT_ACTION "EggRecentFile"
+#define EGG_RECENT_SEPARATOR (NULL)
+
+struct _EggRecentViewUIManager {
+       GObject         parent_instance;
+
+       GCallback       action_callback;
+       gpointer        action_user_data;
+
+       gboolean        leading_sep;
+       gboolean        trailing_sep;
+
+       GtkUIManager   *uimanager;
+       GtkActionGroup *action_group;
+       guint           merge_id;
+       gulong          changed_cb_id;
+
+       gchar          *path;
+
+       gboolean        show_icons;
+       gboolean        show_numbers;
+#ifndef USE_STABLE_LIBGNOMEUI
+       GnomeIconTheme *theme;
+#endif
+
+       EggUIManagerTooltipFunc tooltip_func;
+       gpointer        tooltip_func_data;
+
+       EggRecentModel *model;
+       GConfClient    *client;
+       GtkIconSize     icon_size;
+};
+
+
+struct _EggRecentViewUIManagerMenuData {
+       EggRecentViewUIManager *view;
+       EggRecentItem *item;
+};
+
+typedef struct _EggRecentViewUIManagerMenuData EggRecentViewUIManagerMenuData;
+
+enum {
+       ACTIVATE,
+       LAST_SIGNAL
+};
+
+/* GObject properties */
+enum {
+       PROP_BOGUS,
+       PROP_UIMANAGER,
+       PROP_PATH,
+       PROP_SHOW_ICONS,
+       PROP_SHOW_NUMBERS
+};
+
+static guint view_signals[LAST_SIGNAL] = { 0 };
+
+static void
+egg_recent_view_uimanager_clear (EggRecentViewUIManager *view)
+{
+       if (view->merge_id != 0) {
+               gtk_ui_manager_remove_ui (view->uimanager, view->merge_id);
+               view->merge_id = 0;
+       }
+
+       if (view->action_group != NULL) {
+               gtk_ui_manager_remove_action_group (view->uimanager, view->action_group);
+               g_object_unref (view->action_group);
+               view->action_group = NULL;
+       }
+
+       gtk_ui_manager_ensure_update (view->uimanager);
+}
+
+static void
+egg_recent_view_uimanager_set_list (EggRecentViewUIManager *view, GList *list)
+{
+       GList  *scan;
+       guint   index = 1;
+
+       g_return_if_fail (view);
+
+       egg_recent_view_uimanager_clear (view);
+
+       if (view->merge_id == 0)
+               view->merge_id = gtk_ui_manager_new_merge_id (view->uimanager);
+
+       if (view->action_group == NULL) {
+               gchar *group = g_strdup_printf ("EggRecentActions%u", 
+                                               view->merge_id);
+               view->action_group = gtk_action_group_new (group);
+               gtk_ui_manager_insert_action_group (view->uimanager, view->action_group, 0);
+               g_free (group);
+       }
+
+       if (view->leading_sep) {
+               gchar *action = g_strdup_printf ("EggRecentLeadingSeparator%u",
+                                                view->merge_id);
+               gtk_ui_manager_add_ui (view->uimanager, 
+                                      view->merge_id, 
+                                      view->path,
+                                      action,
+                                      EGG_RECENT_SEPARATOR,
+                                      GTK_UI_MANAGER_AUTO, 
+                                      FALSE);
+               g_free (action);
+       }
+
+       for (scan = list; scan; scan = scan->next, index++) {
+               EggRecentItem *item = scan->data;
+               GtkAction     *action;
+               gchar         *name;
+               gchar         *uri;
+               gchar         *basename;
+               gchar         *escaped;
+               gchar         *ellipsized;
+               gchar         *label;
+               gchar         *tooltip = NULL;
+
+               uri = egg_recent_item_get_uri_for_display (item);
+               if (uri == NULL)
+                       continue;
+
+               name = g_strdup_printf (EGG_RECENT_NAME_PREFIX"%u-%u", 
+                                       view->merge_id,
+                                       index);
+
+               if (view->tooltip_func != NULL)
+                       tooltip = (*view->tooltip_func) (item, view->tooltip_func_data);
+
+               basename = g_path_get_basename (uri);
+               escaped = egg_recent_util_escape_underlines (basename);
+               g_free (basename);
+               g_free (uri);
+           
+               if (strlen (escaped) > 40) {
+                       ellipsized = g_strdup_printf ("%.40s...", escaped);
+                       g_free (escaped);
+               } else {        
+                       ellipsized = escaped;
+               }
+
+               if (view->show_numbers) {
+                       if (index >= 10)
+                               label = g_strdup_printf ("%d.  %s", 
+                                                        index, 
+                                                        ellipsized);
+                       else
+                               label = g_strdup_printf ("_%d.  %s", 
+                                                        index, 
+                                                        ellipsized);
+                       g_free (ellipsized);
+               } else 
+                       label = ellipsized;
+
+               action = g_object_new (GTK_TYPE_ACTION,
+                                      "name", name,
+                                      "label", label,
+                                      (view->show_icons)? "stock_id": NULL, 
+                                      GTK_STOCK_OPEN,
+                                      NULL);
+               if (tooltip != NULL) {
+                       g_object_set (action, "tooltip", tooltip, NULL);
+                       g_free (tooltip);
+               }
+               egg_recent_item_ref (item);
+               g_object_set_data_full (G_OBJECT (action), 
+                                       "egg_recent_uri", 
+                                       item, 
+                                       (GFreeFunc) egg_recent_item_unref);
+
+               if (view->action_callback != NULL) {
+                       GClosure *closure;
+                       closure = g_cclosure_new (view->action_callback, view->action_user_data, NULL);
+                       g_signal_connect_closure (action, "activate", closure, FALSE);
+               }
+
+               gtk_action_group_add_action (view->action_group, action);
+               g_object_unref (action);
+
+               gtk_ui_manager_add_ui (view->uimanager, 
+                                      view->merge_id, 
+                                      view->path,
+                                      name,
+                                      name,
+                                      GTK_UI_MANAGER_AUTO, 
+                                      FALSE);
+
+               g_free (name);
+               g_free (label);
+       }
+
+       if (view->trailing_sep) {
+               gchar *action = g_strdup_printf ("EggRecentTrailingSeparator%u",
+                                               view->merge_id);
+               gtk_ui_manager_add_ui (view->uimanager, 
+                                      view->merge_id, 
+                                      view->path,
+                                      action,
+                                      EGG_RECENT_SEPARATOR,
+                                      GTK_UI_MANAGER_AUTO, 
+                                      FALSE);
+               g_free (action);
+       }
+}
+
+static void
+model_changed_cb (EggRecentModel         *model,  
+                 GList                  *list, 
+                 EggRecentViewUIManager *view)
+{
+       if (list != NULL)
+               egg_recent_view_uimanager_set_list (view, list);
+       else
+               egg_recent_view_uimanager_clear (view);
+       gtk_ui_manager_ensure_update (view->uimanager);
+}
+
+static EggRecentModel *
+egg_recent_view_uimanager_get_model (EggRecentView *view_parent)
+{
+       EggRecentViewUIManager *view;
+       
+       g_return_val_if_fail (view_parent != NULL, NULL);
+       view = EGG_RECENT_VIEW_UIMANAGER (view_parent);
+       return view->model;
+}
+
+static void
+egg_recent_view_uimanager_set_model (EggRecentView  *view_parent,
+                                    EggRecentModel *model)
+{
+       EggRecentViewUIManager *view;
+       
+       g_return_if_fail (view_parent != NULL);
+       view = EGG_RECENT_VIEW_UIMANAGER (view_parent);
+
+       if (view->model != NULL) {
+               if (view->changed_cb_id != 0)
+                       g_signal_handler_disconnect (G_OBJECT (view->model),
+                                                    view->changed_cb_id);
+               g_object_unref (view->model);
+       }
+       
+       view->model = model;
+       g_object_ref (view->model);
+
+       view->changed_cb_id = g_signal_connect_object (G_OBJECT (model),
+                                                      "changed",
+                                                      G_CALLBACK (model_changed_cb),
+                                                      view, 0);
+
+       egg_recent_model_changed (view->model);
+}
+
+void
+egg_recent_view_uimanager_set_leading_sep (EggRecentViewUIManager *view, 
+                                          gboolean                val)
+{
+       view->leading_sep = val;
+       egg_recent_view_uimanager_clear (view);
+       if (view->model)
+               egg_recent_model_changed (view->model);
+}
+
+void
+egg_recent_view_uimanager_set_trailing_sep (EggRecentViewUIManager *view,
+                                           gboolean                val)
+{
+       view->trailing_sep = val;
+       egg_recent_view_uimanager_clear (view);
+       if (view->model)
+               egg_recent_model_changed (view->model);
+}
+
+static void
+egg_recent_view_uimanager_set_property (GObject      *object,
+                                       guint         prop_id,
+                                       const GValue *value,
+                                       GParamSpec   *pspec)
+{
+       EggRecentViewUIManager *view = EGG_RECENT_VIEW_UIMANAGER (object);
+
+       switch (prop_id) {
+       case PROP_UIMANAGER:
+               egg_recent_view_uimanager_set_uimanager (view, (GtkUIManager*)g_value_get_object (value));
+               break;
+       case PROP_PATH:
+               egg_recent_view_uimanager_set_path (view, g_value_get_string (value));
+               break;
+       case PROP_SHOW_ICONS:
+               egg_recent_view_uimanager_show_icons (view, g_value_get_boolean (value));
+               break;
+       case PROP_SHOW_NUMBERS:
+               egg_recent_view_uimanager_show_numbers (view, g_value_get_boolean (value));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+egg_recent_view_uimanager_get_property (GObject    *object,
+                                       guint       prop_id,
+                                       GValue     *value,
+                                       GParamSpec *pspec)
+{
+       EggRecentViewUIManager *view = EGG_RECENT_VIEW_UIMANAGER (object);
+
+       switch (prop_id) {
+       case PROP_UIMANAGER:
+               g_value_set_object (value, view->uimanager);
+               break;
+       case PROP_PATH:
+               g_value_set_string (value, view->path);
+               break;
+       case PROP_SHOW_ICONS:
+               g_value_set_boolean (value, view->show_icons);
+               break;
+       case PROP_SHOW_NUMBERS:
+               g_value_set_boolean (value, view->show_numbers);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+egg_recent_view_uimanager_finalize (GObject *object)
+{
+       EggRecentViewUIManager *view = EGG_RECENT_VIEW_UIMANAGER (object);
+
+       if (view->changed_cb_id != 0) {
+               g_signal_handler_disconnect (G_OBJECT (view->model),
+                                            view->changed_cb_id);
+               view->changed_cb_id = 0;
+       }
+
+       g_free (view->path);
+
+       egg_recent_view_uimanager_clear (view);
+
+       if (view->action_group != NULL) {
+               g_object_unref (view->action_group);
+               view->action_group = NULL;
+       }
+
+       if (view->uimanager != NULL) {
+               g_object_unref (view->uimanager);
+               view->uimanager = NULL;
+       }
+
+       if (view->model != NULL) {
+               g_object_unref (view->model);
+               view->model = NULL;
+       }
+
+#ifndef USE_STABLE_LIBGNOMEUI
+       if (view->theme != NULL) {
+               g_object_unref (view->theme);
+               view->theme = NULL;
+       }
+#endif
+
+       if (view->client != NULL) {
+               g_object_unref (view->client);
+               view->client = NULL;
+       }
+}
+
+static void
+egg_recent_view_uimanager_class_init (EggRecentViewUIManagerClass * klass)
+{
+       GObjectClass *object_class;
+
+       object_class = G_OBJECT_CLASS (klass);
+
+       object_class->set_property = egg_recent_view_uimanager_set_property;
+       object_class->get_property = egg_recent_view_uimanager_get_property;
+       object_class->finalize     = egg_recent_view_uimanager_finalize;
+
+       view_signals[ACTIVATE] = g_signal_new ("activate",
+                                              G_OBJECT_CLASS_TYPE (object_class),
+                                              G_SIGNAL_RUN_LAST,
+                                              G_STRUCT_OFFSET (EggRecentViewUIManagerClass, activate),
+                                              NULL, NULL,
+                                              g_cclosure_marshal_VOID__BOXED,
+                                              G_TYPE_NONE, 1,
+                                              EGG_TYPE_RECENT_ITEM);
+
+       g_object_class_install_property (object_class,
+                                        PROP_UIMANAGER,
+                                        g_param_spec_object ("uimanager",
+                                                             "UI Manager",
+                                                             "The UI manager this object will use to update.the UI",
+                                                             GTK_TYPE_UI_MANAGER,
+                                                             G_PARAM_READWRITE));
+       g_object_class_install_property (object_class,
+                                        PROP_PATH,
+                                        g_param_spec_string ("path",
+                                                             "Path",
+                                                             "The UI path this object will update.",
+                                                             NULL,
+                                                             G_PARAM_READWRITE));
+       g_object_class_install_property (object_class,
+                                        PROP_SHOW_ICONS,
+                                        g_param_spec_boolean ("show-icons",
+                                                              "Show Icons",
+                                                              "Whether or not to show icons",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE));
+       
+       g_object_class_install_property (object_class,
+                                        PROP_SHOW_NUMBERS,
+                                        g_param_spec_boolean ("show-numbers",
+                                                              "Show Numbers",
+                                                              "Whether or not to show numbers",
+                                                              TRUE,
+                                                              G_PARAM_READWRITE));
+
+       klass->activate = NULL;
+}
+
+static void
+egg_recent_view_init (EggRecentViewClass *iface)
+{
+       iface->do_get_model = egg_recent_view_uimanager_get_model;
+       iface->do_set_model = egg_recent_view_uimanager_set_model;
+}
+
+static void
+show_menus_changed_cb (GConfClient            *client,
+                      guint                   cnxn_id,
+                      GConfEntry             *entry,
+                      EggRecentViewUIManager *view)
+{
+       GConfValue *value;
+
+       value = gconf_entry_get_value (entry);
+       g_return_if_fail (value->type == GCONF_VALUE_BOOL);
+
+       egg_recent_view_uimanager_show_icons (view, gconf_value_get_bool (value));
+}
+
+#ifndef USE_STABLE_LIBGNOMEUI
+static void
+theme_changed_cb (GnomeIconTheme         *theme, 
+                 EggRecentViewUIManager *view)
+{
+       if (view->model != NULL)
+               egg_recent_model_changed (view->model);
+}
+#endif
+
+static void
+egg_recent_view_uimanager_init (EggRecentViewUIManager * view)
+{
+       view->client = gconf_client_get_default ();
+
+       view->show_icons = gconf_client_get_bool (view->client,
+                                                 "/desktop/gnome/interface/menus_have_icons",
+                                                 NULL);
+       
+       gconf_client_add_dir (view->client, "/desktop/gnome/interface",
+                             GCONF_CLIENT_PRELOAD_NONE,
+                             NULL);
+       gconf_client_notify_add (view->client,
+                                "/desktop/gnome/interface/menus_have_icons",
+                                (GConfClientNotifyFunc)show_menus_changed_cb,
+                                view, NULL, NULL);
+
+
+       view->leading_sep = FALSE;
+       view->trailing_sep = FALSE;
+       view->show_numbers = TRUE;
+
+       view->uimanager = NULL;
+       view->action_group = NULL;
+       view->merge_id = 0;
+       view->changed_cb_id = 0;
+
+       view->path = NULL;
+
+#ifndef USE_STABLE_LIBGNOMEUI
+       view->theme = gnome_icon_theme_new ();
+       gnome_icon_theme_set_allow_svg (view->theme, TRUE);
+       g_signal_connect_object (view->theme, "changed",
+                                G_CALLBACK (theme_changed_cb), view, 0);
+#endif
+
+       view->tooltip_func = NULL;
+       view->tooltip_func_data = NULL;
+
+       view->icon_size = GTK_ICON_SIZE_MENU;
+}
+
+void
+egg_recent_view_uimanager_set_icon_size (EggRecentViewUIManager *view,
+                                        GtkIconSize             icon_size)
+{
+       if (view->icon_size != icon_size) {
+               view->icon_size = icon_size;
+               egg_recent_model_changed (view->model);
+       } else {
+               view->icon_size = icon_size;
+       }
+}
+
+GtkIconSize
+egg_recent_view_uimanager_get_icon_size (EggRecentViewUIManager *view)
+{
+       return view->icon_size;
+}
+
+void
+egg_recent_view_uimanager_show_icons (EggRecentViewUIManager *view,
+                                     gboolean                show)
+{
+       view->show_icons = show;
+       if (view->model != NULL)
+               egg_recent_model_changed (view->model);
+}
+
+void
+egg_recent_view_uimanager_show_numbers (EggRecentViewUIManager *view, 
+                                       gboolean                show)
+{
+       view->show_numbers = show;
+       if (view->model != NULL)
+               egg_recent_model_changed (view->model);
+}
+
+void
+egg_recent_view_uimanager_set_tooltip_func (EggRecentViewUIManager   *view,
+                                           EggUIManagerTooltipFunc   func,
+                                           gpointer                  user_data)
+{
+       view->tooltip_func = func;
+       view->tooltip_func_data = user_data;
+       if (view->model)
+               egg_recent_model_changed (view->model);
+}
+
+/**
+ * egg_recent_view_uimanager_set_uimanager:
+ * @view: A EggRecentViewUIManager object.
+ * @uimanager: The ui manager used to put the menu items in.
+ *
+ * Use this function to change the ui manager used to update the menu.
+ *
+ */
+void
+egg_recent_view_uimanager_set_uimanager (EggRecentViewUIManager *view,
+                                        GtkUIManager           *uimanager)
+{
+       g_return_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view));
+       g_return_if_fail (uimanager != NULL);
+
+       if (view->uimanager != NULL)
+               g_object_unref (view->uimanager);
+       view->uimanager = uimanager;
+       g_object_ref (view->uimanager);
+}
+
+/**
+ * egg_recent_view_uimanager_get_uimanager:
+ * @view: A EggRecentViewUIManager object.
+ *
+ */
+GtkUIManager*
+egg_recent_view_uimanager_get_uimanager (EggRecentViewUIManager *view)
+{
+       g_return_val_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view), NULL);
+       return view->uimanager;
+}
+
+/**
+ * egg_recent_view_uimanager_set_path:
+ * @view: A EggRecentViewUIManager object.
+ * @path: The path to put the menu items in.
+ *
+ * Use this function to change the path where the recent
+ * documents appear in.
+ *
+ */
+void
+egg_recent_view_uimanager_set_path (EggRecentViewUIManager *view,
+                                   const gchar            *path)
+{
+       g_return_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view));
+       g_return_if_fail (path);
+
+       g_free (view->path);
+       view->path = g_strdup (path);
+}
+
+/**
+ * egg_recent_view_uimanager_get_path:
+ * @view: A EggRecentViewUIManager object.
+ *
+ */
+G_CONST_RETURN gchar*
+egg_recent_view_uimanager_get_path (EggRecentViewUIManager *view)
+{
+       g_return_val_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view), NULL);
+       return view->path;
+}
+
+void
+egg_recent_view_uimanager_set_action_func (EggRecentViewUIManager   *view,
+                                          GCallback                 callback,
+                                          gpointer                  user_data)
+{
+       g_return_if_fail (EGG_IS_RECENT_VIEW_UIMANAGER (view));
+       view->action_callback = callback;
+       view->action_user_data = user_data;
+}
+
+/**
+ * egg_recent_view_uimanager_new:
+ * @appname: The name of your application.
+ * @limit:  The maximum number of items allowed.
+ *
+ * This creates a new EggRecentViewUIManager object.
+ *
+ * Returns: a EggRecentViewUIManager object
+ */
+EggRecentViewUIManager *
+egg_recent_view_uimanager_new (GtkUIManager  *uimanager,
+                              const gchar   *path,
+                              GCallback      callback,
+                              gpointer       user_data)
+{
+       GObject *view;
+
+       g_return_val_if_fail (uimanager, NULL);
+       g_return_val_if_fail (path, NULL);
+
+       view = g_object_new (egg_recent_view_uimanager_get_type (),
+                            "uimanager", uimanager,
+                            "path", path,
+                            NULL);
+
+       g_return_val_if_fail (view, NULL);
+       
+       egg_recent_view_uimanager_set_action_func (EGG_RECENT_VIEW_UIMANAGER (view),
+                                                  callback,
+                                                  user_data);
+
+       return EGG_RECENT_VIEW_UIMANAGER (view);
+}
+
+/**
+ * egg_recent_view_uimanager_get_type:
+ * @:
+ *
+ * This returns a GType representing a EggRecentViewUIManager object.
+ *
+ * Returns: a GType
+ */
+GType
+egg_recent_view_uimanager_get_type (void)
+{
+       static GType egg_recent_view_uimanager_type = 0;
+
+       if(!egg_recent_view_uimanager_type) {
+               static const GTypeInfo egg_recent_view_uimanager_info = {
+                       sizeof (EggRecentViewUIManagerClass),
+                       NULL, /* base init */
+                       NULL, /* base finalize */
+                       (GClassInitFunc)egg_recent_view_uimanager_class_init, /* class init */
+                       NULL, /* class finalize */
+                       NULL, /* class data */
+                       sizeof (EggRecentViewUIManager),
+                       0,
+                       (GInstanceInitFunc) egg_recent_view_uimanager_init
+               };
+
+               static const GInterfaceInfo view_info =
+               {
+                       (GInterfaceInitFunc) egg_recent_view_init,
+                       NULL,
+                       NULL
+               };
+
+               egg_recent_view_uimanager_type = g_type_register_static (G_TYPE_OBJECT,
+                                                                        "EggRecentViewUIManager",
+                                                                        &egg_recent_view_uimanager_info, 0);
+               g_type_add_interface_static (egg_recent_view_uimanager_type,
+                                            EGG_TYPE_RECENT_VIEW,
+                                            &view_info);
+       }
+
+       return egg_recent_view_uimanager_type;
+}
+
+EggRecentItem*
+egg_recent_view_uimanager_get_item (EggRecentViewUIManager   *view,
+                                   GtkAction                *action)
+{
+       return g_object_get_data (G_OBJECT(action), "egg_recent_uri");
+}
diff --git a/cut-n-paste/recent-files/egg-recent-view-uimanager.h b/cut-n-paste/recent-files/egg-recent-view-uimanager.h
new file mode 100644 (file)
index 0000000..b6eadfa
--- /dev/null
@@ -0,0 +1,60 @@
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+#ifndef __EGG_RECENT_VIEW_UIMANAGER_H__
+#define __EGG_RECENT_VIEW_UIMANAGER_H__
+
+
+#include <gtk/gtk.h>
+#include "egg-recent-item.h"
+
+G_BEGIN_DECLS
+
+#define EGG_RECENT_VIEW_UIMANAGER(obj)         G_TYPE_CHECK_INSTANCE_CAST (obj, egg_recent_view_uimanager_get_type (), EggRecentViewUIManager)
+#define EGG_RECENT_VIEW_UIMANAGER_CLASS(klass)         G_TYPE_CHECK_CLASS_CAST (klass, egg_recent_view_uimanager_get_type (), EggRecentViewUIManagerClass)
+#define EGG_IS_RECENT_VIEW_UIMANAGER(obj)      G_TYPE_CHECK_INSTANCE_TYPE (obj, egg_recent_view_uimanager_get_type ())
+
+typedef char* (*EggUIManagerTooltipFunc) (EggRecentItem *item,
+                                         gpointer       user_data);
+
+typedef struct _EggRecentViewUIManager      EggRecentViewUIManager;
+typedef struct _EggRecentViewUIManagerClass EggRecentViewUIManagerClass;
+
+struct _EggRecentViewUIManagerClass {
+       GObjectClass parent_class;
+       void (*activate) (EggRecentViewUIManager *view, EggRecentItem *item);
+};
+
+GType                   egg_recent_view_uimanager_get_type         (void);
+EggRecentViewUIManager *egg_recent_view_uimanager_new              (GtkUIManager             *uimanager,
+                                                                   const gchar              *path,
+                                                                   GCallback                 callback,
+                                                                   gpointer                  user_data);
+void                    egg_recent_view_uimanager_set_uimanager    (EggRecentViewUIManager   *view,
+                                                                   GtkUIManager             *uimanager);
+GtkUIManager*           egg_recent_view_uimanager_get_uimanager    (EggRecentViewUIManager *view);
+void                    egg_recent_view_uimanager_set_path         (EggRecentViewUIManager   *view,
+                                                                   const gchar              *path);
+G_CONST_RETURN gchar   *egg_recent_view_uimanager_get_path         (EggRecentViewUIManager   *view);
+void                    egg_recent_view_uimanager_set_action_func  (EggRecentViewUIManager   *view,
+                                                                   GCallback                 callback,
+                                                                   gpointer                  user_data);
+void                    egg_recent_view_uimanager_set_leading_sep  (EggRecentViewUIManager   *view,
+                                                                   gboolean                  val);
+void                    egg_recent_view_uimanager_set_trailing_sep (EggRecentViewUIManager   *view,
+                                                                   gboolean                  val);
+void                    egg_recent_view_uimanager_show_icons       (EggRecentViewUIManager   *view,
+                                                                   gboolean                  show);
+void                    egg_recent_view_uimanager_show_numbers     (EggRecentViewUIManager   *view,
+                                                                   gboolean                  show);
+void                    egg_recent_view_uimanager_set_tooltip_func (EggRecentViewUIManager   *view,
+                                                                   EggUIManagerTooltipFunc   func,
+                                                                   gpointer                  user_data);
+void                    egg_recent_view_uimanager_set_icon_size    (EggRecentViewUIManager   *view,
+                                                                   GtkIconSize               icon_size);
+GtkIconSize             egg_recent_view_uimanager_get_icon_size    (EggRecentViewUIManager   *view);
+EggRecentItem          *egg_recent_view_uimanager_get_item         (EggRecentViewUIManager   *view,
+                                                                   GtkAction                *action);
+
+G_END_DECLS
+
+
+#endif /* __EGG_RECENT_VIEW_UIMANAGER_H__ */
index 81e4f316cf2f3c63b745434e69a0480dd7d09809..29141d224a588b9b73dcc2d95400be296efefc43 100644 (file)
@@ -48,7 +48,7 @@
 #include "ev-statusbar.h"
 #include "ev-sidebar-page.h"
 #include "eggfindbar.h"
-#include "egg-recent-view-gtk.h"
+#include "egg-recent-view-uimanager.h"
 #include "egg-recent-view.h"
 #include "egg-recent-model.h"
 #include "egg-toolbar-editor.h"
@@ -137,7 +137,7 @@ struct _EvWindowPrivate {
 
        /* recent file stuff */
        EggRecentModel *recent_model;
-       EggRecentViewGtk *recent_view;
+       EggRecentViewUIManager *recent_view;
 };
 
 static const GtkTargetEntry ev_drop_types[] = {
@@ -958,14 +958,18 @@ ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
 }
 
 static void
-ev_window_cmd_recent_file_activate (EggRecentViewGtk *view, EggRecentItem *item,
+ev_window_cmd_recent_file_activate (GtkAction *action,
                                    EvWindow *ev_window)
 {
        char *uri;
+       EggRecentItem *item;
        GtkWidget *window;
 
-       uri = egg_recent_item_get_uri (item);
+       item = egg_recent_view_uimanager_get_item (ev_window->priv->recent_view,
+                                                  action);
 
+       uri = egg_recent_item_get_uri (item);
+       
        window = GTK_WIDGET (ev_application_get_empty_window (EV_APP));
        gtk_widget_show (window);
        ev_window_open_uri (EV_WINDOW (window), uri);
@@ -986,23 +990,20 @@ ev_window_add_recent (EvWindow *window, const char *filename)
 static void
 ev_window_setup_recent (EvWindow *ev_window)
 {
-       GtkWidget *menu_item;
-       GtkWidget *menu;
 
-       menu_item = gtk_ui_manager_get_widget (ev_window->priv->ui_manager, "/MainMenu/FileMenu");
-       menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu_item));
-       menu_item = gtk_ui_manager_get_widget (ev_window->priv->ui_manager, "/MainMenu/FileMenu/RecentFilesMenu");
 
-       g_return_if_fail (menu != NULL);
-       g_return_if_fail (menu_item != NULL);
 
        /* it would be better if we just filtered by mime-type, but there
         * doesn't seem to be an easy way to figure out which mime-types we
         * can handle */
        ev_window->priv->recent_model = egg_recent_model_new (EGG_RECENT_MODEL_SORT_MRU);
 
-       ev_window->priv->recent_view = egg_recent_view_gtk_new (menu, menu_item);
-       egg_recent_view_gtk_show_icons (EGG_RECENT_VIEW_GTK (ev_window->priv->recent_view), FALSE);
+       ev_window->priv->recent_view = egg_recent_view_uimanager_new (ev_window->priv->ui_manager,
+                                                                     "/MainMenu/FileMenu/RecentFilesMenu",
+                                                                     G_CALLBACK (ev_window_cmd_recent_file_activate), 
+                                                                     ev_window);       
+
+        egg_recent_view_uimanager_show_icons (EGG_RECENT_VIEW_UIMANAGER (ev_window->priv->recent_view), FALSE);
        egg_recent_model_set_limit (ev_window->priv->recent_model, 5);
 
        egg_recent_view_set_model (EGG_RECENT_VIEW (ev_window->priv->recent_view),
@@ -1011,7 +1012,7 @@ ev_window_setup_recent (EvWindow *ev_window)
        egg_recent_model_set_filter_groups (ev_window->priv->recent_model,
                                            "Evince", NULL);
 
-       egg_recent_view_gtk_set_trailing_sep (ev_window->priv->recent_view, TRUE);
+       egg_recent_view_uimanager_set_trailing_sep (ev_window->priv->recent_view, TRUE);
        
        g_signal_connect (ev_window->priv->recent_view, "activate",
                        G_CALLBACK (ev_window_cmd_recent_file_activate), ev_window);