[evolution] Add e_tree_model_node_get_n_nodes().



commit a100a1588a2a880da482f4bbc15aa02d7abab312
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Jun 19 10:48:21 2013 -0400

    Add e_tree_model_node_get_n_nodes().
    
    Returns the total number of nodes in the tree model, including hidden
    nodes in collapsed tree branches.

 .../evolution-util/evolution-util-sections.txt     |    1 +
 e-util/e-tree-model.c                              |   13 +++++++++++++
 e-util/e-tree-model.h                              |    2 ++
 mail/message-list.c                                |   18 ++++++++++++++++++
 4 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/doc/reference/evolution-util/evolution-util-sections.txt 
b/doc/reference/evolution-util/evolution-util-sections.txt
index c41d18c..9df7b9b 100644
--- a/doc/reference/evolution-util/evolution-util-sections.txt
+++ b/doc/reference/evolution-util/evolution-util-sections.txt
@@ -4265,6 +4265,7 @@ e_tree_model_node_get_first_child
 e_tree_model_node_get_next
 e_tree_model_node_is_root
 e_tree_model_node_is_expandable
+e_tree_model_node_get_n_nodes
 e_tree_model_node_get_n_children
 e_tree_model_node_depth
 e_tree_model_get_expanded_default
diff --git a/e-util/e-tree-model.c b/e-util/e-tree-model.c
index 8524891..b03824d 100644
--- a/e-util/e-tree-model.c
+++ b/e-util/e-tree-model.c
@@ -359,6 +359,19 @@ e_tree_model_node_is_expandable (ETreeModel *tree_model,
 }
 
 guint
+e_tree_model_node_get_n_nodes (ETreeModel *tree_model)
+{
+       ETreeModelInterface *interface;
+
+       g_return_val_if_fail (E_IS_TREE_MODEL (tree_model), 0);
+
+       interface = E_TREE_MODEL_GET_INTERFACE (tree_model);
+       g_return_val_if_fail (interface->get_n_nodes != NULL, 0);
+
+       return interface->get_n_nodes (tree_model);
+}
+
+guint
 e_tree_model_node_get_n_children (ETreeModel *tree_model,
                                   ETreePath path)
 {
diff --git a/e-util/e-tree-model.h b/e-util/e-tree-model.h
index c6ed8c8..08a397c 100644
--- a/e-util/e-tree-model.h
+++ b/e-util/e-tree-model.h
@@ -65,6 +65,7 @@ struct _ETreeModelInterface {
                                                 ETreePath path);
        gboolean        (*is_expandable)        (ETreeModel *tree_model,
                                                 ETreePath path);
+       guint           (*get_n_nodes)          (ETreeModel *tree_model);
        guint           (*get_n_children)       (ETreeModel *tree_model,
                                                 ETreePath path);
        guint           (*depth)                (ETreeModel *tree_model,
@@ -147,6 +148,7 @@ gboolean    e_tree_model_node_is_root       (ETreeModel *tree_model,
                                                 ETreePath path);
 gboolean       e_tree_model_node_is_expandable (ETreeModel *tree_model,
                                                 ETreePath path);
+guint          e_tree_model_node_get_n_nodes   (ETreeModel *tree_model);
 guint          e_tree_model_node_get_n_children
                                                (ETreeModel *tree_model,
                                                 ETreePath path);
diff --git a/mail/message-list.c b/mail/message-list.c
index ada7f11..d6a2248 100644
--- a/mail/message-list.c
+++ b/mail/message-list.c
@@ -2704,6 +2704,23 @@ message_list_is_expandable (ETreeModel *tree_model,
 }
 
 static guint
+message_list_get_n_nodes (ETreeModel *tree_model)
+{
+       ETreePath root;
+       guint n_nodes = 0;
+
+       root = e_tree_model_get_root (tree_model);
+
+       if (root == NULL)
+               return 0;
+
+       /* The root node is an empty placeholder, so
+        * subtract one from the count to exclude it. */
+
+       return g_node_n_nodes ((GNode *) root, G_TRAVERSE_ALL) - 1;
+}
+
+static guint
 message_list_get_n_children (ETreeModel *tree_model,
                              ETreePath path)
 {
@@ -3154,6 +3171,7 @@ message_list_tree_model_init (ETreeModelInterface *interface)
        interface->get_next = message_list_get_next;
        interface->is_root = message_list_is_root;
        interface->is_expandable = message_list_is_expandable;
+       interface->get_n_nodes = message_list_get_n_nodes;
        interface->get_n_children = message_list_get_n_children;
        interface->depth = message_list_depth;
        interface->get_expanded_default = message_list_get_expanded_default;


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