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

added utility functions file_utils_uri_to_utf8_basename() and

2002-04-14  Michael Natterer  <mitch@gimp.org>

	* app/file/file-utils.[ch]: added utility functions
	file_utils_uri_to_utf8_basename() and
	file_utils_uri_to_utf8_filename().

	* app/nav_window.c
	* app/undo_history.c
	* app/display/gimpdisplayshell.c
	* app/gui/info-window.c
	* app/gui/menus.c
	* app/gui/palette-import-dialog.c
	* app/tools/gimpbycolorselecttool.c
	* app/widgets/gimpcontainerview-utils.c: use the new functions.
parent 5e51cebc
2002-04-14 Michael Natterer <mitch@gimp.org>
* app/file/file-utils.[ch]: added utility functions
file_utils_uri_to_utf8_basename() and
file_utils_uri_to_utf8_filename().
* app/nav_window.c
* app/undo_history.c
* app/display/gimpdisplayshell.c
* app/gui/info-window.c
* app/gui/menus.c
* app/gui/palette-import-dialog.c
* app/tools/gimpbycolorselecttool.c
* app/widgets/gimpcontainerview-utils.c: use the new functions.
2002-04-14 Michael Natterer <mitch@gimp.org>
 
Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile.
......
......@@ -33,6 +33,8 @@
#include "core/gimpimage-projection.h"
#include "core/gimpunit.h"
#include "file/file-utils.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
......@@ -376,7 +378,7 @@ info_window_title (GimpDisplay *gdisp)
gchar *basename;
gchar *title;
basename = g_path_get_basename (gimp_image_get_uri (gdisp->gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gdisp->gimage));
title = g_strdup_printf (_("Info: %s-%d.%d"),
basename,
......
......@@ -34,6 +34,8 @@
#include "core/gimppalette.h"
#include "core/gimppalette-import.h"
#include "file/file-utils.h"
#include "widgets/gimpcontainermenuimpl.h"
#include "widgets/gimppreview.h"
......@@ -145,7 +147,7 @@ palette_import_image_changed (GimpContext *context,
gimp_preview_set_viewable (GIMP_PREVIEW (import_dialog->preview),
GIMP_VIEWABLE (gimage));
basename = g_path_get_basename (gimp_image_get_uri (gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage));
label = g_strdup_printf ("%s-%d", basename, gimp_image_get_ID (gimage));
g_free (basename);
......
......@@ -40,6 +40,8 @@
#include "core/gimplayermask.h"
#include "core/gimppattern.h"
#include "file/file-utils.h"
#include "widgets/gimpcolorpanel.h"
#include "widgets/gimpcursor.h"
#include "widgets/gimpdnd.h"
......@@ -756,7 +758,7 @@ gimp_display_shell_close (GimpDisplayShell *shell,
{
gchar *basename;
basename = g_path_get_basename (gimp_image_get_uri (gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage));
gimp_display_shell_close_warning_dialog (shell, basename);
......@@ -2144,7 +2146,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
{
gchar *basename;
basename = g_path_get_basename (gimp_image_get_uri (gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage));
i += print (title, title_len, i, "%s", basename);
......@@ -2153,7 +2155,15 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
break;
case 'F': /* full filename */
i += print (title, title_len, i, "%s", gimp_image_get_uri (gimage));
{
gchar *filename;
filename = file_utils_uri_to_utf8_filename (gimp_image_get_uri (gimage));
i += print (title, title_len, i, "%s", filename);
g_free (filename);
}
break;
case 'p': /* PDB id */
......
......@@ -40,6 +40,8 @@
#include "core/gimplayermask.h"
#include "core/gimppattern.h"
#include "file/file-utils.h"
#include "widgets/gimpcolorpanel.h"
#include "widgets/gimpcursor.h"
#include "widgets/gimpdnd.h"
......@@ -756,7 +758,7 @@ gimp_display_shell_close (GimpDisplayShell *shell,
{
gchar *basename;
basename = g_path_get_basename (gimp_image_get_uri (gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage));
gimp_display_shell_close_warning_dialog (shell, basename);
......@@ -2144,7 +2146,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
{
gchar *basename;
basename = g_path_get_basename (gimp_image_get_uri (gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage));
i += print (title, title_len, i, "%s", basename);
......@@ -2153,7 +2155,15 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
break;
case 'F': /* full filename */
i += print (title, title_len, i, "%s", gimp_image_get_uri (gimage));
{
gchar *filename;
filename = file_utils_uri_to_utf8_filename (gimp_image_get_uri (gimage));
i += print (title, title_len, i, "%s", filename);
g_free (filename);
}
break;
case 'p': /* PDB id */
......
......@@ -41,6 +41,8 @@
#include "core/gimpimage.h"
#include "core/gimplist.h"
#include "file/file-utils.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h"
#include "display/gimpdisplayshell.h"
......@@ -664,7 +666,7 @@ nav_dialog_title (GimpDisplay *gdisp)
gchar *basename;
gchar *title;
basename = g_path_get_basename (gimp_image_get_uri (gdisp->gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gdisp->gimage));
title = g_strdup_printf (_("Navigation: %s-%d.%d"),
basename,
......
......@@ -41,6 +41,8 @@
#include "core/gimpimage.h"
#include "core/gimplist.h"
#include "file/file-utils.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h"
#include "display/gimpdisplayshell.h"
......@@ -664,7 +666,7 @@ nav_dialog_title (GimpDisplay *gdisp)
gchar *basename;
gchar *title;
basename = g_path_get_basename (gimp_image_get_uri (gdisp->gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gdisp->gimage));
title = g_strdup_printf (_("Navigation: %s-%d.%d"),
basename,
......
......@@ -204,19 +204,75 @@ file_utils_find_proc (GSList *procs,
return file_proc_find_by_name (all_procs, uri, FALSE);
}
gchar *
file_utils_uri_to_utf8_basename (const gchar *uri)
{
gchar *filename;
gchar *basename;
g_assert (uri != NULL);
g_return_val_if_fail (uri != NULL, NULL);
filename = file_utils_uri_to_utf8_filename (uri);
if (strstr (filename, G_DIR_SEPARATOR_S))
{
basename = g_path_get_basename (filename);
g_free (filename);
return basename;
}
else if (strstr (filename, "://"))
{
basename = strrchr (uri, '/');
basename = g_strdup (basename + 1);
g_free (filename);
return basename;
}
return filename;
}
gchar *
file_utils_uri_to_utf8_filename (const gchar *uri)
{
g_return_val_if_fail (uri != NULL, NULL);
if (! strncmp (uri, "file:", strlen ("file:")))
{
gchar *filename;
filename = g_filename_from_uri (uri, NULL, NULL);
if (filename)
{
gchar *utf8;
utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
g_free (filename);
return utf8;
}
}
return g_strdup (uri);
}
/* private functions */
static PlugInProcDef *
file_proc_find_by_name (GSList *procs,
const gchar *uri,
gboolean skip_magic)
file_proc_find_by_prefix (GSList *procs,
const gchar *uri,
gboolean skip_magic)
{
GSList *p;
gchar *ext = strrchr (uri, '.');
if (ext)
ext++;
for (p = procs; p; p = g_slist_next (p))
{
......@@ -235,6 +291,26 @@ file_proc_find_by_name (GSList *procs,
}
}
return NULL;
}
static PlugInProcDef *
file_proc_find_by_name (GSList *procs,
const gchar *uri,
gboolean skip_magic)
{
PlugInProcDef *proc;
GSList *p;
gchar *ext = strrchr (uri, '.');
if (ext)
ext++;
proc = file_proc_find_by_prefix (procs, uri, skip_magic);
if (proc)
return proc;
for (p = procs; p; p = g_slist_next (p))
{
PlugInProcDef *proc = p->data;
......
......@@ -23,11 +23,13 @@
#include <stdio.h>
gchar * file_utils_filename_to_uri (Gimp *gimp,
const gchar *filename,
GError **error);
PlugInProcDef * file_utils_find_proc (GSList *procs,
const gchar *filename);
gchar * file_utils_filename_to_uri (Gimp *gimp,
const gchar *filename,
GError **error);
PlugInProcDef * file_utils_find_proc (GSList *procs,
const gchar *filename);
gchar * file_utils_uri_to_utf8_basename (const gchar *uri);
gchar * file_utils_uri_to_utf8_filename (const gchar *uri);
/* .xvpics thumbnail stuff */
......
......@@ -33,6 +33,8 @@
#include "core/gimpimage-projection.h"
#include "core/gimpunit.h"
#include "file/file-utils.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
......@@ -376,7 +378,7 @@ info_window_title (GimpDisplay *gdisp)
gchar *basename;
gchar *title;
basename = g_path_get_basename (gimp_image_get_uri (gdisp->gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gdisp->gimage));
title = g_strdup_printf (_("Info: %s-%d.%d"),
basename,
......
......@@ -34,6 +34,8 @@
#include "core/gimplist.h"
#include "core/gimptoolinfo.h"
#include "file/file-utils.h"
#include "widgets/gimpitemfactory.h"
#include "brushes-commands.h"
......@@ -2523,42 +2525,21 @@ menus_last_opened_update (GimpContainer *container,
if (g_object_get_data (G_OBJECT (widget), "gimp-imagefile") !=
(gpointer) imagefile)
{
gchar *basename;
gchar *utf8;
const gchar *uri;
gchar *filename;
gchar *basename;
basename = g_path_get_basename (GIMP_OBJECT (imagefile)->name);
uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
utf8 = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
filename = file_utils_uri_to_utf8_filename (uri);
basename = file_utils_uri_to_utf8_basename (uri);
if (utf8)
{
gtk_label_set_text (GTK_LABEL (GTK_BIN (widget)->child), utf8);
g_free (utf8);
}
else
{
gtk_label_set_text (GTK_LABEL (GTK_BIN (widget)->child),
"(broken filename)");
}
gtk_label_set_text (GTK_LABEL (GTK_BIN (widget)->child), basename);
gimp_help_set_help_data (widget, filename, NULL);
g_free (filename);
g_free (basename);
utf8 = g_filename_to_utf8 (GIMP_OBJECT (imagefile)->name, -1,
NULL, NULL, NULL);
if (utf8)
{
gimp_help_set_help_data (widget, utf8, NULL);
g_free (utf8);
}
else
{
gimp_help_set_help_data (widget,
"filename contains characters which "
"can't be converted to UFT-8",
NULL);
}
g_object_set_data (G_OBJECT (widget), "gimp-imagefile", imagefile);
gtk_widget_show (widget);
}
......
......@@ -34,6 +34,8 @@
#include "core/gimppalette.h"
#include "core/gimppalette-import.h"
#include "file/file-utils.h"
#include "widgets/gimpcontainermenuimpl.h"
#include "widgets/gimppreview.h"
......@@ -145,7 +147,7 @@ palette_import_image_changed (GimpContext *context,
gimp_preview_set_viewable (GIMP_PREVIEW (import_dialog->preview),
GIMP_VIEWABLE (gimage));
basename = g_path_get_basename (gimp_image_get_uri (gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage));
label = g_strdup_printf ("%s-%d", basename, gimp_image_get_ID (gimage));
g_free (basename);
......
......@@ -34,6 +34,8 @@
#include "core/gimplist.h"
#include "core/gimptoolinfo.h"
#include "file/file-utils.h"
#include "widgets/gimpitemfactory.h"
#include "brushes-commands.h"
......@@ -2523,42 +2525,21 @@ menus_last_opened_update (GimpContainer *container,
if (g_object_get_data (G_OBJECT (widget), "gimp-imagefile") !=
(gpointer) imagefile)
{
gchar *basename;
gchar *utf8;
const gchar *uri;
gchar *filename;
gchar *basename;
basename = g_path_get_basename (GIMP_OBJECT (imagefile)->name);
uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
utf8 = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
filename = file_utils_uri_to_utf8_filename (uri);
basename = file_utils_uri_to_utf8_basename (uri);
if (utf8)
{
gtk_label_set_text (GTK_LABEL (GTK_BIN (widget)->child), utf8);
g_free (utf8);
}
else
{
gtk_label_set_text (GTK_LABEL (GTK_BIN (widget)->child),
"(broken filename)");
}
gtk_label_set_text (GTK_LABEL (GTK_BIN (widget)->child), basename);
gimp_help_set_help_data (widget, filename, NULL);
g_free (filename);
g_free (basename);
utf8 = g_filename_to_utf8 (GIMP_OBJECT (imagefile)->name, -1,
NULL, NULL, NULL);
if (utf8)
{
gimp_help_set_help_data (widget, utf8, NULL);
g_free (utf8);
}
else
{
gimp_help_set_help_data (widget,
"filename contains characters which "
"can't be converted to UFT-8",
NULL);
}
g_object_set_data (G_OBJECT (widget), "gimp-imagefile", imagefile);
gtk_widget_show (widget);
}
......
......@@ -41,6 +41,8 @@
#include "core/gimpimage.h"
#include "core/gimplist.h"
#include "file/file-utils.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h"
#include "display/gimpdisplayshell.h"
......@@ -664,7 +666,7 @@ nav_dialog_title (GimpDisplay *gdisp)
gchar *basename;
gchar *title;
basename = g_path_get_basename (gimp_image_get_uri (gdisp->gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gdisp->gimage));
title = g_strdup_printf (_("Navigation: %s-%d.%d"),
basename,
......
......@@ -50,6 +50,8 @@
#include "core/gimpimage-projection.h"
#include "core/gimptoolinfo.h"
#include "file/file-utils.h"
#include "widgets/gimpdnd.h"
#include "display/gimpdisplay.h"
......@@ -732,7 +734,7 @@ by_color_select_draw (ByColorDialog *bcd,
gtk_widget_queue_draw (bcd->preview);
basename = g_path_get_basename (gimp_image_get_uri (gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage));
gtk_label_set_text (GTK_LABEL (bcd->gimage_name), basename);
......
......@@ -64,6 +64,8 @@
#include "core/gimpimage.h"
#include "core/gimpimage-mask.h"
#include "file/file-utils.h"
#include "display/gimpdisplay-foreach.h"
#include "gimprc.h"
......@@ -822,7 +824,7 @@ undo_history_new (GimpImage *gimage)
gchar *basename;
gchar *title;
basename = g_path_get_basename (gimp_image_get_uri (gimage));
basename = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage));
title = g_strdup_printf (_("Undo History: %s"), basename);
......
......@@ -32,6 +32,8 @@
#include "core/gimppattern.h"
#include "core/gimptoolinfo.h"
#include "file/file-utils.h"
#include "gimpcontainereditor.h"
#include "gimpcontainerview.h"
#include "gimpcontainerview-utils.h"
......@@ -210,10 +212,22 @@ gimp_container_view_image_name_func (GtkWidget *widget,
if (gimage)
{
gchar *basename;
gchar *retval;
const gchar *uri;
gchar *basename;
gchar *retval;
uri = gimp_image_get_uri (GIMP_IMAGE (gimage));
basename = file_utils_uri_to_utf8_basename (uri);
basename = g_path_get_basename (gimp_image_get_uri (gimage));
if (tooltip)
{
gchar *filename;
filename = file_utils_uri_to_utf8_filename (uri);
*tooltip = filename;
}
retval = g_strdup_printf ("%s-%d",
basename,
......@@ -221,9 +235,6 @@ gimp_container_view_image_name_func (GtkWidget *widget,
g_free (basename);
if (tooltip)
*tooltip = g_strdup (gimp_image_get_uri (gimage));
return retval;
}
}
......@@ -362,25 +373,34 @@ gimp_container_view_imagefile_name_func (GtkWidget *widget,
if (imagefile)
{
gchar *name;
const gchar *uri;
gchar *basename;
name = g_path_get_basename (GIMP_OBJECT (imagefile)->name);
uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
if (tooltip)
*tooltip = g_strdup (GIMP_OBJECT (imagefile)->name);
basename = file_utils_uri_to_utf8_basename (uri);
if (tooltip)
{
gchar *filename;
filename = file_utils_uri_to_utf8_filename (uri);
*tooltip = filename;
}
if (imagefile->width > 0 && imagefile->height > 0)
{
gchar *tmp = name;
gchar *tmp = basename;
name = g_strdup_printf ("%s (%d x %d)",
tmp,
imagefile->width,
imagefile->height);
basename = g_strdup_printf ("%s (%d x %d)",
tmp,
imagefile->width,
imagefile->height);
g_free (tmp);
}
return name;
return basename;
}
}
......
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