From: Andrea Zagli Date: Mon, 30 Jan 2017 15:28:19 +0000 (+0100) Subject: Use of GValue. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=f2437fbdcfa91c7c29ced02391ab2cb0761fab7f;p=zakform%2Fhashtable Use of GValue. --- diff --git a/src/form.c b/src/form.c index 2e121a6..0c6e569 100644 --- a/src/form.c +++ b/src/form.c @@ -236,7 +236,66 @@ zak_form_hashtable_provider_load (ZakFormIProvider *provider, GPtrArray *element } } - g_free (group); + return ret; +} + +static GValue +*zak_form_hashtable_provider_new_gvalue_from_element (ZakFormElement *element) +{ + GValue *ret; + + gchar *value; + gchar *type; + GHashTable *format; + + value = zak_form_element_get_value (element); + type = zak_form_element_get_provider_type (element); + format = zak_form_element_get_format (element); + + if (g_ascii_strcasecmp (type, "integer") == 0) + { + gchar *thousands_saparator; + gdouble unformatted; + + thousands_saparator = (gchar *)g_hash_table_lookup (format, "thousands_separator"); + + unformatted = zak_utils_unformat_money_full (value, thousands_saparator, NULL); + + ret = zak_utils_gvalue_new_int ((gint)unformatted); + } + else if (g_ascii_strcasecmp (type, "float") == 0) + { + gchar *thousands_saparator; + gchar *currency_symbol; + gdouble unformatted; + + thousands_saparator = (gchar *)g_hash_table_lookup (format, "thousands_separator"); + currency_symbol = (gchar *)g_hash_table_lookup (format, "currency_symbol"); + + unformatted = zak_utils_unformat_money_full (value, thousands_saparator, currency_symbol); + ret = zak_utils_gvalue_new_float (unformatted); + } + else if (g_ascii_strcasecmp (type, "string") == 0) + { + ret = zak_utils_gvalue_new_string (value); + } + else if (g_ascii_strcasecmp (type, "boolean") == 0) + { + ret = zak_utils_gvalue_new_boolean (g_strcmp0 (value, "TRUE") == 0); + } + else if (g_ascii_strcasecmp (type, "date") == 0 + || g_ascii_strcasecmp (type, "time") == 0 + || g_ascii_strcasecmp (type, "datetime") == 0) + { + GDateTime *gdt; + + gchar *datetime_format; + + datetime_format = (gchar *)g_hash_table_lookup (format, "content"); + gdt = zak_utils_get_gdatetime_from_string (value, datetime_format); + + ret = zak_utils_gvalue_new_gdatetime (gdt); + } return ret; } @@ -248,7 +307,6 @@ zak_form_hashtable_provider_insert (ZakFormIProvider *provider, GPtrArray *eleme guint i; - gchar *value; GHashTable *group; ZakFormHashtableProviderPrivate *priv = zak_form_hashtable_provider_get_instance_private (ZAK_FORM_HASHTABLE_PROVIDER (provider)); @@ -262,18 +320,12 @@ zak_form_hashtable_provider_insert (ZakFormIProvider *provider, GPtrArray *eleme ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (elements, i); if (zak_form_element_get_to_save (element)) { - value = zak_form_element_unformat (element, NULL); - g_hash_table_insert (group, zak_form_element_get_name (element), - value); - - g_free (value); + zak_form_hashtable_provider_new_gvalue_from_element (element)); } } - g_free (group); - return ret; } @@ -308,7 +360,5 @@ zak_form_hashtable_provider_delete (ZakFormIProvider *provider, GPtrArray *eleme } } - g_free (group); - return ret; }