diff options
Diffstat (limited to 'src')
-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 |
6 files changed, 226 insertions, 158 deletions
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 |