parser = json_parser_new ();
error = NULL;
- if (!json_parser_load_from_data (parser, data, size, &error))
+ if (!json_parser_load_from_data (parser, data, length, &error))
{
g_warning ("Unable to read data\n. %s",
error != NULL && error->message != NULL ? error->message : "No details.");
parent_class->finalize (gobject);
}
-static gchar
-*zak_form_json_provider_get_group (GPtrArray *elements)
+static JsonObject
+*zak_form_json_provider_get_object (ZakFormIProvider *provider, GPtrArray *elements)
{
gchar *ret;
guint i;
+ JsonNode *node;
+ JsonPath *path;
+ JsonArray *ar;
+ JsonObject *obj;
+
+ ZakFormJsonProviderPrivate *priv = zak_form_json_provider_get_instance_private (ZAK_FORM_JSON_PROVIDER (provider));
+
key = g_string_new ("");
for (i = 0; i < elements->len; i++)
{
if (key->len > 0)
{
- ret = g_strdup (key->str + 1);
+ ret = g_strdup_printf ("KEY:%s", key->str + 1);
}
else
{
- ret = g_strdup ("THE_KEY");
+ ret = g_strdup ("KEY:");
}
g_string_free (key, TRUE);
- return ret;
+ path = json_path_new ();
+ json_path_compile (path, g_strdup_printf ("$[*].%s", ret), NULL);
+
+ node = json_path_match (path, priv->root);
+
+ ar = json_node_get_array (node);;
+ obj = json_array_get_object_element (ar, 0);
+
+ return obj;
}
static gboolean
guint i;
- gchar *group;
-
- GError *error;
-
- ZakFormJsonProviderPrivate *priv = zak_form_json_provider_get_instance_private (ZAK_FORM_JSON_PROVIDER (provider));
+ JsonObject *obj;
ret = TRUE;
- group = zak_form_json_provider_get_group (elements);
+ obj = zak_form_json_provider_get_object (provider, elements);
for (i = 0; i < elements->len; i++)
{
ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (elements, i);
if (zak_form_element_get_to_load (element))
{
- error = NULL;
- zak_form_element_set_value (element, g_key_file_get_string (priv->kfile, group, zak_form_element_get_name (element), &error));
+ zak_form_element_set_value (element, json_object_get_string_member (obj, zak_form_element_get_name (element)));
zak_form_element_set_as_original_value (element);
}
}
- g_free (group);
-
return ret;
}
guint i;
GValue *value;
- gchar *group;
+ JsonObject *obj;
GError *error;
ret = TRUE;
- group = zak_form_json_provider_get_group (elements);
+ obj = zak_form_json_provider_get_object (provider, elements);
for (i = 0; i < elements->len; i++)
{
{
value = zak_form_element_unformat_gvalue (element, zak_form_element_get_value_gvalue (element));
- g_key_file_set_string (priv->kfile, group,
- zak_form_element_get_name (element),
- g_value_get_string (value));
+ /* g_key_file_set_string (priv->kfile, group, */
+ /* zak_form_element_get_name (element), */
+ /* g_value_get_string (value)); */
error = NULL;
- if (!g_key_file_save_to_file (priv->kfile, priv->filename, &error)
- || error != NULL)
- {
- g_warning ("Unable to write to file «%s»: %s.",
- priv->filename,
- error != NULL && error->message != NULL ? error->message : "no details");
- }
+ /* if (!g_key_file_save_to_file (priv->kfile, priv->filename, &error) */
+ /* || error != NULL) */
+ /* { */
+ /* g_warning ("Unable to write to file «%s»: %s.", */
+ /* priv->filename, */
+ /* error != NULL && error->message != NULL ? error->message : "no details"); */
+ /* } */
+
g_value_unset (value);
}
}
- g_free (group);
-
return ret;
}
{
gboolean ret;
- gchar *group;
+ JsonObject *obj;
guint i;
ret = TRUE;
- group = zak_form_json_provider_get_group (elements);
+ obj = zak_form_json_provider_get_object (provider, elements);
for (i = 0; i < elements->len; i++)
{
if (zak_form_element_get_to_save (element))
{
error = NULL;
- g_key_file_remove_key (priv->kfile, group,
- zak_form_element_get_name (element),
- &error);
+ /* g_key_file_remove_key (priv->kfile, group, */
+ /* zak_form_element_get_name (element), */
+ /* &error); */
+
error = NULL;
- if (!g_key_file_save_to_file (priv->kfile, priv->filename, &error)
- || error != NULL)
- {
- g_warning ("Unable to write to file «%s»: %s.",
- priv->filename,
- error != NULL && error->message != NULL ? error->message : "no details");
- }
+ /* if (!g_key_file_save_to_file (priv->kfile, priv->filename, &error) */
+ /* || error != NULL) */
+ /* { */
+ /* g_warning ("Unable to write to file «%s»: %s.", */
+ /* priv->filename, */
+ /* error != NULL && error->message != NULL ? error->message : "no details"); */
+ /* } */
+
}
}
- g_free (group);
-
return ret;
}