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

index b5825837d24b10dcc36419b479d8ae2fdd0da234..9b701fbecb51d2d59c5db68ce111f9e226999b3a 100644 (file)
@@ -297,6 +297,25 @@ _zak_form_form_get_module_new (ZakFormForm *zakform, const gchar *namespace)
        return ret;
 }
 
+/**
+ * zak_form_form_get_form_element:
+ * @zakform:
+ * @namespace:
+ *
+ * Returns:
+ */
+ZakFormElementConstructorFunc
+zak_form_form_get_form_element (ZakFormForm *zakform, const gchar *namespace)
+{
+       ZakFormElementConstructorFunc element_constructor;
+
+       g_return_val_if_fail (ZAK_FORM_IS_FORM (zakform), NULL);
+
+       element_constructor = (ZakFormElementConstructorFunc)_zak_form_form_get_module_new (zakform, namespace);
+
+       return element_constructor;
+}
+
 /**
  * zak_form_form_get_form_element_filter:
  * @zakform:
@@ -357,7 +376,7 @@ zak_form_form_load_from_xml (ZakFormForm *zakform, xmlDoc *xmldoc)
        guint i;
        gint y;
 
-       FormElementConstructorFunc element_constructor;
+       ZakFormElementConstructorFunc element_constructor;
        FormValidatorConstructorFunc validator_constructor;
 
        xmlXPathContextPtr xpcontext;
@@ -387,33 +406,23 @@ zak_form_form_load_from_xml (ZakFormForm *zakform, xmlDoc *xmldoc)
 
                                                                        type = (gchar *)xmlGetProp (cur, (const xmlChar *)"type");
 
-                                                                       /* for each module */
-                                                                       for (i = 0; i < priv->ar_modules->len; i++)
+                                                                       element_constructor = zak_form_form_get_form_element (zakform, type);
+                                                                       if (element_constructor != NULL)
                                                                                {
-                                                                                       if (g_module_symbol ((GModule *)g_ptr_array_index (priv->ar_modules, i),
-                                                                                                            g_strconcat (type, "_new", NULL),
-                                                                                                            (gpointer *)&element_constructor))
+                                                                                       element = element_constructor ();
+                                                                                       if (element != NULL)
                                                                                                {
-                                                                                                       if (element_constructor != NULL)
-                                                                                                               {
-                                                                                                                       element = element_constructor ();
-                                                                                                                       if (element != NULL)
-                                                                                                                               {
-                                                                                                                                       zak_form_form_add_element (zakform, element);
-
-                                                                                                                                       cur_clean = xmlCopyNode (cur, 1);
-                                                                                                                                       zak_form_form_element_xml_parsing (zakform, element, cur_clean);
-                                                                                                                                       zak_form_element_xml_parsing (element, cur_clean);
-
-                                                                                                                                       xmlUnlinkNode (cur_clean);
-                                                                                                                                       xmlFreeNode (cur_clean);
-                                                                                                                               }
-                                                                                                                       break;
-                                                                                                               }
+                                                                                                       zak_form_form_add_element (zakform, element);
+
+                                                                                                       cur_clean = xmlCopyNode (cur, 1);
+                                                                                                       zak_form_form_element_xml_parsing (zakform, element, cur_clean);
+                                                                                                       zak_form_element_xml_parsing (element, cur_clean);
+
+                                                                                                       xmlUnlinkNode (cur_clean);
+                                                                                                       xmlFreeNode (cur_clean);
                                                                                                }
                                                                                }
-
-                                                                       if (element == NULL)
+                                                                       else
                                                                                {
                                                                                        g_warning (_("Unknown element type «%s»."), type);
                                                                                }
index 23e0faf017f1b412e8bb5a87d14c2d810ebf8f0c..7737f7b9e08474f91683b1284916c39e286495be 100644 (file)
@@ -44,6 +44,9 @@ struct _ZakFormFormClass
        void (*element_added) (ZakFormForm *zakform, ZakFormElement *element);
 };
 
+typedef ZakFormElement *(* ZakFormElementConstructorFunc) (void);
+ZakFormElementConstructorFunc zak_form_form_get_form_element (ZakFormForm *zakform, const gchar *namespace);
+
 typedef ZakFormElementFilter *(* ZakFormElementFilterConstructorFunc) (void);
 ZakFormElementFilterConstructorFunc zak_form_form_get_form_element_filter (ZakFormForm *zakform, const gchar *namespace);