]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Added function ZakFormForm::get_form_element_filter.
authorAndrea Zagli <azagli@libero.it>
Mon, 12 Jun 2017 13:39:32 +0000 (15:39 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 12 Jun 2017 13:39:32 +0000 (15:39 +0200)
src/form.c
src/form.h

index 72e5dc6075644bfadb4ef782b9b952552b73b5f0..637f007fa116f7bdcff87479a9e00e1cca2a6e60 100644 (file)
@@ -37,7 +37,6 @@ typedef ZakFormElement *(* FormElementConstructorFunc) (void);
 typedef gboolean (* FormElementXmlParsingFunc) (ZakFormElement *, xmlNodePtr);
 typedef GObject *(* FormElementExtensionConstructorFunc) (void);
 typedef gboolean (* FormElementExtensionXmlParsingFunc) (GObject *, xmlNodePtr);
-typedef ZakFormElementFilter *(* FormElementFilterConstructorFunc) (void);
 typedef ZakFormValidator *(* FormValidatorConstructorFunc) (void);
 
 static void zak_form_form_class_init (ZakFormFormClass *class);
@@ -164,7 +163,7 @@ zak_form_form_element_xml_parsing (ZakFormForm *zakform, ZakFormElement *element
 
        FormElementExtensionConstructorFunc extension_constructor;
        FormElementExtensionXmlParsingFunc extension_xml_parsing;
-       FormElementFilterConstructorFunc filter_constructor;
+       ZakFormElementFilterConstructorFunc filter_constructor;
        ZakFormElementValidatorConstructorFunc validator_constructor;
 
        gboolean to_unlink;
@@ -218,25 +217,15 @@ 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++)
+                                       filter_constructor = zak_form_form_get_form_element_filter (zakform, type);
+                                       if (filter_constructor != NULL)
                                                {
-                                                       if (g_module_symbol ((GModule *)g_ptr_array_index (priv->ar_modules, i),
-                                                                            g_strconcat (type, "_new", NULL),
-                                                                            (gpointer *)&filter_constructor))
-                                                               {
-                                                                       if (filter_constructor != NULL)
-                                                                               {
-                                                                                       filter = filter_constructor ();
-                                                                                       zak_form_element_add_filter (element, filter);
-
-                                                                                       zak_form_element_filter_xml_parsing (filter, xnode);
+                                                       filter = filter_constructor ();
+                                                       zak_form_element_add_filter (element, filter);
 
-                                                                                       break;
-                                                                               }
-                                                               }
+                                                       zak_form_element_filter_xml_parsing (filter, xnode);
                                                }
-                                       if (i >= priv->ar_modules->len)
+                                       else
                                                {
                                                        g_warning ("Filter «%s» not found.", type);
                                                }
@@ -309,6 +298,25 @@ _zak_form_form_get_module_new (ZakFormForm *zakform, const gchar *namespace)
        return ret;
 }
 
+/**
+ * zak_form_form_get_form_element_filter:
+ * @zakform:
+ * @namespace:
+ *
+ * Returns:
+ */
+ZakFormElementFilterConstructorFunc
+zak_form_form_get_form_element_filter (ZakFormForm *zakform, const gchar *namespace)
+{
+       ZakFormElementFilterConstructorFunc filter_constructor;
+
+       g_return_val_if_fail (ZAK_FORM_IS_FORM (zakform), NULL);
+
+       filter_constructor = (ZakFormElementFilterConstructorFunc)_zak_form_form_get_module_new (zakform, namespace);
+
+       return filter_constructor;
+}
+
 /**
  * zak_form_form_get_form_element_validator:
  * @zakform:
index c2542e6c0ebe36c620e0df88c47c44ddaab9e9c8..23e0faf017f1b412e8bb5a87d14c2d810ebf8f0c 100644 (file)
@@ -44,8 +44,10 @@ struct _ZakFormFormClass
        void (*element_added) (ZakFormForm *zakform, ZakFormElement *element);
 };
 
-typedef ZakFormElementValidator *(* ZakFormElementValidatorConstructorFunc) (void);
+typedef ZakFormElementFilter *(* ZakFormElementFilterConstructorFunc) (void);
+ZakFormElementFilterConstructorFunc zak_form_form_get_form_element_filter (ZakFormForm *zakform, const gchar *namespace);
 
+typedef ZakFormElementValidator *(* ZakFormElementValidatorConstructorFunc) (void);
 ZakFormElementValidatorConstructorFunc zak_form_form_get_form_element_validator (ZakFormForm *zakform, const gchar *namespace);
 
 gboolean zak_form_form_load_from_xml (ZakFormForm *zakform, xmlDoc *xmldoc);