]> saetta.ns0.it Git - libgtkform/commitdiff
Added functions GtkForm::get_values_as_hashtable and and hashtable 0.1.3
authorAndrea Zagli <azagli@libero.it>
Mon, 19 Jul 2010 09:21:56 +0000 (11:21 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 19 Jul 2010 09:21:56 +0000 (11:21 +0200)
GtkForm::fill_from_hashtable.

19 files changed:
configure.ac
docs/reference/libgtkform-decl-list.txt
docs/reference/libgtkform-decl.txt
docs/reference/libgtkform-undocumented.txt
docs/reference/libgtkform-unused.txt
src/field.c
src/field.h
src/fieldboolean.c
src/fieldboolean.h
src/fielddatetime.c
src/fielddatetime.h
src/fieldfloat.c
src/fieldfloat.h
src/fieldinteger.c
src/fieldinteger.h
src/fieldtext.c
src/fieldtext.h
src/form.c
src/form.h

index 9f539b03fcbca643df2f6865474abb2a603b5862..f9198e70efa1811f7cf2f5b07df6b7724e2ffe54 100644 (file)
@@ -2,7 +2,7 @@
 # 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])
 
index ae19f43e768e9d37cca9aa88c90da1e7134e8a78..619bf22b59140a640028c18ef150910b6008b9c7 100644 (file)
@@ -19,6 +19,7 @@ gtk_form_field_float_is_empty
 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>
@@ -63,6 +64,8 @@ GtkFormSqlType
 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>
@@ -104,6 +107,7 @@ gtk_form_field_datetime_is_empty
 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
@@ -131,6 +135,7 @@ gtk_form_field_boolean_is_empty
 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>
 
@@ -233,6 +238,7 @@ gtk_form_field_is_empty
 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>
@@ -256,6 +262,7 @@ gtk_form_field_text_is_empty
 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>
@@ -320,6 +327,7 @@ gtk_form_field_integer_is_empty
 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>
index 6cfd4ce9924c3bc9b9ad27e6eaec845f64b0537f..1bbddf2aadec230114fac9287be1550771612aba 100644 (file)
@@ -92,6 +92,11 @@ GtkFormField *field
 <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 ())
@@ -296,6 +301,16 @@ GtkForm *form, GdaDataModel *dm, gint row
 <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 ())
@@ -460,6 +475,11 @@ GtkFormField *field
 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 
@@ -574,6 +594,11 @@ GtkFormField *field
 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 
@@ -911,6 +936,7 @@ struct _GtkFormFieldClass
                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>
@@ -988,6 +1014,11 @@ GtkFormField *field
 <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 ())
@@ -1082,6 +1113,11 @@ GtkFormField *field
 <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 ())
@@ -1345,6 +1381,11 @@ GtkFormField *field
 <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 ())
index 972b6db6c1f27d7033a7c52d90ce27a57f6cc303..4e051ae2812ab84015a6e7ca1a778e235e9d4795 100644 (file)
@@ -1,7 +1,7 @@
-8% symbol docs coverage.
+7% symbol docs coverage.
 24 symbols documented.
 2 symbols incomplete.
-291 not documented.
+299 not documented.
 
 
 GTK_FORM
@@ -123,6 +123,7 @@ gtk_form_field_boolean_is_empty
 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
@@ -141,6 +142,7 @@ gtk_form_field_datetime_new
 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
@@ -151,6 +153,7 @@ gtk_form_field_float_is_empty
 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
@@ -167,6 +170,7 @@ gtk_form_field_integer_is_empty
 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
@@ -174,6 +178,7 @@ gtk_form_field_is_to_save
 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
@@ -184,8 +189,10 @@ gtk_form_field_text_is_empty
 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
@@ -199,6 +206,7 @@ gtk_form_get_objects_by_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
index 86f142b9e55e3f337c2bca719035783231f6b40a..d6d29f1e78a199966c812e64e4350c7299994e4f 100644 (file)
@@ -7,6 +7,7 @@ IS_GTK_FORM_WIDGET_RADIO
 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
@@ -14,18 +15,24 @@ gtk_form_field_datetime_get_str_from_tm
 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
@@ -35,6 +42,7 @@ gtk_form_get_gtkbuilder
 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
index a7d7096bb457f6a8ea7a25a87bc308040300c00e..7a791478936067502a32c4436da753fa752195b8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -362,6 +362,29 @@ gtk_form_field_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint r
        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,
index 7d19f721ac9431619607bfc73f1dd7cd37dc03d1..194175127da2d61800465a3dd8c1a969a274cf5e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -58,6 +58,7 @@ struct _GtkFormFieldClass
                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;
@@ -84,6 +85,7 @@ gboolean gtk_form_field_is_changed (GtkFormField *field);
 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
index e9e5d47f037d0fbd6bf38dc78771d22c4187d5b2..ae342989064f419e4936747927f23ce7e4aa1b64 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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"
 
@@ -272,7 +278,7 @@ gtk_form_field_boolean_set_as_origin (GtkFormField *field)
 /**
  * gtk_form_field_boolean_set_from_datamodel:
  * @field: a #GtkFormField object.
- * @dm:
+ * @dm: a #GdaDataModel object.
  * @row:
  *
  */
@@ -291,17 +297,77 @@ gtk_form_field_boolean_set_from_datamodel (GtkFormField *field, GdaDataModel *dm
 
        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);
index c1a9ca45c0238422e09dc288f6c5e443d19afe71..7485d6d79b356c26ac5e3721d22dc169c7b7bd38 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -64,6 +64,7 @@ gboolean gtk_form_filed_boolean_is_changed (GtkFormField *field);
 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);
 
index 8b5b8596d262ba9804ee2999ce6c8cc1b37c7c05..59478589beedb4b3f37843129cab00ceaa1df5d4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -92,6 +92,7 @@ gtk_form_field_datetime_class_init (GtkFormFieldDateTimeClass *klass)
        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",
@@ -405,6 +406,61 @@ gtk_form_field_datetime_set_from_datamodel (GtkFormField *field, GdaDataModel *d
        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.
index 09dba45254d54baa3796c67ca218097702b5c2c9..b5acc9acc93c4b0978acdeff27377b969807049a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -71,6 +71,7 @@ gboolean gtk_form_field_datetime_is_changed (GtkFormField *field);
 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);
index f0f2a1e1fb3a182dd8b4434f3091bcb17959bb20..b8e0235cfd7e426b5a0c9ddc69faf336a033032c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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"
 
@@ -70,6 +76,7 @@ gtk_form_field_float_class_init (GtkFormFieldFloatClass *klass)
        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",
@@ -315,6 +322,54 @@ gtk_form_field_float_set_from_datamodel (GtkFormField *field, GdaDataModel *dm,
        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,
index f048571cc5e8b540adb9b892b83fc2ad5794a543..b1dc528910348787f82947b9570a7c6a5540181f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -64,6 +64,7 @@ gboolean gtk_form_field_float_is_changed (GtkFormField *field);
 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
index 06afcb2853c2bf44ea6036a6afc0523b578e32b6..611f790a3f3a96c2cd341cc488f045fcff0e73d6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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"
 
@@ -68,6 +74,7 @@ gtk_form_field_integer_class_init (GtkFormFieldIntegerClass *klass)
        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",
@@ -292,6 +299,46 @@ gtk_form_field_integer_set_from_datamodel (GtkFormField *field, GdaDataModel *dm
        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,
index e559ac9d438bd30ebf89794cd0a5806037f39c1c..0d55392e94401557a7fe51481aa4c77b0b6434e4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -64,6 +64,7 @@ gboolean gtk_form_field_integer_is_changed (GtkFormField *field);
 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
index 72db199a470108899165adc5fdeb341339451f49..c3b03f206a535b43e0a654cf5ae07cda908c147c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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"
 
@@ -68,6 +74,7 @@ gtk_form_field_text_class_init (GtkFormFieldTextClass *klass)
        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",
@@ -303,6 +310,45 @@ gtk_form_field_text_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, g
        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,
index 5a96a513a640dafc3f015ca1e1b1bcd16d82655b..c693aa80c4efb7fa79d3144100b32478878e7fe3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -64,6 +64,7 @@ gboolean gtk_form_field_text_is_changed (GtkFormField *field);
 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
index d431340583afd09c368d6bee1b01bf80254e1f30..731c5834aa81e4c04093167acdf6db59e1655e4c 100644 (file)
@@ -1441,7 +1441,6 @@ gtk_form_fill_from_datamodel (GtkForm *form, GdaDataModel *dm, gint row)
        GSList *fields;
        gboolean ret = TRUE;
        GtkFormField *field;
-       gchar *field_name;
 
        g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
 
@@ -1494,6 +1493,85 @@ gtk_form_fill_from_table (GtkForm *form)
        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,
index 65ea0b9c16a55a8b9d58d21a20499ad2c1ea0e99..83bd90c56aa33ae06890f31bfc7f98a240ddbfe1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -111,6 +111,9 @@ gchar *gtk_form_get_sql (GtkForm *form, GtkFormSqlType type);
 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