[libgda] Implemented tables from imported files in virtual connection



commit e22ac913ddaab421f0a89385ff4607bce64eec7d
Author: Vivien Malerba <malerba gnome-db org>
Date:   Mon Oct 19 20:31:33 2009 +0200

    Implemented tables from imported files in virtual connection

 tools/browser/browser-virtual-connection.c    |    3 -
 tools/browser/browser-virtual-connection.h    |    1 -
 tools/browser/common/Makefile.am              |   10 +-
 tools/browser/common/gdaui-data-import.c      |  450 +++++++++++++++++++++++++
 tools/browser/common/gdaui-data-import.h      |   66 ++++
 tools/browser/common/gdaui-entry-import.c     |  299 ++++++++++++++++
 tools/browser/common/gdaui-entry-import.h     |   59 ++++
 tools/browser/common/import_encodings.xml     |  315 +++++++++++++++++
 tools/browser/connection-binding-properties.c |   81 ++++-
 9 files changed, 1268 insertions(+), 16 deletions(-)
---
diff --git a/tools/browser/browser-virtual-connection.c b/tools/browser/browser-virtual-connection.c
index f848281..eb8bd29 100644
--- a/tools/browser/browser-virtual-connection.c
+++ b/tools/browser/browser-virtual-connection.c
@@ -474,8 +474,6 @@ browser_virtual_connection_part_copy (const BrowserVirtualConnectionPart *part)
 		BrowserVirtualConnectionModel *npm;
 		spm = &(part->u.model);
 		npm = &(npart->u.model);
-		if (spm->table_schema)
-			npm->table_schema = g_strdup (spm->table_schema);
 		if (spm->table_name)
 			npm->table_name = g_strdup (spm->table_name);
 		if (spm->model)
@@ -513,7 +511,6 @@ browser_virtual_connection_part_free (BrowserVirtualConnectionPart *part)
 	case BROWSER_VIRTUAL_CONNECTION_PART_MODEL: {
 		BrowserVirtualConnectionModel *pm;
 		pm = &(part->u.model);
-		g_free (pm->table_schema);
 		g_free (pm->table_name);
 		if (pm->model)
 			g_object_unref (pm->model);
diff --git a/tools/browser/browser-virtual-connection.h b/tools/browser/browser-virtual-connection.h
index d17b686..a58c37d 100644
--- a/tools/browser/browser-virtual-connection.h
+++ b/tools/browser/browser-virtual-connection.h
@@ -56,7 +56,6 @@ typedef enum {
 
 /* part: a table from a GdaDataModel */
 typedef struct {
-	gchar *table_schema;
 	gchar *table_name;
 	GdaDataModel *model;	
 } BrowserVirtualConnectionModel;
diff --git a/tools/browser/common/Makefile.am b/tools/browser/common/Makefile.am
index 07fae25..f3f0214 100644
--- a/tools/browser/common/Makefile.am
+++ b/tools/browser/common/Makefile.am
@@ -19,7 +19,11 @@ libcommon_la_SOURCES = \
 	objects-cloud.c \
 	objects-cloud.h \
 	popup-container.c \
-	popup-container.h
+	popup-container.h \
+	gdaui-data-import.c \
+	gdaui-data-import.h \
+	gdaui-entry-import.c \
+	gdaui-entry-import.h
 
 $(OBJECTS): marshal.c marshal.h
 
@@ -28,6 +32,10 @@ libcommon_la_LIBADD = \
 	$(LIBGDA_LIBS) \
 	$(GTK_LIBS)
 
+xmldir=$(datadir)/libgda-4.0
+xml_DATA= \
+	import_encodings.xml
+
 EXTRA_DIST = \
 	marshal.list
 
diff --git a/tools/browser/common/gdaui-data-import.c b/tools/browser/common/gdaui-data-import.c
new file mode 100644
index 0000000..1cb62bd
--- /dev/null
+++ b/tools/browser/common/gdaui-data-import.c
@@ -0,0 +1,450 @@
+/* gdaui-data-import.c
+ *
+ * Copyright (C) 2006 - 2008 Vivien Malerba
+ *
+ * This Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include <string.h>
+#include "gdaui-data-import.h"
+#include <libgda/libgda.h>
+#include <glib/gi18n-lib.h>
+#include <libgda-ui/gdaui-combo.h>
+#include <libgda-ui/gdaui-grid.h>
+#include <libgda-ui/gdaui-raw-grid.h>
+#include <libgda-ui/gdaui-data-widget-info.h>
+#include <libgda/binreloc/gda-binreloc.h>
+
+static void gdaui_data_import_class_init (GdauiDataImportClass *class);
+static void gdaui_data_import_init (GdauiDataImport *wid);
+static void gdaui_data_import_dispose (GObject *object);
+
+
+enum {
+	SEP_COMMA,
+	SEP_SEMICOL,
+	SEP_TAB,
+	SEP_SPACE,
+	SEP_PIPE,
+	SEP_OTHER,
+	SEP_LAST
+};
+
+struct _GdauiDataImportPriv
+{
+	GdaDataModel  *model;
+
+	/* spec widgets */
+	GtkWidget     *file_chooser;
+	GtkWidget     *encoding_combo;
+	GtkWidget     *first_line_check;
+	GtkWidget     *sep_array [SEP_LAST];
+	GtkWidget     *sep_other_entry;
+
+	/* preview widgets */
+	GtkWidget     *preview_box;
+	GtkWidget     *no_data_label;
+	GtkWidget     *preview_grid;
+};
+
+static void spec_changed_cb (GtkWidget *wid, GdauiDataImport *import);
+
+/* get a pointer to the parents to be able to call their destructor */
+static GObjectClass *parent_class = NULL;
+
+GType
+gdaui_data_import_get_type (void)
+{
+	static GType type = 0;
+
+	if (G_UNLIKELY (type == 0)) {
+		static const GTypeInfo info = {
+			sizeof (GdauiDataImportClass),
+			(GBaseInitFunc) NULL,
+			(GBaseFinalizeFunc) NULL,
+			(GClassInitFunc) gdaui_data_import_class_init,
+			NULL,
+			NULL,
+			sizeof (GdauiDataImport),
+			0,
+			(GInstanceInitFunc) gdaui_data_import_init
+		};		
+		
+		type = g_type_register_static (GTK_TYPE_VPANED, "GdauiDataImport", &info, 0);
+	}
+
+	return type;
+}
+
+static void
+gdaui_data_import_class_init (GdauiDataImportClass * class)
+{
+	GObjectClass   *object_class = G_OBJECT_CLASS (class);
+	
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class->dispose = gdaui_data_import_dispose;
+}
+
+static void
+gdaui_data_import_init (GdauiDataImport * import)
+{
+	GtkWidget *label, *vbox, *hbox;
+	gchar *str;
+	GtkWidget *table, *entry;
+	GtkFileFilter *filter;
+	GdaDataModel *encs;
+	GSList *encs_errors;
+	
+	import->priv = g_new0 (GdauiDataImportPriv, 1);
+	import->priv->model = NULL;
+
+	/* 
+	 * top part: import specs. 
+	 */
+	vbox = gtk_vbox_new (FALSE, 0);
+        gtk_paned_pack1 (GTK_PANED (import), vbox, FALSE, FALSE);
+
+	str = g_strdup_printf ("<b>%s:</b>", _("Import specifications"));
+        label = gtk_label_new ("");
+        gtk_label_set_markup (GTK_LABEL (label), str);
+        gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
+        g_free (str);
+        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+        hbox = gtk_hbox_new (FALSE, 0); /* HIG */
+        gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
+        gtk_widget_show (hbox);
+        label = gtk_label_new ("    ");
+        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+	table = gtk_table_new (7, 4, FALSE);
+	gtk_box_pack_start (GTK_BOX (hbox), table, TRUE, TRUE, 0);
+	gtk_table_set_col_spacings (GTK_TABLE (table), 5);
+	gtk_table_set_row_spacings (GTK_TABLE (table), 5);
+
+	/* file to import from */
+	label = gtk_label_new (_("File to import from:"));
+	gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
+	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_SHRINK | GTK_FILL, 0, 0, 0);
+
+	entry = gtk_file_chooser_button_new (_("File to import data from"), GTK_FILE_CHOOSER_ACTION_OPEN);
+	import->priv->file_chooser = entry;
+	filter = gtk_file_filter_new ();
+	gtk_file_filter_set_name (filter, _("Comma separated values"));
+	gtk_file_filter_add_pattern (filter, "*.csv");
+	gtk_file_filter_add_pattern (filter, "*.txt");
+	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (entry), filter);
+	filter = gtk_file_filter_new ();
+	gtk_file_filter_set_name (filter, _("XML exported"));
+	gtk_file_filter_add_pattern (filter, "*.xml");
+	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (entry), filter);
+	filter = gtk_file_filter_new ();
+	gtk_file_filter_set_name (filter, _("All files"));
+	gtk_file_filter_add_pattern (filter, "*");
+	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (entry), filter);
+	gtk_table_attach (GTK_TABLE (table), entry, 1, 4, 0, 1, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0, 0);
+	g_signal_connect (G_OBJECT (entry), "selection-changed",
+			  G_CALLBACK (spec_changed_cb), import);
+
+	/* Encoding */ 
+	label = gtk_label_new (_("Encoding:"));
+	gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
+	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_SHRINK | GTK_FILL, 0, 0, 0);
+
+	gchar *fname = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "import_encodings.xml", NULL);
+	encs = gda_data_model_import_new_file (fname, TRUE, NULL);
+	g_free (fname);
+	encs_errors = gda_data_model_import_get_errors (GDA_DATA_MODEL_IMPORT (encs));
+	if (encs_errors) {
+		for (; encs_errors; encs_errors = g_slist_next (encs_errors)) {
+			g_print ("Error: %s\n", encs_errors->data && ((GError *) encs_errors->data)->message ?
+				 ((GError *) encs_errors->data)->message : _("no detail"));
+		}
+		import->priv->encoding_combo = NULL;
+	}
+	else {
+		gint cols[] = {0};
+		entry = gdaui_combo_new_with_model (encs, 1, cols);
+		import->priv->encoding_combo = entry;
+	}
+	g_object_unref (encs);
+	gtk_table_attach (GTK_TABLE (table), entry, 1, 4, 1, 2, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0, 0);
+	g_signal_connect (G_OBJECT (entry), "changed",
+			  G_CALLBACK (spec_changed_cb), import);
+
+	/* first line as title */
+	label = gtk_label_new (_("First line as title:"));
+	gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
+	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, GTK_SHRINK | GTK_FILL, 0, 0, 0);
+	
+	entry = gtk_check_button_new ();
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (entry), TRUE);
+	import->priv->first_line_check = entry,
+	gtk_table_attach (GTK_TABLE (table), entry, 1, 3, 2, 3, GTK_SHRINK | GTK_FILL, 0, 0, 0);
+	g_signal_connect (G_OBJECT (entry), "toggled",
+			  G_CALLBACK (spec_changed_cb), import);
+
+	/* separator */
+	label = gtk_label_new (_("Separator:"));
+	gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
+	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4, GTK_SHRINK | GTK_FILL, 0, 0, 0);
+
+	entry = gtk_radio_button_new_with_label (NULL, _("Comma"));
+	import->priv->sep_array [SEP_COMMA] = entry;
+	gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 3, 4, GTK_FILL, 0, 0, 0);
+	g_object_set_data (G_OBJECT (entry), "_sep", ",");
+	g_signal_connect (G_OBJECT (entry), "toggled",
+			  G_CALLBACK (spec_changed_cb), import);
+
+	entry = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (entry), _("Semi column"));
+	import->priv->sep_array [SEP_SEMICOL] = entry;
+	gtk_table_attach (GTK_TABLE (table), entry, 2, 3, 3, 4, GTK_FILL, 0, 0, 0);
+	g_object_set_data (G_OBJECT (entry), "_sep", ";");
+	g_signal_connect (G_OBJECT (entry), "toggled",
+			  G_CALLBACK (spec_changed_cb), import);
+
+	entry = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (entry), _("Tab"));
+	import->priv->sep_array [SEP_TAB] = entry;
+	gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 4, 5, GTK_FILL, 0, 0, 0);
+	g_object_set_data (G_OBJECT (entry), "_sep", "\t");
+	g_signal_connect (G_OBJECT (entry), "toggled",
+			  G_CALLBACK (spec_changed_cb), import);
+
+	entry = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (entry), _("Space"));
+	import->priv->sep_array [SEP_SPACE] = entry;
+	gtk_table_attach (GTK_TABLE (table), entry, 2, 3, 4, 5, GTK_FILL, 0, 0, 0);
+	g_object_set_data (G_OBJECT (entry), "_sep", " ");
+	g_signal_connect (G_OBJECT (entry), "toggled",
+			  G_CALLBACK (spec_changed_cb), import);
+
+	entry = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (entry), _("Pipe"));
+	import->priv->sep_array [SEP_PIPE] = entry;
+	gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 5, 6, GTK_FILL, 0, 0, 0);
+	g_object_set_data (G_OBJECT (entry), "_sep", "|");
+	g_signal_connect (G_OBJECT (entry), "toggled",
+			  G_CALLBACK (spec_changed_cb), import);
+
+	hbox = gtk_hbox_new (FALSE, 0);
+	gtk_table_attach (GTK_TABLE (table), hbox, 2, 3, 5, 6, GTK_FILL, 0, 0, 0);
+	entry = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (entry), _("Other:"));
+	import->priv->sep_array [SEP_OTHER] = entry;
+	gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
+	g_object_set_data (G_OBJECT (entry), "_sep", "");
+	g_signal_connect (G_OBJECT (entry), "toggled",
+			  G_CALLBACK (spec_changed_cb), import);
+
+	entry = gtk_entry_new ();
+	import->priv->sep_other_entry = entry;
+	gtk_entry_set_max_length (GTK_ENTRY (entry), 1);
+	gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+	gtk_widget_set_sensitive (entry, FALSE);
+	g_signal_connect (G_OBJECT (entry), "changed",
+			  G_CALLBACK (spec_changed_cb), import);
+
+        gtk_widget_show_all (vbox);
+	
+
+	/* 
+	 * bottom part: import preview 
+	 */
+	vbox = gtk_vbox_new (FALSE, 0);
+        gtk_paned_pack2 (GTK_PANED (import), vbox, TRUE, FALSE);
+
+	str = g_strdup_printf ("<b>%s:</b>", _("Import preview"));
+        label = gtk_label_new ("");
+        gtk_label_set_markup (GTK_LABEL (label), str);
+        gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
+        g_free (str);
+        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+        hbox = gtk_hbox_new (FALSE, 0); /* HIG */
+        gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
+        gtk_widget_show (hbox);
+        label = gtk_label_new ("    ");
+        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+	import->priv->preview_box = hbox;
+
+        label = gtk_label_new ("");
+        gtk_label_set_markup (GTK_LABEL (label), _("No data."));
+        gtk_misc_set_alignment (GTK_MISC (label), 0., 0.);
+        gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+	import->priv->no_data_label = label;
+
+	gtk_widget_show_all (vbox);
+
+	gtk_paned_set_position (GTK_PANED (import), 1);
+	
+}
+
+/**
+ * gdaui_data_import_new
+ * Creates a new #GdauiDataImport widget. After import, a #GdaDataModel will be created.
+ *
+ * Returns: the new widget
+ */
+GtkWidget *
+gdaui_data_import_new (void)
+{
+	GdauiDataImport *import;
+		
+	import = GDAUI_DATA_IMPORT (g_object_new (GDAUI_TYPE_DATA_IMPORT, NULL));
+	
+	return GTK_WIDGET (import);
+}
+
+
+static void
+gdaui_data_import_dispose (GObject *object)
+{
+	GdauiDataImport *import;
+
+	g_return_if_fail (object != NULL);
+	g_return_if_fail (GDAUI_IS_DATA_IMPORT (object));
+	import = GDAUI_DATA_IMPORT (object);
+
+	if (import->priv) {
+		if (import->priv->model) {
+			g_object_unref (import->priv->model);
+			import->priv->model = NULL;
+		}
+
+		/* the private area itself */
+		g_free (import->priv);
+		import->priv = NULL;
+	}
+
+	/* for the parent class */
+	parent_class->dispose (object);
+}
+
+static void
+spec_changed_cb (GtkWidget *wid, GdauiDataImport *import)
+{
+	gchar *file;
+	GdaSet *options;
+	gchar *sep;
+	GdaHolder *psep = NULL;
+	gint sepno;
+
+	if (import->priv->preview_grid) {
+		gtk_widget_destroy (import->priv->preview_grid);
+		import->priv->preview_grid = NULL;
+	}
+	if (import->priv->model) {
+		g_object_unref (import->priv->model);
+		import->priv->model = NULL;
+	}
+
+	sep = g_object_get_data (G_OBJECT (wid), "_sep");
+	if (sep) {
+		if (*sep == 0)
+			gtk_widget_set_sensitive (import->priv->sep_other_entry,  
+						  gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (wid)));
+		
+		if (! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (wid)))
+			return;
+	}
+
+	for (sepno = SEP_COMMA; sepno < SEP_LAST; sepno++) {
+		if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (import->priv->sep_array [sepno]))) {
+			sep = g_object_get_data (G_OBJECT (import->priv->sep_array [sepno]), "_sep");
+			psep = gda_holder_new (G_TYPE_STRING);
+			g_object_set (G_OBJECT (psep), "id", "SEPARATOR", NULL);
+			if (sepno != SEP_OTHER)
+				gda_holder_set_value_str (psep, NULL, sep, NULL);
+			else
+				gda_holder_set_value_str (psep, NULL,
+							  gtk_entry_get_text (GTK_ENTRY (import->priv->sep_other_entry)),
+							  NULL);
+			break;
+		}
+	}
+
+	options = gda_set_new (NULL);
+	if (psep) {
+		gda_set_add_holder (options, psep);
+		g_object_unref (psep);
+	}
+
+	if (import->priv->encoding_combo) {
+		GSList *values;
+
+		values = gdaui_combo_get_values (GDAUI_COMBO (import->priv->encoding_combo));
+		if (values) {
+			GdaHolder *h;
+			h = g_object_new (GDA_TYPE_HOLDER, "id", "ENCODING", "g-type", G_TYPE_STRING, NULL);
+			
+			gda_holder_set_value (h, (GValue *) values->data, NULL);
+			gda_set_add_holder (options, h);
+			g_object_unref (h);
+			g_slist_free (values);
+		}
+	}
+
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (import->priv->first_line_check))) {
+			GdaHolder *h;
+			h = gda_holder_new_inline (G_TYPE_BOOLEAN, "TITLE_AS_FIRST_LINE", TRUE);
+			gda_set_add_holder (options, h);
+			g_object_unref (h);
+	}
+
+	file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (import->priv->file_chooser));
+	if (file) {
+		import->priv->model = gda_data_model_import_new_file (file, TRUE, options);
+		g_free (file);
+	}
+
+	if (options)
+		g_object_unref (options);
+
+	if (import->priv->model) {
+		GObject *raw;
+		GObject *info;
+
+		gtk_widget_hide (import->priv->no_data_label);
+		import->priv->preview_grid = gdaui_grid_new (import->priv->model);
+
+		g_object_get (G_OBJECT (import->priv->preview_grid), "raw-grid", &raw, 
+			      "widget-info", &info, NULL);
+		g_object_set (raw, "info-cell-visible", FALSE, NULL);
+		gdaui_raw_grid_set_sample_size (GDAUI_RAW_GRID (raw), 50);
+		g_object_set (info, "flags", 
+			      GDAUI_DATA_WIDGET_INFO_CHUNCK_CHANGE_BUTTONS | 
+			      GDAUI_DATA_WIDGET_INFO_CURRENT_ROW, NULL);
+		g_object_unref (info);
+
+		gtk_box_pack_start (GTK_BOX (import->priv->preview_box), import->priv->preview_grid, TRUE, TRUE, 0);
+		gtk_widget_show (import->priv->preview_grid);
+	}
+	else 
+		gtk_widget_show (import->priv->no_data_label);
+}
+
+/**
+ * gdaui_data_import_get_model
+ * @import: a #GdauiDataImport widget
+ *
+ * Get the current imported data model. The caller has to reference it if needed.
+ *
+ * Returns: the #GdaDataModel, or %NULL
+ */
+GdaDataModel *
+gdaui_data_import_get_model (GdauiDataImport *import)
+{
+	g_return_val_if_fail (GDAUI_IS_DATA_IMPORT (import), NULL);
+	return import->priv->model;
+}
diff --git a/tools/browser/common/gdaui-data-import.h b/tools/browser/common/gdaui-data-import.h
new file mode 100644
index 0000000..ce5b80d
--- /dev/null
+++ b/tools/browser/common/gdaui-data-import.h
@@ -0,0 +1,66 @@
+/* gdaui-data-import.h
+ *
+ * Copyright (C) 2006 - 2009 Vivien Malerba
+ *
+ * This Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef __GDAUI_DATA_IMPORT__
+#define __GDAUI_DATA_IMPORT__
+
+#include <gtk/gtk.h>
+#include <libgda/libgda.h>
+
+G_BEGIN_DECLS
+
+#define GDAUI_TYPE_DATA_IMPORT          (gdaui_data_import_get_type())
+#define GDAUI_DATA_IMPORT(obj)          G_TYPE_CHECK_INSTANCE_CAST (obj, gdaui_data_import_get_type(), GdauiDataImport)
+#define GDAUI_DATA_IMPORT_CLASS(klass)  G_TYPE_CHECK_CLASS_CAST (klass, gdaui_data_import_get_type (), GdauiDataImportClass)
+#define GDAUI_IS_DATA_IMPORT(obj)       G_TYPE_CHECK_INSTANCE_TYPE (obj, gdaui_data_import_get_type ())
+
+
+typedef struct _GdauiDataImport      GdauiDataImport;
+typedef struct _GdauiDataImportClass GdauiDataImportClass;
+typedef struct _GdauiDataImportPriv  GdauiDataImportPriv;
+
+/* struct for the object's data */
+struct _GdauiDataImport
+{
+	GtkVPaned              object;
+
+	GdauiDataImportPriv *priv;
+};
+
+/* struct for the object's class */
+struct _GdauiDataImportClass
+{
+	GtkVPanedClass         parent_class;
+};
+
+/* 
+ * Generic widget's methods 
+*/
+GType         gdaui_data_import_get_type     (void) G_GNUC_CONST; 
+GtkWidget    *gdaui_data_import_new          (void);
+GdaDataModel *gdaui_data_import_get_model    (GdauiDataImport *import);
+
+
+G_END_DECLS
+
+#endif
+
+
+
diff --git a/tools/browser/common/gdaui-entry-import.c b/tools/browser/common/gdaui-entry-import.c
new file mode 100644
index 0000000..aeae819
--- /dev/null
+++ b/tools/browser/common/gdaui-entry-import.c
@@ -0,0 +1,299 @@
+/* gdaui-entry-import.c
+ *
+ * Copyright (C) 2009 Vivien Malerba
+ *
+ * This Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include "gdaui-entry-import.h"
+#include <libgda/gda-data-handler.h>
+#include <glib/gi18n-lib.h>
+#include "gdaui-data-import.h"
+
+/* 
+ * Main static functions 
+ */
+static void gdaui_entry_import_class_init (GdauiEntryImportClass * class);
+static void gdaui_entry_import_init (GdauiEntryImport * srv);
+static void gdaui_entry_import_dispose (GObject   * object);
+static void gdaui_entry_import_finalize (GObject   * object);
+
+/* virtual functions */
+static GtkWidget *create_entry (GdauiEntryWrapper *mgwrap);
+static void       real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value);
+static GValue    *real_get_value (GdauiEntryWrapper *mgwrap);
+static void       connect_signals(GdauiEntryWrapper *mgwrap, GCallback modify_cb, GCallback activate_cb);
+static gboolean   expand_in_layout (GdauiEntryWrapper *mgwrap);
+
+/* get a pointer to the parents to be able to call their destructor */
+static GObjectClass  *parent_class = NULL;
+
+/* private structure */
+struct _GdauiEntryImportPrivate
+{
+	GtkWidget     *button;
+	GdaDataModel  *model;
+	GtkLabel      *label;
+	GCallback      modify_cb;
+};
+
+
+GType
+gdaui_entry_import_get_type (void)
+{
+	static GType type = 0;
+
+	if (G_UNLIKELY (type == 0)) {
+		static const GTypeInfo info = {
+			sizeof (GdauiEntryImportClass),
+			(GBaseInitFunc) NULL,
+			(GBaseFinalizeFunc) NULL,
+			(GClassInitFunc) gdaui_entry_import_class_init,
+			NULL,
+			NULL,
+			sizeof (GdauiEntryImport),
+			0,
+			(GInstanceInitFunc) gdaui_entry_import_init
+		};
+		
+		type = g_type_register_static (GDAUI_TYPE_ENTRY_WRAPPER, "GdauiEntryImport", &info, 0);
+	}
+	return type;
+}
+
+static void
+gdaui_entry_import_class_init (GdauiEntryImportClass * class)
+{
+	GObjectClass   *object_class = G_OBJECT_CLASS (class);
+
+	parent_class = g_type_class_peek_parent (class);
+
+	object_class->dispose = gdaui_entry_import_dispose;
+	object_class->finalize = gdaui_entry_import_finalize;
+
+	GDAUI_ENTRY_WRAPPER_CLASS (class)->create_entry = create_entry;
+	GDAUI_ENTRY_WRAPPER_CLASS (class)->real_set_value = real_set_value;
+	GDAUI_ENTRY_WRAPPER_CLASS (class)->real_get_value = real_get_value;
+	GDAUI_ENTRY_WRAPPER_CLASS (class)->connect_signals = connect_signals;
+	GDAUI_ENTRY_WRAPPER_CLASS (class)->expand_in_layout = expand_in_layout;
+}
+
+static void
+gdaui_entry_import_init (GdauiEntryImport * gdaui_entry_import)
+{
+	gdaui_entry_import->priv = g_new0 (GdauiEntryImportPrivate, 1);
+	gdaui_entry_import->priv->button = NULL;
+	gdaui_entry_import->priv->model = NULL;
+}
+
+/**
+ * gdaui_entry_import_new
+ * @type: the requested data type (compatible with @dh)
+ *
+ * Creates a new widget which is mainly a GtkEntry
+ *
+ * Returns: the new widget
+ */
+GtkWidget *
+gdaui_entry_import_new (GType type)
+{
+	GObject *obj;
+	GdauiEntryImport *mgtxt;
+
+	g_return_val_if_fail (type == GDA_TYPE_DATA_MODEL, NULL);
+
+	obj = g_object_new (GDAUI_TYPE_ENTRY_IMPORT, NULL);
+	mgtxt = GDAUI_ENTRY_IMPORT (obj);
+	gdaui_data_entry_set_value_type (GDAUI_DATA_ENTRY (mgtxt), type);
+
+	return GTK_WIDGET (obj);
+}
+
+
+static void
+gdaui_entry_import_dispose (GObject   * object)
+{
+	GdauiEntryImport *gdaui_entry_import;
+
+	g_return_if_fail (object != NULL);
+	g_return_if_fail (GDAUI_IS_ENTRY_IMPORT (object));
+
+	gdaui_entry_import = GDAUI_ENTRY_IMPORT (object);
+	if (gdaui_entry_import->priv) {
+		if (gdaui_entry_import->priv->model) {
+			g_object_unref (gdaui_entry_import->priv->model);
+			gdaui_entry_import->priv->model = NULL;
+		}
+	}
+
+	/* parent class */
+	parent_class->dispose (object);
+}
+
+static void
+gdaui_entry_import_finalize (GObject   * object)
+{
+	GdauiEntryImport *gdaui_entry_import;
+
+	g_return_if_fail (object != NULL);
+	g_return_if_fail (GDAUI_IS_ENTRY_IMPORT (object));
+
+	gdaui_entry_import = GDAUI_ENTRY_IMPORT (object);
+	if (gdaui_entry_import->priv) {
+
+		g_free (gdaui_entry_import->priv);
+		gdaui_entry_import->priv = NULL;
+	}
+
+	/* parent class */
+	parent_class->finalize (object);
+}
+
+typedef void (*Callback2) (gpointer, gpointer);
+
+static void
+open_button_clicked_cb (GtkWidget *button, GdauiEntryImport *mgtxt)
+{
+	GtkWidget *dialog, *wid;
+	gint res;
+	dialog = gtk_dialog_new_with_buttons (_("Data set import from file"),
+					      (GtkWindow*) gtk_widget_get_toplevel (button),
+					      GTK_DIALOG_MODAL,
+					      GTK_STOCK_OK,
+					      GTK_RESPONSE_ACCEPT,
+					      GTK_STOCK_CANCEL,
+					      GTK_RESPONSE_REJECT,
+					      NULL);
+	wid = gdaui_data_import_new ();
+	gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), wid);
+	gtk_widget_show_all (dialog);
+	
+	res = gtk_dialog_run (GTK_DIALOG (dialog));
+	gtk_widget_hide (dialog);
+	if (res == GTK_RESPONSE_ACCEPT) {
+		if (mgtxt->priv->model)
+			g_object_unref (mgtxt->priv->model);
+		mgtxt->priv->model = gdaui_data_import_get_model (GDAUI_DATA_IMPORT (wid));
+		if (mgtxt->priv->model) {
+			g_object_ref (mgtxt->priv->model);
+
+			gchar *str;
+			gint n, c;
+			gchar *tmp1, *tmp2;
+			n = gda_data_model_get_n_rows (GDA_DATA_MODEL (mgtxt->priv->model));
+			c = gda_data_model_get_n_columns (GDA_DATA_MODEL (mgtxt->priv->model));
+			tmp1 = g_strdup_printf (ngettext ("%d row", "%d rows", n), n);
+			tmp2 = g_strdup_printf (ngettext ("%d column", "%d columns", c), c);
+			str = g_strdup_printf (_("Data set with %s and %s"), tmp1, tmp2);
+			g_free (tmp1);
+			g_free (tmp2);
+			gtk_label_set_text (mgtxt->priv->label, str);
+			g_free (str);
+		}
+		else
+			gtk_label_set_text (mgtxt->priv->label, _("No data set"));
+		
+
+		/* send notofocations */
+		if (mgtxt->priv->modify_cb)
+			((Callback2)mgtxt->priv->modify_cb) (NULL, mgtxt);
+	}
+	gtk_widget_destroy (dialog);
+}
+
+static GtkWidget *
+create_entry (GdauiEntryWrapper *mgwrap)
+{
+	GdauiEntryImport *mgtxt;
+	GtkWidget *hbox;
+	gfloat ya;
+
+	g_return_val_if_fail (mgwrap && GDAUI_IS_ENTRY_IMPORT (mgwrap), NULL);
+	mgtxt = GDAUI_ENTRY_IMPORT (mgwrap);
+	g_return_val_if_fail (mgtxt->priv, NULL);
+
+	hbox = gtk_hbox_new (FALSE, 0);
+
+	mgtxt->priv->label = GTK_LABEL (gtk_label_new (_("No data set")));
+	gtk_misc_get_alignment (GTK_MISC (mgtxt->priv->label), NULL, &ya);
+	gtk_misc_set_alignment (GTK_MISC (mgtxt->priv->label), 0., ya);
+	gtk_widget_show ((GtkWidget*) mgtxt->priv->label);
+	gtk_box_pack_start (GTK_BOX (hbox), (GtkWidget*) mgtxt->priv->label, TRUE, TRUE, 0);
+
+	mgtxt->priv->button = gtk_button_new_from_stock (GTK_STOCK_OPEN);
+	g_signal_connect (mgtxt->priv->button, "clicked",
+			  G_CALLBACK (open_button_clicked_cb), mgtxt);
+	gtk_widget_show (mgtxt->priv->button);
+	gtk_box_pack_start (GTK_BOX (hbox), mgtxt->priv->button, FALSE, FALSE, 0);
+
+	return hbox;
+}
+
+static void
+real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value)
+{
+	GdauiEntryImport *mgtxt;
+
+	g_return_if_fail (mgwrap && GDAUI_IS_ENTRY_IMPORT (mgwrap));
+	mgtxt = GDAUI_ENTRY_IMPORT (mgwrap);
+	g_return_if_fail (mgtxt->priv);
+
+	if (mgtxt->priv->model) {
+		g_object_unref (mgtxt->priv->model);
+		mgtxt->priv->model = NULL;
+	}
+
+	if (value) {
+		if (! gda_value_is_null ((GValue *) value))
+			mgtxt->priv->model = g_value_dup_object (value);
+	}
+}
+
+static GValue *
+real_get_value (GdauiEntryWrapper *mgwrap)
+{
+	GdauiEntryImport *mgtxt;
+
+	g_return_val_if_fail (GDAUI_IS_ENTRY_IMPORT (mgwrap), NULL);
+	mgtxt = GDAUI_ENTRY_IMPORT (mgwrap);
+
+	if (mgtxt->priv->model) {
+		GValue *value;
+		value = gda_value_new (GDA_TYPE_DATA_MODEL);
+		g_value_set_object (value, mgtxt->priv->model);
+		return value;
+	}
+	else
+		return gda_value_new_null ();
+}
+
+static void
+connect_signals(GdauiEntryWrapper *mgwrap, GCallback modify_cb, GCallback activate_cb)
+{
+	GdauiEntryImport *mgtxt;
+
+	g_return_if_fail (mgwrap && GDAUI_IS_ENTRY_IMPORT (mgwrap));
+	mgtxt = GDAUI_ENTRY_IMPORT (mgwrap);
+	g_return_if_fail (mgtxt->priv);
+
+	mgtxt->priv->modify_cb = modify_cb;
+}
+
+static gboolean
+expand_in_layout (GdauiEntryWrapper *mgwrap)
+{
+	return FALSE;
+}
diff --git a/tools/browser/common/gdaui-entry-import.h b/tools/browser/common/gdaui-entry-import.h
new file mode 100644
index 0000000..afb004e
--- /dev/null
+++ b/tools/browser/common/gdaui-entry-import.h
@@ -0,0 +1,59 @@
+/* gdaui-entry-import.h
+ *
+ * Copyright (C) 2003 - 2006 Vivien Malerba
+ *
+ * This Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+
+#ifndef __GDAUI_ENTRY_IMPORT_H_
+#define __GDAUI_ENTRY_IMPORT_H_
+
+#include <libgda-ui/data-entries/gdaui-entry-wrapper.h>
+
+G_BEGIN_DECLS
+
+#define GDAUI_TYPE_ENTRY_IMPORT          (gdaui_entry_import_get_type())
+#define GDAUI_ENTRY_IMPORT(obj)          G_TYPE_CHECK_INSTANCE_CAST (obj, gdaui_entry_import_get_type(), GdauiEntryImport)
+#define GDAUI_ENTRY_IMPORT_CLASS(klass)  G_TYPE_CHECK_CLASS_CAST (klass, gdaui_entry_import_get_type (), GdauiEntryImportClass)
+#define GDAUI_IS_ENTRY_IMPORT(obj)       G_TYPE_CHECK_INSTANCE_TYPE (obj, gdaui_entry_import_get_type ())
+
+
+typedef struct _GdauiEntryImport GdauiEntryImport;
+typedef struct _GdauiEntryImportClass GdauiEntryImportClass;
+typedef struct _GdauiEntryImportPrivate GdauiEntryImportPrivate;
+
+
+/* struct for the object's data */
+struct _GdauiEntryImport
+{
+	GdauiEntryWrapper              object;
+	GdauiEntryImportPrivate         *priv;
+};
+
+/* struct for the object's class */
+struct _GdauiEntryImportClass
+{
+	GdauiEntryWrapperClass         parent_class;
+};
+
+GType        gdaui_entry_import_get_type        (void) G_GNUC_CONST;
+GtkWidget   *gdaui_entry_import_new             (GType type);
+
+
+G_END_DECLS
+
+#endif
diff --git a/tools/browser/common/import_encodings.xml b/tools/browser/common/import_encodings.xml
new file mode 100644
index 0000000..fb064d7
--- /dev/null
+++ b/tools/browser/common/import_encodings.xml
@@ -0,0 +1,315 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gda_array name="iconv_enc">
+  <gda_array_field name="id" gdatype="gchararray"/>
+  <gda_array_data>
+    <gda_array_row>
+      <gda_value></gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>US-ASCII</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UTF-8</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UCS-2</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UCS-2BE</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UCS-2LE</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UCS-4</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UCS-4BE</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UCS-4LE</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UTF-16</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UTF-16BE</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UTF-16LE</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UTF-32</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UTF-32BE</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UTF-32LE</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UTF-7</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UCS-2-INTERNAL</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UCS-2-SWAPPED</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UCS-4-INTERNAL</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>UCS-4-SWAPPED</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>C99</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>JAVA</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-1</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-2</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-3</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-4</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-5</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-6</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-7</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-8</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-9</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-10</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-13</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-14</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-15</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-8859-16</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>KOI8-R</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>KOI8-U</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>KOI8-RU</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP1250</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP1251</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP1252</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP1253</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP1254</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP1255</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP1256</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP1257</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP1258</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP850</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP862</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP866</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MacRoman</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MacCentralEurope</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MacIceland</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MacCroatian</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MacRomania</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MacCyrillic</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MacUkraine</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MacGreek</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MacTurkish</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MacHebrew</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MacArabic</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MacThai</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>HP-ROMAN8</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>NEXTSTEP</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ARMSCII-8</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>GEORGIAN-ACADEMY</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>GEORGIAN-PS</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>KOI8-T</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>MULELAO-1</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP1133</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>TIS-620</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP874</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>VISCII</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>TCVN</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>JIS_C6220-1969-RO</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>JIS_X0201</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>JIS_X0208</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>JIS_X0212</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>GB_1988-80</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>GB_2312-80</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-IR-165</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>KSC_5601</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>EUC-JP</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>SHIFT_JIS</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP932</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-2022-JP</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-2022-JP-1</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-2022-JP-2</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>EUC-CN</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>GBK</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>GB18030</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-2022-CN</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-2022-CN-EXT</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>HZ</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>EUC-TW</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>BIG5</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP950</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>BIG5-HKSCS</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>EUC-KR</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>CP949</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>JOHAB</gda_value>
+    </gda_array_row>
+    <gda_array_row>
+      <gda_value>ISO-2022-KR</gda_value>
+    </gda_array_row>
+  </gda_array_data>
+</gda_array>
diff --git a/tools/browser/connection-binding-properties.c b/tools/browser/connection-binding-properties.c
index b0681e5..368f93a 100644
--- a/tools/browser/connection-binding-properties.c
+++ b/tools/browser/connection-binding-properties.c
@@ -23,6 +23,8 @@
 #include "browser-connection.h"
 #include "support.h"
 #include <libgda-ui/libgda-ui.h>
+#include <libgda-ui/gdaui-plugin.h>
+#include "common/gdaui-entry-import.h"
 
 /* 
  * Main static functions 
@@ -346,11 +348,57 @@ del_part_clicked_cb (GtkWidget *button, BrowserVirtualConnectionPart *part)
 	update_display (cprop);
 }
 
+static void
+part_for_model_holder_changed_cb (GdaSet *set, GdaHolder *holder, BrowserVirtualConnectionModel *pm)
+{
+	const gchar *hid;
+	const GValue *value;
+
+	hid = gda_holder_get_id (holder);
+	g_assert (hid);
+	value = gda_holder_get_value (holder);
+
+	if (!strcmp (hid, "NAME")) {
+		g_free (pm->table_name);
+		pm->table_name = g_value_dup_string (value);
+	}
+	else if (!strcmp (hid, "DATASET")) {
+		if (pm->model)
+			g_object_unref (pm->model);
+		pm->model = (GdaDataModel*) g_value_get_object (value);
+		if (pm->model)
+			g_object_ref (pm->model);
+	}
+	else
+		g_assert_not_reached ();
+
+	ConnectionBindingProperties *cprop;
+	cprop = g_object_get_data (G_OBJECT (set), "cprop");
+	update_buttons_sensitiveness (cprop);
+}
+
+static GdauiDataEntry *
+plugin_entry_import_create_func (GdaDataHandler *handler, GType type, const gchar *options)
+{
+	return GDAUI_DATA_ENTRY (gdaui_entry_import_new (type));
+}
+
 static GtkWidget *
 create_part_for_model (ConnectionBindingProperties *cprop, BrowserVirtualConnectionModel *pm)
 {
 	GtkWidget *vbox, *label;
 	gchar *str;
+	static gboolean plugin_added = FALSE;
+
+	if (!plugin_added) {
+		GdauiPlugin plugin = {"data-model-import", NULL, NULL, 1, NULL, NULL,
+				      plugin_entry_import_create_func, NULL};
+		plugin.valid_g_types = g_new (GType, 1);
+		plugin.valid_g_types[0] = GDA_TYPE_DATA_MODEL;
+		gdaui_plugin_declare (&plugin);
+		g_free (plugin.valid_g_types);
+		plugin_added = TRUE;
+	}
 
 	vbox = gtk_vbox_new (FALSE, 0);
 	label = gtk_label_new ("");
@@ -363,21 +411,26 @@ create_part_for_model (ConnectionBindingProperties *cprop, BrowserVirtualConnect
 	GdaSet *set;
 	GdaHolder *holder;
 	GtkWidget *form;
-	set = gda_set_new_inline (2,
-				  "SCHEMA", G_TYPE_STRING, pm->table_schema,
+	GValue *value;
+	set = gda_set_new_inline (1,
 				  "NAME", G_TYPE_STRING, pm->table_name);
 
-	holder = gda_holder_new (G_TYPE_POINTER);
+	holder = gda_holder_new (GDA_TYPE_DATA_MODEL);
 	g_object_set (holder, "id", "DATASET", "name", "Data set", NULL);
+	value = gda_value_new_from_string ("data-model-import", G_TYPE_STRING);
+	gda_holder_set_attribute_static (holder, GDAUI_ATTRIBUTE_PLUGIN, value);
+	gda_value_free (value);
 	g_assert (gda_set_add_holder (set, holder));
 	g_object_unref (holder);
 
-	g_object_set (gda_set_get_holder (set, "SCHEMA"), "name", "Table's schema", NULL);
 	g_object_set (gda_set_get_holder (set, "NAME"), "name", "Table's name", NULL);
 							  
 	form = gdaui_basic_form_new (set);
 	g_object_unref (set);
 	gtk_box_pack_start (GTK_BOX (vbox), form, TRUE, TRUE, 0);
+	g_object_set_data (G_OBJECT (set), "cprop", cprop);
+	g_signal_connect (set, "holder-changed",
+			  G_CALLBACK (part_for_model_holder_changed_cb), pm);
 
 	return vbox;
 }
@@ -503,6 +556,16 @@ update_buttons_sensitiveness (ConnectionBindingProperties *cprop)
 		BrowserVirtualConnectionPart *part;
 		part = (BrowserVirtualConnectionPart*) list->data;
 		switch (part->part_type) {
+		case BROWSER_VIRTUAL_CONNECTION_PART_MODEL: {
+			BrowserVirtualConnectionModel *pm;
+			pm = &(part->u.model);
+			if (!pm->table_name || ! *pm->table_name || !pm->model)
+				goto out;
+			if (g_hash_table_lookup (schemas_hash, pm->table_name))
+				goto out;
+			g_hash_table_insert (schemas_hash, pm->table_name, (gpointer) 0x01);
+			break;
+		}
 		case BROWSER_VIRTUAL_CONNECTION_PART_CNC: {
 			BrowserVirtualConnectionCnc *cnc;
 			cnc = &(part->u.cnc);
@@ -514,15 +577,11 @@ update_buttons_sensitiveness (ConnectionBindingProperties *cprop)
 			g_hash_table_insert (schemas_hash, cnc->table_schema, (gpointer) 0x01);
 			break;
 		}
-		case BROWSER_VIRTUAL_CONNECTION_PART_MODEL:
-			TO_IMPLEMENT;
-			goto out;
-			break;
 		}
 	}
-
+	
 	allok = TRUE;
-
+	
  out:
 	g_hash_table_destroy (schemas_hash);
 	gtk_dialog_set_response_sensitive (GTK_DIALOG (cprop), GTK_RESPONSE_OK, allok);
@@ -538,6 +597,6 @@ const BrowserVirtualConnectionSpecs *
 connection_binding_properties_get_specs (ConnectionBindingProperties *prop)
 {
 	g_return_val_if_fail (CONNECTION_IS_BINDING_PROPERTIES (prop), NULL);
-
+	
 	return prop->priv->specs;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]