[evolution/webkit] Make EMFormat parsing asynchronous
- From: Dan VrÃtil <dvratil src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/webkit] Make EMFormat parsing asynchronous
- Date: Mon, 19 Dec 2011 18:18:05 +0000 (UTC)
commit 1d0dfaaff054a5e26e1465e7f239af305e2d818e
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, 86 insertions(+), 15 deletions(-)
---
diff --git a/em-format/em-format.c b/em-format/em-format.c
index c8825ef..d135e46 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 44db3c0..305ac97 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -2514,7 +2514,25 @@ formatter_weak_ref_cb (struct _formatter_weak_ref_closure *data,
g_free (data->mail_uri);
g_free (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_cb (CamelFolder *folder,
@@ -2522,7 +2540,6 @@ mail_reader_message_loaded_cb (CamelFolder *folder,
EMailReaderClosure *closure)
{
EMailReader *reader;
- EMailDisplay *display;
EMailReaderPrivate *priv;
CamelMimeMessage *message = NULL;
GtkWidget *message_list;
@@ -2530,7 +2547,6 @@ mail_reader_message_loaded_cb (CamelFolder *folder,
EShellBackend *shell_backend;
EShellSettings *shell_settings;
EShell *shell;
- EWebView *web_view;
EMFormatHTMLDisplay *formatter;
EMEvent *event;
EMEventTargetMessage *target;
@@ -2541,6 +2557,7 @@ mail_reader_message_loaded_cb (CamelFolder *folder,
GError *error = NULL;
SoupSession *session;
GHashTable *formatters;
+ GCancellable *cancellable;
reader = closure->reader;
message_uid = closure->message_uid;
@@ -2566,7 +2583,6 @@ mail_reader_message_loaded_cb (CamelFolder *folder,
backend = e_mail_reader_get_backend (reader);
message_list = e_mail_reader_get_message_list (reader);
- display = e_mail_reader_get_mail_display (reader);
if (!message_list) {
/* for cases where message fetching took so long that
@@ -2616,11 +2632,14 @@ mail_reader_message_loaded_cb (CamelFolder *folder,
formatter_data);
EM_FORMAT (formatter)->message_uid = g_strdup (message_uid);
+ EM_FORMAT (formatter)->uri_base = g_strdup (mail_uri);
/* 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);
+ cancellable = e_activity_get_cancellable (closure->activity);
+ em_format_parse_async (EM_FORMAT (formatter), message, folder,
+ cancellable, format_parser_async_done_cb, reader);
g_hash_table_insert (formatters, g_strdup (mail_uri), formatter);
} else {
@@ -2629,14 +2648,6 @@ mail_reader_message_loaded_cb (CamelFolder *folder,
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);
- g_free (mail_uri);
-
/* 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]