[epiphany/wip/ephy-sync: 91/126] bookmarks: Serialize tags too
- From: Gabriel - Cristian Ivascu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/ephy-sync: 91/126] bookmarks: Serialize tags too
- Date: Fri, 19 Aug 2016 17:39:13 +0000 (UTC)
commit 4ddb9e8cb79e62df946a60947c5fef4833179219
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Sat Jul 30 16:55:17 2016 +0300
bookmarks: Serialize tags too
src/ephy-bookmark.c | 65 ++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 51 insertions(+), 14 deletions(-)
---
diff --git a/src/ephy-bookmark.c b/src/ephy-bookmark.c
index d590001..3c280f0 100644
--- a/src/ephy-bookmark.c
+++ b/src/ephy-bookmark.c
@@ -140,7 +140,7 @@ ephy_bookmark_class_init (EphyBookmarkClass *klass)
g_param_spec_pointer ("tags",
"Tags",
"The bookmark's tags",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
obj_properties[PROP_TIME_ADDED] =
g_param_spec_int64 ("time-added",
@@ -193,28 +193,65 @@ ephy_bookmark_init (EphyBookmark *self)
static JsonNode *
ephy_bookmark_json_serializable_serialize_property (JsonSerializable *serializable,
- const gchar *property_name,
+ const gchar *name,
const GValue *value,
GParamSpec *pspec)
{
- return serializable_iface->serialize_property (serializable,
- property_name,
- value,
- pspec);
+ JsonNode *node = NULL;
+
+ if (g_strcmp0 (name, "tags") == 0) {
+ GSequence *tags;
+ GSequenceIter *iter;
+ JsonArray *array;
+
+ node = json_node_new (JSON_NODE_ARRAY);
+ array = json_array_new ();
+ tags = g_value_get_pointer (value);
+
+ for (iter = g_sequence_get_begin_iter (tags);
+ !g_sequence_iter_is_end (iter);
+ iter = g_sequence_iter_next (iter)) {
+ json_array_add_string_element (array, g_sequence_get (iter));
+ }
+
+ json_node_set_array (node, array);
+ } else {
+ node = serializable_iface->serialize_property (serializable, name,
+ value, pspec);
+ }
+
+ return node;
}
static gboolean
ephy_bookmark_json_serializable_deserialize_property (JsonSerializable *serializable,
- const gchar *property_name,
+ const gchar *name,
GValue *value,
GParamSpec *pspec,
- JsonNode *property_node)
+ JsonNode *node)
{
- return serializable_iface->deserialize_property (serializable,
- property_name,
- value,
- pspec,
- property_node);
+ if (g_strcmp0 (name, "tags") == 0) {
+ GSequence *tags;
+ JsonArray *array;
+ const char *tag;
+
+ g_assert (JSON_NODE_HOLDS_ARRAY (node));
+ array = json_node_get_array (node);
+ tags = g_sequence_new (g_free);
+
+ for (gsize i = 0; i < json_array_get_length (array); i++) {
+ tag = json_node_get_string (json_array_get_element (array, i));
+ g_sequence_insert_sorted (tags, g_strdup (tag),
+ (GCompareDataFunc)ephy_bookmark_tags_compare, NULL);
+ }
+
+ g_value_set_pointer (value, tags);
+ } else {
+ serializable_iface->deserialize_property (serializable, name,
+ value, pspec, node);
+ }
+
+ return TRUE;
}
static void
@@ -410,7 +447,7 @@ ephy_bookmark_to_bso (EphyBookmark *self)
service = ephy_shell_get_global_sync_service (ephy_shell_get_default ());
sync_key = ephy_sync_crypto_decode_hex (ephy_sync_service_get_token (service, TOKEN_KB));
- serialized = json_gobject_to_data (G_OBJECT (self), &length);
+ serialized = json_gobject_to_data (G_OBJECT (self), NULL);
encrypted = ephy_sync_crypto_aes_256 (AES_256_MODE_ENCRYPT, sync_key,
(guint8 *)serialized, strlen (serialized), &length);
payload = ephy_sync_crypto_base64_urlsafe_encode (encrypted, length, FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]