[evolution] Bug 271691 - Add a way to view all attachments inline



commit f1c03de09dfda7052753b86a78bc22f87ca039a1
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Aug 10 18:38:10 2010 -0400

    Bug 271691 - Add a way to view all attachments inline

 mail/em-format-html-display.c    |   33 ++++++-------
 widgets/misc/e-attachment-view.c |   96 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 110 insertions(+), 19 deletions(-)
---
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c
index d49d797..b2661b6 100644
--- a/mail/em-format-html-display.c
+++ b/mail/em-format-html-display.c
@@ -744,31 +744,24 @@ efhd_message_prefix(EMFormat *emf, CamelStream *stream, CamelMimePart *part, EMF
 
 /* ********************************************************************** */
 
-/* Checks on the widget whether it can be processed, based on the
- * state of EMFormatHTML.  The widget should have set "efh" data as
- * the EMFormatHTML instance. */
-static gboolean
-efhd_can_process_attachment (GtkWidget *button)
+static void
+efhd_attachment_button_expanded (EAttachmentButton *button,
+                                 GParamSpec *pspec,
+                                 struct _attach_puri *info)
 {
 	EMFormatHTML *efh;
 
-	if (!button)
-		return FALSE;
-
+	/* FIXME The PURI struct seems to have some lifecycle issues,
+	 *       because casting info->puri.format to an EMFormatHTML
+	 *       can lead to crashes.  So we hack around it. */
 	efh = g_object_get_data (G_OBJECT (button), "efh");
+	g_return_if_fail (EM_IS_FORMAT_HTML (efh));
 
-	return efh && efh->state != EM_FORMAT_HTML_STATE_RENDERING;
-}
-
-static void
-efhd_attachment_button_expanded (GtkWidget *widget,
-                                 GParamSpec *pspec,
-                                 struct _attach_puri *info)
-{
-	if (!efhd_can_process_attachment (widget))
+	if (efh->state == EM_FORMAT_HTML_STATE_RENDERING)
 		return;
 
-	info->shown = ~info->shown;
+	info->shown = e_attachment_button_get_expanded (button);
+
 	em_format_set_inline (
 		info->puri.format, info->puri.part_id, info->shown);
 }
@@ -848,6 +841,10 @@ efhd_attachment_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje
 	gtk_container_add (GTK_CONTAINER (eb), widget);
 	gtk_widget_show (widget);
 
+	/* FIXME Not sure why the expanded callback can't just use
+	 *       info->puri.format, but there seems to be lifecycle
+	 *       issues with the PURI struct.  Maybe it should have
+	 *       a reference count? */
 	g_object_set_data (G_OBJECT (widget), "efh", efh);
 
 	g_signal_connect (
diff --git a/widgets/misc/e-attachment-view.c b/widgets/misc/e-attachment-view.c
index 3715c21..60ce098 100644
--- a/widgets/misc/e-attachment-view.c
+++ b/widgets/misc/e-attachment-view.c
@@ -55,7 +55,10 @@ static const gchar *ui =
 "    <separator/>"
 "    <placeholder name='inline-actions'>"
 "      <menuitem action='show'/>"
+"      <menuitem action='show-all'/>"
+"      <separator/>"
 "      <menuitem action='hide'/>"
+"      <menuitem action='hide-all'/>"
 "    </placeholder>"
 "    <separator/>"
 "    <placeholder name='custom-actions'/>"
@@ -117,6 +120,27 @@ action_hide_cb (GtkAction *action,
 }
 
 static void
+action_hide_all_cb (GtkAction *action,
+                    EAttachmentView *view)
+{
+	EAttachmentStore *store;
+	GList *list, *iter;
+
+	store = e_attachment_view_get_store (view);
+	list = e_attachment_store_get_attachments (store);
+
+	for (iter = list; iter != NULL; iter = iter->next) {
+		EAttachment *attachment;
+
+		attachment = E_ATTACHMENT (iter->data);
+		e_attachment_set_shown (attachment, FALSE);
+	}
+
+	g_list_foreach (list, (GFunc) g_object_unref, NULL);
+	g_list_free (list);
+}
+
+static void
 action_open_in_cb (GtkAction *action,
                    EAttachmentView *view)
 {
@@ -287,6 +311,27 @@ action_show_cb (GtkAction *action,
 	g_list_free (list);
 }
 
+static void
+action_show_all_cb (GtkAction *action,
+                    EAttachmentView *view)
+{
+	EAttachmentStore *store;
+	GList *list, *iter;
+
+	store = e_attachment_view_get_store (view);
+	list = e_attachment_store_get_attachments (store);
+
+	for (iter = list; iter != NULL; iter = iter->next) {
+		EAttachment *attachment;
+
+		attachment = E_ATTACHMENT (iter->data);
+		e_attachment_set_shown (attachment, TRUE);
+	}
+
+	g_list_foreach (list, (GFunc) g_object_unref, NULL);
+	g_list_free (list);
+}
+
 static GtkActionEntry standard_entries[] = {
 
 	{ "cancel",
@@ -353,12 +398,26 @@ static GtkActionEntry inline_entries[] = {
 	  NULL,  /* XXX Add a tooltip! */
 	  G_CALLBACK (action_hide_cb) },
 
+	{ "hide-all",
+	  NULL,
+	  N_("Hid_e All"),
+	  NULL,
+	  NULL,  /* XXX Add a tooltip! */
+	  G_CALLBACK (action_hide_all_cb) },
+
 	{ "show",
 	  NULL,
 	  N_("_View Inline"),
 	  NULL,
 	  NULL,  /* XXX Add a tooltip! */
-	  G_CALLBACK (action_show_cb) }
+	  G_CALLBACK (action_show_cb) },
+
+	{ "show-all",
+	  NULL,
+	  N_("Vie_w All Inline"),
+	  NULL,
+	  NULL,  /* XXX Add a tooltip! */
+	  G_CALLBACK (action_show_all_cb) }
 };
 
 static void
@@ -568,17 +627,40 @@ attachment_view_update_actions (EAttachmentView *view)
 {
 	EAttachmentViewPrivate *priv;
 	EAttachment *attachment;
+	EAttachmentStore *store;
 	GtkActionGroup *action_group;
 	GtkAction *action;
 	GList *list, *iter;
+	guint n_shown = 0;
+	guint n_hidden = 0;
 	guint n_selected;
 	gboolean busy = FALSE;
 	gboolean can_show = FALSE;
 	gboolean shown = FALSE;
+	gboolean visible;
 
 	g_return_if_fail (E_IS_ATTACHMENT_VIEW (view));
 
 	priv = e_attachment_view_get_private (view);
+
+	store = e_attachment_view_get_store (view);
+	list = e_attachment_store_get_attachments (store);
+
+	for (iter = list; iter != NULL; iter = iter->next) {
+		attachment = iter->data;
+
+		if (!e_attachment_get_can_show (attachment))
+			continue;
+
+		if (e_attachment_get_shown (attachment))
+			n_shown++;
+		else
+			n_hidden++;
+	}
+
+	g_list_foreach (list, (GFunc) g_object_unref, NULL);
+	g_list_free (list);
+
 	list = e_attachment_view_get_selected_attachments (view);
 	n_selected = g_list_length (list);
 
@@ -600,6 +682,12 @@ attachment_view_update_actions (EAttachmentView *view)
 	action = e_attachment_view_get_action (view, "hide");
 	gtk_action_set_visible (action, can_show && shown);
 
+	/* Show this action if there are multiple viewable
+	 * attachments, and at least one of them is shown. */
+	visible = (n_shown + n_hidden > 1) && (n_shown > 0);
+	action = e_attachment_view_get_action (view, "hide-all");
+	gtk_action_set_visible (action, visible);
+
 	action = e_attachment_view_get_action (view, "properties");
 	gtk_action_set_visible (action, !busy && n_selected == 1);
 
@@ -612,6 +700,12 @@ attachment_view_update_actions (EAttachmentView *view)
 	action = e_attachment_view_get_action (view, "show");
 	gtk_action_set_visible (action, can_show && !shown);
 
+	/* Show this action if there are multiple viewable
+	 * attachments, and at least one of them is hidden. */
+	visible = (n_shown + n_hidden > 1) && (n_hidden > 0);
+	action = e_attachment_view_get_action (view, "show-all");
+	gtk_action_set_visible (action, visible);
+
 	/* Clear out the "openwith" action group. */
 	gtk_ui_manager_remove_ui (priv->ui_manager, priv->merge_id);
 	action_group = e_attachment_view_get_action_group (view, "openwith");



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