[epiphany/wip/bookmarks: 259/315] bookmarks: Make 'tags' a property



commit 8426cd2eab8ead5c8f2c87a41a9fe677417f90fb
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Sat Jul 30 14:34:10 2016 +0300

    bookmarks: Make 'tags' a property

 src/ephy-bookmark.c          |   25 +++++++++++++++----------
 src/ephy-bookmark.h          |   15 +++++++--------
 src/ephy-bookmarks-manager.c |    3 +--
 src/ephy-bookmarks-popover.c |    5 +++--
 4 files changed, 26 insertions(+), 22 deletions(-)
---
diff --git a/src/ephy-bookmark.c b/src/ephy-bookmark.c
index f5b18d2..f4fad11 100644
--- a/src/ephy-bookmark.c
+++ b/src/ephy-bookmark.c
@@ -31,6 +31,7 @@ G_DEFINE_TYPE (EphyBookmark, ephy_bookmark, G_TYPE_OBJECT)
 
 enum {
   PROP_0,
+  PROP_TAGS,
   PROP_TITLE,
   PROP_URL,
   LAST_PROP
@@ -53,6 +54,9 @@ ephy_bookmark_set_property (GObject      *object,
   EphyBookmark *self = EPHY_BOOKMARK (object);
 
   switch (prop_id) {
+    case PROP_TAGS:
+      self->tags = g_value_get_pointer (value);
+      break;
     case PROP_TITLE:
       self->title = g_value_dup_string (value);
       break;
@@ -73,6 +77,9 @@ ephy_bookmark_get_property (GObject      *object,
   EphyBookmark *self = EPHY_BOOKMARK (object);
 
   switch (prop_id) {
+    case PROP_TAGS:
+      g_value_set_pointer (value, ephy_bookmark_get_tags (self));
+      break;
     case PROP_TITLE:
       g_value_set_string (value, ephy_bookmark_get_title (self));
       break;
@@ -106,6 +113,12 @@ ephy_bookmark_class_init (EphyBookmarkClass *klass)
   object_class->get_property = ephy_bookmark_get_property;
   object_class->finalize = ephy_bookmark_finalize;
 
+  obj_properties[PROP_TAGS] =
+    g_param_spec_pointer ("tags",
+                          "Tags",
+                          "The bookmark's tags",
+                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
   obj_properties[PROP_TITLE] =
     g_param_spec_string ("title",
                          "Title",
@@ -137,11 +150,12 @@ ephy_bookmark_init (EphyBookmark *self)
 }
 
 EphyBookmark *
-ephy_bookmark_new (char *url, char *title)
+ephy_bookmark_new (char *url, char *title, GSequence *tags)
 {
   return g_object_new (EPHY_TYPE_BOOKMARK,
                        "url", url,
                        "title", title,
+                       "tags", tags,
                        NULL);
 }
 
@@ -215,15 +229,6 @@ ephy_bookmark_has_tag (EphyBookmark *self, const char *tag)
   return tag_iter != NULL;
 }
 
-void
-ephy_bookmark_set_tags (EphyBookmark *self, GSequence *tags)
-{
-  g_return_if_fail (EPHY_IS_BOOKMARK (self));
-  g_return_if_fail (tags != NULL);
-
-  self->tags = tags;
-}
-
 GSequence *
 ephy_bookmark_get_tags (EphyBookmark *self)
 {
diff --git a/src/ephy-bookmark.h b/src/ephy-bookmark.h
index 7ce719a..c76c509 100644
--- a/src/ephy-bookmark.h
+++ b/src/ephy-bookmark.h
@@ -26,21 +26,20 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (EphyBookmark, ephy_bookmark, EPHY, BOOKMARK, GObject)
 
-EphyBookmark        *ephy_bookmark_new          (char *url,
-                                                 char *title);
+EphyBookmark        *ephy_bookmark_new          (char      *url,
+                                                 char      *title,
+                                                 GSequence *tags);
 
 const char          *ephy_bookmark_get_url      (EphyBookmark *self);
 const char          *ephy_bookmark_get_title    (EphyBookmark *self);
+
 void                 ephy_bookmark_add_tag      (EphyBookmark *self,
-                                                 const char *tag);
+                                                 const char   *tag);
 void                 ephy_bookmark_remove_tag   (EphyBookmark *self,
-                                                 const char *tag);
+                                                 const char   *tag);
 gboolean             ephy_bookmark_has_tag      (EphyBookmark *self,
-                                                 const char *tag);
-void                 ephy_bookmark_set_tags     (EphyBookmark *self,
-                                                 GSequence    *tags);
+                                                 const char   *tag);
 GSequence           *ephy_bookmark_get_tags     (EphyBookmark *self);
-
 int                  ephy_bookmark_tags_compare (const char *tag1,
                                                  const char *tag2);
 
diff --git a/src/ephy-bookmarks-manager.c b/src/ephy-bookmarks-manager.c
index 1c321dc..755df77 100644
--- a/src/ephy-bookmarks-manager.c
+++ b/src/ephy-bookmarks-manager.c
@@ -353,8 +353,7 @@ ephy_bookmarks_manager_load_from_file (EphyBookmarksManager *self)
     }
 
     /* Create the new bookmark. */
-    bookmark = ephy_bookmark_new (g_strdup (list[i]), title);
-    ephy_bookmark_set_tags (bookmark, tags);
+    bookmark = ephy_bookmark_new (g_strdup (list[i]), title, tags);
     ephy_bookmarks_manager_add_bookmark (self, bookmark);
   }
   gvdb_table_free (table);
diff --git a/src/ephy-bookmarks-popover.c b/src/ephy-bookmarks-popover.c
index 1a50a1a..c44b38d 100644
--- a/src/ephy-bookmarks-popover.c
+++ b/src/ephy-bookmarks-popover.c
@@ -267,8 +267,9 @@ ephy_bookmarks_popover_init (EphyBookmarksPopover *self)
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  dummy_bookmark = ephy_bookmark_new (g_strdup ("https://facebook.com";), g_strdup ("Facebook"));
-  ephy_bookmark_set_tags (dummy_bookmark, g_sequence_new (g_free));
+  dummy_bookmark = ephy_bookmark_new (g_strdup ("https://facebook.com";),
+                                      g_strdup ("Facebook"),
+                                      g_sequence_new (g_free));
   ephy_bookmarks_manager_add_bookmark (manager, dummy_bookmark);
 
   gtk_list_box_bind_model (GTK_LIST_BOX (self->bookmarks_list_box),


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