[evolution/webkit] Remove mail_store_prepare_offline().



commit e940829687c84dd7129223c87baa0627d0cde72e
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue May 17 12:08:07 2011 -0400

    Remove mail_store_prepare_offline().
    
    Use e_mail_store_prepare_for_offline() instead.

 mail/e-mail-store-utils.c                |   74 +++++++++++++++++++++++++++
 mail/e-mail-store-utils.h                |   10 ++++
 mail/mail-ops.c                          |   81 ------------------------------
 mail/mail-ops.h                          |    4 --
 mail/mail.error.xml                      |    5 ++
 modules/mail/e-mail-shell-view-actions.c |   53 ++++++++++++++++++--
 modules/mail/e-mail-shell-view-private.h |    1 +
 7 files changed, 139 insertions(+), 89 deletions(-)
---
diff --git a/mail/e-mail-store-utils.c b/mail/e-mail-store-utils.c
index 57304f9..47c9970 100644
--- a/mail/e-mail-store-utils.c
+++ b/mail/e-mail-store-utils.c
@@ -188,3 +188,77 @@ e_mail_store_go_online_finish (CamelStore *store,
 	/* Assume success unless a GError is set. */
 	return !g_simple_async_result_propagate_error (simple, error);
 }
+
+static void
+mail_store_prepare_for_offline_thread (GSimpleAsyncResult *simple,
+                                       CamelStore *store,
+                                       GCancellable *cancellable)
+{
+	CamelService *service;
+	gchar *service_name;
+	GError *error = NULL;
+
+	service = CAMEL_SERVICE (store);
+
+	service_name = camel_service_get_name (service, TRUE);
+	camel_operation_push_message (
+		cancellable, _("Preparing account '%s' for offline"),
+		service_name);
+	g_free (service_name);
+
+	if (CAMEL_IS_DISCO_STORE (store))
+		camel_disco_store_prepare_for_offline (
+			CAMEL_DISCO_STORE (store), cancellable, &error);
+
+	else if (CAMEL_IS_OFFLINE_STORE (store))
+		camel_offline_store_prepare_for_offline_sync (
+			CAMEL_OFFLINE_STORE (store), cancellable, &error);
+
+	if (error != NULL) {
+		g_simple_async_result_set_from_error (simple, error);
+		g_error_free (error);
+	}
+
+	camel_operation_pop_message (cancellable);
+}
+
+void
+e_mail_store_prepare_for_offline (CamelStore *store,
+                                  gint io_priority,
+                                  GCancellable *cancellable,
+                                  GAsyncReadyCallback callback,
+                                  gpointer user_data)
+{
+	GSimpleAsyncResult *simple;
+
+	g_return_if_fail (CAMEL_IS_STORE (store));
+
+	simple = g_simple_async_result_new (
+		G_OBJECT (store), callback, user_data,
+		e_mail_store_prepare_for_offline);
+
+	g_simple_async_result_run_in_thread (
+		simple, (GSimpleAsyncThreadFunc)
+		mail_store_prepare_for_offline_thread,
+		io_priority, cancellable);
+
+	g_object_unref (simple);
+}
+
+gboolean
+e_mail_store_prepare_for_offline_finish (CamelStore *store,
+                                         GAsyncResult *result,
+                                         GError **error)
+{
+	GSimpleAsyncResult *simple;
+
+	g_return_val_if_fail (
+		g_simple_async_result_is_valid (
+		result, G_OBJECT (store),
+		e_mail_store_prepare_for_offline), FALSE);
+
+	simple = G_SIMPLE_ASYNC_RESULT (result);
+
+	/* Assume success unless a GError is set. */
+	return !g_simple_async_result_propagate_error (simple, error);
+}
diff --git a/mail/e-mail-store-utils.h b/mail/e-mail-store-utils.h
index daf7a98..7610b82 100644
--- a/mail/e-mail-store-utils.h
+++ b/mail/e-mail-store-utils.h
@@ -41,6 +41,16 @@ void		e_mail_store_go_online		(CamelStore *store,
 gboolean	e_mail_store_go_online_finish	(CamelStore *store,
 						 GAsyncResult *result,
 						 GError **error);
+void		e_mail_store_prepare_for_offline
+						(CamelStore *store,
+						 gint io_priority,
+						 GCancellable *cancellable,
+						 GAsyncReadyCallback callback,
+						 gpointer user_data);
+gboolean	e_mail_store_prepare_for_offline_finish
+						(CamelStore *store,
+						 GAsyncResult *result,
+						 GError **error);
 
 G_END_DECLS
 
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
index 0678370..1438805 100644
--- a/mail/mail-ops.c
+++ b/mail/mail-ops.c
@@ -1894,87 +1894,6 @@ mail_save_messages (CamelFolder *folder, GPtrArray *uids, const gchar *path,
 	return id;
 }
 
-/* ** Prepare OFFLINE ***************************************************** */
-
-struct _set_offline_msg {
-	MailMsg base;
-
-	CamelStore *store;
-	gboolean offline;
-	void (*done)(CamelStore *store, gpointer data);
-	gpointer data;
-};
-
-static gchar *
-prepare_offline_desc (struct _set_offline_msg *m)
-{
-	gchar *service_name = camel_service_get_name (CAMEL_SERVICE (m->store), TRUE);
-	gchar *msg;
-
-	msg = g_strdup_printf (_("Preparing account '%s' for offline"), service_name);
-	g_free (service_name);
-
-	return msg;
-}
-
-static void
-prepare_offline_exec (struct _set_offline_msg *m,
-                      GCancellable *cancellable,
-                      GError **error)
-{
-	if (CAMEL_IS_DISCO_STORE (m->store)) {
-		camel_disco_store_prepare_for_offline (
-			CAMEL_DISCO_STORE (m->store),
-			cancellable, error);
-	} else if (CAMEL_IS_OFFLINE_STORE (m->store)) {
-		camel_offline_store_prepare_for_offline_sync (
-			CAMEL_OFFLINE_STORE (m->store),
-			cancellable, error);
-	}
-}
-
-static void
-prepare_offline_done (struct _set_offline_msg *m)
-{
-	if (m->done)
-		m->done (m->store, m->data);
-}
-
-static void
-prepare_offline_free (struct _set_offline_msg *m)
-{
-	g_object_unref (m->store);
-}
-
-static MailMsgInfo prepare_offline_info = {
-	sizeof (struct _set_offline_msg),
-	(MailMsgDescFunc) prepare_offline_desc,
-	(MailMsgExecFunc) prepare_offline_exec,
-	(MailMsgDoneFunc) prepare_offline_done,
-	(MailMsgFreeFunc) prepare_offline_free
-};
-
-gint
-mail_store_prepare_offline (CamelStore *store)
-{
-	struct _set_offline_msg *m;
-	gint id;
-
-	/* Cancel any pending connect first so the set_offline_op
-	 * thread won't get queued behind a hung connect op.
-	 */
-
-	m = mail_msg_new (&prepare_offline_info);
-	m->store = store;
-	g_object_ref (store);
-	m->data = NULL;
-	m->done = NULL;
-
-	id = m->base.seq;
-	mail_msg_unordered_push (m);
-
-	return id;
-}
 /* ** Execute Shell Command ***************************************************** */
 
 void
diff --git a/mail/mail-ops.h b/mail/mail-ops.h
index 58dd8df..2d18b1a 100644
--- a/mail/mail-ops.h
+++ b/mail/mail-ops.h
@@ -112,14 +112,10 @@ void		mail_filter_folder		(EMailSession *session,
 						 const gchar *type,
 						 gboolean notify);
 
-/* Work Offline */
-gint mail_store_prepare_offline (CamelStore *store);
-
 /* filter driver execute shell command async callback */
 void mail_execute_shell_command (CamelFilterDriver *driver, gint argc, gchar **argv, gpointer data);
 
 gint mail_disconnect_store (CamelStore *store);
-gint mail_remove_attachments (CamelFolder *folder, GPtrArray *uids);
 
 G_END_DECLS
 
diff --git a/mail/mail.error.xml b/mail/mail.error.xml
index 8eab30e..82767fc 100644
--- a/mail/mail.error.xml
+++ b/mail/mail.error.xml
@@ -525,5 +525,10 @@ An mbox account will be created to preserve the old mbox folders. You can delete
     <_secondary>The reported error was &quot;{0}&quot;.</_secondary>
   </error>
 
+  <error id="prepare-for-offline" type="warning">
+    <_primary>Failed to download messages for offline viewing.</_primary>
+    <_secondary>The reported error was &quot;{0}&quot;.</_secondary>
+  </error>
+
 </error-list>
 
diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c
index a0a6ec2..dcef6af 100644
--- a/modules/mail/e-mail-shell-view-actions.c
+++ b/modules/mail/e-mail-shell-view-actions.c
@@ -170,17 +170,62 @@ action_mail_create_search_folder_cb (GtkAction *action,
 }
 
 static void
-action_mail_download_foreach_cb (CamelService *service)
+action_mail_download_finished_cb (CamelStore *store,
+                                  GAsyncResult *result,
+                                  EActivity *activity)
 {
-	if (CAMEL_IS_DISCO_STORE (service) || CAMEL_IS_OFFLINE_STORE (service))
-		mail_store_prepare_offline (CAMEL_STORE (service));
+	EAlertSink *alert_sink;
+	GError *error = NULL;
+
+	alert_sink = e_activity_get_alert_sink (activity);
+
+	e_mail_store_prepare_for_offline_finish (store, result, &error);
+
+	if (e_activity_handle_cancellation (activity, error)) {
+		g_error_free (error);
+
+	} else if (error != NULL) {
+		e_alert_submit (
+			alert_sink, "mail:prepare-for-offline",
+			error->message, NULL);
+		g_error_free (error);
+	}
+
+	g_object_unref (activity);
+}
+
+static void
+action_mail_download_foreach_cb (CamelStore *store,
+                                 const gchar *display_name,
+                                 EMailReader *reader)
+{
+	EActivity *activity;
+	GCancellable *cancellable;
+
+	activity = e_mail_reader_new_activity (reader);
+	cancellable = e_activity_get_cancellable (activity);
+
+	e_mail_store_prepare_for_offline (
+		store, G_PRIORITY_DEFAULT,
+		cancellable, (GAsyncReadyCallback)
+		action_mail_download_finished_cb, activity);
 }
 
 static void
 action_mail_download_cb (GtkAction *action,
                          EMailShellView *mail_shell_view)
 {
-	e_mail_store_foreach ((GHFunc) action_mail_download_foreach_cb, NULL);
+	EMailShellContent *mail_shell_content;
+	EMailView *mail_view;
+	EMailReader *reader;
+
+	mail_shell_content = mail_shell_view->priv->mail_shell_content;
+	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
+
+	reader = E_MAIL_READER (mail_view);
+
+	e_mail_store_foreach (
+		(GHFunc) action_mail_download_foreach_cb, reader);
 }
 
 static void
diff --git a/modules/mail/e-mail-shell-view-private.h b/modules/mail/e-mail-shell-view-private.h
index b8c2571..15bcf8c 100644
--- a/modules/mail/e-mail-shell-view-private.h
+++ b/modules/mail/e-mail-shell-view-private.h
@@ -47,6 +47,7 @@
 #include "e-mail-session-utils.h"
 #include "e-mail-sidebar.h"
 #include "e-mail-store.h"
+#include "e-mail-store-utils.h"
 #include "em-composer-utils.h"
 #include "em-folder-properties.h"
 #include "em-folder-selector.h"



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