Commit ee64ca3c authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

introduced variants of file_utils_uri_to_utf8_filename() and

2005-10-02  Sven Neumann  <sven@gimp.org>

	* app/file/file-utils.[ch]: introduced variants of
	file_utils_uri_to_utf8_filename() and
	file_utils_uri_to_utf8_basename() that use g_filename_display_name()
	and g_filename_display_basename().

	* app/actions/data-commands.c
	* app/actions/documents-commands.c
	* app/actions/file-actions.c
	* app/actions/file-commands.c
	* app/core/gimpimage.c
	* app/core/gimpimagefile.c
	* app/dialogs/file-open-dialog.c
	* app/dialogs/file-open-location-dialog.c
	* app/dialogs/file-save-dialog.c
	* app/dialogs/palette-import-dialog.c
	* app/display/gimpdisplayshell-close.c
	* app/display/gimpdisplayshell-dnd.c
	* app/display/gimpdisplayshell-title.c
	* app/file/file-open.c
	* app/widgets/gimpdnd-xds.c
	* app/widgets/gimpfiledialog.c
	* app/widgets/gimplayertreeview.c
	* app/widgets/gimpthumbbox.c
	* app/widgets/gimptoolbox-dnd.c
	* app/widgets/gimptoolbox.c
	* app/widgets/gimpviewabledialog.c: use the new functions.

	* plug-ins/help/domain.c: use g_filename_display_name().
parent 3c019cac
2005-10-02 Sven Neumann <sven@gimp.org>
* app/file/file-utils.[ch]: introduced variants of
file_utils_uri_to_utf8_filename() and
file_utils_uri_to_utf8_basename() that use g_filename_display_name()
and g_filename_display_basename().
* app/actions/data-commands.c
* app/actions/documents-commands.c
* app/actions/file-actions.c
* app/actions/file-commands.c
* app/core/gimpimage.c
* app/core/gimpimagefile.c
* app/dialogs/file-open-dialog.c
* app/dialogs/file-open-location-dialog.c
* app/dialogs/file-save-dialog.c
* app/dialogs/palette-import-dialog.c
* app/display/gimpdisplayshell-close.c
* app/display/gimpdisplayshell-dnd.c
* app/display/gimpdisplayshell-title.c
* app/file/file-open.c
* app/widgets/gimpdnd-xds.c
* app/widgets/gimpfiledialog.c
* app/widgets/gimplayertreeview.c
* app/widgets/gimpthumbbox.c
* app/widgets/gimptoolbox-dnd.c
* app/widgets/gimptoolbox.c
* app/widgets/gimpviewabledialog.c: use the new functions.
* plug-ins/help/domain.c: use g_filename_display_name().
2005-10-01 Michael Natterer <mitch@gimp.org> 2005-10-01 Michael Natterer <mitch@gimp.org>
* app/sanity.c (sanity_check_glib): we require 2.8.0 now. * app/sanity.c (sanity_check_glib): we require 2.8.0 now.
......
...@@ -96,7 +96,7 @@ data_open_as_image_cmd_callback (GtkAction *action, ...@@ -96,7 +96,7 @@ data_open_as_image_cmd_callback (GtkAction *action,
{ {
gchar *filename; gchar *filename;
filename = file_utils_uri_to_utf8_filename (uri); filename = file_utils_uri_display_name (uri);
g_message (_("Opening '%s' failed:\n\n%s"), g_message (_("Opening '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
g_clear_error (&error); g_clear_error (&error);
......
...@@ -327,7 +327,7 @@ documents_open_image (GimpContext *context, ...@@ -327,7 +327,7 @@ documents_open_image (GimpContext *context,
{ {
gchar *filename; gchar *filename;
filename = file_utils_uri_to_utf8_filename (uri); filename = file_utils_uri_display_name (uri);
g_message (_("Opening '%s' failed:\n\n%s"), g_message (_("Opening '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
g_clear_error (&error); g_clear_error (&error);
......
...@@ -256,8 +256,8 @@ file_actions_last_opened_update (GimpContainer *container, ...@@ -256,8 +256,8 @@ file_actions_last_opened_update (GimpContainer *container,
uri = gimp_object_get_name (GIMP_OBJECT (imagefile)); uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
filename = file_utils_uri_to_utf8_filename (uri); filename = file_utils_uri_display_name (uri);
basename = file_utils_uri_to_utf8_basename (uri); basename = file_utils_uri_display_basename (uri);
escaped = gimp_escape_uline (basename); escaped = gimp_escape_uline (basename);
......
...@@ -167,10 +167,8 @@ file_last_opened_cmd_callback (GtkAction *action, ...@@ -167,10 +167,8 @@ file_last_opened_cmd_callback (GtkAction *action,
if (! gimage && status != GIMP_PDB_CANCEL) if (! gimage && status != GIMP_PDB_CANCEL)
{ {
gchar *filename; gchar *filename =
file_utils_uri_display_name (GIMP_OBJECT (imagefile)->name);
filename =
file_utils_uri_to_utf8_filename (GIMP_OBJECT (imagefile)->name);
g_message (_("Opening '%s' failed:\n\n%s"), g_message (_("Opening '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
...@@ -224,9 +222,7 @@ file_save_cmd_callback (GtkAction *action, ...@@ -224,9 +222,7 @@ file_save_cmd_callback (GtkAction *action,
if (status != GIMP_PDB_SUCCESS && if (status != GIMP_PDB_SUCCESS &&
status != GIMP_PDB_CANCEL) status != GIMP_PDB_CANCEL)
{ {
gchar *filename; gchar *filename = file_utils_uri_display_name (uri);
filename = file_utils_uri_to_utf8_filename (uri);
g_message (_("Saving '%s' failed:\n\n%s"), g_message (_("Saving '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
...@@ -338,8 +334,8 @@ file_revert_cmd_callback (GtkAction *action, ...@@ -338,8 +334,8 @@ file_revert_cmd_callback (GtkAction *action,
G_CALLBACK (file_revert_confirm_response), G_CALLBACK (file_revert_confirm_response),
gdisp); gdisp);
basename = g_path_get_basename (uri); basename = file_utils_uri_display_basename (uri);
filename = file_utils_uri_to_utf8_filename (uri); filename = file_utils_uri_display_name (uri);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box, gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("Revert '%s' to '%s'?"), _("Revert '%s' to '%s'?"),
...@@ -543,7 +539,7 @@ file_revert_confirm_response (GtkWidget *dialog, ...@@ -543,7 +539,7 @@ file_revert_confirm_response (GtkWidget *dialog,
{ {
gchar *filename; gchar *filename;
filename = file_utils_uri_to_utf8_filename (uri); filename = file_utils_uri_display_name (uri);
g_message (_("Reverting to '%s' failed:\n\n%s"), g_message (_("Reverting to '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
......
...@@ -1069,10 +1069,10 @@ gimp_image_get_description (GimpViewable *viewable, ...@@ -1069,10 +1069,10 @@ gimp_image_get_description (GimpViewable *viewable,
uri = gimp_image_get_uri (GIMP_IMAGE (gimage)); uri = gimp_image_get_uri (GIMP_IMAGE (gimage));
basename = file_utils_uri_to_utf8_basename (uri); basename = file_utils_uri_display_basename (uri);
if (tooltip) if (tooltip)
*tooltip = file_utils_uri_to_utf8_filename (uri); *tooltip = file_utils_uri_display_name (uri);
retval = g_strdup_printf ("%s-%d", basename, gimp_image_get_ID (gimage)); retval = g_strdup_printf ("%s-%d", basename, gimp_image_get_ID (gimage));
......
...@@ -522,7 +522,7 @@ gimp_imagefile_get_description (GimpViewable *viewable, ...@@ -522,7 +522,7 @@ gimp_imagefile_get_description (GimpViewable *viewable,
gchar *filename; gchar *filename;
const gchar *desc; const gchar *desc;
filename = file_utils_uri_to_utf8_filename (thumbnail->image_uri); filename = file_utils_uri_display_name (thumbnail->image_uri);
desc = gimp_imagefile_get_desc_string (imagefile); desc = gimp_imagefile_get_desc_string (imagefile);
if (desc) if (desc)
...@@ -536,7 +536,7 @@ gimp_imagefile_get_description (GimpViewable *viewable, ...@@ -536,7 +536,7 @@ gimp_imagefile_get_description (GimpViewable *viewable,
} }
} }
basename = file_utils_uri_to_utf8_basename (thumbnail->image_uri); basename = file_utils_uri_display_basename (thumbnail->image_uri);
if (thumbnail->image_width > 0 && thumbnail->image_height > 0) if (thumbnail->image_width > 0 && thumbnail->image_height > 0)
{ {
......
...@@ -203,7 +203,7 @@ file_open_dialog_open_image (GtkWidget *open_dialog, ...@@ -203,7 +203,7 @@ file_open_dialog_open_image (GtkWidget *open_dialog,
} }
else if (status != GIMP_PDB_CANCEL) else if (status != GIMP_PDB_CANCEL)
{ {
gchar *filename = file_utils_uri_to_utf8_filename (uri); gchar *filename = file_utils_uri_display_name (uri);
g_message (_("Opening '%s' failed:\n\n%s"), g_message (_("Opening '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
...@@ -254,7 +254,7 @@ file_open_dialog_open_layer (GtkWidget *open_dialog, ...@@ -254,7 +254,7 @@ file_open_dialog_open_layer (GtkWidget *open_dialog,
} }
else if (status != GIMP_PDB_CANCEL) else if (status != GIMP_PDB_CANCEL)
{ {
gchar *filename = file_utils_uri_to_utf8_filename (uri); gchar *filename = file_utils_uri_display_name (uri);
g_message (_("Opening '%s' failed:\n\n%s"), g_message (_("Opening '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
......
...@@ -196,7 +196,7 @@ file_open_location_response (GtkDialog *dialog, ...@@ -196,7 +196,7 @@ file_open_location_response (GtkDialog *dialog,
if (image == NULL && status != GIMP_PDB_CANCEL) if (image == NULL && status != GIMP_PDB_CANCEL)
{ {
gchar *filename = file_utils_uri_to_utf8_filename (uri); gchar *filename = file_utils_uri_display_name (uri);
g_message (_("Opening '%s' failed:\n\n%s"), g_message (_("Opening '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
......
...@@ -459,7 +459,7 @@ file_save_dialog_save_image (GtkWidget *save_dialog, ...@@ -459,7 +459,7 @@ file_save_dialog_save_image (GtkWidget *save_dialog,
if (status != GIMP_PDB_SUCCESS && if (status != GIMP_PDB_SUCCESS &&
status != GIMP_PDB_CANCEL) status != GIMP_PDB_CANCEL)
{ {
gchar *filename = file_utils_uri_to_utf8_filename (uri); gchar *filename = file_utils_uri_display_name (uri);
g_message (_("Saving '%s' failed:\n\n%s"), g_message (_("Saving '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
......
...@@ -479,7 +479,8 @@ palette_import_image_changed (GimpContext *context, ...@@ -479,7 +479,8 @@ palette_import_image_changed (GimpContext *context,
gchar *basename; gchar *basename;
gchar *label; gchar *label;
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage)); basename =
file_utils_uri_display_basename (gimp_image_get_uri (gimage));
label = g_strdup_printf ("%s-%d", basename, gimp_image_get_ID (gimage)); label = g_strdup_printf ("%s-%d", basename, gimp_image_get_ID (gimage));
g_free (basename); g_free (basename);
......
...@@ -118,7 +118,7 @@ gimp_display_shell_close_dialog (GimpDisplayShell *shell, ...@@ -118,7 +118,7 @@ gimp_display_shell_close_dialog (GimpDisplayShell *shell,
return; return;
} }
name = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage)); name = file_utils_uri_display_basename (gimp_image_get_uri (gimage));
title = g_strdup_printf (_("Close %s"), name); title = g_strdup_printf (_("Close %s"), name);
g_free (name); g_free (name);
...@@ -191,7 +191,7 @@ gimp_display_shell_close_name_changed (GimpImage *image, ...@@ -191,7 +191,7 @@ gimp_display_shell_close_name_changed (GimpImage *image,
GtkWidget *window = gtk_widget_get_toplevel (GTK_WIDGET (box)); GtkWidget *window = gtk_widget_get_toplevel (GTK_WIDGET (box));
gchar *name; gchar *name;
name = file_utils_uri_to_utf8_basename (gimp_image_get_uri (image)); name = file_utils_uri_display_basename (gimp_image_get_uri (image));
if (window) if (window)
{ {
......
...@@ -443,7 +443,7 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget, ...@@ -443,7 +443,7 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget,
} }
else if (status != GIMP_PDB_CANCEL) else if (status != GIMP_PDB_CANCEL)
{ {
gchar *filename = file_utils_uri_to_utf8_filename (uri); gchar *filename = file_utils_uri_display_name (uri);
g_message (_("Opening '%s' failed:\n\n%s"), g_message (_("Opening '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
......
...@@ -184,7 +184,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell, ...@@ -184,7 +184,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
const gchar *uri = gimp_image_get_uri (image); const gchar *uri = gimp_image_get_uri (image);
gchar *basename; gchar *basename;
basename = file_utils_uri_to_utf8_basename (uri); basename = file_utils_uri_display_basename (uri);
i += print (title, title_len, i, "%s", basename); i += print (title, title_len, i, "%s", basename);
...@@ -197,7 +197,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell, ...@@ -197,7 +197,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
gchar *filename; gchar *filename;
const gchar *uri = gimp_image_get_uri (image); const gchar *uri = gimp_image_get_uri (image);
filename = file_utils_uri_to_utf8_filename (uri); filename = file_utils_uri_display_name (uri);
i += print (title, title_len, i, "%s", filename); i += print (title, title_len, i, "%s", filename);
......
...@@ -399,11 +399,10 @@ file_open_layer (Gimp *gimp, ...@@ -399,11 +399,10 @@ file_open_layer (Gimp *gimp,
if (item) if (item)
{ {
gchar *basename; gchar *basename = file_utils_uri_display_basename (uri);
new_layer = GIMP_LAYER (item); new_layer = GIMP_LAYER (item);
basename = file_utils_uri_to_utf8_basename (uri);
gimp_object_set_name (GIMP_OBJECT (new_layer), basename); gimp_object_set_name (GIMP_OBJECT (new_layer), basename);
g_free (basename); g_free (basename);
......
...@@ -265,6 +265,35 @@ file_utils_find_proc_by_extension (GSList *procs, ...@@ -265,6 +265,35 @@ file_utils_find_proc_by_extension (GSList *procs,
} }
gchar * gchar *
file_utils_uri_to_utf8_filename (const gchar *uri)
{
g_return_val_if_fail (uri != NULL, NULL);
if (g_str_has_prefix (uri, "file:"))
{
gchar *filename = file_utils_filename_from_uri (uri);
if (filename)
{
GError *error = NULL;
gchar *utf8;
utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, &error);
g_free (filename);
if (utf8)
return utf8;
g_warning ("%s: cannot convert filename to UTF-8: %s",
G_STRLOC, error->message);
g_error_free (error);
}
}
return g_strdup (uri);
}
static gchar *
file_utils_uri_to_utf8_basename (const gchar *uri) file_utils_uri_to_utf8_basename (const gchar *uri)
{ {
gchar *filename; gchar *filename;
...@@ -297,7 +326,7 @@ file_utils_uri_to_utf8_basename (const gchar *uri) ...@@ -297,7 +326,7 @@ file_utils_uri_to_utf8_basename (const gchar *uri)
} }
gchar * gchar *
file_utils_uri_to_utf8_filename (const gchar *uri) file_utils_uri_display_basename (const gchar *uri)
{ {
g_return_val_if_fail (uri != NULL, NULL); g_return_val_if_fail (uri != NULL, NULL);
...@@ -307,25 +336,39 @@ file_utils_uri_to_utf8_filename (const gchar *uri) ...@@ -307,25 +336,39 @@ file_utils_uri_to_utf8_filename (const gchar *uri)
if (filename) if (filename)
{ {
GError *error = NULL; gchar *basename = g_filename_display_basename (filename);
gchar *utf8;
utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, &error);
g_free (filename); g_free (filename);
if (utf8) return basename;
return utf8; }
}
g_warning ("%s: cannot convert filename to UTF-8: %s", return file_utils_uri_to_utf8_basename (uri);
G_STRLOC, error->message); }
g_error_free (error);
gchar *
file_utils_uri_display_name (const gchar *uri)
{
g_return_val_if_fail (uri != NULL, NULL);
if (g_str_has_prefix (uri, "file:"))
{
gchar *filename = file_utils_filename_from_uri (uri);
if (filename)
{
gchar *name = g_filename_display_name (filename);
g_free (filename);
return name;
} }
} }
return g_strdup (uri); return g_strdup (uri);
} }
/* private functions */ /* private functions */
static PlugInProcDef * static PlugInProcDef *
......
...@@ -27,9 +27,11 @@ gchar * file_utils_filename_to_uri (GSList *procs, ...@@ -27,9 +27,11 @@ gchar * file_utils_filename_to_uri (GSList *procs,
GError **error); GError **error);
gchar * file_utils_filename_from_uri (const gchar *uri); gchar * file_utils_filename_from_uri (const gchar *uri);
gchar * file_utils_uri_to_utf8_basename (const gchar *uri);
gchar * file_utils_uri_to_utf8_filename (const gchar *uri); gchar * file_utils_uri_to_utf8_filename (const gchar *uri);
gchar * file_utils_uri_display_basename (const gchar *uri);
gchar * file_utils_uri_display_name (const gchar *uri);
PlugInProcDef * file_utils_find_proc (GSList *procs, PlugInProcDef * file_utils_find_proc (GSList *procs,
const gchar *filename); const gchar *filename);
PlugInProcDef * file_utils_find_proc_by_extension (GSList *procs, PlugInProcDef * file_utils_find_proc_by_extension (GSList *procs,
......
...@@ -153,7 +153,7 @@ gimp_dnd_xds_save_image (GdkDragContext *context, ...@@ -153,7 +153,7 @@ gimp_dnd_xds_save_image (GdkDragContext *context,
if (error) if (error)
{ {
gchar *filename = file_utils_uri_to_utf8_filename (uri); gchar *filename = file_utils_uri_display_name (uri);
g_message (_("Saving '%s' failed:\n\n%s"), g_message (_("Saving '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
......
...@@ -449,7 +449,7 @@ gimp_file_overwrite_dialog (GtkWidget *parent, ...@@ -449,7 +449,7 @@ gimp_file_overwrite_dialog (GtkWidget *parent,
GTK_RESPONSE_CANCEL, GTK_RESPONSE_CANCEL,
-1); -1);
filename = file_utils_uri_to_utf8_filename (uri); filename = file_utils_uri_display_name (uri);
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box, gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
_("A file named '%s' already exists."), _("A file named '%s' already exists."),
filename); filename);
...@@ -726,7 +726,7 @@ gimp_file_dialog_proc_changed (GimpFileProcView *view, ...@@ -726,7 +726,7 @@ gimp_file_dialog_proc_changed (GimpFileProcView *view,
gtk_file_chooser_set_uri (chooser, s->str); gtk_file_chooser_set_uri (chooser, s->str);
basename = file_utils_uri_to_utf8_basename (s->str); basename = file_utils_uri_display_basename (s->str);
gtk_file_chooser_set_current_name (chooser, basename); gtk_file_chooser_set_current_name (chooser, basename);
g_free (basename); g_free (basename);
......
...@@ -759,7 +759,7 @@ gimp_layer_tree_view_drop_uri_list (GimpContainerTreeView *view, ...@@ -759,7 +759,7 @@ gimp_layer_tree_view_drop_uri_list (GimpContainerTreeView *view,
} }
else if (status != GIMP_PDB_CANCEL) else if (status != GIMP_PDB_CANCEL)
{ {
gchar *filename = file_utils_uri_to_utf8_filename (uri); gchar *filename = file_utils_uri_display_name (uri);
g_message (_("Opening '%s' failed:\n\n%s"), g_message (_("Opening '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
......
...@@ -481,9 +481,8 @@ gimp_thumb_box_set_uri (GimpThumbBox *box, ...@@ -481,9 +481,8 @@ gimp_thumb_box_set_uri (GimpThumbBox *box,
if (uri) if (uri)
{ {
gchar *basename; gchar *basename = file_utils_uri_display_basename (uri);
basename = file_utils_uri_to_utf8_basename (uri);
gtk_label_set_text (GTK_LABEL (box->filename), basename); gtk_label_set_text (GTK_LABEL (box->filename), basename);
g_free (basename); g_free (basename);
} }
...@@ -707,7 +706,7 @@ gimp_thumb_box_create_thumbnail (GimpThumbBox *box, ...@@ -707,7 +706,7 @@ gimp_thumb_box_create_thumbnail (GimpThumbBox *box,
thumb = box->imagefile->thumbnail; thumb = box->imagefile->thumbnail;
basename = file_utils_uri_to_utf8_basename (uri); basename = file_utils_uri_display_basename (uri);
gtk_label_set_text (GTK_LABEL (box->filename), basename); gtk_label_set_text (GTK_LABEL (box->filename), basename);
g_free (basename); g_free (basename);
......
...@@ -152,7 +152,7 @@ gimp_toolbox_drop_uri_list (GtkWidget *widget, ...@@ -152,7 +152,7 @@ gimp_toolbox_drop_uri_list (GtkWidget *widget,
if (! gimage && status != GIMP_PDB_CANCEL) if (! gimage && status != GIMP_PDB_CANCEL)
{ {
gchar *filename = file_utils_uri_to_utf8_filename (uri); gchar *filename = file_utils_uri_display_name (uri);
g_message (_("Opening '%s' failed:\n\n%s"), g_message (_("Opening '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
......
...@@ -939,7 +939,7 @@ toolbox_paste_received (GtkClipboard *clipboard, ...@@ -939,7 +939,7 @@ toolbox_paste_received (GtkClipboard *clipboard,
if (! image && status != GIMP_PDB_CANCEL) if (! image && status != GIMP_PDB_CANCEL)
{ {
gchar *filename = file_utils_uri_to_utf8_filename (copy); gchar *filename = file_utils_uri_display_name (copy);
g_message (_("Opening '%s' failed:\n\n%s"), g_message (_("Opening '%s' failed:\n\n%s"),
filename, error->message); filename, error->message);
......
...@@ -346,7 +346,7 @@ gimp_viewable_dialog_name_changed (GimpObject *object, ...@@ -346,7 +346,7 @@ gimp_viewable_dialog_name_changed (GimpObject *object,