[epiphany] Bookmarks popover should only connect to tag changes once per bookmark



commit 2a2a3a5c7be47bd78906c3d397b354fd2d6be67f
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Jan 22 11:46:34 2017 -0600

    Bookmarks popover should only connect to tag changes once per bookmark
    
    Currently, the EphyBookmarksPopover connects to tag added/removed
    signals on each EphyBookmark once for each EphyBookmarksRow that is
    created for this bookmark. Usually that is exactly two, once for the All
    view and once for the Tags view, but it can be three during an
    intermediate state when adding a tag when the tag has just been added to
    the Tags subview and not yet removed from the Tags main view. At any
    rate, it should not be connected two or three times, it should be
    connected once. So have EphyBookmarksManager emit these notifications
    and get them from it instead, irrespective of the number of
    EphyBookmarksRows that have been created.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772131

 src/bookmarks/ephy-bookmarks-manager.c |   45 ++++++++++++++++++++++++++++++++
 src/bookmarks/ephy-bookmarks-popover.c |   31 +++++++++++----------
 2 files changed, 61 insertions(+), 15 deletions(-)
---
diff --git a/src/bookmarks/ephy-bookmarks-manager.c b/src/bookmarks/ephy-bookmarks-manager.c
index 6912507..f5a4ae1 100644
--- a/src/bookmarks/ephy-bookmarks-manager.c
+++ b/src/bookmarks/ephy-bookmarks-manager.c
@@ -45,6 +45,8 @@ enum {
   BOOKMARK_REMOVED,
   BOOKMARK_TITLE_CHANGED,
   BOOKMARK_URL_CHANGED,
+  BOOKMARK_TAG_ADDED,
+  BOOKMARK_TAG_REMOVED,
   TAG_CREATED,
   TAG_DELETED,
   LAST_SIGNAL
@@ -119,6 +121,26 @@ ephy_bookmarks_manager_class_init (EphyBookmarksManagerClass *klass)
                   G_TYPE_NONE, 1,
                   EPHY_TYPE_BOOKMARK);
 
+  signals[BOOKMARK_TAG_ADDED] =
+    g_signal_new ("bookmark-tag-added",
+                  EPHY_TYPE_BOOKMARKS_MANAGER,
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL, NULL,
+                  G_TYPE_NONE, 2,
+                  EPHY_TYPE_BOOKMARK,
+                  G_TYPE_STRING);
+
+  signals[BOOKMARK_TAG_REMOVED] =
+    g_signal_new ("bookmark-tag-removed",
+                  EPHY_TYPE_BOOKMARKS_MANAGER,
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL, NULL,
+                  G_TYPE_NONE, 2,
+                  EPHY_TYPE_BOOKMARK,
+                  G_TYPE_STRING);
+
   signals[TAG_CREATED] =
     g_signal_new ("tag-created",
                   EPHY_TYPE_BOOKMARKS_MANAGER,
@@ -176,6 +198,23 @@ bookmark_url_changed_cb (EphyBookmark         *bookmark,
   g_signal_emit (self, signals[BOOKMARK_URL_CHANGED], 0, bookmark);
 }
 
+static void
+bookmark_tag_added_cb (EphyBookmark         *bookmark,
+                       const char           *tag,
+                       EphyBookmarksManager *self)
+{
+  g_signal_emit (self, signals[BOOKMARK_TAG_ADDED], 0, bookmark, tag);
+}
+
+static void
+bookmark_tag_removed_cb (EphyBookmark         *bookmark,
+                         const char           *tag,
+                         EphyBookmarksManager *self)
+{
+  g_signal_emit (self, signals[BOOKMARK_TAG_REMOVED], 0, bookmark, tag);
+}
+
+
 EphyBookmarksManager *
 ephy_bookmarks_manager_new (void)
 {
@@ -211,6 +250,10 @@ ephy_bookmarks_manager_add_bookmark (EphyBookmarksManager *self,
                              G_CALLBACK (bookmark_title_changed_cb), self, 0);
     g_signal_connect_object (bookmark, "notify::url",
                              G_CALLBACK (bookmark_url_changed_cb), self, 0);
+    g_signal_connect_object (bookmark, "tag-added",
+                             G_CALLBACK (bookmark_tag_added_cb), self, 0);
+    g_signal_connect_object (bookmark, "tag-removed",
+                             G_CALLBACK (bookmark_tag_removed_cb), self, 0);
   }
 }
 
@@ -276,6 +319,8 @@ ephy_bookmarks_manager_remove_bookmark (EphyBookmarksManager *self,
 
   g_signal_handlers_disconnect_by_func (bookmark, bookmark_title_changed_cb, self);
   g_signal_handlers_disconnect_by_func (bookmark, bookmark_url_changed_cb, self);
+  g_signal_handlers_disconnect_by_func (bookmark, bookmark_tag_added_cb, self);
+  g_signal_handlers_disconnect_by_func (bookmark, bookmark_tag_removed_cb, self);
 }
 
 EphyBookmark *
diff --git a/src/bookmarks/ephy-bookmarks-popover.c b/src/bookmarks/ephy-bookmarks-popover.c
index bcd59c8..2f33c6a 100644
--- a/src/bookmarks/ephy-bookmarks-popover.c
+++ b/src/bookmarks/ephy-bookmarks-popover.c
@@ -62,9 +62,10 @@ static GParamSpec *obj_properties[LAST_PROP];
 static GtkWidget *create_bookmark_row (gpointer item, gpointer user_data);
 
 static void
-bookmark_tag_added_cb (EphyBookmark         *bookmark,
-                       const char           *tag,
-                       EphyBookmarksPopover *popover)
+ephy_bookmarks_popover_bookmark_tag_added_cb (EphyBookmarksPopover *popover,
+                                              EphyBookmark         *bookmark,
+                                              const char           *tag,
+                                              EphyBookmarksManager *manager)
 {
   g_assert (EPHY_IS_BOOKMARK (bookmark));
   g_assert (EPHY_IS_BOOKMARKS_POPOVER (popover));
@@ -86,9 +87,10 @@ bookmark_tag_added_cb (EphyBookmark         *bookmark,
 }
 
 static void
-bookmark_tag_removed_cb (EphyBookmark         *bookmark,
-                         const char           *tag,
-                         EphyBookmarksPopover *popover)
+ephy_bookmarks_popover_bookmark_tag_removed_cb (EphyBookmarksPopover *popover,
+                                                EphyBookmark         *bookmark,
+                                                const char           *tag,
+                                                EphyBookmarksManager *manager)
 {
   g_assert (EPHY_IS_BOOKMARK (bookmark));
   g_assert (EPHY_IS_BOOKMARKS_POPOVER (popover));
@@ -122,8 +124,8 @@ bookmark_tag_removed_cb (EphyBookmark         *bookmark,
       gtk_container_add (GTK_CONTAINER (popover->tags_list_box), row);
     }
 
-    /* If we are on tag detail list box, we remove the tag from it to reflect
-     * the changes */
+    /* If we are on tag detail list box, we remove the bookmark from it to
+     * reflect the changes */
     visible_stack_child = gtk_stack_get_visible_child_name (GTK_STACK (popover->toplevel_stack));
     if (g_strcmp0 (visible_stack_child, "tag_detail") == 0) {
       children = gtk_container_get_children (GTK_CONTAINER (popover->tag_detail_list_box));
@@ -170,13 +172,6 @@ create_bookmark_row (gpointer item,
                           g_strdup (ephy_bookmark_get_url (bookmark)),
                           (GDestroyNotify)g_free);
 
-  g_signal_connect_object (bookmark, "tag-added",
-                           G_CALLBACK (bookmark_tag_added_cb),
-                           user_data, 0);
-  g_signal_connect_object (bookmark, "tag-removed",
-                           G_CALLBACK (bookmark_tag_removed_cb),
-                           user_data, 0);
-
   return row;
 }
 
@@ -556,6 +551,12 @@ ephy_bookmarks_popover_init (EphyBookmarksPopover *self)
   g_signal_connect_object (self->manager, "tag-deleted",
                            G_CALLBACK (ephy_bookmarks_popover_tag_deleted_cb),
                            self, G_CONNECT_SWAPPED);
+  g_signal_connect_object (self->manager, "bookmark-tag-added",
+                           G_CALLBACK (ephy_bookmarks_popover_bookmark_tag_added_cb),
+                           self, G_CONNECT_SWAPPED);
+  g_signal_connect_object (self->manager, "bookmark-tag-removed",
+                           G_CALLBACK (ephy_bookmarks_popover_bookmark_tag_removed_cb),
+                           self, G_CONNECT_SWAPPED);
 
   g_signal_connect_object (self->bookmarks_list_box, "row-activated",
                            G_CALLBACK (ephy_bookmarks_popover_list_box_row_activated_cb),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]