[gimp] app: use gimp_file_get_utf8_name() in the code ported to GFile earlier



commit 20032907e0ce383b7167079ab1c50cb9fceb5090
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jul 1 14:25:37 2014 +0200

    app: use gimp_file_get_utf8_name() in the code ported to GFile earlier

 app/core/gimpbrush-load.c          |  232 ++++++++++++++++++------------------
 app/core/gimpbrush-load.h          |    2 +-
 app/core/gimpbrushgenerated-load.c |   19 ++--
 app/core/gimpbrushgenerated-save.c |    6 +-
 app/core/gimpbrushpipe-load.c      |   18 +--
 app/core/gimpcurve-save.c          |    6 +-
 app/core/gimpgradient-load.c       |   51 +++------
 app/core/gimpgradient-save.c       |    6 +-
 app/core/gimppalette-import.c      |   28 +++--
 app/core/gimppalette-load.c        |  138 +++++++++++-----------
 app/core/gimppalette-load.h        |   28 ++--
 app/core/gimppalette-save.c        |    6 +-
 app/core/gimppattern-load.c        |   28 ++---
 app/core/gimptoolpreset-load.c     |    5 +-
 14 files changed, 264 insertions(+), 309 deletions(-)
---
diff --git a/app/core/gimpbrush-load.c b/app/core/gimpbrush-load.c
index b1d579c..4e18940 100644
--- a/app/core/gimpbrush-load.c
+++ b/app/core/gimpbrush-load.c
@@ -87,36 +87,36 @@ struct _AbrSampledBrushHeader
 
 /*  local function prototypes  */
 
-static GList     * gimp_brush_load_abr_v12       (FILE         *file,
+static GList     * gimp_brush_load_abr_v12       (FILE         *f,
                                                   AbrHeader    *abr_hdr,
-                                                  const gchar  *path,
+                                                  GFile        *file,
                                                   GError      **error);
-static GList     * gimp_brush_load_abr_v6        (FILE         *file,
+static GList     * gimp_brush_load_abr_v6        (FILE         *f,
                                                   AbrHeader    *abr_hdr,
-                                                  const gchar  *path,
+                                                  GFile        *file,
                                                   GError      **error);
-static GimpBrush * gimp_brush_load_abr_brush_v12 (FILE         *file,
+static GimpBrush * gimp_brush_load_abr_brush_v12 (FILE         *f,
                                                   AbrHeader    *abr_hdr,
                                                   gint          index,
-                                                  const gchar  *path,
+                                                  GFile        *file,
                                                   GError      **error);
-static GimpBrush * gimp_brush_load_abr_brush_v6  (FILE         *file,
+static GimpBrush * gimp_brush_load_abr_brush_v6  (FILE         *f,
                                                   AbrHeader    *abr_hdr,
                                                   gint32        max_offset,
                                                   gint          index,
-                                                  const gchar  *path,
+                                                  GFile        *file,
                                                   GError      **error);
 
-static gchar       abr_read_char                 (FILE         *file);
-static gint16      abr_read_short                (FILE         *file);
-static gint32      abr_read_long                 (FILE         *file);
-static gchar     * abr_read_ucs2_text            (FILE         *file);
+static gchar       abr_read_char                 (FILE         *f);
+static gint16      abr_read_short                (FILE         *f);
+static gint32      abr_read_long                 (FILE         *f);
+static gchar     * abr_read_ucs2_text            (FILE         *f);
 static gboolean    abr_supported                 (AbrHeader    *abr_hdr,
-                                                  const gchar  *path,
+                                                  GFile        *f,
                                                   GError      **error);
 static gboolean    abr_reach_8bim_section        (FILE         *abr,
                                                   const gchar  *name);
-static gint32      abr_rle_decode                (FILE         *file,
+static gint32      abr_rle_decode                (FILE         *f,
                                                   gchar        *buffer,
                                                   gint32        height);
 
@@ -140,19 +140,19 @@ gimp_brush_load (GimpContext  *context,
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   fd = g_open (path, O_RDONLY | _O_BINARY, 0);
+  g_free (path);
+
   if (fd == -1)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for reading: %s"),
-                   gimp_filename_to_utf8 (path), g_strerror (errno));
-      g_free (path);
+                   gimp_file_get_utf8_name (file), g_strerror (errno));
       return NULL;
     }
 
-  brush = gimp_brush_load_brush (context, fd, path, error);
+  brush = gimp_brush_load_brush (context, file, fd, error);
 
   close (fd);
-  g_free (path);
 
   if (! brush)
     return NULL;
@@ -162,8 +162,8 @@ gimp_brush_load (GimpContext  *context,
 
 GimpBrush *
 gimp_brush_load_brush (GimpContext  *context,
+                       GFile        *file,
                        gint          fd,
-                       const gchar  *path,
                        GError      **error)
 {
   GimpBrush   *brush;
@@ -175,7 +175,7 @@ gimp_brush_load_brush (GimpContext  *context,
   gssize       i, size;
   gboolean     success = TRUE;
 
-  g_return_val_if_fail (path != NULL, NULL);
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
   g_return_val_if_fail (fd != -1, NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
@@ -187,7 +187,7 @@ gimp_brush_load_brush (GimpContext  *context,
                              "Could not read %d bytes from '%s': %s",
                              (gint) sizeof (header)),
                    (gint) sizeof (header),
-                   gimp_filename_to_utf8 (path), g_strerror (errno));
+                   gimp_file_get_utf8_name (file), g_strerror (errno));
       return NULL;
     }
 
@@ -207,7 +207,7 @@ gimp_brush_load_brush (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in brush file '%s': "
                      "Width = 0."),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
       return NULL;
     }
 
@@ -216,7 +216,7 @@ gimp_brush_load_brush (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in brush file '%s': "
                      "Height = 0."),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
       return NULL;
     }
 
@@ -225,7 +225,7 @@ gimp_brush_load_brush (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in brush file '%s': "
                      "Bytes = 0."),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
       return NULL;
     }
 
@@ -249,7 +249,7 @@ gimp_brush_load_brush (GimpContext  *context,
           g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                        _("Fatal parse error in brush file '%s': "
                          "Unknown depth %d."),
-                       gimp_filename_to_utf8 (path), header.bytes);
+                       gimp_file_get_utf8_name (file), header.bytes);
           return NULL;
         }
       /*  fallthrough  */
@@ -262,7 +262,7 @@ gimp_brush_load_brush (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in brush file '%s': "
                      "Unknown version %d."),
-                   gimp_filename_to_utf8 (path), header.version);
+                   gimp_file_get_utf8_name (file), header.version);
       return NULL;
     }
 
@@ -278,14 +278,14 @@ gimp_brush_load_brush (GimpContext  *context,
           g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                        _("Fatal parse error in brush file '%s': "
                          "File appears truncated."),
-                       gimp_filename_to_utf8 (path));
+                       gimp_file_get_utf8_name (file));
           g_free (name);
           return NULL;
         }
 
       utf8 = gimp_any_to_utf8 (name, -1,
                                _("Invalid UTF-8 string in brush file '%s'."),
-                               gimp_filename_to_utf8 (path));
+                               gimp_file_get_utf8_name (file));
       g_free (name);
       name = utf8;
     }
@@ -363,7 +363,7 @@ gimp_brush_load_brush (GimpContext  *context,
                      "GIMP brushes must be GRAY or RGBA.\n"
                      "This might be an obsolete GIMP brush file, try "
                      "loading it as image and save it again."),
-                   gimp_filename_to_utf8 (path), header.bytes);
+                   gimp_file_get_utf8_name (file), header.bytes);
       return NULL;
       break;
 
@@ -406,7 +406,7 @@ gimp_brush_load_brush (GimpContext  *context,
                    _("Fatal parse error in brush file '%s': "
                      "Unsupported brush depth %d\n"
                      "GIMP brushes must be GRAY or RGBA."),
-                   gimp_filename_to_utf8 (path), header.bytes);
+                   gimp_file_get_utf8_name (file), header.bytes);
       return NULL;
     }
 
@@ -416,7 +416,7 @@ gimp_brush_load_brush (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in brush file '%s': "
                      "File appears truncated."),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
       return NULL;
     }
 
@@ -447,31 +447,32 @@ gimp_brush_load_abr (GimpContext  *context,
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   f = g_fopen (path, "rb");
+  g_free (path);
+
   if (! f)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for reading: %s"),
-                   gimp_filename_to_utf8 (path), g_strerror (errno));
-      g_free (path);
+                   gimp_file_get_utf8_name (file), g_strerror (errno));
       return NULL;
     }
 
   abr_hdr.version = abr_read_short (f);
   abr_hdr.count   = abr_read_short (f); /* sub-version for ABR v6 */
 
-  if (abr_supported (&abr_hdr, path, error))
+  if (abr_supported (&abr_hdr, file, error))
     {
       switch (abr_hdr.version)
         {
         case 1:
         case 2:
           brush_list = gimp_brush_load_abr_v12 (f, &abr_hdr,
-                                                path, error);
+                                                file, error);
           break;
 
         case 6:
           brush_list = gimp_brush_load_abr_v6 (f, &abr_hdr,
-                                               path, error);
+                                               file, error);
         }
     }
 
@@ -481,9 +482,7 @@ gimp_brush_load_abr (GimpContext  *context,
     g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                  _("Fatal parse error in brush file '%s': "
                    "unable to decode abr format version %d."),
-                 gimp_filename_to_utf8 (path), abr_hdr.version);
-
-  g_free (path);
+                 gimp_file_get_utf8_name (file), abr_hdr.version);
 
   return g_list_reverse (brush_list);
 }
@@ -492,10 +491,10 @@ gimp_brush_load_abr (GimpContext  *context,
 /*  private functions  */
 
 static GList *
-gimp_brush_load_abr_v12 (FILE         *file,
-                         AbrHeader    *abr_hdr,
-                         const gchar  *path,
-                         GError      **error)
+gimp_brush_load_abr_v12 (FILE       *f,
+                         AbrHeader  *abr_hdr,
+                         GFile      *file,
+                         GError    **error)
 {
   GList *brush_list = NULL;
   gint   i;
@@ -505,8 +504,8 @@ gimp_brush_load_abr_v12 (FILE         *file,
       GimpBrush *brush;
       GError    *my_error = NULL;
 
-      brush = gimp_brush_load_abr_brush_v12 (file, abr_hdr, i,
-                                             path, &my_error);
+      brush = gimp_brush_load_abr_brush_v12 (f, abr_hdr, i,
+                                             file, &my_error);
 
       /*  a NULL brush without an error means an unsupported brush
        *  type was encountered, silently skip it and try the next one
@@ -527,29 +526,29 @@ gimp_brush_load_abr_v12 (FILE         *file,
 }
 
 static GList *
-gimp_brush_load_abr_v6 (FILE         *file,
-                        AbrHeader    *abr_hdr,
-                        const gchar  *path,
-                        GError      **error)
+gimp_brush_load_abr_v6 (FILE       *f,
+                        AbrHeader  *abr_hdr,
+                        GFile      *file,
+                        GError    **error)
 {
   GList  *brush_list = NULL;
   gint32  sample_section_size;
   gint32  sample_section_end;
   gint    i = 1;
 
-  if (! abr_reach_8bim_section (file, "samp"))
+  if (! abr_reach_8bim_section (f, "samp"))
     return brush_list;
 
-  sample_section_size = abr_read_long (file);
-  sample_section_end  = sample_section_size + ftell (file);
+  sample_section_size = abr_read_long (f);
+  sample_section_end  = sample_section_size + ftell (f);
 
-  while (ftell (file) < sample_section_end)
+  while (ftell (f) < sample_section_end)
     {
       GimpBrush *brush;
       GError    *my_error = NULL;
 
-      brush = gimp_brush_load_abr_brush_v6 (file, abr_hdr, sample_section_end,
-                                            i, path, &my_error);
+      brush = gimp_brush_load_abr_brush_v6 (f, abr_hdr, sample_section_end,
+                                            i, file, &my_error);
 
       /*  a NULL brush without an error means an unsupported brush
        *  type was encountered, silently skip it and try the next one
@@ -572,20 +571,17 @@ gimp_brush_load_abr_v6 (FILE         *file,
 }
 
 static GimpBrush *
-gimp_brush_load_abr_brush_v12 (FILE         *file,
-                               AbrHeader    *abr_hdr,
-                               gint          index,
-                               const gchar  *path,
-                               GError      **error)
+gimp_brush_load_abr_brush_v12 (FILE       *f,
+                               AbrHeader  *abr_hdr,
+                               gint        index,
+                               GFile      *file,
+                               GError    **error)
 {
   GimpBrush      *brush = NULL;
   AbrBrushHeader  abr_brush_hdr;
 
-  g_return_val_if_fail (path != NULL, NULL);
-  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
-  abr_brush_hdr.type = abr_read_short (file);
-  abr_brush_hdr.size = abr_read_long (file);
+  abr_brush_hdr.type = abr_read_short (f);
+  abr_brush_hdr.size = abr_read_long (f);
 
   /*  g_print(" + BRUSH\n | << type: %i  block size: %i bytes\n",
    *          abr_brush_hdr.type, abr_brush_hdr.size);
@@ -601,7 +597,7 @@ gimp_brush_load_abr_brush_v12 (FILE         *file,
        * types -akl
        */
       g_printerr ("WARNING: computed brush unsupported, skipping.\n");
-      fseek (file, abr_brush_hdr.size, SEEK_CUR);
+      fseek (f, abr_brush_hdr.size, SEEK_CUR);
       break;
 
     case 2: /* sampled brush */
@@ -617,21 +613,21 @@ gimp_brush_load_abr_brush_v12 (FILE         *file,
         gchar                 *tmp;
         gshort                 compress;
 
-        abr_sampled_brush_hdr.misc    = abr_read_long (file);
-        abr_sampled_brush_hdr.spacing = abr_read_short (file);
+        abr_sampled_brush_hdr.misc    = abr_read_long (f);
+        abr_sampled_brush_hdr.spacing = abr_read_short (f);
 
         if (abr_hdr->version == 2)
-          sample_name = abr_read_ucs2_text (file);
+          sample_name = abr_read_ucs2_text (f);
 
-        abr_sampled_brush_hdr.antialiasing = abr_read_char (file);
+        abr_sampled_brush_hdr.antialiasing = abr_read_char (f);
 
         for (i = 0; i < 4; i++)
-          abr_sampled_brush_hdr.bounds[i] = abr_read_short (file);
+          abr_sampled_brush_hdr.bounds[i] = abr_read_short (f);
 
         for (i = 0; i < 4; i++)
-          abr_sampled_brush_hdr.bounds_long[i] = abr_read_long (file);
+          abr_sampled_brush_hdr.bounds_long[i] = abr_read_long (f);
 
-        abr_sampled_brush_hdr.depth = abr_read_short (file);
+        abr_sampled_brush_hdr.depth = abr_read_short (f);
 
         height = (abr_sampled_brush_hdr.bounds_long[2] -
                   abr_sampled_brush_hdr.bounds_long[0]); /* bottom - top */
@@ -650,11 +646,11 @@ gimp_brush_load_abr_brush_v12 (FILE         *file,
             g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                          _("Fatal parse error in brush file '%s': "
                            "Wide brushes are not supported."),
-                         gimp_filename_to_utf8 (path));
+                         gimp_file_get_utf8_name (file));
             return NULL;
           }
 
-        tmp = g_filename_display_basename (path);
+        tmp = g_path_get_basename (gimp_file_get_utf8_name (file));
         if (! sample_name)
           {
             /* build name from filename and index */
@@ -687,7 +683,7 @@ gimp_brush_load_abr_brush_v12 (FILE         *file,
         mask = gimp_temp_buf_get_data (brush->mask);
         size = width * height * bytes;
 
-        compress = abr_read_char (file);
+        compress = abr_read_char (f);
 
         /* g_print(" | << size: %dx%d %d bit (%d bytes) %s\n",
          *         width, height, abr_sampled_brush_hdr.depth, size,
@@ -695,15 +691,15 @@ gimp_brush_load_abr_brush_v12 (FILE         *file,
          */
 
         if (! compress)
-          fread (mask, size, 1, file);
+          fread (mask, size, 1, f);
         else
-          abr_rle_decode (file, (gchar *) mask, height);
+          abr_rle_decode (f, (gchar *) mask, height);
       }
       break;
 
     default:
       g_printerr ("WARNING: unknown brush type, skipping.\n");
-      fseek (file, abr_brush_hdr.size, SEEK_CUR);
+      fseek (f, abr_brush_hdr.size, SEEK_CUR);
       break;
     }
 
@@ -711,12 +707,12 @@ gimp_brush_load_abr_brush_v12 (FILE         *file,
 }
 
 static GimpBrush *
-gimp_brush_load_abr_brush_v6 (FILE         *file,
-                              AbrHeader    *abr_hdr,
-                              gint32        max_offset,
-                              gint          index,
-                              const gchar  *path,
-                              GError      **error)
+gimp_brush_load_abr_brush_v6 (FILE       *f,
+                              AbrHeader  *abr_hdr,
+                              gint32      max_offset,
+                              gint        index,
+                              GFile      *file,
+                              GError    **error)
 {
   GimpBrush *brush = NULL;
   guchar    *mask;
@@ -736,43 +732,43 @@ gimp_brush_load_abr_brush_v6 (FILE         *file,
   gchar     *name;
   gint       r;
 
-  brush_size = abr_read_long (file);
+  brush_size = abr_read_long (f);
   brush_end = brush_size;
 
   /* complement to 4 */
   while (brush_end % 4 != 0)
     brush_end++;
 
-  next_brush = ftell (file) + brush_end;
+  next_brush = ftell (f) + brush_end;
 
   if (abr_hdr->count == 1)
     /* discard key and short coordinates and unknown short */
-    r = fseek (file, 47, SEEK_CUR);
+    r = fseek (f, 47, SEEK_CUR);
   else
     /* discard key and unknown bytes */
-    r = fseek (file, 301, SEEK_CUR);
+    r = fseek (f, 301, SEEK_CUR);
 
   if (r == -1)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in brush file '%s': "
                      "File appears truncated."),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
       return NULL;
     }
 
-  top      = abr_read_long (file);
-  left     = abr_read_long (file);
-  bottom   = abr_read_long (file);
-  right    = abr_read_long (file);
-  depth    = abr_read_short (file);
-  compress = abr_read_char (file);
+  top      = abr_read_long (f);
+  left     = abr_read_long (f);
+  bottom   = abr_read_long (f);
+  right    = abr_read_long (f);
+  depth    = abr_read_short (f);
+  compress = abr_read_char (f);
 
   width  = right - left;
   height = bottom - top;
   size   = width * (depth >> 3) * height;
 
-  tmp = g_filename_display_basename (path);
+  tmp = g_path_get_basename (gimp_file_get_utf8_name (file));
   name = g_strdup_printf ("%s-%03d", tmp, index);
   g_free (tmp);
 
@@ -797,43 +793,43 @@ gimp_brush_load_abr_brush_v6 (FILE         *file,
   /* data decoding */
   if (! compress)
     /* not compressed - read raw bytes as brush data */
-    fread (mask, size, 1, file);
+    fread (mask, size, 1, f);
   else
-    abr_rle_decode (file, (gchar *) mask, height);
+    abr_rle_decode (f, (gchar *) mask, height);
 
-  fseek (file, next_brush, SEEK_SET);
+  fseek (f, next_brush, SEEK_SET);
 
   return brush;
 }
 
 static gchar
-abr_read_char (FILE *file)
+abr_read_char (FILE *f)
 {
-  return fgetc (file);
+  return fgetc (f);
 }
 
 static gint16
-abr_read_short (FILE *file)
+abr_read_short (FILE *f)
 {
   gint16 val;
 
-  fread (&val, sizeof (val), 1, file);
+  fread (&val, sizeof (val), 1, f);
 
   return GINT16_FROM_BE (val);
 }
 
 static gint32
-abr_read_long (FILE *file)
+abr_read_long (FILE *f)
 {
   gint32 val;
 
-  fread (&val, sizeof (val), 1, file);
+  fread (&val, sizeof (val), 1, f);
 
   return GINT32_FROM_BE (val);
 }
 
 static gchar *
-abr_read_ucs2_text (FILE *file)
+abr_read_ucs2_text (FILE *f)
 {
   gchar *name_ucs2;
   gchar *name_utf8;
@@ -846,14 +842,14 @@ abr_read_ucs2_text (FILE *file)
    *   data : zero terminated UCS-2 string
    */
 
-  len = 2 * abr_read_long (file);
+  len = 2 * abr_read_long (f);
   if (len <= 0)
     return NULL;
 
   name_ucs2 = g_new (gchar, len);
 
   for (i = 0; i < len; i++)
-    name_ucs2[i] = abr_read_char (file);
+    name_ucs2[i] = abr_read_char (f);
 
   name_utf8 = g_convert (name_ucs2, len,
                          "UTF-8", "UCS-2BE",
@@ -865,9 +861,9 @@ abr_read_ucs2_text (FILE *file)
 }
 
 static gboolean
-abr_supported (AbrHeader    *abr_hdr,
-               const gchar  *path,
-               GError      **error)
+abr_supported (AbrHeader  *abr_hdr,
+               GFile      *file,
+               GError    **error)
 {
   switch (abr_hdr->version)
     {
@@ -885,7 +881,7 @@ abr_supported (AbrHeader    *abr_hdr,
         g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                      _("Fatal parse error in brush file '%s': "
                        "unable to decode abr format version %d."),
-                     gimp_filename_to_utf8 (path),
+                     gimp_file_get_utf8_name (file),
 
                      /* horrid subversion display, but better than
                       * having yet another translatable string for
@@ -935,7 +931,7 @@ abr_reach_8bim_section (FILE        *abr,
 }
 
 static gint32
-abr_rle_decode (FILE   *file,
+abr_rle_decode (FILE   *f,
                 gchar  *buffer,
                 gint32  height)
 {
@@ -947,14 +943,14 @@ abr_rle_decode (FILE   *file,
   /* read compressed size foreach scanline */
   cscanline_len = g_new0 (gshort, height);
   for (i = 0; i < height; i++)
-    cscanline_len[i] = abr_read_short (file);
+    cscanline_len[i] = abr_read_short (f);
 
   /* unpack each scanline data */
   for (i = 0; i < height; i++)
     {
       for (j = 0; j < cscanline_len[i];)
         {
-          gint32 n = abr_read_char (file);
+          gint32 n = abr_read_char (f);
 
           j++;
 
@@ -969,7 +965,7 @@ abr_rle_decode (FILE   *file,
                 continue;
 
               n = -n + 1;
-              ch = abr_read_char (file);
+              ch = abr_read_char (f);
               j++;
 
               for (c = 0; c < n; c++, data++)
@@ -980,7 +976,7 @@ abr_rle_decode (FILE   *file,
               /* read the following n + 1 chars (no compr) */
 
               for (c = 0; c < n + 1; c++, j++, data++)
-                *data = abr_read_char (file);
+                *data = abr_read_char (f);
             }
         }
     }
diff --git a/app/core/gimpbrush-load.h b/app/core/gimpbrush-load.h
index bf7931f..9865811 100644
--- a/app/core/gimpbrush-load.h
+++ b/app/core/gimpbrush-load.h
@@ -29,8 +29,8 @@ GList     * gimp_brush_load        (GimpContext  *context,
                                     GFile        *file,
                                     GError      **error);
 GimpBrush * gimp_brush_load_brush  (GimpContext  *context,
+                                    GFile        *file,
                                     gint          fd,
-                                    const gchar  *path,
                                     GError      **error);
 
 GList     * gimp_brush_load_abr    (GimpContext  *context,
diff --git a/app/core/gimpbrushgenerated-load.c b/app/core/gimpbrushgenerated-load.c
index ba9a5f3..dd8f295 100644
--- a/app/core/gimpbrushgenerated-load.c
+++ b/app/core/gimpbrushgenerated-load.c
@@ -69,12 +69,13 @@ gimp_brush_generated_load (GimpContext  *context,
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   f = g_fopen (path, "rb");
+  g_free (path);
+
   if (! f)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for reading: %s"),
-                   gimp_filename_to_utf8 (path), g_strerror (errno));
-      g_free (path);
+                   gimp_file_get_utf8_name (file), g_strerror (errno));
       return NULL;
     }
 
@@ -89,7 +90,7 @@ gimp_brush_generated_load (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in brush file '%s': "
                      "Not a GIMP brush file."),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
       goto failed;
     }
 
@@ -106,7 +107,7 @@ gimp_brush_generated_load (GimpContext  *context,
           g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                        _("Fatal parse error in brush file '%s': "
                          "Unknown GIMP brush version in line %d."),
-                       gimp_filename_to_utf8 (path), linenum);
+                       gimp_file_get_utf8_name (file), linenum);
           goto failed;
         }
       else
@@ -129,7 +130,7 @@ gimp_brush_generated_load (GimpContext  *context,
 
   name = gimp_any_to_utf8 (string, -1,
                            _("Invalid UTF-8 string in brush file '%s'."),
-                           gimp_filename_to_utf8 (path));
+                           gimp_file_get_utf8_name (file));
 
   if (have_shape)
     {
@@ -152,7 +153,7 @@ gimp_brush_generated_load (GimpContext  *context,
           g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                        _("Fatal parse error in brush file '%s': "
                          "Unknown GIMP brush shape in line %d."),
-                       gimp_filename_to_utf8 (path), linenum);
+                       gimp_file_get_utf8_name (file), linenum);
           goto failed;
         }
 
@@ -212,8 +213,6 @@ gimp_brush_generated_load (GimpContext  *context,
 
   brush->spacing = spacing;
 
-  g_free (path);
-
   return g_list_prepend (NULL, brush);
 
  failed:
@@ -234,12 +233,10 @@ gimp_brush_generated_load (GimpContext  *context,
 
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Error while reading brush file '%s': %s"),
-                   gimp_filename_to_utf8 (path), msg);
+                   gimp_file_get_utf8_name (file), msg);
 
       g_free (msg);
     }
 
-  g_free (path);
-
   return NULL;
 }
diff --git a/app/core/gimpbrushgenerated-save.c b/app/core/gimpbrushgenerated-save.c
index 661640c..4cd8187 100644
--- a/app/core/gimpbrushgenerated-save.c
+++ b/app/core/gimpbrushgenerated-save.c
@@ -56,19 +56,17 @@ gimp_brush_generated_save (GimpData  *data,
 
   path = g_file_get_path (gimp_data_get_file (data));
   file = g_fopen (path, "wb");
+  g_free (path);
 
   if (! file)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for writing: %s"),
-                   gimp_filename_to_utf8 (path),
+                   gimp_file_get_utf8_name (gimp_data_get_file (data)),
                    g_strerror (errno));
-      g_free (path);
       return FALSE;
     }
 
-  g_free (path);
-
   /* write magic header */
   fprintf (file, "GIMP-VBR\n");
 
diff --git a/app/core/gimpbrushpipe-load.c b/app/core/gimpbrushpipe-load.c
index bc22fad..39ddbc2 100644
--- a/app/core/gimpbrushpipe-load.c
+++ b/app/core/gimpbrushpipe-load.c
@@ -77,12 +77,13 @@ gimp_brush_pipe_load (GimpContext  *context,
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   fd = g_open (path, O_RDONLY | _O_BINARY, 0);
+  g_free (path);
+
   if (fd == -1)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for reading: %s"),
-                   gimp_filename_to_utf8 (path), g_strerror (errno));
-      g_free (path);
+                   gimp_file_get_utf8_name (file), g_strerror (errno));
       return NULL;
     }
 
@@ -98,7 +99,7 @@ gimp_brush_pipe_load (GimpContext  *context,
       gchar *utf8 =
         gimp_any_to_utf8 (buffer->str, buffer->len,
                           _("Invalid UTF-8 string in brush file '%s'."),
-                          gimp_filename_to_utf8 (path));
+                          gimp_file_get_utf8_name (file));
 
       pipe = g_object_new (GIMP_TYPE_BRUSH_PIPE,
                            "name",      utf8,
@@ -115,9 +116,8 @@ gimp_brush_pipe_load (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in brush file '%s': "
                      "File is corrupt."),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
       close (fd);
-      g_free (path);
       return NULL;
     }
 
@@ -136,9 +136,8 @@ gimp_brush_pipe_load (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in brush file '%s': "
                      "File is corrupt."),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
       close (fd);
-      g_free (path);
       g_object_unref (pipe);
       g_string_free (buffer, TRUE);
       return NULL;
@@ -218,7 +217,7 @@ gimp_brush_pipe_load (GimpContext  *context,
       GError *my_error = NULL;
 
       pipe->brushes[pipe->n_brushes] = gimp_brush_load_brush (context,
-                                                              fd, path,
+                                                              file, fd,
                                                               &my_error);
 
       if (pipe->brushes[pipe->n_brushes])
@@ -230,7 +229,6 @@ gimp_brush_pipe_load (GimpContext  *context,
         {
           g_propagate_error (error, my_error);
           close (fd);
-          g_free (path);
           g_object_unref (pipe);
           return NULL;
         }
@@ -250,7 +248,5 @@ gimp_brush_pipe_load (GimpContext  *context,
   GIMP_BRUSH (pipe)->mask     = pipe->current->mask;
   GIMP_BRUSH (pipe)->pixmap   = pipe->current->pixmap;
 
-  g_free (path);
-
   return g_list_prepend (NULL, pipe);
 }
diff --git a/app/core/gimpcurve-save.c b/app/core/gimpcurve-save.c
index 59563a0..8f5f029 100644
--- a/app/core/gimpcurve-save.c
+++ b/app/core/gimpcurve-save.c
@@ -48,19 +48,17 @@ gimp_curve_save (GimpData  *data,
 
   path = g_file_get_path (gimp_data_get_file (data));
   file = g_fopen (path, "wb");
+  g_free (path);
 
   if (! file)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for writing: %s"),
-                   gimp_filename_to_utf8 (path),
+                   gimp_file_get_utf8_name (gimp_data_get_file (data)),
                    g_strerror (errno));
-      g_free (path);
       return FALSE;
     }
 
-  g_free (path);
-
   /* FIXME: write curve */
 
   fclose (file);
diff --git a/app/core/gimpgradient-load.c b/app/core/gimpgradient-load.c
index a2204cf..05651e2 100644
--- a/app/core/gimpgradient-load.c
+++ b/app/core/gimpgradient-load.c
@@ -61,12 +61,13 @@ gimp_gradient_load (GimpContext  *context,
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   f = g_fopen (path, "rb");
+  g_free (path);
+
   if (! f)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for reading: %s"),
-                   gimp_filename_to_utf8 (path), g_strerror (errno));
-      g_free (path);
+                   gimp_file_get_utf8_name (file), g_strerror (errno));
       return NULL;
     }
 
@@ -76,9 +77,8 @@ gimp_gradient_load (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in gradient file '%s': "
                      "Read error in line %d."),
-                   gimp_filename_to_utf8 (path), linenum);
+                   gimp_file_get_utf8_name (file), linenum);
       fclose (f);
-      g_free (path);
       return NULL;
     }
 
@@ -87,9 +87,8 @@ gimp_gradient_load (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in gradient file '%s': "
                      "Not a GIMP gradient file."),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
       fclose (f);
-      g_free (path);
       return NULL;
     }
 
@@ -103,9 +102,8 @@ gimp_gradient_load (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in gradient file '%s': "
                      "Read error in line %d."),
-                   gimp_filename_to_utf8 (path), linenum);
+                   gimp_file_get_utf8_name (file), linenum);
       fclose (f);
-      g_free (path);
       g_object_unref (gradient);
       return NULL;
     }
@@ -116,7 +114,7 @@ gimp_gradient_load (GimpContext  *context,
 
       utf8 = gimp_any_to_utf8 (g_strstrip (line + strlen ("Name: ")), -1,
                                _("Invalid UTF-8 string in gradient file '%s'."),
-                               gimp_filename_to_utf8 (path));
+                               gimp_file_get_utf8_name (file));
       gimp_object_take_name (GIMP_OBJECT (gradient), utf8);
 
       linenum++;
@@ -125,9 +123,8 @@ gimp_gradient_load (GimpContext  *context,
           g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                        _("Fatal parse error in gradient file '%s': "
                          "Read error in line %d."),
-                       gimp_filename_to_utf8 (path), linenum);
+                       gimp_file_get_utf8_name (file), linenum);
           fclose (f);
-          g_free (path);
           g_object_unref (gradient);
           return NULL;
         }
@@ -135,7 +132,7 @@ gimp_gradient_load (GimpContext  *context,
   else /* old gradient format */
     {
       gimp_object_take_name (GIMP_OBJECT (gradient),
-                             g_filename_display_basename (path));
+                             g_path_get_basename (gimp_file_get_utf8_name (file)));
     }
 
   num_segments = atoi (line);
@@ -145,10 +142,9 @@ gimp_gradient_load (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in gradient file '%s': "
                      "File is corrupt in line %d."),
-                   gimp_filename_to_utf8 (path), linenum);
+                   gimp_file_get_utf8_name (file), linenum);
       g_object_unref (gradient);
       fclose (f);
-      g_free (path);
       return NULL;
     }
 
@@ -178,9 +174,8 @@ gimp_gradient_load (GimpContext  *context,
           g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                        _("Fatal parse error in gradient file '%s': "
                          "Read error in line %d."),
-                       gimp_filename_to_utf8 (path), linenum);
+                       gimp_file_get_utf8_name (file), linenum);
           fclose (f);
-          g_free (path);
           g_object_unref (gradient);
           return NULL;
         }
@@ -229,10 +224,9 @@ gimp_gradient_load (GimpContext  *context,
               g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                            _("Fatal parse error in gradient file '%s': "
                              "Corrupt segment %d in line %d."),
-                           gimp_filename_to_utf8 (path), i, linenum);
+                           gimp_file_get_utf8_name (file), i, linenum);
               g_object_unref (gradient);
               fclose (f);
-              g_free (path);
               return NULL;
             }
         }
@@ -241,10 +235,9 @@ gimp_gradient_load (GimpContext  *context,
           g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                        _("Fatal parse error in gradient file '%s': "
                          "Corrupt segment %d in line %d."),
-                       gimp_filename_to_utf8 (path), i, linenum);
+                       gimp_file_get_utf8_name (file), i, linenum);
           g_object_unref (gradient);
           fclose (f);
-          g_free (path);
           return NULL;
         }
 
@@ -254,10 +247,9 @@ gimp_gradient_load (GimpContext  *context,
           g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                        _("Gradient file '%s' is corrupt: "
                          "Segments do not span the range 0-1."),
-                       gimp_filename_to_utf8 (path));
+                       gimp_file_get_utf8_name (file));
           g_object_unref (gradient);
           fclose (f);
-          g_free (path);
           return NULL;
         }
 
@@ -269,15 +261,13 @@ gimp_gradient_load (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Gradient file '%s' is corrupt: "
                      "Segments do not span the range 0-1."),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
       g_object_unref (gradient);
       fclose (f);
-      g_free (path);
       return NULL;
     }
 
   fclose (f);
-  g_free (path);
 
   return g_list_prepend (NULL, gradient);
 }
@@ -334,14 +324,9 @@ gimp_gradient_load_svg (GimpContext  *context,
 {
   GimpXmlParser *xml_parser;
   SvgParser      parser = { NULL, };
-  gchar         *path;
   gboolean       success;
 
   g_return_val_if_fail (G_IS_FILE (file), NULL);
-
-  path = g_file_get_path (file);
-
-  g_return_val_if_fail (g_path_is_absolute (path), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   xml_parser = gimp_xml_parser_new (&markup_parser, &parser);
@@ -354,7 +339,7 @@ gimp_gradient_load_svg (GimpContext  *context,
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("No linear gradients found in '%s'"),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
     }
   else
     {
@@ -364,7 +349,7 @@ gimp_gradient_load_svg (GimpContext  *context,
 
           (*error)->message =
             g_strdup_printf (_("Failed to import gradients from '%s': %s"),
-                             gimp_filename_to_utf8 (path), msg);
+                             gimp_file_get_utf8_name (file), msg);
 
           g_free (msg);
         }
@@ -383,8 +368,6 @@ gimp_gradient_load_svg (GimpContext  *context,
       g_list_free (parser.stops);
     }
 
-  g_free (path);
-
   return g_list_reverse (parser.gradients);
 }
 
diff --git a/app/core/gimpgradient-save.c b/app/core/gimpgradient-save.c
index 593fd8c..7598541 100644
--- a/app/core/gimpgradient-save.c
+++ b/app/core/gimpgradient-save.c
@@ -46,19 +46,17 @@ gimp_gradient_save (GimpData  *data,
 
   path = g_file_get_path (gimp_data_get_file (data));
   file = g_fopen (path, "wb");
+  g_free (path);
 
   if (! file)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for writing: %s"),
-                   gimp_filename_to_utf8 (path),
+                   gimp_file_get_utf8_name (gimp_data_get_file (data)),
                    g_strerror (errno));
-      g_free (path);
       return FALSE;
     }
 
-  g_free (path);
-
   /* File format is:
    *
    *   GIMP Gradient
diff --git a/app/core/gimppalette-import.c b/app/core/gimppalette-import.c
index c32324b..4f6d91a 100644
--- a/app/core/gimppalette-import.c
+++ b/app/core/gimppalette-import.c
@@ -499,17 +499,16 @@ gimp_palette_import_from_file (GimpContext  *context,
                                GError      **error)
 {
   GList *palette_list = NULL;
-
-  FILE  *file;
+  GFile *file;
+  FILE  *f;
 
   g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
   g_return_val_if_fail (filename != NULL, NULL);
   g_return_val_if_fail (palette_name != NULL, NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-  file = g_fopen (filename, "rb");
-
-  if (!file)
+  f = g_fopen (filename, "rb");
+  if (! f)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for reading: %s"),
@@ -517,30 +516,32 @@ gimp_palette_import_from_file (GimpContext  *context,
       return NULL;
     }
 
-  switch (gimp_palette_load_detect_format (filename, file))
+  file = g_file_new_for_path (filename);
+
+  switch (gimp_palette_load_detect_format (file, f))
     {
     case GIMP_PALETTE_FILE_FORMAT_GPL:
-      palette_list = gimp_palette_load_gpl (context, filename, file, error);
+      palette_list = gimp_palette_load_gpl (context, file, f, error);
       break;
 
     case GIMP_PALETTE_FILE_FORMAT_ACT:
-      palette_list = gimp_palette_load_act (context, filename, file, error);
+      palette_list = gimp_palette_load_act (context, file, f, error);
       break;
 
     case GIMP_PALETTE_FILE_FORMAT_RIFF_PAL:
-      palette_list = gimp_palette_load_riff (context, filename, file, error);
+      palette_list = gimp_palette_load_riff (context, file, f, error);
       break;
 
     case GIMP_PALETTE_FILE_FORMAT_PSP_PAL:
-      palette_list = gimp_palette_load_psp (context, filename, file, error);
+      palette_list = gimp_palette_load_psp (context, file, f, error);
       break;
 
     case GIMP_PALETTE_FILE_FORMAT_ACO:
-      palette_list = gimp_palette_load_aco (context, filename, file, error);
+      palette_list = gimp_palette_load_aco (context, file, f, error);
       break;
 
     case GIMP_PALETTE_FILE_FORMAT_CSS:
-      palette_list = gimp_palette_load_css (context, filename, file, error);
+      palette_list = gimp_palette_load_css (context, file, f, error);
       break;
 
     default:
@@ -551,7 +552,8 @@ gimp_palette_import_from_file (GimpContext  *context,
       break;
     }
 
-  fclose (file);
+  g_object_unref (file);
+  fclose (f);
 
   if (palette_list)
     {
diff --git a/app/core/gimppalette-load.c b/app/core/gimppalette-load.c
index dcce107..aa5bbaa 100644
--- a/app/core/gimppalette-load.c
+++ b/app/core/gimppalette-load.c
@@ -46,6 +46,7 @@
 
 #include "gimp-intl.h"
 
+
 GList *
 gimp_palette_load (GimpContext  *context,
                    GFile        *file,
@@ -63,26 +64,26 @@ gimp_palette_load (GimpContext  *context,
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   f = g_fopen (path, "rb");
+  g_free (path);
+
   if (! f)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for reading: %s"),
-                   gimp_filename_to_utf8 (path), g_strerror (errno));
-      g_free (path);
+                   gimp_file_get_utf8_name (file), g_strerror (errno));
       return NULL;
     }
 
-  glist = gimp_palette_load_gpl (context, path, f, error);
+  glist = gimp_palette_load_gpl (context, file, f, error);
   fclose (f);
 
   return glist;
 }
 
-
 GList *
 gimp_palette_load_gpl (GimpContext  *context,
-                       const gchar  *filename,
-                       FILE         *file,
+                       GFile        *file,
+                       FILE         *f,
                        GError      **error)
 {
   GimpPalette      *palette;
@@ -92,19 +93,18 @@ gimp_palette_load_gpl (GimpContext  *context,
   gint              r, g, b;
   gint              linenum;
 
-  g_return_val_if_fail (filename != NULL, NULL);
-  g_return_val_if_fail (g_path_is_absolute (filename), NULL);
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   r = g = b = 0;
 
   linenum = 1;
-  if (! fgets (str, sizeof (str), file))
+  if (! fgets (str, sizeof (str), f))
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in palette file '%s': "
                      "Read error in line %d."),
-                   gimp_filename_to_utf8 (filename), linenum);
+                   gimp_file_get_utf8_name (file), linenum);
       return NULL;
     }
 
@@ -113,7 +113,7 @@ gimp_palette_load_gpl (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in palette file '%s': "
                      "Missing magic header."),
-                   gimp_filename_to_utf8 (filename));
+                   gimp_file_get_utf8_name (file));
       return NULL;
     }
 
@@ -123,12 +123,12 @@ gimp_palette_load_gpl (GimpContext  *context,
 
   linenum++;
 
-  if (! fgets (str, sizeof (str), file))
+  if (! fgets (str, sizeof (str), f))
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in palette file '%s': "
                      "Read error in line %d."),
-                   gimp_filename_to_utf8 (filename), linenum);
+                   gimp_file_get_utf8_name (file), linenum);
       g_object_unref (palette);
       return NULL;
     }
@@ -139,16 +139,16 @@ gimp_palette_load_gpl (GimpContext  *context,
 
       utf8 = gimp_any_to_utf8 (g_strstrip (str + strlen ("Name: ")), -1,
                                _("Invalid UTF-8 string in palette file '%s'"),
-                               gimp_filename_to_utf8 (filename));
+                               gimp_file_get_utf8_name (file));
       gimp_object_take_name (GIMP_OBJECT (palette), utf8);
 
       linenum++;
-      if (! fgets (str, sizeof (str), file))
+      if (! fgets (str, sizeof (str), f))
         {
           g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                        _("Fatal parse error in palette file '%s': "
                          "Read error in line %d."),
-                       gimp_filename_to_utf8 (filename), linenum);
+                       gimp_file_get_utf8_name (file), linenum);
           g_object_unref (palette);
           return NULL;
         }
@@ -164,19 +164,19 @@ gimp_palette_load_gpl (GimpContext  *context,
               g_message (_("Reading palette file '%s': "
                            "Invalid number of columns in line %d. "
                            "Using default value."),
-                         gimp_filename_to_utf8 (filename), linenum);
+                         gimp_file_get_utf8_name (file), linenum);
               columns = 0;
             }
 
           gimp_palette_set_columns (palette, columns);
 
           linenum++;
-          if (! fgets (str, sizeof (str), file))
+          if (! fgets (str, sizeof (str), f))
             {
               g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                            _("Fatal parse error in palette file '%s': "
                              "Read error in line %d."),
-                           gimp_filename_to_utf8 (filename), linenum);
+                           gimp_file_get_utf8_name (file), linenum);
               g_object_unref (palette);
               return NULL;
             }
@@ -185,10 +185,10 @@ gimp_palette_load_gpl (GimpContext  *context,
   else /* old palette format */
     {
       gimp_object_take_name (GIMP_OBJECT (palette),
-                             g_filename_display_basename (filename));
+                             g_path_get_basename (gimp_file_get_utf8_name (file)));
     }
 
-  while (! feof (file))
+  while (! feof (f))
     {
       if (str[0] != '#' && str[0] != '\n')
         {
@@ -198,7 +198,7 @@ gimp_palette_load_gpl (GimpContext  *context,
           else
             g_message (_("Reading palette file '%s': "
                          "Missing RED component in line %d."),
-                       gimp_filename_to_utf8 (filename), linenum);
+                       gimp_file_get_utf8_name (file), linenum);
 
           tok = strtok (NULL, " \t");
           if (tok)
@@ -206,7 +206,7 @@ gimp_palette_load_gpl (GimpContext  *context,
           else
             g_message (_("Reading palette file '%s': "
                          "Missing GREEN component in line %d."),
-                       gimp_filename_to_utf8 (filename), linenum);
+                       gimp_file_get_utf8_name (file), linenum);
 
           tok = strtok (NULL, " \t");
           if (tok)
@@ -214,7 +214,7 @@ gimp_palette_load_gpl (GimpContext  *context,
           else
             g_message (_("Reading palette file '%s': "
                          "Missing BLUE component in line %d."),
-                       gimp_filename_to_utf8 (filename), linenum);
+                       gimp_file_get_utf8_name (file), linenum);
 
           /* optional name */
           tok = strtok (NULL, "\n");
@@ -224,7 +224,7 @@ gimp_palette_load_gpl (GimpContext  *context,
               b < 0 || b > 255)
             g_message (_("Reading palette file '%s': "
                          "RGB value out of range in line %d."),
-                       gimp_filename_to_utf8 (filename), linenum);
+                       gimp_file_get_utf8_name (file), linenum);
 
           /* don't call gimp_palette_add_entry here, it's rather inefficient */
           entry = g_slice_new0 (GimpPaletteEntry);
@@ -243,15 +243,15 @@ gimp_palette_load_gpl (GimpContext  *context,
         }
 
       linenum++;
-      if (! fgets (str, sizeof (str), file))
+      if (! fgets (str, sizeof (str), f))
         {
-          if (feof (file))
+          if (feof (f))
             break;
 
           g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                        _("Fatal parse error in palette file '%s': "
                          "Read error in line %d."),
-                       gimp_filename_to_utf8 (filename), linenum);
+                       gimp_file_get_utf8_name (file), linenum);
           g_object_unref (palette);
           return NULL;
         }
@@ -264,20 +264,19 @@ gimp_palette_load_gpl (GimpContext  *context,
 
 GList *
 gimp_palette_load_act (GimpContext  *context,
-                       const gchar  *filename,
-                       FILE         *file,
+                       GFile        *file,
+                       FILE         *f,
                        GError      **error)
 {
   GimpPalette *palette;
   gchar       *palette_name;
-  gint         fd = fileno (file);
+  gint         fd = fileno (f);
   guchar       color_bytes[4];
 
-  g_return_val_if_fail (filename != NULL, NULL);
-  g_return_val_if_fail (g_path_is_absolute (filename), NULL);
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-  palette_name = g_filename_display_basename (filename);
+  palette_name = g_path_get_basename (gimp_file_get_utf8_name (file));
   palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
   g_free (palette_name);
 
@@ -298,20 +297,19 @@ gimp_palette_load_act (GimpContext  *context,
 
 GList *
 gimp_palette_load_riff (GimpContext  *context,
-                        const gchar  *filename,
-                        FILE         *file,
+                        GFile        *file,
+                        FILE         *f,
                         GError      **error)
 {
   GimpPalette *palette;
   gchar       *palette_name;
-  gint         fd = fileno (file);
+  gint         fd = fileno (f);
   guchar       color_bytes[4];
 
-  g_return_val_if_fail (filename != NULL, NULL);
-  g_return_val_if_fail (g_path_is_absolute (filename), NULL);
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-  palette_name = g_filename_display_basename (filename);
+  palette_name = g_path_get_basename (gimp_file_get_utf8_name (file));
   palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
   g_free (palette_name);
 
@@ -335,13 +333,13 @@ gimp_palette_load_riff (GimpContext  *context,
 
 GList *
 gimp_palette_load_psp (GimpContext  *context,
-                       const gchar  *filename,
-                       FILE         *file,
+                       GFile        *file,
+                       FILE         *f,
                        GError      **error)
 {
   GimpPalette *palette;
   gchar       *palette_name;
-  gint         fd = fileno (file);
+  gint         fd = fileno (f);
   guchar       color_bytes[4];
   gint         number_of_colors;
   gint         data_size;
@@ -352,11 +350,10 @@ gimp_palette_load_psp (GimpContext  *context,
   gchar      **lines;
   gchar      **ascii_colors;
 
-  g_return_val_if_fail (filename != NULL, NULL);
-  g_return_val_if_fail (g_path_is_absolute (filename), NULL);
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-  palette_name = g_filename_display_basename (filename);
+  palette_name = g_path_get_basename (gimp_file_get_utf8_name (file));
   palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
   g_free (palette_name);
 
@@ -373,7 +370,7 @@ gimp_palette_load_psp (GimpContext  *context,
       if (lines[i + 1] == NULL)
         {
           g_printerr ("Premature end of file reading %s.",
-                      gimp_filename_to_utf8 (filename));
+                      gimp_file_get_utf8_name (file));
           break;
         }
 
@@ -385,7 +382,7 @@ gimp_palette_load_psp (GimpContext  *context,
           if (ascii_colors[j] == NULL)
             {
               g_printerr ("Corrupted palette file %s.",
-                          gimp_filename_to_utf8 (filename));
+                          gimp_file_get_utf8_name (file));
               color_ok = FALSE;
               break;
             }
@@ -415,13 +412,13 @@ gimp_palette_load_psp (GimpContext  *context,
 
 GList *
 gimp_palette_load_aco (GimpContext  *context,
-                       const gchar  *filename,
-                       FILE         *file,
+                       GFile        *file,
+                       FILE         *f,
                        GError      **error)
 {
   GimpPalette *palette;
   gchar       *palette_name;
-  gint         fd = fileno (file);
+  gint         fd = fileno (f);
   gint         format_version;
   gint         number_of_colors;
   gint         i;
@@ -430,8 +427,7 @@ gimp_palette_load_aco (GimpContext  *context,
   gchar        format2_preamble[4];
   gint         status;
 
-  g_return_val_if_fail (filename != NULL, NULL);
-  g_return_val_if_fail (g_path_is_absolute (filename), NULL);
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   status = read (fd, header, sizeof (header));
@@ -441,11 +437,11 @@ gimp_palette_load_aco (GimpContext  *context,
       g_set_error (error,
                    GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Could not read header from palette file '%s'"),
-                   gimp_filename_to_utf8 (filename));
+                   gimp_file_get_utf8_name (file));
       return NULL;
     }
 
-  palette_name = g_filename_display_basename (filename);
+  palette_name = g_path_get_basename (gimp_file_get_utf8_name (file));
   palette = GIMP_PALETTE (gimp_palette_new (context, palette_name));
   g_free (palette_name);
 
@@ -463,7 +459,7 @@ gimp_palette_load_aco (GimpContext  *context,
        {
           g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                        _("Fatal parse error in palette file '%s'"),
-                       gimp_filename_to_utf8 (filename));
+                       gimp_file_get_utf8_name (file));
           g_object_unref (palette);
           return NULL;
        }
@@ -537,7 +533,7 @@ gimp_palette_load_aco (GimpContext  *context,
       else
         {
           g_printerr ("Unsupported color space (%d) in ACO file %s\n",
-                      color_space, gimp_filename_to_utf8 (filename));
+                      color_space, gimp_file_get_utf8_name (file));
         }
 
       if (format_version == 2)
@@ -550,7 +546,7 @@ gimp_palette_load_aco (GimpContext  *context,
            {
              g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                           _("Fatal parse error in palette file '%s'"),
-                          gimp_filename_to_utf8 (filename));
+                          gimp_file_get_utf8_name (file));
              g_object_unref (palette);
              return NULL;
            }
@@ -569,8 +565,8 @@ gimp_palette_load_aco (GimpContext  *context,
 
 GList *
 gimp_palette_load_css (GimpContext  *context,
-                       const gchar  *filename,
-                       FILE         *file,
+                       GFile        *file,
+                       FILE         *f,
                        GError      **error)
 {
   GimpPalette *palette;
@@ -578,15 +574,14 @@ gimp_palette_load_css (GimpContext  *context,
   GRegex      *regex;
   GimpRGB      color;
 
-  g_return_val_if_fail (filename != NULL, NULL);
-  g_return_val_if_fail (g_path_is_absolute (filename), NULL);
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   regex = g_regex_new (".*color.*:(?P<param>.*);", G_REGEX_CASELESS, 0, error);
   if (! regex)
     return NULL;
 
-  name = g_filename_display_basename (filename);
+  name = g_path_get_basename (gimp_file_get_utf8_name (file));
   palette = GIMP_PALETTE (gimp_palette_new (context, name));
   g_free (name);
 
@@ -595,7 +590,7 @@ gimp_palette_load_css (GimpContext  *context,
       GMatchInfo *matches;
       gchar       buf[1024];
 
-      if (fgets (buf, sizeof (buf), file) != NULL)
+      if (fgets (buf, sizeof (buf), f) != NULL)
         {
           if (g_regex_match (regex, buf, 0, &matches))
             {
@@ -612,7 +607,7 @@ gimp_palette_load_css (GimpContext  *context,
               g_free (word);
             }
         }
-    } while (! feof (file));
+    } while (! feof (f));
 
   g_regex_unref (regex);
 
@@ -620,14 +615,14 @@ gimp_palette_load_css (GimpContext  *context,
 }
 
 GimpPaletteFileFormat
-gimp_palette_load_detect_format (const gchar *filename,
-                                 FILE        *file)
+gimp_palette_load_detect_format (GFile *file,
+                                 FILE  *f)
 {
   GimpPaletteFileFormat format = GIMP_PALETTE_FILE_FORMAT_UNKNOWN;
-  gint                  fd = fileno (file);
+  gint                  fd = fileno (f);
   gchar                 header[16];
 
-  if (fread (header, 1, sizeof (header), file) == sizeof (header))
+  if (fread (header, 1, sizeof (header), f) == sizeof (header))
     {
       if (g_str_has_prefix (header + 0, "RIFF") &&
           g_str_has_prefix (header + 8, "PAL data"))
@@ -646,7 +641,8 @@ gimp_palette_load_detect_format (const gchar *filename,
 
   if (format == GIMP_PALETTE_FILE_FORMAT_UNKNOWN)
     {
-      gchar *lower_filename = g_ascii_strdown (filename, -1);
+      gchar *lower_filename =
+        g_ascii_strdown (gimp_file_get_utf8_name (file), -1);
 
       if (g_str_has_suffix (lower_filename, ".aco"))
         {
@@ -671,7 +667,7 @@ gimp_palette_load_detect_format (const gchar *filename,
         }
     }
 
-  rewind (file);
+  rewind (f);
 
   return format;
 }
diff --git a/app/core/gimppalette-load.h b/app/core/gimppalette-load.h
index c3f4fd2..38560c5 100644
--- a/app/core/gimppalette-load.h
+++ b/app/core/gimppalette-load.h
@@ -38,32 +38,32 @@ GList               * gimp_palette_load               (GimpContext  *context,
                                                        GFile        *file,
                                                        GError      **error);
 GList               * gimp_palette_load_gpl           (GimpContext  *context,
-                                                       const gchar  *filename,
-                                                       FILE         *file,
+                                                       GFile        *file,
+                                                       FILE         *f,
                                                        GError      **error);
 GList               * gimp_palette_load_act           (GimpContext  *context,
-                                                       const gchar  *filename,
-                                                       FILE         *file,
+                                                       GFile        *file,
+                                                       FILE         *f,
                                                        GError      **error);
 GList               * gimp_palette_load_riff          (GimpContext  *context,
-                                                       const gchar  *filename,
-                                                       FILE         *file,
+                                                       GFile        *file,
+                                                       FILE         *f,
                                                        GError      **error);
 GList               * gimp_palette_load_psp           (GimpContext  *context,
-                                                       const gchar  *filename,
-                                                       FILE         *file,
+                                                       GFile        *file,
+                                                       FILE         *f,
                                                        GError      **error);
 GList               * gimp_palette_load_aco           (GimpContext  *context,
-                                                       const gchar  *filename,
-                                                       FILE         *file,
+                                                       GFile        *file,
+                                                       FILE         *f,
                                                        GError      **error);
 GList               * gimp_palette_load_css           (GimpContext  *context,
-                                                       const gchar  *filename,
-                                                       FILE         *file,
+                                                       GFile        *file,
+                                                       FILE         *f,
                                                        GError      **error);
 
-GimpPaletteFileFormat gimp_palette_load_detect_format (const gchar  *filename,
-                                                       FILE         *file);
+GimpPaletteFileFormat gimp_palette_load_detect_format (GFile        *file,
+                                                       FILE         *f);
 
 
 #endif /* __GIMP_PALETTE_H__ */
diff --git a/app/core/gimppalette-save.c b/app/core/gimppalette-save.c
index 179e237..5116a57 100644
--- a/app/core/gimppalette-save.c
+++ b/app/core/gimppalette-save.c
@@ -52,19 +52,17 @@ gimp_palette_save (GimpData  *data,
 
   path = g_file_get_path (gimp_data_get_file (data));
   file = g_fopen (path, "wb");
+  g_free (path);
 
   if (! file)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for writing: %s"),
-                   gimp_filename_to_utf8 (path),
+                   gimp_file_get_utf8_name (gimp_data_get_file (data)),
                    g_strerror (errno));
-      g_free (path);
       return FALSE;
     }
 
-  g_free (path);
-
   fprintf (file, "GIMP Palette\n");
   fprintf (file, "Name: %s\n", gimp_object_get_name (palette));
   fprintf (file, "Columns: %d\n#\n", CLAMP (gimp_palette_get_columns (palette),
diff --git a/app/core/gimppattern-load.c b/app/core/gimppattern-load.c
index bfbb790..383f983 100644
--- a/app/core/gimppattern-load.c
+++ b/app/core/gimppattern-load.c
@@ -79,12 +79,13 @@ gimp_pattern_load (GimpContext  *context,
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   fd = g_open (path, O_RDONLY | _O_BINARY, 0);
+  g_free (path);
+
   if (fd == -1)
     {
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                    _("Could not open '%s' for reading: %s"),
-                   gimp_filename_to_utf8 (path), g_strerror (errno));
-      g_free (path);
+                   gimp_file_get_utf8_name (file), g_strerror (errno));
       return NULL;
     }
 
@@ -94,7 +95,7 @@ gimp_pattern_load (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in pattern file '%s': "
                      "File appears truncated."),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
       goto error;
     }
 
@@ -113,7 +114,7 @@ gimp_pattern_load (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in pattern file '%s': "
                      "Unknown pattern format version %d."),
-                   gimp_filename_to_utf8 (path), header.version);
+                   gimp_file_get_utf8_name (file), header.version);
       goto error;
     }
 
@@ -124,7 +125,7 @@ gimp_pattern_load (GimpContext  *context,
                    _("Fatal parse error in pattern file '%s: "
                      "Unsupported pattern depth %d.\n"
                      "GIMP Patterns must be GRAY or RGB."),
-                   gimp_filename_to_utf8 (path), header.bytes);
+                   gimp_file_get_utf8_name (file), header.bytes);
       goto error;
     }
 
@@ -140,14 +141,14 @@ gimp_pattern_load (GimpContext  *context,
           g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                        _("Fatal parse error in pattern file '%s': "
                          "File appears truncated."),
-                       gimp_filename_to_utf8 (path));
+                       gimp_file_get_utf8_name (file));
           g_free (name);
           goto error;
         }
 
       utf8 = gimp_any_to_utf8 (name, -1,
                                _("Invalid UTF-8 string in pattern file '%s'."),
-                               gimp_filename_to_utf8 (path));
+                               gimp_file_get_utf8_name (file));
       g_free (name);
       name = utf8;
     }
@@ -179,12 +180,11 @@ gimp_pattern_load (GimpContext  *context,
       g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                    _("Fatal parse error in pattern file '%s': "
                      "File appears truncated."),
-                   gimp_filename_to_utf8 (path));
+                   gimp_file_get_utf8_name (file));
       goto error;
     }
 
   close (fd);
-  g_free (path);
 
   return g_list_prepend (NULL, pattern);
 
@@ -193,7 +193,6 @@ gimp_pattern_load (GimpContext  *context,
     g_object_unref (pattern);
 
   close (fd);
-  g_free (path);
 
   return NULL;
 }
@@ -216,12 +215,10 @@ gimp_pattern_load_pixbuf (GimpContext  *context,
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   pixbuf = gdk_pixbuf_new_from_file (path, error);
+  g_free (path);
 
   if (! pixbuf)
-    {
-      g_free (path);
-      return NULL;
-    }
+    return NULL;
 
   name = g_strdup (gdk_pixbuf_get_option (pixbuf, "tEXt::Title"));
 
@@ -229,7 +226,7 @@ gimp_pattern_load_pixbuf (GimpContext  *context,
     name = g_strdup (gdk_pixbuf_get_option (pixbuf, "tEXt::Comment"));
 
   if (! name)
-    name = g_filename_display_basename (path);
+    name = g_path_get_basename (gimp_file_get_utf8_name (file));
 
   pattern = g_object_new (GIMP_TYPE_PATTERN,
                           "name",      name,
@@ -240,7 +237,6 @@ gimp_pattern_load_pixbuf (GimpContext  *context,
   pattern->mask = gimp_temp_buf_new_from_pixbuf (pixbuf, NULL);
 
   g_object_unref (pixbuf);
-  g_free (path);
 
   return g_list_prepend (NULL, pattern);
 }
diff --git a/app/core/gimptoolpreset-load.c b/app/core/gimptoolpreset-load.c
index 54e332d..ee6c2d4 100644
--- a/app/core/gimptoolpreset-load.c
+++ b/app/core/gimptoolpreset-load.c
@@ -57,12 +57,9 @@ gimp_tool_preset_load (GimpContext  *context,
         }
       else
         {
-          gchar *path = g_file_get_path (file);
-
           g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
                        _("Error while parsing '%s'"),
-                       gimp_filename_to_utf8 (path));
-          g_free (path);
+                       gimp_file_get_utf8_name (file));
         }
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]