GtkForm::fill_from_hashtable.
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT([libgtkform], [0.1.2], [azagli@libero.it])
+AC_INIT([libgtkform], [0.1.3], [azagli@libero.it])
AC_CONFIG_SRCDIR([src/form.c])
AC_CONFIG_HEADER([config.h])
gtk_form_field_float_is_changed
gtk_form_field_float_set_as_origin
gtk_form_field_float_set_from_datamodel
+gtk_form_field_float_set_from_hashtable
</SECTION>
<SECTION>
gtk_form_get_sql
gtk_form_fill_from_datamodel
gtk_form_fill_from_table
+gtk_form_get_values_as_hashtable
+gtk_form_fill_from_hashtable
</SECTION>
<SECTION>
gtk_form_field_datetime_is_changed
gtk_form_field_datetime_set_as_origin
gtk_form_field_datetime_set_from_datamodel
+gtk_form_field_datetime_set_from_hashtable
gtk_form_field_datetime_get_tm_from_str
gtk_form_field_datetime_get_str_from_tm
gtk_form_field_datetime_get_gdate_from_tm
gtk_form_filed_boolean_is_changed
gtk_form_field_boolean_set_as_origin
gtk_form_field_boolean_set_from_datamodel
+gtk_form_field_boolean_set_from_hashtable
gtk_form_field_boolean_str_to_boolean
</SECTION>
gtk_form_field_is_changed
gtk_form_field_set_as_origin
gtk_form_field_set_from_datamodel
+gtk_form_field_set_from_hashtable
</SECTION>
<SECTION>
gtk_form_field_text_is_changed
gtk_form_field_text_set_as_origin
gtk_form_field_text_set_from_datamodel
+gtk_form_field_text_set_from_hashtable
</SECTION>
<SECTION>
gtk_form_field_integer_is_changed
gtk_form_field_integer_set_as_origin
gtk_form_field_integer_set_from_datamodel
+gtk_form_field_integer_set_from_hashtable
</SECTION>
<SECTION>
<RETURNS>gboolean </RETURNS>
GtkFormField *field, GdaDataModel *dm, gint row
</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_field_float_set_from_hashtable</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkFormField *field, GHashTable *hashtable
+</FUNCTION>
<MACRO>
<NAME>TYPE_GTK_FORM</NAME>
#define TYPE_GTK_FORM (gtk_form_get_type ())
<RETURNS>gboolean </RETURNS>
GtkForm *form
</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_get_values_as_hashtable</NAME>
+<RETURNS>GHashTable *</RETURNS>
+GtkForm *form
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_fill_from_hashtable</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkForm *form, GHashTable *hashtable
+</FUNCTION>
<MACRO>
<NAME>TYPE_GTK_FORM_WIDGET_ENTRY</NAME>
#define TYPE_GTK_FORM_WIDGET_ENTRY (gtk_form_widget_entry_get_type ())
GtkFormField *field, GdaDataModel *dm, gint row
</FUNCTION>
<FUNCTION>
+<NAME>gtk_form_field_datetime_set_from_hashtable</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkFormField *field, GHashTable *hashtable
+</FUNCTION>
+<FUNCTION>
<NAME>gtk_form_field_datetime_get_tm_from_str</NAME>
<RETURNS>struct tm *</RETURNS>
const gchar *str, const gchar *format
GtkFormField *field, GdaDataModel *dm, gint row
</FUNCTION>
<FUNCTION>
+<NAME>gtk_form_field_boolean_set_from_hashtable</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkFormField *field, GHashTable *hashtable
+</FUNCTION>
+<FUNCTION>
<NAME>gtk_form_field_boolean_str_to_boolean</NAME>
<RETURNS>gboolean </RETURNS>
const gchar *value
gboolean (*is_changed) (GtkFormField *field);
void (*set_as_origin) (GtkFormField *field);
gboolean (*set_from_datamodel) (GtkFormField *field, GdaDataModel *dm, gint row);
+ gboolean (*set_from_hashtable) (GtkFormField *field, GHashTable *hashtable);
};
</STRUCT>
<FUNCTION>
<RETURNS>gboolean </RETURNS>
GtkFormField *field, GdaDataModel *dm, gint row
</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_field_set_from_hashtable</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkFormField *field, GHashTable *hashtable
+</FUNCTION>
<MACRO>
<NAME>TYPE_GTK_FORM_FIELD_TEXT</NAME>
#define TYPE_GTK_FORM_FIELD_TEXT (gtk_form_field_text_get_type ())
<RETURNS>gboolean </RETURNS>
GtkFormField *field, GdaDataModel *dm, gint row
</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_field_text_set_from_hashtable</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkFormField *field, GHashTable *hashtable
+</FUNCTION>
<MACRO>
<NAME>TYPE_GTK_FORM_WIDGET_TEXTVIEW</NAME>
#define TYPE_GTK_FORM_WIDGET_TEXTVIEW (gtk_form_widget_textview_get_type ())
<RETURNS>gboolean </RETURNS>
GtkFormField *field, GdaDataModel *dm, gint row
</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_field_integer_set_from_hashtable</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkFormField *field, GHashTable *hashtable
+</FUNCTION>
<MACRO>
<NAME>TYPE_GTK_FORM_WIDGET_RADIO</NAME>
#define TYPE_GTK_FORM_WIDGET_RADIO (gtk_form_widget_radio_get_type ())
-8% symbol docs coverage.
+7% symbol docs coverage.
24 symbols documented.
2 symbols incomplete.
-291 not documented.
+299 not documented.
GTK_FORM
gtk_form_field_boolean_new
gtk_form_field_boolean_set_as_origin
gtk_form_field_boolean_set_from_datamodel
+gtk_form_field_boolean_set_from_hashtable
gtk_form_field_boolean_str_to_boolean (value)
gtk_form_field_clear
gtk_form_field_datetime_clear
gtk_form_field_datetime_replace_str
gtk_form_field_datetime_set_as_origin
gtk_form_field_datetime_set_from_datamodel
+gtk_form_field_datetime_set_from_hashtable
gtk_form_field_float_clear
gtk_form_field_float_get_type
gtk_form_field_float_get_value
gtk_form_field_float_new
gtk_form_field_float_set_as_origin
gtk_form_field_float_set_from_datamodel
+gtk_form_field_float_set_from_hashtable
gtk_form_field_get_field_name
gtk_form_field_get_gtk_form_widget
gtk_form_field_get_type
gtk_form_field_integer_new
gtk_form_field_integer_set_as_origin
gtk_form_field_integer_set_from_datamodel
+gtk_form_field_integer_set_from_hashtable
gtk_form_field_is_auto_increment
gtk_form_field_is_changed
gtk_form_field_is_empty
gtk_form_field_new
gtk_form_field_new_from_gtk_form_widget
gtk_form_field_set_from_datamodel
+gtk_form_field_set_from_hashtable
gtk_form_field_text_clear
gtk_form_field_text_get_type
gtk_form_field_text_get_value
gtk_form_field_text_new
gtk_form_field_text_set_as_origin
gtk_form_field_text_set_from_datamodel
+gtk_form_field_text_set_from_hashtable
gtk_form_filed_boolean_is_changed
gtk_form_fill_from_datamodel
+gtk_form_fill_from_hashtable
gtk_form_fill_from_table
gtk_form_get_field_from_name
gtk_form_get_form_field_from_name
gtk_form_get_sql
gtk_form_get_table
gtk_form_get_type
+gtk_form_get_values_as_hashtable
gtk_form_get_widget_from_name
gtk_form_is_changed
gtk_form_key_add_field
IS_GTK_FORM_WIDGET_RADIO_CLASS
TYPE_GTK_FORM_WIDGET_RADIO
gtk_form_field_boolean_set_as_origin
+gtk_form_field_boolean_set_from_hashtable
gtk_form_field_boolean_str_to_boolean
gtk_form_field_datetime_get_gdate_from_tm
gtk_form_field_datetime_get_now
gtk_form_field_datetime_get_tm_from_str
gtk_form_field_datetime_is_changed
gtk_form_field_datetime_set_as_origin
+gtk_form_field_datetime_set_from_hashtable
gtk_form_field_float_is_changed
gtk_form_field_float_set_as_origin
+gtk_form_field_float_set_from_hashtable
gtk_form_field_get_form_widget
gtk_form_field_integer_is_changed
gtk_form_field_integer_set_as_origin
+gtk_form_field_integer_set_from_hashtable
gtk_form_field_is_auto_increment
gtk_form_field_is_changed
gtk_form_field_is_to_save
gtk_form_field_set_as_origin
+gtk_form_field_set_from_hashtable
gtk_form_field_text_is_changed
gtk_form_field_text_set_as_origin
+gtk_form_field_text_set_from_hashtable
gtk_form_filed_boolean_is_changed
+gtk_form_fill_from_hashtable
gtk_form_fill_from_table
gtk_form_get_form_field_from_name
gtk_form_get_form_field_from_widget
gtk_form_get_key
gtk_form_get_objects_by_name
gtk_form_get_table
+gtk_form_get_values_as_hashtable
gtk_form_get_widgets
gtk_form_is_changed
gtk_form_load_from_file
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
return ret;
}
+/**
+ * gtk_form_field_set_from_hashtable:
+ * @field: a #GtkFormField object.
+ * @hashtable: a #GHashTable object.
+ *
+ */
+gboolean
+gtk_form_field_set_from_hashtable (GtkFormField *field, GHashTable *hashtable)
+{
+ gboolean ret = FALSE;
+
+ GtkFormFieldPrivate *priv = GTK_FORM_FIELD_GET_PRIVATE (field);
+
+ g_return_val_if_fail (hashtable != NULL, FALSE);
+
+ if (IS_GTK_FORM_FIELD (field) && GTK_FORM_FIELD_GET_CLASS (field)->set_from_hashtable != NULL)
+ {
+ ret = GTK_FORM_FIELD_GET_CLASS (field)->set_from_hashtable (field, hashtable);
+ }
+
+ return ret;
+}
+
/* PRIVATE */
static void
gtk_form_field_set_property (GObject *object,
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
gboolean (*is_changed) (GtkFormField *field);
void (*set_as_origin) (GtkFormField *field);
gboolean (*set_from_datamodel) (GtkFormField *field, GdaDataModel *dm, gint row);
+ gboolean (*set_from_hashtable) (GtkFormField *field, GHashTable *hashtable);
};
GType gtk_form_field_get_type (void) G_GNUC_CONST;
void gtk_form_field_set_as_origin (GtkFormField *field);
gboolean gtk_form_field_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
+gboolean gtk_form_field_set_from_hashtable (GtkFormField *field, GHashTable *hashtable);
G_END_DECLS
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifdef HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
#include <string.h>
+#include <glib/gi18n-lib.h>
+
#include "widget.h"
#include "fieldboolean.h"
/**
* gtk_form_field_boolean_set_from_datamodel:
* @field: a #GtkFormField object.
- * @dm:
+ * @dm: a #GdaDataModel object.
* @row:
*
*/
field_name = gtk_form_field_get_field_name (field);
- if (gdaex_data_model_get_field_value_boolean_at (dm, row, field_name))
+ if (field_name != NULL && g_strcmp0 (g_strstrip (field_name), "") != 0)
{
- value = g_strdup_printf ("TRUE");
+ priv->original_value = gdaex_data_model_get_field_value_boolean_at (dm, row, field_name);
+ if (priv->original_value)
+ {
+ value = g_strdup_printf ("TRUE");
+ }
+ else
+ {
+ value = g_strdup_printf ("FALSE");
+ }
+ ret = gtk_form_field_boolean_set_value_stringify (field, value);
}
else
{
- value = g_strdup_printf ("FALSE");
+ g_warning (_("GtkFormField hasn't a field name."));
}
- ret = gtk_form_field_boolean_set_value_stringify (field, value);
- priv->original_value = gtk_form_field_boolean_str_to_boolean (value);
+ g_free (field_name);
+ g_free (value);
+
+ return ret;
+}
+
+/**
+ * gtk_form_field_boolean_set_from_hashtable:
+ * @field: a #GtkFormField object.
+ * @hashtable: a #GHashTable object.
+ *
+ */
+gboolean
+gtk_form_field_boolean_set_from_hashtable (GtkFormField *field, GHashTable *hashtable)
+{
+ gboolean ret = FALSE;
+ GtkFormFieldBooleanPrivate *priv;
+ gchar *field_name;
+ GValue *gval;
+ gchar *value;
+
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_BOOLEAN (field), FALSE);
+ g_return_val_if_fail (hashtable != NULL, FALSE);
+
+ priv = GTK_FORM_FIELD_BOOLEAN_GET_PRIVATE (GTK_FORM_FIELD_BOOLEAN (field));
+
+ field_name = gtk_form_field_get_field_name (field);
+ if (field_name != NULL && g_strcmp0 (g_strstrip (field_name), "") != 0)
+ {
+ gval = (GValue *)g_hash_table_lookup (hashtable, field_name);
+ if (gval == NULL)
+ {
+ priv->original_value = FALSE;
+ ret = gtk_form_field_boolean_set_value_stringify (field, "FALSE");
+ }
+ else
+ {
+ priv->original_value = g_value_get_boolean (gval);
+ if (priv->original_value)
+ {
+ value = g_strdup_printf ("TRUE");
+ }
+ else
+ {
+ value = g_strdup_printf ("FALSE");
+ }
+ ret = gtk_form_field_boolean_set_value_stringify (field, value);
+ }
+ }
+ else
+ {
+ g_warning (_("GtkFormField hasn't a field name."));
+ }
g_free (field_name);
g_free (value);
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
void gtk_form_field_boolean_set_as_origin (GtkFormField *field);
gboolean gtk_form_field_boolean_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
+gboolean gtk_form_field_boolean_set_from_hashtable (GtkFormField *field, GHashTable *hashtable);
gboolean gtk_form_field_boolean_str_to_boolean (const gchar *value);
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
field_class->is_changed = gtk_form_field_datetime_is_changed;
field_class->set_as_origin = gtk_form_field_datetime_set_as_origin;
field_class->set_from_datamodel = gtk_form_field_datetime_set_from_datamodel;
+ field_class->set_from_hashtable = gtk_form_field_datetime_set_from_hashtable;
g_object_class_install_property (object_class, PROP_DEFAULT,
g_param_spec_pointer ("default",
return ret;
}
+/**
+ * gtk_form_field_datetime_set_from_hashtable:
+ * @field: a #GtkFormField object.
+ * @hashtable: a #GHashTable object.
+ *
+ */
+gboolean
+gtk_form_field_datetime_set_from_hashtable (GtkFormField *field, GHashTable *hashtable)
+{
+ gboolean ret;
+ GtkFormFieldDateTimePrivate *priv;
+ gchar *field_name;
+ GValue *gval;
+ struct tm *datetime;
+ gchar *value;
+
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), FALSE);
+ g_return_val_if_fail (hashtable != NULL, FALSE);
+
+ ret = FALSE;
+
+ priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (GTK_FORM_FIELD_DATETIME (field));
+
+ field_name = (gchar *)gtk_form_field_get_field_name (field);
+ if (field_name != NULL && g_strcmp0 (g_strstrip (field_name), "") != 0)
+ {
+ gval = (GValue *)g_hash_table_lookup (hashtable, field_name);
+ if (gval == NULL)
+ {
+ priv->original_value = NULL;
+ ret = gtk_form_field_datetime_set_value_stringify (field, "");
+ }
+ else
+ {
+ datetime = (struct tm *)g_value_get_pointer (gval);
+
+ value = gtk_form_field_datetime_get_str_from_tm (datetime, priv->display_format);
+
+ ret = gtk_form_field_datetime_set_value_stringify (field, value);
+
+ priv->original_value = g_memdup (datetime, sizeof (struct tm));
+
+ g_free (value);
+ }
+ }
+ else
+ {
+ g_warning (_("GtkFormField hasn't a field name."));
+ }
+
+ g_free (field_name);
+
+ return ret;
+}
+
/**
* gtk_form_field_datetime_get_tm_from_str:
* @str: the #gchar to be parsed.
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
void gtk_form_field_datetime_set_as_origin (GtkFormField *field);
gboolean gtk_form_field_datetime_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
+gboolean gtk_form_field_datetime_set_from_hashtable (GtkFormField *field, GHashTable *hashtable);
struct tm *gtk_form_field_datetime_get_tm_from_str (const gchar *str, const gchar *format);
gchar *gtk_form_field_datetime_get_str_from_tm (struct tm *datetime, const gchar *format);
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifdef HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
#include <locale.h>
+#include <glib/gi18n-lib.h>
+
#include "widget.h"
#include "fieldfloat.h"
field_class->is_changed = gtk_form_field_float_is_changed;
field_class->set_as_origin = gtk_form_field_float_set_as_origin;
field_class->set_from_datamodel = gtk_form_field_float_set_from_datamodel;
+ field_class->set_from_hashtable = gtk_form_field_float_set_from_hashtable;
g_object_class_install_property (object_class, PROP_DEFAULT,
g_param_spec_float ("default",
return ret;
}
+/**
+ * gtk_form_field_float_set_from_hashtable:
+ * @field: a #GtkFormField object.
+ * @hashtable: a #GHashTable object.
+ *
+ */
+gboolean
+gtk_form_field_float_set_from_hashtable (GtkFormField *field, GHashTable *hashtable)
+{
+ gboolean ret = FALSE;
+ GtkFormFieldFloatPrivate *priv;
+ GValue *gval;
+ gchar *field_name;
+
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_FLOAT (field), FALSE);
+ g_return_val_if_fail (hashtable != NULL, FALSE);
+
+ priv = GTK_FORM_FIELD_FLOAT_GET_PRIVATE (GTK_FORM_FIELD_FLOAT (field));
+
+ field_name = gtk_form_field_get_field_name (field);
+ if (field_name != NULL && g_strcmp0 (g_strstrip (field_name), "") != 0)
+ {
+ gval = (GValue *)g_hash_table_lookup (hashtable, field_name);
+ if (gval == NULL)
+ {
+ priv->original_value = 0.0;
+
+ setlocale (LC_NUMERIC, "");
+ ret = gtk_form_field_float_set_value_stringify (field, "0.0");
+ }
+ else
+ {
+ priv->original_value = g_value_get_float (gval);
+
+ setlocale (LC_NUMERIC, "");
+ ret = gtk_form_field_float_set_value_stringify (field, g_strdup_printf ("%f", priv->original_value));
+ }
+ }
+ else
+ {
+ g_warning (_("GtkFormField hasn't a field name."));
+ }
+
+ g_free (field_name);
+
+ return ret;
+}
+
/* PRIVATE */
static void
gtk_form_field_float_set_property (GObject *object,
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
void gtk_form_field_float_set_as_origin (GtkFormField *field);
gboolean gtk_form_field_float_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
+gboolean gtk_form_field_float_set_from_hashtable (GtkFormField *field, GHashTable *hashtable);
G_END_DECLS
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifdef HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
+
#include "widget.h"
#include "fieldinteger.h"
field_class->is_changed = gtk_form_field_integer_is_changed;
field_class->set_as_origin = gtk_form_field_integer_set_as_origin;
field_class->set_from_datamodel = gtk_form_field_integer_set_from_datamodel;
+ field_class->set_from_hashtable = gtk_form_field_integer_set_from_hashtable;
g_object_class_install_property (object_class, PROP_DEFAULT,
g_param_spec_int ("default",
return ret;
}
+/**
+ * gtk_form_field_integer_set_from_hashtable:
+ * @field: a #GtkFormField object.
+ * @hashtable: a #GHashTable object.
+ *
+ */
+gboolean
+gtk_form_field_integer_set_from_hashtable (GtkFormField *field, GHashTable *hashtable)
+{
+ gboolean ret = FALSE;
+ GtkFormFieldIntegerPrivate *priv;
+ GValue *gval;
+ gchar *field_name;
+
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_INTEGER (field), FALSE);
+ g_return_val_if_fail (hashtable != NULL, FALSE);
+
+ priv = GTK_FORM_FIELD_INTEGER_GET_PRIVATE (GTK_FORM_FIELD_INTEGER (field));
+
+ field_name = gtk_form_field_get_field_name (field);
+ if (field_name != NULL && g_strcmp0 (g_strstrip (field_name), "") != 0)
+ {
+ gval = (GValue *)g_hash_table_lookup (hashtable, field_name);
+ if (gval == NULL)
+ {
+ priv->original_value = 0;
+ ret = gtk_form_field_integer_set_value_stringify (field, "0");
+ }
+ else
+ {
+ priv->original_value = g_value_get_int (gval);
+ ret = gtk_form_field_integer_set_value_stringify (field, g_strdup_printf ("%d", priv->original_value));
+ }
+
+ g_free (field_name);
+ }
+
+ return ret;
+}
+
/* PRIVATE */
static void
gtk_form_field_integer_set_property (GObject *object,
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
void gtk_form_field_integer_set_as_origin (GtkFormField *field);
gboolean gtk_form_field_integer_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
+gboolean gtk_form_field_integer_set_from_hashtable (GtkFormField *field, GHashTable *hashtable);
G_END_DECLS
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifdef HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
+
#include "widget.h"
#include "fieldtext.h"
field_class->is_changed = gtk_form_field_text_is_changed;
field_class->set_as_origin = gtk_form_field_text_set_as_origin;
field_class->set_from_datamodel = gtk_form_field_text_set_from_datamodel;
+ field_class->set_from_hashtable = gtk_form_field_text_set_from_hashtable;
g_object_class_install_property (object_class, PROP_DEFAULT,
g_param_spec_string ("default",
return ret;
}
+/**
+ * gtk_form_field_text_set_from_hashtable:
+ * @field: a #GtkFormField object.
+ * @hashtable: a #GHashTable object.
+ *
+ */
+gboolean
+gtk_form_field_text_set_from_hashtable (GtkFormField *field, GHashTable *hashtable)
+{
+ gboolean ret = FALSE;
+ GtkFormFieldTextPrivate *priv;
+ GValue *gval;
+ gchar *field_name;
+
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_TEXT (field), FALSE);
+ g_return_val_if_fail (hashtable != NULL, FALSE);
+
+ priv = GTK_FORM_FIELD_TEXT_GET_PRIVATE (GTK_FORM_FIELD_TEXT (field));
+
+ field_name = gtk_form_field_get_field_name (field);
+ if (field_name != NULL && g_strcmp0 (g_strstrip (field_name), "") != 0)
+ {
+ gval = (GValue *)g_hash_table_lookup (hashtable, field_name);
+ if (gval == NULL)
+ {
+ priv->original_value = g_strdup ("");
+ ret = gtk_form_field_text_set_value_stringify (field, "");
+ }
+ else
+ {
+ priv->original_value = g_strdup (g_value_get_string (gval));
+ ret = gtk_form_field_text_set_value_stringify (field, priv->original_value);
+ }
+ g_free (field_name);
+ }
+
+ return ret;
+}
+
/* PRIVATE */
static void
gtk_form_field_text_set_property (GObject *object,
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
void gtk_form_field_text_set_as_origin (GtkFormField *field);
gboolean gtk_form_field_text_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
+gboolean gtk_form_field_text_set_from_hashtable (GtkFormField *field, GHashTable *hashtable);
G_END_DECLS
GSList *fields;
gboolean ret = TRUE;
GtkFormField *field;
- gchar *field_name;
g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
return ret;
}
+/**
+ * gtk_form_get_values_as_hashtable:
+ * @form: a #GtkForm object.
+ *
+ */
+GHashTable
+*gtk_form_get_values_as_hashtable (GtkForm *form)
+{
+ GtkFormPrivate *priv;
+ GSList *fields;
+ GtkFormField *field;
+ gchar *field_name;
+ GValue *gval;
+ GHashTable *ht;
+
+ g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+
+ priv = GTK_FORM_GET_PRIVATE (form);
+
+ fields = priv->fields;
+
+ if (fields != NULL)
+ {
+ ht = g_hash_table_new (g_str_hash, g_str_equal);
+ }
+
+ while (fields != NULL)
+ {
+ field = (GtkFormField *)fields->data;
+
+ field_name = gtk_form_field_get_field_name (field);
+
+ gval = gtk_form_field_get_value (field);
+ if (gval != NULL)
+ {
+ /* TODO check if the field already exists */
+ g_hash_table_insert (ht, field_name, gval);
+ }
+
+ fields = g_slist_next (fields);
+ }
+
+ return ht;
+}
+
+/**
+ * gtk_form_fill_from_hashtable:
+ * @form: a #GtkForm object.
+ * @hashtable: a @GHashTable object.
+ *
+ */
+gboolean
+gtk_form_fill_from_hashtable (GtkForm *form, GHashTable *hashtable)
+{
+ GtkFormPrivate *priv;
+ GSList *fields;
+ GtkFormField *field;
+
+ gboolean ret;
+
+ g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
+ g_return_val_if_fail (hashtable != NULL, FALSE);
+
+ priv = GTK_FORM_GET_PRIVATE (form);
+
+ fields = priv->fields;
+
+ while (fields != NULL)
+ {
+ field = (GtkFormField *)fields->data;
+
+ gtk_form_field_set_from_hashtable (field, hashtable);
+
+ fields = g_slist_next (fields);
+ }
+
+ return ret;
+}
+
/* PRIVATE */
static void
gtk_form_set_property (GObject *object,
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
gboolean gtk_form_fill_from_datamodel (GtkForm *form, GdaDataModel *dm, gint row);
gboolean gtk_form_fill_from_table (GtkForm *form);
+GHashTable *gtk_form_get_values_as_hashtable (GtkForm *form);
+gboolean gtk_form_fill_from_hashtable (GtkForm *form, GHashTable *hashtable);
+
G_END_DECLS