]> saetta.ns0.it Git - libgdaex/commitdiff
Enabled modules in QueryEditor for value choosing.
authorAndrea Zagli <andrea.zagli@email.it>
Sat, 9 Jan 2016 18:30:23 +0000 (19:30 +0100)
committerAndrea Zagli <andrea.zagli@email.it>
Sat, 9 Jan 2016 18:30:23 +0000 (19:30 +0100)
Added module GdaExQueryEditorEntryDate.

configure.ac
libgdaex.pc.in
src/Makefile.am
src/queryeditor.c
src/queryeditorentrydate.c [new file with mode: 0644]
src/queryeditorentrydate.h [new file with mode: 0644]
tests/query_editor.xml

index 1719743dbd50acbdcbbf27713ff6831a274c3121..a56219254ea1ed35a56bd1611e8cc45dff79c94b 100644 (file)
@@ -43,7 +43,8 @@ AM_GLIB_GNU_GETTEXT
 PKG_CHECK_MODULES(GDAEX, [gmodule-2.0 >= 2
                           libgda-5.0 >= 5
                           gio-2.0 >= 2.36
-                          gtk+-3.0 >= 3])
+                          gtk+-3.0 >= 3
+                                                 libzakutils])
 
 AC_SUBST(GDAEX_CFLAGS)
 AC_SUBST(GDAEX_LIBS)
index cdb1d13bff62ad52224b45712bec7745419f06ce..7f64fdfa691e36db8c02d2173a4cb0d42b23411d 100644 (file)
@@ -2,6 +2,7 @@ prefix=@prefix@
 exec_prefix=@exec_prefix@
 libdir=@libdir@
 includedir=@includedir@
+modulesdir=@libdir@/@PACKAGE@/modules
 
 Name: @PACKAGE_NAME@
 Description: A libgda's "subclass"
index 610d7214ccd029b085ad01bd7229b0bd4c4cfcbd..f6640802c05934843bb012bc59e12318312e3189 100644 (file)
@@ -4,6 +4,7 @@ AM_CPPFLAGS = -I$(top_srcdir) \
               $(GDAEX_CFLAGS) \
               -DGUIDIR=\""$(guidir)"\" \
               -DLOCALEDIR=\"$(localedir)\" \
+              -DMODULESDIR=\""$(libdir)/$(PACKAGE)/modules"\" \
               -DG_LOG_DOMAIN=\"GdaEx\"
 
 LIBS = $(GDAEX_LIBS)
@@ -14,6 +15,7 @@ libgdaex_la_SOURCES = gdaex.c \
                       queryeditor.c \
                       queryeditor_widget_interface.c \
                       queryeditorentry.c \
+                      queryeditorentrydate.c \
                       sqlbuilder.c
 
 libgdaex_la_LDFLAGS = -no-undefined
@@ -23,6 +25,13 @@ libgdaex_include_HEADERS = libgdaex.h \
                            queryeditor.h \
                            queryeditor_widget_interface.h \
                            queryeditorentry.h \
+                           queryeditorentrydate.h \
                            sqlbuilder.h
 
 libgdaex_includedir = $(includedir)/libgdaex
+
+install-exec-hook:
+       mkdir -p "$(libdir)/$(PACKAGE)/modules"
+
+uninstall-hook:
+       rm -rf "$(libdir)/$(PACKAGE)"
index b5c825c1012e24a7c901e1e4c79e009545fdae6b..d7f367398c50a932c586009ce486d2b84475ea3f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011-2012 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2011-2016 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
@@ -30,6 +30,7 @@
 
 #include "queryeditor.h"
 #include "queryeditorentry.h"
+#include "queryeditorentrydate.h"
 
 #define GROUP "{--group--}"
 
@@ -175,21 +176,12 @@ static void gdaex_query_editor_on_txt2_btn_browse_clicked (gpointer instance, gp
 
 #define GDAEX_QUERY_EDITOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GDAEX_QUERY_EDITOR, GdaExQueryEditorPrivate))
 
-typedef GtkWidget *(* GtkDateEntryNew) (const gchar *format,
-                                        const gchar *separator,
-                                        gboolean calendar_button_is_visible);
-typedef void (* GtkDateEntrySetDateVisible) (gpointer gtkdateentry, gboolean visible);
-typedef void (* GtkDateEntrySetTimeVisible) (gpointer gtkdateentry, gboolean visible);
-
 typedef struct _GdaExQueryEditorPrivate GdaExQueryEditorPrivate;
 struct _GdaExQueryEditorPrivate
        {
                GdaEx *gdaex;
 
-               GModule *gtk_date_entry_module;
-               GtkDateEntryNew gtk_date_entry_new;
-               GtkDateEntrySetDateVisible gtk_date_entry_set_date_visible;
-               GtkDateEntrySetTimeVisible gtk_date_entry_set_time_visible;
+               GPtrArray *ar_modules;
 
                GtkBuilder *gtkbuilder;
 
@@ -310,6 +302,103 @@ gdaex_query_editor_init (GdaExQueryEditor *gdaex_query_editor)
 
 }
 
+static void
+gdaex_query_editor_load_modules (GdaExQueryEditor *gdaex_query_editor)
+{
+       GdaExQueryEditorPrivate *priv;
+
+       gchar *modulesdir;
+       GDir *dir;
+       GError *error;
+
+       GModule *module;
+       const gchar *filename;
+
+       if (g_module_supported ())
+               {
+                       priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (gdaex_query_editor);
+
+                       modulesdir = (gchar *)g_getenv ("LIBGDAEX_MODULESDIR");
+                       if (modulesdir == NULL)
+                               {
+#ifdef G_OS_WIN32
+
+                                       gchar *moddir;
+                                       gchar *p;
+
+                                       moddir = g_win32_get_package_installation_directory_of_module (NULL);
+
+                                       p = g_strrstr (moddir, g_strdup_printf ("%c", G_DIR_SEPARATOR));
+                                       if (p != NULL
+                                               && (g_ascii_strcasecmp (p + 1, "src") == 0
+                                                       || g_ascii_strcasecmp (p + 1, ".libs") == 0))
+                                               {
+                                                       modulesdir = g_strdup (MODULESDIR);
+                                               }
+                                       else
+                                               {
+                                                       modulesdir = g_build_filename (moddir, "lib", PACKAGE, "modules", NULL);
+                                               }
+
+#else
+
+                                       modulesdir = g_strdup (MODULESDIR);
+
+#endif
+                               }
+
+                       /* load myself as module (for filters and validators) */
+                       module = g_module_open (NULL, G_MODULE_BIND_LAZY);
+                       if (module == NULL)
+                               {
+                                       g_warning (_("Unable to load module of myself"));
+                               }
+                       else
+                               {
+                                       if (priv->ar_modules == NULL)
+                                               {
+                                                       priv->ar_modules = g_ptr_array_new ();
+                                               }
+                                       g_ptr_array_add (priv->ar_modules, (gpointer)module);
+                               }
+
+                       /* for each file in MODULESDIR */
+                       error = NULL;
+                       dir = g_dir_open (modulesdir, 0, &error);
+                       if (dir != NULL && error == NULL)
+                               {
+                                       while ((filename = g_dir_read_name (dir)) != NULL)
+                                               {
+                                                       /* trying to open the module */
+                                                       module = g_module_open (filename, G_MODULE_BIND_LAZY);
+                                                       if (module != NULL)
+                                                               {
+                                                                       if (priv->ar_modules == NULL)
+                                                                               {
+                                                                                       priv->ar_modules = g_ptr_array_new ();
+                                                                               }
+                                                                   g_ptr_array_add (priv->ar_modules, (gpointer)module);
+                                                               }
+                                                       else
+                                                               {
+                                                                       g_warning (_("Unable to load %s: %s."), filename, g_module_error ());
+                                                               }
+                                               }
+
+                                       g_dir_close (dir);
+                               }
+                       else
+                               {
+                                       g_warning (_("Unable to open modules dir: %s."),
+                                                          error != NULL && error->message != NULL ? error->message : _("no details"));
+                               }
+               }
+       else
+               {
+                       g_warning (_("Modules not supported by this operating system."));
+               }
+}
+
 /**
  * gdaex_query_editor_new:
  * @gdaex:
@@ -341,33 +430,7 @@ GdaExQueryEditor
 
        priv->gdaex = gdaex;
 
-       /* test if we can use GtkDateEntry */
-       priv->gtk_date_entry_module = NULL;
-       priv->gtk_date_entry_new = NULL;
-       priv->gtk_date_entry_set_date_visible = NULL;
-       priv->gtk_date_entry_set_time_visible = NULL;
-       if (g_module_supported ())
-               {
-                       /* TODO it must be found in a better way */
-#ifdef G_OS_WIN32
-                       priv->gtk_date_entry_module = g_module_open (g_build_filename (g_win32_get_package_installation_directory_of_module (NULL), "libgtkdateentry-0.dll", NULL), G_MODULE_BIND_LAZY);
-#else
-                       priv->gtk_date_entry_module = g_module_open ("/usr/local/lib/libgtkdateentry.la", G_MODULE_BIND_LAZY);
-#endif
-                       if (priv->gtk_date_entry_module != NULL)
-                               {
-                                       if (!g_module_symbol (priv->gtk_date_entry_module, "gtk_date_entry_new", (gpointer *)&(priv->gtk_date_entry_new))
-                                           || !g_module_symbol (priv->gtk_date_entry_module, "gtk_date_entry_set_date_visible", (gpointer *)&(priv->gtk_date_entry_set_date_visible))
-                                           || !g_module_symbol (priv->gtk_date_entry_module, "gtk_date_entry_set_time_visible", (gpointer *)&(priv->gtk_date_entry_set_time_visible)))
-                                               {
-                                                       g_module_close (priv->gtk_date_entry_module);
-                                                       priv->gtk_date_entry_module = NULL;
-                                                       priv->gtk_date_entry_new = NULL;
-                                                       priv->gtk_date_entry_set_date_visible = NULL;
-                                                       priv->gtk_date_entry_set_time_visible = NULL;
-                                               }
-                               }
-               }
+       gdaex_query_editor_load_modules (gdaex_query_editor);
 
        priv->gtkbuilder = gdaex_get_gtkbuilder (priv->gdaex);
 
@@ -657,80 +720,62 @@ gdaex_query_editor_table_add_field (GdaExQueryEditor *qe,
 
        if (!GDAEX_QUERY_EDITOR_IS_IWIDGET (_field->iwidget_from))
                {
-                       if (priv->gtk_date_entry_module != NULL
-                           && (_field->type == GDAEX_QE_FIELD_TYPE_DATE
-                               || _field->type == GDAEX_QE_FIELD_TYPE_DATETIME
-                               || _field->type == GDAEX_QE_FIELD_TYPE_TIME))
+                       if (_field->type == GDAEX_QE_FIELD_TYPE_DATE
+                               || _field->type == GDAEX_QE_FIELD_TYPE_DATETIME
+                               || _field->type == GDAEX_QE_FIELD_TYPE_TIME)
                                {
-                                       _field->iwidget_from = GDAEX_QUERY_EDITOR_IWIDGET (priv->gtk_date_entry_new (NULL, NULL, TRUE));
+                                       _field->iwidget_from = GDAEX_QUERY_EDITOR_IWIDGET (gdaex_query_editor_entry_date_new ());
+                                       /* TODO
+                                        * read format from locale */
                                        if (_field->type == GDAEX_QE_FIELD_TYPE_DATE)
                                                {
-                                                       priv->gtk_date_entry_set_date_visible ((gpointer)_field->iwidget_from, TRUE);
-                                                       priv->gtk_date_entry_set_time_visible ((gpointer)_field->iwidget_from, FALSE);
+                                                       gdaex_query_editor_entry_date_set_format (GDAEX_QUERY_EDITOR_ENTRY_DATE (_field->iwidget_from), "%d/%m/%Y");
+                                                       gtk_entry_set_max_length (GTK_ENTRY (_field->iwidget_from), 10);
                                                }
                                        else if (_field->type == GDAEX_QE_FIELD_TYPE_DATETIME)
                                                {
+                                                       gdaex_query_editor_entry_date_set_format (GDAEX_QUERY_EDITOR_ENTRY_DATE (_field->iwidget_from), "%d/%m/%Y %H:%M:%S");
+                                                       gtk_entry_set_max_length (GTK_ENTRY (_field->iwidget_from), 19);
                                                }
                                        else if (_field->type == GDAEX_QE_FIELD_TYPE_TIME)
                                                {
-                                                       priv->gtk_date_entry_set_date_visible ((gpointer)_field->iwidget_from, FALSE);
-                                                       priv->gtk_date_entry_set_time_visible ((gpointer)_field->iwidget_from, TRUE);
+                                                       gdaex_query_editor_entry_date_set_format (GDAEX_QUERY_EDITOR_ENTRY_DATE (_field->iwidget_from), "%H:%M:%S");
+                                                       gtk_entry_set_max_length (GTK_ENTRY (_field->iwidget_from), 8);
                                                }
                                }
                        else
                                {
                                        _field->iwidget_from = GDAEX_QUERY_EDITOR_IWIDGET (gdaex_query_editor_entry_new ());
-                                       if (_field->type == GDAEX_QE_FIELD_TYPE_DATE)
-                                               {
-                                                       gtk_entry_set_max_length (GTK_ENTRY (_field->iwidget_from), 10);
-                                               }
-                                       else if (_field->type == GDAEX_QE_FIELD_TYPE_DATETIME)
-                                               {
-                                                       gtk_entry_set_max_length (GTK_ENTRY (_field->iwidget_from), 19);
-                                               }
-                                       else if (_field->type == GDAEX_QE_FIELD_TYPE_TIME)
-                                               {
-                                                       gtk_entry_set_max_length (GTK_ENTRY (_field->iwidget_from), 8);
-                                               }
                                }
                }
        if (!GDAEX_QUERY_EDITOR_IS_IWIDGET (_field->iwidget_to))
                {
-                       if (priv->gtk_date_entry_module != NULL
-                           && (_field->type == GDAEX_QE_FIELD_TYPE_DATE
-                               || _field->type == GDAEX_QE_FIELD_TYPE_DATETIME
-                               || _field->type == GDAEX_QE_FIELD_TYPE_TIME))
+                       if (_field->type == GDAEX_QE_FIELD_TYPE_DATE
+                               || _field->type == GDAEX_QE_FIELD_TYPE_DATETIME
+                               || _field->type == GDAEX_QE_FIELD_TYPE_TIME)
                                {
-                                       _field->iwidget_to = GDAEX_QUERY_EDITOR_IWIDGET (priv->gtk_date_entry_new (NULL, NULL, TRUE));
+                                       _field->iwidget_to = GDAEX_QUERY_EDITOR_IWIDGET (gdaex_query_editor_entry_date_new ());
+                                       /* TODO
+                                        * read format from locale */
                                        if (_field->type == GDAEX_QE_FIELD_TYPE_DATE)
                                                {
-                                                       priv->gtk_date_entry_set_date_visible ((gpointer)_field->iwidget_to, TRUE);
-                                                       priv->gtk_date_entry_set_time_visible ((gpointer)_field->iwidget_to, FALSE);
+                                                       gdaex_query_editor_entry_date_set_format (GDAEX_QUERY_EDITOR_ENTRY_DATE (_field->iwidget_to), "%d/%m/%Y");
+                                                       gtk_entry_set_max_length (GTK_ENTRY (_field->iwidget_to), 10);
                                                }
                                        else if (_field->type == GDAEX_QE_FIELD_TYPE_DATETIME)
                                                {
+                                                       gdaex_query_editor_entry_date_set_format (GDAEX_QUERY_EDITOR_ENTRY_DATE (_field->iwidget_to), "%d/%m/%Y %H:%M:%S");
+                                                       gtk_entry_set_max_length (GTK_ENTRY (_field->iwidget_to), 19);
                                                }
                                        else if (_field->type == GDAEX_QE_FIELD_TYPE_TIME)
                                                {
-                                                       priv->gtk_date_entry_set_date_visible ((gpointer)_field->iwidget_to, FALSE);
-                                                       priv->gtk_date_entry_set_time_visible ((gpointer)_field->iwidget_to, TRUE);
+                                                       gdaex_query_editor_entry_date_set_format (GDAEX_QUERY_EDITOR_ENTRY_DATE (_field->iwidget_to), "%H:%M:%S");
+                                                       gtk_entry_set_max_length (GTK_ENTRY (_field->iwidget_to), 8);
                                                }
                                }
                        else
                                {
                                        _field->iwidget_to = GDAEX_QUERY_EDITOR_IWIDGET (gdaex_query_editor_entry_new ());
-                                       if (_field->type == GDAEX_QE_FIELD_TYPE_DATE)
-                                               {
-                                                       gtk_entry_set_max_length (GTK_ENTRY (_field->iwidget_to), 10);
-                                               }
-                                       else if (_field->type == GDAEX_QE_FIELD_TYPE_DATETIME)
-                                               {
-                                                       gtk_entry_set_max_length (GTK_ENTRY (_field->iwidget_to), 19);
-                                               }
-                                       else if (_field->type == GDAEX_QE_FIELD_TYPE_TIME)
-                                               {
-                                                       gtk_entry_set_max_length (GTK_ENTRY (_field->iwidget_to), 8);
-                                               }
                                }
                }
 
@@ -1062,11 +1107,16 @@ gdaex_query_editor_str_to_join_type (gchar *str)
        return ret;
 }
 
+typedef GdaExQueryEditorIWidget *(* IWidgetConstructorFunc) (void);
+typedef gboolean (* IWidgetXmlParsingFunc) (GdaExQueryEditorIWidget *, xmlNodePtr);
+
 void
 gdaex_query_editor_load_tables_from_xml (GdaExQueryEditor *qe,
                                          xmlNode *root,
                                          gboolean clean)
 {
+       GdaExQueryEditorPrivate *priv;
+
        xmlDoc *xdoc;
        xmlXPathContextPtr xpcontext;
        xmlXPathObjectPtr xpresult;
@@ -1093,10 +1143,15 @@ 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);
 
+       priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe);
+
        if (clean)
                {
                        gdaex_query_editor_clean (qe);
@@ -1282,6 +1337,64 @@ gdaex_query_editor_load_tables_from_xml (GdaExQueryEditor *qe,
                                                                                                                        xdecode = xdecode->next;
                                                                                                                }
                                                                                                }
+                                                                                       else if (xmlStrcmp (cur->name, "widget") == 0
+                                                                                                        || xmlStrcmp (cur->name, "widget_from") == 0
+                                                                                                        || xmlStrcmp (cur->name, "widget_to") == 0)
+                                                                                               {
+                                                                                                       gchar *type;
+
+                                                                                                       guint i;
+
+                                                                                                       GdaExQueryEditorIWidget *iwidget;
+
+                                                                                                       type = xmlGetProp (xnode, (const xmlChar *)"type");
+
+                                                                                                       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)
+                                                                                                                                                               {
+                                                                                                                                                                       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;
+                                                                                                                                               }
+                                                                                                                               }
+                                                                                                               }
+
+                                                                                                       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)
+                                                                                                               {
+                                                                                                                       field->iwidget_to = iwidget;
+                                                                                                               }
+                                                                                               }
 
                                                                                        cur = cur->next;
                                                                                }
@@ -1458,11 +1571,11 @@ static GDate
        month = 0;
        day = 0;
 
-       if (strlen (sql) >= 10)
+       if (strlen (sql + 1) >= 10)
                {
-                       year = strtol (g_strndup (sql, 4), NULL, 10);
-                       month = strtol (g_strndup (sql + 5, 2), NULL, 10);
-                       day = strtol (g_strndup (sql + 8, 2), NULL, 10);
+                       year = strtol (g_strndup (sql + 1, 4), NULL, 10);
+                       month = strtol (g_strndup (sql + 6, 2), NULL, 10);
+                       day = strtol (g_strndup (sql + 9, 2), NULL, 10);
 
                        ret = g_date_new_dmy (day,
                                              month,
@@ -1479,21 +1592,21 @@ static GdaTimestamp
 
        ret = NULL;
 
-       if (strlen (sql) >= 10)
+       if (strlen (sql + 1) >= 10)
                {
                        ret = g_new0 (GdaTimestamp, 1);
 
-                       ret->year = strtol (g_strndup (sql, 4), NULL, 10);
-                       ret->month = strtol (g_strndup (sql + 5, 2), NULL, 10);
-                       ret->day = strtol (g_strndup (sql + 8, 2), NULL, 10);
+                       ret->year = strtol (g_strndup (sql + 1, 4), NULL, 10);
+                       ret->month = strtol (g_strndup (sql + 6, 2), NULL, 10);
+                       ret->day = strtol (g_strndup (sql + 9, 2), NULL, 10);
 
-                       if (strlen (sql) >= 12)
+                       if (strlen (sql + 1) >= 12)
                                {
-                                       ret->hour = strtol (g_strndup (sql + 11, 2), NULL, 10);
-                                       ret->minute = strtol (g_strndup (sql + 14, 2), NULL, 10);
-                                       if (strlen (sql) >= 16)
+                                       ret->hour = strtol (g_strndup (sql + 12, 2), NULL, 10);
+                                       ret->minute = strtol (g_strndup (sql + 15, 2), NULL, 10);
+                                       if (strlen (sql + 1) >= 16)
                                                {
-                                                       ret->second = strtol (g_strndup (sql + 17, 2), NULL, 10);
+                                                       ret->second = strtol (g_strndup (sql + 18, 2), NULL, 10);
                                                }
                                }
                }
@@ -1835,17 +1948,25 @@ gdaex_query_editor_sql_where (GdaExQueryEditor *qe,
                                                }
 
                                        id_cond_iter = gda_sql_builder_add_cond (sqlbuilder, where_op, id_field, id_value1, id_value2);
-                                       if (not && where_type != GDAEX_QE_WHERE_TYPE_IS_NULL)
-                                               {
-                                                       id_cond_iter = gda_sql_builder_add_cond (sqlbuilder, GDA_SQL_OPERATOR_TYPE_NOT, id_cond_iter, 0, 0);
-                                               }
-                                       if (id_ret == 0)
+                                       if (id_cond_iter == 0)
                                                {
-                                                       id_ret = id_cond_iter;
+                                                       g_warning (_("Unable to create GdaSqlBuilder condition."));
+                                                       continue;
                                                }
                                        else
                                                {
-                                                       id_ret = gda_sql_builder_add_cond (sqlbuilder, link_op, id_ret, id_cond_iter, 0);
+                                                       if (not && where_type != GDAEX_QE_WHERE_TYPE_IS_NULL)
+                                                               {
+                                                                       id_cond_iter = gda_sql_builder_add_cond (sqlbuilder, GDA_SQL_OPERATOR_TYPE_NOT, id_cond_iter, 0, 0);
+                                                               }
+                                                       if (id_ret == 0)
+                                                               {
+                                                                       id_ret = id_cond_iter;
+                                                               }
+                                                       else
+                                                               {
+                                                                       id_ret = gda_sql_builder_add_cond (sqlbuilder, link_op, id_ret, id_cond_iter, 0);
+                                                               }
                                                }
                                }
                        else
@@ -3536,7 +3657,8 @@ gdaex_query_editor_on_btn_save_clicked (GtkButton *button,
                                                                        {
                                                                                val1 = g_strdup (val1);
                                                                        }
-                                                               if (val1_sql == NULL)
+                                                               if (val1_sql == NULL
+                                                                       || g_strcmp0 (val1_sql, "NULL") == 0)
                                                                        {
                                                                                val1_sql = g_strdup ("");
                                                                        }
@@ -3555,7 +3677,8 @@ gdaex_query_editor_on_btn_save_clicked (GtkButton *button,
                                                                        {
                                                                                val2 = g_strdup (val2);
                                                                        }
-                                                               if (val2_sql == NULL)
+                                                               if (val2_sql == NULL
+                                                                       || g_strcmp0 (val2_sql, "NULL") == 0)
                                                                        {
                                                                                val2_sql = g_strdup ("");
                                                                        }
diff --git a/src/queryeditorentrydate.c b/src/queryeditorentrydate.c
new file mode 100644 (file)
index 0000000..f1ec109
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2016 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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+       #include "config.h"
+#endif
+
+#include <libzakutils/libzakutils.h>
+
+#include "libgdaex.h"
+
+#include "queryeditorentrydate.h"
+
+static void gdaex_query_editor_entry_date_class_init (GdaExQueryEditorEntryDateClass *klass);
+static void gdaex_query_editor_entry_date_init (GdaExQueryEditorEntryDate *masked_entry);
+
+static void gdaex_query_editor_entry_date_gdaex_query_editor_iwidget_interface_init (GdaExQueryEditorIWidgetIface *iface);
+
+static void gdaex_query_editor_entry_date_set_property (GObject *object,
+                                           guint property_id,
+                                           const GValue *value,
+                                           GParamSpec *pspec);
+static void gdaex_query_editor_entry_date_get_property (GObject *object,
+                                           guint property_id,
+                                           GValue *value,
+                                           GParamSpec *pspec);
+
+static const gchar *gdaex_query_editor_entry_date_get_value (GdaExQueryEditorIWidget *iwidget);
+static const gchar *gdaex_query_editor_entry_date_get_value_sql (GdaExQueryEditorIWidget *iwidget);
+static void gdaex_query_editor_entry_date_set_value (GdaExQueryEditorIWidget *iwidget, const gchar *value);
+
+#define GDAEX_QUERY_EDITOR_ENTRY_DATE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDAEX_QUERY_EDITOR_TYPE_ENTRY_DATE, GdaExQueryEditorEntryDatePrivate))
+
+typedef struct _GdaExQueryEditorEntryDatePrivate GdaExQueryEditorEntryDatePrivate;
+struct _GdaExQueryEditorEntryDatePrivate
+       {
+               gchar *format;
+       };
+
+G_DEFINE_TYPE_WITH_CODE (GdaExQueryEditorEntryDate, gdaex_query_editor_entry_date, GTK_TYPE_ENTRY,
+                         G_IMPLEMENT_INTERFACE (GDAEX_QUERY_EDITOR_TYPE_IWIDGET,
+                                                gdaex_query_editor_entry_date_gdaex_query_editor_iwidget_interface_init));
+
+static void
+gdaex_query_editor_entry_date_class_init (GdaExQueryEditorEntryDateClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (GdaExQueryEditorEntryDatePrivate));
+
+       object_class->set_property = gdaex_query_editor_entry_date_set_property;
+       object_class->get_property = gdaex_query_editor_entry_date_get_property;
+}
+
+static void
+gdaex_query_editor_entry_date_init (GdaExQueryEditorEntryDate *entry)
+{
+       GdaExQueryEditorEntryDatePrivate *priv = GDAEX_QUERY_EDITOR_ENTRY_DATE_GET_PRIVATE (entry);
+
+       priv->format = NULL;
+}
+
+static void
+gdaex_query_editor_entry_date_gdaex_query_editor_iwidget_interface_init (GdaExQueryEditorIWidgetIface *iface)
+{
+       iface->get_value = gdaex_query_editor_entry_date_get_value;
+       iface->get_value_sql = gdaex_query_editor_entry_date_get_value_sql;
+       iface->set_value = gdaex_query_editor_entry_date_set_value;
+}
+
+/**
+ * gdaex_query_editor_entry_date_new:
+ *
+ * Creates a new #GdaExQueryEditorEntryDate widget.
+ *
+ * Returns: the newly created #GdaExQueryEditorEntryDate widget.
+ */
+GtkWidget*
+gdaex_query_editor_entry_date_new ()
+{
+       return GTK_WIDGET (g_object_new (gdaex_query_editor_entry_date_get_type (), NULL));
+}
+
+void
+gdaex_query_editor_entry_date_set_format (GdaExQueryEditorEntryDate *entry, const gchar *format)
+{
+       GdaExQueryEditorEntryDatePrivate *priv = GDAEX_QUERY_EDITOR_ENTRY_DATE_GET_PRIVATE (entry);
+
+       if (priv->format != NULL)
+               {
+                       g_free (priv->format);
+               }
+       priv->format = g_strdup (format);
+}
+gchar
+*gdaex_query_editor_entry_date_get_format (GdaExQueryEditorEntryDate* entry)
+{
+       GdaExQueryEditorEntryDatePrivate *priv = GDAEX_QUERY_EDITOR_ENTRY_DATE_GET_PRIVATE (entry);
+
+       return g_strdup (priv->format);
+}
+
+static void
+gdaex_query_editor_entry_date_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       GdaExQueryEditorEntryDate *entry = GDAEX_QUERY_EDITOR_ENTRY_DATE (object);
+       GdaExQueryEditorEntryDatePrivate *priv = GDAEX_QUERY_EDITOR_ENTRY_DATE_GET_PRIVATE (entry);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+gdaex_query_editor_entry_date_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       GdaExQueryEditorEntryDate *entry = GDAEX_QUERY_EDITOR_ENTRY_DATE (object);
+       GdaExQueryEditorEntryDatePrivate *priv = GDAEX_QUERY_EDITOR_ENTRY_DATE_GET_PRIVATE (entry);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static const gchar
+*gdaex_query_editor_entry_date_get_value (GdaExQueryEditorIWidget *iwidget)
+{
+       return gtk_entry_get_text (GTK_ENTRY (iwidget));
+}
+
+static const gchar
+*gdaex_query_editor_entry_date_get_value_sql (GdaExQueryEditorIWidget *iwidget)
+{
+       gchar *ret;
+       GDateTime *gdt;
+
+       GdaExQueryEditorEntryDatePrivate *priv = GDAEX_QUERY_EDITOR_ENTRY_DATE_GET_PRIVATE (GDAEX_QUERY_EDITOR_ENTRY_DATE (iwidget));
+
+       gdt = zak_utils_get_gdatetime_from_string (gtk_entry_get_text (GTK_ENTRY (iwidget)), priv->format);
+       ret = g_strdup (zak_utils_gdatetime_to_sql (gdt, NULL));
+
+       return ret;
+}
+
+static void
+gdaex_query_editor_entry_date_set_value (GdaExQueryEditorIWidget *iwidget,
+                            const gchar *value)
+{
+       gtk_entry_set_text (GTK_ENTRY (iwidget), value);
+}
diff --git a/src/queryeditorentrydate.h b/src/queryeditorentrydate.h
new file mode 100644 (file)
index 0000000..431bc0c
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2016 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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GDAEX_QUERY_EDITOR_ENTRY_DATE_H__
+#define __GDAEX_QUERY_EDITOR_ENTRY_DATE_H__
+
+#include <gtk/gtk.h>
+
+
+G_BEGIN_DECLS
+
+
+#define GDAEX_QUERY_EDITOR_TYPE_ENTRY_DATE                 (gdaex_query_editor_entry_date_get_type ())
+#define GDAEX_QUERY_EDITOR_ENTRY_DATE(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDAEX_QUERY_EDITOR_TYPE_ENTRY_DATE, GdaExQueryEditorEntryDate))
+#define GDAEX_QUERY_EDITOR_ENTRY_DATE_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GDAEX_QUERY_EDITOR_TYPE_ENTRY_DATE, GdaExQueryEditorEntryDateClass))
+#define GDAEX_QUERY_EDITOR_IS_ENTRY_DATE(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDAEX_QUERY_EDITOR_TYPE_ENTRY_DATE))
+#define GDAEX_QUERY_EDITOR_IS_ENTRY_DATE_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GDAEX_QUERY_EDITOR_TYPE__ENTRY_DATE))
+#define GDAEX_QUERY_EDITOR_ENTRY_DATE_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GDAEX_QUERY_EDITOR_TYPE_ENTRY_DATE, GdaExQueryEditorEntryDateClass))
+
+
+typedef struct _GdaExQueryEditorEntryDate        GdaExQueryEditorEntryDate;
+typedef struct _GdaExQueryEditorEntryDateClass   GdaExQueryEditorEntryDateClass;
+
+
+struct _GdaExQueryEditorEntryDate
+{
+       GtkEntry entry;
+};
+
+struct _GdaExQueryEditorEntryDateClass
+{
+       GtkEntryClass parent_class;
+};
+
+
+GType gdaex_query_editor_entry_date_get_type (void) G_GNUC_CONST;
+
+GtkWidget *gdaex_query_editor_entry_date_new (void);
+
+void gdaex_query_editor_entry_date_set_format (GdaExQueryEditorEntryDate *entry, const gchar *format);
+gchar *gdaex_query_editor_entry_date_get_format (GdaExQueryEditorEntryDate* entry);
+
+
+G_END_DECLS
+
+
+#endif /* __GDAEX_QUERY_EDITOR_ENTRY_DATE_H__ */
index 68a29480a2fe3772811802029ed416b0ec758c84..963515e47a5a12da49c30670ce5be367bb410b1a 100644 (file)
                        </fields_joined>
                </relation>
        </relations>
-</gdaex_query_editor>
\ No newline at end of file
+</gdaex_query_editor>