From: Andrea Zagli Date: Sun, 15 Aug 2010 09:40:25 +0000 (+0200) Subject: Bugfixes. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=2e704aae619f3df8636199b2ef06dab48900701c;p=zakaudit%2Fgui Bugfixes. Add select and unselect all fields in table form. --- diff --git a/data/audit-gui/gui/audit-gui.gui b/data/audit-gui/gui/audit-gui.gui index 3f5eec8..b65e125 100644 --- a/data/audit-gui/gui/audit-gui.gui +++ b/data/audit-gui/gui/audit-gui.gui @@ -496,40 +496,91 @@ - + True - True - automatic - automatic - etched-in + 5 - + True True - lstore_fields + automatic + automatic + etched-in - - Fields + + True + True + lstore_fields + False + 0 - - - 1 - + + Fields + + + + 1 + + + + + + + Under audit + + + + 2 + + + + + + 0 + + + + + True + vertical + 5 + spread - - Under audit - - - - 2 - - + + _Select all + True + True + True + True + + False + False + 0 + + + + + _Unselect all + True + True + True + True + + + False + False + 1 + + + False + 1 + diff --git a/src/table.c b/src/table.c index 0b8dd51..09a67a2 100644 --- a/src/table.c +++ b/src/table.c @@ -45,6 +45,11 @@ static void fixed_toggled (GtkCellRendererToggle *cell, static void table_on_cb_tables_changed (GtkComboBox *widget, gpointer user_data); +static void table_on_btn_select_all_clicked (GtkButton *button, + gpointer user_data); +static void table_on_btn_unselect_all_clicked (GtkButton *button, + gpointer user_data); + static void table_on_btn_cancel_clicked (GtkButton *button, gpointer user_data); static void table_on_btn_save_clicked (GtkButton *button, @@ -136,6 +141,11 @@ Table "toggled", G_CALLBACK (fixed_toggled), priv->lstore_fields); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button11"), + "clicked", G_CALLBACK (table_on_btn_select_all_clicked), (gpointer *)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button12"), + "clicked", G_CALLBACK (table_on_btn_unselect_all_clicked), (gpointer *)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button5"), "clicked", G_CALLBACK (table_on_btn_cancel_clicked), (gpointer *)a); g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button6"), @@ -372,11 +382,12 @@ table_save (Table *table) new_id++; sql = g_strdup_printf ("INSERT INTO %stables" - " (id, name)" - " VALUES (%d, '%s')", + " (id, name, id_datasources)" + " VALUES (%d, '%s', %d)", priv->commons->prefix, new_id, - table_name); + table_name, + strtol (gtk_label_get_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label8"))), NULL, 10)); stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, NULL); } else @@ -419,10 +430,8 @@ table_save (Table *table) if (id_field == 0) { error = NULL; - sql = g_strdup_printf ("SELECT COALESCE (MAX (id), 0) FROM %sfields" - " WHERE id_tables = %d", - priv->commons->prefix, - priv->id); + sql = g_strdup_printf ("SELECT COALESCE (MAX (id), 0) FROM %sfields", + priv->commons->prefix); stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, NULL); dm = gda_connection_statement_execute_select (priv->commons->gdacon, stmt, NULL, &error); if (dm != NULL && gda_data_model_get_n_rows (dm) == 1) @@ -449,7 +458,7 @@ table_save (Table *table) gda_connection_statement_execute_non_select (priv->commons->gdacon, stmt, NULL, NULL, &error); if (error != NULL) { - g_warning ("Error save new field: %s", + g_warning ("Error saving new field: %s", (error->message != NULL ? error->message : "No details.")); } g_object_unref (stmt); @@ -459,26 +468,23 @@ table_save (Table *table) } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->lstore_fields), &iter)); } - if (g_strcmp0 (id_saved, "") != 0) + /* removing fields not saved */ + error = NULL; + id_saved[strlen (id_saved) - 1] = '\0'; + sql = g_strdup_printf ("DELETE FROM %sfields" + " WHERE id_tables = %d" + "%s", + priv->commons->prefix, + priv->id, + (g_strcmp0 (id_saved, "") != 0 ? g_strdup_printf (" AND id NOT IN (%s)", id_saved) : "")); + stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, NULL); + gda_connection_statement_execute_non_select (priv->commons->gdacon, stmt, NULL, NULL, &error); + if (error != NULL) { - /* removing fields not saved */ - error = NULL; - id_saved[strlen (id_saved) - 1] = '\0'; - sql = g_strdup_printf ("DELETE FROM %sfields" - " WHERE id_tables = %d" - " AND id NOT IN (%s)", - priv->commons->prefix, - priv->id, - id_saved); - stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, NULL); - gda_connection_statement_execute_non_select (priv->commons->gdacon, stmt, NULL, NULL, &error); - if (error != NULL) - { - g_warning ("Error removing old fields: %s", - (error->message != NULL ? error->message : "No details.")); - } - g_object_unref (stmt); + g_warning ("Error removing old fields: %s", + (error->message != NULL ? error->message : "No details.")); } + g_object_unref (stmt); g_signal_emit (table, klass->updated_signal_id, 0); @@ -657,6 +663,48 @@ table_on_cb_tables_changed (GtkComboBox *widget, } +static void +table_on_btn_select_all_clicked (GtkButton *button, + gpointer user_data) +{ + Table *table = (Table *)user_data; + + TablePrivate *priv = TABLE_GET_PRIVATE (table); + + GtkTreeIter iter; + + if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->lstore_fields), &iter)) + { + do + { + gtk_list_store_set (priv->lstore_fields, &iter, + 2, TRUE, + -1); + } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->lstore_fields), &iter)); + } +} + +static void +table_on_btn_unselect_all_clicked (GtkButton *button, + gpointer user_data) +{ + Table *table = (Table *)user_data; + + TablePrivate *priv = TABLE_GET_PRIVATE (table); + + GtkTreeIter iter; + + if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->lstore_fields), &iter)) + { + do + { + gtk_list_store_set (priv->lstore_fields, &iter, + 2, FALSE, + -1); + } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->lstore_fields), &iter)); + } +} + static void table_on_btn_cancel_clicked (GtkButton *button, gpointer user_data)