aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2004-07-23 10:25:05 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2004-07-23 10:25:05 +0800
commitdc446979575a5a845199a48c926c34df0ef9d49e (patch)
tree44057f89e969a05addd1a52c30ac03694062765c
parent279b35fe0123505605c9fe0ddf4e4ac21a71b2ab (diff)
downloadgsoc2013-epiphany-dc446979575a5a845199a48c926c34df0ef9d49e.tar
gsoc2013-epiphany-dc446979575a5a845199a48c926c34df0ef9d49e.tar.gz
gsoc2013-epiphany-dc446979575a5a845199a48c926c34df0ef9d49e.tar.bz2
gsoc2013-epiphany-dc446979575a5a845199a48c926c34df0ef9d49e.tar.lz
gsoc2013-epiphany-dc446979575a5a845199a48c926c34df0ef9d49e.tar.xz
gsoc2013-epiphany-dc446979575a5a845199a48c926c34df0ef9d49e.tar.zst
gsoc2013-epiphany-dc446979575a5a845199a48c926c34df0ef9d49e.zip
Simplify node view filtering code and make it a normal property (no more
2004-07-23 Marco Pesenti Gritti <marco@gnome.org> * lib/widgets/ephy-node-view.c: (filter_changed_cb), (ephy_node_view_set_filter), (ephy_node_view_set_property), (ephy_node_view_init), (ephy_node_view_select_node), (filter_visible_func), (ephy_node_view_constructor), (ephy_node_view_class_init): * lib/widgets/ephy-tree-model-node.c: (ephy_tree_model_node_set_property), (ephy_tree_model_node_get_property), (ephy_tree_model_node_class_init), (ephy_tree_model_node_init), (ephy_tree_model_node_new), (ephy_tree_model_node_get_column_type), (ephy_tree_model_node_get_value): * lib/widgets/ephy-tree-model-node.h: * src/prefs-dialog.c: (create_node_combo): Simplify node view filtering code and make it a normal property (no more constructor only)
-rw-r--r--ChangeLog19
-rw-r--r--lib/widgets/ephy-node-view.c75
-rw-r--r--lib/widgets/ephy-tree-model-node.c103
-rw-r--r--lib/widgets/ephy-tree-model-node.h10
-rw-r--r--src/prefs-dialog.c2
5 files changed, 90 insertions, 119 deletions
diff --git a/ChangeLog b/ChangeLog
index 19d483900..22f314213 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
2004-07-23 Marco Pesenti Gritti <marco@gnome.org>
+ * lib/widgets/ephy-node-view.c: (filter_changed_cb),
+ (ephy_node_view_set_filter), (ephy_node_view_set_property),
+ (ephy_node_view_init), (ephy_node_view_select_node),
+ (filter_visible_func), (ephy_node_view_constructor),
+ (ephy_node_view_class_init):
+ * lib/widgets/ephy-tree-model-node.c:
+ (ephy_tree_model_node_set_property),
+ (ephy_tree_model_node_get_property),
+ (ephy_tree_model_node_class_init), (ephy_tree_model_node_init),
+ (ephy_tree_model_node_new), (ephy_tree_model_node_get_column_type),
+ (ephy_tree_model_node_get_value):
+ * lib/widgets/ephy-tree-model-node.h:
+ * src/prefs-dialog.c: (create_node_combo):
+
+ Simplify node view filtering code and make it a normal
+ property (no more constructor only)
+
+2004-07-23 Marco Pesenti Gritti <marco@gnome.org>
+
* lib/widgets/ephy-node-view.c: (ephy_node_view_new),
(ephy_node_view_constructor), (ephy_node_view_class_init):
diff --git a/lib/widgets/ephy-node-view.c b/lib/widgets/ephy-node-view.c
index 836d01ee5..2416f4101 100644
--- a/lib/widgets/ephy-node-view.c
+++ b/lib/widgets/ephy-node-view.c
@@ -54,7 +54,7 @@ struct EphyNodeViewPrivate
GtkTreeModel *sortmodel;
GtkCellRenderer *editable_renderer;
GtkTreeViewColumn *editable_column;
- EphyTreeModelNodeColumn editable_node_column;
+ int editable_node_column;
EphyNodeFilter *filter;
@@ -546,6 +546,9 @@ filter_changed_cb (EphyNodeFilter *filter,
/* no flush: this will cause the cursor to be reset
* only when the UI is free again */
}
+
+ gtk_tree_model_filter_refilter
+ (GTK_TREE_MODEL_FILTER (view->priv->filtermodel));
}
static void
@@ -841,6 +844,32 @@ ephy_node_view_button_press_cb (GtkWidget *treeview,
}
static void
+ephy_node_view_set_filter (EphyNodeView *view, EphyNodeFilter *filter)
+{
+ gboolean refilter = FALSE;
+
+ if (view->priv->filter)
+ {
+ g_object_unref (view->priv->filter);
+ refilter = TRUE;
+ }
+
+ if (filter)
+ {
+ view->priv->filter = g_object_ref (filter);
+ g_signal_connect_object (G_OBJECT (view->priv->filter),
+ "changed", G_CALLBACK (filter_changed_cb),
+ G_OBJECT (view), 0);
+ }
+
+ if (refilter)
+ {
+ gtk_tree_model_filter_refilter
+ (GTK_TREE_MODEL_FILTER (view->priv->filtermodel));
+ }
+}
+
+static void
ephy_node_view_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -854,16 +883,7 @@ ephy_node_view_set_property (GObject *object,
view->priv->root = g_value_get_pointer (value);
break;
case PROP_FILTER:
- view->priv->filter = g_value_get_object (value);
-
- if (view->priv->filter != NULL)
- {
- g_signal_connect_object (G_OBJECT (view->priv->filter),
- "changed",
- G_CALLBACK (filter_changed_cb),
- G_OBJECT (view),
- 0);
- }
+ ephy_node_view_set_filter (view, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1255,6 +1275,7 @@ ephy_node_view_init (EphyNodeView *view)
{
view->priv = EPHY_NODE_VIEW_GET_PRIVATE (view);
+ view->priv->filter = NULL;
view->priv->editable_renderer = NULL;
view->priv->editing = TRUE;
view->priv->searchable_data_column = -1;
@@ -1370,19 +1391,11 @@ ephy_node_view_select_node (EphyNodeView *view,
EphyNode *node)
{
GtkTreeIter iter, iter2;
- GValue val = { 0, };
- gboolean visible;
g_return_if_fail (node != NULL);
ephy_tree_model_node_iter_from_node (EPHY_TREE_MODEL_NODE (view->priv->nodemodel),
node, &iter);
- gtk_tree_model_get_value (GTK_TREE_MODEL (view->priv->nodemodel), &iter,
- EPHY_TREE_MODEL_NODE_COL_VISIBLE, &val);
- visible = g_value_get_boolean (&val);
- g_value_unset (&val);
- if (visible == FALSE) return;
-
gtk_tree_model_filter_convert_child_iter_to_iter (GTK_TREE_MODEL_FILTER (view->priv->filtermodel),
&iter2, &iter);
gtk_tree_model_sort_convert_child_iter_to_iter (GTK_TREE_MODEL_SORT (view->priv->sortmodel),
@@ -1479,6 +1492,22 @@ ephy_node_view_has_selection (EphyNodeView *view, gboolean *multiple)
return rows > 0;
}
+static gboolean
+filter_visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
+{
+ EphyNode *node;
+ EphyNodeView *view = EPHY_NODE_VIEW (data);
+
+ if (view->priv->filter)
+ {
+ node = ephy_tree_model_node_node_from_iter (view->priv->nodemodel, iter);
+
+ return ephy_node_filter_evaluate (view->priv->filter, node);
+ }
+
+ return TRUE;
+}
+
static GObject *
ephy_node_view_constructor (GType type, guint n_construct_properties,
GObjectConstructParam *construct_params)
@@ -1494,11 +1523,11 @@ ephy_node_view_constructor (GType type, guint n_construct_properties,
view = EPHY_NODE_VIEW (object);
priv = EPHY_NODE_VIEW_GET_PRIVATE (object);
- priv->nodemodel = ephy_tree_model_node_new (priv->root, priv->filter);
+ priv->nodemodel = ephy_tree_model_node_new (priv->root);
priv->filtermodel = gtk_tree_model_filter_new (GTK_TREE_MODEL (priv->nodemodel),
NULL);
- gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (priv->filtermodel),
- EPHY_TREE_MODEL_NODE_COL_VISIBLE);
+ gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filtermodel),
+ filter_visible_func, view, NULL);
priv->sortmodel = ephy_tree_model_sort_new (priv->filtermodel);
gtk_tree_view_set_model (GTK_TREE_VIEW (object), GTK_TREE_MODEL (priv->sortmodel));
g_signal_connect_object (object, "button_press_event",
@@ -1545,7 +1574,7 @@ ephy_node_view_class_init (EphyNodeViewClass *klass)
"Filter object",
"Filter object",
EPHY_TYPE_NODE_FILTER,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ G_PARAM_READWRITE));
ephy_node_view_signals[NODE_ACTIVATED] =
g_signal_new ("node_activated",
diff --git a/lib/widgets/ephy-tree-model-node.c b/lib/widgets/ephy-tree-model-node.c
index df3010345..0895ed166 100644
--- a/lib/widgets/ephy-tree-model-node.c
+++ b/lib/widgets/ephy-tree-model-node.c
@@ -26,7 +26,6 @@
#include <time.h>
#include <string.h>
-#include "ephy-node-filter.h"
#include "ephy-tree-model-node.h"
#include "ephy-stock-icons.h"
#include "ephy-node.h"
@@ -43,8 +42,6 @@ struct EphyTreeModelNodePrivate
{
EphyNode *root;
- EphyNodeFilter *filter;
-
GPtrArray *columns;
int columns_num;
@@ -62,8 +59,7 @@ typedef struct
enum
{
PROP_0,
- PROP_ROOT,
- PROP_FILTER
+ PROP_ROOT
};
static GObjectClass *parent_class = NULL;
@@ -206,23 +202,6 @@ root_destroy_cb (EphyNode *node,
}
static void
-filter_changed_cb (EphyNodeFilter *filter,
- EphyTreeModelNode *model)
-{
- GPtrArray *kids;
- int i;
-
- kids = ephy_node_get_children (model->priv->root);
-
- for (i = 0; i < kids->len; i++)
- {
- ephy_tree_model_node_update_node (model,
- g_ptr_array_index (kids, i),
- i);
- }
-}
-
-static void
ephy_tree_model_node_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -257,18 +236,6 @@ ephy_tree_model_node_set_property (GObject *object,
G_OBJECT (model));
break;
- case PROP_FILTER:
- model->priv->filter = g_value_get_object (value);
-
- if (model->priv->filter != NULL)
- {
- g_signal_connect_object (G_OBJECT (model->priv->filter),
- "changed",
- G_CALLBACK (filter_changed_cb),
- G_OBJECT (model),
- 0);
- }
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -288,9 +255,6 @@ ephy_tree_model_node_get_property (GObject *object,
case PROP_ROOT:
g_value_set_pointer (value, model->priv->root);
break;
- case PROP_FILTER:
- g_value_set_object (value, model->priv->filter);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -315,13 +279,6 @@ ephy_tree_model_node_class_init (EphyTreeModelNodeClass *klass)
"Root node",
"Root node",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (object_class,
- PROP_FILTER,
- g_param_spec_object ("filter",
- "Filter object",
- "Filter object",
- EPHY_TYPE_NODE_FILTER,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (object_class, sizeof (EphyTreeModelNodePrivate));
}
@@ -332,7 +289,7 @@ ephy_tree_model_node_init (EphyTreeModelNode *model)
model->priv = EPHY_TREE_MODEL_NODE_GET_PRIVATE (model);
model->priv->stamp = g_random_int ();
model->priv->columns = g_ptr_array_new ();
- model->priv->columns_num = EPHY_TREE_MODEL_NODE_BUILTIN_COLUMNS;
+ model->priv->columns_num = 0;
}
static void
@@ -347,13 +304,11 @@ ephy_tree_model_node_finalize (GObject *object)
}
EphyTreeModelNode *
-ephy_tree_model_node_new (EphyNode *root,
- EphyNodeFilter *filter)
+ephy_tree_model_node_new (EphyNode *root)
{
EphyTreeModelNode *model;
model = EPHY_TREE_MODEL_NODE (g_object_new (EPHY_TYPE_TREE_MODEL_NODE,
- "filter", filter,
"root", root,
NULL));
@@ -417,15 +372,10 @@ static GType
ephy_tree_model_node_get_column_type (GtkTreeModel *tree_model,
int index)
{
- int list_index;
EphyTreeModelNodeColData *col;
EphyTreeModelNode *model = EPHY_TREE_MODEL_NODE (tree_model);
- if (index == EPHY_TREE_MODEL_NODE_COL_VISIBLE)
- return G_TYPE_BOOLEAN;
-
- list_index = index - EPHY_TREE_MODEL_NODE_BUILTIN_COLUMNS;
- col = g_ptr_array_index (model->priv->columns, list_index);
+ col = g_ptr_array_index (model->priv->columns, index);
return col->type;
}
@@ -436,7 +386,6 @@ ephy_tree_model_node_get_value (GtkTreeModel *tree_model,
int column,
GValue *value)
{
- int list_index;
EphyTreeModelNodeColData *col;
EphyTreeModelNode *model = EPHY_TREE_MODEL_NODE (tree_model);
EphyNode *node;
@@ -450,43 +399,25 @@ ephy_tree_model_node_get_value (GtkTreeModel *tree_model,
node = iter->user_data;
- if (column == EPHY_TREE_MODEL_NODE_COL_VISIBLE)
- {
- g_value_init (value, G_TYPE_BOOLEAN);
-
- if (model->priv->filter != NULL)
- {
- g_value_set_boolean (value,
- ephy_node_filter_evaluate (model->priv->filter, node));
- }
- else
- {
- g_value_set_boolean (value, TRUE);
- }
- }
- else
- {
- list_index = column - EPHY_TREE_MODEL_NODE_BUILTIN_COLUMNS;
- col = g_ptr_array_index (model->priv->columns, list_index);
+ col = g_ptr_array_index (model->priv->columns, column);
- g_return_if_fail (col != NULL);
+ g_return_if_fail (col != NULL);
- if (col->prop_id >= 0)
+ if (col->prop_id >= 0)
+ {
+ if (!ephy_node_get_property (node, col->prop_id, value))
{
- if (!ephy_node_get_property (node, col->prop_id, value))
+ /* make sure to return a valid string anyway */
+ g_value_init (value, col->type);
+ if (col->type == G_TYPE_STRING)
{
- /* make sure to return a valid string anyway */
- g_value_init (value, col->type);
- if (col->type == G_TYPE_STRING)
- {
- g_value_set_string (value, "");
- }
+ g_value_set_string (value, "");
}
}
- else
- {
- col->func (node, value, col->user_data);
- }
+ }
+ else
+ {
+ col->func (node, value, col->user_data);
}
}
diff --git a/lib/widgets/ephy-tree-model-node.h b/lib/widgets/ephy-tree-model-node.h
index fe1c08446..3e32288be 100644
--- a/lib/widgets/ephy-tree-model-node.h
+++ b/lib/widgets/ephy-tree-model-node.h
@@ -24,7 +24,6 @@
#include <gtk/gtktreemodel.h>
#include "ephy-node.h"
-#include "ephy-node-filter.h"
G_BEGIN_DECLS
@@ -35,12 +34,6 @@ G_BEGIN_DECLS
#define EPHY_IS_TREE_MODEL_NODE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_TREE_MODEL_NODE))
#define EPHY_TREE_MODEL_NODE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_TREE_MODEL_NODE, EphyTreeModelNodeClass))
-typedef enum
-{
- EPHY_TREE_MODEL_NODE_COL_VISIBLE,
- EPHY_TREE_MODEL_NODE_BUILTIN_COLUMNS
-} EphyTreeModelNodeColumn;
-
typedef void (*EphyTreeModelNodeValueFunc) (EphyNode *node, GValue *value, gpointer user_data);
typedef struct EphyTreeModelNodePrivate EphyTreeModelNodePrivate;
@@ -60,8 +53,7 @@ typedef struct
GType ephy_tree_model_node_get_type (void);
-EphyTreeModelNode *ephy_tree_model_node_new (EphyNode *root,
- EphyNodeFilter *filter);
+EphyTreeModelNode *ephy_tree_model_node_new (EphyNode *root);
int ephy_tree_model_node_add_prop_column (EphyTreeModelNode *model,
GType value_type,
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 8b715692e..a74ecb9f6 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -602,7 +602,7 @@ create_node_combo (EphyDialog *dialog,
combo = GTK_COMBO_BOX (ephy_dialog_get_control (dialog, properties[prop].id));
- nodemodel = ephy_tree_model_node_new (node, NULL);
+ nodemodel = ephy_tree_model_node_new (node);
title_col = ephy_tree_model_node_add_prop_column
(nodemodel, G_TYPE_STRING, EPHY_NODE_ENCODING_PROP_TITLE_ELIDED);