evolution r35354 - in trunk: . calendar calendar/gui/dialogs composer ui widgets/misc



Author: msuman
Date: Fri Apr 11 19:52:39 2008
New Revision: 35354
URL: http://svn.gnome.org/viewvc/evolution?rev=35354&view=rev

Log:
Fix for bug #517134 : Extend the 'Insert' menu (in editors) to show a "Recent Documents" submenu (to quickly add them as attachments). 

M    configure.in
M    ChangeLog
M    composer/evolution-composer.ui
M    composer/ChangeLog
M    composer/e-composer-actions.c
M    composer/e-composer-private.c
M    widgets/misc/ChangeLog
M    widgets/misc/e-attachment-bar.c
M    widgets/misc/e-attachment-bar.h
M    calendar/gui/dialogs/comp-editor.c
M    calendar/ChangeLog
M    ui/ChangeLog
M    ui/evolution-editor.xml


Modified:
   trunk/ChangeLog
   trunk/calendar/ChangeLog
   trunk/calendar/gui/dialogs/comp-editor.c
   trunk/composer/ChangeLog
   trunk/composer/e-composer-actions.c
   trunk/composer/e-composer-private.c
   trunk/composer/evolution-composer.ui
   trunk/configure.in
   trunk/ui/ChangeLog
   trunk/ui/evolution-editor.xml
   trunk/widgets/misc/ChangeLog
   trunk/widgets/misc/e-attachment-bar.c
   trunk/widgets/misc/e-attachment-bar.h

Modified: trunk/calendar/gui/dialogs/comp-editor.c
==============================================================================
--- trunk/calendar/gui/dialogs/comp-editor.c	(original)
+++ trunk/calendar/gui/dialogs/comp-editor.c	Fri Apr 11 19:52:39 2008
@@ -1432,35 +1432,70 @@
 }
 
 static void
+add_to_bar (CompEditor *editor, GPtrArray *file_list, int is_inline)
+{
+	CompEditorPrivate *priv = editor->priv;
+	int i;
+
+	for (i = 0; i < file_list->len; i++) {
+		CamelURL *url;
+
+		if (!(url = camel_url_new (file_list->pdata[i], NULL)))
+			continue;
+
+		if (!g_ascii_strcasecmp (url->protocol, "file")) {
+			e_attachment_bar_attach((EAttachmentBar *)priv->attachment_bar, url->path, is_inline ? "inline" : "attachment");
+		} else {
+			e_attachment_bar_attach_remote_file ((EAttachmentBar *)priv->attachment_bar, file_list->pdata[i], is_inline ? "inline" : "attachment");
+		}
+
+		camel_url_free (url);
+	}
+}
+
+static void
 menu_insert_attachment_cb (BonoboUIComponent *uic,
 		   	   void *data,
 		   	   const char *path)
 {
 	CompEditor *editor = (CompEditor *) data;
-	EAttachmentBar *bar = (EAttachmentBar *)editor->priv->attachment_bar;
 	GPtrArray *file_list;
 	gboolean is_inline = FALSE;
 	int i;
 
 	file_list = comp_editor_select_file_attachments (editor, &is_inline);
-	/*TODO add a good implementation here */
-	if (!file_list)
-		return;
-	for (i = 0; i < file_list->len; i++) {
-		CamelURL *url;
 
-		url = camel_url_new (file_list->pdata[i], NULL);
-		if (url == NULL)
-			continue;
+	if (file_list) {
+		add_to_bar (editor, file_list, is_inline);
 
-		if (!g_ascii_strcasecmp (url->protocol, "file"))
-			 e_attachment_bar_attach (bar, url->path, is_inline ? "inline" : "attachment");
-		else
-			 e_attachment_bar_attach_remote_file (bar, file_list->pdata[i], is_inline ? "inline" : "attachment");
-		g_free (file_list->pdata[i]);
-		camel_url_free (url);
+		for (i = 0; i < file_list->len; i++)
+			g_free (file_list->pdata[i]);
+
+		g_ptr_array_free (file_list, TRUE);
 	}
+}
 
+static void
+menu_insert_attach_recent_docs_cb (BonoboUIComponent *uic,
+				   gpointer user_data,
+				   const char *cname)
+{
+	CompEditor *editor = (CompEditor *) user_data;
+	gchar *command = NULL, *uri = NULL;
+	GPtrArray *file_list = g_ptr_array_new ();
+	int i;
+
+	command = g_strdup_printf ("/commands/%s", cname);
+	uri = bonobo_ui_component_get_prop (editor->uic, command, "uri", NULL);
+	g_free (command);
+
+	if (uri && *uri) {
+		g_ptr_array_add (file_list, uri);
+		add_to_bar (editor, file_list, FALSE);
+	}
+
+	for (i = 0; i < file_list->len; i++)
+		g_free (file_list->pdata[i]);
 	g_ptr_array_free (file_list, TRUE);
 }
 
@@ -1636,6 +1671,11 @@
 
 	bonobo_ui_component_set_prop (editor->uic, "/commands/FileSave", "sensitive", "0", NULL);
 
+	/* FIXME: this should have been setup_widgets, but editor->uic is uninitialized then */
+	e_attachment_bar_bonobo_ui_populate_with_recent (editor->uic, "/menu/Insert/RecentDocsPlaceholder", 
+							 E_ATTACHMENT_BAR (priv->attachment_bar), 
+							 menu_insert_attach_recent_docs_cb, editor);
+
 	/* DND support */
 	gtk_drag_dest_set (GTK_WIDGET (editor), GTK_DEST_DEFAULT_ALL,  drop_types, num_drop_types, GDK_ACTION_COPY|GDK_ACTION_ASK|GDK_ACTION_MOVE);
 	g_signal_connect(editor, "drag_data_received", G_CALLBACK (drag_data_received), NULL);

Modified: trunk/composer/e-composer-actions.c
==============================================================================
--- trunk/composer/e-composer-actions.c	(original)
+++ trunk/composer/e-composer-actions.c	Fri Apr 11 19:52:39 2008
@@ -36,6 +36,7 @@
 	GtkWidget *dialog;
 	GtkWidget *option;
 	GSList *uris, *iter;
+	const gchar *disposition;
 	gboolean active;
 	gint response;
 
@@ -72,16 +73,15 @@
 
 	uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (dialog));
 	active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (option));
+	disposition = active ? "inline" : "attachment";
 
 	for (iter = uris; iter != NULL; iter = iter->next) {
-		const gchar *disposition;
 		CamelURL *url;
 
 		url = camel_url_new (iter->data, NULL);
 		if (url == NULL)
 			continue;
 
-		disposition = active ? "inline" : "attachment";
 		if (!g_ascii_strcasecmp (url->protocol, "file"))
 			e_attachment_bar_attach (bar, url->path, disposition);
 		else

Modified: trunk/composer/e-composer-private.c
==============================================================================
--- trunk/composer/e-composer-private.c	(original)
+++ trunk/composer/e-composer-private.c	Fri Apr 11 19:52:39 2008
@@ -43,6 +43,38 @@
 
 		list = g_list_delete_link (list, list);
 	}
+
+	gtk_ui_manager_ensure_update (manager);
+}
+
+static void
+composer_setup_recent_menu (EMsgComposer *composer)
+{
+	GtkUIManager *manager;
+	GtkAction *action = NULL;
+	const gchar *path, *action_name;
+	guint merge_id;
+
+	manager = gtkhtml_editor_get_ui_manager (GTKHTML_EDITOR (composer));
+	action_name = "recent-menu";
+	path = "/main-menu/insert-menu/insert-menu-top/recent-placeholder";
+	merge_id = gtk_ui_manager_new_merge_id (manager);
+
+	action = e_attachment_bar_recent_action_new (
+			e_msg_composer_get_attachment_bar (composer), 
+			action_name, _("Recent _Documents"));
+
+	if (action != NULL) {
+		gtk_action_group_add_action (composer->priv->composer_actions, action);
+
+		gtk_ui_manager_add_ui ( 
+			manager, merge_id, path,
+			action_name, 
+			action_name, 
+			GTK_UI_MANAGER_AUTO, FALSE);
+	}
+
+	gtk_ui_manager_ensure_update (manager);
 }
 
 void
@@ -86,10 +118,10 @@
 
 	filename = e_composer_find_data_file ("evolution-composer.ui");
 	gtk_ui_manager_add_ui_from_file (manager, filename, &error);
-	composer_setup_charset_menu (composer);
-	gtk_ui_manager_ensure_update (manager);
 	g_free (filename);
 
+	composer_setup_charset_menu (composer);
+
 	if (error != NULL) {
 		/* Henceforth, bad things start happening. */
 		g_critical ("%s", error->message);
@@ -158,6 +190,8 @@
 	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 6);
 	priv->attachment_expander_num = g_object_ref (widget);
 	gtk_widget_show (widget);
+
+	composer_setup_recent_menu (composer);
 }
 
 void

Modified: trunk/composer/evolution-composer.ui
==============================================================================
--- trunk/composer/evolution-composer.ui	(original)
+++ trunk/composer/evolution-composer.ui	Fri Apr 11 19:52:39 2008
@@ -34,6 +34,7 @@
     <menu action='insert-menu'>
       <placeholder name='insert-menu-top'>
         <menuitem action='attach'/>
+        <placeholder name='recent-placeholder'/>
         <separator/>
         <menuitem action='send-options'/>
         <separator/>

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Fri Apr 11 19:52:39 2008
@@ -11,7 +11,7 @@
 GTKHTML_PACKAGE=3.14
 
 # Required Packages
-m4_define([glib_minimum_version], [2.15.3])
+m4_define([glib_minimum_version], [2.16.0])
 m4_define([gtk_minimum_version], [2.12.0])
 m4_define([eds_minimum_version], [2.23.1])
 m4_define([gnome_icon_theme_minimum_version], [2.19.91])

Modified: trunk/ui/evolution-editor.xml
==============================================================================
--- trunk/ui/evolution-editor.xml	(original)
+++ trunk/ui/evolution-editor.xml	Fri Apr 11 19:52:39 2008
@@ -41,6 +41,7 @@
       <placeholder name="Attachments">
 	      <menuitem name="InsertAttachments" verb="" _label="_Attachment..."/>
       </placeholder>
+      <placeholder f="" name="RecentDocsPlaceholder"/>
      </submenu>
 
     <submenu name="Options" _label="_Options">

Modified: trunk/widgets/misc/e-attachment-bar.c
==============================================================================
--- trunk/widgets/misc/e-attachment-bar.c	(original)
+++ trunk/widgets/misc/e-attachment-bar.c	Fri Apr 11 19:52:39 2008
@@ -28,6 +28,7 @@
 
 #include <string.h>
 #include <gtk/gtk.h>
+#include <gio/gio.h>
 #include <glade/glade.h>
 #include <gconf/gconf.h>
 #include <gconf/gconf-client.h>
@@ -71,6 +72,9 @@
 struct _EAttachmentBarPrivate {
 	GtkWidget *attach;	/* attachment file dialogue, if active */
 
+	/* Recent documents. Use this widget directly when bonoboui is obsoleted */
+	GtkWidget *recent;
+
 	gboolean batch_unref;
 	GPtrArray *attachments;
 	char *path;
@@ -551,7 +555,6 @@
 	return &bar->priv->attach;
 }
 
-
 /**
  * e_attachment_bar_get_selected:
  * @bar: an #EAttachmentBar object
@@ -694,6 +697,9 @@
 		if (priv->attach)
 			gtk_widget_destroy (priv->attach);
 
+		if (priv->recent)
+			gtk_widget_destroy (priv->recent);
+
 		if (priv->path)
 			g_free (priv->path);
 
@@ -969,6 +975,15 @@
 	priv->attach = NULL;
 	priv->batch_unref = FALSE;
 	priv->attachments = g_ptr_array_new ();
+
+	priv->recent = gtk_recent_chooser_menu_new ();
+	gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (priv->recent), TRUE);
+	gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (priv->recent), GTK_RECENT_SORT_MRU);
+	gtk_recent_chooser_set_show_not_found (GTK_RECENT_CHOOSER (priv->recent), FALSE);
+	gtk_recent_chooser_set_show_private (GTK_RECENT_CHOOSER (priv->recent), FALSE);
+	gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (priv->recent), TRUE);
+	gtk_recent_chooser_set_show_tips (GTK_RECENT_CHOOSER (priv->recent), TRUE);
+
 	priv->path = NULL;
 
 	bar->priv = priv;
@@ -1228,3 +1243,145 @@
 
 	add_from_mime_part (bar, part);
 }
+
+/* FIXME: Remove this API if nobody uses it */
+void 
+e_attachment_bar_bonobo_ui_populate_with_recent (BonoboUIComponent *uic, const char *path,
+						 EAttachmentBar *bar, 
+						 BonoboUIVerbFn verb_cb, gpointer user_data)
+{
+	struct _EAttachmentBarPrivate *priv;
+	GList *items, *l;
+	gint limit, i;
+	GString *menuitems;
+	char *encoded_label, *label;
+
+	g_return_if_fail (E_IS_ATTACHMENT_BAR (bar));
+
+	priv = bar->priv;
+	limit = gtk_recent_chooser_get_limit (GTK_RECENT_CHOOSER (priv->recent));
+	items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (priv->recent));
+
+	menuitems = g_string_new ("<submenu");
+	g_string_append (menuitems, " name=\"RecentDocsSubmenu\"");
+	g_string_append_printf (menuitems, " sensitive=\"%s\"", items ? "1" : "0");
+	g_string_append_printf (menuitems, " label=\"%s\"", _("Recent Docu_ments"));
+	g_string_append (menuitems, ">\n");
+
+	for (l = g_list_first (items), i = 1; l && i <= limit; l = l->next, ++i) {
+		GtkRecentInfo *info = ((GtkRecentInfo *)(l->data));
+		const gchar *info_dn = gtk_recent_info_get_display_name (info);
+		char *display_name, *u;
+
+		/* escape _'s in the display name so that it doesn't become an underline in a GtkLabel */
+		if ((u = strchr (info_dn, '_'))) {
+			int extra = 1;
+			char *d;
+			const char *s;
+
+			while ((u = strchr (u + 1, '_')))
+				extra++;
+
+			d = display_name = g_alloca (strlen (info_dn) + extra + 1);
+			s = info_dn;
+			while (*s != '\0') {
+				if (*s == '_')
+					*d++ = '_';
+				*d++ = *s++;
+			}
+			*d = '\0';
+		} else
+			display_name = info_dn;
+
+		/* Add menu item */
+		label = g_strdup (display_name);
+		encoded_label = bonobo_ui_util_encode_str (label);
+		g_string_append_printf (menuitems, 
+					"  <menuitem name=\"Recent-%d\" verb=\"\" label=\"%s\"/>\n",
+					i, encoded_label);
+		g_free (encoded_label);
+		g_free (label);
+	}
+
+	g_string_append (menuitems, "</submenu>\n");
+
+	bonobo_ui_component_set (uic, path, menuitems->str, NULL);
+
+	g_string_free (menuitems, TRUE);
+
+	/* Add uri prop */
+	for (l = g_list_first (items), i = 1; l && i <= limit; l = l->next, ++i) {
+		GtkRecentInfo *info = ((GtkRecentInfo *)(l->data));
+		const gchar *info_uri = gtk_recent_info_get_uri (info);
+		label = g_strdup_printf ("/commands/Recent-%d", i);
+		bonobo_ui_component_set_prop (uic, label, "uri", info_uri, NULL);
+		g_free (label);
+	}
+
+	/* Add verb */
+	for (l = g_list_first (items), i = 1; l && i <= limit; l = l->next, ++i) {
+		label = g_strdup_printf ("Recent-%d", i);
+		bonobo_ui_component_add_verb (uic, label, verb_cb, user_data);
+		g_free (label);
+	}
+
+	for (l = g_list_first (items); l; l = l->next)
+		gtk_recent_info_unref ((GtkRecentInfo *)(l->data));
+	g_list_free (items);
+}
+
+static void
+action_recent_cb (GtkAction *action, 
+		  EAttachmentBar *attachment_bar)
+{
+	GtkRecentChooser *chooser;
+	GFile *file;
+	gchar *uri;
+
+	chooser = GTK_RECENT_CHOOSER (action);
+
+	/* Wish: gtk_recent_chooser_get_current_file() */
+	uri = gtk_recent_chooser_get_current_uri (chooser);
+	file = g_file_new_for_uri (uri);
+	g_free (uri);
+
+	if (g_file_is_native (file))
+		e_attachment_bar_attach (
+			E_ATTACHMENT_BAR (attachment_bar),
+			g_file_get_path (file), "attachment");
+	else
+		e_attachment_bar_attach_remote_file (
+			E_ATTACHMENT_BAR (attachment_bar),
+			g_file_get_uri (file), "attachment");
+
+	g_object_unref (file);
+}
+
+GtkAction *
+e_attachment_bar_recent_action_new (EAttachmentBar *bar, 
+				const gchar *action_name,
+				const gchar *action_label)
+{
+	GtkAction *action;
+	GtkRecentChooser *chooser;
+
+	g_return_val_if_fail (E_IS_ATTACHMENT_BAR (bar), NULL);
+
+	action = gtk_recent_action_new (
+		action_name, action_label, NULL, NULL);
+	gtk_recent_action_set_show_numbers (GTK_RECENT_ACTION (action), TRUE);
+
+	chooser = GTK_RECENT_CHOOSER (action);
+	gtk_recent_chooser_set_show_icons (chooser, TRUE);
+	gtk_recent_chooser_set_show_not_found (chooser, FALSE);
+	gtk_recent_chooser_set_show_private (chooser, FALSE);
+	gtk_recent_chooser_set_show_tips (chooser, TRUE);
+	gtk_recent_chooser_set_sort_type (chooser, GTK_RECENT_SORT_MRU);
+
+	g_signal_connect (
+		action, "item-activated",
+		G_CALLBACK (action_recent_cb), bar);
+
+	return action;
+}
+

Modified: trunk/widgets/misc/e-attachment-bar.h
==============================================================================
--- trunk/widgets/misc/e-attachment-bar.h	(original)
+++ trunk/widgets/misc/e-attachment-bar.h	Fri Apr 11 19:52:39 2008
@@ -27,6 +27,9 @@
 
 #include <libgnomeui/gnome-icon-list.h>
 
+#include <bonobo/bonobo-ui-node.h>
+#include <bonobo/bonobo-ui-util.h>
+
 #include <camel/camel-multipart.h>
 #include "e-attachment.h"
 
@@ -83,6 +86,14 @@
 void e_attachment_bar_set_width(EAttachmentBar *bar, int bar_width);
 GSList * e_attachment_bar_get_all_attachments (EAttachmentBar *bar);
 void e_attachment_bar_create_attachment_cache (EAttachment *attachment);
+void 
+e_attachment_bar_bonobo_ui_populate_with_recent (BonoboUIComponent *uic, const char *path,
+						 EAttachmentBar *bar, 
+						 BonoboUIVerbFn verb_cb, gpointer user_data);
+GtkAction *
+e_attachment_bar_recent_action_new (EAttachmentBar *bar, 
+				const gchar *action_name,
+				const gchar *action_label);
 
 #ifdef __cplusplus
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]