]> saetta.ns0.it Git - libgtkform/commitdiff
Started xml definition file.
authorAndrea Zagli <azagli@libero.it>
Mon, 27 Jul 2009 16:14:25 +0000 (18:14 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 27 Jul 2009 16:14:25 +0000 (18:14 +0200)
Added functions GtkForm::new_from_xml and GtkForm::new_from_file.
Added functions GtkForm::get_table, GtkForm::set_table,
GtkForm::get_key and GtkForm::set_key.

Makefile.am
configure.ac
data/Makefile.am [new file with mode: 0644]
data/gtkform.dtd [new file with mode: 0644]
libgtkform.pc.in
src/form.c
src/form.h
test/main.c

index 668a94ede7996761c60a08a2eb270c2ef830dc79..6fb292aae24b9ebfaa0c05af1f1e56d0a42c3317 100644 (file)
@@ -1,6 +1,6 @@
 DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc
 
-SUBDIRS = src test docs
+SUBDIRS = src test docs data
 
 ACLOCAL_AMFLAGS = -I m4
 
index fcad5c74e95f854d6f4a471ef65dd5b0acbf91a2..3557fccc524b462ee7d372bae108fa91d0bba596 100644 (file)
@@ -30,6 +30,7 @@ GTK_DOC_CHECK
 
 # Checks for libraries.
 PKG_CHECK_MODULES(GTKFORM, [gtk+-2.0 >= 2.12.0
+                            libxml-2.0 >= 2.0.0
                             libgdaex >= 0.1.0])
 
 AC_SUBST(GTKFORM_CFLAGS)
@@ -56,5 +57,6 @@ AC_CONFIG_FILES([
   docs/Makefile
   docs/reference/Makefile
   docs/reference/version.xml
+  data/Makefile
 ])
 AC_OUTPUT
diff --git a/data/Makefile.am b/data/Makefile.am
new file mode 100644 (file)
index 0000000..152bf2c
--- /dev/null
@@ -0,0 +1,2 @@
+EXTRA_DIST = \
+             gtkform.dtd
diff --git a/data/gtkform.dtd b/data/gtkform.dtd
new file mode 100644 (file)
index 0000000..5a4c83e
--- /dev/null
@@ -0,0 +1,23 @@
+<!ELEMENT gtkform (table, widget*)>
+
+<!ELEMENT table (#PCDATA)>
+
+<!ELEMENT widget (column-field?, field)>
+
+<!ATTLIST widget
+       type  (checkbox | combobox | entry | label | spin | textview)  #REQUIRED
+       name  CDATA  #REQUIRED
+>
+
+<!ELEMENT column-field (#PCDATA)>
+
+<!ELEMENT field (obligatory?, default-value?, is-key?)>
+
+<!ATTLIST field
+       type  (boolean | datetime | float | integer | text)  #REQUIRED
+       name  CDATA  #REQUIRED
+>
+
+<!ELEMENT obligatory (#PCDATA)>
+<!ELEMENT default-value (#PCDATA)>
+<!ELEMENT is-key (#PCDATA)>
index 274802ea356a7f10d4779262ea86979e60c55f82..bfbedc4a5be1735c78c6b8e59104a37de58c7049 100644 (file)
@@ -6,6 +6,6 @@ includedir=@includedir@
 Name: @PACKAGE_NAME@
 Description: Class for easly manage Gtk+ forms binded to db.
 Version: @PACKAGE_VERSION@
-Requires: gtk+-2.0, libgdaex
+Requires: gtk+-2.0, libxml-2.0, libgdaex
 Libs: -L${libdir} -lgtkform
 Cflags: -I${includedir}/libgtkform
index 4c9eef0cba236ad46a229b288437669fdafe4f61..007b242afb0956a77bec23222eb92a8afd549bc9 100644 (file)
@@ -48,9 +48,8 @@ static void gtk_form_get_property (GObject *object,
 typedef struct _GtkFormPrivate GtkFormPrivate;
 struct _GtkFormPrivate
        {
-               GList *fields;
-
                gchar *table;
+               GList *fields;
                GtkFormKey *key;
        };
 
@@ -86,13 +85,15 @@ gtk_form_init (GtkForm *form)
 {
        GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
 
+       priv->table = "";
        priv->fields = NULL;
+       priv->key = NULL;
 }
 
 /**
  * gtk_form_new:
  *
- * Returns: the newly created #GtkForm.
+ * Returns: the newly created #GtkForm object.
  */
 GtkForm
 *gtk_form_new ()
@@ -100,6 +101,129 @@ GtkForm
        return GTK_FORM (g_object_new (gtk_form_get_type (), NULL));
 }
 
+/**
+ * gtk_form_new_from_xml:
+ * @xmldoc:
+ *
+ * Returns: the newly created #GtkForm object from an #xmlDoc that contains the
+ * xml definition of the form.
+ */
+GtkForm
+*gtk_form_new_from_xml (xmlDoc *xmldoc)
+{
+       GtkForm *form;
+       xmlNode *cur;
+
+       form = NULL;
+
+       cur = xmlDocGetRootElement (xmldoc);
+       if (cur != NULL)
+               {
+                       if (xmlStrcmp (cur->name, "gtkform") == 0)
+                               {
+                               }
+                       else
+                               {
+                                       /* TO DO */
+                                       g_warning ("The file is not a valid gtkform definition file");
+                               }
+               }
+
+       return form;
+}
+
+/**
+ * gtk_form_new_from_file:
+ * @filename:
+ *
+ * Returns: the newly created #GtkForm object from a file that contains the
+ * xml denifition of the form.
+ */
+GtkForm
+*gtk_form_new_from_file (const gchar *filename)
+{
+       GtkForm *form;
+       xmlDoc *xdoc;
+
+       g_return_val_if_fail (filename != NULL, NULL);
+
+       form = NULL;
+
+       xdoc = xmlParseFile (filename);
+       if (xdoc != NULL)
+               {
+                       form = gtk_form_new_from_xml (xdoc);
+               }
+
+       return form;
+}
+
+/**
+ * gtk_form_get_table:
+ * @form: a #GtkForm object.
+ *
+ * Returns: the table's name associated to the form.
+ */
+const gchar
+*gtk_form_get_table (GtkForm *form)
+{
+       GtkFormPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+
+       return (const gchar *)g_strdup (priv->table);
+}
+
+/**
+ * gtk_form_set_table:
+ * @form: a #GtkForm object.
+ * @table:
+ *
+ */
+void
+gtk_form_set_table (GtkForm *form, const gchar *table)
+{
+       GtkFormPrivate *priv;
+
+       g_return_if_fail (IS_GTK_FORM (form));
+       g_return_if_fail (table != NULL);
+
+       priv->table = g_strstrip (g_strdup (table));
+}
+
+/**
+ * gtk_form_get_key:
+ * @form: a #GtkForm object.
+ *
+ * Returns: the #GtkFormKey associated to the form.
+ */
+GtkFormKey *
+gtk_form_get_key (GtkForm *form)
+{
+       GtkFormPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+
+       return priv->key;
+}
+
+/**
+ * gtk_form_set_key:
+ * @form: a #GtkForm object.
+ * @key:
+ *
+ */
+void
+gtk_form_set_key (GtkForm *form, GtkFormKey *key)
+{
+       GtkFormPrivate *priv;
+
+       g_return_if_fail (IS_GTK_FORM (form));
+       g_return_if_fail (IS_GTK_FORM_KEY (key));
+
+       priv->key = key;
+}
+
 /**
  * gtk_form_add_field:
  * @form: a #GtkForm object.
@@ -112,6 +236,7 @@ gtk_form_add_field (GtkForm *form, GtkFormField *field)
        gboolean ret;
        GtkFormPrivate *priv;
 
+       g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
        g_return_val_if_fail (IS_GTK_FORM_FIELD (field), FALSE);
 
        ret = FALSE;
@@ -137,6 +262,7 @@ gtk_form_remove_field (GtkForm *form, GtkFormField *field)
        gboolean ret = FALSE;
        GtkFormPrivate *priv;
 
+       g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
        g_return_val_if_fail (IS_GTK_FORM_FIELD (field), FALSE);
 
        priv = GTK_FORM_GET_PRIVATE (form);
@@ -160,6 +286,8 @@ gtk_form_add_fields (GtkForm *form, ...)
 
        va_list vargs;
 
+       g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
+
        va_start (vargs, form);
 
        while ((field = va_arg (vargs, GtkFormField *)) != NULL)
@@ -181,7 +309,11 @@ GtkFormField
 {
        GtkFormField *field = NULL;
        const gchar *name;
-       GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
+       GtkFormPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+
+       priv = GTK_FORM_GET_PRIVATE (form);
 
        GList *fields = g_list_first (priv->fields);
        while (fields != NULL)
@@ -211,7 +343,12 @@ GtkFormWidget
        GtkFormWidget *widget = NULL;
        GtkFormWidget *widget_ret = NULL;
        gchar *name;
-       GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
+       GtkFormPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+       g_return_val_if_fail (widget_name != NULL, NULL);
+
+       priv = GTK_FORM_GET_PRIVATE (form);
 
        GList *fields = g_list_first (priv->fields);
        while (fields != NULL)
@@ -240,8 +377,11 @@ gtk_form_clear (GtkForm *form)
 {
        GtkFormField *field;
        gboolean ret = FALSE;
+       GtkFormPrivate *priv;
 
-       GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
+       g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
+
+       priv = GTK_FORM_GET_PRIVATE (form);
 
        GList *fields = g_list_first (priv->fields);
 
@@ -272,6 +412,8 @@ gtk_form_check (GtkForm *form)
        gboolean ret = TRUE;
        gboolean obl = FALSE;
 
+       g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
+
        GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
 
        GList *fields = g_list_first (priv->fields);
@@ -314,6 +456,8 @@ gtk_form_set_sensitive (GtkForm *form, gboolean sensitive)
        GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
        GtkWidget *widget;
 
+       g_return_if_fail (IS_GTK_FORM (form));
+
        GList *fields = g_list_first (priv->fields);
        while (fields != NULL)
                {
@@ -338,6 +482,8 @@ gtk_form_set_editable (GtkForm *form, gboolean editable)
        GtkFormWidget *fwidget;
        GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
 
+       g_return_if_fail (IS_GTK_FORM (form));
+
        GList *fields = g_list_first (priv->fields);
        while (fields != NULL)
                {
@@ -367,6 +513,8 @@ gchar
        gchar *where = "";
        const gchar *field_name;
 
+       g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+
        GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
 
        GList *fields = g_list_first (priv->fields);
@@ -462,6 +610,8 @@ gtk_form_fill_from_datamodel (GtkForm *form, GdaDataModel *dm, gint row)
        GtkFormField *field;
        gchar *field_name;
 
+       g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
+
        GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
 
        GList *fields = g_list_first (priv->fields);
@@ -492,11 +642,11 @@ gtk_form_set_property (GObject *object,
        switch (property_id)
                {
                        case PROP_TABLE:
-                               priv->table = g_strstrip (g_strdup (g_value_get_string (value)));
+                               gtk_form_set_table (form, g_value_get_string (value));
                                break;
 
                        case PROP_KEY:
-                               priv->key = g_value_get_object (value);
+                               gtk_form_set_key (form, GTK_FORM_KEY (g_value_get_object (value)));
                                break;
 
                        default:
@@ -518,11 +668,11 @@ gtk_form_get_property (GObject *object,
        switch (property_id)
                {
                        case PROP_TABLE:
-                               g_value_set_string (value, priv->table);
+                               g_value_set_string (value, gtk_form_get_table (form));
                                break;
 
                        case PROP_KEY:
-                               g_value_set_object (value, priv->key);
+                               g_value_set_object (value, gtk_form_get_key (form));
                                break;
 
                        default:
index 4191586b0eef8e649919b38c1629001fca463e48..f10860c3826972b1d6a4adda58e5c41694ce2aef 100644 (file)
@@ -20,6 +20,8 @@
 #define __LIBGTK_FORM_H__
 
 #include <glib.h>
+#include <libxml/tree.h>
+
 
 #include "field.h"
 #include "widget.h"
@@ -54,6 +56,14 @@ GType gtk_form_get_type (void) G_GNUC_CONST;
 
 
 GtkForm *gtk_form_new (void);
+GtkForm *gtk_form_new_from_xml (xmlDoc *xmldoc);
+GtkForm *gtk_form_new_from_file (const gchar *filename);
+
+const gchar *gtk_form_get_table (GtkForm *form);
+void gtk_form_set_table (GtkForm *form, const gchar *table);
+
+GtkFormKey *gtk_form_get_key (GtkForm *form);
+void gtk_form_set_key (GtkForm *form, GtkFormKey *key);
 
 gboolean gtk_form_add_field (GtkForm *form, GtkFormField *field);
 gboolean gtk_form_remove_field (GtkForm *form, GtkFormField *field);
index d11ff9e02f780cd659a5b79d23157f807e8ea603..09488f485ffa3725d4708a1bf38beac2ab71570e 100644 (file)
@@ -260,7 +260,7 @@ main (int argc, char **argv)
        ftext = gtk_form_field_text_new ();
        g_object_set (ftext,
                      "field", "name",
-                                                               "obligatory", TRUE,
+                     "obligatory", TRUE,
                      "form-widget", wentry,
                      "default", "entry default value",
                      NULL);
@@ -297,7 +297,7 @@ main (int argc, char **argv)
        gtk_form_widget_set_from_gtkbuilder (wcombobox, gtkbuilder, "cbNation");
        g_object_set (wcombobox,
                      "column-field", 0,
-                                                               NULL);
+                     NULL);
 
        fint = gtk_form_field_integer_new ();
        g_object_set (fint,
@@ -326,7 +326,7 @@ main (int argc, char **argv)
        g_object_set (ftext,
                      "field", "description",
                      "form-widget", wtxtv,
-                                                               "default", "the default value\nfor this text view\nwith also line feed\nand\tt\ta\tb",
+                     "default", "the default value\nfor this text view\nwith also line feed\nand\tt\ta\tb",
                      NULL);
        gtk_form_add_field (form, ftext);
 
@@ -341,7 +341,7 @@ main (int argc, char **argv)
        g_object_set (fdatetime,
                      "field", "now",
                      "form-widget", wlabel,
-                                                               "default", now,
+                     "default", now,
                      NULL);
        gtk_form_add_field (form, fdatetime);