diff options
author | Marco Pesenti Gritti <marco@it.gnome.org> | 2003-05-27 03:02:39 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <mpeseng@src.gnome.org> | 2003-05-27 03:02:39 +0800 |
commit | 5ff8f7cb898f02ddf1f2dfe0370e90c1c8d3e061 (patch) | |
tree | f1a60e760e06a39a3966e301fc520e90aed00263 | |
parent | 70183cca32190c0d2b038441c01bd927e11b8148 (diff) | |
download | gsoc2013-epiphany-5ff8f7cb898f02ddf1f2dfe0370e90c1c8d3e061.tar gsoc2013-epiphany-5ff8f7cb898f02ddf1f2dfe0370e90c1c8d3e061.tar.gz gsoc2013-epiphany-5ff8f7cb898f02ddf1f2dfe0370e90c1c8d3e061.tar.bz2 gsoc2013-epiphany-5ff8f7cb898f02ddf1f2dfe0370e90c1c8d3e061.tar.lz gsoc2013-epiphany-5ff8f7cb898f02ddf1f2dfe0370e90c1c8d3e061.tar.xz gsoc2013-epiphany-5ff8f7cb898f02ddf1f2dfe0370e90c1c8d3e061.tar.zst gsoc2013-epiphany-5ff8f7cb898f02ddf1f2dfe0370e90c1c8d3e061.zip |
s/DESTROYED/DESTROY which is more useulf
2003-05-26 Marco Pesenti Gritti <marco@it.gnome.org>
* lib/ephy-node.c: (callback), (ephy_node_dispose):
* lib/ephy-node.h:
s/DESTROYED/DESTROY which is more useulf
* lib/widgets/ephy-tree-model-node.c:
(ephy_tree_model_node_set_property), (root_destroy_cb):
* src/bookmarks/ephy-bookmarks-editor.c:
(ephy_bookmarks_editor_update_menu):
* src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_init_defaults),
(ephy_bookmarks_set_toolbars_model), (ephy_bookmarks_set_property),
(ephy_bookmarks_get_property), (ephy_bookmarks_class_init),
(bookmarks_removed_cb), (topics_removed_cb), (ephy_bookmarks_init),
(ephy_bookmarks_finalize):
* src/ephy-shell.c: (ephy_shell_get_toolbars_model):
* src/ephy-toolbars-model.c: (impl_add_item),
(ephy_toolbars_model_set_bookmarks),
(ephy_toolbars_model_set_property),
(ephy_toolbars_model_get_property),
(ephy_toolbars_model_class_init), (ephy_toolbars_model_init),
(ephy_toolbars_model_finalize), (ephy_toolbars_model_new):
* src/ephy-toolbars-model.h:
* src/toolbar.c: (topic_destroy_cb), (bookmark_destroy_cb),
(toolbar_ensure_action), (toolbar_init):
Better way to remove unrefed bookmarks from the toolbar.
Ref bookmarks in toolbars model and weak reaf toolbars model
in bookmarks. So setting defaults really works.
-rw-r--r-- | ChangeLog | 32 | ||||
-rw-r--r-- | lib/ephy-node.c | 10 | ||||
-rw-r--r-- | lib/ephy-node.h | 2 | ||||
-rw-r--r-- | lib/widgets/ephy-tree-model-node.c | 12 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-editor.c | 2 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks.c | 147 | ||||
-rw-r--r-- | src/ephy-shell.c | 8 | ||||
-rwxr-xr-x | src/ephy-toolbars-model.c | 73 | ||||
-rwxr-xr-x | src/ephy-toolbars-model.h | 3 | ||||
-rwxr-xr-x | src/toolbar.c | 151 |
10 files changed, 272 insertions, 168 deletions
@@ -1,3 +1,35 @@ +2003-05-26 Marco Pesenti Gritti <marco@it.gnome.org> + + * lib/ephy-node.c: (callback), (ephy_node_dispose): + * lib/ephy-node.h: + + s/DESTROYED/DESTROY which is more useulf + + * lib/widgets/ephy-tree-model-node.c: + (ephy_tree_model_node_set_property), (root_destroy_cb): + * src/bookmarks/ephy-bookmarks-editor.c: + (ephy_bookmarks_editor_update_menu): + * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_init_defaults), + (ephy_bookmarks_set_toolbars_model), (ephy_bookmarks_set_property), + (ephy_bookmarks_get_property), (ephy_bookmarks_class_init), + (bookmarks_removed_cb), (topics_removed_cb), (ephy_bookmarks_init), + (ephy_bookmarks_finalize): + * src/ephy-shell.c: (ephy_shell_get_toolbars_model): + * src/ephy-toolbars-model.c: (impl_add_item), + (ephy_toolbars_model_set_bookmarks), + (ephy_toolbars_model_set_property), + (ephy_toolbars_model_get_property), + (ephy_toolbars_model_class_init), (ephy_toolbars_model_init), + (ephy_toolbars_model_finalize), (ephy_toolbars_model_new): + * src/ephy-toolbars-model.h: + * src/toolbar.c: (topic_destroy_cb), (bookmark_destroy_cb), + (toolbar_ensure_action), (toolbar_init): + + Better way to remove unrefed bookmarks from the toolbar. + + Ref bookmarks in toolbars model and weak reaf toolbars model + in bookmarks. So setting defaults really works. + 2003-05-25 Marco Pesenti Gritti <marco@it.gnome.org> * lib/ephy-node.c: (ephy_node_dispose): diff --git a/lib/ephy-node.c b/lib/ephy-node.c index aaea35ef2..91110b565 100644 --- a/lib/ephy-node.c +++ b/lib/ephy-node.c @@ -122,7 +122,7 @@ callback (long id, EphyNodeSignalData *data, gpointer *user_data) switch (data->type) { - case EPHY_NODE_DESTROYED: + case EPHY_NODE_DESTROY: case EPHY_NODE_RESTORED: data->callback (data->node, data->data); break; @@ -281,6 +281,12 @@ ephy_node_dispose (EphyNode *node) { guint i; + write_lock_to_read_lock (node); + + ephy_node_emit_signal (node, EPHY_NODE_DESTROY); + + read_lock_to_write_lock (node); + lock_gdk (); /* remove from DAG */ @@ -302,8 +308,6 @@ ephy_node_dispose (EphyNode *node) g_static_rw_lock_writer_unlock (node->lock); - ephy_node_emit_signal (node, EPHY_NODE_DESTROYED); - g_hash_table_foreach (node->signals, (GHFunc) unref_signal_objects, node); diff --git a/lib/ephy-node.h b/lib/ephy-node.h index 5a6853f4e..a473c9abb 100644 --- a/lib/ephy-node.h +++ b/lib/ephy-node.h @@ -30,7 +30,7 @@ typedef struct EphyNode EphyNode; typedef enum { - EPHY_NODE_DESTROYED, /* RBNode *node */ + EPHY_NODE_DESTROY, /* RBNode *node */ EPHY_NODE_RESTORED, /* RBNode *node */ EPHY_NODE_CHILD_ADDED, /* RBNode *node, RBNode *child */ EPHY_NODE_CHILD_CHANGED, /* RBNode *node, RBNode *child */ diff --git a/lib/widgets/ephy-tree-model-node.c b/lib/widgets/ephy-tree-model-node.c index cf92167d2..563853016 100644 --- a/lib/widgets/ephy-tree-model-node.c +++ b/lib/widgets/ephy-tree-model-node.c @@ -80,8 +80,8 @@ static void root_children_reordered_cb (EphyNode *node, static inline void ephy_tree_model_node_update_node (EphyTreeModelNode *model, EphyNode *node, int idx); -static void root_destroyed_cb (EphyNode *node, - EphyTreeModelNode *model); +static void root_destroy_cb (EphyNode *node, + EphyTreeModelNode *model); static inline GtkTreePath *get_path_real (EphyTreeModelNode *model, EphyNode *node); @@ -267,8 +267,8 @@ ephy_tree_model_node_set_property (GObject *object, (EphyNodeCallback) root_children_reordered_cb, G_OBJECT (model)); ephy_node_signal_connect_object (model->priv->root, - EPHY_NODE_DESTROYED, - (EphyNodeCallback) root_destroyed_cb, + EPHY_NODE_DESTROY, + (EphyNodeCallback) root_destroy_cb, G_OBJECT (model)); break; @@ -726,8 +726,8 @@ root_children_reordered_cb (EphyNode *node, } static void -root_destroyed_cb (EphyNode *node, - EphyTreeModelNode *model) +root_destroy_cb (EphyNode *node, + EphyTreeModelNode *model) { model->priv->root = NULL; diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c index 7b9c2deb1..81e6e1e4b 100644 --- a/src/bookmarks/ephy-bookmarks-editor.c +++ b/src/bookmarks/ephy-bookmarks-editor.c @@ -729,6 +729,8 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor) EphyNode *node = selected->data; gulong id; + g_return_if_fail (node != NULL); + id = ephy_node_get_id (node); show_in_bookmarks_bar = ephy_toolbars_model_has_bookmark (editor->priv->tb_model, FALSE, id); diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c index b83c29888..ab15fcba0 100644 --- a/src/bookmarks/ephy-bookmarks.c +++ b/src/bookmarks/ephy-bookmarks.c @@ -42,6 +42,8 @@ struct EphyBookmarksPrivate { + EphyToolbarsModel *toolbars_model; + gboolean init_defaults; char *xml_file; EphyNodeDb *db; EphyNode *bookmarks; @@ -81,6 +83,12 @@ static const char *default_topics [] = }; static int n_default_topics = G_N_ELEMENTS (default_topics); +enum +{ + PROP_0, + PROP_TOOLBARS_MODEL +}; + static void ephy_bookmarks_class_init (EphyBookmarksClass *klass); static void @@ -90,17 +98,8 @@ ephy_bookmarks_finalize (GObject *object); static void ephy_bookmarks_autocompletion_source_init (EphyAutocompletionSourceIface *iface); -enum -{ - BOOKMARK_REMOVE, - TOPIC_REMOVE, - LAST_SIGNAL -}; - static GObjectClass *parent_class = NULL; -static guint ephy_bookmarks_signals[LAST_SIGNAL] = { 0 }; - GType ephy_bookmarks_get_type (void) { @@ -203,44 +202,10 @@ ephy_bookmarks_autocompletion_source_init (EphyAutocompletionSourceIface *iface) } static void -ephy_bookmarks_class_init (EphyBookmarksClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - object_class->finalize = ephy_bookmarks_finalize; - - ephy_bookmarks_signals[BOOKMARK_REMOVE] = - g_signal_new ("bookmark_remove", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (EphyBookmarksClass, bookmark_remove), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, - 1, - G_TYPE_INT); - ephy_bookmarks_signals[TOPIC_REMOVE] = - g_signal_new ("topic_remove", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (EphyBookmarksClass, topic_remove), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, - 1, - G_TYPE_INT); -} - -static void ephy_bookmarks_init_defaults (EphyBookmarks *eb) { int i, id; EphyNode *node; - EphyToolbarsModel *model; - - model = ephy_shell_get_toolbars_model (ephy_shell); for (i = 0; i < n_default_topics; i++) { @@ -256,12 +221,83 @@ ephy_bookmarks_init_defaults (EphyBookmarks *eb) node = ephy_bookmarks_find_bookmark (eb, default_bookmarks[i].location); if (node == NULL) break; id = ephy_node_get_id (node); - ephy_toolbars_model_add_bookmark (model, FALSE, id); + ephy_toolbars_model_add_bookmark (eb->priv->toolbars_model, FALSE, id); } ephy_bookmarks_save (eb); } +static void +ephy_bookmarks_set_toolbars_model (EphyBookmarks *eb, EphyToolbarsModel *model) +{ + eb->priv->toolbars_model = model; + g_object_add_weak_pointer (G_OBJECT(eb->priv->toolbars_model), + (gpointer *)&eb->priv->toolbars_model); + + if (eb->priv->init_defaults) + { + ephy_bookmarks_init_defaults (eb); + } +} + +static void +ephy_bookmarks_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EphyBookmarks *eb; + + eb = EPHY_BOOKMARKS (object); + + switch (prop_id) + { + case PROP_TOOLBARS_MODEL: + ephy_bookmarks_set_toolbars_model (eb, g_value_get_object (value)); + break; + } +} + +static void +ephy_bookmarks_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EphyBookmarks *eb; + + eb = EPHY_BOOKMARKS (object); + + switch (prop_id) + { + case PROP_TOOLBARS_MODEL: + g_value_set_object (value, eb->priv->toolbars_model); + break; + } +} + + +static void +ephy_bookmarks_class_init (EphyBookmarksClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->finalize = ephy_bookmarks_finalize; + object_class->set_property = ephy_bookmarks_set_property; + object_class->get_property = ephy_bookmarks_get_property; + + g_object_class_install_property (object_class, + PROP_TOOLBARS_MODEL, + g_param_spec_object ("toolbars_model", + "Toolbars model", + "Toolbars model", + EPHY_TOOLBARS_MODEL_TYPE, + G_PARAM_READWRITE)); + +} + static gboolean ephy_bookmarks_load (EphyBookmarks *eb) { @@ -485,12 +521,6 @@ bookmarks_removed_cb (EphyNode *node, guint old_index, EphyBookmarks *eb) { - long id; - - id = ephy_node_get_id (child); - g_signal_emit (eb, ephy_bookmarks_signals[BOOKMARK_REMOVE], - 0, id); - ephy_bookmarks_emit_data_changed (eb); } @@ -548,7 +578,6 @@ topics_removed_cb (EphyNode *node, guint old_index, EphyBookmarks *eb) { - long id; GPtrArray *children; int i; @@ -574,10 +603,6 @@ topics_removed_cb (EphyNode *node, g_free (list); } ephy_node_thaw (child); - - id = ephy_node_get_id (child); - g_signal_emit (eb, ephy_bookmarks_signals[TOPIC_REMOVE], - 0, id); } static void @@ -587,6 +612,7 @@ ephy_bookmarks_init (EphyBookmarks *eb) EphyNodeDb *db; eb->priv = g_new0 (EphyBookmarksPrivate, 1); + eb->priv->toolbars_model = NULL; db = ephy_node_db_new ("EphyBookmarks"); eb->priv->db = db; @@ -664,10 +690,7 @@ ephy_bookmarks_init (EphyBookmarks *eb) g_value_unset (&value); ephy_node_add_child (eb->priv->keywords, eb->priv->notcategorized); - if (!ephy_bookmarks_load (eb)) - { - ephy_bookmarks_init_defaults (eb); - } + eb->priv->init_defaults = !ephy_bookmarks_load (eb); ephy_bookmarks_emit_data_changed (eb); @@ -695,6 +718,12 @@ ephy_bookmarks_finalize (GObject *object) g_object_unref (eb->priv->db); + if (eb->priv->toolbars_model) + { + g_object_remove_weak_pointer (G_OBJECT(eb->priv->toolbars_model), + (gpointer *)&eb->priv->toolbars_model); + } + g_free (eb->priv); LOG ("Bookmarks finalized") diff --git a/src/ephy-shell.c b/src/ephy-shell.c index 4fcbcdf28..b2faa8cb3 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -663,8 +663,11 @@ ephy_shell_get_toolbars_model (EphyShell *gs) { char *xml_file; EggToolbarsModel *model; + EphyBookmarks *bookmarks; - gs->priv->toolbars_model = ephy_toolbars_model_new (); + bookmarks = ephy_shell_get_bookmarks (gs); + + gs->priv->toolbars_model = ephy_toolbars_model_new (bookmarks); model = EGG_TOOLBARS_MODEL (gs->priv->toolbars_model); xml_file = g_build_filename (ephy_dot_dir (), @@ -682,6 +685,9 @@ ephy_shell_get_toolbars_model (EphyShell *gs) egg_toolbars_model_load (model, default_xml); } g_free (xml_file); + + g_object_set (bookmarks, "toolbars_model", + gs->priv->toolbars_model, NULL); } return gs->priv->toolbars_model; diff --git a/src/ephy-toolbars-model.c b/src/ephy-toolbars-model.c index f2eacbe20..475de34f7 100755 --- a/src/ephy-toolbars-model.c +++ b/src/ephy-toolbars-model.c @@ -34,11 +34,17 @@ enum LAST_SIGNAL }; +enum +{ + PROP_0, + PROP_BOOKMARKS +}; + static GObjectClass *parent_class = NULL; struct EphyToolbarsModelPrivate { - gpointer dummy; + EphyBookmarks *bookmarks; }; GType @@ -75,7 +81,6 @@ impl_add_item (EggToolbarsModel *t, GdkAtom type, const char *name) { - EphyBookmarks *bookmarks; char *action_name = NULL; const char *res; gboolean topic = FALSE, normal_item = FALSE; @@ -83,8 +88,6 @@ impl_add_item (EggToolbarsModel *t, LOG ("Add item %s", name) - bookmarks = ephy_shell_get_bookmarks (ephy_shell); - if (gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE) == type) { GList *nodes; @@ -122,6 +125,49 @@ impl_add_item (EggToolbarsModel *t, } static void +ephy_toolbars_model_set_bookmarks (EphyToolbarsModel *model, EphyBookmarks *bookmarks) +{ + model->priv->bookmarks = bookmarks; + g_object_ref (model->priv->bookmarks); +} + +static void +ephy_toolbars_model_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EphyToolbarsModel *model; + + model = EPHY_TOOLBARS_MODEL (object); + + switch (prop_id) + { + case PROP_BOOKMARKS: + ephy_toolbars_model_set_bookmarks (model, g_value_get_object (value)); + break; + } +} + +static void +ephy_toolbars_model_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EphyToolbarsModel *model; + + model = EPHY_TOOLBARS_MODEL (object); + + switch (prop_id) + { + case PROP_BOOKMARKS: + g_value_set_object (value, model->priv->bookmarks); + break; + } +} + +static void ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -132,14 +178,25 @@ ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass) parent_class = g_type_class_peek_parent (klass); object_class->finalize = ephy_toolbars_model_finalize; + object_class->set_property = ephy_toolbars_model_set_property; + object_class->get_property = ephy_toolbars_model_get_property; etm_class->add_item = impl_add_item; + + g_object_class_install_property (object_class, + PROP_BOOKMARKS, + g_param_spec_object ("bookmarks", + "Bookmarks", + "Bookmarks", + EPHY_BOOKMARKS_TYPE, + G_PARAM_READWRITE)); } static void ephy_toolbars_model_init (EphyToolbarsModel *t) { t->priv = g_new0 (EphyToolbarsModelPrivate, 1); + t->priv->bookmarks = NULL; } static void @@ -150,17 +207,21 @@ ephy_toolbars_model_finalize (GObject *object) g_return_if_fail (object != NULL); g_return_if_fail (IS_EPHY_TOOLBARS_MODEL (object)); + g_object_unref (t->priv->bookmarks); + g_free (t->priv); G_OBJECT_CLASS (parent_class)->finalize (object); } EphyToolbarsModel * -ephy_toolbars_model_new (void) +ephy_toolbars_model_new (EphyBookmarks *bookmarks) { EphyToolbarsModel *t; - t = EPHY_TOOLBARS_MODEL (g_object_new (EPHY_TOOLBARS_MODEL_TYPE, NULL)); + t = EPHY_TOOLBARS_MODEL (g_object_new (EPHY_TOOLBARS_MODEL_TYPE, + "bookmarks", bookmarks, + NULL)); g_return_val_if_fail (t->priv != NULL, NULL); diff --git a/src/ephy-toolbars-model.h b/src/ephy-toolbars-model.h index 0f1de55ad..c3345274a 100755 --- a/src/ephy-toolbars-model.h +++ b/src/ephy-toolbars-model.h @@ -20,6 +20,7 @@ #define EPHY_TOOLBARS_MODEL_H #include "egg-toolbars-model.h" +#include "ephy-bookmarks.h" G_BEGIN_DECLS @@ -48,7 +49,7 @@ struct EphyToolbarsModelClass GType ephy_toolbars_model_get_type (void); -EphyToolbarsModel *ephy_toolbars_model_new (void); +EphyToolbarsModel *ephy_toolbars_model_new (EphyBookmarks *bookmarks); void ephy_toolbars_model_add_bookmark (EphyToolbarsModel *model, gboolean topic, diff --git a/src/toolbar.c b/src/toolbar.c index d211de6d5..b43a58c26 100755 --- a/src/toolbar.c +++ b/src/toolbar.c @@ -133,21 +133,50 @@ zoom_to_level_cb (EggAction *action, float zoom, EphyWindow *window) ephy_window_set_zoom (window, zoom); } -static EggAction * -ensure_bookmark_action (Toolbar *t, EphyBookmarks *bookmarks, gulong id, const char *action_name) +static void +topic_destroy_cb (EphyNode *node, + Toolbar *t) { EggAction *action; + char *name; + EphyToolbarsModel *model; + long id; - LOG ("Creating action for bookmark id %ld", id) + model = ephy_shell_get_toolbars_model (ephy_shell); - action = ephy_bookmark_action_new (action_name, id); + id = ephy_node_get_id (node); + name = g_strdup_printf ("GoTopicId%ld", ephy_node_get_id (node)); + action = egg_action_group_get_action (t->priv->action_group, name); + if (action) + { + ephy_toolbars_model_remove_bookmark (model, TRUE, id); + egg_action_group_remove_action (t->priv->action_group, action); + } - g_signal_connect (action, "go_location", - G_CALLBACK (go_location_cb), t->priv->window); - egg_action_group_add_action (t->priv->action_group, action); - g_object_unref (action); + g_free (name); +} + +static void +bookmark_destroy_cb (EphyNode *node, + Toolbar *t) +{ + EggAction *action; + char *name; + EphyToolbarsModel *model; + long id; - return action; + model = ephy_shell_get_toolbars_model (ephy_shell); + + id = ephy_node_get_id (node); + name = g_strdup_printf ("GoBookmarkId%ld", id); + action = egg_action_group_get_action (t->priv->action_group, name); + if (action) + { + ephy_toolbars_model_remove_bookmark (model, FALSE, id); + egg_action_group_remove_action (t->priv->action_group, action); + } + + g_free (name); } static void @@ -155,7 +184,7 @@ toolbar_ensure_action (Toolbar *t, const char *name) { EggAction *action = NULL; - gulong id = 0; + long id = 0; EphyBookmarks *bookmarks; LOG ("Ensure action %s", name) @@ -164,6 +193,8 @@ toolbar_ensure_action (Toolbar *t, if (g_str_has_prefix (name, "GoBookmarkId")) { + EphyNode *node; + if (!ephy_str_to_int (name + strlen ("GoBookmarkId"), &id)) { return; @@ -171,10 +202,22 @@ toolbar_ensure_action (Toolbar *t, LOG ("Create action %s", name) - action = ensure_bookmark_action (t, bookmarks, id, name); + action = ephy_bookmark_action_new (name, id); + g_signal_connect (action, "go_location", + G_CALLBACK (go_location_cb), t->priv->window); + egg_action_group_add_action (t->priv->action_group, action); + g_object_unref (action); + + node = ephy_bookmarks_get_from_id (bookmarks, id); + ephy_node_signal_connect_object (node, + EPHY_NODE_DESTROY, + (EphyNodeCallback) bookmark_destroy_cb, + G_OBJECT (t)); } else if (g_str_has_prefix (name, "GoTopicId")) { + EphyNode *node; + if (!ephy_str_to_int (name + strlen ("GoTopicId"), &id)) { return; @@ -188,6 +231,12 @@ toolbar_ensure_action (Toolbar *t, t->priv->window); egg_action_group_add_action (t->priv->action_group, action); g_object_unref (action); + + node = ephy_bookmarks_get_from_id (bookmarks, id); + ephy_node_signal_connect_object (node, + EPHY_NODE_DESTROY, + (EphyNodeCallback) topic_destroy_cb, + G_OBJECT (t)); } } @@ -441,93 +490,13 @@ toolbar_set_window (Toolbar *t, EphyWindow *window) } static void -remove_action (EphyToolbarsModel *model, - const char *action_name) -{ - int i, n_toolbars, l, n_items; - - n_toolbars = egg_toolbars_model_n_toolbars - (EGG_TOOLBARS_MODEL (model)); - - for (i = 0; i < n_toolbars; i++) - { - n_items = egg_toolbars_model_n_items (EGG_TOOLBARS_MODEL (model), i); - for (l = 0; l < n_items; l++) - { - const char *i_name; - gboolean sep; - - i_name = egg_toolbars_model_item_nth - (EGG_TOOLBARS_MODEL (model), i, l, &sep); - if (!sep && strcmp (action_name, i_name) == 0) - { - egg_toolbars_model_remove_item - (EGG_TOOLBARS_MODEL (model), i, l); - } - } - } -} - -static void -topic_remove_cb (EphyBookmarks *eb, - long id, - Toolbar *t) -{ - EggAction *action; - char *name; - EphyToolbarsModel *model; - - model = ephy_shell_get_toolbars_model (ephy_shell); - - name = g_strdup_printf ("GoTopicId%ld", id); - action = egg_action_group_get_action (t->priv->action_group, name); - if (action) - { - remove_action (model, action->name); - egg_action_group_remove_action (t->priv->action_group, action); - } - - g_free (name); -} - -static void -bookmark_remove_cb (EphyBookmarks *eb, - long id, - Toolbar *t) -{ - EggAction *action; - char *name; - EphyToolbarsModel *model; - - model = ephy_shell_get_toolbars_model (ephy_shell); - - name = g_strdup_printf ("GoBookmarkId%ld", id); - action = egg_action_group_get_action (t->priv->action_group, name); - if (action) - { - remove_action (model, action->name); - egg_action_group_remove_action (t->priv->action_group, action); - } - - g_free (name); -} - -static void toolbar_init (Toolbar *t) { - EphyBookmarks *bookmarks; - t->priv = g_new0 (ToolbarPrivate, 1); t->priv->window = NULL; t->priv->ui_merge = NULL; t->priv->visibility = TRUE; - - bookmarks = ephy_shell_get_bookmarks (ephy_shell); - g_signal_connect (bookmarks, "bookmark_remove", - G_CALLBACK (bookmark_remove_cb), t); - g_signal_connect (bookmarks, "topic_remove", - G_CALLBACK (topic_remove_cb), t); } static void |