Commit fd1a0e14 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

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.
parent 51b8b94e
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>
* 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.
* app/actions/plug-in-commands.c
......
......@@ -304,3 +304,26 @@ gimp_parameters_free (GParameter *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;
}
......@@ -20,44 +20,48 @@
#define __APP_GIMP_UTILS_H__
gboolean gimp_rectangle_intersect (gint x1,
gint y1,
gint width1,
gint height1,
gint x2,
gint y2,
gint width2,
gint height2,
gint *dest_x,
gint *dest_y,
gint *dest_width,
gint *dest_height);
gint64 gimp_g_object_get_memsize (GObject *object);
gint64 gimp_g_hash_table_get_memsize (GHashTable *hash);
gint64 gimp_g_slist_get_memsize (GSList *slist,
gint64 data_size);
gint64 gimp_g_list_get_memsize (GList *list,
gint64 data_size);
gint64 gimp_g_value_get_memsize (GValue *value);
gchar * gimp_get_default_language (const gchar *category);
gboolean gimp_boolean_handled_accum (GSignalInvocationHint *ihint,
GValue *return_accu,
const GValue *handler_return,
gpointer dummy);
GParameter * gimp_parameters_append (GType object_type,
GParameter *params,
gint *n_params,
gboolean gimp_rectangle_intersect (gint x1,
gint y1,
gint width1,
gint height1,
gint x2,
gint y2,
gint width2,
gint height2,
gint *dest_x,
gint *dest_y,
gint *dest_width,
gint *dest_height);
gint64 gimp_g_object_get_memsize (GObject *object);
gint64 gimp_g_hash_table_get_memsize (GHashTable *hash);
gint64 gimp_g_slist_get_memsize (GSList *slist,
gint64 data_size);
gint64 gimp_g_list_get_memsize (GList *list,
gint64 data_size);
gint64 gimp_g_value_get_memsize (GValue *value);
gchar * gimp_get_default_language (const gchar *category);
gboolean gimp_boolean_handled_accum (GSignalInvocationHint *ihint,
GValue *return_accu,
const GValue *handler_return,
gpointer dummy);
GParameter * gimp_parameters_append (GType object_type,
GParameter *params,
gint *n_params,
...);
GParameter * gimp_parameters_append_valist (GType object_type,
GParameter *params,
gint *n_params,
va_list args);
void gimp_parameters_free (GParameter *params,
gint n_params);
GParameter * gimp_parameters_append_valist (GType object_type,
GParameter *params,
gint *n_params,
va_list args);
void gimp_parameters_free (GParameter *params,
gint n_params);
const gchar * gimp_check_glib_version (guint required_major,
guint required_minor,
guint required_micro);
#endif /* __APP_GIMP_UTILS_H__ */
......@@ -31,6 +31,7 @@
#include "config/gimpguiconfig.h"
#include "core/gimp.h"
#include "core/gimp-utils.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpenvirontable.h"
......@@ -214,6 +215,18 @@ gui_post_init (Gimp *gimp)
gimp_dialog_factory_dialog_new (global_dialog_factory,
gdk_screen_get_default (),
"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.");
}
}
......
......@@ -28,6 +28,7 @@
#include "widgets-types.h"
#include "core/gimp.h"
#include "core/gimp-utils.h"
#include "core/gimpbrush.h"
#include "core/gimpcontainer.h"
#include "core/gimpdatafactory.h"
......@@ -177,10 +178,11 @@ gimp_unescape_uri_string (const char *escaped,
GList *
gimp_selection_data_get_uri_list (GtkSelectionData *selection)
{
GList *crap_list = NULL;
GList *uri_list = NULL;
GList *list;
gchar *buffer;
GList *crap_list = NULL;
GList *uri_list = NULL;
GList *list;
gchar *buffer;
gboolean file_uris_are_utf8;
g_return_val_if_fail (selection != NULL, NULL);
......@@ -224,6 +226,9 @@ gimp_selection_data_get_uri_list (GtkSelectionData *selection)
if (! crap_list)
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
* arbitrary crap...
*/
......@@ -241,7 +246,11 @@ gimp_selection_data_get_uri_list (GtkSelectionData *selection)
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);
......@@ -270,13 +279,36 @@ gimp_selection_data_get_uri_list (GtkSelectionData *selection)
if (start != dnd_crap)
{
/* try if we got a "file:" uri in the local filename encoding */
gchar *unescaped_filename;
/* 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;
if (strstr (dnd_crap, "%"))
{
unescaped_filename = gimp_unescape_uri_string (start, -1,
"/", 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
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment