diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2010-11-01 05:16:57 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-11-01 10:54:30 +0800 |
commit | c211a974e3d532077b3be3235ff2e891533b9c3c (patch) | |
tree | 84b380a0ba37b9ec0feec3b61cac5725773c8534 | |
parent | ccc2b3a14bf19b3db1d837887a07e74f50db078c (diff) | |
download | gsoc2013-evolution-c211a974e3d532077b3be3235ff2e891533b9c3c.tar gsoc2013-evolution-c211a974e3d532077b3be3235ff2e891533b9c3c.tar.gz gsoc2013-evolution-c211a974e3d532077b3be3235ff2e891533b9c3c.tar.bz2 gsoc2013-evolution-c211a974e3d532077b3be3235ff2e891533b9c3c.tar.lz gsoc2013-evolution-c211a974e3d532077b3be3235ff2e891533b9c3c.tar.xz gsoc2013-evolution-c211a974e3d532077b3be3235ff2e891533b9c3c.tar.zst gsoc2013-evolution-c211a974e3d532077b3be3235ff2e891533b9c3c.zip |
Kill em_folder_utils_unsubscribe_folder().
Use e_mail_session_unsubscribe_folder() instead.
-rw-r--r-- | mail/e-mail-session-utils.c | 119 | ||||
-rw-r--r-- | mail/e-mail-session-utils.h | 16 | ||||
-rw-r--r-- | mail/em-folder-utils.c | 75 | ||||
-rw-r--r-- | mail/em-folder-utils.h | 3 | ||||
-rw-r--r-- | mail/mail.error.xml | 5 | ||||
-rw-r--r-- | modules/mail/e-mail-shell-view-actions.c | 50 | ||||
-rw-r--r-- | 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 2369a69d35..0df301f67f 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 4d97524f5d..e7ec28dd2d 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 c2720fc5ae..e84152e574 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 f67ef50531..9d937d2424 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 60e4d5670c..0e9dfa151f 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 "{0}".</_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 467afa5ff9..ba21f28b8d 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 92f00d4eb9..806b408772 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" |