[evolution] Add em_folder_tree_model_get_row_reference().



commit 59f124ac280124f0723dfef9d679c10c90792a74
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Nov 19 09:08:31 2013 -0500

    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.

 mail/em-folder-tree-model.c      |   51 ++++++++++++++++++++++++++++++++---
 mail/em-folder-tree-model.h      |    5 +++
 mail/em-folder-tree.c            |   41 +++++++++++-----------------
 modules/mail/e-mail-shell-view.c |   55 ++++++++++++++++++++++---------------
 4 files changed, 101 insertions(+), 51 deletions(-)
---
diff --git a/mail/em-folder-tree-model.c b/mail/em-folder-tree-model.c
index 4859f97..7b2bf8b 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 6aa85bc..5785af6 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 c7ee3ec..3406a6a 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)) {
diff --git a/modules/mail/e-mail-shell-view.c b/modules/mail/e-mail-shell-view.c
index 1442ba7..cf86af8 100644
--- a/modules/mail/e-mail-shell-view.c
+++ b/modules/mail/e-mail-shell-view.c
@@ -862,8 +862,9 @@ mail_shell_view_update_actions (EShellView *shell_view)
        EMailReader *reader;
        EMailView *mail_view;
        GtkAction *action;
+       CamelStore *store = NULL;
        GList *list, *link;
-       gchar *uri;
+       gchar *folder_name = NULL;
        gboolean sensitive;
        guint32 state;
 
@@ -871,6 +872,7 @@ mail_shell_view_update_actions (EShellView *shell_view)
        gboolean folder_allows_children;
        gboolean folder_can_be_deleted;
        gboolean folder_is_outbox;
+       gboolean folder_is_selected = FALSE;
        gboolean folder_is_store;
        gboolean folder_is_trash;
        gboolean folder_is_virtual;
@@ -923,12 +925,12 @@ mail_shell_view_update_actions (EShellView *shell_view)
        store_can_be_disabled =
                (state & E_MAIL_SIDEBAR_STORE_CAN_BE_DISABLED);
 
-       uri = em_folder_tree_get_selected_uri (folder_tree);
-
-       if (uri != NULL) {
+       if (em_folder_tree_get_selected (folder_tree, &store, &folder_name)) {
                GtkTreeRowReference *reference;
                CamelFolder *folder;
 
+               folder_is_selected = TRUE;
+
                folder = e_mail_reader_ref_folder (reader);
 
                /* XXX If the user right-clicks on a folder other than what
@@ -939,17 +941,22 @@ mail_shell_view_update_actions (EShellView *shell_view)
                 *     folder tree editing, it's just too hairy to try to
                 *     get right.  So we're punting. */
                if (folder != NULL) {
-                       gchar *folder_uri;
+                       gchar *uri1, *uri2;
+
+                       uri1 = e_mail_folder_uri_from_folder (folder);
+                       uri2 = e_mail_folder_uri_build (store, folder_name);
 
-                       folder_uri = e_mail_folder_uri_from_folder (folder);
                        folder_tree_and_message_list_agree =
-                               (g_strcmp0 (uri, folder_uri) == 0);
-                       g_free (folder_uri);
+                               (g_strcmp0 (uri1, uri2) == 0);
+
+                       g_free (uri1);
+                       g_free (uri2);
 
                        g_object_unref (folder);
                }
 
-               reference = em_folder_tree_model_lookup_uri (model, uri);
+               reference = em_folder_tree_model_get_row_reference (
+                       model, store, folder_name);
                if (reference != NULL) {
                        GtkTreePath *path;
                        GtkTreeIter iter;
@@ -964,7 +971,9 @@ mail_shell_view_update_actions (EShellView *shell_view)
                        gtk_tree_path_free (path);
                }
 
-               g_free (uri);
+               g_clear_object (&store);
+               g_free (folder_name);
+               folder_name = NULL;
        }
 
        /* Look for a CamelStore that supports subscriptions. */
@@ -1000,19 +1009,19 @@ mail_shell_view_update_actions (EShellView *shell_view)
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_FOLDER_COPY);
-       sensitive = !folder_is_store;
+       sensitive = folder_is_selected;
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_FOLDER_DELETE);
-       sensitive = !folder_is_store && folder_can_be_deleted;
+       sensitive = folder_is_selected && folder_can_be_deleted;
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_FOLDER_EXPUNGE);
-       sensitive = !folder_is_store && !folder_is_virtual && uri != NULL;
+       sensitive = folder_is_selected && !folder_is_virtual;
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_FOLDER_MOVE);
-       sensitive = !folder_is_store && folder_can_be_deleted;
+       sensitive = folder_is_selected && folder_can_be_deleted;
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_FOLDER_NEW);
@@ -1020,39 +1029,41 @@ mail_shell_view_update_actions (EShellView *shell_view)
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_FOLDER_PROPERTIES);
-       sensitive = !folder_is_store && uri != NULL;
+       sensitive = folder_is_selected;
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_FOLDER_REFRESH);
-       sensitive = !folder_is_store;
+       sensitive = folder_is_selected;
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_FOLDER_RENAME);
        sensitive =
-               !folder_is_store && folder_can_be_deleted &&
+               folder_is_selected &&
+               folder_can_be_deleted &&
                folder_tree_and_message_list_agree;
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_FOLDER_SELECT_THREAD);
-       sensitive = !folder_is_store;
+       sensitive = folder_is_selected;
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_FOLDER_SELECT_SUBTHREAD);
-       sensitive = !folder_is_store;
+       sensitive = folder_is_selected;
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_FOLDER_UNSUBSCRIBE);
        sensitive =
+               folder_is_selected &&
                store_is_subscribable &&
-               !folder_is_store && !folder_is_virtual;
+               !folder_is_virtual;
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_FOLDER_MARK_ALL_AS_READ);
-       sensitive = folder_has_unread && !folder_is_store;
+       sensitive = folder_is_selected && folder_has_unread;
        gtk_action_set_sensitive (action, sensitive);
 
        action = ACTION (MAIL_POPUP_FOLDER_MARK_ALL_AS_READ);
-       sensitive = folder_has_unread_rec && !folder_is_store;
+       sensitive = folder_is_selected && folder_has_unread_rec;
        gtk_action_set_visible (action, sensitive);
 
        action = ACTION (MAIL_MANAGE_SUBSCRIPTIONS);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]