From aa16dd03495c96afb231b1ddb316075a356173b7 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 23 Oct 2011 16:23:36 +0200 Subject: [PATCH] Started implementation of GdaExQueryEditorIWidget. --- src/Makefile.am | 8 ++- src/libgdaex.h | 1 + src/queryeditor.c | 65 +++++++++++++-------- src/queryeditor.h | 6 +- src/queryeditor_widget_interface.c | 90 ++++++++++++++++++++++++++++++ src/queryeditor_widget_interface.h | 56 +++++++++++++++++++ 6 files changed, 199 insertions(+), 27 deletions(-) create mode 100644 src/queryeditor_widget_interface.c create mode 100644 src/queryeditor_widget_interface.h diff --git a/src/Makefile.am b/src/Makefile.am index bc65d20..8f2d818 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,9 +11,10 @@ LIBS = $(GDAEX_LIBS) lib_LTLIBRARIES = libgdaex.la libgdaex_la_SOURCES = gdaex.c \ - queryeditor.c \ grid.c \ - gridcolumn.c + gridcolumn.c \ + queryeditor.c \ + queryeditor_widget_interface.c libgdaex_la_LDFLAGS = -no-undefined @@ -21,6 +22,7 @@ libgdaex_include_HEADERS = libgdaex.h \ gdaex.h \ grid.h \ gridcolumn.h \ - queryeditor.h + queryeditor.h \ + queryeditor_widget_interface.h libgdaex_includedir = $(includedir)/libgdaex diff --git a/src/libgdaex.h b/src/libgdaex.h index 5e3d8ca..fbbdb31 100644 --- a/src/libgdaex.h +++ b/src/libgdaex.h @@ -28,6 +28,7 @@ #include "grid.h" #include "gridcolumn.h" #include "queryeditor.h" +#include "queryeditor_widget_interface.h" #endif /* __LIBGDAEX_H__ */ diff --git a/src/queryeditor.c b/src/queryeditor.c index ff798e4..7c68ebc 100644 --- a/src/queryeditor.c +++ b/src/queryeditor.c @@ -2229,10 +2229,9 @@ gdaex_query_editor_remove_child_from_vbx_values (GdaExQueryEditor *qe) { GdaExQueryEditorPrivate *priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe); - GList *lw = gtk_container_get_children (GTK_CONTAINER (priv->vbx_values)); - if (lw != NULL && lw->data != NULL) + if (GTK_IS_HBOX (priv->hbox)) { - gtk_container_remove (GTK_CONTAINER (priv->vbx_values), (GtkWidget *)lw->data); + gtk_container_remove (GTK_CONTAINER (priv->vbx_values), (GtkWidget *)priv->hbox); } } @@ -2468,6 +2467,10 @@ gdaex_query_editor_on_cb_where_type_changed (GtkComboBox *widget, { gtk_date_entry_set_date_gdatetime (GTK_DATE_ENTRY (priv->txt1), NULL); } + else if (GDAEX_QUERY_EDITOR_IS_IWIDGET (priv->txt1)) + { + gdaex_query_editor_iwidget_set_value (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt1), ""); + } else { gtk_entry_set_text (GTK_ENTRY (priv->txt1), ""); @@ -2483,6 +2486,10 @@ gdaex_query_editor_on_cb_where_type_changed (GtkComboBox *widget, { gtk_date_entry_set_date_gdatetime (GTK_DATE_ENTRY (priv->txt2), NULL); } + else if (GDAEX_QUERY_EDITOR_IS_IWIDGET (priv->txt2)) + { + gdaex_query_editor_iwidget_set_value (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt2), ""); + } else { gtk_entry_set_text (GTK_ENTRY (priv->txt2), ""); @@ -2637,6 +2644,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 (GDAEX_QUERY_EDITOR_IS_IWIDGET (priv->txt1)) + { + val1 = (gchar *)gdaex_query_editor_iwidget_get_value (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt1)); + val1_sql = (gchar *)gdaex_query_editor_iwidget_get_value_sql (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt1)); + } else { val1 = (gchar *)gtk_entry_get_text (GTK_ENTRY (priv->txt1)); @@ -2664,6 +2676,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 (GDAEX_QUERY_EDITOR_IS_IWIDGET (priv->txt2)) + { + val2 = (gchar *)gdaex_query_editor_iwidget_get_value (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt2)); + val2_sql = (gchar *)gdaex_query_editor_iwidget_get_value_sql (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt2)); + } else { val2 = (gchar *)gtk_entry_get_text (GTK_ENTRY (priv->txt2)); @@ -3032,8 +3049,6 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection, GdaExQueryEditorField *field; GtkWidget *lbl; - GtkWidget *widget_val1; - GtkWidget *widget_val2; GtkTreeIter iter_cb; GtkCellRenderer *renderer; @@ -3308,66 +3323,70 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection, case GDAEX_QE_FIELD_TYPE_TEXT: priv->txt1 = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (priv->txt1), from == NULL ? "" : from); - widget_val1 = priv->txt1; priv->txt2 = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (priv->txt2), to == NULL ? "" : to); - widget_val2 = priv->txt2; 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 (GDAEX_QUERY_EDITOR_IS_IWIDGET (field->iwidget_from)) + { + priv->txt1 = GTK_WIDGET (field->iwidget_from); + gdaex_query_editor_iwidget_set_value (field->iwidget_from, from_sql == NULL ? "0" : from_sql); + } + else + { + 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; + if (GDAEX_QUERY_EDITOR_IS_IWIDGET (field->iwidget_to)) + { + priv->txt2 = GTK_WIDGET (field->iwidget_to); + gdaex_query_editor_iwidget_set_value (field->iwidget_to, to_sql == NULL ? "0" : to_sql); + } + else + { + priv->txt2 = gtk_entry_new (); + gtk_entry_set_text (GTK_ENTRY (priv->txt2), to == NULL ? "" : to); + } break; case GDAEX_QE_FIELD_TYPE_DOUBLE: priv->txt1 = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (priv->txt1), from == NULL ? "" : from); - widget_val1 = priv->txt1; priv->txt2 = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (priv->txt2), to == NULL ? "" : to); - widget_val2 = priv->txt2; break; case GDAEX_QE_FIELD_TYPE_DATE: priv->txt1 = gtk_date_entry_new (NULL, NULL, TRUE); gtk_date_entry_set_time_visible (GTK_DATE_ENTRY (priv->txt1), FALSE); gtk_date_entry_set_date_strf (GTK_DATE_ENTRY (priv->txt1), from_sql == NULL ? g_date_time_format (g_date_time_new_now_local (), "%Y-%m-%d") : from_sql, "Ymd"); - widget_val1 = priv->txt1; priv->txt2 = gtk_date_entry_new (NULL, NULL, TRUE); gtk_date_entry_set_time_visible (GTK_DATE_ENTRY (priv->txt2), FALSE); gtk_date_entry_set_date_strf (GTK_DATE_ENTRY (priv->txt2), to_sql == NULL ? g_date_time_format (g_date_time_new_now_local (), "%Y-%m-%d") : to_sql, "Ymd"); - widget_val2 = priv->txt2; break; case GDAEX_QE_FIELD_TYPE_DATETIME: priv->txt1 = gtk_date_entry_new (NULL, NULL, TRUE); gtk_date_entry_set_time_separator (GTK_DATE_ENTRY (priv->txt1), "."); gtk_date_entry_set_date_strf (GTK_DATE_ENTRY (priv->txt1), from_sql == NULL ? g_date_time_format (g_date_time_new_now_local (), "%Y-%m-%d %H.%M.%S") : from_sql, "YmdHMS"); - widget_val1 = priv->txt1; priv->txt2 = gtk_date_entry_new (NULL, NULL, TRUE); gtk_date_entry_set_time_separator (GTK_DATE_ENTRY (priv->txt2), "."); gtk_date_entry_set_date_strf (GTK_DATE_ENTRY (priv->txt2), to_sql == NULL ? g_date_time_format (g_date_time_new_now_local (), "%Y-%m-%d %H.%M.%S") : to_sql, "YmdHMS"); - widget_val2 = priv->txt2; break; case GDAEX_QE_FIELD_TYPE_TIME: priv->txt1 = gtk_entry_new (); gtk_entry_set_max_length (GTK_ENTRY (priv->txt1), 8); gtk_entry_set_text (GTK_ENTRY (priv->txt1), from == NULL ? "" : from); - widget_val1 = priv->txt1; priv->txt2 = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (priv->txt2), to == NULL ? "" : to); - widget_val2 = priv->txt2; break; default: @@ -3375,8 +3394,8 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection, break; }; - gtk_table_attach (GTK_TABLE (priv->tbl), widget_val1, 4, 5, 1, 2, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0, 0); - gtk_table_attach (GTK_TABLE (priv->tbl), widget_val2, 4, 5, 2, 3, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0, 0); + gtk_table_attach (GTK_TABLE (priv->tbl), priv->txt1, 4, 5, 1, 2, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0, 0); + gtk_table_attach (GTK_TABLE (priv->tbl), priv->txt2, 4, 5, 2, 3, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0, 0); gtk_box_pack_start (GTK_BOX (priv->vbx_values), priv->hbox, FALSE, FALSE, 0); diff --git a/src/queryeditor.h b/src/queryeditor.h index a86f9c1..bdf9ed5 100644 --- a/src/queryeditor.h +++ b/src/queryeditor.h @@ -24,7 +24,8 @@ #include -#include +#include "libgdaex.h" +#include "queryeditor_widget_interface.h" G_BEGIN_DECLS @@ -119,6 +120,9 @@ typedef struct guint available_where_type; gboolean for_order; + GdaExQueryEditorIWidget *iwidget_from; + GdaExQueryEditorIWidget *iwidget_to; + /* TODO * to refactor */ diff --git a/src/queryeditor_widget_interface.c b/src/queryeditor_widget_interface.c new file mode 100644 index 0000000..69bd95d --- /dev/null +++ b/src/queryeditor_widget_interface.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2011 Andrea Zagli + * + * 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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include "queryeditor_widget_interface.h" + +typedef GdaExQueryEditorIWidgetIface GdaExQueryEditorIWidgetInterface; + +G_DEFINE_INTERFACE (GdaExQueryEditorIWidget, gdaex_query_editor_iwidget, G_TYPE_OBJECT) + +static void +gdaex_query_editor_iwidget_default_init (GdaExQueryEditorIWidgetInterface *iface) +{ +} + +const gchar +*gdaex_query_editor_iwidget_get_value (GdaExQueryEditorIWidget *iwidget) +{ + GdaExQueryEditorIWidgetIface *iface; + + gchar *ret; + + ret = NULL; + + g_return_val_if_fail (GDAEX_QUERY_EDITOR_IS_IWIDGET (iwidget), ret); + + iface = GDAEX_QUERY_EDITOR_IWIDGET_GET_IFACE (iwidget); + + if (iface->get_value) + { + ret = (gchar *)(* iface->get_value) (iwidget); + } + + return ret; +} + +const gchar +*gdaex_query_editor_iwidget_get_value_sql (GdaExQueryEditorIWidget *iwidget) +{ + GdaExQueryEditorIWidgetIface *iface; + + gchar *ret; + + ret = NULL; + + g_return_val_if_fail (GDAEX_QUERY_EDITOR_IS_IWIDGET (iwidget), ret); + + iface = GDAEX_QUERY_EDITOR_IWIDGET_GET_IFACE (iwidget); + + if (iface->get_value_sql) + { + ret = (gchar *)(* iface->get_value_sql) (iwidget); + } + + return ret; +} + +void +gdaex_query_editor_iwidget_set_value (GdaExQueryEditorIWidget *iwidget, + const gchar *value) +{ + GdaExQueryEditorIWidgetIface *iface; + + g_return_if_fail (GDAEX_QUERY_EDITOR_IS_IWIDGET (iwidget)); + + iface = GDAEX_QUERY_EDITOR_IWIDGET_GET_IFACE (iwidget); + + if (iface->set_value) + { + (* iface->set_value) (iwidget, value); + } +} diff --git a/src/queryeditor_widget_interface.h b/src/queryeditor_widget_interface.h new file mode 100644 index 0000000..4677692 --- /dev/null +++ b/src/queryeditor_widget_interface.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011 Andrea Zagli + * + * 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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __GDAEX_QUERY_EDITOR_IWIDGET_H__ +#define __GDAEX_QUERY_EDITOR_IWIDGET_H__ + +#include + + +G_BEGIN_DECLS + + +#define GDAEX_QUERY_EDITOR_TYPE_IWIDGET (gdaex_query_editor_iwidget_get_type ()) +#define GDAEX_QUERY_EDITOR_IWIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDAEX_QUERY_EDITOR_TYPE_IWIDGET, GdaExQueryEditorIWidget)) +#define GDAEX_QUERY_EDITOR_IS_IWIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDAEX_QUERY_EDITOR_TYPE_IWIDGET)) +#define GDAEX_QUERY_EDITOR_IWIDGET_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GDAEX_QUERY_EDITOR_TYPE_IWIDGET, GdaExQueryEditorIWidgetIface)) + + +typedef struct _GdaExQueryEditorIWidget GdaExQueryEditorIWidget; +typedef struct _GdaExQueryEditorIWidgetIface GdaExQueryEditorIWidgetIface; + +struct _GdaExQueryEditorIWidgetIface + { + GTypeInterface g_iface; + + const gchar *(*get_value) (GdaExQueryEditorIWidget *irole); + const gchar *(*get_value_sql) (GdaExQueryEditorIWidget *irole); + void (*set_value) (GdaExQueryEditorIWidget *irole, const gchar *value); + }; + +GType gdaex_query_editor_irole_get_type (void) G_GNUC_CONST; + +const gchar *gdaex_query_editor_iwidget_get_value (GdaExQueryEditorIWidget *iwidget); +const gchar *gdaex_query_editor_iwidget_get_value_sql (GdaExQueryEditorIWidget *iwidget); +void gdaex_query_editor_iwidget_set_value (GdaExQueryEditorIWidget *iwidget, const gchar *value); + + +G_END_DECLS + + +#endif /* __GDAEX_QUERY_EDITOR_IWIDGET_H__ */ -- 2.49.0