aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@it.gnome.org>2003-07-27 21:10:56 +0800
committerMarco Pesenti Gritti <mpeseng@src.gnome.org>2003-07-27 21:10:56 +0800
commitd1f38adb951f506e11864f0784f325a940a3d232 (patch)
treed58f9243e7c3926ac2840edb05797fbbe75e1de6 /src
parente9f8e15bf4f624f566eb0ea66e47be67098d5dc2 (diff)
downloadgsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar
gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.gz
gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.bz2
gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.lz
gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.xz
gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.zst
gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.zip
2003-07-27 Marco Pesenti Gritti <marco@it.gnome.org>
* data/ui/epiphany-toolbar.xml.in: * lib/egg/egg-editable-toolbar.c: (drag_data_received_cb): * lib/egg/egg-editable-toolbar.h: * lib/egg/egg-toolbar-editor.c: (parse_item_list): * lib/egg/egg-toolbars-model.c: (egg_toolbars_model_to_xml), (safe_save_xml), (egg_toolbars_model_save), (toolbars_item_new), (free_item_node), (egg_toolbars_model_add_separator), (egg_toolbars_model_add_item), (parse_item_list), (impl_get_item_id), (impl_get_item_name), (impl_get_item_type), (egg_toolbars_model_class_init), (egg_toolbars_model_item_nth), (egg_toolbars_model_toolbar_nth), (egg_toolbars_model_get_item_id), (egg_toolbars_model_get_item_name), (egg_toolbars_model_get_item_type): * lib/egg/egg-toolbars-model.h: * lib/egg/eggtoolbar.c: (egg_toolbar_finalize): * lib/ephy-dnd.c: (add_one_topic), (ephy_dnd_drag_data_get): * lib/ephy-dnd.h: * lib/widgets/ephy-node-view.c: (drag_data_received_cb), (ephy_node_view_select_node_by_key), (ephy_node_view_construct), (ephy_node_view_add_data_column), (ephy_node_view_enable_drag_source): * lib/widgets/ephy-node-view.h: * lib/widgets/ephy-tree-model-sort.c: (ephy_tree_model_sort_class_init), (ephy_tree_model_sort_init), (ephy_tree_model_sort_multi_row_draggable), (ephy_tree_model_sort_set_column_id), (each_property_get_data_binder), (ephy_tree_model_sort_multi_drag_data_get): * lib/widgets/ephy-tree-model-sort.h: * src/bookmarks/ephy-bookmark-properties.c: (toolbar_checkbox_changed_cb), (build_ui): * src/bookmarks/ephy-bookmarks-editor.c: (cmd_show_in_bookmarks_bar), (ephy_bookmarks_editor_update_menu), (node_dropped_cb), (provide_keyword_uri), (ephy_bookmarks_editor_construct): * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_init_defaults), (ephy_bookmarks_remove_keyword), (ephy_bookmarks_get_topic_uri), (ephy_bookmarks_find_keyword): * src/bookmarks/ephy-bookmarks.h: * src/ephy-history-window.c: (ephy_history_window_construct): * src/ephy-toolbars-model.c: (ephy_toolbars_model_get_action_name), (ephy_toolbars_model_get_node), (bookmark_destroy_cb), (impl_get_item_name), (impl_get_item_id), (impl_get_item_type), (connect_item), (ephy_toolbars_model_set_bookmarks), (ephy_toolbars_model_class_init), (save_changes), (item_added), (item_removed), (toolbar_added), (toolbar_removed), (ephy_toolbars_model_init), (ephy_toolbars_model_finalize), (ephy_toolbars_model_remove_bookmark),
Diffstat (limited to 'src')
-rw-r--r--src/bookmarks/ephy-bookmark-properties.c4
-rw-r--r--src/bookmarks/ephy-bookmarks-editor.c52
-rw-r--r--src/bookmarks/ephy-bookmarks.c72
-rw-r--r--src/bookmarks/ephy-bookmarks.h3
-rw-r--r--src/ephy-history-window.c19
-rwxr-xr-xsrc/ephy-toolbars-model.c293
-rwxr-xr-xsrc/ephy-toolbars-model.h9
-rwxr-xr-xsrc/toolbar.c100
8 files changed, 272 insertions, 280 deletions
diff --git a/src/bookmarks/ephy-bookmark-properties.c b/src/bookmarks/ephy-bookmark-properties.c
index 9fda1cfea..050fa21cc 100644
--- a/src/bookmarks/ephy-bookmark-properties.c
+++ b/src/bookmarks/ephy-bookmark-properties.c
@@ -285,7 +285,7 @@ toolbar_checkbox_changed_cb (GtkWidget *checkbox, EphyBookmarkProperties *props)
else
{
ephy_toolbars_model_remove_bookmark
- (props->priv->tb_model, FALSE, id);
+ (props->priv->tb_model, id);
}
}
@@ -418,7 +418,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, FALSE, id);
+ state = ephy_toolbars_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);
diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c
index 900e576ba..2556fdd99 100644
--- a/src/bookmarks/ephy-bookmarks-editor.c
+++ b/src/bookmarks/ephy-bookmarks-editor.c
@@ -32,6 +32,7 @@
#include <gdk/gdkkeysyms.h>
#include <bonobo/bonobo-i18n.h>
#include <libgnomeui/gnome-stock-icons.h>
+#include <libgnomevfs/gnome-vfs-uri.h>
#include <string.h>
#include "ephy-bookmarks-editor.h"
@@ -60,7 +61,7 @@
static GtkTargetEntry topic_drag_dest_types [] =
{
- { EPHY_DND_BOOKMARK_TYPE, 0, 0 }
+ { EPHY_DND_URI_LIST_TYPE, 0, 0 }
};
static int n_topic_drag_dest_types = G_N_ELEMENTS (topic_drag_dest_types);
@@ -69,8 +70,7 @@ static GtkTargetEntry bmk_drag_types [] =
{
{ EPHY_DND_URI_LIST_TYPE, 0, 0 },
{ EPHY_DND_TEXT_TYPE, 0, 1 },
- { EPHY_DND_URL_TYPE, 0, 2 },
- { EPHY_DND_BOOKMARK_TYPE, 0, 3 }
+ { EPHY_DND_URL_TYPE, 0, 2 }
};
static int n_bmk_drag_types = G_N_ELEMENTS (bmk_drag_types);
@@ -334,7 +334,7 @@ cmd_show_in_bookmarks_bar (EggAction *action,
else
{
ephy_toolbars_model_remove_bookmark
- (editor->priv->tb_model, topic, id);
+ (editor->priv->tb_model, id);
}
g_list_free (selection);
@@ -827,7 +827,7 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor)
id = ephy_node_get_id (node);
show_in_bookmarks_bar = ephy_toolbars_model_has_bookmark
- (editor->priv->tb_model, TRUE, id);
+ (editor->priv->tb_model, id);
priority = ephy_node_get_property_int
(node, EPHY_NODE_KEYWORD_PROP_PRIORITY);
@@ -847,7 +847,7 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor)
id = ephy_node_get_id (node);
show_in_bookmarks_bar = ephy_toolbars_model_has_bookmark
- (editor->priv->tb_model, FALSE, id);
+ (editor->priv->tb_model, id);
g_list_free (selected);
}
@@ -1150,9 +1150,18 @@ node_dropped_cb (EphyNodeView *view, EphyNode *node,
for (l = nodes; l != NULL; l = l->next)
{
- EphyNode *bmk = l->data;
+ GnomeVFSURI *uri = l->data;
+ char *url;
+ EphyNode *bmk;
+
+ url = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
+ bmk = ephy_bookmarks_find_bookmark (editor->priv->bookmarks, url);
+ g_free (url);
- ephy_bookmarks_set_keyword (editor->priv->bookmarks, node, bmk);
+ if (bmk)
+ {
+ ephy_bookmarks_set_keyword (editor->priv->bookmarks, node, bmk);
+ }
}
}
@@ -1186,6 +1195,19 @@ view_selection_changed_cb (GtkWidget *view, EphyBookmarksEditor *editor)
}
static void
+provide_keyword_uri (EphyNode *node, GValue *value, gpointer data)
+{
+ EphyBookmarks *bookmarks = EPHY_BOOKMARKS_EDITOR (data)->priv->bookmarks;
+ char *uri;
+
+ uri = ephy_bookmarks_get_topic_uri (bookmarks, node);
+
+ g_value_init (value, G_TYPE_STRING);
+ g_value_set_string (value, uri);
+ g_free (uri);
+}
+
+static void
ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor)
{
GtkTreeSelection *selection;
@@ -1197,7 +1219,7 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor)
EggActionGroup *action_group;
EggAction *action;
GdkPixbuf *icon;
- int i;
+ int i, col_id;
gtk_window_set_title (GTK_WINDOW (editor), _("Bookmarks"));
@@ -1260,10 +1282,12 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor)
/* Keywords View */
key_view = ephy_node_view_new (node, NULL);
add_focus_monitor (editor, key_view);
+ col_id = ephy_node_view_add_data_column (EPHY_NODE_VIEW (key_view),
+ G_TYPE_STRING, -1,
+ provide_keyword_uri, editor);
ephy_node_view_enable_drag_source (EPHY_NODE_VIEW (key_view),
topic_drag_types,
- n_topic_drag_types,
- -1);
+ n_topic_drag_types, col_id);
ephy_node_view_enable_drag_dest (EPHY_NODE_VIEW (key_view),
topic_drag_dest_types,
n_topic_drag_dest_types);
@@ -1326,10 +1350,14 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor)
/* Bookmarks View */
bm_view = ephy_node_view_new (node, editor->priv->bookmarks_filter);
add_focus_monitor (editor, bm_view);
+ col_id = ephy_node_view_add_data_column (EPHY_NODE_VIEW (bm_view),
+ G_TYPE_STRING,
+ EPHY_NODE_BMK_PROP_LOCATION,
+ NULL, NULL);
ephy_node_view_enable_drag_source (EPHY_NODE_VIEW (bm_view),
bmk_drag_types,
n_bmk_drag_types,
- EPHY_NODE_BMK_PROP_LOCATION);
+ col_id);
ephy_node_view_add_column (EPHY_NODE_VIEW (bm_view), _("Title"),
G_TYPE_STRING, EPHY_NODE_BMK_PROP_TITLE, -1,
EPHY_NODE_VIEW_AUTO_SORT |
diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c
index 187efc9be..2ba82aa78 100644
--- a/src/bookmarks/ephy-bookmarks.c
+++ b/src/bookmarks/ephy-bookmarks.c
@@ -210,8 +210,7 @@ ephy_bookmarks_autocompletion_source_init (EphyAutocompletionSourceIface *iface)
static void
ephy_bookmarks_init_defaults (EphyBookmarks *eb)
{
- int i, id;
- EphyNode *node;
+ int i;
for (i = 0; i < n_default_topics; i++)
{
@@ -220,13 +219,12 @@ ephy_bookmarks_init_defaults (EphyBookmarks *eb)
for (i = 0; i < n_default_bookmarks; i++)
{
- ephy_bookmarks_add (eb, default_bookmarks[i].title,
- default_bookmarks[i].location);
+ EphyNode *bmk;
- 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 (eb->priv->toolbars_model, FALSE, id);
+ 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));
}
}
@@ -1119,13 +1117,44 @@ ephy_bookmarks_add_keyword (EphyBookmarks *eb,
return key;
}
-void
+void
ephy_bookmarks_remove_keyword (EphyBookmarks *eb,
- EphyNode *keyword)
+ EphyNode *keyword)
{
ephy_node_remove_child (eb->priv->keywords, keyword);
}
+char *
+ephy_bookmarks_get_topic_uri (EphyBookmarks *eb,
+ EphyNode *node)
+{
+ char *uri;
+
+ if (ephy_bookmarks_get_bookmarks (eb) == node)
+ {
+ uri = g_strdup ("topic://Special/All");
+ }
+ else if (ephy_bookmarks_get_not_categorized (eb) == node)
+ {
+ uri = g_strdup ("topic://Special/NotCategorized");
+ }
+ else if (ephy_bookmarks_get_favorites (eb) == node)
+ {
+ uri = g_strdup ("topic://Special/Favorites");
+ }
+ else
+ {
+ const char *name;
+
+ name = ephy_node_get_property_string
+ (node, EPHY_NODE_KEYWORD_PROP_NAME);
+
+ uri = g_strdup_printf ("topic://%s", name);
+ }
+
+ return uri;
+}
+
EphyNode *
ephy_bookmarks_find_keyword (EphyBookmarks *eb,
const char *name,
@@ -1134,9 +1163,11 @@ ephy_bookmarks_find_keyword (EphyBookmarks *eb,
EphyNode *node;
GPtrArray *children;
int i;
+ const char *topic_name;
g_return_val_if_fail (name != NULL, NULL);
+ topic_name = name;
if (g_utf8_strlen (name, -1) == 0)
{
@@ -1144,6 +1175,23 @@ ephy_bookmarks_find_keyword (EphyBookmarks *eb,
return NULL;
}
+ if (strcmp (name, "topic://Special/All") == 0)
+ {
+ return ephy_bookmarks_get_bookmarks (eb);
+ }
+ else if (strcmp (name, "topic://Special/NotCategorized") == 0)
+ {
+ return ephy_bookmarks_get_not_categorized (eb);
+ }
+ else if (strcmp (name, "topic://Special/Favorites") == 0)
+ {
+ return ephy_bookmarks_get_favorites (eb);
+ }
+ else if (g_str_has_prefix (name, "topic://"))
+ {
+ topic_name += strlen ("topic://");
+ }
+
children = ephy_node_get_children (eb->priv->keywords);
node = NULL;
for (i = 0; i < children->len; i++)
@@ -1154,8 +1202,8 @@ ephy_bookmarks_find_keyword (EphyBookmarks *eb,
kid = g_ptr_array_index (children, i);
key = ephy_node_get_property_string (kid, EPHY_NODE_KEYWORD_PROP_NAME);
- if ((partial_match && g_str_has_prefix (key, name) > 0) ||
- (!partial_match && strcmp (key, name) == 0))
+ if ((partial_match && g_str_has_prefix (key, topic_name) > 0) ||
+ (!partial_match && strcmp (key, topic_name) == 0))
{
node = kid;
}
diff --git a/src/bookmarks/ephy-bookmarks.h b/src/bookmarks/ephy-bookmarks.h
index 55c03bca0..962326d24 100644
--- a/src/bookmarks/ephy-bookmarks.h
+++ b/src/bookmarks/ephy-bookmarks.h
@@ -112,6 +112,9 @@ void ephy_bookmarks_unset_keyword (EphyBookmarks *eb,
EphyNode *keyword,
EphyNode *bookmark);
+char *ephy_bookmarks_get_topic_uri (EphyBookmarks *eb,
+ EphyNode *node);
+
/* Favorites */
EphyNode *ephy_bookmarks_get_favorites (EphyBookmarks *eb);
diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c
index bbd8a6190..6ef64dea8 100644
--- a/src/ephy-history-window.c
+++ b/src/ephy-history-window.c
@@ -57,8 +57,7 @@ static GtkTargetEntry page_drag_types [] =
{
{ EPHY_DND_URI_LIST_TYPE, 0, 0 },
{ EPHY_DND_TEXT_TYPE, 0, 1 },
- { EPHY_DND_URL_TYPE, 0, 2 },
- { EPHY_DND_BOOKMARK_TYPE, 0, 3 }
+ { EPHY_DND_URL_TYPE, 0, 2 }
};
static int n_page_drag_types = G_N_ELEMENTS (page_drag_types);
@@ -955,7 +954,7 @@ ephy_history_window_construct (EphyHistoryWindow *editor)
EggActionGroup *action_group;
EggAction *action;
GdkPixbuf *icon;
- int i;
+ int i, col_id;
gtk_window_set_title (GTK_WINDOW (editor), _("History"));
@@ -1016,12 +1015,15 @@ ephy_history_window_construct (EphyHistoryWindow *editor)
gtk_widget_show (scrolled_window);
sites_view = ephy_node_view_new (node, NULL);
add_focus_monitor (editor, sites_view);
+ col_id = ephy_node_view_add_data_column (EPHY_NODE_VIEW (sites_view),
+ G_TYPE_STRING,
+ EPHY_NODE_PAGE_PROP_LOCATION,
+ NULL, NULL);
ephy_node_view_select_node (EPHY_NODE_VIEW (sites_view),
ephy_history_get_pages (editor->priv->history));
ephy_node_view_enable_drag_source (EPHY_NODE_VIEW (sites_view),
page_drag_types,
- n_page_drag_types,
- EPHY_NODE_PAGE_PROP_LOCATION);
+ n_page_drag_types, col_id);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sites_view));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
ephy_node_view_add_column (EPHY_NODE_VIEW (sites_view), _("Sites"),
@@ -1067,10 +1069,13 @@ ephy_history_window_construct (EphyHistoryWindow *editor)
add_focus_monitor (editor, pages_view);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (pages_view));
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (pages_view), TRUE);
+ col_id = ephy_node_view_add_data_column (EPHY_NODE_VIEW (pages_view),
+ G_TYPE_STRING,
+ EPHY_NODE_PAGE_PROP_LOCATION,
+ NULL, NULL);
ephy_node_view_enable_drag_source (EPHY_NODE_VIEW (pages_view),
page_drag_types,
- n_page_drag_types,
- EPHY_NODE_PAGE_PROP_LOCATION);
+ n_page_drag_types, col_id);
col = ephy_node_view_add_column (EPHY_NODE_VIEW (pages_view), _("Title"),
G_TYPE_STRING, EPHY_NODE_PAGE_PROP_TITLE,
-1, EPHY_NODE_VIEW_USER_SORT |
diff --git a/src/ephy-toolbars-model.c b/src/ephy-toolbars-model.c
index fb70e7c50..6bfce6264 100755
--- a/src/ephy-toolbars-model.c
+++ b/src/ephy-toolbars-model.c
@@ -33,10 +33,12 @@ static void ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass);
static void ephy_toolbars_model_init (EphyToolbarsModel *t);
static void ephy_toolbars_model_finalize (GObject *object);
+#define EPHY_TOOLBARS_XML_VERSION "1.0"
+
enum
{
- ACTION_ADDED,
- LAST_SIGNAL
+ ACTION_ADDED,
+ LAST_SIGNAL
};
enum
@@ -57,6 +59,7 @@ struct EphyToolbarsModelPrivate
{
EphyBookmarks *bookmarks;
char *xml_file;
+ gboolean loading;
};
GType
@@ -88,50 +91,24 @@ ephy_toolbars_model_get_type (void)
char *
ephy_toolbars_model_get_action_name (EphyToolbarsModel *model,
- gboolean topic, long id)
+ long id)
{
- char *action_name;
- const char *name;
- EphyNode *node;
- EphyNodePriority priority;
-
- node = ephy_bookmarks_get_from_id (model->priv->bookmarks, id);
- g_return_val_if_fail (node != NULL, NULL);
+ return g_strdup_printf ("GoBookmark-%ld", id);
+}
- priority = ephy_node_get_property_int
- (node, EPHY_NODE_KEYWORD_PROP_PRIORITY);
+EphyNode *
+ephy_toolbars_model_get_node (EphyToolbarsModel *model,
+ const char *action_name)
+{
+ EphyBookmarks *bookmarks = EPHY_TOOLBARS_MODEL (model)->priv->bookmarks;
+ long node_id;
- if (topic)
- {
- if (priority != EPHY_NODE_NORMAL_PRIORITY)
- {
- action_name = g_strdup_printf ("GoSpecialTopic-%ld", id);
- }
- else
- {
- name = ephy_node_get_property_string
- (node, EPHY_NODE_KEYWORD_PROP_NAME);
- action_name = g_strdup_printf ("GoTopic-%s", name);
- }
- }
- else
+ if (!ephy_string_to_int (action_name + strlen ("GoBookmark-"), &node_id))
{
- name = ephy_node_get_property_string
- (node, EPHY_NODE_BMK_PROP_LOCATION);
- action_name = g_strdup_printf ("GoBookmark-%s", name);
+ return NULL;
}
- return action_name;
-}
-
-static void
-topic_destroy_cb (EphyNode *node,
- EphyToolbarsModel *model)
-{
- long id;
-
- id = ephy_node_get_id (node);
- ephy_toolbars_model_remove_bookmark (model, TRUE, id);
+ return ephy_bookmarks_get_from_id (bookmarks, node_id);
}
static void
@@ -141,118 +118,69 @@ bookmark_destroy_cb (EphyNode *node,
long id;
id = ephy_node_get_id (node);
- ephy_toolbars_model_remove_bookmark (model, FALSE, id);
+ ephy_toolbars_model_remove_bookmark (model, id);
}
-static gboolean
-setup_item (EphyToolbarsModel *model,
- const char *name,
- gboolean *is_bookmark,
- gboolean *is_topic,
- long *id)
+static char *
+impl_get_item_name (EggToolbarsModel *t,
+ const char *type,
+ const char *id)
{
- EphyBookmarks *bookmarks = model->priv->bookmarks;
- EphyNode *node = NULL;
-
- *is_topic = FALSE;
+ EphyToolbarsModel *model = EPHY_TOOLBARS_MODEL (t);
+ EphyNode *node;
- if (g_str_has_prefix (name, "GoBookmark-"))
+ if (strcmp (type, EPHY_DND_TOPIC_TYPE) == 0)
{
- node = ephy_bookmarks_find_bookmark
- (bookmarks, name + strlen ("GoBookmark-"));
- if (node == NULL) return FALSE;
+ char *uri;
- ephy_node_signal_connect_object (node,
- EPHY_NODE_DESTROY,
- (EphyNodeCallback) bookmark_destroy_cb,
- G_OBJECT (model));
- }
- else if (g_str_has_prefix (name, "GoTopic-"))
- {
- EphyNode *node;
+ node = ephy_toolbars_model_get_node (model, id);
+ g_return_val_if_fail (node != NULL, NULL);
- node = ephy_bookmarks_find_keyword
- (bookmarks, name + strlen ("GoTopic-"), FALSE);
- if (node == NULL) return FALSE;
+ uri = ephy_bookmarks_get_topic_uri
+ (model->priv->bookmarks, node);
- ephy_node_signal_connect_object (node,
- EPHY_NODE_DESTROY,
- (EphyNodeCallback) topic_destroy_cb,
- G_OBJECT (model));
- *is_topic = TRUE;
+ return uri;
}
- else if (g_str_has_prefix (name, "GoSpecialTopic-"))
+ else if (strcmp (type, EPHY_DND_URL_TYPE) == 0)
{
- EphyNode *node;
- long id;
-
- if (!ephy_string_to_int (name + strlen ("GoSpecialTopic-"), &id))
- {
- return FALSE;
- }
+ const char *name;
- node = ephy_bookmarks_get_from_id (bookmarks, id);
- if (node == NULL) return FALSE;
+ node = ephy_toolbars_model_get_node (model, id);
+ g_return_val_if_fail (node != NULL, NULL);
- ephy_node_signal_connect_object (node,
- EPHY_NODE_DESTROY,
- (EphyNodeCallback) topic_destroy_cb,
- G_OBJECT (model));
-
- *is_topic = TRUE;
- }
+ name = ephy_node_get_property_string
+ (node, EPHY_NODE_BMK_PROP_LOCATION);
- if (node)
- {
- *is_bookmark = TRUE;
- *id = ephy_node_get_id (node);
+ return g_strdup (name);
}
- return TRUE;
+ return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_name (t, type, id);
}
-static const char *
-impl_add_item (EggToolbarsModel *t,
- int toolbar_position,
- int position,
- GdkAtom type,
- const char *name)
+static char *
+impl_get_item_id (EggToolbarsModel *t,
+ const char *type,
+ const char *name)
{
- char *action_name = NULL;
- const char *res;
- gboolean valid, duped_bookmark = FALSE, is_bookmark, is_topic;
- long id = -1;
-
- LOG ("Add item %s", name)
+ EphyToolbarsModel *model = EPHY_TOOLBARS_MODEL (t);
+ EphyBookmarks *bookmarks = model->priv->bookmarks;
- if (gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE) == type)
+ if (strcmp (type, EPHY_DND_TOPIC_TYPE) == 0)
{
- GList *nodes;
+ EphyNode *topic;
- nodes = ephy_dnd_node_list_extract_nodes (name);
- id = ephy_node_get_id (nodes->data);
- action_name = ephy_toolbars_model_get_action_name
- (EPHY_TOOLBARS_MODEL (t), TRUE, id);
- g_list_free (nodes);
- }
- else if (gdk_atom_intern (EPHY_DND_BOOKMARK_TYPE, FALSE) == type)
- {
- GList *nodes;
+ topic = ephy_bookmarks_find_keyword (bookmarks, name, FALSE);
+ if (topic == NULL) return NULL;
- nodes = ephy_dnd_node_list_extract_nodes (name);
- id = ephy_node_get_id (nodes->data);
- action_name = ephy_toolbars_model_get_action_name
- (EPHY_TOOLBARS_MODEL (t), FALSE, id);
- g_list_free (nodes);
+ return ephy_toolbars_model_get_action_name
+ (model, ephy_node_get_id (topic));
}
- else if (gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE) == type)
+ else if (strcmp (type, EPHY_DND_URL_TYPE) == 0)
{
EphyNode *node = NULL;
- EphyBookmarks *bookmarks;
gchar **netscape_url;
netscape_url = g_strsplit (name, "\n", 2);
- bookmarks = ephy_shell_get_bookmarks (ephy_shell);
node = ephy_bookmarks_find_bookmark (bookmarks, netscape_url[URL]);
if (!node)
@@ -273,34 +201,49 @@ impl_add_item (EggToolbarsModel *t,
}
}
- id = ephy_node_get_id (node);
- action_name = ephy_toolbars_model_get_action_name
- (EPHY_TOOLBARS_MODEL (t), FALSE, id);
g_strfreev (netscape_url);
+
+ g_return_val_if_fail (node != NULL, NULL);
+
+ return ephy_toolbars_model_get_action_name
+ (model, ephy_node_get_id (node));
}
- res = action_name ? action_name : name;
+ return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_id (t, type, name);
+}
- valid = setup_item (EPHY_TOOLBARS_MODEL (t), res, &is_bookmark, &is_topic, &id);
- if (!valid)
+static char *
+impl_get_item_type (EggToolbarsModel *t,
+ GdkAtom type)
+{
+ if (gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE) == type)
{
- g_warning ("Invalid bookmark in the toolbar. Removed.");
- return NULL;
+ return g_strdup (EPHY_DND_TOPIC_TYPE);
}
-
- if (is_bookmark)
+ else if (gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE) == type)
{
- duped_bookmark = ephy_toolbars_model_has_bookmark
- (EPHY_TOOLBARS_MODEL (t), is_topic, id);
+ return g_strdup (EPHY_DND_URL_TYPE);
}
- if (!duped_bookmark)
+ return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_type (t, type);
+}
+
+static void
+connect_item (EphyToolbarsModel *model,
+ const char *name)
+{
+ EphyNode *node;
+
+ if (g_str_has_prefix (name, "GoBookmark-"))
{
- EGG_TOOLBARS_MODEL_CLASS (parent_class)->add_item
- (t, toolbar_position, position, type, res);
- }
+ node = ephy_toolbars_model_get_node (model, name);
+ g_return_if_fail (node != NULL);
- return res;
+ ephy_node_signal_connect_object (node,
+ EPHY_NODE_DESTROY,
+ (EphyNodeCallback) bookmark_destroy_cb,
+ G_OBJECT (model));
+ }
}
static void
@@ -311,6 +254,8 @@ ephy_toolbars_model_set_bookmarks (EphyToolbarsModel *model, EphyBookmarks *book
model->priv->bookmarks = bookmarks;
g_object_ref (model->priv->bookmarks);
+ model->priv->loading = TRUE;
+
if (g_file_test (model->priv->xml_file, G_FILE_TEST_EXISTS))
{
egg_toolbars_model_load (egg_model,
@@ -323,6 +268,8 @@ ephy_toolbars_model_set_bookmarks (EphyToolbarsModel *model, EphyBookmarks *book
default_xml = ephy_file ("epiphany-toolbar.xml");
egg_toolbars_model_load (egg_model, default_xml);
}
+
+ model->priv->loading = FALSE;
}
static void
@@ -375,7 +322,9 @@ ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass)
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;
+ etm_class->get_item_id = impl_get_item_id;
+ etm_class->get_item_name = impl_get_item_name;
+ etm_class->get_item_type = impl_get_item_type;
g_object_class_install_property (object_class,
PROP_BOOKMARKS,
@@ -387,31 +336,49 @@ ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass)
}
static void
+save_changes (EphyToolbarsModel *model)
+{
+ if (!model->priv->loading)
+ {
+ egg_toolbars_model_save (EGG_TOOLBARS_MODEL (model),
+ model->priv->xml_file,
+ EPHY_TOOLBARS_XML_VERSION);
+ }
+}
+
+static void
item_added (EphyToolbarsModel *model, int toolbar_position, int position)
{
- egg_toolbars_model_save (EGG_TOOLBARS_MODEL (model),
- model->priv->xml_file);
+ const char *i_name;
+ gboolean is_separator;
+
+ i_name = egg_toolbars_model_item_nth
+ (EGG_TOOLBARS_MODEL (model), toolbar_position,
+ position, &is_separator);
+ if (!is_separator)
+ {
+ connect_item (model, i_name);
+ }
+
+ save_changes (model);
}
static void
item_removed (EphyToolbarsModel *model, int toolbar_position, int position)
{
- egg_toolbars_model_save (EGG_TOOLBARS_MODEL (model),
- model->priv->xml_file);
+ save_changes (model);
}
static void
toolbar_added (EphyToolbarsModel *model, int position)
{
- egg_toolbars_model_save (EGG_TOOLBARS_MODEL (model),
- model->priv->xml_file);
+ save_changes (model);
}
static void
toolbar_removed (EphyToolbarsModel *model, int position)
{
- egg_toolbars_model_save (EGG_TOOLBARS_MODEL (model),
- model->priv->xml_file);
+ save_changes (model);
}
static void
@@ -419,9 +386,9 @@ ephy_toolbars_model_init (EphyToolbarsModel *t)
{
t->priv = g_new0 (EphyToolbarsModelPrivate, 1);
t->priv->bookmarks = NULL;
-
+ t->priv->loading = FALSE;
t->priv->xml_file = g_build_filename (ephy_dot_dir (),
- "ephy-toolbars.xml",
+ "epiphany-toolbars.xml",
NULL);
g_signal_connect (t, "item_added", G_CALLBACK (item_added), NULL);
@@ -438,6 +405,8 @@ ephy_toolbars_model_finalize (GObject *object)
g_return_if_fail (object != NULL);
g_return_if_fail (IS_EPHY_TOOLBARS_MODEL (object));
+ save_changes (t);
+
g_object_unref (t->priv->bookmarks);
g_free (t->priv->xml_file);
@@ -526,13 +495,12 @@ get_toolbar_and_item_pos (EphyToolbarsModel *model,
void
ephy_toolbars_model_remove_bookmark (EphyToolbarsModel *model,
- gboolean topic,
long id)
{
char *action_name;
int toolbar, position;
- action_name = ephy_toolbars_model_get_action_name (model, topic, id);
+ action_name = ephy_toolbars_model_get_action_name (model, id);
g_return_if_fail (action_name != NULL);
if (get_toolbar_and_item_pos (model, action_name, &toolbar, &position))
@@ -549,32 +517,29 @@ ephy_toolbars_model_add_bookmark (EphyToolbarsModel *model,
gboolean topic,
long id)
{
- char *action_name;
+ char *name;
int toolbar_position;
- action_name = ephy_toolbars_model_get_action_name (model, topic, id);
- g_return_if_fail (action_name != NULL);
-
toolbar_position = get_toolbar_pos (model, "BookmarksBar");
g_return_if_fail (toolbar_position != -1);
+ name = ephy_toolbars_model_get_action_name (model, id);
egg_toolbars_model_add_item (EGG_TOOLBARS_MODEL (model),
- toolbar_position, -1,
- 0, action_name);
-
- g_free (action_name);
+ toolbar_position, -1, name,
+ topic ? EPHY_DND_TOPIC_TYPE :
+ EPHY_DND_URL_TYPE);
+ g_free (name);
}
gboolean
ephy_toolbars_model_has_bookmark (EphyToolbarsModel *model,
- gboolean topic,
long id)
{
char *action_name;
gboolean found;
int toolbar, pos;
- action_name = ephy_toolbars_model_get_action_name (model, topic, id);
+ action_name = ephy_toolbars_model_get_action_name (model, id);
g_return_val_if_fail (action_name != NULL, FALSE);
found = get_toolbar_and_item_pos (model, action_name, &toolbar, &pos);
diff --git a/src/ephy-toolbars-model.h b/src/ephy-toolbars-model.h
index dd8814dc9..0261a85fb 100755
--- a/src/ephy-toolbars-model.h
+++ b/src/ephy-toolbars-model.h
@@ -52,20 +52,21 @@ GType ephy_toolbars_model_get_type (void);
EphyToolbarsModel *ephy_toolbars_model_new (EphyBookmarks *bookmarks);
void ephy_toolbars_model_add_bookmark (EphyToolbarsModel *model,
- gboolean topic,
+ gboolean topic,
long id);
gboolean ephy_toolbars_model_has_bookmark (EphyToolbarsModel *model,
- gboolean topic,
long id);
+
void ephy_toolbars_model_remove_bookmark (EphyToolbarsModel *model,
- gboolean topic,
long id);
char *ephy_toolbars_model_get_action_name (EphyToolbarsModel *model,
- gboolean topic,
long id);
+EphyNode *ephy_toolbars_model_get_node (EphyToolbarsModel *model,
+ const char *action_name);
+
void ephy_toolbars_model_set_flag (EphyToolbarsModel *model,
EggTbModelFlags flags);
diff --git a/src/toolbar.c b/src/toolbar.c
index ae6a8f13f..b57284727 100755
--- a/src/toolbar.c
+++ b/src/toolbar.c
@@ -67,8 +67,7 @@ toolbar_get_property (GObject *object,
static GtkTargetEntry drag_targets[] = {
{ EGG_TOOLBAR_ITEM_TYPE, 0, 0 },
{ EPHY_DND_TOPIC_TYPE, 0, 1 },
- { EPHY_DND_BOOKMARK_TYPE, 0, 2 },
- { EPHY_DND_URL_TYPE, 0, 3 },
+ { EPHY_DND_URL_TYPE, 0, 2 },
};
static int n_drag_targets = G_N_ELEMENTS (drag_targets);
@@ -134,29 +133,6 @@ zoom_to_level_cb (EggAction *action, float zoom, EphyWindow *window)
}
static void
-topic_destroy_cb (EphyNode *node,
- Toolbar *t)
-{
- EggAction *action;
- char *name;
- EphyToolbarsModel *model;
- long id;
-
- model = EPHY_TOOLBARS_MODEL
- (ephy_shell_get_toolbars_model (ephy_shell));
-
- id = ephy_node_get_id (node);
- name = ephy_toolbars_model_get_action_name (model, TRUE, id);
- action = egg_action_group_get_action (t->priv->action_group, name);
- if (action)
- {
- egg_action_group_remove_action (t->priv->action_group, action);
- }
-
- g_free (name);
-}
-
-static void
bookmark_destroy_cb (EphyNode *node,
Toolbar *t)
{
@@ -169,7 +145,7 @@ bookmark_destroy_cb (EphyNode *node,
(ephy_shell_get_toolbars_model (ephy_shell));
id = ephy_node_get_id (node);
- name = ephy_toolbars_model_get_action_name (model, FALSE, id);
+ name = ephy_toolbars_model_get_action_name (model, id);
action = egg_action_group_get_action (t->priv->action_group, name);
if (action)
{
@@ -184,78 +160,44 @@ toolbar_ensure_action (Toolbar *t,
const char *name)
{
EggAction *action = NULL;
+ EphyToolbarsModel *model;
EphyBookmarks *bookmarks;
+ EphyNode *bmks, *topics;
- LOG ("Ensure action %s", name)
-
+ model = EPHY_TOOLBARS_MODEL
+ (ephy_shell_get_toolbars_model (ephy_shell));
bookmarks = ephy_shell_get_bookmarks (ephy_shell);
+ bmks = ephy_bookmarks_get_bookmarks (bookmarks);
+ topics = ephy_bookmarks_get_keywords (bookmarks);
- if (g_str_has_prefix (name, "GoBookmark-"))
- {
- EphyNode *node;
-
- LOG ("Create action %s", name)
-
- node = ephy_bookmarks_find_bookmark
- (bookmarks, name + strlen ("GoBookmark-"));
- g_return_if_fail (node != NULL);
-
- action = ephy_bookmark_action_new (name, ephy_node_get_id (node));
- 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);
+ LOG ("Ensure action %s", name)
- ephy_node_signal_connect_object (node,
- EPHY_NODE_DESTROY,
- (EphyNodeCallback) bookmark_destroy_cb,
- G_OBJECT (t));
- }
- else if (g_str_has_prefix (name, "GoTopic-"))
+ if (g_str_has_prefix (name, "GoBookmark-"))
{
EphyNode *node;
- LOG ("Create action %s", name)
-
- node = ephy_bookmarks_find_keyword
- (bookmarks, name + strlen ("GoTopic-"), FALSE);
+ node = ephy_toolbars_model_get_node (model,name);
g_return_if_fail (node != NULL);
- action = ephy_topic_action_new (name, ephy_node_get_id (node));
- 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);
-
- ephy_node_signal_connect_object (node,
- EPHY_NODE_DESTROY,
- (EphyNodeCallback) topic_destroy_cb,
- G_OBJECT (t));
- }
- else if (g_str_has_prefix (name, "GoSpecialTopic-"))
- {
- EphyNode *node;
- long id;
-
- LOG ("Create action %s", name)
-
- if (!ephy_string_to_int (name + strlen ("GoSpecialTopic-"), &id))
+ if (ephy_node_has_child (topics, node))
+ {
+ action = ephy_topic_action_new (name, ephy_node_get_id (node));
+ }
+ else if (ephy_node_has_child (bmks, node))
{
- return;
+ action = ephy_bookmark_action_new (name, ephy_node_get_id (node));
}
- action = ephy_topic_action_new (name, id);
+ g_return_if_fail (action != NULL);
+
g_signal_connect (action, "go_location",
- G_CALLBACK (go_location_cb),
- t->priv->window);
+ 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) topic_destroy_cb,
+ (EphyNodeCallback) bookmark_destroy_cb,
G_OBJECT (t));
}
}