[evolution/webkit: 143/196] Single-webview transition - fix EMailReader and displaying mail source



commit 234046e70f9c3f70bb87f332f8dafd1ff352f2f3
Author: Dan VrÃtil <dvratil redhat com>
Date:   Thu Feb 9 12:59:08 2012 +0100

    Single-webview transition - fix EMailReader and displaying mail source

 mail/e-mail-browser.c |   47 ++++++++++++-----
 mail/e-mail-display.c |    7 ++-
 mail/e-mail-reader.c  |  134 ++++++++++++++++++++++++++++---------------------
 mail/em-format-html.c |    9 +++
 4 files changed, 124 insertions(+), 73 deletions(-)
---
diff --git a/mail/e-mail-browser.c b/mail/e-mail-browser.c
index 54dd264..56024cb 100644
--- a/mail/e-mail-browser.c
+++ b/mail/e-mail-browser.c
@@ -76,6 +76,7 @@ enum {
 	PROP_SHOW_DELETED,
 	PROP_REPLY_STYLE,
 	PROP_UI_MANAGER,
+	PROP_DISPLAY_MODE,
 };
 
 static gpointer parent_class;
@@ -412,6 +413,11 @@ mail_browser_set_property (GObject *object,
 				E_MAIL_BROWSER (object),
 				g_value_get_boolean (value));
 			return;
+
+		case PROP_DISPLAY_MODE:
+			E_MAIL_BROWSER (object)->priv->mode =
+				g_value_get_int (value);
+			return;
 	}
 
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -465,6 +471,11 @@ mail_browser_get_property (GObject *object,
 				value, e_mail_browser_get_ui_manager (
 				E_MAIL_BROWSER (object)));
 			return;
+
+		case PROP_DISPLAY_MODE:
+			g_value_set_int (
+				value, E_MAIL_BROWSER (object)->priv->mode);
+			return;
 	}
 
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -579,8 +590,9 @@ mail_browser_constructed (GObject *object)
 		browser->priv->message_list, "message-list-built",
 		G_CALLBACK (mail_browser_message_list_built_cb), object);
 
-        display = g_object_new (E_TYPE_MAIL_DISPLAY, NULL);
-        e_mail_display_set_mode (display, E_MAIL_BROWSER (object)->priv->mode);
+
+        display = g_object_new (E_TYPE_MAIL_DISPLAY,
+			"mode", E_MAIL_BROWSER (object)->priv->mode, NULL);
 
 	g_signal_connect_swapped (
 		display, "popup-event",
@@ -590,7 +602,9 @@ mail_browser_constructed (GObject *object)
 		display, "status-message",
 		G_CALLBACK (mail_browser_status_message_cb), object);
 
-	/* Add action groups before initializing the reader interface. */
+	widget = e_preview_pane_new (E_WEB_VIEW (display));
+	browser->priv->preview_pane = g_object_ref (widget);
+	gtk_widget_show (widget);
 
 	action_group = gtk_action_group_new (ACTION_GROUP_STANDARD);
 	gtk_action_group_set_translation_domain (action_group, domain);
@@ -603,6 +617,7 @@ mail_browser_constructed (GObject *object)
 	gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
 
 	/* For easy access.  Takes ownership of the reference. */
+
 	g_object_set_data_full (
 		object, ACTION_GROUP_STANDARD,
 		action_group, (GDestroyNotify) g_object_unref);
@@ -654,7 +669,6 @@ mail_browser_constructed (GObject *object)
 
 	container = widget;
 
-	/* Create the status bar before connecting proxy widgets. */
 	widget = gtk_statusbar_new ();
 	gtk_box_pack_end (GTK_BOX (container), widget, FALSE, FALSE, 0);
 	browser->priv->statusbar = g_object_ref (widget);
@@ -672,14 +686,11 @@ mail_browser_constructed (GObject *object)
 
 	gtk_style_context_add_class (
 		gtk_widget_get_style_context (widget),
-		GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
+				     GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
 
-	widget = e_preview_pane_new (E_WEB_VIEW (display));
-	gtk_container_add (GTK_CONTAINER (container), widget);
-	browser->priv->preview_pane = g_object_ref (widget);
-	gtk_widget_show (widget);
-
-	search_bar = e_preview_pane_get_search_bar (E_PREVIEW_PANE (widget));
+	gtk_container_add (GTK_CONTAINER (container), browser->priv->preview_pane);
+	search_bar = e_preview_pane_get_search_bar (
+		E_PREVIEW_PANE (browser->priv->preview_pane));
 
 	g_signal_connect_swapped (
 		search_bar, "changed",
@@ -903,6 +914,17 @@ e_mail_browser_class_init (EMailBrowserClass *class)
 			FALSE,
 			G_PARAM_READWRITE));
 
+	g_object_class_install_property (
+		object_class,
+		PROP_DISPLAY_MODE,
+		g_param_spec_int (
+			"display-mode",
+			"Display Mode",
+			NULL,
+			0,
+			G_MAXINT,
+			EM_FORMAT_WRITE_MODE_NORMAL,
+			G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 }
 
 static void
@@ -946,10 +968,9 @@ e_mail_browser_new (EMailBackend *backend,
 	widget= g_object_new (
 		E_TYPE_MAIL_BROWSER,
 		"backend", backend,
+		"display-mode", mode,
 		NULL);
 
-	E_MAIL_BROWSER (widget)->priv->mode = mode;
-
 	return widget;
 }
 
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 06d3cff..2d4ddef 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -697,8 +697,8 @@ e_mail_display_class_init (EMailDisplayClass *class)
 			"mode",
 			"Display Mode",
 			NULL,
-			EM_FORMAT_WRITE_MODE_NORMAL,
-			EM_FORMAT_WRITE_MODE_SOURCE,
+			0,
+			G_MAXINT,
 			EM_FORMAT_WRITE_MODE_NORMAL,
 			G_PARAM_READWRITE));
 
@@ -853,6 +853,7 @@ e_mail_display_set_mode (EMailDisplay *display,
 		return;
 
 	display->priv->mode = mode;
+
         e_mail_display_reload (display);
 
 	g_object_notify (G_OBJECT (display), "mode");
@@ -945,7 +946,7 @@ e_mail_display_reload (EMailDisplay *display)
 	web_view = E_WEB_VIEW (display);
 	uri = e_web_view_get_uri (web_view);
 
-	if (!uri)
+	if (!uri || !*uri)
 		return;
 
 	if (strstr(uri, "?") == NULL) {
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 00f27dd..375ca5f 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -127,6 +127,13 @@ static guint signals[LAST_SIGNAL];
 G_DEFINE_INTERFACE (EMailReader, e_mail_reader, G_TYPE_INITIALLY_UNOWNED)
 
 static void
+mail_reader_set_display_formatter_for_message (EMailReader *reader,
+					       EMailDisplay *display,
+					       const gchar *message_uid,
+					       CamelMimeMessage *message,
+					       CamelFolder *folder);
+
+static void
 mail_reader_closure_free (EMailReaderClosure *closure)
 {
 	if (closure->reader != NULL)
@@ -1709,28 +1716,29 @@ action_mail_show_source_cb (GtkAction *action,
 {
 	EMailBackend *backend;
 	EMailDisplay *display;
-	EMFormatHTML *formatter;
 	CamelFolder *folder;
+	CamelMimeMessage *message;
 	GtkWidget *browser;
 	GPtrArray *uids;
 	const gchar *message_uid;
 
 	backend = e_mail_reader_get_backend (reader);
 	folder = e_mail_reader_get_folder (reader);
-	display = e_mail_reader_get_mail_display (reader);
-	formatter = e_mail_display_get_formatter (display);
 
 	uids = e_mail_reader_get_selected_uids (reader);
 	g_return_if_fail (uids != NULL && uids->len == 1);
 	message_uid = g_ptr_array_index (uids, 0);
 
+	message = camel_folder_get_message_sync (folder, message_uid, NULL, NULL);
+
 	browser = e_mail_browser_new (backend, NULL, NULL, EM_FORMAT_WRITE_MODE_SOURCE);
 	e_mail_reader_set_folder (E_MAIL_READER (browser), folder);
 	e_mail_reader_set_message (E_MAIL_READER (browser), message_uid);
 
 	display = e_mail_reader_get_mail_display (E_MAIL_READER (browser));
-	e_mail_display_set_formatter (display, formatter);
-	e_mail_display_set_mode (display, EM_FORMAT_WRITE_MODE_SOURCE);
+	mail_reader_set_display_formatter_for_message (
+		E_MAIL_READER (browser), display, message_uid, message, folder);
+
 	gtk_widget_show (browser);
 
 	em_utils_uids_free (uids);
@@ -3053,8 +3061,6 @@ format_parser_async_done_cb (GObject *source,
         EMFormat *emf = EM_FORMAT (source);
         struct format_parser_async_closure_ *closure = user_data;
 
-        g_message ("format_parser_async_done for result %p", result);
-
         e_mail_display_set_formatter (closure->display, EM_FORMAT_HTML (emf));
         e_mail_display_load (closure->display, emf->uri_base);
 
@@ -3068,12 +3074,73 @@ format_parser_async_done_cb (GObject *source,
 }
 
 static void
+mail_reader_set_display_formatter_for_message (EMailReader *reader,
+					       EMailDisplay *display,
+					       const gchar *message_uid,
+					       CamelMimeMessage *message,
+					       CamelFolder *folder)
+{
+	SoupSession *session;
+	GHashTable *formatters;
+	EMFormat *formatter;
+	gchar *mail_uri;
+
+	mail_uri = em_format_build_mail_uri (folder, message_uid, NULL, NULL);
+
+	session = webkit_get_default_session ();
+	formatters = g_object_get_data (G_OBJECT (session), "formatters");
+	if (!formatters) {
+		formatters = g_hash_table_new_full (g_str_hash, g_str_equal,
+				(GDestroyNotify) g_free, NULL);
+		g_object_set_data (G_OBJECT (session), "formatters", formatters);
+	}
+
+	if ((formatter = g_hash_table_lookup (formatters, mail_uri)) == NULL) {
+		struct _formatter_weak_ref_closure *formatter_data =
+				g_new0 (struct _formatter_weak_ref_closure, 1);
+
+		struct format_parser_async_closure_ *closure;
+
+		formatter_data->formatters = g_hash_table_ref (formatters);
+		formatter_data->mail_uri = g_strdup (mail_uri);
+
+		formatter = EM_FORMAT (em_format_html_display_new ());
+
+		/* When no EMailDisplay holds reference to the formatter, then
+		 * the formatter can be destroyed. */
+		g_object_weak_ref (G_OBJECT (formatter),
+			(GWeakNotify) formatter_weak_ref_cb, formatter_data);
+
+		formatter->message_uid = g_strdup (message_uid);
+		formatter->uri_base = g_strdup (mail_uri);
+
+		e_mail_reader_connect_headers (reader, formatter);
+
+		closure = g_new0 (struct format_parser_async_closure_, 1);
+		closure->activity = e_mail_reader_new_activity (reader);
+		e_activity_set_text (closure->activity, _("Parsing message"));
+		closure->display = g_object_ref (display);
+
+		em_format_parse_async (formatter, message, folder,
+			e_activity_get_cancellable (closure->activity),
+			format_parser_async_done_cb, closure);
+
+		/* Don't free the mail_uri!! */
+		g_hash_table_insert (formatters, mail_uri, formatter);
+	} else {
+		e_mail_display_set_formatter (display, EM_FORMAT_HTML (formatter));
+		e_mail_display_load (display, formatter->uri_base);
+
+		g_free (mail_uri);
+	}
+}
+
+static void
 mail_reader_message_loaded (EMailReader *reader,
                             const gchar *message_uid,
                             CamelMimeMessage *message)
 {
 	EMailReaderPrivate *priv;
-	EMFormat *formatter;
 	GtkWidget *message_list;
 	EMailBackend *backend;
 	CamelFolder *folder;
@@ -3083,9 +3150,6 @@ mail_reader_message_loaded (EMailReader *reader,
 	EMEvent *event;
 	EMEventTargetMessage *target;
 	GError *error = NULL;
-	gchar *mail_uri;
-	SoupSession *session;
-	GHashTable *formatters;
 
 	priv = E_MAIL_READER_GET_PRIVATE (reader);
 
@@ -3111,52 +3175,8 @@ mail_reader_message_loaded (EMailReader *reader,
 		(EEventTarget *) target);
 
 
-	mail_uri = em_format_build_mail_uri (folder, message_uid, NULL, NULL);
-
-	session = webkit_get_default_session ();
-	formatters = g_object_get_data (G_OBJECT (session), "formatters");
-	if (!formatters) {
-		formatters = g_hash_table_new_full (g_str_hash, g_str_equal,
-			(GDestroyNotify) g_free, NULL);
-		g_object_set_data (G_OBJECT (session), "formatters", formatters);
-	}
-
-
-	if ((formatter = g_hash_table_lookup (formatters, mail_uri)) == NULL) {
-		struct _formatter_weak_ref_closure *formatter_data =
-			g_new0 (struct _formatter_weak_ref_closure, 1);
-
-                struct format_parser_async_closure_ *closure;
-
-		formatter_data->formatters = g_hash_table_ref (formatters);
-		formatter_data->mail_uri = g_strdup (mail_uri);
-
-		formatter = EM_FORMAT (em_format_html_display_new ());
-		/* When no EMailDisplay holds reference to the f ormatter, then
-		 * the formatter can be destroyed. */
-		 g_object_weak_ref (G_OBJECT (formatter), (GWeakNotify) formatter_weak_ref_cb,
-		 		    formatter_data);
-
-		formatter->message_uid = g_strdup (message_uid);
-		formatter->uri_base = g_strdup (mail_uri);
-
-		e_mail_reader_connect_headers (reader, formatter);
-
-                closure = g_new0 (struct format_parser_async_closure_, 1);
-                closure->activity = e_mail_reader_new_activity (reader);
-                e_activity_set_text (closure->activity, _("Parsing message"));
-                closure->display = g_object_ref (display);
-
-		em_format_parse_async (formatter, message, folder,
-			e_activity_get_cancellable (closure->activity),
-                        format_parser_async_done_cb, closure);
-
-		g_hash_table_insert (formatters, mail_uri, formatter);
-		e_mail_display_set_formatter (display, EM_FORMAT_HTML (formatter));
-	} else {
-		e_mail_display_set_formatter (display, EM_FORMAT_HTML (formatter));
-		e_mail_display_load (display, formatter->uri_base);
-	}
+	mail_reader_set_display_formatter_for_message (
+		reader, display, message_uid, message, folder);
 
 	/* Reset the shell view icon. */
 	e_shell_event (shell, "mail-icon", (gpointer) "evolution-mail");
diff --git a/mail/em-format-html.c b/mail/em-format-html.c
index d32f9a7..3891041 100644
--- a/mail/em-format-html.c
+++ b/mail/em-format-html.c
@@ -1314,6 +1314,15 @@ efh_write (EMFormat *emf,
 	camel_stream_write_string (stream, header, cancellable, NULL);
 	g_free (header);
 
+	if (info->mode == EM_FORMAT_WRITE_MODE_SOURCE) {
+
+		efh_write_source (emf, emf->mail_part_list->data,
+			stream, info, cancellable);
+
+		camel_stream_write_string (stream, "</body></html>", cancellable, NULL);
+		return;
+	}
+
 	for (iter = emf->mail_part_list; iter; iter = iter->next) {
 
 		EMFormatPURI *puri = iter->data;



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