[frogr] Save groups and photosets too
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr] Save groups and photosets too
- Date: Sun, 11 Nov 2012 00:06:22 +0000 (UTC)
commit c21f6d4312163d6c0e0c2873fc195d3b04f76da5
Author: Mario Sanchez Prada <msanchez2 gnome org>
Date: Thu Nov 8 13:25:05 2012 +0100
Save groups and photosets too
src/frogr-controller.c | 10 +++++++---
src/frogr-serializer.c | 43 +++++++++++++++++++++++++++++++------------
src/frogr-serializer.h | 5 ++++-
3 files changed, 42 insertions(+), 16 deletions(-)
---
diff --git a/src/frogr-controller.c b/src/frogr-controller.c
index f93e3c0..0fa0c49 100644
--- a/src/frogr-controller.c
+++ b/src/frogr-controller.c
@@ -2742,16 +2742,20 @@ frogr_controller_save_current_session (FrogrController *self)
FrogrControllerPrivate *priv = NULL;
FrogrMainViewModel *mainview_model = NULL;
GSList *pictures = NULL;
+ GSList *photosets = NULL;
+ GSList *groups = NULL;
g_return_if_fail(FROGR_IS_CONTROLLER (self));
priv = FROGR_CONTROLLER_GET_PRIVATE (self);
mainview_model = frogr_main_view_get_model (priv->mainview);
- if (frogr_main_view_model_n_pictures (mainview_model) > 0)
- pictures = frogr_main_view_model_get_pictures_as_loaded (mainview_model);
+ pictures = frogr_main_view_model_get_pictures_as_loaded (mainview_model);
+ photosets = frogr_main_view_model_get_photosets (mainview_model);
+ groups = frogr_main_view_model_get_groups (mainview_model);
- frogr_serializer_save_current_session (priv->serializer, pictures);
+ frogr_serializer_save_current_session (priv->serializer,
+ pictures, photosets, groups);
}
#ifdef GTK_API_VERSION_3
diff --git a/src/frogr-serializer.c b/src/frogr-serializer.c
index caa0d14..477fd69 100644
--- a/src/frogr-serializer.c
+++ b/src/frogr-serializer.c
@@ -130,33 +130,52 @@ frogr_serializer_get_instance (void)
return FROGR_SERIALIZER (g_object_new (FROGR_TYPE_SERIALIZER, NULL));
}
-void
-frogr_serializer_save_current_session (FrogrSerializer *self, GSList *pictures)
+static JsonArray *
+serialize_list_to_json_array (GSList *list)
{
- FrogrSerializerPrivate *priv = NULL;
- JsonGenerator *json_gen = NULL;
JsonArray *json_array = NULL;
JsonNode *json_node = NULL;
- JsonNode *root_node = NULL;
- JsonObject *root_object = NULL;
GSList *item = NULL;
- gchar *session_path = NULL;
- GError *error = NULL;
-
- g_return_if_fail(FROGR_IS_SERIALIZER (self));
/* Generate a JsonArray with contents */
json_array = json_array_new ();
- for (item = pictures; item; item = g_slist_next (item))
+ for (item = list; item; item = g_slist_next (item))
{
json_node = json_gobject_serialize (G_OBJECT (item->data));
if (json_node)
json_array_add_element (json_array, json_node);
}
- /* Generate the root JsonNode */
+ return json_array;
+}
+
+void
+frogr_serializer_save_current_session (FrogrSerializer *self,
+ GSList *pictures,
+ GSList *photosets,
+ GSList *groups)
+{
+ FrogrSerializerPrivate *priv = NULL;
+ JsonGenerator *json_gen = NULL;
+ JsonArray *json_array = NULL;
+ JsonNode *root_node = NULL;
+ JsonObject *root_object = NULL;
+ gchar *session_path = NULL;
+ GError *error = NULL;
+
+ g_return_if_fail(FROGR_IS_SERIALIZER (self));
+
root_object = json_object_new ();
+
+ json_array = serialize_list_to_json_array (pictures);
json_object_set_array_member (root_object, "pictures", json_array);
+
+ json_array = serialize_list_to_json_array (photosets);
+ json_object_set_array_member (root_object, "photosets", json_array);
+
+ json_array = serialize_list_to_json_array (groups);
+ json_object_set_array_member (root_object, "groups", json_array);
+
root_node = json_node_new (JSON_NODE_OBJECT);
json_node_set_object (root_node, root_object);
diff --git a/src/frogr-serializer.h b/src/frogr-serializer.h
index 5045bc3..27cee81 100644
--- a/src/frogr-serializer.h
+++ b/src/frogr-serializer.h
@@ -56,7 +56,10 @@ GType frogr_serializer_get_type (void) G_GNUC_CONST;
FrogrSerializer* frogr_serializer_get_instance (void);
-void frogr_serializer_save_current_session (FrogrSerializer *self, GSList *pictures);
+void frogr_serializer_save_current_session (FrogrSerializer *self,
+ GSList *pictures,
+ GSList *photosets,
+ GSList *groups);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]