]> saetta.ns0.it Git - libgtkform/commitdiff
Completed GtkFormWidgetDecoder.
authorAndrea Zagli <azagli@libero.it>
Sat, 18 Jun 2011 16:30:31 +0000 (18:30 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 18 Jun 2011 16:30:31 +0000 (18:30 +0200)
Added the ability for plugin to auto parse xml.

configure.ac
src/form.c
ui/Makefile.am
ui/gtkformdecoder.c
ui/gtkformwidgetdecoder.c
ui/gtkformwidgetdecoder.h

index 37ac490ac5468ea3cd9c714d419cff872466c162..ecf171e19fad48ba8c04b50cbe65464a438bf8c2 100644 (file)
@@ -68,7 +68,21 @@ AC_CHECK_FUNCS([localeconv setlocale strcasecmp strtol])
 AC_FUNC_STRTOD
 AC_FUNC_MALLOC
 
-# Checks for library functions.
+dnl ******************************
+dnl Check for Operating System
+dnl ******************************
+
+platform_win32=no
+
+case "$host" in
+*-mingw*)
+    platform_win32=yes
+    ;;
+esac
+
+AM_CONDITIONAL(PLATFORM_WIN32, [test $platform_win32 = yes])
+
+# Output files
 AC_CONFIG_FILES([
   libgtkform.pc
   libgtkformui.pc
index 8fd465edf4c459c7a957af7286a9512ed2cc97ee..e6b2e3d2f2772cd206c493505d6f2f54203871d4 100644 (file)
@@ -66,6 +66,7 @@ enum
 };
 
 typedef GtkFormWidget *(* FormWidgetConstructorFunc) (void);
+typedef gboolean (* FormWidgetXmlParsingFunc) (GtkFormWidget *, xmlNodePtr);
 
 typedef struct
 {
@@ -505,6 +506,10 @@ gtk_form_load_from_xml (GtkForm *form, xmlDoc *xmldoc, GtkBuilder *gtkbuilder)
 
        gboolean ret;
 
+       GList *modules;
+       FormWidgetConstructorFunc widget_constructor;
+       FormWidgetXmlParsingFunc widget_xml_parsing;
+
        g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
        g_return_val_if_fail (xmldoc != NULL, FALSE);
 
@@ -582,6 +587,7 @@ gtk_form_load_from_xml (GtkForm *form, xmlDoc *xmldoc, GtkBuilder *gtkbuilder)
                                                        else if (xmlStrcmp (cur->name, (const xmlChar *)"widget") == 0)
                                                                {
                                                                        widget = NULL;
+                                                                       modules = NULL;
 
                                                                        type = xmlGetProp (cur, (const xmlChar *)"type");
                                                                        if (g_strcmp0 (type, "checkbox") == 0)
@@ -615,9 +621,6 @@ gtk_form_load_from_xml (GtkForm *form, xmlDoc *xmldoc, GtkBuilder *gtkbuilder)
                                                                        else
                                                                                {
                                                                                        /* trying in modules */
-                                                                                       GList *modules;
-                                                                                       FormWidgetConstructorFunc widget_constructor;
-                                                                                       
                                                                                        modules = g_list_first (priv->modules);
                                                                                        while (modules != NULL)
                                                                                                {
@@ -638,6 +641,7 @@ gtk_form_load_from_xml (GtkForm *form, xmlDoc *xmldoc, GtkBuilder *gtkbuilder)
                                                                                        if (widget == NULL)
                                                                                                {
                                                                                                        g_warning (_("Unknown type «%s»."), type);
+                                                                                                       modules = NULL;
                                                                                                }
                                                                                }
 
@@ -680,21 +684,21 @@ gtk_form_load_from_xml (GtkForm *form, xmlDoc *xmldoc, GtkBuilder *gtkbuilder)
                                                                                                                         && IS_GTK_FORM_WIDGET_COMBO_BOX (widget))
                                                                                                                {
                                                                                                                        g_object_set (G_OBJECT (widget), "column-field",
-                                                                                                                                             strtol ((gchar *)xmlNodeGetContent (node_widget), NULL, 10), NULL);
+                                                                                                                                     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")));
+                                                                                                                                     (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))
                                                                                                                {
                                                                                                                        g_object_set (G_OBJECT (widget), "return-value",
-                                                                                                                                             xmlNodeGetContent (node_widget), NULL);
+                                                                                                                                     xmlNodeGetContent (node_widget), NULL);
                                                                                                                }
                                                                                                        else if (xmlStrcmp (node_widget->name, (const xmlChar *)"on-change") == 0)
                                                                                                                {
@@ -878,7 +882,24 @@ gtk_form_load_from_xml (GtkForm *form, xmlDoc *xmldoc, GtkBuilder *gtkbuilder)
                                                                                                                                {
                                                                                                                                        g_warning (_("Field of type «%s» not found."), type);
                                                                                                                                }
-                                                                                                               } 
+                                                                                                               }
+                                                                                                       else
+                                                                                                               {
+                                                                                                                       /* if the widget is a plugin,
+                                                                                                                          try to make xml parsing by the plugin */
+                                                                                                                       if (modules != NULL)
+                                                                                                                               {
+                                                                                                                                       if (g_module_symbol ((GModule *)modules->data,
+                                                                                                                                                                g_strconcat ("gtk_form_widget_", type, "_xml_parsing", NULL),
+                                                                                                                                                                                (gpointer *)&widget_xml_parsing))
+                                                                                                                                               {
+                                                                                                                                                       if (widget_xml_parsing != NULL)
+                                                                                                                                                               {
+                                                                                                                                                                       widget_xml_parsing (widget, node_widget);
+                                                                                                                                                               }
+                                                                                                                                               }
+                                                                                                                               }
+                                                                                                               }
 
                                                                                                        node_widget = node_widget->next;
                                                                                                }
@@ -2536,6 +2557,8 @@ gtk_form_add_db_connection_gdaex (GtkForm *form, const gchar *name, GdaEx *gdaex
  * @form:
  * @name:
  *
+ * Returns: if @name is #NULL, the default #GdaEx connection; otherwise
+ * the connection associated with the name requested.
  */
 GdaEx
 *gtk_form_get_db_connection_by_name (GtkForm *form, const gchar *name)
@@ -2547,14 +2570,18 @@ GdaEx
        GtkFormDbConnection *dbc;
 
        g_return_val_if_fail (IS_GTK_FORM (form), NULL);
-       g_return_val_if_fail (name != NULL, NULL);
+
+       GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
+
+       if (name == NULL)
+               {
+                       return priv->gdaex;
+               }
 
        _name = g_strstrip (g_strdup (name));
 
        g_return_val_if_fail (g_strcmp0 (_name, "") != 0, NULL);
 
-       GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
-
        gdaex = NULL;
 
        dbs = priv->db_connections;
index 42b7e739ed11218074d82151e83e809c25e37838..e4f45039813c87e2e0758d16adea2f8fef5fcca4 100644 (file)
@@ -4,6 +4,14 @@ else
 GLADEDIR =
 endif
 
+if PLATFORM_WIN32
+libmodulesext = -0.dll
+libmodulesdir = $(bindir)
+else
+libmodulesext = .so
+libmodulesdir = $(libdir)
+endif
+
 SUBDIRS = . \
           test \
           $(GLADEDIR)
@@ -33,7 +41,7 @@ libgtkformui_includedir = $(includedir)/libgtkformui
 
 install-exec-hook:
        cd $(libdir)/$(PACKAGE)/modules && \
-       ln -s -f $(libdir)/libgtkformui.so .
+       ln -s -f $(libmodulesdir)/libgtkformui$(libmodulesext) .
 
 uninstall-hook:
-       rm -f $(libdir)/$(PACKAGE)/modules/libgtkdateentry.so
+       rm -f $(libdir)/$(PACKAGE)/modules/libgtkdateentry$(libmodulesext)
index bf0ba1dd63d8c3a49a28e75ac1a7b1f53c68e6c1..d8d7b7fb4c405fe6ccaa316cfdaebcf391cf6350 100644 (file)
@@ -202,7 +202,7 @@ gtk_form_decoder_init (GtkFormDecoder *decoder)
                          G_CALLBACK (gtk_form_decoder_on_btn_clean_clicked), (gpointer)decoder);
 
        priv->btn_open = gtk_button_new ();
-       gtk_widget_set_tooltip_text (priv->btn_open, "Open");
+       gtk_widget_set_tooltip_text (priv->btn_open, _("Open"));
        gtk_box_pack_start (GTK_BOX (priv->hbox), priv->btn_open, FALSE, FALSE, 0);
        gtk_widget_set_no_show_all (priv->btn_open, TRUE);
        icon = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_MENU);
@@ -214,7 +214,7 @@ gtk_form_decoder_init (GtkFormDecoder *decoder)
                          G_CALLBACK (gtk_form_decoder_on_btn_open_clicked), (gpointer)decoder);
 
        priv->btn_browse = gtk_button_new_with_label ("...");
-       gtk_widget_set_tooltip_text (priv->btn_browse, "Find");
+       gtk_widget_set_tooltip_text (priv->btn_browse, _("Find"));
        gtk_box_pack_start (GTK_BOX (priv->hbox), priv->btn_browse, FALSE, FALSE, 0);
        gtk_widget_set_no_show_all (priv->btn_browse, TRUE);
        gtk_widget_show (priv->btn_browse);
index c6190bd6f396bf38cc5ec5681a3cf2dea7185831..7089fa0d369595a6a13d9d1405d2098a13012232 100644 (file)
@@ -18,6 +18,9 @@
 
 #include <gtk/gtk.h>
 
+#include <libgtkform/form.h>
+#include <libgtkform/fieldboolean.h>
+
 #include "gtkformdecoder.h"
 #include "gtkformwidgetdecoder.h"
 
@@ -81,6 +84,62 @@ GtkFormWidget
        return g_object_new (gtk_form_widget_decoder_get_type (), NULL);
 }
 
+/**
+ * gtk_form_widget_decoder_xml_parsing:
+ * @widget:
+ * @xml_node:
+ *
+ */
+gboolean
+gtk_form_widget_decoder_xml_parsing (GtkFormWidget *fwidget, xmlNodePtr xml_node)
+{
+       GtkFormWidgetDecoderPrivate *priv = GTK_FORM_WIDGET_DECODER_GET_PRIVATE (fwidget);
+
+       GtkForm *form;
+       GtkWidget *w;
+
+       gchar *connection_name;
+
+       xmlNodePtr child;
+
+       if (xmlStrcmp (xml_node->name, "decoder") != 0)
+               {
+                       return FALSE;
+               }
+
+       w = gtk_form_widget_get_widget (fwidget);
+
+       connection_name = NULL;
+
+       child = xml_node->children;
+       while (child != NULL)
+               {
+                       if (xmlStrcmp (child->name, (const xmlChar *)"sql") == 0)
+                               {
+                                       g_object_set (G_OBJECT (w), "sql", gtk_form_field_boolean_str_to_boolean ((gchar *)xmlNodeGetContent (child)), NULL);
+                               }
+                       else if (xmlStrcmp (child->name, (const xmlChar *)"connection-name") == 0)
+                               {
+                                       connection_name = g_strdup ((gchar *)xmlNodeGetContent (child));
+                               }
+                       else if (xmlStrcmp (child->name, (const xmlChar *)"show-btn-clean") == 0)
+                               {
+                                       g_object_set (G_OBJECT (w), "show-btn-clean", gtk_form_field_boolean_str_to_boolean ((gchar *)xmlNodeGetContent (child)), NULL);
+                               }
+                       else if (xmlStrcmp (child->name, (const xmlChar *)"show-btn-open") == 0)
+                               {
+                                       g_object_set (G_OBJECT (w), "show-btn-open", gtk_form_field_boolean_str_to_boolean ((gchar *)xmlNodeGetContent (child)), NULL);
+                               }
+
+                       child = child->next;
+               }
+
+       g_object_get (G_OBJECT (fwidget), "form", &form, NULL);
+       g_object_set (G_OBJECT (w), "gdaex", gtk_form_get_db_connection_by_name (form, connection_name), NULL);
+
+       return TRUE;
+}
+
 /**
  * gtk_form_widget_decoder_get_value_stringify:
  * @widget:
@@ -145,7 +204,6 @@ gtk_form_widget_decoder_set_property (GObject *object,
                                 GParamSpec *pspec)
 {
        GtkFormWidgetDecoder *widget_entry = (GtkFormWidgetDecoder *)object;
-
        GtkFormWidgetDecoderPrivate *priv = GTK_FORM_WIDGET_DECODER_GET_PRIVATE (widget_entry);
 
        switch (property_id)
@@ -153,7 +211,7 @@ gtk_form_widget_decoder_set_property (GObject *object,
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
-         }
+               }
 }
 
 static void
@@ -163,7 +221,6 @@ gtk_form_widget_decoder_get_property (GObject *object,
                                 GParamSpec *pspec)
 {
        GtkFormWidgetDecoder *widget_entry = (GtkFormWidgetDecoder *)object;
-
        GtkFormWidgetDecoderPrivate *priv = GTK_FORM_WIDGET_DECODER_GET_PRIVATE (widget_entry);
 
        switch (property_id)
@@ -171,5 +228,5 @@ gtk_form_widget_decoder_get_property (GObject *object,
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
-         }
+               }
 }
index 9dbc5c20e19f4d87b4b63ead09aa65b0e8db9138..20da97f6a7d47020b040d895cdc72dfc82b95c2a 100644 (file)
@@ -50,6 +50,8 @@ GType gtk_form_widget_decoder_get_type (void) G_GNUC_CONST;
 
 GtkFormWidget *gtk_form_widget_decoder_new (void);
 
+gboolean gtk_form_widget_decoder_xml_parsing (GtkFormWidget *fwidget, xmlNodePtr xml_node);
+
 gchar *gtk_form_widget_decoder_get_value_stringify (GtkFormWidget *widget);
 
 gboolean gtk_form_widget_decoder_set_value_stringify (GtkFormWidget *fwidget, const gchar *value);