From: Andrea Zagli Date: Sat, 18 Jun 2011 16:30:31 +0000 (+0200) Subject: Completed GtkFormWidgetDecoder. X-Git-Tag: 0.3.1~3 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=4da56663afcf3b164dcbb62fa20dfeda541e889a;p=libgtkform Completed GtkFormWidgetDecoder. Added the ability for plugin to auto parse xml. --- diff --git a/configure.ac b/configure.ac index 37ac490..ecf171e 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/form.c b/src/form.c index 8fd465e..e6b2e3d 100644 --- a/src/form.c +++ b/src/form.c @@ -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; diff --git a/ui/Makefile.am b/ui/Makefile.am index 42b7e73..e4f4503 100644 --- a/ui/Makefile.am +++ b/ui/Makefile.am @@ -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) diff --git a/ui/gtkformdecoder.c b/ui/gtkformdecoder.c index bf0ba1d..d8d7b7f 100644 --- a/ui/gtkformdecoder.c +++ b/ui/gtkformdecoder.c @@ -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); diff --git a/ui/gtkformwidgetdecoder.c b/ui/gtkformwidgetdecoder.c index c6190bd..7089fa0 100644 --- a/ui/gtkformwidgetdecoder.c +++ b/ui/gtkformwidgetdecoder.c @@ -18,6 +18,9 @@ #include +#include +#include + #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; - } + } } diff --git a/ui/gtkformwidgetdecoder.h b/ui/gtkformwidgetdecoder.h index 9dbc5c2..20da97f 100644 --- a/ui/gtkformwidgetdecoder.h +++ b/ui/gtkformwidgetdecoder.h @@ -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);