diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2013-11-19 22:08:31 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2013-11-20 03:50:56 +0800 |
commit | 59f124ac280124f0723dfef9d679c10c90792a74 (patch) | |
tree | 106e458a7dd81e0ed39e3d4b688889d519343a82 /mail | |
parent | 705a5a00001270a5283666bc34a13bfc455438de (diff) | |
download | gsoc2013-evolution-59f124ac280124f0723dfef9d679c10c90792a74.tar gsoc2013-evolution-59f124ac280124f0723dfef9d679c10c90792a74.tar.gz gsoc2013-evolution-59f124ac280124f0723dfef9d679c10c90792a74.tar.bz2 gsoc2013-evolution-59f124ac280124f0723dfef9d679c10c90792a74.tar.lz gsoc2013-evolution-59f124ac280124f0723dfef9d679c10c90792a74.tar.xz gsoc2013-evolution-59f124ac280124f0723dfef9d679c10c90792a74.tar.zst gsoc2013-evolution-59f124ac280124f0723dfef9d679c10c90792a74.zip |
Add em_folder_tree_model_get_row_reference().
Replaces em_folder_tree_model_lookup_uri() and to some extent
em_folder_tree_model_lookup_store_info().
Working toward making the EMFolderTreeModelStoreInfo struct private to
EMFolderTreeModel, so it can then be made thread-safe.
Diffstat (limited to 'mail')
-rw-r--r-- | mail/em-folder-tree-model.c | 51 | ||||
-rw-r--r-- | mail/em-folder-tree-model.h | 5 | ||||
-rw-r--r-- | mail/em-folder-tree.c | 41 |
3 files changed, 68 insertions, 29 deletions
diff --git a/mail/em-folder-tree-model.c b/mail/em-folder-tree-model.c index 4859f970be..7b2bf8b37c 100644 --- a/mail/em-folder-tree-model.c +++ b/mail/em-folder-tree-model.c @@ -1395,6 +1395,46 @@ em_folder_tree_model_lookup_uri (EMFolderTreeModel *model, return reference; } +/** + * em_folder_tree_model_get_row_reference: + * @model: an #EMFolderTreeModel + * @store: a #CamelStore + * @folder_name: a folder name, or %NULL + * + * Returns the #GtkTreeRowReference for the folder described by @store and + * @folder_name. If @folder_name is %NULL, returns the #GtkTreeRowReference + * for the @store itself. If no matching row is found, the function returns + * %NULL. + * + * Returns: a valid #GtkTreeRowReference, or %NULL + **/ +GtkTreeRowReference * +em_folder_tree_model_get_row_reference (EMFolderTreeModel *model, + CamelStore *store, + const gchar *folder_name) +{ + GtkTreeRowReference *reference = NULL; + EMFolderTreeModelStoreInfo *si; + + g_return_val_if_fail (EM_IS_FOLDER_TREE_MODEL (model), NULL); + g_return_val_if_fail (CAMEL_IS_STORE (store), NULL); + + si = g_hash_table_lookup (model->priv->store_index, store); + + if (si == NULL) + return NULL; + + if (folder_name != NULL) + reference = g_hash_table_lookup (si->full_hash, folder_name); + else + reference = si->row; + + if (!gtk_tree_row_reference_valid (reference)) + reference = NULL; + + return reference; +} + void em_folder_tree_model_user_marked_unread (EMFolderTreeModel *model, CamelFolder *folder, @@ -1403,7 +1443,8 @@ em_folder_tree_model_user_marked_unread (EMFolderTreeModel *model, GtkTreeRowReference *reference; GtkTreePath *path; GtkTreeIter iter; - gchar *folder_uri; + CamelStore *parent_store; + const gchar *folder_name; guint unread; /* The user marked messages in the given folder as unread. @@ -1413,9 +1454,11 @@ em_folder_tree_model_user_marked_unread (EMFolderTreeModel *model, g_return_if_fail (EM_IS_FOLDER_TREE_MODEL (model)); g_return_if_fail (CAMEL_IS_FOLDER (folder)); - folder_uri = e_mail_folder_uri_from_folder (folder); - reference = em_folder_tree_model_lookup_uri (model, folder_uri); - g_free (folder_uri); + parent_store = camel_folder_get_parent_store (folder); + folder_name = camel_folder_get_full_name (folder); + + reference = em_folder_tree_model_get_row_reference ( + model, parent_store, folder_name); g_return_if_fail (gtk_tree_row_reference_valid (reference)); diff --git a/mail/em-folder-tree-model.h b/mail/em-folder-tree-model.h index 6aa85bc117..5785af6bdf 100644 --- a/mail/em-folder-tree-model.h +++ b/mail/em-folder-tree-model.h @@ -157,6 +157,11 @@ GtkTreeRowReference * em_folder_tree_model_lookup_uri (EMFolderTreeModel *model, const gchar *folder_uri); +GtkTreeRowReference * + em_folder_tree_model_get_row_reference + (EMFolderTreeModel *model, + CamelStore *store, + const gchar *folder_name); void em_folder_tree_model_user_marked_unread (EMFolderTreeModel *model, CamelFolder *folder, diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c index c7ee3ecff4..3406a6aae9 100644 --- a/mail/em-folder-tree.c +++ b/mail/em-folder-tree.c @@ -474,8 +474,7 @@ static void folder_tree_expand_node (const gchar *key, EMFolderTree *folder_tree) { - struct _EMFolderTreeModelStoreInfo *si = NULL; - GtkTreeRowReference *row; + GtkTreeRowReference *row = NULL; GtkTreeView *tree_view; GtkTreeModel *model; GtkTreePath *path; @@ -502,23 +501,24 @@ folder_tree_expand_node (const gchar *key, service = camel_session_ref_service (CAMEL_SESSION (session), uid); - if (CAMEL_IS_STORE (service)) - si = em_folder_tree_model_lookup_store_info ( + if (CAMEL_IS_STORE (service)) { + const gchar *folder_name; + + if (p != NULL && p[1] != '\0') + folder_name = p + 1; + else + folder_name = NULL; + + row = em_folder_tree_model_get_row_reference ( EM_FOLDER_TREE_MODEL (model), - CAMEL_STORE (service)); + CAMEL_STORE (service), folder_name); + } - if (service != NULL) - g_object_unref (service); + g_clear_object (&service); - if (si == NULL) + if (row == NULL) return; - if (p != NULL && p[1]) { - if (!(row = g_hash_table_lookup (si->full_hash, p + 1))) - return; - } else - row = si->row; - path = gtk_tree_row_reference_get_path (row); gtk_tree_view_expand_to_path (tree_view, path); @@ -3614,17 +3614,8 @@ em_folder_tree_restore_state (EMFolderTree *folder_tree, key_file, group_name, key, NULL); if (expanded && success) { - EMFolderTreeModelStoreInfo *si; - - si = em_folder_tree_model_lookup_store_info ( - folder_tree_model, store); - if (si != NULL) { - if (folder_name != NULL) - reference = g_hash_table_lookup ( - si->full_hash, folder_name); - else - reference = si->row; - } + reference = em_folder_tree_model_get_row_reference ( + folder_tree_model, store, folder_name); } if (gtk_tree_row_reference_valid (reference)) { |