Some bugfixes and adjustments.
authorAndrea Zagli <azagli@libero.it>
Wed, 9 Sep 2009 11:00:19 +0000 (13:00 +0200)
committerAndrea Zagli <azagli@libero.it>
Wed, 9 Sep 2009 11:00:19 +0000 (13:00 +0200)
Added property GtkFormField::to-save.

data/gtkform.dtd
src/field.c
src/field.h
src/form.c

index ad8db76ff3447420b40ce737134c90385bf5f4dd..f2de6e0f147da8fd42b2594612d4f1195af454a6 100644 (file)
 
 <!ELEMENT column-field (#PCDATA)>
 
-<!ELEMENT field (obligatory?, default?, is-key?, type?, display-format?)>
+<!ELEMENT field (no-save?, obligatory?, default?, is-key?, type?, display-format?)>
 
 <!ATTLIST field
        type  (boolean | datetime | float | integer | text)  #REQUIRED
        name  CDATA  #REQUIRED
 >
 
+<!ELEMENT to-save (y | n)>
 <!ELEMENT obligatory (#PCDATA)>
 <!ELEMENT default (#PCDATA)>
 <!ELEMENT is-key (#PCDATA)>
index 82b66461ee8519de04488c4d383229ed8531154c..d16a03dddd7deb3432e050179b670fe7e79462c1 100644 (file)
@@ -23,6 +23,7 @@ enum
 {
        PROP_0,
        PROP_FIELD,
+       PROP_TO_SAVE,
        PROP_OBLIGATORY,
        PROP_DATAMODEL,
        PROP_WIDGET
@@ -47,6 +48,7 @@ struct _GtkFormFieldPrivate
        {
                gchar *field;
                gboolean is_key;
+               gboolean to_save;
                gboolean obligatory;
 
                GdaDataModel *dm;
@@ -76,6 +78,13 @@ gtk_form_field_class_init (GtkFormFieldClass *klass)
                                                              "",
                                                              G_PARAM_READWRITE));
 
+       g_object_class_install_property (object_class, PROP_TO_SAVE,
+                                        g_param_spec_boolean ("to-save",
+                                                              "Whether save the field or not",
+                                                              "Whether the field should be included or not on sql INSERT INTO and UPDATE",
+                                                              TRUE,
+                                                              G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
+
        g_object_class_install_property (object_class, PROP_OBLIGATORY,
                                         g_param_spec_boolean ("obligatory",
                                                               "Obligatory",
@@ -227,6 +236,23 @@ gtk_form_field_clear (GtkFormField *field)
        return ret;
 }
 
+/**
+ * gtk_form_field_is_to_save:
+ * @field: a #GtkFormField object.
+ *
+ */
+gboolean
+gtk_form_field_is_to_save (GtkFormField *field)
+{
+       GtkFormFieldPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM_FIELD (field), FALSE);
+
+       priv = GTK_FORM_FIELD_GET_PRIVATE (field);
+
+       return priv->to_save;
+}
+
 /**
  * gtk_form_field_is_empty:
  * @field: a #GtkFormField object.
@@ -323,6 +349,10 @@ gtk_form_field_set_property (GObject *object,
                                priv->field = g_strstrip (g_value_dup_string (value));
                                break;
 
+                       case PROP_TO_SAVE:
+                               priv->to_save = g_value_get_boolean (value);
+                               break;
+
                        case PROP_OBLIGATORY:
                                priv->obligatory = g_value_get_boolean (value);
                                break;
@@ -357,6 +387,10 @@ gtk_form_field_get_property (GObject *object,
                                g_value_set_string (value, gtk_form_field_get_field_name (field));
                                break;
 
+                       case PROP_TO_SAVE:
+                               g_value_set_boolean (value, priv->to_save);
+                               break;
+
                        case PROP_OBLIGATORY:
                                g_value_set_boolean (value, priv->obligatory);
                                break;
index 0a51a13957aa84acac1c56570f38965948971bdf..d6a2e774295327ca04ffb89ef0b3d80c71cf5382 100644 (file)
@@ -74,6 +74,8 @@ const gchar *gtk_form_field_get_value_sql (GtkFormField *field);
 
 gboolean gtk_form_field_clear (GtkFormField *field);
 
+gboolean gtk_form_field_is_to_save (GtkFormField *field);
+
 gboolean gtk_form_field_is_empty (GtkFormField *field);
 
 gboolean gtk_form_field_is_changed (GtkFormField *field);
index 2cd115e1ea402fded4a6969a187e3025a1f033b7..7e55067fdb8c9ea2da019e616d943a64be6a0006 100644 (file)
@@ -316,7 +316,13 @@ GtkForm
                                                                                                                                        while (node_field != NULL)
                                                                                                                                                {
                                                                                                                                                        prop = (gchar *)xmlNodeGetContent (node_field);
-                                                                                                                                                       if (xmlStrcmp (node_field->name, (const xmlChar *)"obligatory") == 0)
+                                                                                                                                                       if (xmlStrcmp (node_field->name, (const xmlChar *)"to-save") == 0)
+                                                                                                                                                               {
+                                                                                                                                                                       g_object_set (G_OBJECT (field),
+                                                                                                                                                                                                "to-save", gtk_form_field_boolean_str_to_boolean (prop),
+                                                                                                                                                                                                NULL);
+                                                                                                                                                               }
+                                                                                                                                                       else if (xmlStrcmp (node_field->name, (const xmlChar *)"obligatory") == 0)
                                                                                                                                                                {
                                                                                                                                                                        g_object_set (G_OBJECT (field),
                                                                                                                                                                                                 "obligatory", gtk_form_field_boolean_str_to_boolean (prop),
@@ -851,7 +857,8 @@ gtk_form_check (GtkForm *form, gboolean with_key, GtkFormWidget **form_widget,
        GtkWidget *widget;
 
        gboolean ret = TRUE;
-       gboolean obl = FALSE;
+       gboolean to_save;
+       gboolean obl;
 
        g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
 
@@ -869,10 +876,11 @@ gtk_form_check (GtkForm *form, gboolean with_key, GtkFormWidget **form_widget,
                        field = (GtkFormField *)fields->data;
 
                        g_object_get (G_OBJECT (field),
+                                     "to-save", &to_save,
                                      "obligatory", &obl,
                                      NULL);
 
-                       if (obl && gtk_form_field_is_empty (field))
+                       if (to_save && obl && gtk_form_field_is_empty (field))
                                {
                                        ret = FALSE;
 
@@ -1118,7 +1126,8 @@ gchar
 
                        field_name = gtk_form_field_get_field_name (field);
 
-                       if (field_name != NULL && g_strcmp0 (field_name, "") != 0)
+                       if (field_name != NULL && g_strcmp0 (field_name, "") != 0
+                           && g_strstr_len (fields_names, -1, field_name) == NULL)
                                {
                                        switch (type)
                                                {
@@ -1127,17 +1136,21 @@ gchar
                                                                break;
 
                                                        case GTK_FORM_SQL_INSERT:
-                                                               value = gtk_form_field_get_value_sql (field);
-                                                               if (value != NULL)
+                                                               if (gtk_form_field_is_to_save (field))
                                                                        {
-                                                                               fields_names = g_strconcat (fields_names, field_name, ", ", NULL);
-                                                                               values = g_strconcat (values, value, ", ", NULL);
+                                                                               value = gtk_form_field_get_value_sql (field);
+                                                                               if (value != NULL)
+                                                                                       {
+                                                                                               fields_names = g_strconcat (fields_names, field_name, ", ", NULL);
+                                                                                               values = g_strconcat (values, value, ", ", NULL);
+                                                                                       }
                                                                        }
                                                                break;
 
                                                        case GTK_FORM_SQL_UPDATE:
-                                                               if (!IS_GTK_FORM_KEY (priv->key) ||
-                                                                   !gtk_form_key_field_is_key (priv->key, field))
+                                                               if (gtk_form_field_is_to_save (field)
+                                                                   && (!IS_GTK_FORM_KEY (priv->key) ||
+                                                                   !gtk_form_key_field_is_key (priv->key, field)))
                                                                        {
                                                                                value = gtk_form_field_get_value_sql (field);
                                                                                if (value != NULL)
@@ -1180,11 +1193,11 @@ gchar
                                break;
                }
 
-       if (IS_GTK_FORM_KEY (priv->key))
+       if (IS_GTK_FORM_KEY (priv->key)
+           && (type == GTK_FORM_SQL_SELECT || type == GTK_FORM_SQL_UPDATE || type == GTK_FORM_SQL_DELETE))
                {
                        where = gtk_form_key_get_sql (priv->key);
-                       if ((type == GTK_FORM_SQL_SELECT || type == GTK_FORM_SQL_UPDATE || type == GTK_FORM_SQL_DELETE)
-                               && where != NULL && g_strcmp0 (where, "") != 0)
+                       if (where != NULL && g_strcmp0 (where, "") != 0)
                                {
                                        sql = g_strconcat (sql, where, NULL);
                                }