From 2bafb905af96c07899879e13a5a5371bbb261248 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 14 Aug 2010 18:56:20 +0200 Subject: [PATCH] Loaded table's fields from db. --- data/audit-gui/gui/audit-gui.gui | 14 ++--- src/table.c | 99 ++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 8 deletions(-) diff --git a/data/audit-gui/gui/audit-gui.gui b/data/audit-gui/gui/audit-gui.gui index ba45c0e..89ebe2d 100644 --- a/data/audit-gui/gui/audit-gui.gui +++ b/data/audit-gui/gui/audit-gui.gui @@ -353,20 +353,18 @@ - + - - - - - + + + @@ -482,7 +480,7 @@ - 1 + 0 @@ -493,7 +491,7 @@ - 2 + 1 diff --git a/src/table.c b/src/table.c index 470cabf..d2c3ab7 100644 --- a/src/table.c +++ b/src/table.c @@ -37,6 +37,10 @@ static void table_get_property (GObject *object, GValue *value, GParamSpec *pspec); +static void fixed_toggled (GtkCellRendererToggle *cell, + gchar *path_str, + gpointer data); + static void table_on_cb_tables_changed (GtkComboBox *widget, gpointer user_data); @@ -53,6 +57,7 @@ struct _TablePrivate Commons *commons; GtkWidget *w; + GtkListStore *lstore_fields; gint id; }; @@ -121,10 +126,15 @@ Table } priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_table")); + priv->lstore_fields = GTK_LIST_STORE (gtk_builder_get_object (priv->commons->gtkbuilder, "lstore_fields")); g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "combobox1"), "changed", G_CALLBACK (table_on_cb_tables_changed), (gpointer *)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "cellrenderertoggle1"), + "toggled", G_CALLBACK (fixed_toggled), + priv->lstore_fields); + 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"), @@ -392,10 +402,99 @@ table_get_property (GObject *object, guint property_id, GValue *value, GParamSpe } /* CALLBACK */ +static void +fixed_toggled (GtkCellRendererToggle *cell, + gchar *path_str, + gpointer data) +{ + GtkTreeModel *model = (GtkTreeModel *)data; + GtkTreeIter iter; + GtkTreePath *path = gtk_tree_path_new_from_string (path_str); + + gboolean choosen; + + /* get toggled iter */ + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, 1, &choosen, -1); + + choosen ^= 1; + + /* set new value */ + gtk_list_store_set (GTK_LIST_STORE (model), &iter, 1, choosen, -1); + + /* clean up */ + gtk_tree_path_free (path); +} + static void table_on_cb_tables_changed (GtkComboBox *widget, gpointer user_data) { + GError *error; + + GdaMetaContext mcontext = {"_columns", 1, NULL, NULL}; + + gchar *table_name; + GdaDataModel *dm; + + GtkTreeIter iter; + + GValue *gval; + + guint rows; + guint row; + + TablePrivate *priv = TABLE_GET_PRIVATE ((Table *)user_data); + + gtk_list_store_clear (GTK_LIST_STORE (priv->lstore_fields)); + + if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "combobox1")), &iter)) + { + return; + } + + gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "combobox1"))), &iter, 0, &table_name, -1); + + error = NULL; + mcontext.column_names = g_new (gchar *, 1); + mcontext.column_names[0] = "table_name"; + mcontext.column_values = g_new (GValue *, 1); + mcontext.column_values[0] = gda_value_new (G_TYPE_STRING); + g_value_take_string (mcontext.column_values[0], + gda_sql_identifier_quote (table_name, priv->commons->gdacon, NULL, FALSE, FALSE)); + if (!gda_connection_update_meta_store (priv->commons->gdacon, &mcontext, &error)) + { + GtkWidget *dialog; + dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_OK, + "Unable to get fields list.\n\n%s", + (error != NULL && error->message != NULL ? error->message : "No details.")); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + return; + } + + error = NULL; + gval = gda_value_new (G_TYPE_STRING); + g_value_take_string (gval, table_name); + dm = gda_connection_get_meta_store_data (priv->commons->gdacon, + GDA_CONNECTION_META_FIELDS, + &error, + 1, + "name", gval); + if (dm != NULL) + { + rows = gda_data_model_get_n_rows (dm); + for (row = 0; row < rows; row++) + { + gtk_list_store_append (priv->lstore_fields, &iter); + gtk_list_store_set (priv->lstore_fields, &iter, + 0, gda_value_stringify (gda_data_model_get_value_at (dm, 0, row, NULL)), + -1); + } + } } -- 2.49.0