[libgda] Picture plugin: removed the SERIALIZE option, and dialog position correction
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Picture plugin: removed the SERIALIZE option, and dialog position correction
- Date: Mon, 30 Nov 2015 21:11:34 +0000 (UTC)
commit 1bb324eb03ea3118bb060107eff23c4d2eccfc33
Author: Vivien Malerba <malerba gnome-db org>
Date: Mon Nov 30 22:07:02 2015 +0100
Picture plugin: removed the SERIALIZE option, and dialog position correction
as it relies on deprecated functions
libgda-ui/data-entries/plugins/.gitignore | 1 -
libgda-ui/data-entries/plugins/Makefile.am | 1 -
libgda-ui/data-entries/plugins/common-pict.c | 172 ++++++--------------
libgda-ui/data-entries/plugins/common-pict.h | 1 -
.../plugins/gdaui-data-cell-renderer-pict.c | 1 -
.../plugins/gdaui-entry-pict-spec.xml.in | 6 -
.../plugins/gdaui-entry-pict-spec_string.xml.in | 1 -
libgda-ui/data-entries/plugins/gdaui-entry-pict.c | 12 +-
libgda-ui/data-entries/plugins/libmain.c | 12 --
9 files changed, 62 insertions(+), 145 deletions(-)
---
diff --git a/libgda-ui/data-entries/plugins/.gitignore b/libgda-ui/data-entries/plugins/.gitignore
index af68ed2..fc3a787 100644
--- a/libgda-ui/data-entries/plugins/.gitignore
+++ b/libgda-ui/data-entries/plugins/.gitignore
@@ -1,6 +1,5 @@
gdaui-entry-filesel-spec.xml
gdaui-entry-password.xml
-gdaui-entry-pict-spec.xml
gdaui-entry-pict-spec_string.xml
gdaui-entry-text-spec.xml
gdaui-entry-format-spec.xml
diff --git a/libgda-ui/data-entries/plugins/Makefile.am b/libgda-ui/data-entries/plugins/Makefile.am
index 3158e5c..d00e7b3 100644
--- a/libgda-ui/data-entries/plugins/Makefile.am
+++ b/libgda-ui/data-entries/plugins/Makefile.am
@@ -63,7 +63,6 @@ libgda_ui_plugins_la_LIBADD = \
xmldir = $(libdir)/libgda-$(GDA_ABI_MAJOR_VERSION).$(GDA_ABI_MINOR_VERSION)/plugins
xml_in_files = \
- gdaui-entry-pict-spec.xml.in \
gdaui-entry-pict-spec_string.xml.in \
gdaui-entry-filesel-spec.xml.in \
gdaui-entry-password.xml.in \
diff --git a/libgda-ui/data-entries/plugins/common-pict.c b/libgda-ui/data-entries/plugins/common-pict.c
index f7bd50d..efd7000 100644
--- a/libgda-ui/data-entries/plugins/common-pict.c
+++ b/libgda-ui/data-entries/plugins/common-pict.c
@@ -201,83 +201,37 @@ common_pict_make_pixbuf (PictOptions *options, PictBinData *bindata, PictAllocat
*out_icon_name = NULL;
if (bindata->data) {
- if (options->serialize) {
- GdkPixdata pixdata;
- GError *loc_error = NULL;
-
- if (!gdk_pixdata_deserialize (&pixdata, bindata->data_length,
- bindata->data, &loc_error)) {
- g_free (bindata->data);
- bindata->data = NULL;
- bindata->data_length = 0;
-
- *out_icon_name = "dialog-error";
- g_set_error (error, GDAUI_DATA_ENTRY_ERROR,
GDAUI_DATA_ENTRY_INVALID_DATA_ERROR,
- _("Error while deserializing data:\n%s"),
- loc_error && loc_error->message ? loc_error->message : _("No
detail"));
-
- g_error_free (loc_error);
- }
- else {
- retpixbuf = gdk_pixbuf_from_pixdata (&pixdata, FALSE, &loc_error);
- if (!retpixbuf) {
- *out_icon_name = "dialog-error";
- g_set_error (error, GDAUI_DATA_ENTRY_ERROR,
GDAUI_DATA_ENTRY_INVALID_DATA_ERROR,
- _("Error while interpreting data as an image:\n%s"),
- loc_error && loc_error->message ? loc_error->message :
_("No detail"));
- g_error_free (loc_error);
- }
- else {
- /* scale resulting pixbuf */
- GdkPixbuf *tmp;
- gint width, height, w, h;
- width = gdk_pixbuf_get_width (retpixbuf);
- height = gdk_pixbuf_get_height (retpixbuf);
- compute_reduced_size (width, height, allocation, &w, &h);
- if ((w != width) || (h != height)) {
- tmp = gdk_pixbuf_scale_simple (retpixbuf, w, h,
- GDK_INTERP_BILINEAR);
- if (tmp) {
- g_object_unref (retpixbuf);
- retpixbuf = tmp;
- }
- }
- }
+ GdkPixbufLoader *loader;
+ GError *loc_error = NULL;
+
+ loader = gdk_pixbuf_loader_new ();
+ if (allocation)
+ g_signal_connect (G_OBJECT (loader), "size-prepared",
+ G_CALLBACK (loader_size_prepared_cb), allocation);
+ if (gdk_pixbuf_loader_write (loader, bindata->data, bindata->data_length, &loc_error) &&
+ gdk_pixbuf_loader_close (loader, &loc_error)) {
+ retpixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+ if (!retpixbuf) {
+ if (loc_error)
+ g_propagate_error (error, loc_error);
+ *out_icon_name = "image-missing";
}
+ else
+ g_object_ref (retpixbuf);
}
else {
- GdkPixbufLoader *loader;
- GError *loc_error = NULL;
-
- loader = gdk_pixbuf_loader_new ();
- if (allocation)
- g_signal_connect (G_OBJECT (loader), "size-prepared",
- G_CALLBACK (loader_size_prepared_cb), allocation);
- if (gdk_pixbuf_loader_write (loader, bindata->data, bindata->data_length, &loc_error)
&&
- gdk_pixbuf_loader_close (loader, &loc_error)) {
- retpixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
- if (!retpixbuf) {
- if (loc_error)
- g_propagate_error (error, loc_error);
- *out_icon_name = "image-missing";
- }
- else
- g_object_ref (retpixbuf);
- }
- else {
- gchar *notice_msg;
- notice_msg = g_strdup_printf (_("Error while interpreting data as an
image:\n%s"),
- loc_error && loc_error->message ?
loc_error->message : _("No detail"));
- *out_icon_name = "dialog-warning";
- g_set_error_literal (error, loc_error ? loc_error->domain :
GDAUI_DATA_ENTRY_ERROR,
- loc_error ? loc_error->code :
GDAUI_DATA_ENTRY_INVALID_DATA_ERROR,
- notice_msg);
- g_error_free (loc_error);
- g_free (notice_msg);
- }
-
- g_object_unref (loader);
+ gchar *notice_msg;
+ notice_msg = g_strdup_printf (_("Error while interpreting data as an image:\n%s"),
+ loc_error && loc_error->message ? loc_error->message :
_("No detail"));
+ *out_icon_name = "dialog-warning";
+ g_set_error_literal (error, loc_error ? loc_error->domain : GDAUI_DATA_ENTRY_ERROR,
+ loc_error ? loc_error->code :
GDAUI_DATA_ENTRY_INVALID_DATA_ERROR,
+ notice_msg);
+ g_error_free (loc_error);
+ g_free (notice_msg);
}
+
+ g_object_unref (loader);
}
return retpixbuf;
@@ -293,11 +247,10 @@ typedef struct {
PictCallback callback;
gpointer data;
} PictMenuData;
-static void file_load_cb (GtkWidget *button, PictMenuData *menudata);
-static void file_save_cb (GtkWidget *button, PictMenuData *menudata);
-static void copy_cb (GtkWidget *button, PictMenuData *menudata);
+static void file_load_cb (GtkMenuItem *mitem, PictMenuData *menudata);
+static void file_save_cb (GtkMenuItem *mitem, PictMenuData *menudata);
+static void copy_cb (GtkMenuItem *mitem, PictMenuData *menudata);
-/* Commented out because it's not used:
static void
menudata_free (PictMenuData *menudata)
{
@@ -307,7 +260,6 @@ menudata_free (PictMenuData *menudata)
}
g_free (menudata);
}
-*/
void
common_pict_create_menu (PictMenu *pictmenu, GtkWidget *attach_to, PictBinData *bindata, PictOptions
*options,
@@ -325,7 +277,7 @@ common_pict_create_menu (PictMenu *pictmenu, GtkWidget *attach_to, PictBinData *
menudata->data = data;
menu = gtk_menu_new ();
- g_object_set_data_full (G_OBJECT (menu), "menudata", menudata, g_free);
+ g_object_set_data_full (G_OBJECT (menu), "menudata", menudata, (GDestroyNotify) menudata_free);
g_signal_connect (menu, "deactivate",
G_CALLBACK (gtk_widget_hide), NULL);
pictmenu->menu = menu;
@@ -341,6 +293,8 @@ common_pict_create_menu (PictMenu *pictmenu, GtkWidget *attach_to, PictBinData *
mitem = gtk_menu_item_new_with_mnemonic (_("_Load image from file"));
gtk_widget_show (mitem);
gtk_container_add (GTK_CONTAINER (menu), mitem);
+ if (attach_to)
+ g_object_set_data_full (G_OBJECT (mitem), "attach-to", g_object_ref (attach_to),
g_object_unref);
g_signal_connect (mitem, "activate",
G_CALLBACK (file_load_cb), menudata);
pictmenu->load_mitem = mitem;
@@ -348,6 +302,8 @@ common_pict_create_menu (PictMenu *pictmenu, GtkWidget *attach_to, PictBinData *
mitem = gtk_menu_item_new_with_mnemonic (_("_Save image"));
gtk_widget_show (mitem);
gtk_container_add (GTK_CONTAINER (menu), mitem);
+ if (attach_to)
+ g_object_set_data_full (G_OBJECT (mitem), "attach-to", g_object_ref (attach_to),
g_object_unref);
g_signal_connect (mitem, "activate",
G_CALLBACK (file_save_cb), menudata);
gtk_widget_set_sensitive (mitem, bindata->data ? TRUE : FALSE);
@@ -357,13 +313,17 @@ common_pict_create_menu (PictMenu *pictmenu, GtkWidget *attach_to, PictBinData *
}
static void
-file_load_cb (GtkWidget *button, PictMenuData *menudata)
+file_load_cb (GtkMenuItem *mitem, PictMenuData *menudata)
{
GtkWidget *dlg;
GtkFileFilter *filter;
+ GtkWidget *attach_to;
+ attach_to = g_object_get_data (G_OBJECT (mitem), "attach-to");
+ if (!attach_to)
+ attach_to = GTK_WIDGET (mitem);
dlg = gtk_file_chooser_dialog_new (_("Select image to load"),
- GTK_WINDOW (gtk_widget_get_toplevel (button)),
+ GTK_WINDOW (gtk_widget_get_toplevel (attach_to)),
GTK_FILE_CHOOSER_ACTION_OPEN,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Open"), GTK_RESPONSE_ACCEPT,
@@ -385,32 +345,8 @@ file_load_cb (GtkWidget *button, PictMenuData *menudata)
if (g_file_get_contents (filename, &data, &length, &error)) {
g_free (menudata->bindata->data);
- menudata->bindata->data = NULL;
- menudata->bindata->data_length = 0;
-
- if (menudata->options->serialize) {
- GdkPixdata pixdata;
- GdkPixbuf *pixbuf;
- guint stream_length;
-
- pixbuf = gdk_pixbuf_new_from_file (filename, &error);
- if (pixbuf) {
- gdk_pixdata_from_pixbuf (&pixdata, pixbuf, TRUE);
- menudata->bindata->data = gdk_pixdata_serialize (&pixdata,
&stream_length);
- menudata->bindata->data_length = stream_length;
-
- g_object_unref (pixbuf);
- g_free (data);
- }
- else {
- menudata->bindata->data = (guchar *) data;
- menudata->bindata->data_length = length;
- }
- }
- else {
- menudata->bindata->data = (guchar *) data;
- menudata->bindata->data_length = length;
- }
+ menudata->bindata->data = (guchar *) data;
+ menudata->bindata->data_length = length;
/* call the callback */
if (menudata->callback)
@@ -422,7 +358,7 @@ file_load_cb (GtkWidget *button, PictMenuData *menudata)
GtkWidget *msg;
gchar *tmp;
tmp = g_strdup_printf (_("Could not load the contents of '%s'"), filename);
- msg = gtk_message_dialog_new_with_markup (GTK_WINDOW (gtk_widget_get_toplevel
(button)),
+ msg = gtk_message_dialog_new_with_markup (GTK_WINDOW (gtk_widget_get_toplevel
(attach_to)),
GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"<b>%s:</b>\n%s: %s",
@@ -463,13 +399,18 @@ add_if_writable (GdkPixbufFormat *data, PictFormat *format)
}
static void
-file_save_cb (GtkWidget *button, PictMenuData *menudata)
+file_save_cb (GtkMenuItem *mitem, PictMenuData *menudata)
{
GtkWidget *dlg;
GtkWidget *combo, *expander, *hbox, *label;
GSList *formats;
PictFormat pictformat;
+ GtkWidget *attach_to;
+ attach_to = g_object_get_data (G_OBJECT (mitem), "attach-to");
+ if (!attach_to)
+ attach_to = GTK_WIDGET (mitem);
+
/* determine writable formats */
expander = gtk_expander_new (_("Image format"));
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
@@ -491,7 +432,7 @@ file_save_cb (GtkWidget *button, PictMenuData *menudata)
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
dlg = gtk_file_chooser_dialog_new (_("Select a file to save the image to"),
- GTK_WINDOW (gtk_widget_get_toplevel (button)),
+ GTK_WINDOW (gtk_widget_get_toplevel (attach_to)),
GTK_FILE_CHOOSER_ACTION_SAVE,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Save"), GTK_RESPONSE_ACCEPT,
@@ -535,7 +476,7 @@ file_save_cb (GtkWidget *button, PictMenuData *menudata)
GtkWidget *msg;
gchar *tmp;
tmp = g_strdup_printf (_("Could not save the image to '%s'"), filename);
- msg = gtk_message_dialog_new_with_markup (GTK_WINDOW (gtk_widget_get_toplevel
(button)),
+ msg = gtk_message_dialog_new_with_markup (GTK_WINDOW (gtk_widget_get_toplevel
(attach_to)),
GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"<b>%s:</b>\n%s: %s",
@@ -560,10 +501,10 @@ file_save_cb (GtkWidget *button, PictMenuData *menudata)
}
static void
-copy_cb (G_GNUC_UNUSED GtkWidget *button, PictMenuData *menudata)
+copy_cb (G_GNUC_UNUSED GtkMenuItem *mitem, PictMenuData *menudata)
{
GtkClipboard *cp;
- cp = gtk_clipboard_get (gdk_atom_intern_static_string ("CLIPBOARD"));
+ cp = gtk_clipboard_get_default (gdk_display_get_default ());
if (!cp)
return;
@@ -729,11 +670,6 @@ common_pict_parse_options (PictOptions *options, const gchar *options_str)
if (!strcmp (str, "base64"))
options->encoding = ENCODING_BASE64;
}
- str = gda_quark_list_find (params, "SERIALIZE");
- if (str) {
- if ((*str == 't') || (*str == 'T'))
- options->serialize = TRUE;
- }
gda_quark_list_free (params);
}
}
diff --git a/libgda-ui/data-entries/plugins/common-pict.h b/libgda-ui/data-entries/plugins/common-pict.h
index 424e29d..21df002 100644
--- a/libgda-ui/data-entries/plugins/common-pict.h
+++ b/libgda-ui/data-entries/plugins/common-pict.h
@@ -38,7 +38,6 @@ typedef struct {
typedef struct {
PictEncodeType encoding;
- gboolean serialize; /* TRUE if must use gdk_pixdata_serialize() */
GHashTable *pixbuf_hash; /* key = GValue pointer, value = a GdkPixbuf */
} PictOptions;
diff --git a/libgda-ui/data-entries/plugins/gdaui-data-cell-renderer-pict.c
b/libgda-ui/data-entries/plugins/gdaui-data-cell-renderer-pict.c
index 9ba5246..a028b45 100644
--- a/libgda-ui/data-entries/plugins/gdaui-data-cell-renderer-pict.c
+++ b/libgda-ui/data-entries/plugins/gdaui-data-cell-renderer-pict.c
@@ -150,7 +150,6 @@ gdaui_data_cell_renderer_pict_init (GdauiDataCellRendererPict *cell)
cell->priv->bindata.data = NULL;
cell->priv->bindata.data_length = 0;
cell->priv->options.encoding = ENCODING_NONE;
- cell->priv->options.serialize = FALSE;
common_pict_init_cache (&(cell->priv->options));
gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &(cell->priv->size.width), &(cell->priv->size.height));
diff --git a/libgda-ui/data-entries/plugins/gdaui-entry-pict-spec_string.xml.in
b/libgda-ui/data-entries/plugins/gdaui-entry-pict-spec_string.xml.in
index 8904fb2..a222dab 100644
--- a/libgda-ui/data-entries/plugins/gdaui-entry-pict-spec_string.xml.in
+++ b/libgda-ui/data-entries/plugins/gdaui-entry-pict-spec_string.xml.in
@@ -4,7 +4,6 @@
<parameter id="ENCODING" _name="Encoding" _descr="Encoding used to convert binary data to the string"
gdatype="gchararray" source="encodings:0" nullok="FALSE">
<gda_value>base64</gda_value>
</parameter>
- <parameter id="SERIALIZE" _name="Serialized picture" _descr="Set to TRUE if data comes from a serialized
GdkPixbuf (F-Spot for example)" gdatype="gboolean"/>
</parameters>
<sources>
<gda_array name="encodings">
diff --git a/libgda-ui/data-entries/plugins/gdaui-entry-pict.c
b/libgda-ui/data-entries/plugins/gdaui-entry-pict.c
index e88e44b..965e6e2 100644
--- a/libgda-ui/data-entries/plugins/gdaui-entry-pict.c
+++ b/libgda-ui/data-entries/plugins/gdaui-entry-pict.c
@@ -119,7 +119,6 @@ gdaui_entry_pict_init (GdauiEntryPict *gdaui_entry_pict)
gdaui_entry_pict->priv->bindata.data = NULL;
gdaui_entry_pict->priv->bindata.data_length = 0;
gdaui_entry_pict->priv->options.encoding = ENCODING_NONE;
- gdaui_entry_pict->priv->options.serialize = FALSE;
common_pict_init_cache (&gdaui_entry_pict->priv->options);
gdaui_entry_pict->priv->editable = TRUE;
gdaui_entry_pict->priv->size.width = 0;
@@ -240,10 +239,14 @@ create_entry (GdauiEntryWrapper *mgwrap)
G_CALLBACK (size_allocate_cb), mgpict);
/* image */
+ GtkWidget *evbox;
+ evbox = gtk_event_box_new ();
+ gtk_container_add (GTK_CONTAINER (mgpict->priv->sw), evbox);
wid = gtk_image_new ();
gtk_widget_set_valign (wid, GTK_ALIGN_CENTER);
- gtk_container_add (GTK_CONTAINER (mgpict->priv->sw), wid);
- gtk_widget_show (wid);
+ gtk_widget_set_halign (wid, GTK_ALIGN_START);
+ gtk_container_add (GTK_CONTAINER (evbox), wid);
+ gtk_widget_show_all (evbox);
mgpict->priv->pict = wid;
wid = gtk_bin_get_child (GTK_BIN (mgpict->priv->sw));
@@ -252,6 +255,7 @@ create_entry (GdauiEntryWrapper *mgwrap)
/* connect signals for popup menu */
g_signal_connect (G_OBJECT (mgpict), "popup-menu",
G_CALLBACK (popup_menu_cb), mgpict);
+ gtk_widget_add_events (evbox, GDK_BUTTON_PRESS_MASK);
g_signal_connect (G_OBJECT (mgpict), "event",
G_CALLBACK (event_cb), mgpict);
@@ -413,7 +417,7 @@ display_image (GdauiEntryPict *mgpict, const GValue *value, const gchar *error_i
}
else {
icon_name = "image-missing";
- notice_msg = g_strdup (_("Empty data"));
+ notice_msg = g_strdup (_("Unspecified"));
}
}
diff --git a/libgda-ui/data-entries/plugins/libmain.c b/libgda-ui/data-entries/plugins/libmain.c
index 8b27b03..3397f46 100644
--- a/libgda-ui/data-entries/plugins/libmain.c
+++ b/libgda-ui/data-entries/plugins/libmain.c
@@ -276,18 +276,6 @@ plugin_init (GError **error)
plugin->cell_create_func = plugin_cell_renderer_pict_create_func;
retlist = g_slist_append (retlist, plugin);
- file = gda_gbr_get_file_path (GDA_LIB_DIR, LIBGDA_ABI_NAME, "plugins", "gdaui-entry-pict-spec.xml",
NULL);
- if (! g_file_test (file, G_FILE_TEST_EXISTS)) {
- if (error && !*error)
- g_set_error (error, GDAUI_DATA_ENTRY_ERROR, GDAUI_DATA_ENTRY_FILE_NOT_FOUND_ERROR,
- _("Missing spec. file '%s'"), file);
- }
- else {
- gsize len;
- g_file_get_contents (file, &(plugin->options_xml_spec), &len, error);
- }
- g_free (file);
-
/* picture - string encoded */
plugin = g_new0 (GdauiPlugin, 1);
plugin->plugin_name = "picture_as_string";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]