static void zak_form_json_provider_dispose (GObject *gobject);
static void zak_form_json_provider_finalize (GObject *gobject);
-static JsonObject *zak_form_json_provider_get_object (ZakFormIProvider *provider, GPtrArray *elements);
+static JsonObject *zak_form_json_provider_get_object (ZakFormIProvider *provider, GPtrArray *elements, guint *idx);
static gboolean zak_form_json_provider_load (ZakFormIProvider *provider, GPtrArray *elements);
static gboolean zak_form_json_provider_insert (ZakFormIProvider *provider, GPtrArray *elements);
}
static JsonObject
-*zak_form_json_provider_get_object (ZakFormIProvider *provider, GPtrArray *elements)
+*zak_form_json_provider_get_object (ZakFormIProvider *provider, GPtrArray *elements, guint *idx)
{
gchar **fields;
gchar **values;
gboolean ok;
- JsonNode *node;
+ JsonNode *jnode;
JsonArray *ar;
JsonObject *obj;
}
}
- if (k > 0)
- {
- k--;
- }
- else
+ if (k < 1)
{
/* no key fields */
return NULL;
l = json_array_get_length (ar);
for (i = 0; i < l; i++)
{
- JsonNode *jnode;
-
jnode = json_array_get_element (ar, i);
obj = json_node_get_object (jnode);
ok = TRUE;
for (j = 0; j < k; j++)
{
- if (g_strcmp0 (json_object_get_string_member (obj, fields[k]), values[k]) != 0)
+ if (g_strcmp0 (json_object_get_string_member (obj, fields[j]), values[j]) != 0)
{
ok = FALSE;
break;
if (ok)
{
+ if (idx != NULL)
+ {
+ *idx = i;
+ }
break;
}
}
ret = TRUE;
- obj = zak_form_json_provider_get_object (provider, elements);
+ obj = zak_form_json_provider_get_object (provider, elements, NULL);
for (i = 0; i < elements->len; i++)
{
ret = TRUE;
- obj = zak_form_json_provider_get_object (provider, elements);
+ obj = zak_form_json_provider_get_object (provider, elements, NULL);
if (obj == NULL)
{
JsonObject *obj;
- guint i;
-
- GError *error;
+ guint idx;
ZakFormJsonProviderPrivate *priv = zak_form_json_provider_get_instance_private (ZAK_FORM_JSON_PROVIDER (provider));
ret = TRUE;
- obj = zak_form_json_provider_get_object (provider, elements);
+ obj = zak_form_json_provider_get_object (provider, elements, &idx);
- for (i = 0; i < elements->len; i++)
- {
- ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (elements, 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); */
-
-
- 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 (obj != NULL)
+ {g_warning ("IDX %d", idx);
+ json_array_remove_element (json_node_get_array (priv->root), idx);
+ if (priv->filename != NULL)
+ {
+ zak_form_json_provider_write_to_file (ZAK_FORM_JSON_PROVIDER (provider));
}
}