[epiphany/wip/bookmarks: 268/315] bookmarks: Save the time at which a bookmark is added



commit 13424090b7538654954c62fc225b5b5375728d66
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Mon Aug 8 13:02:44 2016 +0300

    bookmarks: Save the time at which a bookmark is added

 src/ephy-bookmark.c          |   37 +++++++++++++++++++++++++++++++++
 src/ephy-bookmark.h          |   46 ++++++++++++++++++++++-------------------
 src/ephy-bookmarks-manager.c |   18 ++++++++++------
 3 files changed, 73 insertions(+), 28 deletions(-)
---
diff --git a/src/ephy-bookmark.c b/src/ephy-bookmark.c
index 2b3d4a9..558925c 100644
--- a/src/ephy-bookmark.c
+++ b/src/ephy-bookmark.c
@@ -25,6 +25,7 @@ struct _EphyBookmark {
   char        *url;
   char        *title;
   GSequence   *tags;
+  gint64       time_added;
 };
 
 G_DEFINE_TYPE (EphyBookmark, ephy_bookmark, G_TYPE_OBJECT)
@@ -32,6 +33,7 @@ G_DEFINE_TYPE (EphyBookmark, ephy_bookmark, G_TYPE_OBJECT)
 enum {
   PROP_0,
   PROP_TAGS,
+  PROP_TIME_ADDED,
   PROP_TITLE,
   PROP_URL,
   LAST_PROP
@@ -57,6 +59,9 @@ ephy_bookmark_set_property (GObject      *object,
     case PROP_TAGS:
       self->tags = g_value_get_pointer (value);
       break;
+    case PROP_TIME_ADDED:
+      ephy_bookmark_set_time_added (self, g_value_get_int64 (value));
+      break;
     case PROP_TITLE:
       self->title = g_value_dup_string (value);
       break;
@@ -80,6 +85,9 @@ ephy_bookmark_get_property (GObject      *object,
     case PROP_TAGS:
       g_value_set_pointer (value, ephy_bookmark_get_tags (self));
       break;
+    case PROP_TIME_ADDED:
+      g_value_set_int64 (value, ephy_bookmark_get_time_added (self));
+      break;
     case PROP_TITLE:
       g_value_set_string (value, ephy_bookmark_get_title (self));
       break;
@@ -119,6 +127,15 @@ ephy_bookmark_class_init (EphyBookmarkClass *klass)
                           "The bookmark's tags",
                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
 
+  obj_properties[PROP_TIME_ADDED] =
+    g_param_spec_int64 ("time-added",
+                        "Time added",
+                        "The bookmark's creation time",
+                        0,
+                        G_MAXINT64,
+                        0,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+
   obj_properties[PROP_TITLE] =
     g_param_spec_string ("title",
                          "Title",
@@ -156,10 +173,30 @@ ephy_bookmark_new (char *url, char *title, GSequence *tags)
                        "url", url,
                        "title", title,
                        "tags", tags,
+                       "time-added", g_get_real_time (),
                        NULL);
 }
 
 void
+ephy_bookmark_set_time_added (EphyBookmark *self,
+                              gint64        time_added)
+{
+  g_return_if_fail (EPHY_IS_BOOKMARK (self));
+  g_assert (time_added >= 0);
+
+  self->time_added = time_added;
+}
+
+gint64
+ephy_bookmark_get_time_added (EphyBookmark *self)
+{
+  g_return_val_if_fail (EPHY_IS_BOOKMARK (self), 0);
+
+  return self->time_added;
+}
+
+
+void
 ephy_bookmark_set_url (EphyBookmark *self, const char *url)
 {
   g_return_if_fail (EPHY_IS_BOOKMARK (self));
diff --git a/src/ephy-bookmark.h b/src/ephy-bookmark.h
index 6115591..8c627bb 100644
--- a/src/ephy-bookmark.h
+++ b/src/ephy-bookmark.h
@@ -26,27 +26,31 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (EphyBookmark, ephy_bookmark, EPHY, BOOKMARK, GObject)
 
-EphyBookmark        *ephy_bookmark_new          (char      *url,
-                                                 char      *title,
-                                                 GSequence *tags);
-
-void                 ephy_bookmark_set_url      (EphyBookmark *self,
-                                                 const char   *url);
-const char          *ephy_bookmark_get_url      (EphyBookmark *self);
-
-void                 ephy_bookmark_set_title    (EphyBookmark *self,
-                                                 const char   *title);
-const char          *ephy_bookmark_get_title    (EphyBookmark *self);
-
-void                 ephy_bookmark_add_tag      (EphyBookmark *self,
-                                                 const char   *tag);
-void                 ephy_bookmark_remove_tag   (EphyBookmark *self,
-                                                 const char   *tag);
-gboolean             ephy_bookmark_has_tag      (EphyBookmark *self,
-                                                 const char   *tag);
-GSequence           *ephy_bookmark_get_tags     (EphyBookmark *self);
-int                  ephy_bookmark_tags_compare (const char *tag1,
-                                                 const char *tag2);
+EphyBookmark        *ephy_bookmark_new            (char      *url,
+                                                   char      *title,
+                                                   GSequence *tags);
+
+void                 ephy_bookmark_set_time_added (EphyBookmark *self,
+                                                   gint64        time_added);
+gint64               ephy_bookmark_get_time_added (EphyBookmark *self);
+
+void                 ephy_bookmark_set_url        (EphyBookmark *self,
+                                                   const char   *url);
+const char          *ephy_bookmark_get_url        (EphyBookmark *self);
+
+void                 ephy_bookmark_set_title      (EphyBookmark *self,
+                                                   const char   *title);
+const char          *ephy_bookmark_get_title      (EphyBookmark *self);
+
+void                 ephy_bookmark_add_tag        (EphyBookmark *self,
+                                                   const char   *tag);
+void                 ephy_bookmark_remove_tag     (EphyBookmark *self,
+                                                   const char   *tag);
+gboolean             ephy_bookmark_has_tag        (EphyBookmark *self,
+                                                   const char   *tag);
+GSequence           *ephy_bookmark_get_tags       (EphyBookmark *self);
+int                  ephy_bookmark_tags_compare   (const char *tag1,
+                                                   const char *tag2);
 
 G_END_DECLS
 
diff --git a/src/ephy-bookmarks-manager.c b/src/ephy-bookmarks-manager.c
index ccf9fef..57c8d3c 100644
--- a/src/ephy-bookmarks-manager.c
+++ b/src/ephy-bookmarks-manager.c
@@ -58,15 +58,19 @@ build_variant (EphyBookmark *bookmark)
   GSequence *tags;
   GSequenceIter *iter;
 
-  g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
+  g_variant_builder_init (&builder, G_VARIANT_TYPE ("(xsas)"));
+
+  g_variant_builder_add (&builder, "x", ephy_bookmark_get_time_added (bookmark));
   g_variant_builder_add (&builder, "s", ephy_bookmark_get_title (bookmark));
 
+  g_variant_builder_open (&builder, G_VARIANT_TYPE ("as"));
   tags = ephy_bookmark_get_tags (bookmark);
   for (iter = g_sequence_get_begin_iter (tags);
        !g_sequence_iter_is_end (iter);
        iter = g_sequence_iter_next (iter)) {
     g_variant_builder_add (&builder, "s", g_sequence_get (iter));
   }
+  g_variant_builder_close (&builder);
 
   return g_variant_builder_end (&builder);
 }
@@ -452,29 +456,29 @@ ephy_bookmarks_manager_load_from_file (EphyBookmarksManager *self)
   for (i = 0; i < length; i++) {
     EphyBookmark *bookmark;
     GVariant *value;
-    GVariantIter iter;
+    GVariantIter *iter;
     GSequence *tags;
     char *tag;
     char *title;
+    gint64 time_added;
 
     /* Obtain the correspoding GVariant. */
     value = gvdb_table_get_value (table, list[i]);
 
-    g_variant_iter_init (&iter, value);
-
-    /* The first string in the array is the bookmark's title. */
-    g_variant_iter_next (&iter, "s", &title);
+    g_variant_get (value, "(x&sas)", &time_added, &title, &iter);
 
     /* Add all stored tags in a GSequence. */
     tags = g_sequence_new (g_free);
-    while (g_variant_iter_next (&iter, "s", &tag)) {
+    while (g_variant_iter_next (iter, "s", &tag)) {
       g_sequence_insert_sorted (tags, tag,
                                 (GCompareDataFunc)ephy_bookmark_tags_compare,
                                 NULL);
     }
+    g_variant_iter_free (iter);
 
     /* Create the new bookmark. */
     bookmark = ephy_bookmark_new (g_strdup (list[i]), title, tags);
+    ephy_bookmark_set_time_added (bookmark, time_added);
     ephy_bookmarks_manager_add_bookmark (self, bookmark);
   }
   gvdb_table_free (table);


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