]> saetta.ns0.it Git - libgtkform/commitdiff
Added display-format property to GtkFormFieldDateTime.
authorAndrea Zagli <azagli@libero.it>
Sat, 5 Sep 2009 14:16:28 +0000 (16:16 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 5 Sep 2009 14:16:28 +0000 (16:16 +0200)
Reimplemented function GtkFormFieldDateTime::get_tm_from_str to be more
accurate and extendable.
Menaged datetime-type property on xml definition for
GtkFormFieldDateTime.

data/gtkform.dtd
docs/reference/libgtkform-decl.txt
docs/reference/libgtkform-undocumented.txt
docs/reference/libgtkform.args
docs/reference/tmpl/fielddatetime.sgml
src/field.c
src/fielddatetime.c
src/fielddatetime.h
src/form.c
test/main.c
test/test_db.xml

index 202f7c168d28ac953dbe5df44e0313b2744b77ab..ad8db76ff3447420b40ce737134c90385bf5f4dd 100644 (file)
@@ -14,7 +14,7 @@
 
 <!ELEMENT column-field (#PCDATA)>
 
-<!ELEMENT field (obligatory?, default?, is-key?)>
+<!ELEMENT field (obligatory?, default?, is-key?, type?, display-format?)>
 
 <!ATTLIST field
        type  (boolean | datetime | float | integer | text)  #REQUIRED
@@ -24,3 +24,5 @@
 <!ELEMENT obligatory (#PCDATA)>
 <!ELEMENT default (#PCDATA)>
 <!ELEMENT is-key (#PCDATA)>
+<!ELEMENT datetime-type (date | time | datetime)>
+<!ELEMENT display-format (#PCDATA)>
index e418092832c26592939e3840f61143cf33ba8e1d..62bcf876c26f635a2ed8cf658c32efcd9592162f 100644 (file)
@@ -526,7 +526,7 @@ GtkFormField *field, GdaDataModel *dm, gint row
 <FUNCTION>
 <NAME>gtk_form_field_datetime_get_tm_from_str</NAME>
 <RETURNS>struct tm *</RETURNS>
-const gchar *str
+const gchar *str, const gchar *format
 </FUNCTION>
 <FUNCTION>
 <NAME>gtk_form_field_datetime_get_str_from_tm</NAME>
index fcb07871a4d46d2a3caaa9bd75597409200d75de..18721ba2151722ac243e30fea1c7e31b3201be1d 100644 (file)
@@ -1,5 +1,5 @@
 7% symbol docs coverage.
-19 symbols documented.
+20 symbols documented.
 1 symbols incomplete.
 271 not documented.
 
@@ -126,6 +126,7 @@ gtk_form_field_boolean_set_from_datamodel
 gtk_form_field_boolean_str_to_boolean (value)
 gtk_form_field_clear
 gtk_form_field_datetime_clear
+gtk_form_field_datetime_get_str_format
 gtk_form_field_datetime_get_str_from_tm
 gtk_form_field_datetime_get_tm_from_str
 gtk_form_field_datetime_get_type
@@ -149,7 +150,6 @@ gtk_form_field_float_new
 gtk_form_field_float_set_as_origin
 gtk_form_field_float_set_from_datamodel
 gtk_form_field_get_field_name
-gtk_form_field_get_str_format
 gtk_form_field_get_type
 gtk_form_field_get_value
 gtk_form_field_get_value_sql
index 4fda5913d59786a71d80e6117aefccf17dab735d..ab99c825419d84e6f3dbfcaceffcd37835b7a737 100644 (file)
 <DEFAULT></DEFAULT>
 </ARG>
 
+<ARG>
+<NAME>GtkFormFieldDateTime::display-format</NAME>
+<TYPE>gchar*</TYPE>
+<RANGE></RANGE>
+<FLAGS>rwx</FLAGS>
+<NICK>Display format</NICK>
+<BLURB>Display format.</BLURB>
+<DEFAULT>"%Y-%m-%d %H:%M:%S"</DEFAULT>
+</ARG>
+
 <ARG>
 <NAME>GtkFormFieldDateTime::type</NAME>
 <TYPE>gint</TYPE>
index a97eb789c6696b4bce4dd2489f9dcce3257c5db8..9706ebe0780f1157f15d5a8431bd7a4d4627db52 100644 (file)
@@ -75,6 +75,11 @@ FormFieldDateTime
 
 </para>
 
+<!-- ##### ARG GtkFormFieldDateTime:display-format ##### -->
+<para>
+
+</para>
+
 <!-- ##### ARG GtkFormFieldDateTime:type ##### -->
 <para>
 
index 218d2598d7683a87653e78fee3855c5072bfc890..82b66461ee8519de04488c4d383229ed8531154c 100644 (file)
@@ -251,7 +251,8 @@ gtk_form_field_is_empty (GtkFormField *field)
  * @field: a #GtkFormField object.
  *
  * Returns: TRUE if the values in the form are changed since last calling to
- * gtk_form_field_clear() or gtk_form_field_set_from_datamodel().
+ * gtk_form_field_clear(), gtk_form_field_set_from_datamodel() or
+ * gtk_form_field_set_as_origin().
  */
 gboolean
 gtk_form_field_is_changed (GtkFormField *field)
index 5af6a417f78de446b94934ad0963db89b91f0543..6cc2bc156dc033168bd360e4dde3e64950f25a87 100644 (file)
@@ -27,7 +27,8 @@ enum
 {
        PROP_0,
        PROP_DEFAULT,
-       PROP_TYPE
+       PROP_TYPE,
+       PROP_DISPLAY_FORMAT
 };
 
 static void gtk_form_field_datetime_class_init (GtkFormFieldDateTimeClass *klass);
@@ -44,7 +45,7 @@ static void gtk_form_field_datetime_get_property (GObject *object,
 
 static gboolean gtk_form_field_datetime_set_value_stringify (GtkFormField *field, const gchar *value);
 
-static gchar *gtk_form_field_get_str_format (GtkFormField *field);
+static gchar *gtk_form_field_datetime_get_str_format (GtkFormFieldDateTime *field);
 
 static gchar *gtk_form_field_datetime_str_replace (const gchar *string,
                                       const gchar *origin,
@@ -59,6 +60,8 @@ struct _GtkFormFieldDateTimePrivate
                struct tm *original_value;
 
                gint type;
+
+               gchar *display_format;
        };
 
 
@@ -97,6 +100,13 @@ gtk_form_field_datetime_class_init (GtkFormFieldDateTimeClass *klass)
                                                           GTK_FORM_FIELD_DATETIME_TYPE_DATETIME,
                                                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
+       g_object_class_install_property (object_class, PROP_DISPLAY_FORMAT,
+                                        g_param_spec_string ("display-format",
+                                                             "Display format",
+                                                             "Display format",
+                                                             "%Y-%m-%d %H:%M:%S",
+                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
        g_type_class_add_private (object_class, sizeof (GtkFormFieldDateTimePrivate));
 }
 
@@ -148,6 +158,7 @@ const gchar
  * gtk_form_field_datetime_get_value:
  * @field: a #GtkFormField object.
  *
+ * Returns: a #GValue of type G_TYPE_POINTER that point to a struct tm.
  */
 const GValue
 *gtk_form_field_datetime_get_value (GtkFormField *field)
@@ -155,14 +166,17 @@ const GValue
        struct tm *datetime;
        GValue *ret;
        const gchar *value;
+       GtkFormFieldDateTimePrivate *priv;
 
        g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), NULL);
 
+       priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (GTK_FORM_FIELD_DATETIME (field));
+
        ret = NULL;
 
        value = gtk_form_field_datetime_get_value_stringify (field);
 
-       datetime = gtk_form_field_datetime_get_tm_from_str (value);
+       datetime = gtk_form_field_datetime_get_tm_from_str (value, priv->display_format);
        if (value != NULL && datetime != NULL)
                {
                        ret = g_malloc0 (sizeof (GValue));
@@ -184,18 +198,21 @@ const gchar
        const gchar *ret;
        const gchar *value;
        const gchar *format;
+       GtkFormFieldDateTimePrivate *priv;
 
        g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), NULL);
 
+       priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (GTK_FORM_FIELD_DATETIME (field));
+
        ret = NULL;
        value = gtk_form_field_datetime_get_value_stringify (field);
-       format = gtk_form_field_get_str_format (field);
+       format = gtk_form_field_datetime_get_str_format (GTK_FORM_FIELD_DATETIME (field));
 
        if (value != NULL)
                {
                        struct tm *datetime;
 
-                       datetime = gtk_form_field_datetime_get_tm_from_str (value);
+                       datetime = gtk_form_field_datetime_get_tm_from_str (value, priv->display_format);
                        if (datetime != NULL)
                                {
                                        gchar *value;
@@ -221,12 +238,9 @@ gtk_form_field_datetime_clear (GtkFormField *field)
 {
        gboolean ret;
        GtkFormFieldDateTimePrivate *priv;
-       gchar *format;
 
        g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), FALSE);
 
-       format = gtk_form_field_get_str_format (field);
-
        priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (field);
        ret = FALSE;
 
@@ -234,7 +248,7 @@ gtk_form_field_datetime_clear (GtkFormField *field)
                {
                        gchar *value;
 
-                       value = gtk_form_field_datetime_get_str_from_tm (priv->default_value, format);
+                       value = gtk_form_field_datetime_get_str_from_tm (priv->default_value, priv->display_format);
                        if (value != NULL)
                                {
                                        ret = gtk_form_field_datetime_set_value_stringify (field, value);
@@ -283,7 +297,8 @@ gtk_form_field_datetime_is_changed (GtkFormField *field)
 
        priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (GTK_FORM_FIELD_DATETIME (field));
 
-       value = gtk_form_field_datetime_get_tm_from_str (gtk_form_field_datetime_get_value_stringify (field));
+       value = gtk_form_field_datetime_get_tm_from_str (gtk_form_field_datetime_get_value_stringify (field),
+                                                        priv->display_format);
 
        if (value != NULL)
                {
@@ -314,7 +329,8 @@ gtk_form_field_datetime_set_as_origin (GtkFormField *field)
 
        priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (GTK_FORM_FIELD_DATETIME (field));
 
-       value = gtk_form_field_datetime_get_tm_from_str (gtk_form_field_datetime_get_value_stringify (field));
+       value = gtk_form_field_datetime_get_tm_from_str (gtk_form_field_datetime_get_value_stringify (field),
+                                                        priv->display_format);
 
        priv->original_value = g_memdup (value, sizeof (struct tm));
 }
@@ -329,23 +345,38 @@ gtk_form_field_datetime_set_as_origin (GtkFormField *field)
 gboolean
 gtk_form_field_datetime_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row)
 {
-       gboolean ret = FALSE;
+       gboolean ret;
        GtkFormFieldDateTimePrivate *priv;
-       const gchar *field_name;
-       const gchar *value;
+       gchar *field_name;
+       struct tm *datetime;
+       gchar *value;
+       gchar *format;
 
        g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), FALSE);
        g_return_val_if_fail (GDA_IS_DATA_MODEL (dm), FALSE);
 
+       ret = FALSE;
+
        priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (GTK_FORM_FIELD_DATETIME (field));
 
-       field_name = gtk_form_field_get_field_name (field);
+       field_name = (gchar *)gtk_form_field_get_field_name (field);
 
-       value = gdaex_data_model_get_field_value_stringify_at (dm, row, field_name);
+       if (field_name != NULL && g_strcmp0 (g_strstrip (field_name), "") != 0)
+               {
+                       datetime = gdaex_data_model_get_field_value_tm_at (dm, row, field_name);
+
+                       value = gtk_form_field_datetime_get_str_from_tm (datetime, priv->display_format);
 
-       ret = gtk_form_field_datetime_set_value_stringify (field, value);
+                       ret = gtk_form_field_datetime_set_value_stringify (field, value);
 
-       priv->original_value = gtk_form_field_datetime_get_tm_from_str (value);
+                       format = gtk_form_field_datetime_get_str_format (GTK_FORM_FIELD_DATETIME (field));
+
+                       priv->original_value = gtk_form_field_datetime_get_tm_from_str (value, format);
+               }
+       else
+               {
+                       g_warning ("GtkFormField hasn't a field name.");
+               }
 
        return ret;
 }
@@ -353,61 +384,100 @@ gtk_form_field_datetime_set_from_datamodel (GtkFormField *field, GdaDataModel *d
 /**
  * gtk_form_field_datetime_get_tm_from_str:
  * @str: the #gchar to be parsed.
+ * @format:
  *
  */
 struct tm
-*gtk_form_field_datetime_get_tm_from_str (const gchar *str)
+*gtk_form_field_datetime_get_tm_from_str (const gchar *str, const gchar *format)
 {
        /* TO DO
         * check if it is a valid date/time
      */
 
-       struct tm *tm;
+       struct tm *ret;
        gchar *new_str;
+       gchar *new_format;
+       gchar **str_tokens;
+       gchar **format_tokens;
+       gchar *delimiters;
+       guint len_strv;
+       guint len_formatv;
+       guint i;
 
        g_return_val_if_fail (str != NULL, NULL);
 
        new_str = g_strstrip (g_strdup (str));
+       if (g_strcmp0 (new_str, "") == 0)
+               {
+                       return NULL;
+               }
+
+       new_format = g_strstrip (g_strdup (format));
+       if (g_strcmp0 (new_format, "") == 0)
+               {
+                       new_format = g_strdup ("%Y-%m-%d %H-%M-%S");
+               }
+
+       /* removes format identifiers to find delimiters */
+       delimiters = gtk_form_field_datetime_str_replace (new_format, "%Y", "");
+       delimiters = gtk_form_field_datetime_str_replace (delimiters, "%m", "");
+       delimiters = gtk_form_field_datetime_str_replace (delimiters, "%d", "");
+       delimiters = gtk_form_field_datetime_str_replace (delimiters, "%H", "");
+       delimiters = gtk_form_field_datetime_str_replace (delimiters, "%M", "");
+       delimiters = gtk_form_field_datetime_str_replace (delimiters, "%S", "");
 
-       if (strcmp (new_str, "") == 0)
+       if (delimiters == NULL || g_strcmp0 (delimiters, "") == 0)
                {
                        return NULL;
                }
 
-       tm = g_malloc0 (sizeof (struct tm));
-       tm->tm_mday = 1;
-       switch (strlen (str))
+       str_tokens = g_strsplit_set (str, delimiters, -1);
+       if (str_tokens == NULL)
                {
-                       case 8:
-                               /* only time */
-                               tm->tm_hour = strtol (g_strndup (new_str, 2), NULL, 10);
-                               tm->tm_min = strtol (g_strndup (new_str + 3, 2), NULL, 10);
-                               tm->tm_sec = strtol (g_strndup (new_str + 6, 2), NULL, 10);
-                               break;
+                       return NULL;
+               }
 
-                       case 10:
-                               /* only date */
-                               tm->tm_year = strtol (g_strndup (new_str, 4), NULL, 10) - 1900;
-                               tm->tm_mon = strtol (g_strndup (new_str + 5, 2), NULL, 10) - 1;
-                               tm->tm_mday = strtol (g_strndup (new_str + 8, 2), NULL, 10);
-                               break;
+       format_tokens = g_strsplit_set (format, delimiters, -1);
+       if (format_tokens == NULL)
+               {
+                       return NULL;
+               }
 
-                       case 19:
-                               /* date & time */
-                               tm->tm_year = strtol (g_strndup (new_str, 4), NULL, 10) - 1900;
-                               tm->tm_mon = strtol (g_strndup (new_str + 5, 2), NULL, 10) - 1;
-                               tm->tm_mday = strtol (g_strndup (new_str + 8, 2), NULL, 10);
-                               tm->tm_hour = strtol (g_strndup (new_str + 11, 2), NULL, 10);
-                               tm->tm_min = strtol (g_strndup (new_str + 14, 2), NULL, 10);
-                               tm->tm_sec = strtol (g_strndup (new_str + 17, 2), NULL, 10);
-                               break;
+       len_strv = g_strv_length (str_tokens);
+       len_formatv = g_strv_length (format_tokens);
 
-                       default:
-                               tm = NULL;
-                               break;
+       ret = g_malloc0 (sizeof (struct tm));
+       ret->tm_mday = 1;
+
+       for (i = 0; i < MIN (len_strv, len_formatv); i++)
+               {
+                       if (g_strcmp0 (format_tokens[i], "%Y") == 0)
+                               {
+                                       ret->tm_year = strtol (str_tokens[i], NULL, 10) - 1900;
+                               }
+                       else if (g_strcmp0 (format_tokens[i], "%m") == 0)
+                               {
+                                       ret->tm_mon = strtol (str_tokens[i], NULL, 10) - 1;
+                               }
+                       else if (g_strcmp0 (format_tokens[i], "%d") == 0)
+                               {
+                                       ret->tm_mday = strtol (str_tokens[i], NULL, 10);
+                               }
+                       else if (g_strcmp0 (format_tokens[i], "%H") == 0)
+                               {
+                                       ret->tm_hour = strtol (str_tokens[i], NULL, 10);
+                               }
+                       else if (g_strcmp0 (format_tokens[i], "%M") == 0)
+                               {
+                                       ret->tm_min = strtol (str_tokens[i], NULL, 10);
+                               }
+                       else if (g_strcmp0 (format_tokens[i], "%S") == 0)
+                               {
+                                       ret->tm_sec = strtol (str_tokens[i], NULL, 10);
+                               }
                }
 
-       return tm;
+       return ret;
 }
 
 /**
@@ -416,7 +486,7 @@ struct tm
  * @format:
  *
  * Returns: a string representation of @datetime based on the format in @format.
- * It interprets a very little subset of format identifier from strftime.
+ * It interprets a very little subset of format identifiers from strftime.
  * %Y: the year with 4 digits.
  * %m: the month with 2 digits.
  * %d: the day with 2 digits.
@@ -469,6 +539,10 @@ gtk_form_field_datetime_set_property (GObject *object,
                                priv->type = g_value_get_int (value);
                                break;
 
+                       case PROP_DISPLAY_FORMAT:
+                               priv->display_format = g_strdup (g_value_get_string (value));
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -495,6 +569,10 @@ gtk_form_field_datetime_get_property (GObject *object,
                                g_value_set_int (value, priv->type);
                                break;
 
+                       case PROP_DISPLAY_FORMAT:
+                               g_value_set_string (value, priv->display_format);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -517,16 +595,19 @@ gtk_form_field_datetime_set_value_stringify (GtkFormField *field, const gchar *v
 }
 
 /**
- * gtk_form_field_get_str_format:
- * @field: a #GtkFormField object.
+ * gtk_form_field_datetime_get_str_format:
+ * @field: a #GtkFormFieldDateTime object.
  *
  */
 static gchar
-*gtk_form_field_get_str_format (GtkFormField *field)
+*gtk_form_field_datetime_get_str_format (GtkFormFieldDateTime *field)
 {
        gchar *format;
+       GtkFormFieldDateTimePrivate *priv;
 
-       GtkFormFieldDateTimePrivate *priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (field);
+       g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), NULL);
+
+       priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (field);
 
        switch (priv->type)
                {
index f56f5b57a82721ec7deec6421b3867a8d1fa080f..a3acef96eca2c99ced79d58b6b883e5f1b93558e 100644 (file)
@@ -72,7 +72,7 @@ void gtk_form_field_datetime_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_datetime_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 
-struct tm *gtk_form_field_datetime_get_tm_from_str (const gchar *str);
+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 9f67e5e1c882bf164cc7ef9f4612faf54f8f5f91..9370a183bc84212864082391da9bfa6c8192c7a8 100644 (file)
@@ -216,27 +216,27 @@ GtkForm
                                                                        widget = NULL;
 
                                                                        type = xmlGetProp (cur, (const xmlChar *)"type");
-                                                                       if (strcmp (type, "checkbox") == 0)
+                                                                       if (g_strcmp0 (type, "checkbox") == 0)
                                                                                {
                                                                                        widget = gtk_form_widget_check_new ();
                                                                                }
-                                                                       else if (strcmp (type, "combobox") == 0)
+                                                                       else if (g_strcmp0 (type, "combobox") == 0)
                                                                                {
                                                                                        widget = gtk_form_widget_combo_box_new ();
                                                                                }
-                                                                       else if (strcmp (type, "entry") == 0)
+                                                                       else if (g_strcmp0 (type, "entry") == 0)
                                                                                {
                                                                                        widget = gtk_form_widget_entry_new ();
                                                                                }
-                                                                       else if (strcmp (type, "label") == 0)
+                                                                       else if (g_strcmp0 (type, "label") == 0)
                                                                                {
                                                                                        widget = gtk_form_widget_label_new ();
                                                                                }
-                                                                       else if (strcmp (type, "spin") == 0)
+                                                                       else if (g_strcmp0 (type, "spin") == 0)
                                                                                {
                                                                                        widget = gtk_form_widget_spin_new ();
                                                                                }
-                                                                       else if (strcmp (type, "textview") == 0)
+                                                                       else if (g_strcmp0 (type, "textview") == 0)
                                                                                {
                                                                                        widget = gtk_form_widget_textview_new ();
                                                                                }
@@ -279,23 +279,23 @@ GtkForm
                                                                                                                        field = NULL;
 
                                                                                                                        type = xmlGetProp (node_widget, (const xmlChar *)"type");
-                                                                                                                       if (strcmp (type, "boolean") == 0)
+                                                                                                                       if (g_strcmp0 (type, "boolean") == 0)
                                                                                                                                {
                                                                                                                                        field = gtk_form_field_boolean_new ();
                                                                                                                                }
-                                                                                                                       else if (strcmp (type, "datetime") == 0)
+                                                                                                                       else if (g_strcmp0 (type, "datetime") == 0)
                                                                                                                                {
                                                                                                                                        field = gtk_form_field_datetime_new ();
                                                                                                                                }
-                                                                                                                       else if (strcmp (type, "float") == 0)
+                                                                                                                       else if (g_strcmp0 (type, "float") == 0)
                                                                                                                                {
                                                                                                                                        field = gtk_form_field_float_new ();
                                                                                                                                }
-                                                                                                                       else if (strcmp (type, "integer") == 0)
+                                                                                                                       else if (g_strcmp0 (type, "integer") == 0)
                                                                                                                                {
                                                                                                                                        field = gtk_form_field_integer_new ();
                                                                                                                                }
-                                                                                                                       else if (strcmp (type, "text") == 0)
+                                                                                                                       else if (g_strcmp0 (type, "text") == 0)
                                                                                                                                {
                                                                                                                                        field = gtk_form_field_text_new ();
                                                                                                                                }
@@ -324,16 +324,16 @@ GtkForm
                                                                                                                                                                }
                                                                                                                                                        else if (xmlStrcmp (node_field->name, (const xmlChar *)"default") == 0)
                                                                                                                                                                {
-                                                                                                                                                                       if (strcmp (type, "boolean") == 0)
+                                                                                                                                                                       if (g_strcmp0 (type, "boolean") == 0)
                                                                                                                                                                                {
                                                                                                                                                                                        gboolean value = gtk_form_field_boolean_str_to_boolean (prop);
                                                                                                                                                                                        g_object_set (G_OBJECT (field), "default", value, NULL);
                                                                                                                                                                                }
-                                                                                                                                                                       else if (strcmp (type, "datetime") == 0)
+                                                                                                                                                                       else if (g_strcmp0 (type, "datetime") == 0)
                                                                                                                                                                                {
                                                                                                                                                                                        struct tm *datetime;
 
-                                                                                                                                                                                       if (strcmp (prop, "now") == 0)
+                                                                                                                                                                                       if (g_strcmp0 (prop, "now") == 0)
                                                                                                                                                                                                {
                                                                                                                                                                                                        time_t time_now;
 
@@ -343,24 +343,24 @@ GtkForm
                                                                                                                                                                                                }
                                                                                                                                                                                        else
                                                                                                                                                                                                {
-                                                                                                                                                                                                       datetime = gtk_form_field_datetime_get_tm_from_str (prop);
+                                                                                                                                                                                                       datetime = gtk_form_field_datetime_get_tm_from_str (prop, "%Y-%m-%d %H:%M:%S");
                                                                                                                                                                                                        if (datetime != NULL)
                                                                                                                                                                                                                {
                                                                                                                                                                                                                        g_object_set (G_OBJECT (field), "default", datetime, NULL);
                                                                                                                                                                                                                }
                                                                                                                                                                                                }
                                                                                                                                                                                }
-                                                                                                                                                                       else if (strcmp (type, "float") == 0)
+                                                                                                                                                                       else if (g_strcmp0 (type, "float") == 0)
                                                                                                                                                                                {
                                                                                                                                                                                        gfloat value = g_strtod (prop, NULL);
                                                                                                                                                                                        g_object_set (G_OBJECT (field), "default", value, NULL);
                                                                                                                                                                                }
-                                                                                                                                                                       else if (strcmp (type, "integer") == 0)
+                                                                                                                                                                       else if (g_strcmp0 (type, "integer") == 0)
                                                                                                                                                                                {
                                                                                                                                                                                        gint value = strtol (prop, NULL, 10);
                                                                                                                                                                                        g_object_set (G_OBJECT (field), "default", value, NULL);
                                                                                                                                                                                }
-                                                                                                                                                                       else if (strcmp (type, "text") == 0)
+                                                                                                                                                                       else if (g_strcmp0 (type, "text") == 0)
                                                                                                                                                                                {
                                                                                                                                                                                        g_object_set (G_OBJECT (field), "default", prop, NULL);
                                                                                                                                                                                }
@@ -377,6 +377,29 @@ GtkForm
                                                                                                                                                                                        gtk_form_key_add_field (priv->key, field);
                                                                                                                                                                                }
                                                                                                                                                                }
+                                                                                                                                                       else if (xmlStrcmp (node_field->name, (const xmlChar *)"datetime-type") == 0)
+                                                                                                                                                               {
+                                                                                                                                                                       if (g_strcmp0 (type, "datetime") == 0)
+                                                                                                                                                                               {
+                                                                                                                                                                                       if (g_strcmp0 (prop, "date"))
+                                                                                                                                                                                               {
+                                                                                                                                                                                                       g_object_set (G_OBJECT (field), "type", GTK_FORM_FIELD_DATETIME_TYPE_DATE, NULL);
+                                                                                                                                                                                               
+                                                                                                                                                                                               }
+                                                                                                                                                                                       else if (g_strcmp0 (prop, "time"))
+                                                                                                                                                                                               {
+                                                                                                                                                                                                       g_object_set (G_OBJECT (field), "type", GTK_FORM_FIELD_DATETIME_TYPE_TIME, NULL);
+                                                                                                                                                                                               
+                                                                                                                                                                                               }
+                                                                                                                                                                               }
+                                                                                                                                                               }
+                                                                                                                                                       else if (xmlStrcmp (node_field->name, (const xmlChar *)"display-format") == 0)
+                                                                                                                                                               {
+                                                                                                                                                                       if (g_strcmp0 (type, "datetime") == 0)
+                                                                                                                                                                               {
+                                                                                                                                                                                       g_object_set (G_OBJECT (field), "display-format", prop, NULL);
+                                                                                                                                                                               }
+                                                                                                                                                               }
 
                                                                                                                                                        node_field = node_field->next;
                                                                                                                                                }
@@ -623,7 +646,7 @@ GtkFormField
        while (fields != NULL)
                {
                        name = gtk_form_field_get_field_name ((GtkFormField *)fields->data);
-                       if (strcmp (name, field_name) == 0)
+                       if (g_strcmp0 (name, field_name) == 0)
                                {
                                        field = (GtkFormField *)fields->data;
                                        break;
@@ -660,7 +683,7 @@ GtkFormWidget
                {
                        widget = gtk_form_field_get_form_widget ((GtkFormField *)fields->data);
 
-                       if (strcmp (gtk_form_widget_get_widget_name (widget), widget_name) == 0)
+                       if (g_strcmp0 (gtk_form_widget_get_widget_name (widget), widget_name) == 0)
                                {
                                        widget_ret = widget;
                                        break;
@@ -906,7 +929,7 @@ gtk_form_check (GtkForm *form, gboolean with_key, GtkFormWidget **form_widget,
  * @form:
  *
  * Returns: TRUE if the values in the form are changed since last calling to
- * gtk_form_clear() or gtk_form_fill_from_datamodel().
+ * gtk_form_clear(), gtk_form_fill_from_datamodel() or gtk_form_set_as_origin().
  */
 gboolean
 gtk_form_is_changed (GtkForm *form)
@@ -1095,7 +1118,7 @@ gchar
 
                        field_name = gtk_form_field_get_field_name (field);
 
-                       if (field_name != NULL && strcmp (field_name, "") != 0)
+                       if (field_name != NULL && g_strcmp0 (field_name, "") != 0)
                                {
                                        switch (type)
                                                {
@@ -1161,7 +1184,7 @@ gchar
                {
                        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 && strcmp (where, "") != 0)
+                               && where != NULL && g_strcmp0 (where, "") != 0)
                                {
                                        sql = g_strconcat (sql, where, NULL);
                                }
index ebd0c879f713d861740ecfd67314830c7ea29bf5..765d04daba578b645a825570e390bf2a37b32bc2 100644 (file)
@@ -341,7 +341,9 @@ main (int argc, char **argv)
        g_object_set (fdatetime,
                      "field", "now",
                      "form-widget", wlabel,
+                     "type", GTK_FORM_FIELD_DATETIME_TYPE_DATE,
                      "default", now,
+                     "display-format", "%d/%m/%Y",
                      NULL);
        gtk_form_add_field (form, fdatetime);
 
index c62baa9d42cd51144f8141d3a1d5e230152abd48..25f3e59747cdc813998be2169c01b40be847f755 100644 (file)
@@ -41,6 +41,7 @@
 
        <widget type="entry" name="txt_birthday">
                <field type="datetime" name="birthday">
+                       <display-format>%d/%m/%Y</display-format>
                </field>
        </widget>