Allow URI drops from apps linked against GLib < 2.4.4 to GIMP linked

2004-08-04  Michael Natterer  <mitch@gimp.org>

	Allow URI drops from apps linked against GLib < 2.4.4 to GIMP
	linked against GLib >= 2.4.5. Fixes bug #148140.

	* app/core/gimp-utils.[ch]: added gimp_check_glib_version().

	* app/widgets/gimpselectiondata.c: added runtime check for GLib
	versions that encode file:// URIs correctly (>= 2.4.5). For older
	(broken) GLibs, leave the code path as is, for newer (fixed) ones,
	perform an additional check if the dropped URI is in the (broken)
	escaped-UTF-8 format and convert it to local filename encoding.

	* app/gui/gui.c: warn the user that non-ASCII filenames can't
	be used when linked against GLib 2.4.4.
This commit is contained in:
Michael Natterer
2004-08-04 17:11:39 +00:00
committed by Michael Natterer
parent 51b8b94ed9
commit fd1a0e142c
5 changed files with 129 additions and 41 deletions

View File

@ -1,7 +1,23 @@
2004-08-04 Michael Natterer <mitch@gimp.org>
Allow URI drops from apps linked against GLib < 2.4.4 to GIMP
linked against GLib >= 2.4.5. Fixes bug #148140.
* app/core/gimp-utils.[ch]: added gimp_check_glib_version().
* app/widgets/gimpselectiondata.c: added runtime check for GLib
versions that encode file:// URIs correctly (>= 2.4.5). For older
(broken) GLibs, leave the code path as is, for newer (fixed) ones,
perform an additional check if the dropped URI is in the (broken)
escaped-UTF-8 format and convert it to local filename encoding.
* app/gui/gui.c: warn the user that non-ASCII filenames can't
be used when linked against GLib 2.4.4.
2004-08-04 Michael Natterer <mitch@gimp.org> 2004-08-04 Michael Natterer <mitch@gimp.org>
* app/core/gimp.[ch]: changed member "ProcRecord last_plug_in" to * app/core/gimp.[ch]: changed member "ProcRecord last_plug_in" to
PlugInProcDef last_plug_in". Added function "PlugInProcDef last_plug_in". Added function
gimp_set_last_plug_in() and signal Gimp::last-plug-in-changed. gimp_set_last_plug_in() and signal Gimp::last-plug-in-changed.
* app/actions/plug-in-commands.c * app/actions/plug-in-commands.c

View File

@ -304,3 +304,26 @@ gimp_parameters_free (GParameter *params,
g_free (params); g_free (params);
} }
} }
const gchar *
gimp_check_glib_version (guint required_major,
guint required_minor,
guint required_micro)
{
#ifdef __GNUC__
#warning FIXME: remove this function as soon as we depend on GLib 2.6.0
#endif
gint glib_effective_micro = 100 * glib_minor_version + glib_micro_version;
gint required_effective_micro = 100 * required_minor + required_micro;
if (required_major > glib_major_version)
return "GLib version too old (major mismatch)";
if (required_major < glib_major_version)
return "GLib version too new (major mismatch)";
if (required_effective_micro < glib_effective_micro - glib_binary_age)
return "GLib version too new (micro mismatch)";
if (required_effective_micro > glib_effective_micro)
return "GLib version too old (micro mismatch)";
return NULL;
}

View File

@ -20,44 +20,48 @@
#define __APP_GIMP_UTILS_H__ #define __APP_GIMP_UTILS_H__
gboolean gimp_rectangle_intersect (gint x1, gboolean gimp_rectangle_intersect (gint x1,
gint y1, gint y1,
gint width1, gint width1,
gint height1, gint height1,
gint x2, gint x2,
gint y2, gint y2,
gint width2, gint width2,
gint height2, gint height2,
gint *dest_x, gint *dest_x,
gint *dest_y, gint *dest_y,
gint *dest_width, gint *dest_width,
gint *dest_height); gint *dest_height);
gint64 gimp_g_object_get_memsize (GObject *object); gint64 gimp_g_object_get_memsize (GObject *object);
gint64 gimp_g_hash_table_get_memsize (GHashTable *hash); gint64 gimp_g_hash_table_get_memsize (GHashTable *hash);
gint64 gimp_g_slist_get_memsize (GSList *slist, gint64 gimp_g_slist_get_memsize (GSList *slist,
gint64 data_size); gint64 data_size);
gint64 gimp_g_list_get_memsize (GList *list, gint64 gimp_g_list_get_memsize (GList *list,
gint64 data_size); gint64 data_size);
gint64 gimp_g_value_get_memsize (GValue *value); gint64 gimp_g_value_get_memsize (GValue *value);
gchar * gimp_get_default_language (const gchar *category); gchar * gimp_get_default_language (const gchar *category);
gboolean gimp_boolean_handled_accum (GSignalInvocationHint *ihint, gboolean gimp_boolean_handled_accum (GSignalInvocationHint *ihint,
GValue *return_accu, GValue *return_accu,
const GValue *handler_return, const GValue *handler_return,
gpointer dummy); gpointer dummy);
GParameter * gimp_parameters_append (GType object_type, GParameter * gimp_parameters_append (GType object_type,
GParameter *params, GParameter *params,
gint *n_params, gint *n_params,
...); ...);
GParameter * gimp_parameters_append_valist (GType object_type, GParameter * gimp_parameters_append_valist (GType object_type,
GParameter *params, GParameter *params,
gint *n_params, gint *n_params,
va_list args); va_list args);
void gimp_parameters_free (GParameter *params, void gimp_parameters_free (GParameter *params,
gint n_params); gint n_params);
const gchar * gimp_check_glib_version (guint required_major,
guint required_minor,
guint required_micro);
#endif /* __APP_GIMP_UTILS_H__ */ #endif /* __APP_GIMP_UTILS_H__ */

View File

@ -31,6 +31,7 @@
#include "config/gimpguiconfig.h" #include "config/gimpguiconfig.h"
#include "core/gimp.h" #include "core/gimp.h"
#include "core/gimp-utils.h"
#include "core/gimpcontainer.h" #include "core/gimpcontainer.h"
#include "core/gimpcontext.h" #include "core/gimpcontext.h"
#include "core/gimpenvirontable.h" #include "core/gimpenvirontable.h"
@ -214,6 +215,18 @@ gui_post_init (Gimp *gimp)
gimp_dialog_factory_dialog_new (global_dialog_factory, gimp_dialog_factory_dialog_new (global_dialog_factory,
gdk_screen_get_default (), gdk_screen_get_default (),
"gimp-tips-dialog", -1); "gimp-tips-dialog", -1);
if (gimp_check_glib_version (2, 4, 4) == NULL &&
gimp_check_glib_version (2, 4, 5) != NULL)
{
g_message ("You are using GLib version 2.4.4.\n\n"
"This version of GLib contains a bug "
"affecting filename conversions. "
"The GIMP won't be able to open any file "
"with non-ASCII characters (e.g. umlauts) "
"in its filename.\n\n"
"Please upgrade to GLib 2.4.5 or newer.");
}
} }

View File

@ -28,6 +28,7 @@
#include "widgets-types.h" #include "widgets-types.h"
#include "core/gimp.h" #include "core/gimp.h"
#include "core/gimp-utils.h"
#include "core/gimpbrush.h" #include "core/gimpbrush.h"
#include "core/gimpcontainer.h" #include "core/gimpcontainer.h"
#include "core/gimpdatafactory.h" #include "core/gimpdatafactory.h"
@ -177,10 +178,11 @@ gimp_unescape_uri_string (const char *escaped,
GList * GList *
gimp_selection_data_get_uri_list (GtkSelectionData *selection) gimp_selection_data_get_uri_list (GtkSelectionData *selection)
{ {
GList *crap_list = NULL; GList *crap_list = NULL;
GList *uri_list = NULL; GList *uri_list = NULL;
GList *list; GList *list;
gchar *buffer; gchar *buffer;
gboolean file_uris_are_utf8;
g_return_val_if_fail (selection != NULL, NULL); g_return_val_if_fail (selection != NULL, NULL);
@ -224,6 +226,9 @@ gimp_selection_data_get_uri_list (GtkSelectionData *selection)
if (! crap_list) if (! crap_list)
return NULL; return NULL;
file_uris_are_utf8 = (gimp_check_glib_version (2, 4, 0) == NULL &&
gimp_check_glib_version (2, 4, 4) != NULL);
/* do various checks because file drag sources send all kinds of /* do various checks because file drag sources send all kinds of
* arbitrary crap... * arbitrary crap...
*/ */
@ -241,7 +246,11 @@ gimp_selection_data_get_uri_list (GtkSelectionData *selection)
if (filename) if (filename)
{ {
/* if we got a correctly encoded "file:" uri... */ /* if we got a correctly encoded "file:" uri...
*
* (for GLib < 2.4.4, this is escaped UTF-8,
* for GLib > 2.4.4, this is escaped local filename encoding)
*/
uri = g_filename_to_uri (filename, NULL, NULL); uri = g_filename_to_uri (filename, NULL, NULL);
@ -270,13 +279,36 @@ gimp_selection_data_get_uri_list (GtkSelectionData *selection)
if (start != dnd_crap) if (start != dnd_crap)
{ {
/* try if we got a "file:" uri in the local filename encoding */ /* try if we got a "file:" uri in the wrong encoding...
gchar *unescaped_filename; *
* (for GLib < 2.4.4, this is escaped local filename encoding,
* for GLib > 2.4.4, this is escaped UTF-8)
*/
gchar *unescaped_filename;
if (strstr (dnd_crap, "%")) if (strstr (dnd_crap, "%"))
{ {
unescaped_filename = gimp_unescape_uri_string (start, -1, unescaped_filename = gimp_unescape_uri_string (start, -1,
"/", FALSE); "/", FALSE);
if (! file_uris_are_utf8)
{
/* if we run with a GLib that correctly encodes
* file: URIs, we still may get a drop from an
* application that encodes file: URIs as UTF-8
*/
gchar *local_filename;
local_filename = g_filename_from_utf8 (unescaped_filename,
-1, NULL, NULL,
NULL);
if (local_filename)
{
g_free (unescaped_filename);
unescaped_filename = local_filename;
}
}
} }
else else
{ {