aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorXan Lopez <xan@src.gnome.org>2003-05-13 03:22:27 +0800
committerXan Lopez <xan@src.gnome.org>2003-05-13 03:22:27 +0800
commitbacb58f2fda5bef60b55500aa79e17be7aa8a384 (patch)
treec317366a2a1f6e84cdcc386257a5c68a932b0b35 /src
parent1044f92a19ab225a74e7829561cfe1733aee6913 (diff)
downloadgsoc2013-epiphany-bacb58f2fda5bef60b55500aa79e17be7aa8a384.tar
gsoc2013-epiphany-bacb58f2fda5bef60b55500aa79e17be7aa8a384.tar.gz
gsoc2013-epiphany-bacb58f2fda5bef60b55500aa79e17be7aa8a384.tar.bz2
gsoc2013-epiphany-bacb58f2fda5bef60b55500aa79e17be7aa8a384.tar.lz
gsoc2013-epiphany-bacb58f2fda5bef60b55500aa79e17be7aa8a384.tar.xz
gsoc2013-epiphany-bacb58f2fda5bef60b55500aa79e17be7aa8a384.tar.zst
gsoc2013-epiphany-bacb58f2fda5bef60b55500aa79e17be7aa8a384.zip
Don't allow to have more than one bookmark with the same URL^H^H^Haddress,
Don't allow to have more than one bookmark with the same URL^H^H^Haddress, warn the user with a nice dialog. Fixes #110854.
Diffstat (limited to 'src')
-rw-r--r--src/bookmarks/ephy-bookmarks.c33
-rw-r--r--src/bookmarks/ephy-bookmarks.h2
-rw-r--r--src/bookmarks/ephy-new-bookmark.c72
-rw-r--r--src/bookmarks/ephy-new-bookmark.h4
-rw-r--r--src/ephy-history-window.c20
-rw-r--r--src/popup-commands.c24
-rw-r--r--src/window-commands.c24
7 files changed, 132 insertions, 47 deletions
diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c
index 529ad0d5d..730caf91e 100644
--- a/src/bookmarks/ephy-bookmarks.c
+++ b/src/bookmarks/ephy-bookmarks.c
@@ -229,8 +229,8 @@ ephy_bookmarks_class_init (EphyBookmarksClass *klass)
static void
ephy_bookmarks_init_defaults (EphyBookmarks *eb)
{
- int i;
- int id;
+ int i, id;
+ EphyNode *node;
EphyToolbarsModel *model;
model = ephy_shell_get_toolbars_model (ephy_shell);
@@ -246,7 +246,9 @@ ephy_bookmarks_init_defaults (EphyBookmarks *eb)
default_bookmarks[i].location,
default_bookmarks[i].smart_url);
- id = ephy_bookmarks_get_bookmark_id (eb, default_bookmarks[i].location);
+ 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);
}
@@ -441,10 +443,8 @@ history_site_visited_cb (EphyHistory *gh, const char *url, EphyBookmarks *eb)
EphyNode *node;
guint id;
- id = ephy_bookmarks_get_bookmark_id (eb, url);
- if (id == 0) return;
-
- node = ephy_node_get_from_id (id);
+ node = ephy_bookmarks_find_bookmark (eb, url);
+ if (node == NULL) return;
if (add_to_favorites (eb, node, gh))
{
@@ -738,9 +738,9 @@ ephy_bookmarks_add (EphyBookmarks *eb,
return bm;
}
-guint
-ephy_bookmarks_get_bookmark_id (EphyBookmarks *eb,
- const char *url)
+EphyNode*
+ephy_bookmarks_find_bookmark (EphyBookmarks *eb,
+ const char *url)
{
GPtrArray *children;
int i;
@@ -757,12 +757,12 @@ ephy_bookmarks_get_bookmark_id (EphyBookmarks *eb,
if (strcmp (url, location) == 0)
{
ephy_node_thaw (eb->priv->bookmarks);
- return ephy_node_get_id (kid);
+ return kid;
}
}
ephy_node_thaw (eb->priv->bookmarks);
- return 0;
+ return NULL;
}
void
@@ -776,10 +776,8 @@ ephy_bookmarks_set_icon (EphyBookmarks *eb,
g_return_if_fail (icon != NULL);
- id = ephy_bookmarks_get_bookmark_id (eb, url);
- if (id == 0) return;
-
- node = ephy_node_get_from_id (id);
+ node = ephy_bookmarks_find_bookmark (eb, url);
+ if (node == NULL) return;
g_value_init (&value, G_TYPE_STRING);
g_value_set_string (&value, icon);
@@ -969,7 +967,8 @@ ephy_bookmarks_add_keyword (EphyBookmarks *eb,
return key;
}
-void ephy_bookmarks_remove_keyword (EphyBookmarks *eb,
+void
+ephy_bookmarks_remove_keyword (EphyBookmarks *eb,
EphyNode *keyword)
{
ephy_node_remove_child (eb->priv->keywords, keyword);
diff --git a/src/bookmarks/ephy-bookmarks.h b/src/bookmarks/ephy-bookmarks.h
index 162937c61..8cf8a4bf9 100644
--- a/src/bookmarks/ephy-bookmarks.h
+++ b/src/bookmarks/ephy-bookmarks.h
@@ -76,7 +76,7 @@ EphyNode *ephy_bookmarks_add (EphyBookmarks *eb,
const char *url,
const char *smart_url);
-guint ephy_bookmarks_get_bookmark_id (EphyBookmarks *eb,
+EphyNode* ephy_bookmarks_find_bookmark (EphyBookmarks *eb,
const char *url);
void ephy_bookmarks_set_icon (EphyBookmarks *eb,
diff --git a/src/bookmarks/ephy-new-bookmark.c b/src/bookmarks/ephy-new-bookmark.c
index 3e12ec602..db69e4ee7 100644
--- a/src/bookmarks/ephy-new-bookmark.c
+++ b/src/bookmarks/ephy-new-bookmark.c
@@ -288,6 +288,77 @@ ephy_new_bookmark_construct (EphyNewBookmark *editor)
gtk_dialog_set_default_response (GTK_DIALOG (editor), GTK_RESPONSE_OK);
}
+static GtkWidget*
+duplicate_dialog_construct (GtkWindow *parent,
+ const char *title)
+{
+ GtkWidget *dialog;
+ GtkWidget *hbox, *vbox, *label, *image;
+ char *str;
+
+ dialog = gtk_dialog_new_with_buttons (_("Duplicated bookmark"),
+ GTK_WINDOW (parent),
+ GTK_DIALOG_NO_SEPARATOR,
+ GTK_STOCK_OK,
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
+ gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 12);
+
+ hbox = gtk_hbox_new (FALSE, 6);
+ gtk_widget_show (hbox);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
+ TRUE, TRUE, 0);
+
+ image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO,
+ GTK_ICON_SIZE_DIALOG);
+ gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
+ gtk_widget_show (image);
+ gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, TRUE, 0);
+
+ vbox = gtk_vbox_new (FALSE, 6);
+ gtk_widget_show (vbox);
+ gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
+
+ label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ str = g_strconcat ("<big>",_("A bookmark titled "), "<b>", title, "</b>",
+ _(" already exists for this address."), "</big>",NULL);
+ gtk_label_set_markup (GTK_LABEL (label), str);
+ g_free (str);
+ gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
+ gtk_widget_show (label);
+
+ return dialog;
+}
+
+gboolean
+ephy_new_bookmark_is_unique (EphyBookmarks *bookmarks,
+ GtkWindow *parent,
+ const char *address)
+{
+ EphyNode *node;
+
+ node = ephy_bookmarks_find_bookmark (bookmarks, address);
+ if (node)
+ {
+ GtkWidget *dialog;
+ const char *title;
+
+ title = ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_TITLE);
+ dialog = duplicate_dialog_construct (parent, title);
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
GtkWidget *
ephy_new_bookmark_new (EphyBookmarks *bookmarks,
GtkWindow *parent,
@@ -302,7 +373,6 @@ ephy_new_bookmark_new (EphyBookmarks *bookmarks,
"bookmarks", bookmarks,
"location", location,
NULL));
-
if (parent)
{
gtk_window_set_transient_for (GTK_WINDOW (editor), parent);
diff --git a/src/bookmarks/ephy-new-bookmark.h b/src/bookmarks/ephy-new-bookmark.h
index 39c1f2f4a..fae8e3b7c 100644
--- a/src/bookmarks/ephy-new-bookmark.h
+++ b/src/bookmarks/ephy-new-bookmark.h
@@ -54,6 +54,10 @@ GtkWidget *ephy_new_bookmark_new (EphyBookmarks *bookmarks,
GtkWindow *parent,
const char *location);
+gboolean ephy_new_bookmark_is_unique (EphyBookmarks *bookmarks,
+ GtkWindow *parent,
+ const char *location);
+
void ephy_new_bookmark_set_title (EphyNewBookmark *bookmark,
const char *title);
diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c
index 6d1be0f7b..5de92482b 100644
--- a/src/ephy-history-window.c
+++ b/src/ephy-history-window.c
@@ -462,14 +462,18 @@ cmd_bookmark_page (EggAction *action,
node = EPHY_NODE (selection->data);
location = ephy_node_get_property_string (node, EPHY_NODE_PAGE_PROP_LOCATION);
title = ephy_node_get_property_string (node, EPHY_NODE_PAGE_PROP_TITLE);
- new_bookmark = ephy_new_bookmark_new
- (bookmarks, window, location);
- ephy_new_bookmark_set_title
- (EPHY_NEW_BOOKMARK (new_bookmark), title);
- g_signal_connect (G_OBJECT (new_bookmark), "response",
- G_CALLBACK (ephy_new_bookmark_response_cb),
- NULL);
- gtk_widget_show (new_bookmark);
+ if (ephy_new_bookmark_is_unique (bookmarks, GTK_WINDOW (window),
+ location))
+ {
+ new_bookmark = ephy_new_bookmark_new
+ (bookmarks, window, location);
+ ephy_new_bookmark_set_title
+ (EPHY_NEW_BOOKMARK (new_bookmark), title);
+ g_signal_connect (G_OBJECT (new_bookmark), "response",
+ G_CALLBACK (ephy_new_bookmark_response_cb),
+ NULL);
+ gtk_widget_show (new_bookmark);
+ }
}
g_list_free (selection);
}
diff --git a/src/popup-commands.c b/src/popup-commands.c
index a32a33618..78c335c55 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -156,16 +156,20 @@ popup_cmd_bookmark_link (EggAction *action,
}
bookmarks = ephy_shell_get_bookmarks (ephy_shell);
- new_bookmark = ephy_new_bookmark_new
- (bookmarks, GTK_WINDOW (window), location);
- ephy_new_bookmark_set_title
- (EPHY_NEW_BOOKMARK (new_bookmark), title);
- ephy_new_bookmark_set_smarturl
- (EPHY_NEW_BOOKMARK (new_bookmark), rel);
- g_signal_connect (G_OBJECT (new_bookmark), "response",
- G_CALLBACK (ephy_new_bookmark_response_cb),
- NULL);
- gtk_widget_show (new_bookmark);
+ if (ephy_new_bookmark_is_unique (bookmarks, GTK_WINDOW (window),
+ location))
+ {
+ new_bookmark = ephy_new_bookmark_new
+ (bookmarks, GTK_WINDOW (window), location);
+ ephy_new_bookmark_set_title
+ (EPHY_NEW_BOOKMARK (new_bookmark), title);
+ ephy_new_bookmark_set_smarturl
+ (EPHY_NEW_BOOKMARK (new_bookmark), rel);
+ g_signal_connect (G_OBJECT (new_bookmark), "response",
+ G_CALLBACK (ephy_new_bookmark_response_cb),
+ NULL);
+ gtk_widget_show (new_bookmark);
+ }
}
void
diff --git a/src/window-commands.c b/src/window-commands.c
index 5d50f6e05..a4f1ef004 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -276,16 +276,20 @@ window_cmd_file_bookmark_page (EggAction *action,
icon = ephy_tab_get_favicon_url (tab);
bookmarks = ephy_shell_get_bookmarks (ephy_shell);
- new_bookmark = ephy_new_bookmark_new
- (bookmarks, GTK_WINDOW (window), location);
- ephy_new_bookmark_set_title
- (EPHY_NEW_BOOKMARK (new_bookmark), title);
- ephy_new_bookmark_set_icon
- (EPHY_NEW_BOOKMARK (new_bookmark), icon);
- g_signal_connect (G_OBJECT (new_bookmark), "response",
- G_CALLBACK (ephy_new_bookmark_response_cb),
- NULL);
- gtk_widget_show (new_bookmark);
+ if (ephy_new_bookmark_is_unique (bookmarks, GTK_WINDOW (window),
+ location))
+ {
+ new_bookmark = ephy_new_bookmark_new
+ (bookmarks, GTK_WINDOW (window), location);
+ ephy_new_bookmark_set_title
+ (EPHY_NEW_BOOKMARK (new_bookmark), title);
+ ephy_new_bookmark_set_icon
+ (EPHY_NEW_BOOKMARK (new_bookmark), icon);
+ g_signal_connect (G_OBJECT (new_bookmark), "response",
+ G_CALLBACK (ephy_new_bookmark_response_cb),
+ NULL);
+ gtk_widget_show (new_bookmark);
+ }
}
void