From 3449e5fcc7f9c797fcde7f2a444b1eb7a934cd81 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Wed, 13 Apr 2011 10:30:40 -0400 Subject: Adapt mail to the new ESource API. --- mail/e-mail-account-store.c | 315 +++++++++++++++++++------------------------- 1 file changed, 134 insertions(+), 181 deletions(-) (limited to 'mail/e-mail-account-store.c') diff --git a/mail/e-mail-account-store.c b/mail/e-mail-account-store.c index 2dac692d82..1c5dedf52e 100644 --- a/mail/e-mail-account-store.c +++ b/mail/e-mail-account-store.c @@ -23,11 +23,11 @@ #include #include +#include #include #include -#include #include #include @@ -101,24 +101,6 @@ index_item_free (IndexItem *item) g_slice_free (IndexItem, item); } -static void -mail_account_store_save_default (EMailAccountStore *store) -{ - EAccountList *account_list; - EAccount *account; - CamelService *service; - const gchar *uid; - - service = e_mail_account_store_get_default_service (store); - - account_list = e_get_account_list (); - uid = camel_service_get_uid (service); - account = e_get_account_by_uid (uid); - g_return_if_fail (account != NULL); - - e_account_list_set_default (account_list, account); -} - static gboolean mail_account_store_get_iter (EMailAccountStore *store, CamelService *service, @@ -237,6 +219,46 @@ mail_account_store_service_notify_cb (CamelService *service, mail_account_store_update_row (store, service, &iter); } +static void +mail_account_store_remove_source_cb (ESource *source, + GAsyncResult *result, + EMailAccountStore *store) +{ + GError *error = NULL; + + /* FIXME EMailAccountStore should implement EAlertSink. */ + if (!e_source_remove_finish (source, result, &error)) { + g_warning ("%s: %s", G_STRFUNC, error->message); + g_error_free (error); + } + + g_return_if_fail (store->priv->busy_count > 0); + store->priv->busy_count--; + g_object_notify (G_OBJECT (store), "busy"); + + g_object_unref (store); +} + +static void +mail_account_store_write_source_cb (ESource *source, + GAsyncResult *result, + EMailAccountStore *store) +{ + GError *error = NULL; + + /* FIXME EMailAccountStore should implement EAlertSink. */ + if (!e_source_write_finish (source, result, &error)) { + g_warning ("%s: %s", G_STRFUNC, error->message); + g_error_free (error); + } + + g_return_if_fail (store->priv->busy_count > 0); + store->priv->busy_count--; + g_object_notify (G_OBJECT (store), "busy"); + + g_object_unref (store); +} + static void mail_account_store_clean_index (EMailAccountStore *store) { @@ -427,23 +449,34 @@ static void mail_account_store_constructed (GObject *object) { EMailAccountStore *store; + EMailSession *session; + ESourceRegistry *registry; const gchar *config_dir; /* Chain up to parent's constructed() method. */ G_OBJECT_CLASS (e_mail_account_store_parent_class)->constructed (object); store = E_MAIL_ACCOUNT_STORE (object); + session = e_mail_account_store_get_session (store); + registry = e_mail_session_get_registry (session); + + /* Bind the default mail account ESource to our default + * CamelService, with help from some transform functions. */ + g_object_bind_property_full ( + registry, "default-mail-account", + store, "default-service", + G_BINDING_BIDIRECTIONAL | + G_BINDING_SYNC_CREATE, + e_binding_transform_source_to_service, + e_binding_transform_service_to_source, + session, (GDestroyNotify) NULL); + config_dir = mail_session_get_config_dir (); /* XXX Should we take the filename as a constructor property? */ store->priv->sort_order_filename = g_build_filename ( config_dir, "sortorder.ini", NULL); - /* XXX This is kinda lame, but should work until EAccount dies. */ - g_signal_connect ( - object, "notify::default-service", - G_CALLBACK (mail_account_store_save_default), NULL); - e_extensible_load_extensions (E_EXTENSIBLE (object)); } @@ -458,94 +491,73 @@ static void mail_account_store_service_removed (EMailAccountStore *store, CamelService *service) { - /* XXX On the account-mgmt branch this operation is asynchronous. - * The 'busy_count' is bumped until changes are written back - * to the D-Bus service. For now I guess we'll just block. */ - - EAccountList *account_list; - EAccount *account; EMailSession *session; - MailFolderCache *cache; - CamelProvider *provider; + ESourceRegistry *registry; + ESource *source; const gchar *uid; session = e_mail_account_store_get_session (store); - cache = e_mail_session_get_folder_cache (session); + registry = e_mail_session_get_registry (session); - mail_folder_cache_service_removed (cache, service); - - account_list = e_get_account_list (); uid = camel_service_get_uid (service); - account = e_get_account_by_uid (uid); - g_return_if_fail (account != NULL); - - /* no change */ - if (!account->enabled) - return; - - provider = camel_service_get_provider (service); - g_return_if_fail (provider != NULL); - - if (provider->flags & CAMEL_PROVIDER_IS_STORAGE) - mail_disconnect_store (CAMEL_STORE (service)); + source = e_source_registry_ref_source (registry, uid); + + /* If this ESource is part of a collection, we need to remove + * the entire collection. Check the ESource and its ancestors + * for a collection extension and remove the containing source. */ + if (source != NULL) { + ESource *collection; + + collection = e_source_registry_find_extension ( + registry, source, E_SOURCE_EXTENSION_COLLECTION); + if (collection != NULL) { + g_object_unref (source); + source = collection; + } + } - /* Remove all the proxies the account has created. - * FIXME This proxy stuff belongs in evolution-groupwise. */ - e_account_list_remove_account_proxies (account_list, account); + if (source != NULL) { + store->priv->busy_count++; + g_object_notify (G_OBJECT (store), "busy"); - e_account_list_remove (account_list, account); + /* XXX Should this be cancellable? */ + e_source_remove ( + source, NULL, (GAsyncReadyCallback) + mail_account_store_remove_source_cb, + g_object_ref (store)); - e_account_list_save (account_list); + g_object_unref (source); + } } static void mail_account_store_service_enabled (EMailAccountStore *store, CamelService *service) { - /* XXX On the account-mgmt branch this operation is asynchronous. - * The 'busy_count' is bumped until changes are written back - * to the D-Bus service. For now I guess we'll just block. */ - EMailSession *session; - MailFolderCache *cache; - GSettings *settings; + ESourceRegistry *registry; + ESource *source; const gchar *uid; session = e_mail_account_store_get_session (store); - cache = e_mail_session_get_folder_cache (session); - - mail_folder_cache_service_enabled (cache, service); + registry = e_mail_session_get_registry (session); uid = camel_service_get_uid (service); + source = e_source_registry_ref_source (registry, uid); - /* Handle built-in services that don't have an EAccount. */ + if (source != NULL) { + e_source_set_enabled (source, TRUE); - if (g_strcmp0 (uid, E_MAIL_SESSION_LOCAL_UID) == 0) { - settings = g_settings_new ("org.gnome.evolution.mail"); - g_settings_set_boolean (settings, "enable-local", TRUE); - g_object_unref (settings); - - } else if (g_strcmp0 (uid, E_MAIL_SESSION_VFOLDER_UID) == 0) { - settings = g_settings_new ("org.gnome.evolution.mail"); - g_settings_set_boolean (settings, "enable-vfolders", TRUE); - g_object_unref (settings); - - } else { - EAccountList *account_list; - EAccount *account; - - account_list = e_get_account_list (); - account = e_get_account_by_uid (uid); - g_return_if_fail (account != NULL); - - /* no change */ - if (account->enabled) - return; + store->priv->busy_count++; + g_object_notify (G_OBJECT (store), "busy"); - account->enabled = TRUE; + /* XXX Should this be cancellable? */ + e_source_write ( + source, NULL, (GAsyncReadyCallback) + mail_account_store_write_source_cb, + g_object_ref (store)); - e_account_list_change (account_list, account); - e_account_list_save (account_list); + g_object_unref (source); } } @@ -553,63 +565,30 @@ static void mail_account_store_service_disabled (EMailAccountStore *store, CamelService *service) { - /* XXX On the account-mgmt branch this operation is asynchronous. - * The 'busy_count' is bumped until changes are written back - * to the D-Bus service. For now I guess we'll just block. */ - EMailSession *session; - MailFolderCache *cache; - GSettings *settings; + ESourceRegistry *registry; + ESource *source; const gchar *uid; session = e_mail_account_store_get_session (store); - cache = e_mail_session_get_folder_cache (session); - - mail_folder_cache_service_disabled (cache, service); + registry = e_mail_session_get_registry (session); uid = camel_service_get_uid (service); + source = e_source_registry_ref_source (registry, uid); - /* Handle built-in services that don't have an EAccount. */ + if (source != NULL) { + e_source_set_enabled (source, FALSE); - if (g_strcmp0 (uid, E_MAIL_SESSION_LOCAL_UID) == 0) { - settings = g_settings_new ("org.gnome.evolution.mail"); - g_settings_set_boolean (settings, "enable-local", FALSE); - g_object_unref (settings); - - } else if (g_strcmp0 (uid, E_MAIL_SESSION_VFOLDER_UID) == 0) { - settings = g_settings_new ("org.gnome.evolution.mail"); - g_settings_set_boolean (settings, "enable-vfolders", FALSE); - g_object_unref (settings); - - } else { - EAccountList *account_list; - EAccount *account; - CamelProvider *provider; + store->priv->busy_count++; + g_object_notify (G_OBJECT (store), "busy"); - account_list = e_get_account_list (); - account = e_get_account_by_uid (uid); - g_return_if_fail (account != NULL); + /* XXX Should this be cancellable? */ + e_source_write ( + source, NULL, (GAsyncReadyCallback) + mail_account_store_write_source_cb, + g_object_ref (store)); - /* no change */ - if (!account->enabled) - return; - - account->enabled = FALSE; - - provider = camel_service_get_provider (service); - g_return_if_fail (provider != NULL); - - if (provider->flags & CAMEL_PROVIDER_IS_STORAGE) - mail_disconnect_store (CAMEL_STORE (service)); - - /* FIXME This proxy stuff belongs in evolution-groupwise. */ - e_account_list_remove_account_proxies (account_list, account); - - if (account->parent_uid != NULL) - e_account_list_remove (account_list, account); - - e_account_list_change (account_list, account); - e_account_list_save (account_list); + g_object_unref (source); } } @@ -643,25 +622,14 @@ mail_account_store_remove_requested (EMailAccountStore *store, GtkWindow *parent_window, CamelService *service) { - EAccountList *account_list; - EAccount *account; - const gchar *alert; - const gchar *uid; gint response; - account_list = e_get_account_list (); - uid = camel_service_get_uid (service); - account = e_get_account_by_uid (uid); - - g_return_val_if_fail (account != NULL, FALSE); + /* FIXME Need to use "mail:ask-delete-account-with-proxies" if the + * mail account has proxies. But this is groupwise-specific + * and doesn't belong here anyway. Think of a better idea. */ - /* FIXME This proxy stuff belongs in evolution-groupwise. */ - if (e_account_list_account_has_proxies (account_list, account)) - alert = "mail:ask-delete-account-with-proxies"; - else - alert = "mail:ask-delete-account"; - - response = e_alert_run_dialog_for_args (parent_window, alert, NULL); + response = e_alert_run_dialog_for_args ( + parent_window, "mail:ask-delete-account", NULL); return (response == GTK_RESPONSE_YES); } @@ -679,34 +647,12 @@ mail_account_store_disable_requested (EMailAccountStore *store, GtkWindow *parent_window, CamelService *service) { - EAccountList *account_list; - EAccount *account; - const gchar *uid; - gint response; - - account_list = e_get_account_list (); - uid = camel_service_get_uid (service); - account = e_get_account_by_uid (uid); - - /* "On This Computer" and "Search Folders" do not have - * EAccounts, so just silently return TRUE if we failed - * to find a matching EAccount for the CamelService. */ - - /* Silently return TRUE if we failed to find a matching - * EAccount since "On This Computer" and "Search Folders" - * do not have EAccounts. */ - if (account == NULL) - return TRUE; + /* FIXME Need to check whether the account has proxies and run a + * "mail:ask-delete-proxy-accounts" alert dialog, but this + * is groupwise-specific and doesn't belong here anyway. + * Think of a better idea. */ - /* FIXME This proxy stuff belongs in evolution-groupwise. */ - if (e_account_list_account_has_proxies (account_list, account)) - response = e_alert_run_dialog_for_args ( - parent_window, - "mail:ask-delete-proxy-accounts", NULL); - else - response = GTK_RESPONSE_YES; - - return (response == GTK_RESPONSE_YES); + return TRUE; } static void @@ -1086,13 +1032,20 @@ e_mail_account_store_add_service (EMailAccountStore *store, g_object_unref (settings); } else { - EAccount *account; + EMailSession *session; + ESourceRegistry *registry; + ESource *source; + + session = e_mail_account_store_get_session (store); - account = e_get_account_by_uid (uid); - g_return_if_fail (account != NULL); + registry = e_mail_session_get_registry (session); + source = e_source_registry_ref_source (registry, uid); + g_return_if_fail (source != NULL); builtin = FALSE; - enabled = account->enabled; + enabled = e_source_get_enabled (source); + + g_object_unref (source); } /* Where do we insert new services now that accounts can be -- cgit v1.2.3