<column type="gboolean"/>
</columns>
</object>
- <object class="GtkListStore" id="lstore_fields">
+ <object class="GtkListStore" id="lstore_tables">
<columns>
- <!-- column-name id -->
- <column type="guint"/>
<!-- column-name name -->
<column type="gchararray"/>
- <!-- column-name choosen -->
- <column type="gboolean"/>
</columns>
</object>
- <object class="GtkListStore" id="lstore_tables">
+ <object class="GtkListStore" id="lstore_fields">
<columns>
<!-- column-name name -->
<column type="gchararray"/>
+ <!-- column-name choosen -->
+ <column type="gboolean"/>
</columns>
</object>
<object class="GtkWindow" id="w_table">
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
- <attribute name="text">1</attribute>
+ <attribute name="text">0</attribute>
</attributes>
</child>
</object>
<child>
<object class="GtkCellRendererToggle" id="cellrenderertoggle1"/>
<attributes>
- <attribute name="activatable">2</attribute>
+ <attribute name="active">1</attribute>
</attributes>
</child>
</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);
Commons *commons;
GtkWidget *w;
+ GtkListStore *lstore_fields;
gint id;
};
}
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"),
}
/* 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);
+ }
+ }
}