[libgda] GdaUI: improved the way binary data is handled to the user
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgda] GdaUI: improved the way binary data is handled to the user
- Date: Sun, 13 Sep 2009 13:25:56 +0000 (UTC)
commit da80b2c467c13f19e57f68c64c870dbeb9b5aa62
Author: Vivien Malerba <malerba gnome-db org>
Date: Sat Sep 12 09:55:43 2009 +0200
GdaUI: improved the way binary data is handled to the user
libgda-ui/data-entries/common-bin.c | 20 +++++-
libgda-ui/data-entries/common-bin.h | 1 +
.../data-entries/gdaui-data-cell-renderer-bin.c | 47 +++++++++---
.../data-entries/gdaui-data-cell-renderer-bin.h | 4 +-
libgda-ui/data-entries/gdaui-entry-bin.c | 74 ++++++++++++++++++-
libgda-ui/data/Makefile.am | 4 +-
libgda-ui/data/bin-attachment-16x16.png | Bin 0 -> 649 bytes
libgda-ui/gdaui-raw-grid.c | 4 +
8 files changed, 134 insertions(+), 20 deletions(-)
---
diff --git a/libgda-ui/data-entries/common-bin.c b/libgda-ui/data-entries/common-bin.c
index 7b72f1c..8be009a 100644
--- a/libgda-ui/data-entries/common-bin.c
+++ b/libgda-ui/data-entries/common-bin.c
@@ -214,8 +214,26 @@ common_bin_adjust_menu (BinMenu *binmenu, gboolean editable, const GValue *value
if (!binmenu || !binmenu->menu)
return;
- binmenu->tmpvalue = value;
+ if (binmenu->tmpvalue) {
+ gda_value_free (binmenu->tmpvalue);
+ binmenu->tmpvalue = NULL;
+ }
+ if (value)
+ binmenu->tmpvalue = gda_value_copy (value);
gtk_widget_set_sensitive (binmenu->load_mitem, editable);
gtk_widget_set_sensitive (binmenu->save_mitem, (value && !gda_value_is_null (value)) ? TRUE : FALSE);
}
+/*
+ * Reset @bonmenu's contents
+ */
+void
+common_bin_reset (BinMenu *binmenu)
+{
+ if (binmenu->tmpvalue)
+ gda_value_free (binmenu->tmpvalue);
+ if (binmenu->menu)
+ gtk_widget_destroy (binmenu->menu);
+
+ memset (binmenu, 0, sizeof (BinMenu));
+}
diff --git a/libgda-ui/data-entries/common-bin.h b/libgda-ui/data-entries/common-bin.h
index 5c721ef..0243876 100644
--- a/libgda-ui/data-entries/common-bin.h
+++ b/libgda-ui/data-entries/common-bin.h
@@ -38,5 +38,6 @@ typedef struct {
void common_bin_create_menu (BinMenu *binmenu, GtkWidget *attach_to, GType entry_type, BinCallback loaded_value_cb, gpointer loaded_value_cb_data);
void common_bin_adjust_menu (BinMenu *binmenu, gboolean editable, const GValue *value);
+void common_bin_reset (BinMenu *binmenu);
#endif
diff --git a/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.c b/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.c
index a12818a..a363baf 100644
--- a/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.c
+++ b/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.c
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <libgda/libgda.h>
+#include <libgda/binreloc/gda-binreloc.h>
#include <glib/gi18n-lib.h>
#include <libgda/gda-enum-types.h>
#include "gdaui-data-cell-renderer-bin.h"
@@ -35,7 +36,7 @@ static void gdaui_data_cell_renderer_bin_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
-static void gdaui_data_cell_renderer_bin_init (GdauiDataCellRendererBin *celltext);
+static void gdaui_data_cell_renderer_bin_init (GdauiDataCellRendererBin *cell);
static void gdaui_data_cell_renderer_bin_class_init (GdauiDataCellRendererBinClass *class);
static void gdaui_data_cell_renderer_bin_dispose (GObject *object);
static void gdaui_data_cell_renderer_bin_finalize (GObject *object);
@@ -91,6 +92,7 @@ enum {
static GObjectClass *parent_class = NULL;
static guint bin_cell_signals[LAST_SIGNAL] = { 0 };
+static GdkPixbuf *attach_pixbuf = NULL;
GType
@@ -112,7 +114,7 @@ gdaui_data_cell_renderer_bin_get_type (void)
};
cell_type =
- g_type_register_static (GTK_TYPE_CELL_RENDERER_TEXT, "GdauiDataCellRendererBin",
+ g_type_register_static (GTK_TYPE_CELL_RENDERER_PIXBUF, "GdauiDataCellRendererBin",
&cell_info, 0);
}
@@ -196,6 +198,15 @@ gdaui_data_cell_renderer_bin_class_init (GdauiDataCellRendererBinClass *class)
G_TYPE_NONE, 2,
G_TYPE_STRING,
G_TYPE_VALUE);
+
+ if (! attach_pixbuf) {
+ gchar *tmp;
+ tmp = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps", "bin-attachment-16x16.png", NULL);
+ attach_pixbuf = gdk_pixbuf_new_from_file (tmp, NULL);
+ if (!attach_pixbuf)
+ g_warning ("Could not find icon file %s", tmp);
+ g_free (tmp);
+ }
}
static void
@@ -218,6 +229,7 @@ gdaui_data_cell_renderer_bin_finalize (GObject *object)
GdauiDataCellRendererBin *datacell = GDAUI_DATA_CELL_RENDERER_BIN (object);
if (datacell->priv) {
+ common_bin_reset (&(datacell->priv->menu));
g_free (datacell->priv);
datacell->priv = NULL;
}
@@ -260,9 +272,15 @@ gdaui_data_cell_renderer_bin_set_property (GObject *object,
switch (param_id) {
case PROP_VALUE:
/* Because we don't have a copy of the value, we MUST NOT free it! */
- if (value) {
+ if (value) {
GValue *gval = g_value_get_boxed (value);
+ if (gval && (G_VALUE_TYPE (gval) != GDA_TYPE_NULL))
+ g_object_set (object, "pixbuf", attach_pixbuf, NULL);
+ else
+ g_object_set (object, "pixbuf", NULL, NULL);
}
+ else
+ g_object_set (object, "pixbuf", NULL, NULL);
break;
case PROP_VALUE_ATTRIBUTES:
break;
@@ -312,8 +330,7 @@ gdaui_data_cell_renderer_bin_new (GdaDataHandler *dh, GType type)
g_return_val_if_fail (dh && GDA_IS_DATA_HANDLER (dh), NULL);
obj = g_object_new (GDAUI_TYPE_DATA_CELL_RENDERER_BIN, "type", type,
"data_handler", dh,
- "editable", FALSE,
- "text", _("Attachment"), NULL);
+ "editable", FALSE, NULL);
return GTK_CELL_RENDERER (obj);
}
@@ -327,9 +344,9 @@ gdaui_data_cell_renderer_bin_get_size (GtkCellRenderer *cell,
gint *width,
gint *height)
{
- GtkCellRendererClass *text_class = g_type_class_peek (GTK_TYPE_CELL_RENDERER_TEXT);
+ GtkCellRendererClass *pixbuf_class = g_type_class_peek (GTK_TYPE_CELL_RENDERER_PIXBUF);
- (text_class->get_size) (cell, widget, cell_area, x_offset, y_offset, width, height);
+ (pixbuf_class->get_size) (cell, widget, cell_area, x_offset, y_offset, width, height);
}
static void
@@ -341,9 +358,9 @@ gdaui_data_cell_renderer_bin_render (GtkCellRenderer *cell,
GdkRectangle *expose_area,
GtkCellRendererState flags)
{
- GtkCellRendererClass *text_class = g_type_class_peek (GTK_TYPE_CELL_RENDERER_TEXT);
+ GtkCellRendererClass *pixbuf_class = g_type_class_peek (GTK_TYPE_CELL_RENDERER_PIXBUF);
- (text_class->render) (cell, window, widget, background_area, cell_area, expose_area, flags);
+ (pixbuf_class->render) (cell, window, widget, background_area, cell_area, expose_area, flags);
if (GDAUI_DATA_CELL_RENDERER_BIN (cell)->priv->to_be_deleted)
gtk_paint_hline (widget->style,
@@ -389,9 +406,15 @@ gdaui_data_cell_renderer_bin_activate (GtkCellRenderer *cell,
model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
tpath = gtk_tree_path_new_from_string (path);
if (gtk_tree_model_get_iter (model, &iter, tpath)) {
- /* FIXME: get the real GValue */
- /*common_bin_adjust_menu (&(bincell->priv->menu), bincell->priv->editable,
- bincell->priv->value);*/
+ gint model_col;
+ GValue *value;
+
+ model_col = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "model_col"));
+
+ gtk_tree_model_get (model, &iter,
+ model_col, &value, -1);
+ common_bin_adjust_menu (&(bincell->priv->menu), bincell->priv->editable,
+ value);
event_time = gtk_get_current_event_time ();
gtk_menu_popup (GTK_MENU (bincell->priv->menu.menu), NULL, NULL, NULL, NULL,
0, event_time);
diff --git a/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.h b/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.h
index 7c5674b..c78c07f 100644
--- a/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.h
+++ b/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.h
@@ -39,14 +39,14 @@ typedef struct _GdauiDataCellRendererBinPrivate GdauiDataCellRendererBinPrivate;
struct _GdauiDataCellRendererBin
{
- GtkCellRendererText parent;
+ GtkCellRendererPixbuf parent;
GdauiDataCellRendererBinPrivate *priv;
};
struct _GdauiDataCellRendererBinClass
{
- GtkCellRendererTextClass parent_class;
+ GtkCellRendererPixbufClass parent_class;
void (* changed) (GdauiDataCellRendererBin *cell_renderer,
const gchar *path,
diff --git a/libgda-ui/data-entries/gdaui-entry-bin.c b/libgda-ui/data-entries/gdaui-entry-bin.c
index 63e0fc0..4ae2f9d 100644
--- a/libgda-ui/data-entries/gdaui-entry-bin.c
+++ b/libgda-ui/data-entries/gdaui-entry-bin.c
@@ -19,6 +19,7 @@
*/
#include <glib/gi18n-lib.h>
+#include <libgda/binreloc/gda-binreloc.h>
#include "gdaui-entry-bin.h"
#include "common-bin.h"
@@ -39,13 +40,19 @@ static gboolean expand_in_layout (GdauiEntryWrapper *mgwrap);
static void set_editable (GdauiEntryWrapper *mgwrap, gboolean editable);
static void grab_focus (GdauiEntryWrapper *mgwrap);
+static void show (GtkWidget *widget);
+
/* get a pointer to the parents to be able to call their destructor */
static GObjectClass *parent_class = NULL;
+static GdkPixbuf *attach_pixbuf = NULL;
/* private structure */
struct _GdauiEntryBinPrivate
{
GtkWidget *button;
+ GtkWidget *button_hbox;
+ GtkWidget *button_label; /* ref held! */
+ GtkWidget *button_image; /* ref held! */
BinMenu menu;
gboolean editable;
@@ -78,9 +85,9 @@ gdaui_entry_bin_get_type (void)
}
static void
-gdaui_entry_bin_class_init (GdauiEntryBinClass * class)
+gdaui_entry_bin_class_init (GdauiEntryBinClass *class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
parent_class = g_type_class_peek_parent (class);
@@ -94,6 +101,17 @@ gdaui_entry_bin_class_init (GdauiEntryBinClass * class)
GDAUI_ENTRY_WRAPPER_CLASS (class)->expand_in_layout = expand_in_layout;
GDAUI_ENTRY_WRAPPER_CLASS (class)->set_editable = set_editable;
GDAUI_ENTRY_WRAPPER_CLASS (class)->grab_focus = grab_focus;
+
+ GTK_WIDGET_CLASS (class)->show = show;
+
+ if (! attach_pixbuf) {
+ gchar *tmp;
+ tmp = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps", "bin-attachment-16x16.png", NULL);
+ attach_pixbuf = gdk_pixbuf_new_from_file (tmp, NULL);
+ if (!attach_pixbuf)
+ g_warning ("Could not find icon file %s", tmp);
+ g_free (tmp);
+ }
}
static void
@@ -105,6 +123,26 @@ gdaui_entry_bin_init (GdauiEntryBin * gdaui_entry_bin)
gdaui_entry_bin->priv->editable = TRUE;
}
+static void
+show (GtkWidget *widget)
+{
+ GValue *value;
+ GdauiEntryBin *dbin;
+
+ ((GtkWidgetClass *)parent_class)->show (widget);
+
+ dbin = GDAUI_ENTRY_BIN (widget);
+ value = dbin->priv->current_data;
+ if (value && (G_VALUE_TYPE (value) != GDA_TYPE_NULL)) {
+ gtk_widget_show (dbin->priv->button_image);
+ gtk_widget_hide (dbin->priv->button_label);
+ }
+ else {
+ gtk_widget_hide (dbin->priv->button_image);
+ gtk_widget_show (dbin->priv->button_label);
+ }
+}
+
/**
* gdaui_entry_bin_new
* @dh: the data handler to be used by the new widget
@@ -150,6 +188,16 @@ gdaui_entry_bin_dispose (GObject * object)
gtk_widget_destroy (gdaui_entry_bin->priv->menu.menu);
gdaui_entry_bin->priv->menu.menu = NULL;
}
+
+ if (gdaui_entry_bin->priv->button_label) {
+ g_object_unref (gdaui_entry_bin->priv->button_label);
+ gdaui_entry_bin->priv->button_label = NULL;
+ }
+
+ if (gdaui_entry_bin->priv->button_image) {
+ g_object_unref (gdaui_entry_bin->priv->button_image);
+ gdaui_entry_bin->priv->button_image = NULL;
+ }
}
/* parent class */
@@ -178,7 +226,7 @@ gdaui_entry_bin_finalize (GObject * object)
static GtkWidget *
create_entry (GdauiEntryWrapper *mgwrap)
{
- GtkWidget *button, *arrow, *label;
+ GtkWidget *button, *arrow, *label, *img;
GdauiEntryBin *dbin;
GtkWidget *hbox;
@@ -191,15 +239,22 @@ create_entry (GdauiEntryWrapper *mgwrap)
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (button), hbox);
+ dbin->priv->button_hbox = hbox;
- label = gtk_label_new (_("Attachement"));
+ label = gtk_label_new ("");
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ dbin->priv->button_label = g_object_ref (G_OBJECT (label));
+
+ img = gtk_image_new_from_pixbuf (attach_pixbuf);
+ gtk_box_pack_start (GTK_BOX (hbox), img, FALSE, FALSE, 0);
+ dbin->priv->button_image = g_object_ref (G_OBJECT (img));
arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
gtk_misc_set_alignment (GTK_MISC (arrow), 1.0, -1);
gtk_box_pack_start (GTK_BOX (hbox), arrow, TRUE, TRUE, 0);
gtk_widget_show_all (hbox);
+ gtk_widget_hide (dbin->priv->button_label);
return button;
}
@@ -211,12 +266,23 @@ create_entry (GdauiEntryWrapper *mgwrap)
static void
take_current_value (GdauiEntryBin *dbin, GValue *value)
{
+ /* clear previous situation */
if (dbin->priv->current_data) {
gda_value_free (dbin->priv->current_data);
dbin->priv->current_data = NULL;
}
+ /* new situation */
dbin->priv->current_data = value;
+ if (value && (G_VALUE_TYPE (value) != GDA_TYPE_NULL)) {
+ gtk_widget_show (dbin->priv->button_image);
+ gtk_widget_hide (dbin->priv->button_label);
+ }
+ else {
+ gtk_widget_hide (dbin->priv->button_image);
+ gtk_widget_show (dbin->priv->button_label);
+ }
+
common_bin_adjust_menu (&(dbin->priv->menu), dbin->priv->editable, value);
}
diff --git a/libgda-ui/data/Makefile.am b/libgda-ui/data/Makefile.am
index e43f25a..4fbbfda 100644
--- a/libgda-ui/data/Makefile.am
+++ b/libgda-ui/data/Makefile.am
@@ -1,6 +1,8 @@
# icons
iconsdir=$(datadir)/libgda-$(GDA_ABI_MAJOR_VERSION).$(GDA_ABI_MINOR_VERSION)/pixmaps
-icons_DATA=gdaui-generic.png
+icons_DATA= \
+ gdaui-generic.png \
+ bin-attachment-16x16.png
# other
xmldir = $(datadir)/libgda-$(GDA_ABI_MAJOR_VERSION).$(GDA_ABI_MINOR_VERSION)
diff --git a/libgda-ui/data/bin-attachment-16x16.png b/libgda-ui/data/bin-attachment-16x16.png
new file mode 100644
index 0000000..529bb7f
Binary files /dev/null and b/libgda-ui/data/bin-attachment-16x16.png differ
diff --git a/libgda-ui/gdaui-raw-grid.c b/libgda-ui/gdaui-raw-grid.c
index 7f18166..1a0f16d 100644
--- a/libgda-ui/gdaui-raw-grid.c
+++ b/libgda-ui/gdaui-raw-grid.c
@@ -1040,6 +1040,7 @@ init_tree_view (GdauiRawGrid *grid)
const gchar *plugin = NULL;
const GValue *plugin_val;
gchar *title;
+ gint model_col;
param = GDA_HOLDER (GDA_SET_NODE (group->group->nodes->data)->holder);
g_type = gda_holder_get_g_type (param);
@@ -1068,6 +1069,9 @@ init_tree_view (GdauiRawGrid *grid)
column = gtk_tree_view_get_column (tree_view, i);
g_free (title);
+ model_col = g_slist_index (((GdaSet *)grid->priv->iter)->holders, param);
+ g_object_set_data (G_OBJECT (renderer), "model_col", GINT_TO_POINTER (model_col));
+
g_signal_connect (G_OBJECT (renderer), "changed",
G_CALLBACK (data_cell_value_changed), grid);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]