]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Added class ZakFormElementExtension.
authorAndrea Zagli <azagli@libero.it>
Mon, 12 Jun 2017 19:35:13 +0000 (21:35 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 12 Jun 2017 19:47:34 +0000 (21:47 +0200)
src/Makefile.am
src/form.c
src/form.h
src/formelement.c
src/formelement.h
src/formelementextension.c [new file with mode: 0644]
src/formelementextension.h [new file with mode: 0644]
src/libzakform.h

index 83af3a3745f969203535c4789425d34ab01eb3dc..dfa41bab3e3179ad778534137f1991fcd1251de3 100644 (file)
@@ -18,6 +18,7 @@ libzakform_la_SOURCES = \
                         zakformmarshal.c \
                         form.c \
                         formelement.c \
+                        formelementextension.c \
                         formelementfilter.c \
                         formelementfilterluc.c \
                         formelementfiltertrim.c \
@@ -38,6 +39,7 @@ gir_include = \
                              zakformmarshal.h \
                              form.h \
                              formelement.h \
+                             formelementextension.h \
                              formelementfilter.h \
                              formelementfilterluc.h \
                              formelementfiltertrim.h \
index 9b701fbecb51d2d59c5db68ce111f9e226999b3a..94baf678935dc55630d32cad943f3fe2aacd2f40 100644 (file)
@@ -33,9 +33,6 @@
        #include <windows.h>
 #endif
 
-typedef ZakFormElement *(* FormElementConstructorFunc) (void);
-typedef GObject *(* FormElementExtensionConstructorFunc) (void);
-typedef gboolean (* FormElementExtensionXmlParsingFunc) (GObject *, xmlNodePtr);
 typedef ZakFormValidator *(* FormValidatorConstructorFunc) (void);
 
 static void zak_form_form_class_init (ZakFormFormClass *class);
@@ -156,12 +153,11 @@ zak_form_form_element_xml_parsing (ZakFormForm *zakform, ZakFormElement *element
        gchar *type;
        guint i;
 
-       GObject *extension;
+       ZakFormElementExtension *extension;
        ZakFormElementFilter *filter;
        ZakFormElementValidator *validator;
 
-       FormElementExtensionConstructorFunc extension_constructor;
-       FormElementExtensionXmlParsingFunc extension_xml_parsing;
+       ZakFormElementExtensionConstructorFunc extension_constructor;
        ZakFormElementFilterConstructorFunc filter_constructor;
        ZakFormElementValidatorConstructorFunc validator_constructor;
 
@@ -179,35 +175,17 @@ zak_form_form_element_xml_parsing (ZakFormForm *zakform, ZakFormElement *element
                                {
                                        type = (gchar *)xmlGetProp (xnode, (const xmlChar *)"type");
 
-                                       /* for each module */
-                                       for (i = 0; i < priv->ar_modules->len; i++)
+                                       extension_constructor = zak_form_form_get_form_element_extension (zakform, type);
+                                       if (extension_constructor != NULL)
                                                {
-                                                       if (g_module_symbol ((GModule *)g_ptr_array_index (priv->ar_modules, i),
-                                                                            g_strconcat (type, "_new", NULL),
-                                                                            (gpointer *)&extension_constructor))
-                                                               {
-                                                                       if (extension_constructor != NULL)
-                                                                               {
-                                                                                       extension = extension_constructor ();
-                                                                                       zak_form_element_add_extension (element, extension);
-
-                                                                                       if (g_module_symbol ((GModule *)g_ptr_array_index (priv->ar_modules, i),
-                                                                                                            g_strconcat (type, "_xml_parsing", NULL),
-                                                                                                            (gpointer *)&extension_xml_parsing))
-                                                                                               {
-                                                                                                       if (extension_xml_parsing != NULL)
-                                                                                                               {
-                                                                                                                       extension_xml_parsing (extension, xnode);
-                                                                                                               }
-                                                                                               }
+                                                       extension = extension_constructor ();
+                                                       zak_form_element_add_extension (element, extension);
 
-                                                                                       break;
-                                                                               }
-                                                               }
+                                                       zak_form_element_extension_xml_parsing (extension, xnode);
                                                }
-                                       if (i >= priv->ar_modules->len)
+                                       else
                                                {
-                                                       g_warning ("Filter «%s» not found.", type);
+                                                       g_warning ("Extension «%s» not found.", type);
                                                }
 
                                        to_unlink = TRUE;
@@ -354,6 +332,25 @@ zak_form_form_get_form_element_validator (ZakFormForm *zakform, const gchar *nam
        return validator_constructor;
 }
 
+/**
+ * zak_form_form_get_form_element_extension:
+ * @zakform:
+ * @namespace:
+ *
+ * Returns:
+ */
+ZakFormElementExtensionConstructorFunc
+zak_form_form_get_form_element_extension (ZakFormForm *zakform, const gchar *namespace)
+{
+       ZakFormElementExtensionConstructorFunc extension_constructor;
+
+       g_return_val_if_fail (ZAK_FORM_IS_FORM (zakform), NULL);
+
+       extension_constructor = (ZakFormElementExtensionConstructorFunc)_zak_form_form_get_module_new (zakform, namespace);
+
+       return extension_constructor;
+}
+
 /**
  * zak_form_form_load_from_xml:
  * @zakform:
index 7737f7b9e08474f91683b1284916c39e286495be..0e05f9d3b4d7ab58d31086fd4b4ead5ce60d06ae 100644 (file)
@@ -25,6 +25,7 @@
 #include <libxml/tree.h>
 
 #include "formelement.h"
+#include "formelementextension.h"
 #include "formiprovider.h"
 #include "formvalidator.h"
 
@@ -53,6 +54,9 @@ ZakFormElementFilterConstructorFunc zak_form_form_get_form_element_filter (ZakFo
 typedef ZakFormElementValidator *(* ZakFormElementValidatorConstructorFunc) (void);
 ZakFormElementValidatorConstructorFunc zak_form_form_get_form_element_validator (ZakFormForm *zakform, const gchar *namespace);
 
+typedef ZakFormElementExtension *(* ZakFormElementExtensionConstructorFunc) (void);
+ZakFormElementExtensionConstructorFunc zak_form_form_get_form_element_extension (ZakFormForm *zakform, const gchar *namespace);
+
 gboolean zak_form_form_load_from_xml (ZakFormForm *zakform, xmlDoc *xmldoc);
 gboolean zak_form_form_load_from_file (ZakFormForm *zakform, const gchar *filename);
 
index dccfe91188dc6cbf8c00d3e6f7eff82c9d2bc920..47d5bce576a91e1722b237ecd72088d09502d9e0 100644 (file)
@@ -242,7 +242,7 @@ zak_form_element_init (ZakFormElement *zak_form_element)
  *
  */
 void
-zak_form_element_add_extension (ZakFormElement *element, GObject *extension)
+zak_form_element_add_extension (ZakFormElement *element, ZakFormElementExtension *extension)
 {
        ZakFormElementPrivate *priv;
 
index 9fb99eb66cd4c898cdec9c0418559573b30397ba..22bcbc1d15421dd7ffd558d9b9c7c745dedfd262 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "formelementfilter.h"
 #include "formelementvalidator.h"
+#include "formelementextension.h"
 
 
 G_BEGIN_DECLS
@@ -118,7 +119,7 @@ gboolean zak_form_element_get_to_save (ZakFormElement *element);
 
 void zak_form_element_clear (ZakFormElement *element);
 
-void zak_form_element_add_extension (ZakFormElement *element, GObject *extension);
+void zak_form_element_add_extension (ZakFormElement *element, ZakFormElementExtension *extension);
 
 GPtrArray *zak_form_element_get_extensions (ZakFormElement *element);
 GPtrArray *zak_form_element_get_extensions_by_type (ZakFormElement *element, GType type);
diff --git a/src/formelementextension.c b/src/formelementextension.c
new file mode 100644 (file)
index 0000000..7a9f964
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2017 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+       #include <config.h>
+#endif
+
+#include <locale.h>
+
+#include <libzakutils/libzakutils.h>
+
+#include "formelementextension.h"
+
+enum
+{
+       PROP_0
+};
+
+static void zak_form_element_extension_class_init (ZakFormElementExtensionClass *class);
+static void zak_form_element_extension_init (ZakFormElementExtension *zak_form_element);
+
+static void zak_form_element_extension_construct (ZakFormElementExtension *element,
+                                        const gchar *id,
+                                        GHashTable *ht_attrs);
+
+static void zak_form_element_extension_set_property (GObject *object,
+                                           guint property_id,
+                                           const GValue *value,
+                                           GParamSpec *pspec);
+static void zak_form_element_extension_get_property (GObject *object,
+                                           guint property_id,
+                                           GValue *value,
+                                           GParamSpec *pspec);
+
+static void zak_form_element_extension_dispose (GObject *gobject);
+static void zak_form_element_extension_finalize (GObject *gobject);
+
+typedef struct
+       {
+               gpointer useless;
+       } ZakFormElementExtensionPrivate;
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ZakFormElementExtension, zak_form_element_extension, G_TYPE_OBJECT)
+
+static void
+zak_form_element_extension_class_init (ZakFormElementExtensionClass *class)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+       object_class->set_property = zak_form_element_extension_set_property;
+       object_class->get_property = zak_form_element_extension_get_property;
+       object_class->dispose = zak_form_element_extension_dispose;
+       object_class->finalize = zak_form_element_extension_finalize;
+}
+
+static void
+zak_form_element_extension_init (ZakFormElementExtension *zak_form_element)
+{
+       ZakFormElementExtensionPrivate *priv = zak_form_element_extension_get_instance_private (zak_form_element);
+
+}
+
+/**
+ * zak_form_element_extension_xml_parsing:
+ * @element:
+ * @xmlnode:
+ *
+ */
+void
+zak_form_element_extension_xml_parsing (ZakFormElementExtension *element, xmlNode *xmlnode)
+{
+       if (ZAK_FORM_ELEMENT_EXTENSION_GET_CLASS (element)->xml_parsing != NULL)
+               {
+                       ZAK_FORM_ELEMENT_EXTENSION_GET_CLASS (element)->xml_parsing (element, xmlnode);
+               }
+}
+
+/* PRIVATE */
+static void
+zak_form_element_extension_set_property (GObject *object,
+                   guint property_id,
+                   const GValue *value,
+                   GParamSpec *pspec)
+{
+       ZakFormElementExtension *zak_form_element_extension = (ZakFormElementExtension *)object;
+       ZakFormElementExtensionPrivate *priv = zak_form_element_extension_get_instance_private (zak_form_element_extension);
+
+       switch (property_id)
+               {
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                       break;
+               }
+}
+
+static void
+zak_form_element_extension_get_property (GObject *object,
+                   guint property_id,
+                   GValue *value,
+                   GParamSpec *pspec)
+{
+       ZakFormElementExtension *zak_form_element_extension = (ZakFormElementExtension *)object;
+       ZakFormElementExtensionPrivate *priv = zak_form_element_extension_get_instance_private (zak_form_element_extension);
+
+       switch (property_id)
+               {
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                       break;
+               }
+}
+
+static void
+zak_form_element_extension_dispose (GObject *gobject)
+{
+       ZakFormElementExtension *zak_form_element_extension = (ZakFormElementExtension *)gobject;
+       ZakFormElementExtensionPrivate *priv = zak_form_element_extension_get_instance_private (zak_form_element_extension);
+
+
+
+       GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+       parent_class->dispose (gobject);
+}
+
+static void
+zak_form_element_extension_finalize (GObject *gobject)
+{
+       ZakFormElementExtension *zak_form_element_extension = (ZakFormElementExtension *)gobject;
+       ZakFormElementExtensionPrivate *priv = zak_form_element_extension_get_instance_private (zak_form_element_extension);
+
+
+
+       GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+       parent_class->finalize (gobject);
+}
diff --git a/src/formelementextension.h b/src/formelementextension.h
new file mode 100644 (file)
index 0000000..35fac40
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2017 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __ZAK_FORM_ELEMENT_EXTENSION_H__
+#define __ZAK_FORM_ELEMENT_EXTENSION_H__
+
+
+#include <glib-object.h>
+
+#include <libxml/tree.h>
+
+
+G_BEGIN_DECLS
+
+
+#define ZAK_FORM_TYPE_ELEMENT_EXTENSION zak_form_element_extension_get_type ()
+G_DECLARE_DERIVABLE_TYPE (ZakFormElementExtension, zak_form_element_extension, ZAK_FORM, ELEMENT_EXTENSION, GObject)
+
+struct _ZakFormElementExtensionClass
+       {
+               GObjectClass parent_class;
+
+               void (*xml_parsing) (ZakFormElementExtension *element, xmlNode *xmlnode);
+       };
+
+void zak_form_element_extension_xml_parsing (ZakFormElementExtension *element, xmlNode *xmlnode);
+
+
+G_END_DECLS
+
+
+#endif /* __ZAK_FORM_ELEMENT_EXTENSION_H__ */
index 63e78ab3faeb5e0a144791725cf99e9300994871..da082764bc1f1f51c654e5eb36a7c36cf0d7f359 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <libzakform/formelement.h>
 
+#include <libzakform/formelementextension.h>
+
 #include <libzakform/formelementfilter.h>
 #include <libzakform/formelementfilterluc.h>
 #include <libzakform/formelementfiltertrim.h>