From a06e4484b8df804124b5bcf88d94dec5acfba270 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Wed, 6 Oct 2010 23:38:52 -0400 Subject: Give MailSession a permanent home. Global variables in shared libraries are a bad idea. EMailBackend now owns the MailSession instance, which is actually now EMailSession. Move the blocking utility functions in mail-tools.c to e-mail-session.c and add asynchronous variants. Same approach as Camel. Replace EMailReader.get_shell_backend() with EMailReader.get_backend(), which returns an EMailBackend. Easier access to the EMailSession. --- mail/em-folder-tree-model.c | 91 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 17 deletions(-) (limited to 'mail/em-folder-tree-model.c') diff --git a/mail/em-folder-tree-model.c b/mail/em-folder-tree-model.c index 1369f3d1ea..5b22bd0f9d 100644 --- a/mail/em-folder-tree-model.c +++ b/mail/em-folder-tree-model.c @@ -36,7 +36,6 @@ #include #include "mail-config.h" -#include "mail-session.h" #include "mail-tools.h" #include "mail-mt.h" #include "mail-ops.h" @@ -65,6 +64,7 @@ struct _EMFolderTreeModelPrivate { GtkTreeSelection *selection; /* weak reference */ EAccountList *accounts; + EMailSession *session; /* EAccount -> EMFolderTreeStoreInfo */ GHashTable *account_index; @@ -82,7 +82,8 @@ struct _EMFolderTreeModelPrivate { enum { PROP_0, - PROP_SELECTION + PROP_SELECTION, + PROP_SESSION }; enum { @@ -204,10 +205,13 @@ account_changed_cb (EAccountList *accounts, EMFolderTreeModel *model) { EMFolderTreeModelStoreInfo *si; + EMailSession *session; CamelProvider *provider; CamelStore *store; gchar *uri; + session = em_folder_tree_model_get_session (model); + si = g_hash_table_lookup (model->priv->account_index, account); if (si == NULL) return; @@ -226,7 +230,8 @@ account_changed_cb (EAccountList *accounts, return; store = (CamelStore *) camel_session_get_service ( - session, uri, CAMEL_PROVIDER_STORE, NULL); + CAMEL_SESSION (session), uri, + CAMEL_PROVIDER_STORE, NULL); if (store == NULL) return; @@ -249,28 +254,25 @@ account_removed_cb (EAccountList *accounts, } /* HACK: FIXME: the component should listen to the account object directly */ -static void -add_new_store (gchar *uri, - CamelStore *store, - gpointer user_data) -{ - EAccount *account = user_data; - - if (store == NULL) - return; - - e_mail_store_add (store, account->name); -} - static void account_added_cb (EAccountList *accounts, EAccount *account, EMFolderTreeModel *model) { + EMailSession *session; + CamelStore *store; const gchar *uri; + session = em_folder_tree_model_get_session (model); uri = e_account_get_string (account, E_ACCOUNT_SOURCE_URL); - mail_get_store (uri, NULL, add_new_store, account); + + store = (CamelStore *) camel_session_get_service ( + CAMEL_SESSION (session), uri, CAMEL_PROVIDER_STORE, NULL); + + if (store != NULL) { + e_mail_store_add (session, store, account->name); + g_object_unref (store); + } } static void @@ -293,6 +295,12 @@ folder_tree_model_set_property (GObject *object, EM_FOLDER_TREE_MODEL (object), g_value_get_object (value)); return; + + case PROP_SESSION: + em_folder_tree_model_set_session ( + EM_FOLDER_TREE_MODEL (object), + g_value_get_object (value)); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -311,6 +319,13 @@ folder_tree_model_get_property (GObject *object, em_folder_tree_model_get_selection ( EM_FOLDER_TREE_MODEL (object))); return; + + case PROP_SESSION: + g_value_set_object ( + value, + em_folder_tree_model_get_session ( + EM_FOLDER_TREE_MODEL (object))); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -330,6 +345,11 @@ folder_tree_model_dispose (GObject *object) priv->selection = NULL; } + if (priv->session != NULL) { + g_object_unref (priv->session); + priv->session = NULL; + } + /* Chain up to parent's dispose() method. */ G_OBJECT_CLASS (parent_class)->dispose (object); } @@ -380,6 +400,16 @@ folder_tree_model_class_init (EMFolderTreeModelClass *class) GTK_TYPE_TREE_SELECTION, G_PARAM_READWRITE)); + g_object_class_install_property ( + object_class, + PROP_SESSION, + g_param_spec_object ( + "session", + NULL, + NULL, + E_TYPE_MAIL_SESSION, + G_PARAM_READWRITE)); + signals[LOADING_ROW] = g_signal_new ( "loading-row", G_OBJECT_CLASS_TYPE (object_class), @@ -611,6 +641,33 @@ em_folder_tree_model_set_selection (EMFolderTreeModel *model, g_object_notify (G_OBJECT (model), "selection"); } +EMailSession * +em_folder_tree_model_get_session (EMFolderTreeModel *model) +{ + g_return_val_if_fail (EM_IS_FOLDER_TREE_MODEL (model), NULL); + + return model->priv->session; +} + +void +em_folder_tree_model_set_session (EMFolderTreeModel *model, + EMailSession *session) +{ + g_return_if_fail (EM_IS_FOLDER_TREE_MODEL (model)); + + if (session != NULL) { + g_return_if_fail (E_IS_MAIL_SESSION (session)); + g_object_ref (session); + } + + if (model->priv->session != NULL) + g_object_unref (model->priv->session); + + model->priv->session = session; + + g_object_notify (G_OBJECT (model), "session"); +} + void em_folder_tree_model_set_folder_info (EMFolderTreeModel *model, GtkTreeIter *iter, -- cgit