pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libgtkform.pc
+
+distclean-local:
+ if test "$(srcdir)" = "."; then :; else \
+ rm -f ChangeLog; \
+ fi
+
+ChangeLog:
+ @echo Creating $@
+ @if test -d "$(srcdir)/.git"; then \
+ (GIT_DIR=$(top_srcdir)/.git ./missing --run git log --stat -M -C --name-status --date=short --no-color) | fmt --split-only > $@.tmp \
+ && mv -f $@.tmp $@ \
+ || ($(RM) $@.tmp; \
+ echo Failed to generate ChangeLog, your ChangeLog may be outdated >&2; \
+ (test -f $@ || echo git-log is required to generate this file >> $@)); \
+ else \
+ test -f $@ || \
+ (echo A git checkout and git-log is required to generate ChangeLog >&2 && \
+ echo A git checkout and git-log is required to generate this file >> $@); \
+ fi
+
+.PHONY: ChangeLog
<!ELEMENT column-field (#PCDATA)>
-<!ELEMENT field (obligatory?, default-value?, is-key?)>
+<!ELEMENT field (obligatory?, default?, is-key?)>
<!ATTLIST field
type (boolean | datetime | float | integer | text) #REQUIRED
>
<!ELEMENT obligatory (#PCDATA)>
-<!ELEMENT default-value (#PCDATA)>
+<!ELEMENT default (#PCDATA)>
<!ELEMENT is-key (#PCDATA)>
/**
* gtk_form_field_datetime_get_value_stringify:
- * @field:
+ * @field: a #GtkFormField object.
*
*/
const gchar
/**
* gtk_form_field_datetime_get_value:
- * @field:
+ * @field: a #GtkFormField object.
*
*/
const GValue
{
struct tm datetime;
GValue *ret = NULL;
+
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), NULL);
+
const gchar *format = gtk_form_field_get_str_format (field);
const gchar *value = gtk_form_field_datetime_get_value_stringify (field);
/**
* gtk_form_field_datetime_get_value_sql:
- * @field:
+ * @field: a #GtkFormField object.
*
*/
const gchar
*gtk_form_field_datetime_get_value_sql (GtkFormField *field)
{
- const gchar *ret = NULL;
- const gchar *value = gtk_form_field_datetime_get_value_stringify (field);
- const gchar *format = gtk_form_field_get_str_format (field);
+ const gchar *ret;
+ const gchar *value;
+ const gchar *format;
+
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), NULL);
+
+ ret = NULL;
+ value = gtk_form_field_datetime_get_value_stringify (field);
+ format = gtk_form_field_get_str_format (field);
if (value != NULL)
{
{
char *buf;
- buf = malloc (100);
+ buf = g_malloc (20);
- if (strftime (buf, 100, format, &datetime) != 0)
+ if (strftime (buf, 20, format, &datetime) != 0)
{
ret = g_strconcat ("'", buf, "'", NULL);
}
+ g_free (buf);
}
}
/**
* gtk_form_field_datetime_clear:
- * @field:
+ * @field: a #GtkFormField object.
*
*/
gboolean
gtk_form_field_datetime_clear (GtkFormField *field)
{
- gboolean ret = FALSE;
- gchar *format = gtk_form_field_get_str_format (field);
+ gboolean ret;
+ GtkFormFieldDateTimePrivate *priv;
+ gchar *format;
- GtkFormFieldDateTimePrivate *priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (field);
+ 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;
if (priv->default_value != NULL)
{
/**
* gtk_form_field_datetime_is_empty:
- * @field:
+ * @field: a #GtkFormField object.
*
*/
gboolean
/**
* gtk_form_field_datetime_set_from_datamodel:
- * @field:
+ * @field: a #GtkFormField object.
* @dm:
* @row:
*
gtk_form_field_datetime_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row)
{
gboolean ret = FALSE;
+
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), FALSE);
+
const gchar *field_name = gtk_form_field_get_field_name (field);
if (dm != NULL)
/**
* gtk_form_field_get_str_format:
- * @field:
+ * @field: a #GtkFormField object.
*
*/
static gchar
#endif
#include <string.h>
+#include <time.h>
#include <libxml/xpath.h>
node_field = node_widget->children;
while (node_field != NULL)
{
+ prop = (gchar *)xmlNodeGetContent (node_field);
if (xmlStrcmp (node_field->name, (const xmlChar *)"obligatory") == 0)
{
- prop = (gchar *)xmlNodeGetContent (node_field);
g_object_set (G_OBJECT (field),
"obligatory", gtk_form_field_boolean_str_to_boolean (prop),
NULL);
}
- else if (xmlStrcmp (node_field->name, (const xmlChar *)"default-value") == 0)
+ else if (xmlStrcmp (node_field->name, (const xmlChar *)"default") == 0)
{
- /*g_object_set (G_OBJECT (field),
- "default-value", name,
- NULL);*/
+ if (strcmp (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)
+ {
+ struct tm *datetime;
+
+ if (strcmp (prop, "now") == 0)
+ {
+ time_t time_now;
+
+ time (&time_now);
+ datetime = localtime (&time_now);
+ g_object_set (G_OBJECT (field), "default", datetime, NULL);
+ }
+ else
+ {
+ datetime = g_malloc (sizeof (struct tm));
+ if (strptime (prop, "%F %T", datetime) != NULL)
+ {
+ g_object_set (G_OBJECT (field), "default", datetime, NULL);
+ }
+ else
+ {
+ datetime = g_malloc0 (sizeof (struct tm));
+ if (strptime (prop, "%F", datetime) != NULL)
+ {
+ g_object_set (G_OBJECT (field), "default", datetime, NULL);
+ }
+ else
+ {
+ datetime = g_malloc0 (sizeof (struct tm));
+ if (strptime (prop, "%T", datetime) != NULL)
+ {
+ g_object_set (G_OBJECT (field), "default", datetime, NULL);
+ }
+ }
+ }
+ }
+ }
+ else if (strcmp (type, "float") == 0)
+ {
+ gfloat value = g_strtod (prop, NULL);
+ g_object_set (G_OBJECT (field), "default", value, NULL);
+ }
+ else if (strcmp (type, "integer") == 0)
+ {
+ gint value = strtol (prop, NULL, 10);
+ g_object_set (G_OBJECT (field), "default", value, NULL);
+ }
+ else if (strcmp (type, "text") == 0)
+ {
+ g_object_set (G_OBJECT (field), "default", prop, NULL);
+ }
}
else if (xmlStrcmp (node_field->name, (const xmlChar *)"is-key") == 0)
{
+ if (gtk_form_field_boolean_str_to_boolean (prop))
+ {
+ if (!IS_GTK_FORM_KEY (priv->key))
+ {
+ priv->key = gtk_form_key_new ();
+ }
+
+ gtk_form_key_add_field (priv->key, field);
+ }
}
node_field = node_field->next;
<property name="value">1</property>
<property name="upper">100</property>
<property name="step_increment">1</property>
- <property name="page_increment">10</property>
- <property name="page_size">10</property>
+ <property name="page_increment">1</property>
</object>
<object class="GtkAdjustment" id="adjustment2">
<property name="value">1</property>
<property name="upper">100</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
- <property name="page_size">10</property>
</object>
</interface>
<widget type="label" name="lblID">
<field type="integer" name="id">
+ <default>15</default>
+ <is-key>t</is-key>
</field>
</widget>
<widget type="label" name="lblText">
<field type="text" name="id">
+ <default>default value</default>
</field>
</widget>
<widget type="entry" name="txtName">
<field type="text" name="name">
<obligatory>TRUE</obligatory>
+ <default>entry default value</default>
</field>
</widget>
<widget type="spin" name="spnAge">
<field type="integer" name="age">
+ <default>23</default>
</field>
</widget>
<widget type="spin" name="spnAmount">
<field type="float" name="amount">
+ <default>12.45</default>
</field>
</widget>
<widget type="combobox" name="cbNation">
<column-field>0</column-field>
<field type="integer" name="id_nation">
+ <default>3</default>
</field>
</widget>
<widget type="textview" name="txtvDescription">
<field type="text" name="description">
+ <default>the default value
+for this text view
+with also line feed
+and t a b</default>
+ </field>
+ </widget>
+
+ <widget type="label" name="lblDateTime">
+ <field type="datetime" name="now">
+ <default>13:20:44</default>
</field>
</widget>