]> saetta.ns0.it Git - libgdaex/commitdiff
QueryEditor: must to be created 2 iwidgets and not only 1.
authorAndrea Zagli <andrea.zagli@email.it>
Wed, 13 Jan 2016 14:53:31 +0000 (15:53 +0100)
committerAndrea Zagli <andrea.zagli@email.it>
Wed, 13 Jan 2016 14:53:31 +0000 (15:53 +0100)
src/queryeditor.c

index 5de9a654026a0b648b83bd1bc7996143def5bf19..731e0fd2e834241201ed008980f03912960979a0 100644 (file)
@@ -1128,6 +1128,62 @@ gdaex_query_editor_str_to_join_type (gchar *str)
 typedef GdaExQueryEditorIWidget *(* IWidgetConstructorFunc) (void);
 typedef gboolean (* IWidgetXmlParsingFunc) (GdaExQueryEditorIWidget *, xmlNodePtr);
 
+static GdaExQueryEditorIWidget
+*gdaex_query_editor_iwidget_construct (GdaExQueryEditor *qe,
+                                                                          const gchar *type,
+                                                                          const gchar *table_name,
+                                                                          const gchar *field_name,
+                                                                          xmlNode *xnode)
+{
+       GdaExQueryEditorPrivate *priv;
+       GdaExQueryEditorClass *klass;
+
+       guint i;
+
+       IWidgetConstructorFunc iwidget_constructor;
+       IWidgetXmlParsingFunc iwidget_xml_parsing;
+
+       GdaExQueryEditorIWidget *iwidget;
+
+       klass = GDAEX_QUERY_EDITOR_GET_CLASS (qe);
+       priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe);
+
+       iwidget = NULL;
+       for (i = 0; i < priv->ar_modules->len; i++)
+               {
+                       if (g_module_symbol ((GModule *)g_ptr_array_index (priv->ar_modules, i),
+                                                                g_strconcat (type, "_new", NULL),
+                                                                (gpointer *)&iwidget_constructor))
+                               {
+                                       if (iwidget_constructor != NULL)
+                                               {
+                                                       iwidget = iwidget_constructor ();
+                                                       if (iwidget != NULL)
+                                                               {
+                                                                       g_signal_emit (qe, klass->iwidget_init_signal_id,
+                                                                                                  0,
+                                                                                                  iwidget,
+                                                                                                  table_name,
+                                                                                                  field_name);
+
+                                                                       if (g_module_symbol ((GModule *)g_ptr_array_index (priv->ar_modules, i),
+                                                                                                                g_strconcat (type, "_xml_parsing", NULL),
+                                                                                                                (gpointer *)&iwidget_xml_parsing))
+                                                                               {
+                                                                                       if (iwidget_xml_parsing != NULL)
+                                                                                               {
+                                                                                                       iwidget_xml_parsing (iwidget, xnode);
+                                                                                               }
+                                                                               }
+                                                               }
+                                                       break;
+                                               }
+                               }
+               }
+
+       return iwidget;
+}
+
 void
 gdaex_query_editor_load_tables_from_xml (GdaExQueryEditor *qe,
                                          xmlNode *root,
@@ -1162,9 +1218,6 @@ gdaex_query_editor_load_tables_from_xml (GdaExQueryEditor *qe,
        GdaExQueryEditorJoinType join_type;
        GSList *fields_joined;
 
-       IWidgetConstructorFunc iwidget_constructor;
-       IWidgetXmlParsingFunc iwidget_xml_parsing;
-
        g_return_if_fail (GDAEX_IS_QUERY_EDITOR (qe));
        g_return_if_fail (root != NULL);
        g_return_if_fail (xmlStrcmp (root->name, "gdaex_query_editor") == 0);
@@ -1364,62 +1417,29 @@ gdaex_query_editor_load_tables_from_xml (GdaExQueryEditor *qe,
                                                                                                {
                                                                                                        gchar *type;
 
-                                                                                                       guint i;
-
-                                                                                                       GdaExQueryEditorIWidget *iwidget;
-
                                                                                                        type = xmlGetProp (cur, (const xmlChar *)"type");
 
-                                                                                                       iwidget = NULL;
-                                                                                                       for (i = 0; i < priv->ar_modules->len; i++)
+                                                                                                       if (xmlStrcmp (cur->name, "widget") == 0
+                                                                                                               || xmlStrcmp (cur->name, "widget_from") == 0)
                                                                                                                {
-                                                                                                                       if (g_module_symbol ((GModule *)g_ptr_array_index (priv->ar_modules, i),
-                                                                                                                                                                g_strconcat (type, "_new", NULL),
-                                                                                                                                                                (gpointer *)&iwidget_constructor))
+                                                                                                                       field->iwidget_from = gdaex_query_editor_iwidget_construct (qe,
+                                                                                                                                                                                                                                               type,
+                                                                                                                                                                                                                                               table_name,
+                                                                                                                                                                                                                                               field->name,
+                                                                                                                                                                                                                                               cur);
+                                                                                                                       if (field->iwidget_from == NULL)
                                                                                                                                {
-                                                                                                                                       if (iwidget_constructor != NULL)
-                                                                                                                                               {
-                                                                                                                                                       iwidget = iwidget_constructor ();
-                                                                                                                                                       if (iwidget != NULL)
-                                                                                                                                                               {
-                                                                                                                                                                       g_signal_emit (qe, klass->iwidget_init_signal_id,
-                                                                                                                                                                                                  0,
-                                                                                                                                                                                                  iwidget,
-                                                                                                                                                                                                  table_name,
-                                                                                                                                                                                                  field->name);
-
-                                                                                                                                                                       if (g_module_symbol ((GModule *)g_ptr_array_index (priv->ar_modules, i),
-                                                                                                                                                                                                                g_strconcat (type, "_xml_parsing", NULL),
-                                                                                                                                                                                                                (gpointer *)&iwidget_xml_parsing))
-                                                                                                                                                                               {
-                                                                                                                                                                                       if (iwidget_xml_parsing != NULL)
-                                                                                                                                                                                               {
-                                                                                                                                                                                                       iwidget_xml_parsing (iwidget, cur);
-                                                                                                                                                                                               }
-                                                                                                                                                                               }
-                                                                                                                                                               }
-                                                                                                                                                       break;
-                                                                                                                                               }
+                                                                                                                                       g_warning (_("Unknown iwidget type «%s»."), type);
                                                                                                                                }
                                                                                                                }
-
-                                                                                                       if (iwidget == NULL)
-                                                                                                               {
-                                                                                                                       g_warning (_("Unknown iwidget type «%s»."), type);
-                                                                                                               }
-
-                                                                                                       if (xmlStrcmp (cur->name, "widget") == 0)
-                                                                                                               {
-                                                                                                                       field->iwidget_from = iwidget;
-                                                                                                                       field->iwidget_to = iwidget;
-                                                                                                               }
-                                                                                                       else if (xmlStrcmp (cur->name, "widget_from") == 0)
-                                                                                                               {
-                                                                                                                       field->iwidget_from = iwidget;
-                                                                                                               }
-                                                                                                       else if (xmlStrcmp (cur->name, "widget_to") == 0)
+                                                                                                       if (xmlStrcmp (cur->name, "widget") == 0
+                                                                                                               || xmlStrcmp (cur->name, "widget_to") == 0)
                                                                                                                {
-                                                                                                                       field->iwidget_to = iwidget;
+                                                                                                                       field->iwidget_to = gdaex_query_editor_iwidget_construct (qe,
+                                                                                                                                                                                                                                         type,
+                                                                                                                                                                                                                                         table_name,
+                                                                                                                                                                                                                                         field->name,
+                                                                                                                                                                                                                                         cur);
                                                                                                                }
                                                                                                }