[evolution/webkit: 86/146] Make EMFormat parsing asynchronous



commit d9279f54d9568815c4a3a29ac11a1b262f5a9191
Author: Dan VrÃtil <dvratil redhat com>
Date:   Mon Dec 19 19:11:40 2011 +0100

    Make EMFormat parsing asynchronous

 em-format/em-format.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++-
 em-format/em-format.h |    9 ++++++++
 mail/e-mail-reader.c  |   37 ++++++++++++++++++++++----------
 3 files changed, 87 insertions(+), 14 deletions(-)
---
diff --git a/em-format/em-format.c b/em-format/em-format.c
index 0b550c4..36b5a2b 100644
--- a/em-format/em-format.c
+++ b/em-format/em-format.c
@@ -1300,6 +1300,11 @@ em_format_finalize (GObject *object)
 		emf->message_uid = NULL;
 	}
 
+	if (emf->uri_base) {
+                g_free (emf->uri_base);
+                emf->uri_base = NULL;
+        }
+
 	if (emf->message) {
 		g_object_unref (emf->message);
 		emf->message = NULL;
@@ -1863,17 +1868,63 @@ em_format_parse (EMFormat *emf,
 
 	/* Create a special PURI with entire message */
 	puri = em_format_puri_new (emf, sizeof (EMFormatPURI),
-		(CamelMimePart *) message, part_id->str);
+		(CamelMimePart *) emf->message, part_id->str);
 	puri->mime_type = g_strdup ("text/html");
 	em_format_add_puri (emf, puri);
 
         info.force_handler = TRUE;
-	em_format_parse_part_as (emf, CAMEL_MIME_PART (message), part_id, &info,
+	em_format_parse_part_as (emf, CAMEL_MIME_PART (emf->message), part_id, &info,
 			"x-evolution/message", cancellable);
 
 	g_string_free (part_id, TRUE);
 }
 
+static void
+emf_start_async_parser (GSimpleAsyncResult *result,
+                        GObject *object,
+                        GCancellable *cancellable)
+{
+        em_format_parse (EM_FORMAT (object), NULL, NULL, cancellable);
+}
+
+void
+em_format_parse_async (EMFormat *emf,
+                       CamelMimeMessage *message,
+                       CamelFolder *folder,
+                       GCancellable *cancellable,
+                       GAsyncReadyCallback callback,
+                       gpointer user_data)
+{
+        GSimpleAsyncResult *result;
+
+        g_return_if_fail (EM_IS_FORMAT (emf));
+
+        if (g_cancellable_is_cancelled (cancellable))
+          return;
+
+        if (message) {
+          g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
+
+          if (emf->message)
+            g_object_unref (emf->message);
+          emf->message = g_object_ref (message);
+        }
+
+        if (folder) {
+          g_return_if_fail (CAMEL_IS_FOLDER  (folder));
+
+          if (emf->folder)
+            g_object_unref (emf->folder);
+          emf->folder = g_object_ref (folder);
+        }
+
+        result = g_simple_async_result_new (G_OBJECT (emf), callback, 
+                user_data, em_format_parse_async);
+        g_simple_async_result_run_in_thread (result, emf_start_async_parser,
+                G_PRIORITY_DEFAULT, cancellable);
+}
+
+
 void
 em_format_parse_part_as (EMFormat *emf,
 			 CamelMimePart *part,
diff --git a/em-format/em-format.h b/em-format/em-format.h
index 0007579..221f6d1 100644
--- a/em-format/em-format.h
+++ b/em-format/em-format.h
@@ -167,6 +167,7 @@ struct _EMFormat {
 	CamelMimeMessage *message;
 	CamelFolder *folder;
 	gchar *message_uid;
+        gchar *uri_base;
 
 	/* Defines order in which parts should be displayed */
 	GList *mail_part_list;
@@ -243,6 +244,14 @@ void			em_format_parse			(EMFormat *emf,
 							 CamelMimeMessage *message,
 							 CamelFolder *folder,
 							 GCancellable *cancellable);
+
+void                    em_format_parse_async           (EMFormat *emf,
+                                                         CamelMimeMessage *message,
+                                                         CamelFolder *folder,
+                                                         GCancellable *cancellable,
+                                                         GAsyncReadyCallback callback,
+                                                         gpointer user_data);
+
 void 			em_format_parse_part		(EMFormat *emf,
 							 CamelMimePart *part,
 							 GString *part_id,
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 8198aa1..54daf54 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -2595,6 +2595,7 @@ mail_reader_message_loaded_cb (CamelFolder *folder,
 	GtkWidget *message_list;
 	const gchar *message_uid;
 	GError *error = NULL;
+        GCancellable *cancellable;
 
 	reader = closure->reader;
 	message_uid = closure->message_uid;
@@ -2917,6 +2918,25 @@ formatter_weak_ref_cb (struct _formatter_weak_ref_closure *data,
 }
 
 static void
+format_parser_async_done_cb (GObject *source,
+                             GAsyncResult *result,
+                             gpointer user_data)
+{
+        EMFormat *emf = EM_FORMAT (source);
+        EMailReader *reader = user_data;
+        EMailDisplay *display;
+
+        display = e_mail_reader_get_mail_display (reader);
+
+        e_mail_display_set_formatter (display, EM_FORMAT_HTML (emf));
+        e_mail_display_load (display, emf->uri_base);
+
+        /* Remove the reference added when formatter was created,
+         * so that only owners are EMailDisplays */
+        g_object_unref (emf);
+}
+
+static void
 mail_reader_message_loaded (EMailReader *reader,
                             const gchar *message_uid,
                             CamelMimeMessage *message)
@@ -2937,7 +2957,6 @@ mail_reader_message_loaded (EMailReader *reader,
 	gchar *mail_uri;
 	SoupSession *session;
 	GHashTable *formatters;
-	GCancellable *cancellable;
 
 	priv = E_MAIL_READER_GET_PRIVATE (reader);
 
@@ -2990,11 +3009,12 @@ mail_reader_message_loaded (EMailReader *reader,
 		 		    formatter_data);
 
 		EM_FORMAT (formatter)->message_uid = g_strdup (message_uid);
+		EM_FORMAT (formatter)->uri_base = g_strdup (mail_uri);
+
+		/* FIXME WEBKIT Not passing GCancellable */
+		em_format_parse_async (EM_FORMAT (formatter), message, folder,
+			NULL, format_parser_async_done_cb, reader);
 
-		/* Parse the message.
-		 * FIXME WEBKIT: This should probably be asynchronous since it
-		 * can block for some time...*/
-		em_format_parse (EM_FORMAT (formatter), message, folder, NULL);
 		g_hash_table_insert (formatters, mail_uri, formatter);
 	} else {
 		/* Add reference that would be otherwise added when
@@ -3002,13 +3022,6 @@ mail_reader_message_loaded (EMailReader *reader,
 		 g_object_ref (formatter);
 	}
 
-	e_mail_display_set_formatter (display, EM_FORMAT_HTML (formatter));
-	e_mail_display_load (display, mail_uri);
-
-	/* Remove the reference added when formatter was created,
-	 * so that only owners are EMailDisplays */
-	g_object_unref (formatter);
-
 	/* Reset the shell view icon. */
 	e_shell_event (shell, "mail-icon", (gpointer) "evolution-mail");
 



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