static void zak_form_hashtable_provider_dispose (GObject *gobject);
static void zak_form_hashtable_provider_finalize (GObject *gobject);
+static GValue *zak_form_hashtable_provider_new_gvalue_from_element (ZakFormElement *element);
+
static GHashTable *zak_form_hashtable_provider_get_group (ZakFormHashtableProvider *zak_form_hashtable_provider, GPtrArray *elements);
static gboolean zak_form_hashtable_provider_load (ZakFormIProvider *provider, GPtrArray *elements);
return zak_form_hashtable_provider;
}
+static gchar
+*zak_form_hashtable_provider_gvalue_stringify (GValue *value)
+{
+ gchar *ret;
+
+ if (G_VALUE_HOLDS (value, G_TYPE_STRING))
+ {
+ ret = (gchar *)g_value_get_string (value);
+ }
+ else if (G_VALUE_HOLDS (value, G_TYPE_INT))
+ {
+ ret = g_strdup_printf ("%d", g_value_get_int (value));
+ }
+ else if (G_VALUE_HOLDS (value, G_TYPE_FLOAT))
+ {
+ ret = g_strdup_printf ("%f", g_value_get_float (value));
+ }
+ else if (G_VALUE_HOLDS (value, G_TYPE_DOUBLE))
+ {
+ ret = g_strdup_printf ("%f", g_value_get_float (value));
+ }
+ else if (G_VALUE_HOLDS (value, G_TYPE_BOOLEAN))
+ {
+ ret = g_strdup (g_value_get_boolean (value) ? "TRUE" : "FALSE");
+ }
+ else if (G_VALUE_HOLDS (value, G_TYPE_DATE_TIME))
+ {
+ ret = zak_utils_gdatetime_format ((GDateTime *)g_value_get_boxed (value), "%F %T");
+ }
+ else
+ {
+ ret = g_strdup ("");
+ }
+
+ return g_strdup (ret);
+}
+
+/**
+ * zak_form_hashtable_provider_load_from_hashtable:
+ * @provider:
+ * @elements:
+ * @ht:
+ */
+void
+zak_form_hashtable_provider_load_from_hashtable (ZakFormHashtableProvider *provider, GPtrArray *elements, GHashTable *ht)
+{
+ guint i;
+
+ for (i = 0; i < elements->len; i++)
+ {
+ ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (elements, i);
+ if (zak_form_element_get_to_load (element))
+ {
+ zak_form_element_set_value (element,
+ zak_form_hashtable_provider_gvalue_stringify ((GValue *)g_hash_table_lookup (ht, zak_form_element_get_name (element))));
+ zak_form_element_set_as_original_value (element);
+ }
+ }
+}
+
+/**
+ * zak_form_hashtable_provider_get_values_as_hashtable:
+ * @provider:
+ * @elements:
+ *
+ * Returns:
+ */
+GHashTable
+*zak_form_hashtable_provider_get_values_as_hashtable (ZakFormHashtableProvider *provider, GPtrArray *elements)
+{
+ GHashTable *ht;
+
+ guint i;
+
+ ht = g_hash_table_new (g_str_hash, g_str_equal);
+
+ for (i = 0; i < elements->len; i++)
+ {
+ ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (elements, i);
+ if (zak_form_element_get_to_save (element))
+ {
+ g_hash_table_insert (ht,
+ zak_form_element_get_name (element),
+ zak_form_hashtable_provider_new_gvalue_from_element (element));
+ }
+ }
+
+ return ht;
+}
+
/* PRIVATE */
static void
zak_form_hashtable_provider_set_property (GObject *object,
{
gboolean ret;
- guint i;
-
GHashTable *group;
ZakFormHashtableProviderPrivate *priv = zak_form_hashtable_provider_get_instance_private (ZAK_FORM_HASHTABLE_PROVIDER (provider));
group = zak_form_hashtable_provider_get_group (ZAK_FORM_HASHTABLE_PROVIDER (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))
- {
- zak_form_element_set_value (element, g_hash_table_lookup (group, zak_form_element_get_name (element)));
- zak_form_element_set_as_original_value (element);
- }
- }
+ zak_form_hashtable_provider_load_from_hashtable (ZAK_FORM_HASHTABLE_PROVIDER (provider), elements, group);
return ret;
}