aboutsummaryrefslogtreecommitdiffstats
path: root/src/bookmarks
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-06-11 03:05:53 +0800
committerChristian Persch <chpe@src.gnome.org>2004-06-11 03:05:53 +0800
commit27ae6e03f698835c1683c03b7cfc0e401d0f601f (patch)
treee0071b3ad7fa45afb0d97930a4deacde7c51ccaf /src/bookmarks
parentee67c4e456ce1bee49da717ee86ae85e76499e6d (diff)
downloadgsoc2013-epiphany-27ae6e03f698835c1683c03b7cfc0e401d0f601f.tar
gsoc2013-epiphany-27ae6e03f698835c1683c03b7cfc0e401d0f601f.tar.gz
gsoc2013-epiphany-27ae6e03f698835c1683c03b7cfc0e401d0f601f.tar.bz2
gsoc2013-epiphany-27ae6e03f698835c1683c03b7cfc0e401d0f601f.tar.lz
gsoc2013-epiphany-27ae6e03f698835c1683c03b7cfc0e401d0f601f.tar.xz
gsoc2013-epiphany-27ae6e03f698835c1683c03b7cfc0e401d0f601f.tar.zst
gsoc2013-epiphany-27ae6e03f698835c1683c03b7cfc0e401d0f601f.zip
Merging bookmarksbar-separation branch.
2004-06-10 Christian Persch <chpe@cvs.gnome.org> Merging bookmarksbar-separation branch.
Diffstat (limited to 'src/bookmarks')
-rw-r--r--src/bookmarks/Makefile.am4
-rw-r--r--src/bookmarks/ephy-bookmark-properties.c14
-rw-r--r--src/bookmarks/ephy-bookmarks-editor.c43
-rw-r--r--src/bookmarks/ephy-bookmarks.c115
-rw-r--r--src/bookmarks/ephy-bookmarks.h114
-rwxr-xr-xsrc/bookmarks/ephy-bookmarksbar-model.c114
-rwxr-xr-xsrc/bookmarks/ephy-bookmarksbar-model.h26
-rw-r--r--src/bookmarks/ephy-bookmarksbar.c60
8 files changed, 288 insertions, 202 deletions
diff --git a/src/bookmarks/Makefile.am b/src/bookmarks/Makefile.am
index 104254cbf..3b2b130ae 100644
--- a/src/bookmarks/Makefile.am
+++ b/src/bookmarks/Makefile.am
@@ -29,6 +29,8 @@ NOINST_H_FILES = \
ephy-bookmarks-export.h \
ephy-bookmarks-import.h \
ephy-bookmarks-menu.h \
+ ephy-bookmarksbar-model.h \
+ ephy-bookmarksbar.h \
ephy-bookmark-properties.h \
ephy-new-bookmark.h \
ephy-topic-action.h \
@@ -41,6 +43,8 @@ libephybookmarks_la_SOURCES = \
ephy-bookmarks-export.c \
ephy-bookmarks-import.c \
ephy-bookmarks-menu.c \
+ ephy-bookmarksbar-model.c \
+ ephy-bookmarksbar.c \
ephy-bookmark-properties.c \
ephy-new-bookmark.c \
ephy-topic-action.c \
diff --git a/src/bookmarks/ephy-bookmark-properties.c b/src/bookmarks/ephy-bookmark-properties.c
index 2b6325add..f984124b8 100644
--- a/src/bookmarks/ephy-bookmark-properties.c
+++ b/src/bookmarks/ephy-bookmark-properties.c
@@ -22,7 +22,7 @@
#include "config.h"
#endif
-#include "ephy-toolbars-model.h"
+#include "ephy-bookmarksbar-model.h"
#include "ephy-bookmark-properties.h"
#include "ephy-topics-selector.h"
#include "ephy-debug.h"
@@ -64,7 +64,7 @@ struct EphyBookmarkPropertiesPrivate
GtkWidget *location_entry;
GtkWidget *topics_selector;
- EphyToolbarsModel *tb_model;
+ EphyBookmarksBarModel *tb_model;
};
enum
@@ -155,6 +155,8 @@ ephy_bookmark_properties_set_property (GObject *object,
{
case PROP_BOOKMARKS:
selector->priv->bookmarks = g_value_get_object (value);
+ selector->priv->tb_model = EPHY_BOOKMARKSBAR_MODEL
+ (ephy_bookmarks_get_toolbars_model (selector->priv->bookmarks));
break;
case PROP_BOOKMARK:
ephy_bookmark_properties_set_bookmark
@@ -260,12 +262,12 @@ toolbar_checkbox_changed_cb (GtkWidget *checkbox, EphyBookmarkProperties *props)
if (state)
{
- ephy_toolbars_model_add_bookmark
+ ephy_bookmarksbar_model_add_bookmark
(props->priv->tb_model, FALSE, id);
}
else
{
- ephy_toolbars_model_remove_bookmark
+ ephy_bookmarksbar_model_remove_bookmark
(props->priv->tb_model, id);
}
}
@@ -402,7 +404,7 @@ build_ui (EphyBookmarkProperties *editor)
checkbox = gtk_check_button_new_with_mnemonic (_("_Show in bookmarks bar"));
id = ephy_node_get_id (editor->priv->bookmark);
- state = ephy_toolbars_model_has_bookmark (editor->priv->tb_model, id);
+ state = ephy_bookmarksbar_model_has_bookmark (editor->priv->tb_model, id);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), state);
g_signal_connect (checkbox, "toggled",
G_CALLBACK (toolbar_checkbox_changed_cb), editor);
@@ -427,8 +429,6 @@ ephy_bookmark_properties_init (EphyBookmarkProperties *editor)
editor->priv = EPHY_BOOKMARK_PROPERTIES_GET_PRIVATE (editor);
editor->priv->bookmark = NULL;
- editor->priv->tb_model = EPHY_TOOLBARS_MODEL
- (ephy_shell_get_toolbars_model (ephy_shell, FALSE));
}
GtkWidget *
diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c
index 5a8b71976..0cc0158a0 100644
--- a/src/bookmarks/ephy-bookmarks-editor.c
+++ b/src/bookmarks/ephy-bookmarks-editor.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003 Marco Pesenti Gritti <mpeseng@tin.it>
+ * Copyright (C) 2003, 2004 Marco Pesenti Gritti <mpeseng@tin.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -56,7 +56,7 @@
#include "ephy-gui.h"
#include "ephy-stock-icons.h"
#include "ephy-search-entry.h"
-#include "ephy-toolbars-model.h"
+#include "ephy-bookmarksbar-model.h"
#include "ephy-favicon-cache.h"
#include "eel-gconf-extensions.h"
#include "ephy-debug.h"
@@ -141,7 +141,7 @@ struct EphyBookmarksEditorPrivate
GtkUIManager *ui_merge;
GtkActionGroup *action_group;
int priority_col;
- EphyToolbarsModel *tb_model;
+ EphyBookmarksBarModel *tb_model;
GHashTable *props_dialogs;
GtkTreeViewColumn *title_col;
@@ -322,6 +322,15 @@ get_target_window (EphyBookmarksEditor *editor)
}
static void
+toolbar_items_changed_cb (EggToolbarsModel *model,
+ int toolbar_position,
+ int position,
+ EphyBookmarksEditor *editor)
+{
+ ephy_bookmarks_editor_update_menu (editor);
+}
+
+static void
cmd_show_in_bookmarks_bar (GtkAction *action,
EphyBookmarksEditor *editor)
{
@@ -353,13 +362,19 @@ cmd_show_in_bookmarks_bar (GtkAction *action,
if (state)
{
- ephy_toolbars_model_add_bookmark
+ ephy_bookmarksbar_model_add_bookmark
(editor->priv->tb_model, topic, id);
}
else
{
- ephy_toolbars_model_remove_bookmark
+ g_signal_handlers_block_by_func
+ (editor->priv->tb_model,
+ G_CALLBACK (toolbar_items_changed_cb), editor);
+ ephy_bookmarksbar_model_remove_bookmark
(editor->priv->tb_model, id);
+ g_signal_handlers_unblock_by_func
+ (editor->priv->tb_model,
+ G_CALLBACK (toolbar_items_changed_cb), editor);
}
g_list_free (selection);
@@ -981,7 +996,7 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor)
gulong id;
id = ephy_node_get_id (node);
- show_in_bookmarks_bar = ephy_toolbars_model_has_bookmark
+ show_in_bookmarks_bar = ephy_bookmarksbar_model_has_bookmark
(editor->priv->tb_model, id);
priority = ephy_node_get_property_int
@@ -1001,7 +1016,7 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor)
g_return_if_fail (node != NULL);
id = ephy_node_get_id (node);
- show_in_bookmarks_bar = ephy_toolbars_model_has_bookmark
+ show_in_bookmarks_bar = ephy_bookmarksbar_model_has_bookmark
(editor->priv->tb_model, id);
g_list_free (selected);
@@ -1653,23 +1668,15 @@ ephy_bookmarks_editor_get_property (GObject *object,
}
static void
-toolbar_items_changed_cb (EphyToolbarsModel *model,
- int toolbar_position,
- int position,
- EphyBookmarksEditor *editor)
-{
- ephy_bookmarks_editor_update_menu (editor);
-}
-
-static void
ephy_bookmarks_editor_init (EphyBookmarksEditor *editor)
{
editor->priv = EPHY_BOOKMARKS_EDITOR_GET_PRIVATE (editor);
editor->priv->props_dialogs = g_hash_table_new (g_direct_hash,
g_direct_equal);
- editor->priv->tb_model = EPHY_TOOLBARS_MODEL
- (ephy_shell_get_toolbars_model (ephy_shell, FALSE));
+ editor->priv->tb_model = EPHY_BOOKMARKSBAR_MODEL
+ (ephy_bookmarks_get_toolbars_model
+ (ephy_shell_get_bookmarks (ephy_shell)));
g_signal_connect (editor->priv->tb_model, "item_added",
G_CALLBACK (toolbar_items_changed_cb), editor);
diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c
index 6e765e6d6..be9884956 100644
--- a/src/bookmarks/ephy-bookmarks.c
+++ b/src/bookmarks/ephy-bookmarks.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2002-2004 Marco Pesenti Gritti
+ * Copyright (C) 2003, 2004 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -30,7 +31,7 @@
#include "ephy-debug.h"
#include "ephy-tree-model-node.h"
#include "ephy-node-common.h"
-#include "ephy-toolbars-model.h"
+#include "ephy-bookmarksbar-model.h"
#include "ephy-bookmarks-export.h"
#include "ephy-bookmarks-import.h"
#include "ephy-prefs.h"
@@ -50,7 +51,7 @@
struct EphyBookmarksPrivate
{
- EphyToolbarsModel *toolbars_model;
+ EphyBookmarksBarModel *toolbars_model;
gboolean init_defaults;
gboolean dirty;
guint save_timeout_id;
@@ -160,22 +161,84 @@ ephy_bookmarks_init_defaults (EphyBookmarks *eb)
bmk = ephy_bookmarks_add (eb, _(default_bookmarks[i].title),
_(default_bookmarks[i].location));
- ephy_toolbars_model_add_bookmark (eb->priv->toolbars_model, FALSE,
- ephy_node_get_id (bmk));
+ ephy_bookmarksbar_model_add_bookmark (eb->priv->toolbars_model, FALSE,
+ ephy_node_get_id (bmk));
}
}
-static void
-ephy_bookmarks_set_toolbars_model (EphyBookmarks *eb, EphyToolbarsModel *model)
+static char *
+get_item_type_forward_cb (EggToolbarsModel *model,
+ GdkAtom type,
+ EggToolbarsModel *bookmarksbar_model)
+{
+ char *retval;
+
+ g_signal_emit_by_name (bookmarksbar_model, "get_item_type",
+ type, &retval);
+
+ return retval;
+}
+
+static char *
+get_item_id_forward_cb (EggToolbarsModel *model,
+ const char *type,
+ const char *name,
+ EggToolbarsModel *bookmarksbar_model)
+{
+ char *retval;
+
+ g_signal_emit_by_name (bookmarksbar_model, "get_item_id",
+ type, name, &retval);
+
+ return retval;
+}
+
+static char *
+get_item_data_forward_cb (EggToolbarsModel *model,
+ const char *type,
+ const char *id,
+ EggToolbarsModel *bookmarksbar_model)
+{
+ char *retval;
+
+ g_signal_emit_by_name (bookmarksbar_model, "get_item_data",
+ type, id, &retval);
+
+ return retval;
+}
+
+EggToolbarsModel *
+ephy_bookmarks_get_toolbars_model (EphyBookmarks *eb)
{
- eb->priv->toolbars_model = model;
- g_object_add_weak_pointer (G_OBJECT(eb->priv->toolbars_model),
- (gpointer *)&eb->priv->toolbars_model);
+ g_return_val_if_fail (EPHY_IS_BOOKMARKS (eb), NULL);
- if (eb->priv->init_defaults)
+ if (eb->priv->toolbars_model == NULL)
{
- ephy_bookmarks_init_defaults (eb);
+ GObject *toolbars_model;
+
+ eb->priv->toolbars_model = EPHY_BOOKMARKSBAR_MODEL
+ (ephy_bookmarksbar_model_new (eb));
+
+ /* forward those signals, so that bookmarks can also be on the main model */
+ toolbars_model = ephy_shell_get_toolbars_model (ephy_shell, FALSE);
+
+ g_signal_connect_after (toolbars_model, "get_item_type",
+ G_CALLBACK (get_item_type_forward_cb),
+ eb->priv->toolbars_model);
+ g_signal_connect_after (toolbars_model, "get_item_id",
+ G_CALLBACK (get_item_id_forward_cb),
+ eb->priv->toolbars_model);
+ g_signal_connect_after (toolbars_model, "get_item_data",
+ G_CALLBACK (get_item_data_forward_cb),
+ eb->priv->toolbars_model);
+
+ if (eb->priv->init_defaults)
+ {
+ ephy_bookmarks_init_defaults (eb);
+ }
}
+
+ return EGG_TOOLBARS_MODEL (eb->priv->toolbars_model);
}
static void
@@ -184,16 +247,8 @@ ephy_bookmarks_set_property (GObject *object,
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;
- }
+ /* no writable properties */
+ g_assert_not_reached ();
}
static void
@@ -202,14 +257,12 @@ ephy_bookmarks_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- EphyBookmarks *eb;
-
- eb = EPHY_BOOKMARKS (object);
+ EphyBookmarks *eb = EPHY_BOOKMARKS (object);
switch (prop_id)
{
case PROP_TOOLBARS_MODEL:
- g_value_set_object (value, eb->priv->toolbars_model);
+ g_value_set_object (value, ephy_bookmarks_get_toolbars_model (eb));
break;
}
}
@@ -238,11 +291,11 @@ ephy_bookmarks_class_init (EphyBookmarksClass *klass)
g_object_class_install_property (object_class,
PROP_TOOLBARS_MODEL,
- g_param_spec_object ("toolbars_model",
+ g_param_spec_object ("toolbars-model",
"Toolbars model",
"Toolbars model",
- EPHY_TYPE_TOOLBARS_MODEL,
- G_PARAM_READWRITE));
+ EPHY_TYPE_BOOKMARKSBAR_MODEL,
+ G_PARAM_READABLE));
g_type_class_add_private (object_class, sizeof(EphyBookmarksPrivate));
}
@@ -763,10 +816,10 @@ ephy_bookmarks_finalize (GObject *object)
g_object_unref (eb->priv->db);
- if (eb->priv->toolbars_model)
+ LOG ("Unref bookmarks toolbars model")
+ if (eb->priv->toolbars_model != NULL)
{
- g_object_remove_weak_pointer (G_OBJECT(eb->priv->toolbars_model),
- (gpointer *)&eb->priv->toolbars_model);
+ g_object_unref (eb->priv->toolbars_model);
}
g_free (eb->priv->xml_file);
diff --git a/src/bookmarks/ephy-bookmarks.h b/src/bookmarks/ephy-bookmarks.h
index 14b352e0a..26c83832e 100644
--- a/src/bookmarks/ephy-bookmarks.h
+++ b/src/bookmarks/ephy-bookmarks.h
@@ -1,5 +1,6 @@
/*
- * Copyright (C) 2000, 2001, 2002 Marco Pesenti Gritti
+ * Copyright (C) 2000-2004 Marco Pesenti Gritti
+ * Copyright (C) 2003, 2004 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,6 +25,7 @@
#include <glib-object.h>
#include "ephy-node.h"
+#include "egg-toolbars-model.h"
G_BEGIN_DECLS
@@ -34,103 +36,105 @@ G_BEGIN_DECLS
#define EPHY_IS_BOOKMARKS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_BOOKMARKS))
#define EPHY_BOOKMARKS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_BOOKMARKS, EphyBookmarksClass))
-typedef struct EphyBookmarksClass EphyBookmarksClass;
-typedef struct EphyBookmarks EphyBookmarks;
-typedef struct EphyBookmarksPrivate EphyBookmarksPrivate;
+typedef struct EphyBookmarksClass EphyBookmarksClass;
+typedef struct EphyBookmarks EphyBookmarks;
+typedef struct EphyBookmarksPrivate EphyBookmarksPrivate;
enum
{
- EPHY_NODE_BMK_PROP_TITLE = 2,
- EPHY_NODE_BMK_PROP_LOCATION = 3,
- EPHY_NODE_BMK_PROP_KEYWORDS = 4,
- EPHY_NODE_KEYWORD_PROP_NAME = 5,
- EPHY_NODE_BMK_PROP_ICON = 7,
- EPHY_NODE_KEYWORD_PROP_PRIORITY = 8
+ EPHY_NODE_BMK_PROP_TITLE = 2,
+ EPHY_NODE_BMK_PROP_LOCATION = 3,
+ EPHY_NODE_BMK_PROP_KEYWORDS = 4,
+ EPHY_NODE_KEYWORD_PROP_NAME = 5,
+ EPHY_NODE_BMK_PROP_ICON = 7,
+ EPHY_NODE_KEYWORD_PROP_PRIORITY = 8
};
struct EphyBookmarks
{
- GObject parent;
+ GObject parent;
/*< private >*/
- EphyBookmarksPrivate *priv;
+ EphyBookmarksPrivate *priv;
};
struct EphyBookmarksClass
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
- void (* tree_changed) (EphyBookmarks *eb);
+ void (* tree_changed) (EphyBookmarks *eb);
};
-GType ephy_bookmarks_get_type (void);
+GType ephy_bookmarks_get_type (void);
-EphyBookmarks *ephy_bookmarks_new (void);
+EphyBookmarks *ephy_bookmarks_new (void);
-EphyNode *ephy_bookmarks_get_from_id (EphyBookmarks *eb,
- long id);
+EphyNode *ephy_bookmarks_get_from_id (EphyBookmarks *eb,
+ long id);
+
+EggToolbarsModel *ephy_bookmarks_get_toolbars_model (EphyBookmarks *eb);
/* Bookmarks */
-EphyNode *ephy_bookmarks_add (EphyBookmarks *eb,
- const char *title,
- const char *url);
+EphyNode *ephy_bookmarks_add (EphyBookmarks *eb,
+ const char *title,
+ const char *url);
-EphyNode* ephy_bookmarks_find_bookmark (EphyBookmarks *eb,
- const char *url);
+EphyNode* ephy_bookmarks_find_bookmark (EphyBookmarks *eb,
+ const char *url);
-void ephy_bookmarks_set_icon (EphyBookmarks *eb,
- const char *url,
- const char *icon);
+void ephy_bookmarks_set_icon (EphyBookmarks *eb,
+ const char *url,
+ const char *icon);
-void ephy_bookmarks_set_address (EphyBookmarks *eb,
- EphyNode *bookmark,
- const char *address);
+void ephy_bookmarks_set_address (EphyBookmarks *eb,
+ EphyNode *bookmark,
+ const char *address);
-char *ephy_bookmarks_solve_smart_url (EphyBookmarks *eb,
- const char *smart_url,
- const char *content);
+char *ephy_bookmarks_solve_smart_url (EphyBookmarks *eb,
+ const char *smart_url,
+ const char *content);
/* Keywords */
-EphyNode *ephy_bookmarks_add_keyword (EphyBookmarks *eb,
- const char *name);
+EphyNode *ephy_bookmarks_add_keyword (EphyBookmarks *eb,
+ const char *name);
-EphyNode *ephy_bookmarks_find_keyword (EphyBookmarks *eb,
- const char *name,
- gboolean partial_match);
+EphyNode *ephy_bookmarks_find_keyword (EphyBookmarks *eb,
+ const char *name,
+ gboolean partial_match);
-void ephy_bookmarks_remove_keyword (EphyBookmarks *eb,
- EphyNode *keyword);
+void ephy_bookmarks_remove_keyword (EphyBookmarks *eb,
+ EphyNode *keyword);
-gboolean ephy_bookmarks_has_keyword (EphyBookmarks *eb,
- EphyNode *keyword,
- EphyNode *bookmark);
+gboolean ephy_bookmarks_has_keyword (EphyBookmarks *eb,
+ EphyNode *keyword,
+ EphyNode *bookmark);
-void ephy_bookmarks_set_keyword (EphyBookmarks *eb,
- EphyNode *keyword,
- EphyNode *bookmark);
+void ephy_bookmarks_set_keyword (EphyBookmarks *eb,
+ EphyNode *keyword,
+ EphyNode *bookmark);
-void ephy_bookmarks_unset_keyword (EphyBookmarks *eb,
- EphyNode *keyword,
- EphyNode *bookmark);
+void ephy_bookmarks_unset_keyword (EphyBookmarks *eb,
+ EphyNode *keyword,
+ EphyNode *bookmark);
-char *ephy_bookmarks_get_topic_uri (EphyBookmarks *eb,
- EphyNode *node);
+char *ephy_bookmarks_get_topic_uri (EphyBookmarks *eb,
+ EphyNode *node);
/* Favorites */
-EphyNode *ephy_bookmarks_get_favorites (EphyBookmarks *eb);
+EphyNode *ephy_bookmarks_get_favorites (EphyBookmarks *eb);
/* Root */
-EphyNode *ephy_bookmarks_get_keywords (EphyBookmarks *eb);
+EphyNode *ephy_bookmarks_get_keywords (EphyBookmarks *eb);
-EphyNode *ephy_bookmarks_get_bookmarks (EphyBookmarks *eb);
+EphyNode *ephy_bookmarks_get_bookmarks (EphyBookmarks *eb);
-EphyNode *ephy_bookmarks_get_not_categorized (EphyBookmarks *eb);
+EphyNode *ephy_bookmarks_get_not_categorized (EphyBookmarks *eb);
-EphyNode *ephy_bookmarks_get_smart_bookmarks (EphyBookmarks *eb);
+EphyNode *ephy_bookmarks_get_smart_bookmarks (EphyBookmarks *eb);
G_END_DECLS
diff --git a/src/bookmarks/ephy-bookmarksbar-model.c b/src/bookmarks/ephy-bookmarksbar-model.c
index cc5bdf773..fc969fddc 100755
--- a/src/bookmarks/ephy-bookmarksbar-model.c
+++ b/src/bookmarks/ephy-bookmarksbar-model.c
@@ -188,9 +188,9 @@ ephy_bookmarksbar_model_add_bookmark (EphyBookmarksBarModel *model,
name = ephy_bookmarksbar_model_get_action_name (model, id);
egg_toolbars_model_add_item (EGG_TOOLBARS_MODEL (model),
- toolbar_position, -1, name,
- topic ? EPHY_DND_TOPIC_TYPE :
- EPHY_DND_URL_TYPE);
+ toolbar_position, -1, name,
+ topic ? EPHY_DND_TOPIC_TYPE :
+ EPHY_DND_URL_TYPE);
g_free (name);
}
@@ -198,19 +198,19 @@ void
ephy_bookmarksbar_model_remove_bookmark (EphyBookmarksBarModel *model,
long id)
{
-/* char *action_name;
+ char *action_name;
int toolbar, position;
action_name = ephy_bookmarksbar_model_get_action_name (model, id);
g_return_if_fail (action_name != NULL);
- if (get_toolbar_and_item_pos (model, action_name, &toolbar, &position))
+ while (get_toolbar_and_item_pos (model, action_name, &toolbar, &position))
{
egg_toolbars_model_remove_item (EGG_TOOLBARS_MODEL (model),
toolbar, position);
}
- g_free (action_name);*/
+ g_free (action_name);
}
gboolean
@@ -285,74 +285,27 @@ update_flags_and_save_changes (EphyBookmarksBarModel *model)
}
static void
-bookmark_destroy_cb (EphyNode *node,
- EphyBookmarksBarModel *model)
-{
- long id;
-
- id = ephy_node_get_id (node);
- ephy_bookmarksbar_model_remove_bookmark (model, id);
-}
-
-static void
item_added_cb (EphyBookmarksBarModel *model,
int toolbar_position,
int position)
{
- EphyNode *node;
- const char *i_name;
- gboolean is_separator;
-
- egg_toolbars_model_item_nth (EGG_TOOLBARS_MODEL (model), toolbar_position,
- position, &is_separator, &i_name, NULL);
- if (!is_separator && g_str_has_prefix (i_name, "GoBookmark-"))
- {
- node = ephy_bookmarksbar_model_get_node (model, i_name);
- g_return_if_fail (node != NULL);
-
- ephy_node_signal_connect_object (node,
- EPHY_NODE_DESTROY,
- (EphyNodeCallback) bookmark_destroy_cb,
- G_OBJECT (model));
- }
-
save_changes (model);
}
static char *
-impl_get_item_name (EggToolbarsModel *eggmodel,
- const char *type,
- const char *id)
+impl_get_item_type (EggToolbarsModel *model,
+ GdkAtom type)
{
- EphyBookmarksBarModel *model = EPHY_BOOKMARKSBAR_MODEL (eggmodel);
- EphyNode *node;
-
- if (strcmp (type, EPHY_DND_TOPIC_TYPE) == 0)
+ if (gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE) == type)
{
- char *uri;
-
- node = ephy_bookmarksbar_model_get_node (model, id);
- g_return_val_if_fail (node != NULL, NULL);
-
- uri = ephy_bookmarks_get_topic_uri
- (model->priv->bookmarks, node);
-
- return uri;
+ return g_strdup (EPHY_DND_TOPIC_TYPE);
}
- else if (strcmp (type, EPHY_DND_URL_TYPE) == 0)
+ else if (gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE) == type)
{
- const char *name;
-
- node = ephy_bookmarksbar_model_get_node (model, id);
- g_return_val_if_fail (node != NULL, NULL);
-
- name = ephy_node_get_property_string
- (node, EPHY_NODE_BMK_PROP_LOCATION);
-
- return g_strdup (name);
+ return g_strdup (EPHY_DND_URL_TYPE);
}
- return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_name (eggmodel, type, id);
+ return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_type (model, type);
}
static char *
@@ -422,19 +375,39 @@ impl_get_item_id (EggToolbarsModel *eggmodel,
}
static char *
-impl_get_item_type (EggToolbarsModel *model,
- GdkAtom type)
+impl_get_item_data (EggToolbarsModel *eggmodel,
+ const char *type,
+ const char *id)
{
- if (gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE) == type)
+ EphyBookmarksBarModel *model = EPHY_BOOKMARKSBAR_MODEL (eggmodel);
+ EphyNode *node;
+
+ if (strcmp (type, EPHY_DND_TOPIC_TYPE) == 0)
{
- return g_strdup (EPHY_DND_TOPIC_TYPE);
+ char *uri;
+
+ node = ephy_bookmarksbar_model_get_node (model, id);
+ g_return_val_if_fail (node != NULL, NULL);
+
+ uri = ephy_bookmarks_get_topic_uri
+ (model->priv->bookmarks, node);
+
+ return uri;
}
- else if (gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE) == type)
+ else if (strcmp (type, EPHY_DND_URL_TYPE) == 0)
{
- return g_strdup (EPHY_DND_URL_TYPE);
+ const char *name;
+
+ node = ephy_bookmarksbar_model_get_node (model, id);
+ g_return_val_if_fail (node != NULL, NULL);
+
+ name = ephy_node_get_property_string
+ (node, EPHY_NODE_BMK_PROP_LOCATION);
+
+ return g_strdup (name);
}
- return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_type (model, type);
+ return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_data (eggmodel, type, id);
}
static void
@@ -527,6 +500,9 @@ ephy_bookmarksbar_model_finalize (GObject *object)
model->priv->timeout = 0;
}
+ /* FIXME: instead of saving on exit, we should detect when items data changes */
+ save_changes_idle (model);
+
g_free (model->priv->xml_file);
G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -572,9 +548,9 @@ ephy_bookmarksbar_model_class_init (EphyBookmarksBarModelClass *klass)
object_class->set_property = ephy_bookmarksbar_model_set_property;
object_class->get_property = ephy_bookmarksbar_model_get_property;
- eggclass->get_item_name = impl_get_item_name;
- eggclass->get_item_id = impl_get_item_id;
eggclass->get_item_type = impl_get_item_type;
+ eggclass->get_item_id = impl_get_item_id;
+ eggclass->get_item_data = impl_get_item_data;
g_object_class_install_property (object_class,
PROP_BOOKMARKS,
diff --git a/src/bookmarks/ephy-bookmarksbar-model.h b/src/bookmarks/ephy-bookmarksbar-model.h
index ac39f9325..41c7efef3 100755
--- a/src/bookmarks/ephy-bookmarksbar-model.h
+++ b/src/bookmarks/ephy-bookmarksbar-model.h
@@ -51,25 +51,25 @@ struct EphyBookmarksBarModelClass
EggToolbarsModelClass parent_class;
};
-GType ephy_bookmarksbar_model_get_type (void);
+GType ephy_bookmarksbar_model_get_type (void);
-EggToolbarsModel *ephy_bookmarksbar_model_new (EphyBookmarks *bookmarks);
+EggToolbarsModel *ephy_bookmarksbar_model_new (EphyBookmarks *bookmarks);
-char *ephy_bookmarksbar_model_get_action_name (EphyBookmarksBarModel *model,
- long id);
+char *ephy_bookmarksbar_model_get_action_name (EphyBookmarksBarModel *model,
+ long id);
-EphyNode *ephy_bookmarksbar_model_get_node (EphyBookmarksBarModel *model,
- const char *action_name);
+EphyNode *ephy_bookmarksbar_model_get_node (EphyBookmarksBarModel *model,
+ const char *action_name);
-void ephy_bookmarksbar_model_add_bookmark (EphyBookmarksBarModel *model,
- gboolean topic,
- long id);
+void ephy_bookmarksbar_model_add_bookmark (EphyBookmarksBarModel *model,
+ gboolean topic,
+ long id);
-void ephy_bookmarksbar_model_remove_bookmark (EphyBookmarksBarModel *model,
- long id);
+void ephy_bookmarksbar_model_remove_bookmark (EphyBookmarksBarModel *model,
+ long id);
-gboolean ephy_bookmarksbar_model_has_bookmark (EphyBookmarksBarModel *model,
- long id);
+gboolean ephy_bookmarksbar_model_has_bookmark (EphyBookmarksBarModel *model,
+ long id);
G_END_DECLS
diff --git a/src/bookmarks/ephy-bookmarksbar.c b/src/bookmarks/ephy-bookmarksbar.c
index 144d7c25e..511b635fa 100644
--- a/src/bookmarks/ephy-bookmarksbar.c
+++ b/src/bookmarks/ephy-bookmarksbar.c
@@ -42,9 +42,8 @@
static GtkTargetEntry drag_targets[] =
{
- { EGG_TOOLBAR_ITEM_TYPE, 0, 0 },
- { EPHY_DND_TOPIC_TYPE, 0, 1 },
- { EPHY_DND_URL_TYPE, 0, 2 }
+ { EPHY_DND_TOPIC_TYPE, 0, 0 },
+ { EPHY_DND_URL_TYPE, 0, 1 }
};
static int n_drag_targets = G_N_ELEMENTS (drag_targets);
@@ -145,30 +144,73 @@ go_location_cb (GtkAction *action,
}
}
+static gboolean
+remove_action_from_model (EggToolbarsModel *model, const char *name)
+{
+ int n_toolbars, n_items, t, i;
+
+ n_toolbars = egg_toolbars_model_n_toolbars (model);
+
+ for (t = 0; t < n_toolbars; t++)
+ {
+ n_items = egg_toolbars_model_n_items (model, t);
+
+ for (i = 0; i < n_items; i++)
+ {
+ const char *i_name;
+ gboolean is_separator;
+
+ egg_toolbars_model_item_nth (model, t , i, &is_separator,
+ &i_name, NULL);
+ g_return_val_if_fail (i_name != NULL, FALSE);
+
+ if (strcmp (i_name, name) == 0)
+ {
+ egg_toolbars_model_remove_item (model, t, i);
+
+ if (!remove_action_from_model (model, name))
+ {
+ return FALSE;
+ }
+ }
+ }
+ }
+
+ return FALSE;
+}
+
static void
bookmark_destroy_cb (EphyNode *node,
EphyBookmarksBar *toolbar)
{
+ EggToolbarsModel *model;
GtkAction *action;
char *name;
long id;
+
+ model = toolbar->priv->toolbars_model;
id = ephy_node_get_id (node);
name = ephy_bookmarksbar_model_get_action_name
- (EPHY_BOOKMARKSBAR_MODEL (toolbar->priv->toolbars_model),
- id);
+ (EPHY_BOOKMARKSBAR_MODEL (model), id);
+ remove_action_from_model (model, name);
- action = gtk_action_group_get_action (toolbar->priv->action_group, name);
- g_return_if_fail (action != NULL);
+ model = EGG_TOOLBARS_MODEL (ephy_shell_get_toolbars_model
+ (ephy_shell, FALSE));
+ remove_action_from_model (model, name);
- gtk_action_group_remove_action (toolbar->priv->action_group, action);
+ action = gtk_action_group_get_action (toolbar->priv->action_group, name);
+ if (action)
+ {
+ gtk_action_group_remove_action (toolbar->priv->action_group, action);
+ }
g_free (name);
}
static void
ephy_bookmarksbar_action_request (EggEditableToolbar *eggtoolbar,
- const char *name)
+ const char *name)
{
EphyBookmarksBar *toolbar = EPHY_BOOKMARKSBAR (eggtoolbar);
GtkAction *action = NULL;