[libgda/LIBGDA_4.2] GdaBrowser: data manager perspective corrections
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/LIBGDA_4.2] GdaBrowser: data manager perspective corrections
- Date: Mon, 20 Jun 2011 19:00:54 +0000 (UTC)
commit 3b027c6697c752ef8c66f4526fb63a472c18de1d
Author: Vivien Malerba <malerba gnome-db org>
Date: Fri Jun 17 21:03:44 2011 +0200
GdaBrowser: data manager perspective corrections
tools/browser/common/ui-formgrid.c | 35 +++++-
tools/browser/common/ui-formgrid.h | 2 +
tools/browser/data-manager/data-source.c | 56 +---------
tools/browser/data-manager/data-widget.c | 176 ++++++++++++++++++++++--------
4 files changed, 165 insertions(+), 104 deletions(-)
---
diff --git a/tools/browser/common/ui-formgrid.c b/tools/browser/common/ui-formgrid.c
index a902595..0155d8d 100644
--- a/tools/browser/common/ui-formgrid.c
+++ b/tools/browser/common/ui-formgrid.c
@@ -64,6 +64,14 @@ struct _UiFormGridPriv
/* get a pointer to the parents to be able to call their destructor */
static GObjectClass *parent_class = NULL;
+/* signals */
+enum {
+ DATA_SET_CHANGED,
+ LAST_SIGNAL
+};
+
+gint ui_formgrid_signals [LAST_SIGNAL] = { 0 };
+
/* properties */
enum {
PROP_0,
@@ -99,13 +107,23 @@ ui_formgrid_get_type (void)
}
static void
-ui_formgrid_class_init (UiFormGridClass *class)
+ui_formgrid_class_init (UiFormGridClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_peek_parent (class);
+ parent_class = g_type_class_peek_parent (klass);
object_class->dispose = ui_formgrid_dispose;
- GTK_WIDGET_CLASS (class)->show = ui_formgrid_show;
+ GTK_WIDGET_CLASS (klass)->show = ui_formgrid_show;
+
+ /* signals */
+ ui_formgrid_signals [DATA_SET_CHANGED] =
+ g_signal_new ("data-set-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (UiFormGridClass, data_set_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+ klass->data_set_changed = NULL;
/* Properties */
object_class->set_property = ui_formgrid_set_property;
@@ -662,6 +680,12 @@ static void ldap_view_dn_mitem_cb (GtkMenuItem *menuitem, UiFormGrid *formgrid)
}
#endif
+static void
+proxy_changed_cb (GdauiDataProxy *dp, GdaDataProxy *proxy, UiFormGrid *formgrid)
+{
+ g_signal_emit (formgrid, ui_formgrid_signals [DATA_SET_CHANGED], 0);
+}
+
/**
* ui_formgrid_new
* @model: a #GdaDataModel
@@ -693,6 +717,9 @@ ui_formgrid_new (GdaDataModel *model, gboolean scroll_form, GdauiDataProxyInfoFl
"flags", formgrid->priv->flags | GDAUI_DATA_PROXY_INFO_CURRENT_ROW |
GDAUI_DATA_PROXY_INFO_CHUNCK_CHANGE_BUTTONS, NULL);
+ g_signal_connect (formgrid->priv->raw_grid, "proxy-changed",
+ G_CALLBACK (proxy_changed_cb), formgrid);
+
/* no more than 300 rows at a time */
if (model)
gda_data_proxy_set_sample_size (proxy, 300);
diff --git a/tools/browser/common/ui-formgrid.h b/tools/browser/common/ui-formgrid.h
index 85493a5..7cf8a9e 100644
--- a/tools/browser/common/ui-formgrid.h
+++ b/tools/browser/common/ui-formgrid.h
@@ -49,6 +49,8 @@ struct _UiFormGrid
struct _UiFormGridClass
{
GtkVBoxClass parent_class;
+ /* signals */
+ void (*data_set_changed) (UiFormGrid *fg);
};
/*
diff --git a/tools/browser/data-manager/data-source.c b/tools/browser/data-manager/data-source.c
index d72ba5f..e7d2cc9 100644
--- a/tools/browser/data-manager/data-source.c
+++ b/tools/browser/data-manager/data-source.c
@@ -988,22 +988,6 @@ data_source_execute (DataSource *source, GError **error)
source->priv->executing = FALSE;
}
-/*
- * creates a new string where double underscores '__' are replaced by a single underscore '_'
- */
-static gchar *
-replace_double_underscores (const gchar *str)
-{
- gchar **arr;
- gchar *ret;
-
- arr = g_strsplit (str, "__", 0);
- ret = g_strjoinv ("_", arr);
- g_strfreev (arr);
-
- return ret;
-}
-
/**
* data_source_create_grid
*
@@ -1018,46 +1002,8 @@ data_source_create_grid (DataSource *source)
return NULL;
GtkWidget *fg;
- GdauiRawGrid *grid;
fg = ui_formgrid_new (source->priv->model, FALSE, 0);
- grid = ui_formgrid_get_grid_widget (UI_FORMGRID (fg));
-
- GList *columns, *list;
- columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (grid));
- for (list = columns; list; list = list->next) {
- /* reduce column's title */
- const gchar *title;
- GtkWidget *header;
- title = gtk_tree_view_column_get_title (GTK_TREE_VIEW_COLUMN (list->data));
- header = gtk_label_new ("");
- if (title) {
- gchar *tmp, *str;
- str = replace_double_underscores (title);
- tmp = g_markup_printf_escaped ("<small>%s</small>", str);
- g_free (str);
- gtk_label_set_markup (GTK_LABEL (header), tmp);
- g_free (tmp);
- }
- else
- gtk_label_set_markup (GTK_LABEL (header), "<small></small>");
- gtk_widget_show (header);
- gtk_tree_view_column_set_widget (GTK_TREE_VIEW_COLUMN (list->data),
- header);
-
- /* reduce text's size */
- GList *renderers, *list2;
- renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (list->data));
- for (list2 = renderers; list2; list2 = list2->next) {
- if (GTK_IS_CELL_RENDERER_TEXT (list2->data))
- g_object_set ((GObject*) list2->data,
- "scale", 0.8, NULL);
- }
- g_list_free (renderers);
- }
-
- /*if (!columns || !columns->next)*/
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (grid), FALSE);
- g_list_free (columns);
+
return fg;
}
diff --git a/tools/browser/data-manager/data-widget.c b/tools/browser/data-manager/data-widget.c
index cfdc117..fcd1920 100644
--- a/tools/browser/data-manager/data-widget.c
+++ b/tools/browser/data-manager/data-widget.c
@@ -645,11 +645,72 @@ source_exec_started_cb (G_GNUC_UNUSED DataSource *source, DataPart *part)
part);
}
+/*
+ * creates a new string where double underscores '__' are replaced by a single underscore '_'
+ */
+static gchar *
+replace_double_underscores (const gchar *str)
+{
+ gchar **arr;
+ gchar *ret;
+
+ arr = g_strsplit (str, "__", 0);
+ ret = g_strjoinv ("_", arr);
+ g_strfreev (arr);
+
+ return ret;
+}
+
+static void
+customize_form_grid (UiFormGrid *cwid)
+{
+ GdauiRawGrid *grid;
+ grid = ui_formgrid_get_grid_widget (UI_FORMGRID (cwid));
+
+ GList *columns, *list;
+ columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (grid));
+ for (list = columns; list; list = list->next) {
+ /* reduce column's title */
+ const gchar *title;
+ GtkWidget *header;
+ title = gtk_tree_view_column_get_title (GTK_TREE_VIEW_COLUMN (list->data));
+ header = gtk_label_new ("");
+ if (title) {
+ gchar *tmp, *str;
+ str = replace_double_underscores (title);
+ tmp = g_markup_printf_escaped ("<small>%s</small>", str);
+ g_free (str);
+ gtk_label_set_markup (GTK_LABEL (header), tmp);
+ g_free (tmp);
+ }
+ else
+ gtk_label_set_markup (GTK_LABEL (header), "<small></small>");
+ gtk_widget_show (header);
+ gtk_tree_view_column_set_widget (GTK_TREE_VIEW_COLUMN (list->data),
+ header);
+
+ /* reduce text's size */
+ GList *renderers, *list2;
+ renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (list->data));
+ for (list2 = renderers; list2; list2 = list2->next) {
+ if (GTK_IS_CELL_RENDERER_TEXT (list2->data))
+ g_object_set ((GObject*) list2->data,
+ "scale", 0.8, NULL);
+ }
+ g_list_free (renderers);
+ }
+
+ /*if (!columns || !columns->next)*/
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (grid), FALSE);
+ g_list_free (columns);
+}
+
+
+static void formgrid_data_set_changed_cb (UiFormGrid *cwid, DataPart *part);
static void data_part_selection_changed_cb (GdauiDataSelector *gdauidataselector, DataPart *part);
static void
source_exec_finished_cb (G_GNUC_UNUSED DataSource *source, GError *error, DataPart *part)
{
- GtkWidget *wid;
if (part->spinner_show_timer_id) {
g_source_remove (part->spinner_show_timer_id);
part->spinner_show_timer_id = 0;
@@ -666,76 +727,101 @@ source_exec_finished_cb (G_GNUC_UNUSED DataSource *source, GError *error, DataPa
}
if (! part->data_widget) {
- GtkWidget *cwid;
+ GtkWidget *cwid, *wid;
BrowserConnection *bcnc;
bcnc = browser_window_get_connection ((BrowserWindow*) gtk_widget_get_toplevel ((GtkWidget*) part->dwid));
cwid = (GtkWidget*) data_source_create_grid (part->source);
ui_formgrid_handle_user_prefs (UI_FORMGRID (cwid), bcnc,
data_source_get_statement (part->source));
+ g_signal_connect (cwid, "data-set-changed",
+ G_CALLBACK (formgrid_data_set_changed_cb), part);
wid = (GtkWidget*) ui_formgrid_get_grid_widget (UI_FORMGRID (cwid));
part->data_widget = wid;
part->data_widget_page = gtk_notebook_append_page (part->nb, cwid, NULL);
+ g_signal_connect (part->data_widget, "selection-changed",
+ G_CALLBACK (data_part_selection_changed_cb), part);
gtk_widget_show (cwid);
+
#ifdef GDA_DEBUG_NO
g_print ("Creating data widget for source [%s]\n",
data_source_get_title (part->source));
#endif
/* compute part->export_data */
- GArray *export_names;
- export_names = data_source_get_export_names (part->source);
- if (export_names && (export_names->len > 0)) {
- GSList *holders = NULL;
- GdaDataModel *model;
- GHashTable *export_columns;
- gsize i;
- GdaDataModelIter *iter;
-
- iter = gdaui_data_selector_get_data_set (GDAUI_DATA_SELECTOR (wid));
- g_object_get (wid, "model", &model, NULL);
-
- export_columns = data_source_get_export_columns (part->source);
- for (i = 0; i < export_names->len; i++) {
- gint col;
- GdaHolder *bindto;
- col = GPOINTER_TO_INT (g_hash_table_lookup (export_columns,
- g_array_index (export_names,
- gchar*, i))) - 1;
- bindto = gda_data_model_iter_get_holder_for_field (iter, col);
- if (bindto) {
- GdaHolder *holder;
- holder = gda_holder_copy (bindto);
- g_object_set ((GObject*) holder, "id",
- g_array_index (export_names, gchar*, i), NULL);
- holders = g_slist_prepend (holders, holder);
+ formgrid_data_set_changed_cb (cwid, part);
+ }
+ else {
+ GError *lerror = NULL;
+ if (! compute_sources_dependencies (part, &lerror)) {
+ data_part_show_error (part, lerror);
+ g_clear_error (&lerror);
+ }
+ }
+ gtk_notebook_set_current_page (part->nb, part->data_widget_page);
+}
+
+static void
+formgrid_data_set_changed_cb (UiFormGrid *cwid, DataPart *part)
+{
+ GtkWidget *wid;
+ GArray *export_names;
+
+ customize_form_grid (cwid);
+ wid = (GtkWidget*) ui_formgrid_get_grid_widget (UI_FORMGRID (cwid));
+
+ if (part->export_data) {
+ g_object_unref (part->export_data);
+ part->export_data = NULL;
+ }
+
+ export_names = data_source_get_export_names (part->source);
+ if (export_names && (export_names->len > 0)) {
+ GSList *holders = NULL;
+ GdaDataModel *model;
+ GHashTable *export_columns;
+ gsize i;
+ GdaDataModelIter *iter;
+
+ iter = gdaui_data_selector_get_data_set (GDAUI_DATA_SELECTOR (wid));
+ g_object_get (wid, "model", &model, NULL);
+
+ export_columns = data_source_get_export_columns (part->source);
+ for (i = 0; i < export_names->len; i++) {
+ gint col;
+ GdaHolder *bindto;
+ col = GPOINTER_TO_INT (g_hash_table_lookup (export_columns,
+ g_array_index (export_names,
+ gchar*, i))) - 1;
+ bindto = gda_data_model_iter_get_holder_for_field (iter, col);
+ if (bindto) {
+ GdaHolder *holder;
+ holder = gda_holder_copy (bindto);
+ g_object_set ((GObject*) holder, "id",
+ g_array_index (export_names, gchar*, i), NULL);
+ holders = g_slist_prepend (holders, holder);
#ifdef DEBUG_NO
- g_print ("HOLDER [%s::%s]\n",
- gda_holder_get_id (holder),
- g_type_name (gda_holder_get_g_type (holder)));
+ g_print ("HOLDER [%s::%s]\n",
+ gda_holder_get_id (holder),
+ g_type_name (gda_holder_get_g_type (holder)));
#endif
- g_assert (gda_holder_set_bind (holder, bindto, NULL));
- }
- }
-
- g_object_unref (model);
- if (holders) {
- part->export_data = gda_set_new (holders);
- g_slist_foreach (holders, (GFunc) g_object_unref, NULL);
- g_slist_free (holders);
-
- g_signal_connect (wid, "selection-changed",
- G_CALLBACK (data_part_selection_changed_cb), part);
+ g_assert (gda_holder_set_bind (holder, bindto, NULL));
}
}
+
+ g_object_unref (model);
+ if (holders) {
+ part->export_data = gda_set_new (holders);
+ g_slist_foreach (holders, (GFunc) g_object_unref, NULL);
+ g_slist_free (holders);
+ }
}
- gtk_notebook_set_current_page (part->nb, part->data_widget_page);
GError *lerror = NULL;
if (! compute_sources_dependencies (part, &lerror)) {
data_part_show_error (part, lerror);
g_clear_error (&lerror);
- }
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]