diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2012-07-07 03:34:39 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2012-07-07 03:35:41 +0800 |
commit | 749b49e5079aaaf171a282f33deb0b12818ba11d (patch) | |
tree | 74a5b593eed428cb8b11c9d2da4e228e13c48e61 | |
parent | 8eae40f7e895782fae19d289090edbb102b01bfd (diff) | |
download | gsoc2013-evolution-749b49e5079aaaf171a282f33deb0b12818ba11d.tar gsoc2013-evolution-749b49e5079aaaf171a282f33deb0b12818ba11d.tar.gz gsoc2013-evolution-749b49e5079aaaf171a282f33deb0b12818ba11d.tar.bz2 gsoc2013-evolution-749b49e5079aaaf171a282f33deb0b12818ba11d.tar.lz gsoc2013-evolution-749b49e5079aaaf171a282f33deb0b12818ba11d.tar.xz gsoc2013-evolution-749b49e5079aaaf171a282f33deb0b12818ba11d.tar.zst gsoc2013-evolution-749b49e5079aaaf171a282f33deb0b12818ba11d.zip |
Disconnect a CamelService after editing its settings.
This will force Evolution to reconnect to the service using the current
settings. However this is not a complete solution. If the new settings
now point to a completely different mail account, we leave behind cached
messages and database tables from the previous account such that you end
up with some weird hybrid of the previous account and current account.
I guess for now the answer is "don't do that", but we should try to
handle that more gracefully in the future -- more for architectural
correctness than it being a common real world use case.
-rw-r--r-- | mail/mail.error.xml | 5 | ||||
-rw-r--r-- | modules/mail/e-mail-shell-backend.c | 82 |
2 files changed, 87 insertions, 0 deletions
diff --git a/mail/mail.error.xml b/mail/mail.error.xml index 65cf052db6..5da0fa52ab 100644 --- a/mail/mail.error.xml +++ b/mail/mail.error.xml @@ -465,6 +465,11 @@ An mbox account will be created to preserve the old mbox folders. You can delete <button stock="gtk-ok" response="GTK_RESPONSE_OK"/> </error> + <error id="disconnect" type="warning"> + <_primary>Failed to disconnect account "{0}".</_primary> + <_secondary>The reported error was "{0}".</_secondary> + </error> + <error id="folder-unsubscribe" type="warning"> <_primary>Failed to unsubscribe from folder.</_primary> <_secondary>The reported error was "{0}".</_secondary> diff --git a/modules/mail/e-mail-shell-backend.c b/modules/mail/e-mail-shell-backend.c index 95fea2edd1..a07a79fe62 100644 --- a/modules/mail/e-mail-shell-backend.c +++ b/modules/mail/e-mail-shell-backend.c @@ -433,6 +433,82 @@ mail_shell_backend_window_added_cb (GtkApplication *application, } static void +mail_shell_backend_disconnect_done_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + CamelService *service; + EActivity *activity; + EAlertSink *alert_sink; + GError *error = NULL; + + service = CAMEL_SERVICE (source_object); + activity = E_ACTIVITY (user_data); + + alert_sink = e_activity_get_alert_sink (activity); + + camel_service_disconnect_finish (service, result, &error); + + if (e_activity_handle_cancellation (activity, error)) { + g_error_free (error); + + } else if (error != NULL) { + e_alert_submit ( + alert_sink, + "mail:disconnect", + camel_service_get_display_name (service), + error->message, NULL); + g_error_free (error); + + } else { + e_activity_set_state (activity, E_ACTIVITY_COMPLETED); + } + + g_object_unref (activity); +} + +static void +mail_shell_backend_changes_committed_cb (EMailConfigWindow *window, + EMailShellBackend *mail_shell_backend) +{ + EMailSession *session; + EShellBackend *shell_backend; + ESource *original_source; + CamelService *service; + EActivity *activity; + GCancellable *cancellable; + GtkWindow *parent; + const gchar *uid; + + session = e_mail_config_window_get_session (window); + original_source = e_mail_config_window_get_original_source (window); + + uid = e_source_get_uid (original_source); + service = camel_session_get_service (CAMEL_SESSION (session), uid); + g_return_if_fail (CAMEL_IS_STORE (service)); + + shell_backend = E_SHELL_BACKEND (mail_shell_backend); + + activity = e_activity_new (); + + /* XXX Can we be sure the parent window will always implement + * EAlertSink? May need some kind of fallback behavior. */ + parent = gtk_window_get_transient_for (GTK_WINDOW (window)); + e_activity_set_alert_sink (activity, E_ALERT_SINK (parent)); + + cancellable = camel_operation_new (); + e_activity_set_cancellable (activity, cancellable); + + e_shell_backend_add_activity (shell_backend, activity); + + camel_service_disconnect ( + service, TRUE, G_PRIORITY_DEFAULT, cancellable, + mail_shell_backend_disconnect_done_cb, activity); + + g_object_unref (cancellable); +} + +static void mail_shell_backend_constructed (GObject *object) { EShell *shell; @@ -772,6 +848,12 @@ e_mail_shell_backend_edit_account (EMailShellBackend *mail_shell_backend, priv->editor = e_mail_config_window_new (session, mail_account); gtk_window_set_transient_for (GTK_WINDOW (priv->editor), parent); g_object_add_weak_pointer (G_OBJECT (priv->editor), &priv->editor); + + g_signal_connect ( + priv->editor, "changes-committed", + G_CALLBACK (mail_shell_backend_changes_committed_cb), + mail_shell_backend); + gtk_widget_show (priv->editor); } |