diff options
-rw-r--r-- | libemail-engine/e-mail-session-utils.c | 107 | ||||
-rw-r--r-- | libemail-engine/e-mail-session-utils.h | 16 | ||||
-rw-r--r-- | mail/e-mail-reader-utils.c | 64 | ||||
-rw-r--r-- | mail/e-mail-reader-utils.h | 4 | ||||
-rw-r--r-- | mail/mail.error.xml | 4 | ||||
-rw-r--r-- | modules/mail/e-mail-shell-view-actions.c | 79 |
6 files changed, 86 insertions, 188 deletions
diff --git a/libemail-engine/e-mail-session-utils.c b/libemail-engine/e-mail-session-utils.c index 0c05a26df9..2ac4170a2e 100644 --- a/libemail-engine/e-mail-session-utils.c +++ b/libemail-engine/e-mail-session-utils.c @@ -856,110 +856,3 @@ e_mail_session_send_to_finish (EMailSession *session, 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_take_error (simple, error); -} - -gboolean -e_mail_session_unsubscribe_folder_sync (EMailSession *session, - const gchar *folder_uri, - GCancellable *cancellable, - GError **error) -{ - CamelStore *store = NULL; - gchar *folder_name = NULL; - const gchar *message; - gboolean success = FALSE; - - g_return_val_if_fail (E_IS_MAIL_SESSION (session), FALSE); - g_return_val_if_fail (folder_uri != NULL, FALSE); - - success = e_mail_folder_uri_parse ( - CAMEL_SESSION (session), folder_uri, - &store, &folder_name, error); - - if (!success) - return FALSE; - - message = _("Unsubscribing from folder '%s'"); - camel_operation_push_message (cancellable, message, folder_name); - - success = - camel_service_connect_sync ( - CAMEL_SERVICE (store), cancellable, error) && - camel_subscribable_unsubscribe_folder_sync ( - CAMEL_SUBSCRIBABLE (store), - folder_name, cancellable, error); - - camel_operation_pop_message (cancellable); - - g_object_unref (store); - g_free (folder_name); - - 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_check_cancellable (simple, cancellable); - - 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/libemail-engine/e-mail-session-utils.h b/libemail-engine/e-mail-session-utils.h index 2c92216533..aec6a500e6 100644 --- a/libemail-engine/e-mail-session-utils.h +++ b/libemail-engine/e-mail-session-utils.h @@ -75,22 +75,6 @@ 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/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c index f9d5e2f8e8..6d1e1bb177 100644 --- a/mail/e-mail-reader-utils.c +++ b/mail/e-mail-reader-utils.c @@ -377,6 +377,70 @@ e_mail_reader_delete_folder_name (EMailReader *reader, context); } +/* Helper for e_mail_reader_unsubscribe_folder_name() */ +static void +mail_reader_unsubscribe_folder_name_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + CamelSubscribable *subscribable; + AsyncContext *context; + EAlertSink *alert_sink; + GError *error = NULL; + + subscribable = CAMEL_SUBSCRIBABLE (source_object); + context = (AsyncContext *) user_data; + + alert_sink = e_activity_get_alert_sink (context->activity); + + camel_subscribable_unsubscribe_folder_finish ( + subscribable, result, &error); + + if (e_activity_handle_cancellation (context->activity, error)) { + g_error_free (error); + + } else if (error != NULL) { + e_alert_submit ( + alert_sink, "mail:folder-unsubscribe", + context->folder_name, error->message, NULL); + g_error_free (error); + + } else { + e_activity_set_state ( + context->activity, E_ACTIVITY_COMPLETED); + } + + async_context_free (context); +} + +void +e_mail_reader_unsubscribe_folder_name (EMailReader *reader, + CamelStore *store, + const gchar *folder_name) +{ + EActivity *activity; + AsyncContext *context; + GCancellable *cancellable; + + g_return_if_fail (E_IS_MAIL_READER (reader)); + g_return_if_fail (CAMEL_IS_SUBSCRIBABLE (store)); + g_return_if_fail (folder_name != NULL); + + activity = e_mail_reader_new_activity (reader); + cancellable = e_activity_get_cancellable (activity); + + context = g_slice_new0 (AsyncContext); + context->activity = activity; + context->reader = g_object_ref (reader); + context->folder_name = g_strdup (folder_name); + + camel_subscribable_unsubscribe_folder ( + CAMEL_SUBSCRIBABLE (store), folder_name, + G_PRIORITY_DEFAULT, cancellable, + mail_reader_unsubscribe_folder_name_cb, + context); +} + guint e_mail_reader_mark_selected (EMailReader *reader, guint32 mask, diff --git a/mail/e-mail-reader-utils.h b/mail/e-mail-reader-utils.h index e2a8dee06a..c75d7d760f 100644 --- a/mail/e-mail-reader-utils.h +++ b/mail/e-mail-reader-utils.h @@ -43,6 +43,10 @@ void e_mail_reader_delete_folder_name (EMailReader *reader, CamelStore *store, const gchar *folder_name); +void e_mail_reader_unsubscribe_folder_name + (EMailReader *reader, + CamelStore *store, + const gchar *folder_name); guint e_mail_reader_mark_selected (EMailReader *reader, guint32 mask, guint32 set); diff --git a/mail/mail.error.xml b/mail/mail.error.xml index 5da0fa52ab..ed3856e51a 100644 --- a/mail/mail.error.xml +++ b/mail/mail.error.xml @@ -471,8 +471,8 @@ An mbox account will be created to preserve the old mbox folders. You can delete </error> <error id="folder-unsubscribe" type="warning"> - <_primary>Failed to unsubscribe from folder.</_primary> - <_secondary>The reported error was "{0}".</_secondary> + <_primary>Failed to unsubscribe from folder "{0}".</_primary> + <_secondary>The reported error was "{1}".</_secondary> </error> <error id="no-retrieve-message" type="warning"> diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c index 9306704ed7..04d23ef509 100644 --- a/modules/mail/e-mail-shell-view-actions.c +++ b/modules/mail/e-mail-shell-view-actions.c @@ -26,35 +26,6 @@ #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 (e_activity_handle_cancellation (activity, error)) { - 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) { @@ -616,48 +587,30 @@ static void action_mail_folder_unsubscribe_cb (GtkAction *action, EMailShellView *mail_shell_view) { + EMailShellContent *mail_shell_content; EMailShellSidebar *mail_shell_sidebar; - EShellBackend *shell_backend; - EShellContent *shell_content; - EShellView *shell_view; - EMailBackend *backend; - EMailSession *session; + EMailView *mail_view; EMFolderTree *folder_tree; - EActivity *activity; - EAlertSink *alert_sink; - GCancellable *cancellable; - gchar *folder_uri; + CamelStore *selected_store = NULL; + gchar *selected_folder_name = NULL; + + mail_shell_content = mail_shell_view->priv->mail_shell_content; + mail_view = e_mail_shell_content_get_mail_view (mail_shell_content); mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar; folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar); - 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 (); - - alert_sink = E_ALERT_SINK (shell_content); - e_activity_set_alert_sink (activity, alert_sink); - - cancellable = camel_operation_new (); - e_activity_set_cancellable (activity, cancellable); - - e_shell_backend_add_activity (shell_backend, activity); - - folder_uri = em_folder_tree_get_selected_uri (folder_tree); - - e_mail_session_unsubscribe_folder ( - session, folder_uri, G_PRIORITY_DEFAULT, cancellable, - (GAsyncReadyCallback) mail_folder_unsubscribe_done_cb, - activity); + em_folder_tree_get_selected ( + folder_tree, &selected_store, &selected_folder_name); + g_return_if_fail (CAMEL_IS_STORE (selected_store)); + g_return_if_fail (selected_folder_name != NULL); - g_free (folder_uri); + e_mail_reader_unsubscribe_folder_name ( + E_MAIL_READER (mail_view), + selected_store, selected_folder_name); - g_object_unref (cancellable); + g_object_unref (selected_store); + g_free (selected_folder_name); } static void |