[epiphany/wip/ephy-sync] bookmarks: Save the time at which a bookmark is added
- From: Gabriel - Cristian Ivascu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/ephy-sync] bookmarks: Save the time at which a bookmark is added
- Date: Mon, 8 Aug 2016 18:22:48 +0000 (UTC)
commit ebe330ae5352d021f15131c0944ac66031a9235b
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 | 60 +++++++++++++++++++++++-------------------
src/ephy-bookmarks-manager.c | 18 +++++++-----
3 files changed, 81 insertions(+), 34 deletions(-)
---
diff --git a/src/ephy-bookmark.c b/src/ephy-bookmark.c
index 2c73717..88bb593 100644
--- a/src/ephy-bookmark.c
+++ b/src/ephy-bookmark.c
@@ -32,6 +32,7 @@ struct _EphyBookmark {
char *url;
char *title;
GSequence *tags;
+ gint64 time_added;
char *id;
double modified;
@@ -47,6 +48,7 @@ G_DEFINE_TYPE_EXTENDED (EphyBookmark, ephy_bookmark, G_TYPE_OBJECT, 0,
enum {
PROP_0,
PROP_TAGS,
+ PROP_TIME_ADDED,
PROP_TITLE,
PROP_URL,
LAST_PROP
@@ -72,6 +74,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;
@@ -95,6 +100,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;
@@ -134,6 +142,15 @@ ephy_bookmark_class_init (EphyBookmarkClass *klass)
"The bookmark's tags",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+ 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",
@@ -246,10 +263,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 3d89c14..87ee3b5 100644
--- a/src/ephy-bookmark.h
+++ b/src/ephy-bookmark.h
@@ -26,33 +26,39 @@ 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);
-
-const char *ephy_bookmark_get_id (EphyBookmark *self);
-double ephy_bookmark_get_modified (EphyBookmark *self);
-void ephy_bookmark_set_modified (EphyBookmark *self,
- double modified);
-
-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);
-char *ephy_bookmark_to_bso (EphyBookmark *self);
+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);
+
+const char *ephy_bookmark_get_id (EphyBookmark *self);
+
+void ephy_bookmark_set_modified (EphyBookmark *self,
+ double modified);
+double ephy_bookmark_get_modified (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);
+
+char *ephy_bookmark_to_bso (EphyBookmark *self);
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]