[evolution] Disconnect a CamelService after editing its settings.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Disconnect a CamelService after editing its settings.
- Date: Fri, 6 Jul 2012 19:42:36 +0000 (UTC)
commit 749b49e5079aaaf171a282f33deb0b12818ba11d
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Jul 6 15:34:39 2012 -0400
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.
mail/mail.error.xml | 5 ++
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 65cf052..5da0fa5 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 95fea2e..a07a79f 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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]