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 /mail | |
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.
Diffstat (limited to 'mail')
-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 |
5 files changed, 140 insertions, 78 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> |