aboutsummaryrefslogtreecommitdiffstats
path: root/src/bookmarks
diff options
context:
space:
mode:
authorPeter Harvey <peter.a.harvey@gmail.com>2006-01-31 07:02:35 +0800
committerPeter Anthony Harvey <paharvey@src.gnome.org>2006-01-31 07:02:35 +0800
commit5a25f384ec84c94e89e07558296620dc74681e7b (patch)
tree21464a9c77288b240f7ca52a23a18627acc5cbdf /src/bookmarks
parent7d08bb7e103b567fd9fc707d4625be9a1335f3fd (diff)
downloadgsoc2013-epiphany-5a25f384ec84c94e89e07558296620dc74681e7b.tar
gsoc2013-epiphany-5a25f384ec84c94e89e07558296620dc74681e7b.tar.gz
gsoc2013-epiphany-5a25f384ec84c94e89e07558296620dc74681e7b.tar.bz2
gsoc2013-epiphany-5a25f384ec84c94e89e07558296620dc74681e7b.tar.lz
gsoc2013-epiphany-5a25f384ec84c94e89e07558296620dc74681e7b.tar.xz
gsoc2013-epiphany-5a25f384ec84c94e89e07558296620dc74681e7b.tar.zst
gsoc2013-epiphany-5a25f384ec84c94e89e07558296620dc74681e7b.zip
src/bookmarks/ephy-bookmark-properties.c src/bookmarks/ephy-bookmarks.c
2006-01-30 Peter Harvey <peter.a.harvey@gmail.com> * src/bookmarks/ephy-bookmark-properties.c * src/bookmarks/ephy-bookmarks.c * src/bookmarks/ephy-bookmarks.h Made the 'Similar' button show more bookmarks, and separate into 'identical' and 'similar'.
Diffstat (limited to 'src/bookmarks')
-rw-r--r--src/bookmarks/ephy-bookmark-properties.c117
-rw-r--r--src/bookmarks/ephy-bookmarks.c81
-rw-r--r--src/bookmarks/ephy-bookmarks.h9
3 files changed, 117 insertions, 90 deletions
diff --git a/src/bookmarks/ephy-bookmark-properties.c b/src/bookmarks/ephy-bookmark-properties.c
index 578ab4eef..6c46ccbc8 100644
--- a/src/bookmarks/ephy-bookmark-properties.c
+++ b/src/bookmarks/ephy-bookmark-properties.c
@@ -84,8 +84,8 @@ update_warning (EphyBookmarkProperties *properties)
char *label;
priv->duplicate_idle = 0;
- priv->duplicate_count = ephy_bookmarks_count_duplicates
- (priv->bookmarks, priv->bookmark);
+ priv->duplicate_count = ephy_bookmarks_get_similar
+ (priv->bookmarks, priv->bookmark, NULL, NULL);
/* Translators: This string is used when counting bookmarks that
* are similar to each other */
@@ -178,20 +178,21 @@ activate_merge_cb (GtkMenuItem *item,
EphyBookmarkProperties *properties)
{
EphyBookmarkPropertiesPrivate *priv = properties->priv;
- GPtrArray *duplicates;
GPtrArray *topics;
EphyNode *node, *topic;
gint i, j;
- duplicates = ephy_bookmarks_find_duplicates
- (priv->bookmarks, priv->bookmark);
+ GPtrArray *identical = g_ptr_array_new ();
+
+ ephy_bookmarks_get_similar
+ (priv->bookmarks, priv->bookmark, identical, NULL);
node = ephy_bookmarks_get_keywords (priv->bookmarks);
topics = ephy_node_get_children (node);
- for (i = 0; i < duplicates->len; i++)
+ for (i = 0; i < identical->len; i++)
{
- node = g_ptr_array_index (duplicates, i);
+ node = g_ptr_array_index (identical, i);
for (j = 0; j < topics->len; j++)
{
topic = g_ptr_array_index (topics, j);
@@ -205,7 +206,7 @@ activate_merge_cb (GtkMenuItem *item,
ephy_node_unref (node);
}
- g_ptr_array_free (duplicates, TRUE);
+ g_ptr_array_free (identical, TRUE);
update_warning (properties);
}
@@ -223,50 +224,82 @@ show_duplicate_cb (GtkButton *button,
{
EphyBookmarkPropertiesPrivate *priv = properties->priv;
EphyNode *node;
- GPtrArray *duplicates;
GtkMenuShell *menu;
GtkWidget *item, *image;
char *label;
gint i;
- update_warning (properties);
- if (priv->duplicate_count == 0)
- {
- return;
- }
-
- duplicates = ephy_bookmarks_find_duplicates
- (priv->bookmarks, priv->bookmark);
+ GPtrArray *identical = g_ptr_array_new ();
+ GPtrArray *similar = g_ptr_array_new ();
+
+ ephy_bookmarks_get_similar (priv->bookmarks,
+ priv->bookmark,
+ identical,
+ similar);
- menu = GTK_MENU_SHELL (gtk_menu_new ());
- item = gtk_image_menu_item_new_with_mnemonic (_("_Merge"));
- image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU);
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
- g_signal_connect (item, "activate", G_CALLBACK (activate_merge_cb), properties);
- gtk_widget_show (image);
- gtk_widget_show (item);
- gtk_menu_shell_append (menu, item);
+ if (identical->len + similar->len > 0)
+ {
+ menu = GTK_MENU_SHELL (gtk_menu_new ());
+
+ if (identical->len > 0)
+ {
+ label = g_strdup_printf (_("_Unify With %d Identical Bookmark(s)"),
+ identical->len);
+ item = gtk_image_menu_item_new_with_mnemonic (label);
+ g_free (label);
+ image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+ g_signal_connect (item, "activate", G_CALLBACK (activate_merge_cb), properties);
+ gtk_widget_show (image);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (menu, item);
- item = gtk_separator_menu_item_new ();
- gtk_widget_show (item);
- gtk_menu_shell_append (menu, item);
+ item = gtk_separator_menu_item_new ();
+ gtk_widget_show (item);
+ gtk_menu_shell_append (menu, item);
- for (i = 0; i < duplicates->len; i++)
- {
- node = g_ptr_array_index (duplicates, i);
- label = g_strdup_printf (_("Show “%s”"),
- ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_TITLE));
- item = gtk_image_menu_item_new_with_label (label);
- g_free (label);
- g_signal_connect (item, "activate", G_CALLBACK (activate_show_cb), node);
- gtk_widget_show (item);
- gtk_menu_shell_append (menu, item);
+ for (i = 0; i < identical->len; i++)
+ {
+ node = g_ptr_array_index (identical, i);
+ label = g_strdup_printf (_("Show “%s”"),
+ ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_TITLE));
+ item = gtk_image_menu_item_new_with_label (label);
+ g_free (label);
+ g_signal_connect (item, "activate", G_CALLBACK (activate_show_cb), node);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (menu, item);
+ }
+ }
+
+ if (identical->len > 0 && similar->len > 0)
+ {
+ item = gtk_separator_menu_item_new ();
+ gtk_widget_show (item);
+ gtk_menu_shell_append (menu, item);
+ }
+
+ if (similar->len > 0)
+ {
+ for (i = 0; i < similar->len; i++)
+ {
+ node = g_ptr_array_index (similar, i);
+ label = g_strdup_printf (_("Show “%s”"),
+ ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_TITLE));
+ item = gtk_image_menu_item_new_with_label (label);
+ g_free (label);
+ g_signal_connect (item, "activate", G_CALLBACK (activate_show_cb), node);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (menu, item);
+ }
+ }
+
+ gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+ ephy_gui_menu_position_under_widget, button,
+ 0, gtk_get_current_event_time ());
}
- gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
- ephy_gui_menu_position_under_widget, button,
- 0, gtk_get_current_event_time ());
- g_ptr_array_free (duplicates, TRUE);
+ g_ptr_array_free (similar, TRUE);
+ g_ptr_array_free (identical, TRUE);
}
static void
diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c
index 207b55e62..36a3455d5 100644
--- a/src/bookmarks/ephy-bookmarks.c
+++ b/src/bookmarks/ephy-bookmarks.c
@@ -1186,53 +1186,36 @@ ephy_bookmarks_find_bookmark (EphyBookmarks *eb,
return NULL;
}
-GPtrArray *
-ephy_bookmarks_find_duplicates (EphyBookmarks *eb,
- EphyNode *bookmark)
+static gboolean
+is_similar (const char *url1, const char *url2)
{
- GPtrArray *children;
- GPtrArray *result;
- const char *url;
- int i;
-
- g_return_val_if_fail (EPHY_IS_BOOKMARKS (eb), NULL);
- g_return_val_if_fail (eb->priv->bookmarks != NULL, NULL);
- g_return_val_if_fail (bookmark != NULL, NULL);
-
- url = ephy_node_get_property_string
- (bookmark, EPHY_NODE_BMK_PROP_LOCATION);
-
- g_return_val_if_fail (url != NULL, NULL);
-
- result = g_ptr_array_new ();
-
- children = ephy_node_get_children (eb->priv->bookmarks);
- for (i = 0; i < children->len; i++)
+ while(*url1 == *url2 && *url1 != '\0' &&
+ *url1 != '#' && *url1 != '?')
{
- EphyNode *kid;
- const char *location;
-
- kid = g_ptr_array_index (children, i);
- if (kid == bookmark)
- {
- continue;
- }
-
- location = ephy_node_get_property_string
- (kid, EPHY_NODE_BMK_PROP_LOCATION);
-
- if (location != NULL && strcmp (url, location) == 0)
- {
- g_ptr_array_add (result, kid);
- }
+ url1++;
+ url2++;
}
-
- return result;
+ if(*url1 == *url2) return TRUE;
+ if(*url1 == '\0')
+ {
+ if(*url2 == '#') return TRUE;
+ if(*url2 == '?') return TRUE;
+ if(*url2 == '/' && *(url2+1) == '\0') return TRUE;
+ }
+ if(*url2 == '\0')
+ {
+ if(*url1 == '#') return TRUE;
+ if(*url1 == '?') return TRUE;
+ if(*url1 == '/' && *(url1+1) == '\0') return TRUE;
+ }
+ return FALSE;
}
gint
-ephy_bookmarks_count_duplicates (EphyBookmarks *eb,
- EphyNode *bookmark)
+ephy_bookmarks_get_similar (EphyBookmarks *eb,
+ EphyNode *bookmark,
+ GPtrArray *identical,
+ GPtrArray *similar)
{
GPtrArray *children;
const char *url;
@@ -1264,9 +1247,21 @@ ephy_bookmarks_count_duplicates (EphyBookmarks *eb,
location = ephy_node_get_property_string
(kid, EPHY_NODE_BMK_PROP_LOCATION);
- if (location != NULL && strcmp (url, location) == 0)
+ if (location != NULL)
{
- result++;
+ if(identical != NULL && strcmp (url, location) == 0)
+ {
+ g_ptr_array_add (identical, kid);
+ result++;
+ }
+ else if(is_similar (url, location))
+ {
+ if (similar != NULL)
+ {
+ g_ptr_array_add (similar, kid);
+ }
+ result++;
+ }
}
}
diff --git a/src/bookmarks/ephy-bookmarks.h b/src/bookmarks/ephy-bookmarks.h
index 774fa2a62..bc3f75ce6 100644
--- a/src/bookmarks/ephy-bookmarks.h
+++ b/src/bookmarks/ephy-bookmarks.h
@@ -88,11 +88,10 @@ EphyNode *ephy_bookmarks_add (EphyBookmarks *eb,
EphyNode* ephy_bookmarks_find_bookmark (EphyBookmarks *eb,
const char *url);
-GPtrArray *ephy_bookmarks_find_duplicates (EphyBookmarks *eb,
- EphyNode *bookmark);
-
-gint ephy_bookmarks_count_duplicates (EphyBookmarks *eb,
- EphyNode *bookmark);
+gint ephy_bookmarks_get_similar (EphyBookmarks *eb,
+ EphyNode *bookmark,
+ GPtrArray *identical,
+ GPtrArray *similar);
void ephy_bookmarks_set_icon (EphyBookmarks *eb,
const char *url,