[evolution/wip/gsettings] Kill em_folder_utils_unsubscribe_folder().



commit a2747569c8c4716c83880a6cc796ee1bd9b3f420
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Oct 31 17:16:57 2010 -0400

    Kill em_folder_utils_unsubscribe_folder().
    
    Use e_mail_session_unsubscribe_folder() instead.

 mail/e-mail-session-utils.c              |  119 ++++++++++++++++++++++++++++++
 mail/e-mail-session-utils.h              |   16 ++++
 mail/em-folder-utils.c                   |   75 -------------------
 mail/em-folder-utils.h                   |    3 -
 mail/mail.error.xml                      |    5 +
 modules/mail/e-mail-shell-view-actions.c |   50 ++++++++++++-
 modules/mail/e-mail-shell-view-private.h |    2 +
 7 files changed, 190 insertions(+), 80 deletions(-)
---
diff --git a/mail/e-mail-session-utils.c b/mail/e-mail-session-utils.c
index 2369a69..0df301f 100644
--- a/mail/e-mail-session-utils.c
+++ b/mail/e-mail-session-utils.c
@@ -50,6 +50,7 @@ struct _AsyncContext {
 
 	GPtrArray *post_to_uris;
 
+	gchar *folder_uri;
 	gchar *destination;
 	gchar *message_uid;
 	gchar *transport_uri;
@@ -91,6 +92,7 @@ async_context_free (AsyncContext *context)
 		g_ptr_array_free (context->post_to_uris, TRUE);
 	}
 
+	g_free (context->folder_uri);
 	g_free (context->destination);
 	g_free (context->message_uid);
 	g_free (context->transport_uri);
@@ -791,3 +793,120 @@ e_mail_session_send_to_finish (EMailSession *session,
 	/* Assume success unless a GError is set. */
 	return !g_simple_async_result_propagate_error (simple, error);
 }
+
+static void
+mail_session_unsubscribe_folder_thread (GSimpleAsyncResult *simple,
+                                        EMailSession *session,
+                                        GCancellable *cancellable)
+{
+	AsyncContext *context;
+	GError *error = NULL;
+
+	context = g_simple_async_result_get_op_res_gpointer (simple);
+
+	e_mail_session_unsubscribe_folder_sync (
+		session, context->folder_uri, cancellable, &error);
+
+	if (error != NULL) {
+		g_simple_async_result_set_from_error (simple, error);
+		g_error_free (error);
+	}
+}
+
+gboolean
+e_mail_session_unsubscribe_folder_sync (EMailSession *session,
+                                        const gchar *folder_uri,
+                                        GCancellable *cancellable,
+                                        GError **error)
+{
+	CamelURL *url;
+	CamelStore *store;
+	CamelProviderURLFlags flags;
+	const gchar *message;
+	const gchar *path = NULL;
+	gboolean success = FALSE;
+
+	g_return_val_if_fail (E_IS_MAIL_SESSION (session), FALSE);
+	g_return_val_if_fail (folder_uri != NULL, FALSE);
+
+	message = _("Unsubscribing from folder '%s'");
+	camel_operation_push_message (cancellable, message, folder_uri);
+
+	store = camel_session_get_store (
+		CAMEL_SESSION (session), folder_uri, error);
+	if (store == NULL)
+		goto exit;
+
+	url = camel_url_new (folder_uri, error);
+	if (url == NULL)
+		goto exit;
+
+	flags = CAMEL_SERVICE (store)->provider->url_flags;
+
+	if (flags & CAMEL_URL_FRAGMENT_IS_PATH)
+		path = url->fragment;
+	else if (url->path != NULL && *url->path != '\0')
+		path = url->path + 1;
+
+	g_return_val_if_fail (path != NULL, FALSE);
+
+	success = camel_store_unsubscribe_folder_sync (
+		store, path, cancellable, error);
+
+	camel_url_free (url);
+
+exit:
+	camel_operation_pop_message (cancellable);
+
+	return success;
+}
+
+void
+e_mail_session_unsubscribe_folder (EMailSession *session,
+                                   const gchar *folder_uri,
+                                   gint io_priority,
+                                   GCancellable *cancellable,
+                                   GAsyncReadyCallback callback,
+                                   gpointer user_data)
+{
+	GSimpleAsyncResult *simple;
+	AsyncContext *context;
+
+	g_return_if_fail (E_IS_MAIL_SESSION (session));
+	g_return_if_fail (folder_uri != NULL);
+
+	context = g_slice_new0 (AsyncContext);
+	context->folder_uri = g_strdup (folder_uri);
+
+	simple = g_simple_async_result_new (
+		G_OBJECT (session), callback, user_data,
+		e_mail_session_unsubscribe_folder);
+
+	g_simple_async_result_set_op_res_gpointer (
+		simple, context, (GDestroyNotify) async_context_free);
+
+	g_simple_async_result_run_in_thread (
+		simple, (GSimpleAsyncThreadFunc)
+		mail_session_unsubscribe_folder_thread,
+		io_priority, cancellable);
+
+	g_object_unref (simple);
+}
+
+gboolean
+e_mail_session_unsubscribe_folder_finish (EMailSession *session,
+                                          GAsyncResult *result,
+                                          GError **error)
+{
+	GSimpleAsyncResult *simple;
+
+	g_return_val_if_fail (
+		g_simple_async_result_is_valid (
+		result, G_OBJECT (session),
+		e_mail_session_unsubscribe_folder), 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-session-utils.h b/mail/e-mail-session-utils.h
index 4d97524..e7ec28d 100644
--- a/mail/e-mail-session-utils.h
+++ b/mail/e-mail-session-utils.h
@@ -69,6 +69,22 @@ void		e_mail_session_send_to		(EMailSession *session,
 gboolean	e_mail_session_send_to_finish	(EMailSession *session,
 						 GAsyncResult *result,
 						 GError **error);
+gboolean	e_mail_session_unsubscribe_folder_sync
+						(EMailSession *session,
+						 const gchar *folder_uri,
+						 GCancellable *cancellable,
+						 GError **error);
+void		e_mail_session_unsubscribe_folder
+						(EMailSession *session,
+						 const gchar *folder_uri,
+						 gint io_priority,
+						 GCancellable *cancellable,
+						 GAsyncReadyCallback callback,
+						 gpointer user_data);
+gboolean	e_mail_session_unsubscribe_folder_finish
+						(EMailSession *session,
+						 GAsyncResult *result,
+						 GError **error);
 
 G_END_DECLS
 
diff --git a/mail/em-folder-utils.c b/mail/em-folder-utils.c
index c2720fc..e84152e 100644
--- a/mail/em-folder-utils.c
+++ b/mail/em-folder-utils.c
@@ -754,81 +754,6 @@ em_folder_utils_create_folder (CamelFolderInfo *folderinfo,
 		gtk_dialog_run (GTK_DIALOG (dialog));
 }
 
-struct _folder_unsub_t {
-	MailMsg base;
-	EMailSession *session;
-	gchar *folder_uri;
-};
-
-static gchar *
-emfu_unsubscribe_folder__desc (struct _folder_unsub_t *msg)
-{
-	return g_strdup_printf (
-		_("Unsubscribing from folder \"%s\""), msg->folder_uri);
-}
-
-static void
-emfu_unsubscribe_folder__exec (struct _folder_unsub_t *msg,
-                               GCancellable *cancellable,
-                               GError **error)
-{
-	CamelStore *store;
-	CamelURL *url;
-	const gchar *path = NULL;
-	gint url_flags;
-
-	store = camel_session_get_store (
-		CAMEL_SESSION (msg->session),
-		msg->folder_uri, error);
-	if (store == NULL)
-		return;
-
-	url = camel_url_new (msg->folder_uri, NULL);
-	url_flags = CAMEL_SERVICE (store)->provider->url_flags;
-
-	if (url_flags & CAMEL_URL_FRAGMENT_IS_PATH)
-		path = url->fragment;
-	else if (url->path != NULL && *url->path != '\0')
-		path = url->path + 1;
-
-	if (path != NULL)
-		camel_store_unsubscribe_folder_sync (
-			store, path, cancellable, error);
-
-	camel_url_free (url);
-}
-
-static void
-emfu_unsubscribe_folder__free (struct _folder_unsub_t *msg)
-{
-	g_object_unref (msg->session);
-	g_free (msg->folder_uri);
-}
-
-static MailMsgInfo unsubscribe_info = {
-	sizeof (struct _folder_unsub_t),
-	(MailMsgDescFunc) emfu_unsubscribe_folder__desc,
-	(MailMsgExecFunc) emfu_unsubscribe_folder__exec,
-	(MailMsgDoneFunc) NULL,
-	(MailMsgFreeFunc) emfu_unsubscribe_folder__free
-};
-
-void
-em_folder_utils_unsubscribe_folder (EMailSession *session,
-                                    const gchar *folder_uri)
-{
-	struct _folder_unsub_t *unsub;
-
-	g_return_if_fail (E_IS_MAIL_SESSION (session));
-	g_return_if_fail (folder_uri != NULL);
-
-	unsub = mail_msg_new (&unsubscribe_info);
-	unsub->session = g_object_ref (session);
-	unsub->folder_uri = g_strdup (folder_uri);
-
-	mail_msg_unordered_push (unsub);
-}
-
 const gchar *
 em_folder_utils_get_icon_name (guint32 flags)
 {
diff --git a/mail/em-folder-utils.h b/mail/em-folder-utils.h
index f67ef50..9d937d2 100644
--- a/mail/em-folder-utils.h
+++ b/mail/em-folder-utils.h
@@ -49,9 +49,6 @@ void		em_folder_utils_delete_folder	(EMailBackend *backend,
 void		em_folder_utils_create_folder	(CamelFolderInfo *folderinfo,
 						 EMFolderTree *emft,
 						 GtkWindow *parent);
-void		em_folder_utils_unsubscribe_folder
-						(EMailSession *session,
-						 const gchar *folder_uri);
 
 const gchar *	em_folder_utils_get_icon_name	(guint32 flags);
 
diff --git a/mail/mail.error.xml b/mail/mail.error.xml
index 60e4d56..0e9dfa1 100644
--- a/mail/mail.error.xml
+++ b/mail/mail.error.xml
@@ -486,5 +486,10 @@ You can choose to ignore this folder, overwrite or append its contents, or quit.
     <_secondary>Folder '{0}' doesn't contain any duplicate message.</_secondary>
     <button stock="gtk-ok" response="GTK_RESPONSE_OK"/>
   </error>
+
+  <error id="folder-unsubscribe" type="warning">
+    <_primary>Failed to unsubscribe from folder.</_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 467afa5..ba21f28 100644
--- a/modules/mail/e-mail-shell-view-actions.c
+++ b/modules/mail/e-mail-shell-view-actions.c
@@ -19,10 +19,39 @@
  *
  */
 
-#include "mail/mail-folder-cache.h"
 #include "e-mail-shell-view-private.h"
 
 static void
+mail_folder_unsubscribe_done_cb (EMailSession *session,
+                                 GAsyncResult *result,
+                                 EActivity *activity)
+{
+	EAlertSink *alert_sink;
+	GError *error = NULL;
+
+	alert_sink = e_activity_get_alert_sink (activity);
+
+	e_mail_session_unsubscribe_folder_finish (session, result, &error);
+
+	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+		e_activity_set_state (activity, E_ACTIVITY_CANCELLED);
+		g_error_free (error);
+
+	} else if (error != NULL) {
+		e_alert_submit (
+			alert_sink,
+			"mail:folder-unsubscribe",
+			error->message, NULL);
+		g_error_free (error);
+
+	} else {
+		e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
+	}
+
+	g_object_unref (activity);
+}
+
+static void
 action_gal_save_custom_view_cb (GtkAction *action,
                                 EMailShellView *mail_shell_view)
 {
@@ -587,10 +616,14 @@ action_mail_folder_unsubscribe_cb (GtkAction *action,
 {
 	EMailShellSidebar *mail_shell_sidebar;
 	EShellBackend *shell_backend;
+	EShellContent *shell_content;
 	EShellView *shell_view;
 	EMailBackend *backend;
 	EMailSession *session;
 	EMFolderTree *folder_tree;
+	EActivity *activity;
+	EAlertSink *alert_sink;
+	GCancellable *cancellable;
 	gchar *folder_uri;
 
 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
@@ -598,12 +631,25 @@ action_mail_folder_unsubscribe_cb (GtkAction *action,
 
 	shell_view = E_SHELL_VIEW (mail_shell_view);
 	shell_backend = e_shell_view_get_shell_backend (shell_view);
+	shell_content = e_shell_view_get_shell_content (shell_view);
 
 	backend = E_MAIL_BACKEND (shell_backend);
 	session = e_mail_backend_get_session (backend);
 
+	activity = e_activity_new ();
+	cancellable = camel_operation_new ();
+	alert_sink = E_ALERT_SINK (shell_content);
+	e_activity_set_alert_sink (activity, alert_sink);
+	e_activity_set_cancellable (activity, cancellable);
+	e_shell_backend_add_activity (shell_backend, activity);
+
 	folder_uri = em_folder_tree_get_selected_uri (folder_tree);
-	em_folder_utils_unsubscribe_folder (session, folder_uri);
+
+	e_mail_session_unsubscribe_folder (
+		session, folder_uri, G_PRIORITY_DEFAULT, cancellable,
+		(GAsyncReadyCallback) mail_folder_unsubscribe_done_cb,
+		activity);
+
 	g_free (folder_uri);
 }
 
diff --git a/modules/mail/e-mail-shell-view-private.h b/modules/mail/e-mail-shell-view-private.h
index 92f00d4..806b408 100644
--- a/modules/mail/e-mail-shell-view-private.h
+++ b/modules/mail/e-mail-shell-view-private.h
@@ -43,6 +43,7 @@
 #include "e-mail-local.h"
 #include "e-mail-reader.h"
 #include "e-mail-session.h"
+#include "e-mail-session-utils.h"
 #include "e-mail-sidebar.h"
 #include "e-mail-store.h"
 #include "em-composer-utils.h"
@@ -53,6 +54,7 @@
 #include "em-subscription-editor.h"
 #include "em-utils.h"
 #include "mail-autofilter.h"
+#include "mail-folder-cache.h"
 #include "mail-ops.h"
 #include "mail-send-recv.h"
 #include "mail-tools.h"



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