#include <config.h>
#endif
+#include <locale.h>
+
#include <libzakform/libzakform.h>
#include <libzakutils/libzakutils.h>
static void zak_form_ini_provider_dispose (GObject *gobject);
static void zak_form_ini_provider_finalize (GObject *gobject);
+static gchar *zak_form_ini_provider_get_group (GPtrArray *elements);
+
static gboolean zak_form_ini_provider_load (ZakFormIProvider *provider, GPtrArray *elements);
static gboolean zak_form_ini_provider_insert (ZakFormIProvider *provider, GPtrArray *elements);
static gboolean zak_form_ini_provider_update (ZakFormIProvider *provider, GPtrArray *elements);
{
GKeyFile *kfile;
gchar *filename;
- gchar *group;
} ZakFormIniProviderPrivate;
struct _ZakFormIniProvider
ZakFormIniProviderPrivate *priv = zak_form_ini_provider_get_instance_private (zak_form_ini_provider);
priv->kfile = NULL;
- priv->group = NULL;
+ priv->filename = NULL;
}
static void
* zak_form_ini_provider_new_from_gkeyfile:
* @kfile:
* @filename:
- * @group:
*
* Returns: the newly created #ZakFormIniProvider object.
*/
ZakFormIniProvider
-*zak_form_ini_provider_new_from_gkeyfile (GKeyFile *kfile, const gchar *filename, const gchar *group)
+*zak_form_ini_provider_new_from_gkeyfile (GKeyFile *kfile, const gchar *filename)
{
ZakFormIniProvider *zak_form_ini_provider;
ZakFormIniProviderPrivate *priv;
priv->kfile = g_key_file_ref (kfile);
priv->filename = g_strdup (filename);
- priv->group = g_strdup (group);
return zak_form_ini_provider;
}
/**
* zak_form_ini_provider_new_from_file:
* @filename:
- * @group:
*
* Returns: the newly created #ZakFormIniProvider object.
*/
ZakFormIniProvider
-*zak_form_ini_provider_new_from_file (const gchar *filename, const gchar *group)
+*zak_form_ini_provider_new_from_file (const gchar *filename)
{
GKeyFile *kfile;
ZakFormIniProvider *zak_form_ini_provider;
- kfile = g_key_file_new ();
+ g_return_val_if_fail (filename != NULL && g_strcmp0 (filename, "") != 0, NULL);
if (!g_file_test (filename, G_FILE_TEST_EXISTS))
{
g_object_unref (gf);
}
+ kfile = g_key_file_new ();
+
error = NULL;
if (!g_key_file_load_from_file (kfile, filename, G_KEY_FILE_NONE, &error))
{
error != NULL && error->message != NULL ? error->message : "No details.");
return NULL;
}
- zak_form_ini_provider = zak_form_ini_provider_new_from_gkeyfile (kfile, filename, group);
+ zak_form_ini_provider = zak_form_ini_provider_new_from_gkeyfile (kfile, filename);
return zak_form_ini_provider;
}
unformatted = zak_utils_unformat_money_full (value, thousands_saparator, NULL);
- ret = zak_utils_format_money_full (unformatted, 0, "", "");
+ ret = zak_utils_format_money_full (unformatted, 0, "", NULL);
}
else if (g_ascii_strcasecmp (type, "float") == 0)
{
unformatted = zak_utils_unformat_money_full (value, thousands_saparator, currency_symbol);
- ret = zak_utils_format_money_full (unformatted, 10, "", "");
+ char *cur = g_strdup (setlocale (LC_NUMERIC, NULL));
+
+ setlocale (LC_NUMERIC, "C");
+
+ ret = g_strdup_printf ("%f", unformatted);
+
+ setlocale (LC_NUMERIC, cur);
+
+ g_free (cur);
}
else if (g_ascii_strcasecmp (type, "string") == 0)
{
return ret;
}
+static gchar
+*zak_form_ini_provider_get_group (GPtrArray *elements)
+{
+ gchar *ret;
+
+ GString *key;
+
+ gchar *value;
+
+ guint i;
+
+ key = g_string_new ("");
+ for (i = 0; i < elements->len; i++)
+ {
+ ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (elements, i);
+
+ if (zak_form_element_get_is_key (element))
+ {
+ value = zak_form_ini_provider_new_gvalue_from_element (element);
+ g_string_append_printf (key, "|%s", value);
+ g_free (value);
+ }
+ }
+
+ if (key->len > 0)
+ {
+ ret = g_strdup (key->str + 1);
+ }
+ else
+ {
+ ret = g_strdup ("THE_KEY");
+ }
+
+ g_string_free (key, TRUE);
+
+ return ret;
+}
+
static gboolean
zak_form_ini_provider_load (ZakFormIProvider *provider, GPtrArray *elements)
{
guint i;
+ gchar *group;
+
GError *error;
ZakFormIniProviderPrivate *priv = zak_form_ini_provider_get_instance_private (ZAK_FORM_INI_PROVIDER (provider));
ret = TRUE;
+ group = zak_form_ini_provider_get_group (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_value (priv->kfile, priv->group, zak_form_element_get_name (element), &error));
+ zak_form_element_set_value (element, g_key_file_get_value (priv->kfile, group, zak_form_element_get_name (element), &error));
zak_form_element_set_as_original_value (element);
}
}
+ g_free (group);
+
return ret;
}
guint i;
gchar *value;
+ gchar *group;
GError *error;
ret = TRUE;
+ group = zak_form_ini_provider_get_group (elements);
+
for (i = 0; i < elements->len; i++)
{
ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (elements, i);
{
value = zak_form_ini_provider_new_gvalue_from_element (element);
- g_key_file_set_value (priv->kfile, priv->group,
- zak_form_element_get_name (element),
- value);
+ g_key_file_set_string (priv->kfile, group,
+ zak_form_element_get_name (element),
+ value);
error = NULL;
if (!g_key_file_save_to_file (priv->kfile, priv->filename, &error)
}
}
+ g_free (group);
+
return ret;
}
{
gboolean ret;
+ gchar *group;
+
guint i;
GError *error;
ret = TRUE;
+ group = zak_form_ini_provider_get_group (elements);
+
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, priv->group,
+ g_key_file_remove_key (priv->kfile, group,
zak_form_element_get_name (element),
&error);
}
}
+ g_free (group);
+
return ret;
}