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

@ -59,5 +59,9 @@ GParameter * gimp_parameters_append_valist (GType object_type,
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"
@ -181,6 +182,7 @@ gimp_selection_data_get_uri_list (GtkSelectionData *selection)
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...
*
* (for GLib < 2.4.4, this is escaped local filename encoding,
* for GLib > 2.4.4, this is escaped UTF-8)
*/
gchar *unescaped_filename; 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
{ {