]> saetta.ns0.it Git - libgdaex/commitdiff
Started integration with GtkFormDecoder. decoder
authorAndrea Zagli <azagli@libero.it>
Sun, 31 Jul 2011 10:05:15 +0000 (12:05 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 31 Jul 2011 10:05:15 +0000 (12:05 +0200)
configure.ac
src/queryeditor.c
tests/query_editor.c
tests/query_editor.db [new file with mode: 0644]

index 0d535058f834c2fbf27536101da8526fb682c6df..2e53c7a987e5aaec5f7fc484630b0be029c050c5 100644 (file)
@@ -33,7 +33,8 @@ GTK_DOC_CHECK(1.0)
 PKG_CHECK_MODULES(GDAEX, [libgda-4.0 >= 4
                           gio-2.0 >= 2.24
                           gtk+-2.0 >= 2.20
-                          libgtkdateentry >= 0.0.4])
+                          libgtkdateentry >= 0.0.4
+                          libgtkformui >= 0.3.0])
 
 AC_SUBST(GDAEX_CFLAGS)
 AC_SUBST(GDAEX_LIBS)
index 3a8021a5a57ef034eb9c4a874910559befdc2b66..c690d9daf65c5938af98311b35b7bce9c2b2c393 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <gtkdateentry.h>
+#include <libgtkformui/gtkformdecoder.h>
 
 #include "queryeditor.h"
 
@@ -146,6 +147,10 @@ static void gdaex_query_editor_on_btn_order_clean_clicked (GtkButton *button,
 static void gdaex_query_editor_on_sel_order_changed (GtkTreeSelection *treeselection,
                                                     gpointer user_data);
 
+static void gdaex_query_editor_on_txt1_btn_browse_clicked (gpointer instance, gpointer user_data);
+static void gdaex_query_editor_on_txt2_btn_browse_clicked (gpointer instance, gpointer user_data);
+
+
 #define GDAEX_QUERY_EDITOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GDAEX_QUERY_EDITOR, GdaExQueryEditorPrivate))
 
 typedef struct _GdaExQueryEditorPrivate GdaExQueryEditorPrivate;
@@ -2002,6 +2007,13 @@ gdaex_query_editor_on_cb_where_type_changed (GtkComboBox *widget,
                                                {
                                                        gtk_date_entry_set_date_gdatetime (GTK_DATE_ENTRY (priv->txt1), NULL);
                                                }
+                                       else if (GTK_IS_FORM_DECODER (priv->txt1))
+                                               {
+                                                       /* TODO
+                                                        * change the passed value to reflect field type
+                                                        */
+                                                       gtk_form_decoder_set_key (GTK_FORM_DECODER (priv->txt1), "0");
+                                               }
                                        else
                                                {
                                                        gtk_entry_set_text (GTK_ENTRY (priv->txt1), "");
@@ -2017,6 +2029,13 @@ gdaex_query_editor_on_cb_where_type_changed (GtkComboBox *widget,
                                                {
                                                        gtk_date_entry_set_date_gdatetime (GTK_DATE_ENTRY (priv->txt2), NULL);
                                                }
+                                       else if (GTK_IS_FORM_DECODER (priv->txt2))
+                                               {
+                                                       /* TODO
+                                                        * change the passed value to reflect field type
+                                                        */
+                                                       gtk_form_decoder_set_key (GTK_FORM_DECODER (priv->txt2), "0");
+                                               }
                                        else
                                                {
                                                        gtk_entry_set_text (GTK_ENTRY (priv->txt2), "");
@@ -2025,10 +2044,30 @@ gdaex_query_editor_on_cb_where_type_changed (GtkComboBox *widget,
                                }
                        else
                                {
-                                       gtk_date_entry_set_date_gdatetime (GTK_DATE_ENTRY (priv->txt1),
-                                                                          g_date_time_new_now_local ());
-                                       gtk_date_entry_set_date_gdatetime (GTK_DATE_ENTRY (priv->txt2),
-                                                                          g_date_time_new_now_local ());
+                                       if (GTK_IS_DATE_ENTRY (priv->txt1))
+                                               {
+                                                       gtk_date_entry_set_date_gdatetime (GTK_DATE_ENTRY (priv->txt1),
+                                                                                          g_date_time_new_now_local ());
+                                                       gtk_date_entry_set_date_gdatetime (GTK_DATE_ENTRY (priv->txt2),
+                                                                                          g_date_time_new_now_local ());
+                                               }
+                                       else if (GTK_IS_FORM_DECODER (priv->txt1))
+                                               {
+                                                       /* TODO
+                                                        * change the passed value to reflect field type
+                                                        */
+                                                       gtk_form_decoder_set_key (GTK_FORM_DECODER (priv->txt1), "0");
+                                                       /* TODO
+                                                        * change the passed value to reflect field type
+                                                        */
+                                                       gtk_form_decoder_set_key (GTK_FORM_DECODER (priv->txt2), "0");
+                                               }
+                                       else
+                                               {
+                                                       gtk_entry_set_text (GTK_ENTRY (priv->txt1), "");
+                                                       gtk_entry_set_text (GTK_ENTRY (priv->txt2), "");
+                                               }
+
                                        gtk_table_set_row_spacing (GTK_TABLE (priv->tbl), 1, 5);
                                }
                }
@@ -2171,6 +2210,11 @@ gdaex_query_editor_on_btn_save_clicked (GtkButton *button,
                                                                val1 = (gchar *)gtk_date_entry_get_strf (GTK_DATE_ENTRY (priv->txt1), gtk_date_entry_is_time_visible (GTK_DATE_ENTRY (priv->txt1)) ? "dmYHMS" : "dmY", NULL, NULL);
                                                                val1_sql = (gchar *)gtk_date_entry_get_sql (GTK_DATE_ENTRY (priv->txt1));
                                                        }
+                                               else if (GTK_IS_FORM_DECODER (priv->txt1))
+                                                       {
+                                                               val1 = (gchar *)gtk_form_decoder_get_decoded (GTK_FORM_DECODER (priv->txt1));
+                                                               val1_sql = (gchar *)gtk_form_decoder_get_key (GTK_FORM_DECODER (priv->txt1));
+                                                       }
                                                else
                                                        {
                                                                val1 = (gchar *)gtk_entry_get_text (GTK_ENTRY (priv->txt1));
@@ -2198,6 +2242,11 @@ gdaex_query_editor_on_btn_save_clicked (GtkButton *button,
                                                                val2 = (gchar *)gtk_date_entry_get_strf (GTK_DATE_ENTRY (priv->txt2), gtk_date_entry_is_time_visible (GTK_DATE_ENTRY (priv->txt2)) ? "dmYHMS" : "dmY", NULL, NULL);
                                                                val2_sql = (gchar *)gtk_date_entry_get_sql (GTK_DATE_ENTRY (priv->txt2));
                                                        }
+                                               else if (GTK_IS_FORM_DECODER (priv->txt2))
+                                                       {
+                                                               val2 = (gchar *)gtk_form_decoder_get_decoded (GTK_FORM_DECODER (priv->txt2));
+                                                               val2_sql = (gchar *)gtk_form_decoder_get_key (GTK_FORM_DECODER (priv->txt2));
+                                                       }
                                                else
                                                        {
                                                                val2 = (gchar *)gtk_entry_get_text (GTK_ENTRY (priv->txt2));
@@ -2850,13 +2899,51 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection,
                                                break;
 
                                        case GDAEX_QE_FIELD_TYPE_INTEGER:
-                                               priv->txt1 = gtk_entry_new ();
-                                               gtk_entry_set_text (GTK_ENTRY (priv->txt1), from == NULL ? "" : from);
-                                               widget_val1 = priv->txt1;
+                                               if (field->decode_table2 != NULL)
+                                                       {
+                                                               /* TODO
+                                                                * change the passed value to reflect field type
+                                                                */
+                                                               priv->txt1 = gtk_form_decoder_new ();
+                                                               g_object_set (G_OBJECT (priv->txt1),
+                                                                             "gdaex", priv->gdaex,
+                                                                             "sql", g_strdup_printf ("SELECT %s"
+                                                                                                     " FROM %s"
+                                                                                                     " WHERE %s = ##key0::gint",
+                                                                                                     field->decode_field_to_show,
+                                                                                                     field->decode_table2,
+                                                                                                     field->decode_field2),
+                                                                             NULL);
+                                                               g_signal_connect (G_OBJECT (priv->txt1), "btn_browse_clicked",
+                                                                                 G_CALLBACK (gdaex_query_editor_on_txt1_btn_browse_clicked), NULL);
+
+                                                               /* TODO
+                                                                * change the passed value to reflect field type
+                                                                */
+                                                               priv->txt2 = gtk_form_decoder_new ();
+                                                               g_object_set (G_OBJECT (priv->txt2),
+                                                                             "gdaex", priv->gdaex,
+                                                                             "sql", g_strdup_printf ("SELECT %s"
+                                                                                                     " FROM %s"
+                                                                                                     " WHERE %s = ##key0::gint",
+                                                                                                     field->decode_field_to_show,
+                                                                                                     field->decode_table2,
+                                                                                                     field->decode_field2),
+                                                                             NULL);
+                                                               g_signal_connect (G_OBJECT (priv->txt2), "btn_browse_clicked",
+                                                                                 G_CALLBACK (gdaex_query_editor_on_txt2_btn_browse_clicked), NULL);
+                                                       }
+                                               else
+                                                       {
+                                                               priv->txt1 = gtk_entry_new ();
+                                                               gtk_entry_set_text (GTK_ENTRY (priv->txt1), from == NULL ? "" : from);
+
+                                                               priv->txt2 = gtk_entry_new ();
+                                                               gtk_entry_set_text (GTK_ENTRY (priv->txt2), to == NULL ? "" : to);
+                                                       }
 
-                                               priv->txt2 = gtk_entry_new ();
-                                               gtk_entry_set_text (GTK_ENTRY (priv->txt2), to == NULL ? "" : to);
                                                widget_val2 = priv->txt2;
+                                               widget_val1 = priv->txt1;
                                                break;
 
                                        case GDAEX_QE_FIELD_TYPE_DOUBLE:
@@ -3100,3 +3187,15 @@ gdaex_query_editor_on_sel_order_changed (GtkTreeSelection *treeselection,
                        g_free (order);
                }
 }
+
+static void
+gdaex_query_editor_on_txt1_btn_browse_clicked (gpointer instance, gpointer user_data)
+{
+       g_debug ("Txt1 Open clicked.");
+}
+
+static void
+gdaex_query_editor_on_txt2_btn_browse_clicked (gpointer instance, gpointer user_data)
+{
+       g_debug ("Txt2 Open clicked.");
+}
index 2e557b544f961dd5d19a49590592feced166d3ad..c65f6fc0cc822f3144327e8ea48f2350bf22fb27 100644 (file)
@@ -148,7 +148,7 @@ main (int argc, char *argv[])
 
        gtk_init (&argc, &argv);
 
-       gdaex = gdaex_new_from_string (g_strdup_printf ("SQLite://DB_DIR=%s;DB_NAME=test_prefix.db", TESTSDIR));
+       gdaex = gdaex_new_from_string (g_strdup_printf ("SQLite://DB_DIR=%s;DB_NAME=query_editor.db", TESTSDIR));
        if (gdaex == NULL)
                {
                        g_error ("Error on GdaEx initialization.");
@@ -256,7 +256,8 @@ main (int argc, char *argv[])
        field->decode_field2 = g_strdup ("id");
        field->decode_field_to_show = g_strdup ("name");
        field->decode_field_alias = g_strdup ("city_name");
-       field->available_where_type = GDAEX_QE_WHERE_TYPE_EQUAL;
+       field->available_where_type = GDAEX_QE_WHERE_TYPE_EQUAL
+                                     | GDAEX_QE_WHERE_TYPE_BETWEEN;
        gdaex_query_editor_table_add_field (qe, "clients", *field);
        g_free (field);
 
diff --git a/tests/query_editor.db b/tests/query_editor.db
new file mode 100644 (file)
index 0000000..cd92e10
Binary files /dev/null and b/tests/query_editor.db differ