[epiphany/wip/sync] bookmark: Change properties to match the ones in Firefox



commit 735e0c4e17b3d34acfe9097250af6a7457dabf9f
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Tue Mar 21 19:42:43 2017 +0200

    bookmark: Change properties to match the ones in Firefox

 src/bookmarks/ephy-bookmark.c |  145 +++++++++++++++++++++++++++++++---------
 1 files changed, 112 insertions(+), 33 deletions(-)
---
diff --git a/src/bookmarks/ephy-bookmark.c b/src/bookmarks/ephy-bookmark.c
index da4ad74..c31b2f4 100644
--- a/src/bookmarks/ephy-bookmark.c
+++ b/src/bookmarks/ephy-bookmark.c
@@ -32,6 +32,11 @@
 #include "ephy-sync-utils.h"
 #endif
 
+#define TYPE_DEFAULT_VAL            "bookmark"
+#define PARENT_ID_DEFAULT_VAL       "toolbar"
+#define PARENT_NAME_DEFAULT_VAL     "Bookmarks Toolbar"
+#define LOAD_IN_SIDEBAR_DEFAULT_VAL FALSE
+
 struct _EphyBookmark {
   GObject      parent_instance;
 
@@ -40,8 +45,8 @@ struct _EphyBookmark {
   GSequence   *tags;
   gint64       time_added;
 
-  /* Keep the modified timestamp as double, and not float, to
-   * preserve the precision enforced by the Storage Server. */
+  /* Firefox Sync specific fields.
+   * Modified timestamp must be double to match server's precision. */
   char        *id;
   double       modified;
   gboolean     uploaded;
@@ -61,12 +66,18 @@ G_DEFINE_TYPE_WITH_CODE (EphyBookmark, ephy_bookmark, G_TYPE_OBJECT,
 
 enum {
   PROP_0,
-  PROP_TAGS,
+  /* Epiphany specific properties. */
   PROP_TIME_ADDED,
+  /* Firefox specific properties (some of these are used by Epiphany too). */
   PROP_TITLE,
-  PROP_URL,
+  PROP_BMK_URI,
+  PROP_TAGS,
+  PROP_TYPE,
+  PROP_PARENT_ID,
+  PROP_PARENT_NAME,
+  PROP_LOAD_IN_SIDEBAR,
   LAST_PROP,
-  /* Firefox related properties. */
+  /* Interface properties. */
   PROP_ID
 };
 
@@ -88,20 +99,28 @@ ephy_bookmark_set_property (GObject      *object,
   EphyBookmark *self = EPHY_BOOKMARK (object);
 
   switch (prop_id) {
-    case PROP_TAGS:
-      if (self->tags != NULL)
-        g_sequence_free (self->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:
       ephy_bookmark_set_title (self, g_value_get_string (value));
       break;
-    case PROP_URL:
+    case PROP_BMK_URI:
       ephy_bookmark_set_url (self, g_value_get_string (value));
       break;
+    case PROP_TAGS:
+      if (self->tags != NULL)
+        g_sequence_free (self->tags);
+      self->tags = g_value_get_pointer (value);
+      break;
+    case PROP_TYPE:
+      break;
+    case PROP_PARENT_ID:
+      break;
+    case PROP_PARENT_NAME:
+      break;
+    case PROP_LOAD_IN_SIDEBAR:
+      break;
     case PROP_ID:
       ephy_bookmark_set_id (self, g_value_get_string (value));
       break;
@@ -111,26 +130,38 @@ ephy_bookmark_set_property (GObject      *object,
 }
 
 static void
-ephy_bookmark_get_property (GObject      *object,
-                            guint         prop_id,
-                            GValue       *value,
-                            GParamSpec   *pspec)
+ephy_bookmark_get_property (GObject    *object,
+                            guint       prop_id,
+                            GValue     *value,
+                            GParamSpec *pspec)
 {
   EphyBookmark *self = EPHY_BOOKMARK (object);
 
   switch (prop_id) {
-    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;
-    case PROP_URL:
+    case PROP_BMK_URI:
       g_value_set_string (value, ephy_bookmark_get_url (self));
       break;
+    case PROP_TAGS:
+      g_value_set_pointer (value, ephy_bookmark_get_tags (self));
+      break;
+    case PROP_TYPE:
+      g_value_set_string (value, TYPE_DEFAULT_VAL);
+      break;
+    case PROP_PARENT_ID:
+      g_value_set_string (value, PARENT_ID_DEFAULT_VAL);
+      break;
+    case PROP_PARENT_NAME:
+      g_value_set_string (value, PARENT_NAME_DEFAULT_VAL);
+      break;
+    case PROP_LOAD_IN_SIDEBAR:
+      g_value_set_boolean (value, LOAD_IN_SIDEBAR_DEFAULT_VAL);
+      break;
     case PROP_ID:
       g_value_set_string (value, ephy_bookmark_get_id (self));
       break;
@@ -162,12 +193,6 @@ 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 | G_PARAM_STATIC_STRINGS);
-
   obj_properties[PROP_TIME_ADDED] =
     g_param_spec_int64 ("time-added",
                         "Time added",
@@ -184,13 +209,47 @@ ephy_bookmark_class_init (EphyBookmarkClass *klass)
                          "Default bookmark title",
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
 
-  obj_properties[PROP_URL] =
-    g_param_spec_string ("url",
-                         "URL",
-                         "The bookmark's URL",
+  obj_properties[PROP_BMK_URI] =
+    g_param_spec_string ("bmkUri",
+                         "URI",
+                         "The bookmark's URI",
                          "about:overview",
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
 
+  obj_properties[PROP_TAGS] =
+    g_param_spec_pointer ("tags",
+                          "Tags",
+                          "The bookmark's tags",
+                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+
+  obj_properties[PROP_TYPE] =
+    g_param_spec_string ("type",
+                         "Type",
+                         "Of type bookmark",
+                         TYPE_DEFAULT_VAL,
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+
+  obj_properties[PROP_PARENT_ID] =
+    g_param_spec_string ("parentid",
+                         "ParentID",
+                         "The parent's id",
+                         PARENT_ID_DEFAULT_VAL,
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+
+  obj_properties[PROP_PARENT_NAME] =
+    g_param_spec_string ("parentName",
+                         "ParentName",
+                         "The parent's name",
+                         PARENT_NAME_DEFAULT_VAL,
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+
+  obj_properties[PROP_LOAD_IN_SIDEBAR] =
+    g_param_spec_boolean ("loadInSidebar",
+                          "LoadInSiderbar",
+                          "Load in sidebar",
+                          LOAD_IN_SIDEBAR_DEFAULT_VAL,
+                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+
   g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
   g_object_class_override_property (object_class, PROP_ID, "id");
 
@@ -242,9 +301,25 @@ ephy_bookmark_json_serializable_serialize_property (JsonSerializable *serializab
     }
 
     json_node_set_array (node, array);
+  }
+  /* JSON-GLib does not serialize properties that have the value equal
+   * to the default value, so we have to do it ourselves. */
+  else if (g_strcmp0 (name, "type") == 0) {
+    node = json_node_new (JSON_NODE_VALUE);
+    json_node_set_string (node, TYPE_DEFAULT_VAL);
+  } else if (g_strcmp0 (name, "parentid") == 0) {
+    node = json_node_new (JSON_NODE_VALUE);
+    json_node_set_string (node, PARENT_ID_DEFAULT_VAL);
+  } else if (g_strcmp0 (name, "parentName") == 0) {
+    node = json_node_new (JSON_NODE_VALUE);
+    json_node_set_string (node, PARENT_NAME_DEFAULT_VAL);
+  } else if (g_strcmp0 (name, "loadInSidebar") == 0) {
+    node = json_node_new (JSON_NODE_VALUE);
+    json_node_set_boolean (node, LOAD_IN_SIDEBAR_DEFAULT_VAL);
+  } else if (g_strcmp0 (name, "time-added") == 0) {
+    /* This is not a Firefox bookmark property, skip it.  */
   } else {
-    node = serializable_iface->serialize_property (serializable, name,
-                                                   value, pspec);
+    node = serializable_iface->serialize_property (serializable, name, value, pspec);
   }
 
   return node;
@@ -398,10 +473,14 @@ ephy_bookmark_new (const char *url,
                    const char *id)
 {
   return g_object_new (EPHY_TYPE_BOOKMARK,
-                       "url", url,
+                       "time-added", g_get_real_time (),
                        "title", title,
+                       "bmkUri", url,
                        "tags", tags,
-                       "time-added", g_get_real_time (),
+                       "type", TYPE_DEFAULT_VAL,
+                       "parentid", PARENT_ID_DEFAULT_VAL,
+                       "parentName", PARENT_NAME_DEFAULT_VAL,
+                       "loadInSidebar", LOAD_IN_SIDEBAR_DEFAULT_VAL,
                        "id", id,
                        NULL);
 }


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