aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-06-18 04:07:40 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-06-18 04:07:40 +0800
commitc603304bd7f55a4a20592bf2704f8b402c36b411 (patch)
tree5c599c51f4b01aff9af8d66358d21b018038a594
parentb2ee70340091137e33b1f17735f3ee9be91c5ac4 (diff)
downloadgsoc2013-evolution-c603304bd7f55a4a20592bf2704f8b402c36b411.tar
gsoc2013-evolution-c603304bd7f55a4a20592bf2704f8b402c36b411.tar.gz
gsoc2013-evolution-c603304bd7f55a4a20592bf2704f8b402c36b411.tar.bz2
gsoc2013-evolution-c603304bd7f55a4a20592bf2704f8b402c36b411.tar.lz
gsoc2013-evolution-c603304bd7f55a4a20592bf2704f8b402c36b411.tar.xz
gsoc2013-evolution-c603304bd7f55a4a20592bf2704f8b402c36b411.tar.zst
gsoc2013-evolution-c603304bd7f55a4a20592bf2704f8b402c36b411.zip
ETreeSelectionModel: Further cleanups.
-rw-r--r--e-util/e-tree-selection-model.c374
1 files changed, 195 insertions, 179 deletions
diff --git a/e-util/e-tree-selection-model.c b/e-util/e-tree-selection-model.c
index e345036de6..3b2fd8fd45 100644
--- a/e-util/e-tree-selection-model.c
+++ b/e-util/e-tree-selection-model.c
@@ -291,35 +291,44 @@ drop_model (ETreeSelectionModel *etsm)
}
static void
-etsm_dispose (GObject *object)
+tree_selection_model_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
+ ESelectionModel *esm = E_SELECTION_MODEL (object);
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (object);
- drop_model (etsm);
-
- /* Chain up to parent's dispose() method. */
- G_OBJECT_CLASS (e_tree_selection_model_parent_class)->dispose (object);
-}
-
-static void
-etsm_finalize (GObject *object)
-{
- ETreeSelectionModelPrivate *priv;
+ switch (property_id) {
+ case PROP_CURSOR_ROW:
+ e_selection_model_do_something (
+ esm, g_value_get_int (value),
+ etsm->priv->cursor_col, 0);
+ break;
- priv = E_TREE_SELECTION_MODEL_GET_PRIVATE (object);
+ case PROP_CURSOR_COL:
+ e_selection_model_do_something (
+ esm, get_cursor_row (etsm),
+ g_value_get_int (value), 0);
+ break;
- clear_selection (E_TREE_SELECTION_MODEL (object));
- g_hash_table_destroy (priv->paths);
+ case PROP_MODEL:
+ drop_model (etsm);
+ add_model (etsm, E_TREE_MODEL (g_value_get_object (value)));
+ break;
- /* Chain up to parent's finalize() method. */
- G_OBJECT_CLASS (e_tree_selection_model_parent_class)->finalize (object);
+ case PROP_ETTA:
+ etsm->priv->etta =
+ E_TREE_TABLE_ADAPTER (g_value_get_object (value));
+ break;
+ }
}
static void
-etsm_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+tree_selection_model_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (object);
@@ -343,52 +352,33 @@ etsm_get_property (GObject *object,
}
static void
-etsm_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+tree_selection_model_dispose (GObject *object)
{
- ESelectionModel *esm = E_SELECTION_MODEL (object);
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (object);
- switch (property_id) {
- case PROP_CURSOR_ROW:
- e_selection_model_do_something (
- esm, g_value_get_int (value),
- etsm->priv->cursor_col, 0);
- break;
-
- case PROP_CURSOR_COL:
- e_selection_model_do_something (
- esm, get_cursor_row (etsm),
- g_value_get_int (value), 0);
- break;
-
- case PROP_MODEL:
- drop_model (etsm);
- add_model (etsm, E_TREE_MODEL (g_value_get_object (value)));
- break;
+ drop_model (etsm);
- case PROP_ETTA:
- etsm->priv->etta =
- E_TREE_TABLE_ADAPTER (g_value_get_object (value));
- break;
- }
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (e_tree_selection_model_parent_class)->dispose (object);
}
-static gboolean
-etsm_is_path_selected (ETreeSelectionModel *etsm,
- ETreePath path)
+static void
+tree_selection_model_finalize (GObject *object)
{
- if (path == NULL)
- return FALSE;
+ ETreeSelectionModelPrivate *priv;
- return g_hash_table_contains (etsm->priv->paths, path);
+ priv = E_TREE_SELECTION_MODEL_GET_PRIVATE (object);
+
+ clear_selection (E_TREE_SELECTION_MODEL (object));
+ g_hash_table_destroy (priv->paths);
+
+ /* Chain up to parent's finalize() method. */
+ G_OBJECT_CLASS (e_tree_selection_model_parent_class)->finalize (object);
}
static gboolean
-etsm_is_row_selected (ESelectionModel *selection,
- gint row)
+tree_selection_model_is_row_selected (ESelectionModel *selection,
+ gint row)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
ETreePath path;
@@ -400,13 +390,17 @@ etsm_is_row_selected (ESelectionModel *selection,
g_return_val_if_fail (etsm != NULL, FALSE);
path = e_tree_table_adapter_node_at_row (etsm->priv->etta, row);
- return etsm_is_path_selected (etsm, path);
+
+ if (path == NULL)
+ return FALSE;
+
+ return g_hash_table_contains (etsm->priv->paths, path);
}
static void
-etsm_foreach (ESelectionModel *selection,
- EForeachFunc callback,
- gpointer closure)
+tree_selection_model_foreach (ESelectionModel *selection,
+ EForeachFunc callback,
+ gpointer closure)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
GList *list, *link;
@@ -426,7 +420,7 @@ etsm_foreach (ESelectionModel *selection,
}
static void
-etsm_clear (ESelectionModel *selection)
+tree_selection_model_clear (ESelectionModel *selection)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
@@ -438,25 +432,19 @@ etsm_clear (ESelectionModel *selection)
}
static gint
-etsm_selected_count (ESelectionModel *selection)
+tree_selection_model_selected_count (ESelectionModel *selection)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
return g_hash_table_size (etsm->priv->paths);
}
-static gint
-etsm_row_count (ESelectionModel *selection)
-{
- ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
- return e_table_model_row_count (E_TABLE_MODEL (etsm->priv->etta));
-}
-
static void
-etsm_select_all (ESelectionModel *selection)
+tree_selection_model_select_all (ESelectionModel *selection)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
ETreePath root;
+ gint count;
root = e_tree_model_get_root (etsm->priv->model);
if (root == NULL)
@@ -464,7 +452,8 @@ etsm_select_all (ESelectionModel *selection)
clear_selection (etsm);
- select_range (etsm, 0, etsm_row_count (selection) - 1);
+ count = e_selection_model_row_count (selection);
+ select_range (etsm, 0, count - 1);
if (etsm->priv->cursor_path == NULL)
etsm->priv->cursor_path = e_tree_table_adapter_node_at_row (
@@ -478,12 +467,14 @@ etsm_select_all (ESelectionModel *selection)
}
static void
-etsm_invert_selection (ESelectionModel *selection)
+tree_selection_model_invert_selection (ESelectionModel *selection)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
- gint count = etsm_row_count (selection);
+ gint count;
gint i;
+ count = e_selection_model_row_count (selection);
+
for (i = 0; i < count; i++) {
ETreePath path;
@@ -504,10 +495,18 @@ etsm_invert_selection (ESelectionModel *selection)
e_selection_model_cursor_changed (E_SELECTION_MODEL (etsm), -1, -1);
}
+static gint
+tree_selection_model_row_count (ESelectionModel *selection)
+{
+ ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
+
+ return e_table_model_row_count (E_TABLE_MODEL (etsm->priv->etta));
+}
+
static void
-etsm_change_one_row (ESelectionModel *selection,
- gint row,
- gboolean grow)
+tree_selection_model_change_one_row (ESelectionModel *selection,
+ gint row,
+ gboolean grow)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
ETreePath path;
@@ -527,9 +526,9 @@ etsm_change_one_row (ESelectionModel *selection,
}
static void
-etsm_change_cursor (ESelectionModel *selection,
- gint row,
- gint col)
+tree_selection_model_change_cursor (ESelectionModel *selection,
+ gint row,
+ gint col)
{
ETreeSelectionModel *etsm;
@@ -549,15 +548,16 @@ etsm_change_cursor (ESelectionModel *selection,
}
static gint
-etsm_cursor_row (ESelectionModel *selection)
+tree_selection_model_cursor_row (ESelectionModel *selection)
{
return get_cursor_row (E_TREE_SELECTION_MODEL (selection));
}
static gint
-etsm_cursor_col (ESelectionModel *selection)
+tree_selection_model_cursor_col (ESelectionModel *selection)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
+
return etsm->priv->cursor_col;
}
@@ -572,8 +572,8 @@ etsm_get_rows (gint row,
}
static void
-etsm_select_single_row (ESelectionModel *selection,
- gint row)
+tree_selection_model_select_single_row (ESelectionModel *selection,
+ gint row)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
ETreePath path;
@@ -587,7 +587,7 @@ etsm_select_single_row (ESelectionModel *selection,
size = g_hash_table_size (etsm->priv->paths);
if (size > 0 && size <= 5) {
rowp = rows;
- etsm_foreach (selection, etsm_get_rows, &rowp);
+ tree_selection_model_foreach (selection, etsm_get_rows, &rowp);
}
select_single_path (etsm, path);
@@ -608,8 +608,8 @@ etsm_select_single_row (ESelectionModel *selection,
}
static void
-etsm_toggle_single_row (ESelectionModel *selection,
- gint row)
+tree_selection_model_toggle_single_row (ESelectionModel *selection,
+ gint row)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
ETreePath path;
@@ -644,8 +644,8 @@ etsm_real_move_selection_end (ETreeSelectionModel *etsm,
}
static void
-etsm_move_selection_end (ESelectionModel *selection,
- gint row)
+tree_selection_model_move_selection_end (ESelectionModel *selection,
+ gint row)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
@@ -656,8 +656,8 @@ etsm_move_selection_end (ESelectionModel *selection,
}
static void
-etsm_set_selection_end (ESelectionModel *selection,
- gint row)
+tree_selection_model_set_selection_end (ESelectionModel *selection,
+ gint row)
{
ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection);
@@ -669,6 +669,95 @@ etsm_set_selection_end (ESelectionModel *selection,
e_selection_model_selection_changed (E_SELECTION_MODEL (etsm));
}
+static void
+e_tree_selection_model_class_init (ETreeSelectionModelClass *class)
+{
+ GObjectClass *object_class;
+ ESelectionModelClass *esm_class;
+
+ g_type_class_add_private (class, sizeof (ETreeSelectionModelPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = tree_selection_model_set_property;
+ object_class->get_property = tree_selection_model_get_property;
+ object_class->dispose = tree_selection_model_dispose;
+ object_class->finalize = tree_selection_model_finalize;
+
+ esm_class = E_SELECTION_MODEL_CLASS (class);
+ esm_class->is_row_selected = tree_selection_model_is_row_selected;
+ esm_class->foreach = tree_selection_model_foreach;
+ esm_class->clear = tree_selection_model_clear;
+ esm_class->selected_count = tree_selection_model_selected_count;
+ esm_class->select_all = tree_selection_model_select_all;
+ esm_class->invert_selection = tree_selection_model_invert_selection;
+ esm_class->row_count = tree_selection_model_row_count;
+
+ esm_class->change_one_row = tree_selection_model_change_one_row;
+ esm_class->change_cursor = tree_selection_model_change_cursor;
+ esm_class->cursor_row = tree_selection_model_cursor_row;
+ esm_class->cursor_col = tree_selection_model_cursor_col;
+
+ esm_class->select_single_row = tree_selection_model_select_single_row;
+ esm_class->toggle_single_row = tree_selection_model_toggle_single_row;
+ esm_class->move_selection_end = tree_selection_model_move_selection_end;
+ esm_class->set_selection_end = tree_selection_model_set_selection_end;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_CURSOR_ROW,
+ g_param_spec_int (
+ "cursor_row",
+ "Cursor Row",
+ NULL,
+ 0, G_MAXINT, 0,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_CURSOR_COL,
+ g_param_spec_int (
+ "cursor_col",
+ "Cursor Column",
+ NULL,
+ 0, G_MAXINT, 0,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_MODEL,
+ g_param_spec_object (
+ "model",
+ "Model",
+ NULL,
+ E_TYPE_TREE_MODEL,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_ETTA,
+ g_param_spec_object (
+ "etta",
+ "ETTA",
+ NULL,
+ E_TYPE_TREE_TABLE_ADAPTER,
+ G_PARAM_READWRITE));
+}
+
+static void
+e_tree_selection_model_init (ETreeSelectionModel *etsm)
+{
+ etsm->priv = E_TREE_SELECTION_MODEL_GET_PRIVATE (etsm);
+
+ etsm->priv->paths = g_hash_table_new (NULL, NULL);
+ etsm->priv->cursor_col = -1;
+}
+
+ESelectionModel *
+e_tree_selection_model_new (void)
+{
+ return g_object_new (E_TYPE_TREE_SELECTION_MODEL, NULL);
+}
+
void
e_tree_selection_model_foreach (ETreeSelectionModel *etsm,
ETreeForeachFunc callback,
@@ -676,6 +765,9 @@ e_tree_selection_model_foreach (ETreeSelectionModel *etsm,
{
GList *list, *link;
+ g_return_if_fail (E_IS_TREE_SELECTION_MODEL (etsm));
+ g_return_if_fail (callback != NULL);
+
list = g_hash_table_get_keys (etsm->priv->paths);
for (link = list; link != NULL; link = g_list_next (link))
@@ -688,6 +780,9 @@ void
e_tree_selection_model_select_single_path (ETreeSelectionModel *etsm,
ETreePath path)
{
+ g_return_if_fail (E_IS_TREE_SELECTION_MODEL (etsm));
+ g_return_if_fail (path != NULL);
+
select_single_path (etsm, path);
e_selection_model_selection_changed (E_SELECTION_MODEL (etsm));
@@ -700,6 +795,9 @@ e_tree_selection_model_select_paths (ETreeSelectionModel *etsm,
ETreePath path;
gint i;
+ g_return_if_fail (E_IS_TREE_SELECTION_MODEL (etsm));
+ g_return_if_fail (paths != NULL);
+
for (i = 0; i < paths->len; i++) {
path = paths->pdata[i];
change_one_path (etsm, path, TRUE);
@@ -712,6 +810,9 @@ void
e_tree_selection_model_add_to_selection (ETreeSelectionModel *etsm,
ETreePath path)
{
+ g_return_if_fail (E_IS_TREE_SELECTION_MODEL (etsm));
+ g_return_if_fail (path != NULL);
+
change_one_path (etsm, path, TRUE);
e_selection_model_selection_changed (E_SELECTION_MODEL (etsm));
@@ -723,6 +824,9 @@ e_tree_selection_model_change_cursor (ETreeSelectionModel *etsm,
{
gint row;
+ g_return_if_fail (E_IS_TREE_SELECTION_MODEL (etsm));
+ /* XXX Not sure if path can be NULL here. */
+
etsm->priv->cursor_path = path;
row = get_cursor_row (etsm);
@@ -738,96 +842,8 @@ e_tree_selection_model_change_cursor (ETreeSelectionModel *etsm,
ETreePath
e_tree_selection_model_get_cursor (ETreeSelectionModel *etsm)
{
- return etsm->priv->cursor_path;
-}
-
-static void
-e_tree_selection_model_init (ETreeSelectionModel *etsm)
-{
- etsm->priv = E_TREE_SELECTION_MODEL_GET_PRIVATE (etsm);
-
- etsm->priv->paths = g_hash_table_new (NULL, NULL);
- etsm->priv->cursor_col = -1;
-}
+ g_return_val_if_fail (E_IS_TREE_SELECTION_MODEL (etsm), NULL);
-static void
-e_tree_selection_model_class_init (ETreeSelectionModelClass *class)
-{
- GObjectClass *object_class;
- ESelectionModelClass *esm_class;
-
- g_type_class_add_private (class, sizeof (ETreeSelectionModelPrivate));
-
- object_class = G_OBJECT_CLASS (class);
- object_class->dispose = etsm_dispose;
- object_class->finalize = etsm_finalize;
- object_class->get_property = etsm_get_property;
- object_class->set_property = etsm_set_property;
-
- esm_class = E_SELECTION_MODEL_CLASS (class);
- esm_class->is_row_selected = etsm_is_row_selected;
- esm_class->foreach = etsm_foreach;
- esm_class->clear = etsm_clear;
- esm_class->selected_count = etsm_selected_count;
- esm_class->select_all = etsm_select_all;
- esm_class->invert_selection = etsm_invert_selection;
- esm_class->row_count = etsm_row_count;
-
- esm_class->change_one_row = etsm_change_one_row;
- esm_class->change_cursor = etsm_change_cursor;
- esm_class->cursor_row = etsm_cursor_row;
- esm_class->cursor_col = etsm_cursor_col;
-
- esm_class->select_single_row = etsm_select_single_row;
- esm_class->toggle_single_row = etsm_toggle_single_row;
- esm_class->move_selection_end = etsm_move_selection_end;
- esm_class->set_selection_end = etsm_set_selection_end;
-
- g_object_class_install_property (
- object_class,
- PROP_CURSOR_ROW,
- g_param_spec_int (
- "cursor_row",
- "Cursor Row",
- NULL,
- 0, G_MAXINT, 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_CURSOR_COL,
- g_param_spec_int (
- "cursor_col",
- "Cursor Column",
- NULL,
- 0, G_MAXINT, 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_MODEL,
- g_param_spec_object (
- "model",
- "Model",
- NULL,
- E_TYPE_TREE_MODEL,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_ETTA,
- g_param_spec_object (
- "etta",
- "ETTA",
- NULL,
- E_TYPE_TREE_TABLE_ADAPTER,
- G_PARAM_READWRITE));
-
-}
-
-ESelectionModel *
-e_tree_selection_model_new (void)
-{
- return g_object_new (E_TYPE_TREE_SELECTION_MODEL, NULL);
+ return etsm->priv->cursor_path;
}