Blob Blame History Raw
diff -ru planner-0.14.4.orig/Makefile.am planner-0.14.4/Makefile.am
--- planner-0.14.4.orig/Makefile.am	2009-09-23 10:07:20.000000000 +0100
+++ planner-0.14.4/Makefile.am	2009-09-23 13:14:28.000000000 +0100
@@ -14,7 +14,6 @@
 SUBDIRS = \
 	po 				\
 	libplanner			\
-	libegg				\
 	src				\
 	data				\
 	docs				\
diff -ru planner-0.14.4.orig/Makefile.in planner-0.14.4/Makefile.in
--- planner-0.14.4.orig/Makefile.in	2009-09-23 10:07:21.000000000 +0100
+++ planner-0.14.4/Makefile.in	2009-09-23 13:14:55.000000000 +0100
@@ -71,7 +71,7 @@
 DATA = $(pkgconfig_DATA)
 ETAGS = etags
 CTAGS = ctags
-DIST_SUBDIRS = po libplanner libegg src data docs examples tests \
+DIST_SUBDIRS = po libplanner src data docs examples tests \
 	python eds-backend
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 distdir = $(PACKAGE)-$(VERSION)
@@ -307,7 +307,6 @@
 SUBDIRS = \
 	po 				\
 	libplanner			\
-	libegg				\
 	src				\
 	data				\
 	docs				\
diff -ru planner-0.14.4.orig/src/Makefile.am planner-0.14.4/src/Makefile.am
--- planner-0.14.4.orig/src/Makefile.am	2009-09-23 10:07:20.000000000 +0100
+++ planner-0.14.4/src/Makefile.am	2009-09-24 10:30:03.000000000 +0100
@@ -21,7 +21,6 @@
 planner_LDADD = \
 	libplannerapp.la \
 	$(top_builddir)/libplanner/libplanner-1.la \
-	$(top_builddir)/libegg/recent-files/libeggrecent.la \
 	$(PLANNER_LIBS)
 
 
diff -ru planner-0.14.4.orig/src/Makefile.in planner-0.14.4/src/Makefile.in
--- planner-0.14.4.orig/src/Makefile.in	2009-09-23 10:07:20.000000000 +0100
+++ planner-0.14.4/src/Makefile.in	2009-09-24 10:29:58.000000000 +0100
@@ -131,7 +131,6 @@
 planner_OBJECTS = $(am_planner_OBJECTS)
 planner_DEPENDENCIES = libplannerapp.la \
 	$(top_builddir)/libplanner/libplanner-1.la \
-	$(top_builddir)/libegg/recent-files/libeggrecent.la \
 	$(am__DEPENDENCIES_1)
 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
 depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -387,7 +386,6 @@
 planner_LDADD = \
 	libplannerapp.la \
 	$(top_builddir)/libplanner/libplanner-1.la \
-	$(top_builddir)/libegg/recent-files/libeggrecent.la \
 	$(PLANNER_LIBS)
 
 
diff -ru planner-0.14.4.orig/src/planner-application.c planner-0.14.4/src/planner-application.c
--- planner-0.14.4.orig/src/planner-application.c	2009-09-23 10:07:20.000000000 +0100
+++ planner-0.14.4/src/planner-application.c	2009-09-23 13:20:54.000000000 +0100
@@ -34,9 +34,6 @@
 
 struct _PlannerApplicationPriv {
 	GList *windows;
-
-	/* recent file stuff */
-	EggRecentModel *recent_model;
 };
 
 
@@ -181,15 +178,6 @@
 
 	priv->windows = NULL;
 	
-	priv->recent_model = egg_recent_model_new (EGG_RECENT_MODEL_SORT_MRU);
-	egg_recent_model_set_filter_mime_types (priv->recent_model,
-						"application/x-planner",
-						"application/x-mrproject",
-						NULL);
-	egg_recent_model_set_filter_uri_schemes (priv->recent_model, "file", NULL);
-
-	g_object_set (priv->recent_model, "limit", 5, NULL);
-
 	app->priv = priv;
 }
 
@@ -198,8 +186,6 @@
 {
 	PlannerApplication *app = PLANNER_APPLICATION (object);
 
-	g_object_unref (app->priv->recent_model);
-	
 	g_free (app->priv);
 
 	if (G_OBJECT_CLASS (parent_class)->finalize) {
@@ -281,12 +267,3 @@
 	
 	g_list_free (list_cpy);
 }
-
-EggRecentModel *
-planner_application_get_recent_model (PlannerApplication *app)
-{
-	g_return_val_if_fail (PLANNER_IS_APPLICATION (app), NULL);
-
-	return app->priv->recent_model;
-}
-
diff -ru planner-0.14.4.orig/src/planner-application.h planner-0.14.4/src/planner-application.h
--- planner-0.14.4.orig/src/planner-application.h	2009-09-23 10:07:20.000000000 +0100
+++ planner-0.14.4/src/planner-application.h	2009-09-23 13:16:52.000000000 +0100
@@ -26,7 +26,6 @@
 
 #include <libplanner/mrp-application.h>
 #include <libplanner/mrp-project.h>
-#include <libegg/recent-files/egg-recent-model.h>
 
 #define PLANNER_TYPE_APPLICATION                (planner_application_get_type ())
 #define PLANNER_APPLICATION(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLANNER_TYPE_APPLICATION, PlannerApplication))
@@ -54,6 +53,5 @@
 PlannerApplication   *planner_application_new              (void);
 GtkWidget       *     planner_application_new_window       (PlannerApplication *app);
 void                  planner_application_exit             (PlannerApplication *app);
-EggRecentModel  *     planner_application_get_recent_model (PlannerApplication *app);
 
 #endif /* __PLANNER_APPLICATION_H__ */
diff -ru planner-0.14.4.orig/src/planner-window.c planner-0.14.4/src/planner-window.c
--- planner-0.14.4.orig/src/planner-window.c	2009-09-23 10:07:20.000000000 +0100
+++ planner-0.14.4/src/planner-window.c	2009-09-24 10:28:38.000000000 +0100
@@ -32,9 +32,6 @@
 #include <libplanner/mrp-error.h>
 #include <libplanner/mrp-project.h>
 #include <libplanner/mrp-paths.h>
-#include <libegg/recent-files/egg-recent-view.h>
-#include <libegg/recent-files/egg-recent-view-uimanager.h>
-#include <libegg/recent-files/egg-recent-util.h>
 #include "planner-marshal.h"
 #include "planner-conf.h"
 #include "planner-sidebar.h"
@@ -80,7 +77,9 @@
 	GList               *plugins;
 	GTimer              *last_saved;
 
-	EggRecentViewUIManager *recent_view;
+	GtkActionGroup      *recents_action_group;
+	guint               recents_menu_ui_id;
+	gulong              recents_handler_id;
 };
 
 /* Drop targets. */
@@ -183,8 +182,6 @@
 static void       window_update_title                    (PlannerWindow                *window);
 static GtkWidget *window_create_dialog_button            (const gchar                  *icon_name,
 							  const gchar                  *text);
-static gchar *    window_recent_tooltip_func             (EggRecentItem                *item,
-							  gpointer                      user_data);
 static void       window_save_state                      (PlannerWindow *window);
 static void       window_restore_state                   (PlannerWindow *window);
 
@@ -410,10 +407,6 @@
 		g_object_unref (priv->cmd_manager);
 	}
 
-	if (priv->recent_view) {
-		g_object_unref (priv->recent_view);
-	}
-
 	if (priv->ui_manager) {
 		g_object_unref (priv->ui_manager);
 	}
@@ -429,11 +422,13 @@
 planner_window_open_recent_cb (GtkAction     *action,
 			       PlannerWindow *window)
 {
-	const EggRecentItem *item;
-	const gchar         *uri;
+	GtkRecentInfo *info;
+	const gchar   *uri;
+
+	info = g_object_get_data (G_OBJECT (action), "gtk-recent-info");
+	g_return_if_fail (info != NULL);
 
-	item = egg_recent_view_uimanager_get_item (window->priv->recent_view, action);
-	uri = egg_recent_item_peek_uri (item);
+	uri = gtk_recent_info_get_uri (info);
 
 	planner_window_open_in_existing_or_new (window, uri, FALSE);
 }
@@ -530,6 +525,264 @@
 			       "24_groups.png");
 }
 
+/*recent files stuff lifted from gedit*/
+static void     update_recent_files_menu (PlannerWindow *window);
+
+static void
+recent_manager_changed (GtkRecentManager *manager,
+                        PlannerWindow *window)
+{
+	/* regenerate the menu when the model changes */
+	update_recent_files_menu (window);
+}
+
+static gint
+sort_recents_mru (GtkRecentInfo *a, GtkRecentInfo *b)
+{
+        return (gtk_recent_info_get_modified (b) - gtk_recent_info_get_modified (a));
+}
+
+
+/*
+ * Doubles underscore to avoid spurious menu accels.
+ */
+static gchar * 
+escape_underscores (const gchar* text,
+                    gssize       length)
+{
+	GString *str;
+	const gchar *p;
+	const gchar *end;
+
+	g_return_val_if_fail (text != NULL, NULL);
+
+	if (length < 0)
+		length = strlen (text);
+
+	str = g_string_sized_new (length);
+
+	p = text;
+	end = text + length;
+
+	while (p != end)
+	{
+		const gchar *next;
+		next = g_utf8_next_char (p);
+
+		switch (*p)
+		{
+			case '_':
+				g_string_append (str, "__");
+				break;
+			default:
+				g_string_append_len (str, p, next - p);
+				break;
+		}
+
+		p = next;
+	}
+
+	return g_string_free (str, FALSE);
+}
+
+
+/**
+ * uri_for_display:
+ * @uri: uri to be displayed.
+ *
+ * Filter, modify, unescape and change @uri to make it appropriate
+ * for display to users.
+ * 
+ * This function is a convenient wrapper for g_file_get_parse_name
+ *
+ * Return value: a string which represents @uri and can be displayed.
+ */
+static gchar *
+uri_for_display (const gchar *uri)
+{
+	GFile *gfile;
+	gchar *parse_name;
+
+	gfile = g_file_new_for_uri (uri);
+	parse_name = g_file_get_parse_name (gfile);
+	g_object_unref (gfile);
+
+	return parse_name;
+}
+
+static gchar *
+replace_home_dir_with_tilde (const gchar *uri)
+{
+	gchar *tmp;
+	gchar *home;
+
+	g_return_val_if_fail (uri != NULL, NULL);
+
+	/* Note that g_get_home_dir returns a const string */
+	tmp = (gchar *)g_get_home_dir ();
+
+	if (tmp == NULL)
+		return g_strdup (uri);
+
+	home = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
+	if (home == NULL)
+		return g_strdup (uri);
+
+	if (strcmp (uri, home) == 0)
+	{
+		g_free (home);
+		
+		return g_strdup ("~");
+	}
+
+	tmp = home;
+	home = g_strdup_printf ("%s/", tmp);
+	g_free (tmp);
+
+	if (g_str_has_prefix (uri, home))
+	{
+		gchar *res;
+
+		res = g_strdup_printf ("~/%s", uri + strlen (home));
+
+		g_free (home);
+		
+		return res;		
+	}
+
+	g_free (home);
+
+	return g_strdup (uri);
+}
+
+static void
+update_recent_files_menu (PlannerWindow *window)
+{
+        PlannerWindowPriv *p = window->priv;
+	GtkRecentManager *recent_manager;
+        gint max_recents = 5;
+	GList *actions, *l, *items;
+	GList *filtered_items = NULL;
+	gint i;
+
+	g_return_if_fail (p->recents_action_group != NULL);
+
+	if (p->recents_menu_ui_id != 0)
+		gtk_ui_manager_remove_ui (p->ui_manager,
+		                          p->recents_menu_ui_id);
+
+	actions = gtk_action_group_list_actions (p->recents_action_group);
+	for (l = actions; l != NULL; l = l->next)
+	{
+		g_signal_handlers_disconnect_by_func (GTK_ACTION (l->data),
+		                                      G_CALLBACK (planner_window_open_recent_cb),
+		                                      window);
+		gtk_action_group_remove_action (p->recents_action_group,
+		                                GTK_ACTION (l->data));
+	}
+	g_list_free (actions);
+
+	p->recents_menu_ui_id = gtk_ui_manager_new_merge_id (p->ui_manager);
+
+	recent_manager =  gtk_recent_manager_get_default ();
+	items = gtk_recent_manager_get_items (recent_manager);
+
+	/* filter */
+	for (l = items; l != NULL; l = l->next)
+	{
+		GtkRecentInfo *info = l->data;
+
+		if (!gtk_recent_info_has_group (info, "planner"))
+			continue;
+
+		filtered_items = g_list_prepend (filtered_items, info);
+	}
+
+	/* sort */
+	filtered_items = g_list_sort (filtered_items,
+				      (GCompareFunc) sort_recents_mru);
+
+	i = 0;
+	for (l = filtered_items; l != NULL; l = l->next)
+	{
+		gchar *action_name;
+		const gchar *display_name;
+		gchar *escaped;
+		gchar *label;
+		gchar *uri;
+		gchar *ruri;
+		gchar *tip;
+		GtkAction *action;
+		GtkRecentInfo *info = l->data;
+
+		/* clamp */
+		if (i >= max_recents)
+			break;
+
+		i++;
+
+		action_name = g_strdup_printf ("recent-info-%d", i);
+
+		display_name = gtk_recent_info_get_display_name (info);
+		escaped = escape_underscores (display_name, -1);
+		if (i >= 10)
+			label = g_strdup_printf ("%d.  %s",
+						 i, 
+						 escaped);
+		else
+			label = g_strdup_printf ("_%d.  %s",
+						 i, 
+						 escaped);
+		g_free (escaped);
+
+		/* gtk_recent_info_get_uri_display (info) is buggy and
+		 * works only for local files */
+		uri = uri_for_display (gtk_recent_info_get_uri (info));
+		ruri = replace_home_dir_with_tilde (uri);
+		g_free (uri);
+
+		/* Translators: %s is a URI */
+		tip = g_strdup_printf (_("Open '%s'"), ruri);
+		g_free (ruri);
+
+		action = gtk_action_new (action_name,
+					 label,
+					 tip,
+					 NULL);
+
+		g_object_set_data_full (G_OBJECT (action),
+					"gtk-recent-info",
+					gtk_recent_info_ref (info),
+					(GDestroyNotify) gtk_recent_info_unref);
+
+		g_signal_connect (action,
+				  "activate",
+				  G_CALLBACK (planner_window_open_recent_cb),
+				  window);
+
+		gtk_action_group_add_action (p->recents_action_group,
+					     action);
+		g_object_unref (action);
+
+		gtk_ui_manager_add_ui (p->ui_manager,
+				       p->recents_menu_ui_id,
+				       "/MenuBar/File/OpenRecent",
+				       action_name,
+				       action_name,
+				       GTK_UI_MANAGER_MENUITEM,
+				       FALSE);
+
+		g_free (action_name);
+		g_free (label);
+		g_free (tip);
+	}
+
+	g_list_free (filtered_items);
+
+	g_list_foreach (items, (GFunc) gtk_recent_info_unref, NULL);
+	g_list_free (items);
+}
+
 static void
 window_populate (PlannerWindow *window)
 {
@@ -606,17 +859,17 @@
 		      NULL);
 
 	/* Handle recent file stuff. */
-	priv->recent_view = egg_recent_view_uimanager_new (priv->ui_manager,
-							   "/MenuBar/File/OpenRecent",
-							   G_CALLBACK (planner_window_open_recent_cb),
-							   window);
-
-	egg_recent_view_set_model (EGG_RECENT_VIEW (priv->recent_view),
-				   planner_application_get_recent_model (priv->application));
-	egg_recent_view_uimanager_set_tooltip_func (priv->recent_view,
-						    window_recent_tooltip_func,
-						    NULL);
+        window->priv->recents_action_group = gtk_action_group_new ("RecentFilesActions");
+        gtk_action_group_set_translation_domain (window->priv->recents_action_group, NULL);
+        gtk_ui_manager_insert_action_group (priv->ui_manager, window->priv->recents_action_group, 0);
+        g_object_unref (window->priv->recents_action_group);
+
+        window->priv->recents_handler_id = g_signal_connect (gtk_recent_manager_get_default (),
+                                                             "changed",
+                                                             G_CALLBACK (recent_manager_changed),
+                                                             window);
 
+	update_recent_files_menu (window);
 	hbox = gtk_hbox_new (FALSE, 0);
 
 	priv->sidebar = planner_sidebar_new ();
@@ -1507,6 +1760,52 @@
 	return TRUE;
 }
 
+static void
+_planner_recent_add (const gchar *uri, const gchar *mime)
+{
+        GtkRecentManager *recent_manager;
+        GtkRecentData *recent_data;
+        gchar *fixeduri = NULL;
+        gchar *scratch;
+
+        static gchar *groups[2] = {
+                "planner",
+                NULL
+        };
+
+        recent_manager =  gtk_recent_manager_get_default ();
+
+        recent_data = g_slice_new (GtkRecentData);
+
+        recent_data->display_name = NULL;
+        recent_data->description = NULL;
+        recent_data->mime_type = (gchar *) mime;
+        recent_data->app_name = (gchar *) g_get_application_name ();
+        recent_data->app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
+        recent_data->groups = groups;
+        recent_data->is_private = FALSE;
+
+	/*
+	 * planner has stripped the file: from local uris so
+	 * if there's not scheme turn it back to a proper uri
+	 */
+	scratch = g_uri_parse_scheme (uri);
+	if (!scratch)
+        	uri = fixeduri = g_filename_to_uri (uri, NULL, NULL);
+	g_free (scratch);
+
+        gtk_recent_manager_add_full (recent_manager,
+                                     uri,
+                                     recent_data);
+
+	if (fixeduri)
+		g_free (fixeduri);
+
+        g_free (recent_data->app_exec);
+
+        g_slice_free (GtkRecentData, recent_data);
+}
+
 static gboolean
 window_do_save_as (PlannerWindow *window)
 {
@@ -1515,7 +1814,6 @@
 	gint              response;
 	gchar            *filename = NULL;
 	gchar            *last_dir;
-	EggRecentItem    *item;
 
 	priv = window->priv;
 
@@ -1583,10 +1881,7 @@
 
 		if (success) {
 			/* Add the file to the recent list */
-			item = egg_recent_item_new_from_uri (mrp_project_get_uri (priv->project));
-			egg_recent_item_set_mime_type (item, "application/x-planner");
-			egg_recent_model_add_full (planner_application_get_recent_model (priv->application), item);
-			egg_recent_item_unref (item);
+			_planner_recent_add(mrp_project_get_uri (priv->project), "application/x-planner");
 		} else {
 			GtkWidget *dialog;
 			
@@ -1686,7 +1981,6 @@
 	PlannerWindowPriv *priv;
 	GError           *error = NULL;
 	GtkWidget        *dialog;
-	EggRecentItem    *item;
 	
 	g_return_val_if_fail (PLANNER_IS_WINDOW (window), FALSE);
 	g_return_val_if_fail (uri != NULL, FALSE);
@@ -1710,11 +2004,7 @@
 
 	if (!internal) {
 		/* Add the file to the recent list */
-		item = egg_recent_item_new_from_uri (uri);
-		egg_recent_item_set_mime_type (item, "application/x-planner");
-		egg_recent_model_add_full (planner_application_get_recent_model (priv->application), item);
-		egg_recent_item_unref (item);
-		
+		_planner_recent_add(uri, "application/x-planner");
 		window_update_title (window);
 	}
 	
@@ -1943,25 +2233,6 @@
 	}
 }
 
-static gchar *
-window_recent_tooltip_func (EggRecentItem *item,
-			    gpointer user_data)
-{
-	gchar *uri;
-	gchar *escaped;
-	gchar *tooltip;
-
-	uri = egg_recent_item_get_uri_for_display (item);
-
-	escaped = egg_recent_util_escape_underlines (uri);
-	tooltip = g_strdup_printf (_("Open '%s'"), escaped);
-
-	g_free (uri);
-	g_free (escaped);
-
-	return tooltip;
-}
-
 PlannerCmdManager *
 planner_window_get_cmd_manager (PlannerWindow *window)
 {