From: Andrea Zagli Date: Wed, 23 Nov 2011 17:44:40 +0000 (+0100) Subject: In GdaExQueryEditor now every field's type is a GdaExQueryEditorIWidget. X-Git-Tag: 0.5.0~20 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=640de197cb3ae2f1e1e77eb3eb6e52627b90cdf2;p=libgdaex In GdaExQueryEditor now every field's type is a GdaExQueryEditorIWidget. Removed GtkDateEntry dependency. --- diff --git a/.anjuta_sym_db.db b/.anjuta_sym_db.db index 9be886b..722ad46 100644 Binary files a/.anjuta_sym_db.db and b/.anjuta_sym_db.db differ diff --git a/configure.ac b/configure.ac index ea19e72..1dde28a 100644 --- a/configure.ac +++ b/configure.ac @@ -42,8 +42,7 @@ AM_GLIB_GNU_GETTEXT # Checks for libraries. PKG_CHECK_MODULES(GDAEX, [libgda-4.0 >= 4 gio-2.0 >= 2.24 - gtk+-2.0 >= 2.20 - libgtkdateentry >= 0.0.4]) + gtk+-2.0 >= 2.20]) AC_SUBST(GDAEX_CFLAGS) AC_SUBST(GDAEX_LIBS) diff --git a/po/it.po b/po/it.po index 9327600..255b8fe 100644 --- a/po/it.po +++ b/po/it.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: libgdaex 0.4.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-10-24 17:40+0200\n" +"POT-Creation-Date: 2011-11-23 18:27+0100\n" "PO-Revision-Date: 2011-10-24 17:44+0200\n" "Last-Translator: Andrea Zagli \n" "Language-Team: Italian \n" @@ -39,8 +39,8 @@ msgstr "Errore nella creazione della connessione al database: %s" #: ../src/gdaex.c:2295 ../src/gdaex.c:2405 ../src/gdaex.c:2452 #: ../src/gdaex.c:2470 ../src/gdaex.c:2523 ../src/gdaex.c:2582 #: ../src/gdaex.c:2635 ../src/gdaex.c:2923 ../src/gdaex.c:2941 -#: ../src/queryeditor.c:323 ../src/queryeditor.c:1224 -#: ../src/queryeditor.c:1236 +#: ../src/queryeditor.c:350 ../src/queryeditor.c:1260 +#: ../src/queryeditor.c:1272 msgid "no details" msgstr "nessun dettaglio" @@ -226,159 +226,167 @@ msgstr "Errore nella creazione dell'espressione regolare: %s" msgid "Error on regex replacing: %s" msgstr "Errore nell'espressione regolare di sostituzione: %s" -#: ../src/queryeditor.c:322 +#: ../src/queryeditor.c:349 #, c-format msgid "Error on gui initialization: %s." msgstr "Errore nell'inizializzazione dell'interfaccia grafica: %s." -#: ../src/queryeditor.c:554 ../src/queryeditor.c:637 ../src/queryeditor.c:645 +#: ../src/queryeditor.c:581 ../src/queryeditor.c:673 ../src/queryeditor.c:681 #, c-format msgid "Table «%s» doesn't exists." msgstr "La tabella «%s» non esiste." -#: ../src/queryeditor.c:563 ../src/queryeditor.c:571 +#: ../src/queryeditor.c:590 ../src/queryeditor.c:598 msgid "No field added: the field must have a name." msgstr "Nessun campo aggiunto: il campo deve avere un nome." -#: ../src/queryeditor.c:681 +#: ../src/queryeditor.c:717 msgid "Relation not created: no field added to the relation." msgstr "Relazione non creata: nesuun campo aggiunto alla relazione." -#: ../src/queryeditor.c:1146 ../src/queryeditor.c:1539 +#: ../src/queryeditor.c:1182 ../src/queryeditor.c:1575 #, c-format msgid "Where type «%d» not valid." msgstr "Tipo where «%d» non valido." -#: ../src/queryeditor.c:1223 +#: ../src/queryeditor.c:1259 #, c-format msgid "Unable to create GdaStatement: %s." msgstr "Impossibile creare l'oggetto GdaStatement: %s." -#: ../src/queryeditor.c:1235 +#: ../src/queryeditor.c:1271 #, c-format msgid "Unable to create sql: %s." msgstr "Impossibile creare l'sql: %s." -#: ../src/queryeditor.c:1474 +#: ../src/queryeditor.c:1510 #, c-format msgid "Link type «%d» not valid." msgstr "Tipo collegamento «%d» non valido." -#: ../src/queryeditor.c:1634 +#: ../src/queryeditor.c:1670 #, c-format msgid "Table «%s» not found." msgstr "Tabella «%s» non trovata." -#: ../src/queryeditor.c:1642 +#: ../src/queryeditor.c:1678 #, c-format msgid "Field «%s» not found in table «%s»." msgstr "Campo «%s» non trovato nella tabella «%s»." -#: ../src/queryeditor.c:2081 +#: ../src/queryeditor.c:1865 ../src/queryeditor.c:2725 +msgid "ASC" +msgstr "ASC" + +#: ../src/queryeditor.c:1866 ../src/queryeditor.c:2729 +msgid "DESC" +msgstr "DISC" + +#: ../src/queryeditor.c:2117 msgid "Are you sure you want to remove the selected field?" msgstr "Eliminare il campo selezionato?" -#: ../src/queryeditor.c:2102 ../src/queryeditor.c:2198 -#: ../src/queryeditor.c:2841 ../src/queryeditor.c:3012 -#: ../src/queryeditor.c:3557 +#: ../src/queryeditor.c:2138 ../src/queryeditor.c:2234 +#: ../src/queryeditor.c:2803 ../src/queryeditor.c:2974 +#: ../src/queryeditor.c:3441 msgid "You must select a field before." msgstr "Occorre prima selezione un campo." -#: ../src/queryeditor.c:2260 +#: ../src/queryeditor.c:2296 msgid "Equal" msgstr "uguale a" -#: ../src/queryeditor.c:2264 +#: ../src/queryeditor.c:2300 msgid "Starts with" msgstr "inizia per" -#: ../src/queryeditor.c:2268 +#: ../src/queryeditor.c:2304 msgid "Contains" msgstr "contiene" -#: ../src/queryeditor.c:2272 +#: ../src/queryeditor.c:2308 msgid "Ends with" msgstr "finisce con" -#: ../src/queryeditor.c:2276 +#: ../src/queryeditor.c:2312 msgid "Case-insensitive starts with" msgstr "inizia per (no maiuscole/minuscole)" -#: ../src/queryeditor.c:2280 +#: ../src/queryeditor.c:2316 msgid "Case-insensitive contains" msgstr "contiene (no maiuscole/minuscole)" -#: ../src/queryeditor.c:2284 +#: ../src/queryeditor.c:2320 msgid "Case-insensitive ends with" msgstr "finisce con (no maiuscole/minuscole)" -#: ../src/queryeditor.c:2288 +#: ../src/queryeditor.c:2324 msgid "Greater" msgstr "maggiore di" -#: ../src/queryeditor.c:2292 +#: ../src/queryeditor.c:2328 msgid "Greater or equal" msgstr "maggiore di o uguale a" -#: ../src/queryeditor.c:2296 +#: ../src/queryeditor.c:2332 msgid "Lesser" msgstr "minore di" -#: ../src/queryeditor.c:2300 +#: ../src/queryeditor.c:2336 msgid "Lesser or equal" msgstr "minore di o uguale a" -#: ../src/queryeditor.c:2304 +#: ../src/queryeditor.c:2340 msgid "Between" msgstr "compreso tra" -#: ../src/queryeditor.c:2308 +#: ../src/queryeditor.c:2344 msgid "Is NULL" msgstr "è NULL" -#: ../src/queryeditor.c:2325 +#: ../src/queryeditor.c:2361 msgid "And" msgstr "e" -#: ../src/queryeditor.c:2329 +#: ../src/queryeditor.c:2365 msgid "Or" msgstr "o" -#: ../src/queryeditor.c:2643 +#: ../src/queryeditor.c:2631 msgid "You must select a link's type before." msgstr "Occorre selezionare prima un tipo di collegamento." -#: ../src/queryeditor.c:2665 +#: ../src/queryeditor.c:2653 msgid "You must select a condition's type before." msgstr "Occorre selezionare prima un tipo di condizione." #. if it is the first condition, "link" isn't visibile -#: ../src/queryeditor.c:3144 ../data/libgdaex/gui/libgdaex.ui.h:6 +#: ../src/queryeditor.c:3106 ../data/libgdaex/gui/libgdaex.ui.h:6 msgid "Link" msgstr "Collegamento" -#: ../src/queryeditor.c:3148 ../data/libgdaex/gui/libgdaex.ui.h:7 +#: ../src/queryeditor.c:3110 ../data/libgdaex/gui/libgdaex.ui.h:7 msgid "Not" msgstr "Non" -#: ../src/queryeditor.c:3151 ../data/libgdaex/gui/libgdaex.ui.h:2 +#: ../src/queryeditor.c:3113 ../data/libgdaex/gui/libgdaex.ui.h:2 msgid "Condition" msgstr "Condizione" -#: ../src/queryeditor.c:3154 +#: ../src/queryeditor.c:3116 msgid "Value" msgstr "Valore" -#: ../src/queryeditor.c:3399 +#: ../src/queryeditor.c:3319 #, c-format msgid "Field's type «%d» not valid." msgstr "Il tipo campo «%d» non è valido." -#: ../src/queryeditor.c:3649 +#: ../src/queryeditor.c:3533 msgid "Ascending" msgstr "ascendente" -#: ../src/queryeditor.c:3652 +#: ../src/queryeditor.c:3536 msgid "Descending" msgstr "discendente" diff --git a/src/Makefile.am b/src/Makefile.am index 8f2d818..9baa50e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,7 +14,8 @@ libgdaex_la_SOURCES = gdaex.c \ grid.c \ gridcolumn.c \ queryeditor.c \ - queryeditor_widget_interface.c + queryeditor_widget_interface.c \ + queryeditorentry.c libgdaex_la_LDFLAGS = -no-undefined @@ -23,6 +24,7 @@ libgdaex_include_HEADERS = libgdaex.h \ grid.h \ gridcolumn.h \ queryeditor.h \ - queryeditor_widget_interface.h + queryeditor_widget_interface.h \ + queryeditorentry.h libgdaex_includedir = $(includedir)/libgdaex diff --git a/src/queryeditor.c b/src/queryeditor.c index 75f5a96..af2191c 100644 --- a/src/queryeditor.c +++ b/src/queryeditor.c @@ -25,9 +25,8 @@ #include -#include - #include "queryeditor.h" +#include "queryeditorentry.h" typedef struct { @@ -160,6 +159,9 @@ static void gdaex_query_editor_on_sel_order_changed (GtkTreeSelection *treeselec #define GDAEX_QUERY_EDITOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GDAEX_QUERY_EDITOR, GdaExQueryEditorPrivate)) +typedef GtkWidget *(* GtkDateEntryNew) (void); +typedef void (* GtkDateEntrySetTimeVisible) (gpointer gtkdateentry, gboolean visible); + typedef struct _GdaExQueryEditorPrivate GdaExQueryEditorPrivate; struct _GdaExQueryEditorPrivate { @@ -200,10 +202,12 @@ struct _GdaExQueryEditorPrivate GtkWidget *cb_link_type; GtkWidget *not; GtkWidget *cb_where_type; - GtkWidget *lbl_txt1; - GtkWidget *txt1; - GtkWidget *lbl_txt2; - GtkWidget *txt2; + GtkWidget *lbl_txt_alias; + GtkWidget *txt_alias; + GtkWidget *lbl_from; + GtkWidget *txt_from; + GtkWidget *lbl_to; + GtkWidget *txt_to; GtkWidget *opt_asc; GtkWidget *opt_desc; @@ -585,6 +589,39 @@ gdaex_query_editor_table_add_field (GdaExQueryEditor *qe, } } + if (!GDAEX_QUERY_EDITOR_IS_IWIDGET (_field->iwidget_from)) + { + _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)) + { + _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); + } + } + g_hash_table_insert (table->fields, _field->name, _field); ret = TRUE; @@ -1825,8 +1862,8 @@ gdaex_query_editor_load_choices_from_xml (GdaExQueryEditor *qe, xmlNode *root, gchar *asc_desc; asc_desc = xmlGetProp (node_field, "asc_desc"); - if (g_strcmp0 (asc_desc, "ASC") == 0 - || g_strcmp0 (asc_desc, "DESC") == 0) + if (g_strcmp0 (asc_desc, _("ASC")) == 0 + || g_strcmp0 (asc_desc, _("DESC")) == 0) { gtk_list_store_append (priv->lstore_order, &iter); gtk_list_store_set (priv->lstore_order, &iter, @@ -2466,74 +2503,26 @@ gdaex_query_editor_on_cb_where_type_changed (GtkComboBox *widget, 0, &where_type, -1); - gtk_widget_set_visible (priv->lbl_txt1, where_type != GDAEX_QE_WHERE_TYPE_IS_NULL); - gtk_widget_set_visible (priv->txt1, where_type != GDAEX_QE_WHERE_TYPE_IS_NULL); + gtk_widget_set_visible (priv->lbl_from, where_type != GDAEX_QE_WHERE_TYPE_IS_NULL); + gtk_widget_set_visible (priv->txt_from, where_type != GDAEX_QE_WHERE_TYPE_IS_NULL); if (where_type == GDAEX_QE_WHERE_TYPE_IS_NULL) { - if (GTK_IS_DATE_ENTRY (priv->txt1)) - { - 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), ""); - } + gdaex_query_editor_iwidget_set_value (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt_from), ""); } - gtk_widget_set_visible (priv->lbl_txt2, where_type == GDAEX_QE_WHERE_TYPE_BETWEEN); - gtk_widget_set_visible (priv->txt2, where_type == GDAEX_QE_WHERE_TYPE_BETWEEN); + gtk_widget_set_visible (priv->lbl_to, where_type == GDAEX_QE_WHERE_TYPE_BETWEEN); + gtk_widget_set_visible (priv->txt_to, where_type == GDAEX_QE_WHERE_TYPE_BETWEEN); if (where_type != GDAEX_QE_WHERE_TYPE_BETWEEN) { - if (GTK_IS_DATE_ENTRY (priv->txt2)) - { - 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), ""); - } + gdaex_query_editor_iwidget_set_value (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt_to), ""); gtk_table_set_row_spacing (GTK_TABLE (priv->tbl), 1, 0); } else { - if (GTK_IS_DATE_ENTRY (priv->txt1)) - { - gtk_date_entry_set_date_gdatetime (GTK_DATE_ENTRY (priv->txt1), - g_date_time_new_now_local ()); - } - 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), ""); - } - - if (GTK_IS_DATE_ENTRY (priv->txt2)) - { - gtk_date_entry_set_date_gdatetime (GTK_DATE_ENTRY (priv->txt2), - g_date_time_new_now_local ()); - } - 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), ""); - } - + gdaex_query_editor_iwidget_set_value (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt_from), ""); + gdaex_query_editor_iwidget_set_value (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt_to), ""); gtk_table_set_row_spacing (GTK_TABLE (priv->tbl), 1, 5); } } @@ -2595,7 +2584,7 @@ gdaex_query_editor_on_btn_save_clicked (GtkButton *button, case GDAEX_QE_PAGE_SHOW: if (gtk_tree_selection_get_selected (priv->sel_show, NULL, &iter)) { - val1 = (gchar *)gtk_entry_get_text (GTK_ENTRY (priv->txt1)); + val1 = (gchar *)gtk_entry_get_text (GTK_ENTRY (priv->txt_alias)); if (val1 == NULL) { val1 = g_strdup (""); @@ -2671,21 +2660,8 @@ gdaex_query_editor_on_btn_save_clicked (GtkButton *button, 0, &where_type, -1); - if (GTK_IS_DATE_ENTRY (priv->txt1)) - { - 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)); - val1_sql = (gchar *)gtk_entry_get_text (GTK_ENTRY (priv->txt1)); - } + val1 = (gchar *)gdaex_query_editor_iwidget_get_value (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt_from)); + val1_sql = (gchar *)gdaex_query_editor_iwidget_get_value_sql (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt_from)); if (val1 == NULL) { val1 = g_strdup (""); @@ -2703,21 +2679,8 @@ gdaex_query_editor_on_btn_save_clicked (GtkButton *button, val1_sql = g_strdup (val1_sql); } - if (GTK_IS_DATE_ENTRY (priv->txt2)) - { - 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)); - val2_sql = (gchar *)gtk_entry_get_text (GTK_ENTRY (priv->txt2)); - } + val2 = (gchar *)gdaex_query_editor_iwidget_get_value (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt_to)); + val2_sql = (gchar *)gdaex_query_editor_iwidget_get_value_sql (GDAEX_QUERY_EDITOR_IWIDGET (priv->txt_to)); if (val2 == NULL) { val2 = g_strdup (""); @@ -2759,11 +2722,11 @@ gdaex_query_editor_on_btn_save_clicked (GtkButton *button, { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->opt_asc))) { - asc_desc = g_strdup ("ASC"); + asc_desc = g_strdup (_("ASC")); } else { - asc_desc = g_strdup ("DESC"); + asc_desc = g_strdup (_("DESC")); } gtk_list_store_set (priv->lstore_order, &iter, @@ -2948,9 +2911,9 @@ gdaex_query_editor_on_sel_show_changed (GtkTreeSelection *treeselection, lbl = gtk_label_new (g_strconcat (table->name_visible, " - ", field->name_visible, NULL)); gtk_table_attach (GTK_TABLE (tbl), lbl, 0, 1, 1, 2, 0, 0, 0, 0); - priv->txt1 = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (priv->txt1), alias == NULL ? "" : alias); - gtk_table_attach (GTK_TABLE (tbl), priv->txt1, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 0, 0); + priv->txt_alias = gtk_entry_new (); + gtk_entry_set_text (GTK_ENTRY (priv->txt_alias), alias == NULL ? "" : alias); + gtk_table_attach (GTK_TABLE (tbl), priv->txt_alias, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 0, 0); } gtk_box_pack_start (GTK_BOX (priv->vbx_values), priv->hbox_show, FALSE, FALSE, 0); @@ -3127,8 +3090,8 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection, if (GTK_IS_HBOX (priv->hbox_where)) { gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->cb_link_type), NULL); - gtk_container_remove (GTK_CONTAINER (priv->tbl), GTK_WIDGET (priv->txt1)); - gtk_container_remove (GTK_CONTAINER (priv->tbl), GTK_WIDGET (priv->txt2)); + gtk_container_remove (GTK_CONTAINER (priv->tbl), GTK_WIDGET (priv->txt_from)); + gtk_container_remove (GTK_CONTAINER (priv->tbl), GTK_WIDGET (priv->txt_to)); } else { @@ -3150,8 +3113,8 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection, lbl = gtk_label_new (_("Condition")); gtk_table_attach (GTK_TABLE (priv->tbl), lbl, 3, 4, 0, 1, GTK_FILL, 0, 0, 0); - priv->lbl_txt1 = gtk_label_new (_("Value")); - gtk_table_attach (GTK_TABLE (priv->tbl), priv->lbl_txt1, 4, 5, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0); + priv->lbl_from = gtk_label_new (_("Value")); + gtk_table_attach (GTK_TABLE (priv->tbl), priv->lbl_from, 4, 5, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0); /* link */ priv->cb_link_type = gtk_combo_box_new_with_model (GTK_TREE_MODEL (priv->lstore_link_type)); @@ -3193,9 +3156,9 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection, g_signal_connect (G_OBJECT (priv->cb_where_type), "changed", G_CALLBACK (gdaex_query_editor_on_cb_where_type_changed), user_data); - priv->lbl_txt2 = gtk_label_new ("and"); - gtk_misc_set_alignment (GTK_MISC (priv->lbl_txt2), 1.0, 0.5); - gtk_table_attach (GTK_TABLE (priv->tbl), priv->lbl_txt2, 3, 4, 2, 3, GTK_FILL, 0, 0, 0); + priv->lbl_to = gtk_label_new ("and"); + gtk_misc_set_alignment (GTK_MISC (priv->lbl_to), 1.0, 0.5); + gtk_table_attach (GTK_TABLE (priv->tbl), priv->lbl_to, 3, 4, 2, 3, GTK_FILL, 0, 0, 0); } /* if it is the first condition, "link" isn't visibile */ @@ -3340,67 +3303,27 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection, switch (field->type) { - /* TODO for now are all equals */ case GDAEX_QE_FIELD_TYPE_TEXT: - priv->txt1 = gtk_entry_new (); - priv->txt2 = gtk_entry_new (); - break; - case GDAEX_QE_FIELD_TYPE_INTEGER: - if (GDAEX_QUERY_EDITOR_IS_IWIDGET (field->iwidget_from)) - { - priv->txt1 = GTK_WIDGET (field->iwidget_from); - g_object_ref (priv->txt1); - } - else - { - priv->txt1 = gtk_entry_new (); - } - - if (GDAEX_QUERY_EDITOR_IS_IWIDGET (field->iwidget_to)) - { - priv->txt2 = GTK_WIDGET (field->iwidget_to); - g_object_ref (priv->txt2); - } - else - { - priv->txt2 = gtk_entry_new (); - } - break; - case GDAEX_QE_FIELD_TYPE_DOUBLE: - priv->txt1 = gtk_entry_new (); - priv->txt2 = gtk_entry_new (); - 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); - priv->txt2 = gtk_date_entry_new (NULL, NULL, TRUE); - gtk_date_entry_set_time_visible (GTK_DATE_ENTRY (priv->txt2), FALSE); - 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), "."); - priv->txt2 = gtk_date_entry_new (NULL, NULL, TRUE); - gtk_date_entry_set_time_separator (GTK_DATE_ENTRY (priv->txt2), "."); - break; - case GDAEX_QE_FIELD_TYPE_TIME: - priv->txt1 = gtk_entry_new (); - gtk_entry_set_max_length (GTK_ENTRY (priv->txt1), 8); - priv->txt2 = gtk_entry_new (); - gtk_entry_set_max_length (GTK_ENTRY (priv->txt2), 8); + priv->txt_from = GTK_WIDGET (field->iwidget_from); + g_object_ref (G_OBJECT (field->iwidget_from)); + priv->txt_to = GTK_WIDGET (field->iwidget_to); + g_object_ref (G_OBJECT (field->iwidget_to)); break; default: + priv->txt_from = NULL; + priv->txt_to = NULL; g_warning (_("Field's type «%d» not valid."), field->type); break; }; - 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_table_attach (GTK_TABLE (priv->tbl), priv->txt_from, 4, 5, 1, 2, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0, 0); + gtk_table_attach (GTK_TABLE (priv->tbl), priv->txt_to, 4, 5, 2, 3, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0, 0); gtk_box_pack_start (GTK_BOX (priv->vbx_values), priv->hbox_where, FALSE, FALSE, 0); @@ -3433,70 +3356,33 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection, switch (field->type) { - /* TODO for now are all equals */ case GDAEX_QE_FIELD_TYPE_TEXT: - gtk_entry_set_text (GTK_ENTRY (priv->txt1), from == NULL ? "" : from); - gtk_entry_set_text (GTK_ENTRY (priv->txt2), to == NULL ? "" : to); - break; - case GDAEX_QE_FIELD_TYPE_INTEGER: - if (GDAEX_QUERY_EDITOR_IS_IWIDGET (field->iwidget_from)) - { - gdaex_query_editor_iwidget_set_value (field->iwidget_from, from_sql == NULL ? "0" : from_sql); - } - else - { - gtk_entry_set_text (GTK_ENTRY (priv->txt1), from == NULL ? "" : from); - } - - if (GDAEX_QUERY_EDITOR_IS_IWIDGET (field->iwidget_to)) - { - gdaex_query_editor_iwidget_set_value (field->iwidget_to, to_sql == NULL ? "0" : to_sql); - } - else - { - gtk_entry_set_text (GTK_ENTRY (priv->txt2), to == NULL ? "" : to); - } - break; - case GDAEX_QE_FIELD_TYPE_DOUBLE: - gtk_entry_set_text (GTK_ENTRY (priv->txt1), from == NULL ? "" : from); - gtk_entry_set_text (GTK_ENTRY (priv->txt2), to == NULL ? "" : to); - break; - case GDAEX_QE_FIELD_TYPE_DATE: - 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"); - 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"); - break; - case GDAEX_QE_FIELD_TYPE_DATETIME: - 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"); - 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"); - break; - case GDAEX_QE_FIELD_TYPE_TIME: - gtk_entry_set_text (GTK_ENTRY (priv->txt1), from == NULL ? "" : from); - gtk_entry_set_text (GTK_ENTRY (priv->txt2), to == NULL ? "" : to); + gdaex_query_editor_iwidget_set_value (field->iwidget_from, from_sql == NULL ? "" : from_sql); + gdaex_query_editor_iwidget_set_value (field->iwidget_to, to_sql == NULL ? "" : to_sql); break; default: - g_warning ("Field's type «%d» not valid.", field->type); break; }; gtk_widget_show_all (priv->vbx_values); gtk_widget_show (priv->vbx_values_container); - gtk_widget_set_visible (priv->lbl_txt1, where_type != GDAEX_QE_WHERE_TYPE_IS_NULL); - gtk_widget_set_visible (priv->txt1, where_type != GDAEX_QE_WHERE_TYPE_IS_NULL); + gtk_widget_set_visible (priv->lbl_from, where_type != GDAEX_QE_WHERE_TYPE_IS_NULL); + gtk_widget_set_visible (priv->txt_from, where_type != GDAEX_QE_WHERE_TYPE_IS_NULL); if (where_type == GDAEX_QE_WHERE_TYPE_IS_NULL) { gtk_table_set_col_spacing (GTK_TABLE (priv->tbl), 3, 0); } - gtk_widget_set_visible (priv->lbl_txt2, where_type == GDAEX_QE_WHERE_TYPE_BETWEEN); - gtk_widget_set_visible (priv->txt2, where_type == GDAEX_QE_WHERE_TYPE_BETWEEN); + gtk_widget_set_visible (priv->lbl_to, where_type == GDAEX_QE_WHERE_TYPE_BETWEEN); + gtk_widget_set_visible (priv->txt_to, where_type == GDAEX_QE_WHERE_TYPE_BETWEEN); if (where_type == 0) { diff --git a/src/queryeditorentry.c b/src/queryeditorentry.c new file mode 100644 index 0000000..fceb7f4 --- /dev/null +++ b/src/queryeditorentry.c @@ -0,0 +1,141 @@ +/* + * 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 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 "libgdaex.h" + +#include "queryeditorentry.h" + +static void gdaex_query_editor_entry_class_init (GdaExQueryEditorEntryClass *klass); +static void gdaex_query_editor_entry_init (GdaExQueryEditorEntry *masked_entry); + +static void gdaex_query_editor_entry_gdaex_query_editor_iwidget_interface_init (GdaExQueryEditorIWidgetIface *iface); + +static void gdaex_query_editor_entry_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gdaex_query_editor_entry_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static const gchar *gdaex_query_editor_entry_get_value (GdaExQueryEditorIWidget *iwidget); +static const gchar *gdaex_query_editor_entry_get_value_sql (GdaExQueryEditorIWidget *iwidget); +static void gdaex_query_editor_entry_set_value (GdaExQueryEditorIWidget *iwidget, const gchar *value); + +#define GDAEX_QUERY_EDITOR_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_MASKED_ENTRY, GdaExQueryEditorEntryPrivate)) + +typedef struct _GdaExQueryEditorEntryPrivate GdaExQueryEditorEntryPrivate; +struct _GdaExQueryEditorEntryPrivate + { + gpointer foo; + }; + +G_DEFINE_TYPE_WITH_CODE (GdaExQueryEditorEntry, gdaex_query_editor_entry, GTK_TYPE_ENTRY, + G_IMPLEMENT_INTERFACE (GDAEX_QUERY_EDITOR_TYPE_IWIDGET, + gdaex_query_editor_entry_gdaex_query_editor_iwidget_interface_init)); + +static void +gdaex_query_editor_entry_class_init (GdaExQueryEditorEntryClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (GdaExQueryEditorEntryPrivate)); + + object_class->set_property = gdaex_query_editor_entry_set_property; + object_class->get_property = gdaex_query_editor_entry_get_property; +} + +static void +gdaex_query_editor_entry_init (GdaExQueryEditorEntry *masked_entry) +{ + GdaExQueryEditorEntryPrivate *priv = GDAEX_QUERY_EDITOR_ENTRY_GET_PRIVATE (masked_entry); +} + +static void +gdaex_query_editor_entry_gdaex_query_editor_iwidget_interface_init (GdaExQueryEditorIWidgetIface *iface) +{ + iface->get_value = gdaex_query_editor_entry_get_value; + iface->get_value_sql = gdaex_query_editor_entry_get_value_sql; + iface->set_value = gdaex_query_editor_entry_set_value; +} + +/** + * gdaex_query_editor_entry_new: + * + * Creates a new #GdaExQueryEditorEntry widget. + * + * Returns: the newly created #GdaExQueryEditorEntry widget. + */ +GtkWidget* +gdaex_query_editor_entry_new () +{ + return GTK_WIDGET (g_object_new (gdaex_query_editor_entry_get_type (), NULL)); +} + +static void +gdaex_query_editor_entry_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + GdaExQueryEditorEntry *masked_entry = GDAEX_QUERY_EDITOR_ENTRY (object); + GdaExQueryEditorEntryPrivate *priv = GDAEX_QUERY_EDITOR_ENTRY_GET_PRIVATE (masked_entry); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gdaex_query_editor_entry_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + GdaExQueryEditorEntry *masked_entry = GDAEX_QUERY_EDITOR_ENTRY (object); + GdaExQueryEditorEntryPrivate *priv = GDAEX_QUERY_EDITOR_ENTRY_GET_PRIVATE (masked_entry); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static const gchar +*gdaex_query_editor_entry_get_value (GdaExQueryEditorIWidget *iwidget) +{ + return gtk_entry_get_text (GTK_ENTRY (iwidget)); +} + +static const gchar +*gdaex_query_editor_entry_get_value_sql (GdaExQueryEditorIWidget *iwidget) +{ + return gtk_entry_get_text (GTK_ENTRY (iwidget)); +} + +static void +gdaex_query_editor_entry_set_value (GdaExQueryEditorIWidget *iwidget, + const gchar *value) +{ + gtk_entry_set_text (GTK_ENTRY (iwidget), value); +} diff --git a/src/queryeditorentry.h b/src/queryeditorentry.h new file mode 100644 index 0000000..01fc784 --- /dev/null +++ b/src/queryeditorentry.h @@ -0,0 +1,60 @@ +/* + * 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 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_H__ +#define __GDAEX_QUERY_EDITOR_ENTRY_H__ + +#include + + +G_BEGIN_DECLS + + +#define GTK_TYPE_MASKED_ENTRY (gdaex_query_editor_entry_get_type ()) +#define GDAEX_QUERY_EDITOR_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_MASKED_ENTRY, GdaExQueryEditorEntry)) +#define GDAEX_QUERY_EDITOR_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_MASKED_ENTRY, GdaExQueryEditorEntryClass)) +#define GTK_IS_MASKED_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_MASKED_ENTRY)) +#define GTK_IS_MASKED_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MASKED_ENTRY)) +#define GDAEX_QUERY_EDITOR_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_MASKED_ENTRY, GdaExQueryEditorEntryClass)) + + +typedef struct _GdaExQueryEditorEntry GdaExQueryEditorEntry; +typedef struct _GdaExQueryEditorEntryClass GdaExQueryEditorEntryClass; + + +struct _GdaExQueryEditorEntry +{ + GtkEntry entry; +}; + +struct _GdaExQueryEditorEntryClass +{ + GtkEntryClass parent_class; +}; + + +GType gdaex_query_editor_entry_get_type (void) G_GNUC_CONST; + +GtkWidget *gdaex_query_editor_entry_new (void); + + +G_END_DECLS + + +#endif /* __GDAEX_QUERY_EDITOR_ENTRY_H__ */