]> saetta.ns0.it Git - libgtkform/commitdiff
Added functions GtkForm::load_from_xml and GtkForm::load_from_file. 0.1.2
authorAndrea Zagli <azagli@libero.it>
Sun, 18 Jul 2010 10:42:12 +0000 (12:42 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 18 Jul 2010 10:42:12 +0000 (12:42 +0200)
Added functions GtkFormWidgetComboBox::fill_from_datamodel and
GtkFormWidgetComboBox::fill_from_datamodel.
Added element "sql" to FormWidget xml definition (with attribute "with-empty-entry").

configure.ac
data/gtkform.dtd
src/form.c
src/form.h
src/widgetcombobox.c
src/widgetcombobox.h

index ab52e49d12483647f7e0390c2c1279fa31eaeb7b..9f539b03fcbca643df2f6865474abb2a603b5862 100644 (file)
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT([libgtkform], [0.1.1], [azagli@libero.it])
+AC_INIT([libgtkform], [0.1.2], [azagli@libero.it])
 AC_CONFIG_SRCDIR([src/form.c])
 AC_CONFIG_HEADER([config.h])
 
index 8ffdb5a69f0aaa90921c9b796066847520d6c57d..e193c8bc9a8af06cebd9a08983cdb4f741b2386f 100644 (file)
@@ -4,7 +4,7 @@
 
 <!ELEMENT table (#PCDATA)>
 
-<!ELEMENT widget (column-field?, return-value?, field?)>
+<!ELEMENT widget (column-field?, sql?, return-value?, field?)>
 
 <!ATTLIST widget
        type  (checkbox | combobox | entry | label | radio | spin | textview)  #REQUIRED
 
 <!ELEMENT column-field (#PCDATA)>
 
+<!ELEMENT sql (#PCDATA)>
+
+<!ATTLIST sql
+       with-empty-entry  (#PCDATA)
+>
+
 <!ELEMENT return-value (#PCDATA)>
 
 <!ELEMENT field (to-save?, obligatory?, default?, is-key?, auto-increment?, datetime-type?, display-format?)>
index d80725b91041c1e3b6a06a522d6598ff5106dcbe..d431340583afd09c368d6bee1b01bf80254e1f30 100644 (file)
@@ -162,10 +162,63 @@ GtkForm
 *gtk_form_new_from_xml (xmlDoc *xmldoc, GtkBuilder *gtkbuilder)
 {
        GtkForm *form;
+
+       form = gtk_form_new ();
+
+       if (!gtk_form_load_from_xml (form, xmldoc, gtkbuilder))
+               {
+                       form = NULL;
+               }
+
+       return form;
+}
+
+/**
+ * gtk_form_new_from_file:
+ * @filename:
+ * @gtkbuilder:
+ *
+ * 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, GtkBuilder *gtkbuilder)
+{
+       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, gtkbuilder);
+               }
+
+       return form;
+}
+
+/**
+ * gtk_form_load_from_xml:
+ * @form:
+ * @xmldoc:
+ * @gtkbuilder:
+ *
+ */
+gboolean
+gtk_form_load_from_xml (GtkForm *form, xmlDoc *xmldoc, GtkBuilder *gtkbuilder)
+{
        GtkFormPrivate *priv;
        xmlNode *cur;
 
-       form = NULL;
+       gboolean ret;
+
+       g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
+       g_return_val_if_fail (xmldoc != NULL, FALSE);
+
+       ret = FALSE;
 
        cur = xmlDocGetRootElement (xmldoc);
        if (cur != NULL)
@@ -182,7 +235,7 @@ GtkForm
                                        GtkFormField *field;
                                        xmlNode *node_field;
 
-                                       form = gtk_form_new ();
+                                       ret = TRUE;
 
                                        priv = GTK_FORM_GET_PRIVATE (form);
 
@@ -313,6 +366,14 @@ GtkForm
                                                                                                                        g_object_set (G_OBJECT (widget), "column-field",
                                                                                                                                              strtol ((gchar *)xmlNodeGetContent (node_widget), NULL, 10), NULL);
                                                                                                                }
+                                                                                                       else if (xmlStrcmp (node_widget->name, (const xmlChar *)"sql") == 0
+                                                                                                                        && IS_GTK_FORM_WIDGET_COMBO_BOX (widget) && IS_GDAEX (priv->gdaex))
+                                                                                                               {
+                                                                                                                       gtk_form_widget_combo_box_fill_from_sql (widget,
+                                                                                                                                     priv->gdaex,
+                                                                                                                                             (gchar *)xmlNodeGetContent (node_widget),
+                                                                                                                                             gtk_form_field_boolean_str_to_boolean (xmlGetProp (node_widget, "with-empty-entry")));
+                                                                                                               }
                                                                                                        else if (xmlStrcmp (node_widget->name, (const xmlChar *)"return-value") == 0
                                                                                                                         && IS_GTK_FORM_WIDGET_RADIO (widget))
                                                                                                                {
@@ -487,34 +548,35 @@ GtkForm
                                }
                }
 
-       return form;
+       return ret;
 }
 
 /**
- * gtk_form_new_from_file:
+ * gtk_form_load_from_file:
+ * @form:
  * @filename:
  * @gtkbuilder:
  *
- * 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, GtkBuilder *gtkbuilder)
+gboolean
+gtk_form_load_from_file (GtkForm *form, const gchar *filename, GtkBuilder *gtkbuilder)
 {
-       GtkForm *form;
        xmlDoc *xdoc;
 
-       g_return_val_if_fail (filename != NULL, NULL);
+       gboolean ret;
 
-       form = NULL;
+       g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
+       g_return_val_if_fail (filename != NULL, FALSE);
+
+       ret = FALSE;
 
        xdoc = xmlParseFile (filename);
        if (xdoc != NULL)
                {
-                       form = gtk_form_new_from_xml (xdoc, gtkbuilder);
+                       ret = gtk_form_load_from_xml (form, xdoc, gtkbuilder);
                }
 
-       return form;
+       return ret;
 }
 
 /**
index 9ef3f10d1705b786a14b94be27bb671cd47e3900..65ea0b9c16a55a8b9d58d21a20499ad2c1ea0e99 100644 (file)
@@ -58,6 +58,9 @@ GtkForm *gtk_form_new (void);
 GtkForm *gtk_form_new_from_xml (xmlDoc *xmldoc, GtkBuilder *gtkbuilder);
 GtkForm *gtk_form_new_from_file (const gchar *filename, GtkBuilder *gtkbuilder);
 
+gboolean gtk_form_load_from_xml (GtkForm *form, xmlDoc *xmldoc, GtkBuilder *gtkbuilder);
+gboolean gtk_form_load_from_file (GtkForm *form, const gchar *filename, GtkBuilder *gtkbuilder);
+
 GtkBuilder *gtk_form_get_gtkbuilder (GtkForm *form);
 
 gchar *gtk_form_get_table (GtkForm *form);
index b107b870e44c6ebf538c068844519ac1ef5c0f27..ae1b2e95b61218610289d0145702f297598cdff1 100644 (file)
@@ -209,6 +209,72 @@ gtk_form_widget_combo_box_set_editable (GtkFormWidget *fwidget, gboolean editabl
        gtk_widget_set_sensitive (w, editable);
 }
 
+/**
+ * gtk_form_widget_combo_box_fill_from_datamodel:
+ * @fwidget: a #GtkFormWidget object.
+ * @dm:
+ * @with_empty_entry:
+ *
+ */
+void
+gtk_form_widget_combo_box_fill_from_datamodel (GtkFormWidget *fwidget, GdaDataModel *dm, gboolean with_empty_entry)
+{
+       GtkWidget *w;
+
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+       guint rows;
+       guint row;
+
+       g_return_if_fail (IS_GTK_FORM_WIDGET_COMBO_BOX (fwidget));
+       g_return_if_fail (GDA_IS_DATA_MODEL (dm));
+
+       g_object_get (G_OBJECT (fwidget),
+                     "widget", &w,
+                     NULL);
+
+       model = gtk_combo_box_get_model (GTK_COMBO_BOX (w));
+       g_return_if_fail (GTK_IS_TREE_MODEL (model));
+
+       if (with_empty_entry)
+               {
+                       gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+                       gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+                                                           0, "",
+                                                           1, "",
+                                                           -1);
+               }
+
+       rows = gda_data_model_get_n_rows (dm);
+       for (row = 0; row < rows; row++)
+               {
+                       gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+                       gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+                                           0, gdaex_data_model_get_value_stringify_at (dm, row, 0),
+                                           1, gdaex_data_model_get_value_stringify_at (dm, row, 1),
+                                           -1);
+               }
+}
+
+/**
+ * gtk_form_widget_combo_box_fill_from_sql:
+ * @fwidget: a #GtkFormWidget object.
+ * @gdaex:
+ * @sql:
+ * @with_empty_entry:
+ *
+ */
+void
+gtk_form_widget_combo_box_fill_from_sql (GtkFormWidget *fwidget, GdaEx *gdaex, const gchar *sql, gboolean with_empty_entry)
+{
+       GdaDataModel *dm;
+
+       g_return_if_fail (IS_GDAEX (gdaex));
+
+       dm = gdaex_query (gdaex, sql);
+       gtk_form_widget_combo_box_fill_from_datamodel (fwidget, dm, with_empty_entry);
+}
+
 /* PRIVATE */
 static void
 gtk_form_widget_combo_box_set_property (GObject *object,
index 6ef3080841b4c27e100c3ba2a0694d714d948ec0..e3435e51a221fd5c55190c387b4cb6fa40955263 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -19,6 +19,8 @@
 #ifndef __LIBGTK_FORM_WIDGET_COMBO_BOX_H__
 #define __LIBGTK_FORM_WIDGET_COMBO_BOX_H__
 
+#include <libgdaex.h>
+
 #include "widget.h"
 
 
@@ -56,6 +58,9 @@ gboolean gtk_form_widget_combo_box_set_value_stringify (GtkFormWidget *fwidget,
 
 void gtk_form_widget_combo_box_set_editable (GtkFormWidget *fwidget, gboolean editable);
 
+void gtk_form_widget_combo_box_fill_from_datamodel (GtkFormWidget *fwidget, GdaDataModel *dm, gboolean with_empty_entry);
+void gtk_form_widget_combo_box_fill_from_sql (GtkFormWidget *fwidget, GdaEx *gdaex, const gchar *sql, gboolean with_empty_entry);
+
 
 G_END_DECLS