# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT([libgtkform], [0.1.0], [azagli@libero.it])
+AC_INIT([libgtkform], [0.1.1], [azagli@libero.it])
AC_CONFIG_SRCDIR([src/form.c])
AC_CONFIG_HEADER([config.h])
<!ELEMENT return-value (#PCDATA)>
-<!ELEMENT field (no-save?, obligatory?, default?, is-key?, type?, display-format?)>
+<!ELEMENT field (to-save?, obligatory?, default?, is-key?, auto-increment?, datetime-type?, display-format?)>
<!ATTLIST field
type (boolean | datetime | float | integer | text) #REQUIRED
name CDATA #REQUIRED
>
-<!ELEMENT to-save (y | n)>
+<!ELEMENT to-save (#PCDATA)>
<!ELEMENT obligatory (#PCDATA)>
<!ELEMENT default (#PCDATA)>
<!ELEMENT is-key (#PCDATA)>
+<!ELEMENT auto-increment (#PCDATA)>
<!ELEMENT datetime-type (date | time | datetime)>
<!ELEMENT display-format (#PCDATA)>
PROP_FIELD,
PROP_TO_SAVE,
PROP_OBLIGATORY,
+ PROP_AUTO_INCREMENT,
PROP_DATAMODEL,
PROP_WIDGET
};
gboolean is_key;
gboolean to_save;
gboolean obligatory;
+ gboolean auto_increment;
GdaDataModel *dm;
FALSE,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class, PROP_AUTO_INCREMENT,
+ g_param_spec_boolean ("auto-increment",
+ "Auto increment",
+ "Whether the field auto increments (works only on numeric fields)",
+ FALSE,
+ G_PARAM_READWRITE));
+
g_object_class_install_property (object_class, PROP_WIDGET,
g_param_spec_object ("form-widget",
"GtkFormWidget",
return priv->to_save;
}
+/**
+ * gtk_form_field_is_auto_increment:
+ * @field: a #GtkFormField object.
+ *
+ */
+gboolean
+gtk_form_field_is_auto_increment (GtkFormField *field)
+{
+ GtkFormFieldPrivate *priv;
+
+ g_return_val_if_fail (IS_GTK_FORM_FIELD (field), FALSE);
+
+ priv = GTK_FORM_FIELD_GET_PRIVATE (field);
+
+ return priv->auto_increment;
+}
+
/**
* gtk_form_field_is_empty:
* @field: a #GtkFormField object.
priv->obligatory = g_value_get_boolean (value);
break;
+ case PROP_AUTO_INCREMENT:
+ priv->auto_increment = g_value_get_boolean (value);
+ break;
+
case PROP_DATAMODEL:
priv->dm = g_value_get_pointer (value);
break;
g_value_set_boolean (value, priv->obligatory);
break;
+ case PROP_AUTO_INCREMENT:
+ g_value_set_boolean (value, priv->auto_increment);
+ break;
+
case PROP_DATAMODEL:
g_value_set_pointer (value, priv->dm);
break;
gboolean gtk_form_field_is_to_save (GtkFormField *field);
+gboolean gtk_form_field_is_auto_increment (GtkFormField *field);
+
gboolean gtk_form_field_is_empty (GtkFormField *field);
gboolean gtk_form_field_is_changed (GtkFormField *field);
/*
- * 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
PROP_0,
PROP_TABLE,
PROP_KEY,
- PROP_QUOTE
+ PROP_QUOTE,
+ PROP_GDAEX
};
static void gtk_form_class_init (GtkFormClass *class);
GSList *fields;
GtkFormKey *key;
gchar quote;
+
+ GdaEx *gdaex;
};
G_DEFINE_TYPE (GtkForm, gtk_form, G_TYPE_OBJECT)
G_MININT8, G_MAXINT8, '"',
G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
+ g_object_class_install_property (object_class, PROP_GDAEX,
+ g_param_spec_pointer ("gdaex",
+ "GdaEx object",
+ "GdaEx object",
+ G_PARAM_READWRITE));
+
g_type_class_add_private (object_class, sizeof (GtkFormPrivate));
}
priv->fields = NULL;
priv->key = NULL;
+ priv->gdaex = NULL;
}
/**
gtk_form_key_add_field (priv->key, field);
}
}
+ else if (xmlStrcmp (node_field->name, (const xmlChar *)"auto-increment") == 0)
+ {
+ if (gtk_form_field_boolean_str_to_boolean (prop))
+ {
+ g_object_set (G_OBJECT (field), "auto-increment", TRUE, NULL);
+ }
+ }
else if (xmlStrcmp (node_field->name, (const xmlChar *)"datetime-type") == 0)
{
if (g_strcmp0 (type, "datetime") == 0)
case GTK_FORM_SQL_INSERT:
if (gtk_form_field_is_to_save (field))
{
+ if (gtk_form_field_is_auto_increment (field))
+ {
+ GdaDataModel *dm;
+ gchar *field_name;
+ guint new_val;
+
+ g_return_val_if_fail (IS_GDAEX (priv->gdaex), NULL);
+
+ g_object_get (field, "field", &field_name, NULL);
+
+ new_val = 0;
+ dm = gdaex_query (priv->gdaex,
+ g_strdup_printf ("SELECT COALESCE (MAX (%s), 0) FROM %s",
+ field_name,
+ priv->table));
+ if (dm != NULL && gda_data_model_get_n_rows (dm) > 0)
+ {
+ new_val = gdaex_data_model_get_value_integer_at (dm, 0, 0);
+ }
+ new_val++;
+
+ gtk_form_widget_set_value_stringify (gtk_form_field_get_form_widget (field), g_strdup_printf ("%d", new_val));
+ }
+
value = gtk_form_field_get_value_sql (field);
if (value != NULL)
{
priv->quote = g_value_get_char (value);
break;
+ case PROP_GDAEX:
+ priv->gdaex = g_value_get_pointer (value);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
g_value_set_char (value, priv->quote);
break;
+ case PROP_GDAEX:
+ g_value_set_pointer (value, priv->gdaex);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;