[gimp] pdb, plug-ins: change gimp_temp_name() to gimp_temp_file()



commit 6468fa06c7d9badbdb03c6431c4c84655d076ba4
Author: Michael Natterer <mitch gimp org>
Date:   Wed Sep 11 22:32:44 2019 +0200

    pdb, plug-ins: change gimp_temp_name() to gimp_temp_file()

 app/pdb/gimp-cmds.c                          |  33 ++---
 libgimp/gimp.def                             |  13 +-
 libgimp/gimp_pdb.c                           |  23 ++--
 libgimp/gimp_pdb.h                           |   2 +-
 pdb/groups/gimp.pdb                          |  18 +--
 plug-ins/common/file-compressor.c            | 185 ++++++++++++++++-----------
 plug-ins/common/file-mng.c                   |  28 ++--
 plug-ins/common/file-ps.c                    |  10 +-
 plug-ins/common/mail.c                       |  27 ++--
 plug-ins/file-jpeg/jpeg-save.c               |   5 +-
 plug-ins/file-raw/file-darktable.c           |  11 +-
 plug-ins/file-raw/file-rawtherapee.c         |  14 +-
 plug-ins/gfig/gfig.c                         |  11 +-
 plug-ins/screenshot/screenshot-gnome-shell.c |   9 +-
 14 files changed, 213 insertions(+), 176 deletions(-)
---
diff --git a/app/pdb/gimp-cmds.c b/app/pdb/gimp-cmds.c
index 830f4988b2..3cfdf92c33 100644
--- a/app/pdb/gimp-cmds.c
+++ b/app/pdb/gimp-cmds.c
@@ -201,7 +201,7 @@ get_parasite_list_invoker (GimpProcedure         *procedure,
 }
 
 static GimpValueArray *
-temp_name_invoker (GimpProcedure         *procedure,
+temp_file_invoker (GimpProcedure         *procedure,
                    Gimp                  *gimp,
                    GimpContext           *context,
                    GimpProgress          *progress,
@@ -211,24 +211,20 @@ temp_name_invoker (GimpProcedure         *procedure,
   gboolean success = TRUE;
   GimpValueArray *return_vals;
   const gchar *extension;
-  gchar *name = NULL;
+  GFile *file = NULL;
 
   extension = g_value_get_string (gimp_value_array_index (args, 0));
 
   if (success)
     {
-      GFile *file = gimp_get_temp_file (gimp, extension);
-
-      name = g_file_get_path (file);
-
-      g_object_unref (file);
+      file = gimp_get_temp_file (gimp, extension);
     }
 
   return_vals = gimp_procedure_get_return_values (procedure, success,
                                                   error ? *error : NULL);
 
   if (success)
-    g_value_take_string (gimp_value_array_index (return_vals, 1), name);
+    g_value_set_object (gimp_value_array_index (return_vals, 1), file);
 
   return return_vals;
 }
@@ -412,14 +408,14 @@ register_gimp_procs (GimpPDB *pdb)
   g_object_unref (procedure);
 
   /*
-   * gimp-temp-name
+   * gimp-temp-file
    */
-  procedure = gimp_procedure_new (temp_name_invoker);
+  procedure = gimp_procedure_new (temp_file_invoker);
   gimp_object_set_static_name (GIMP_OBJECT (procedure),
-                               "gimp-temp-name");
+                               "gimp-temp-file");
   gimp_procedure_set_static_help (procedure,
-                                  "Generates a unique filename.",
-                                  "Generates a unique filename using the temp path supplied in the user's 
gimprc.",
+                                  "Generates a unique temporary file.",
+                                  "Generates a unique file using the temp path supplied in the user's 
gimprc.",
                                   NULL);
   gimp_procedure_set_static_attribution (procedure,
                                          "Josh MacDonald",
@@ -433,12 +429,11 @@ register_gimp_procs (GimpPDB *pdb)
                                                        NULL,
                                                        GIMP_PARAM_READWRITE));
   gimp_procedure_add_return_value (procedure,
-                                   gimp_param_spec_string ("name",
-                                                           "name",
-                                                           "The new temp filename",
-                                                           FALSE, FALSE, FALSE,
-                                                           NULL,
-                                                           GIMP_PARAM_READWRITE));
+                                   g_param_spec_object ("file",
+                                                        "file",
+                                                        "The new temp file",
+                                                        G_TYPE_FILE,
+                                                        GIMP_PARAM_READWRITE));
   gimp_pdb_register_procedure (pdb, procedure);
   g_object_unref (procedure);
 }
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 37cd7184b3..4e606cba1a 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -385,13 +385,13 @@ EXPORTS
        gimp_image_get_component_visible
        gimp_image_get_default_new_layer_mode
        gimp_image_get_effective_color_profile
-       gimp_image_get_exported_uri
-       gimp_image_get_filename
+       gimp_image_get_exported_file
+       gimp_image_get_file
        gimp_image_get_floating_sel
        gimp_image_get_guide_orientation
        gimp_image_get_guide_position
        gimp_image_get_id
-       gimp_image_get_imported_uri
+       gimp_image_get_imported_file
        gimp_image_get_item_position
        gimp_image_get_layer_by_name
        gimp_image_get_layer_by_tattoo
@@ -409,11 +409,10 @@ EXPORTS
        gimp_image_get_thumbnail_data
        gimp_image_get_type
        gimp_image_get_unit
-       gimp_image_get_uri
        gimp_image_get_vectors
        gimp_image_get_vectors_by_name
        gimp_image_get_vectors_by_tattoo
-       gimp_image_get_xcf_uri
+       gimp_image_get_xcf_file
        gimp_image_grid_get_background_color
        gimp_image_grid_get_foreground_color
        gimp_image_grid_get_offset
@@ -470,7 +469,7 @@ EXPORTS
        gimp_image_set_colormap
        gimp_image_set_component_active
        gimp_image_set_component_visible
-       gimp_image_set_filename
+       gimp_image_set_file
        gimp_image_set_metadata
        gimp_image_set_resolution
        gimp_image_set_tattoo_state
@@ -746,7 +745,7 @@ EXPORTS
        gimp_show_help_button
        gimp_smudge
        gimp_smudge_default
-       gimp_temp_name
+       gimp_temp_file
        gimp_text_fontname
        gimp_text_get_extents_fontname
        gimp_text_layer_get_antialias
diff --git a/libgimp/gimp_pdb.c b/libgimp/gimp_pdb.c
index 29d9bc4c78..43d10734c6 100644
--- a/libgimp/gimp_pdb.c
+++ b/libgimp/gimp_pdb.c
@@ -256,37 +256,36 @@ gimp_get_parasite_list (gint *num_parasites)
 }
 
 /**
- * gimp_temp_name:
+ * gimp_temp_file:
  * @extension: The extension the file will have.
  *
- * Generates a unique filename.
+ * Generates a unique temporary file.
  *
- * Generates a unique filename using the temp path supplied in the
- * user's gimprc.
+ * Generates a unique file using the temp path supplied in the user's
+ * gimprc.
  *
- * Returns: (transfer full): The new temp filename.
- *          The returned value must be freed with g_free().
+ * Returns: (transfer full): The new temp file.
  **/
-gchar *
-gimp_temp_name (const gchar *extension)
+GFile *
+gimp_temp_file (const gchar *extension)
 {
   GimpValueArray *args;
   GimpValueArray *return_vals;
-  gchar *name = NULL;
+  GFile *file = NULL;
 
   args = gimp_value_array_new_from_types (NULL,
                                           G_TYPE_STRING, extension,
                                           G_TYPE_NONE);
 
   return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
-                                              "gimp-temp-name",
+                                              "gimp-temp-file",
                                               args);
   gimp_value_array_unref (args);
 
   if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
-    name = GIMP_VALUES_DUP_STRING (return_vals, 1);
+    file = GIMP_VALUES_DUP_FILE (return_vals, 1);
 
   gimp_value_array_unref (return_vals);
 
-  return name;
+  return file;
 }
diff --git a/libgimp/gimp_pdb.h b/libgimp/gimp_pdb.h
index 25ef652825..7209094aa3 100644
--- a/libgimp/gimp_pdb.h
+++ b/libgimp/gimp_pdb.h
@@ -38,7 +38,7 @@ gboolean      gimp_attach_parasite   (const GimpParasite *parasite);
 gboolean      gimp_detach_parasite   (const gchar        *name);
 GimpParasite* gimp_get_parasite      (const gchar        *name);
 gchar**       gimp_get_parasite_list (gint               *num_parasites);
-gchar*        gimp_temp_name         (const gchar        *extension);
+GFile*        gimp_temp_file         (const gchar        *extension);
 
 
 G_END_DECLS
diff --git a/pdb/groups/gimp.pdb b/pdb/groups/gimp.pdb
index ac065d70bf..726f4a8e65 100644
--- a/pdb/groups/gimp.pdb
+++ b/pdb/groups/gimp.pdb
@@ -190,11 +190,11 @@ CODE
     );
 }
 
-sub temp_name {
-    $blurb = 'Generates a unique filename.';
+sub temp_file {
+    $blurb = 'Generates a unique temporary file.';
 
     $help = <<'HELP';
-Generates a unique filename using the temp path supplied in the user's gimprc.
+Generates a unique file using the temp path supplied in the user's gimprc.
 HELP
 
     &josh_pdb_misc('1997');
@@ -206,18 +206,14 @@ HELP
     );
 
     @outargs = (
-        { name => 'name', type => 'string',
-          desc => 'The new temp filename' }
+        { name => 'file', type => 'file',
+          desc => 'The new temp file' }
     );
 
     %invoke = (
         code => <<'CODE'
 {
-  GFile *file = gimp_get_temp_file (gimp, extension);
-
-  name = g_file_get_path (file);
-
-  g_object_unref (file);
+  file = gimp_get_temp_file (gimp, extension);
 }
 CODE
     );
@@ -234,7 +230,7 @@ CODE
             detach_parasite
             get_parasite
             get_parasite_list
-            temp_name);
+            temp_file);
 
 %exports = (app => [@procs], lib => [@procs[0..1,3..7]]);
 
diff --git a/plug-ins/common/file-compressor.c b/plug-ins/common/file-compressor.c
index 4a2eda66e6..becd7a4a4a 100644
--- a/plug-ins/common/file-compressor.c
+++ b/plug-ins/common/file-compressor.c
@@ -102,10 +102,10 @@
  * that metric, I figure this plug-in is worth about $10,000 USD */
 /* But you got it free.   Magic of Gnu. */
 
-typedef gboolean (*LoadFn) (const char *infile,
-                            const char *outfile);
-typedef gboolean (*SaveFn) (const char *infile,
-                            const char *outfile);
+typedef gboolean (* LoadFn) (GFile *infile,
+                             GFile *outfile);
+typedef gboolean (* SaveFn) (GFile *infile,
+                             GFile *outfile);
 
 typedef struct _CompressorEntry CompressorEntry;
 
@@ -178,25 +178,25 @@ static GimpPDBStatusType   save_image     (const CompressorEntry *compressor,
                                            gint32                 run_mode,
                                            GError               **error);
 
-static gboolean            valid_file     (const gchar           *filename);
+static gboolean            valid_file     (GFile                 *file);
 static const gchar       * find_extension (const CompressorEntry *compressor,
                                            const gchar           *filename);
 
-static gboolean            gzip_load      (const char            *infile,
-                                           const char            *outfile);
-static gboolean            gzip_save      (const char            *infile,
-                                           const char            *outfile);
+static gboolean            gzip_load      (GFile                 *infile,
+                                           GFile                 *outfile);
+static gboolean            gzip_save      (GFile                 *infile,
+                                           GFile                 *outfile);
 
-static gboolean            bzip2_load     (const char            *infile,
-                                           const char            *outfile);
-static gboolean            bzip2_save     (const char            *infile,
-                                           const char            *outfile);
+static gboolean            bzip2_load     (GFile                 *infile,
+                                           GFile                 *outfile);
+static gboolean            bzip2_save     (GFile                 *infile,
+                                           GFile                 *outfile);
 
-static gboolean            xz_load        (const char            *infile,
-                                           const char            *outfile);
-static gboolean            xz_save        (const char            *infile,
-                                           const char            *outfile);
-static goffset             get_file_info  (const gchar           *filename);
+static gboolean            xz_load        (GFile                 *infile,
+                                           GFile                 *outfile);
+static gboolean            xz_save        (GFile                 *infile,
+                                           GFile                 *outfile);
+static goffset             get_file_info  (GFile                 *file);
 
 
 G_DEFINE_TYPE (Compressor, compressor, GIMP_TYPE_PLUG_IN)
@@ -424,7 +424,7 @@ save_image (const CompressorEntry  *compressor,
 {
   gchar       *filename = g_file_get_path (file);
   const gchar *ext;
-  gchar       *tmpname;
+  GFile       *tmp_file;
 
   ext = find_extension (compressor, filename);
 
@@ -436,16 +436,16 @@ save_image (const CompressorEntry  *compressor,
 
   /* get a temp name with the right extension and save into it. */
 
-  tmpname = gimp_temp_name (ext + 1);
+  tmp_file = gimp_temp_file (ext + 1);
 
   if (! (gimp_file_save (run_mode,
                          image,
                          drawable,
-                         g_file_new_for_path (tmpname)) &&
-         valid_file (tmpname)))
+                         tmp_file) &&
+         valid_file (tmp_file)))
     {
-      g_unlink (tmpname);
-      g_free (tmpname);
+      g_file_delete (tmp_file, NULL, NULL);
+      g_object_unref (tmp_file);
       g_free (filename);
 
       g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
@@ -457,18 +457,19 @@ save_image (const CompressorEntry  *compressor,
   gimp_progress_init_printf (_("Compressing '%s'"),
                              gimp_file_get_utf8_name  (file));
 
-  if (! compressor->save_fn (tmpname, filename))
+  if (! compressor->save_fn (tmp_file, file))
     {
-      g_unlink (tmpname);
-      g_free (tmpname);
+      g_file_delete (tmp_file, NULL, NULL);
+      g_object_unref (tmp_file);
       g_free (filename);
 
       return GIMP_PDB_EXECUTION_ERROR;
     }
 
-  g_unlink (tmpname);
+  g_file_delete (tmp_file, NULL, NULL);
+  g_object_unref (tmp_file);
+
   gimp_progress_update (1.0);
-  g_free (tmpname);
 
   /* ask the core to save a thumbnail for compressed XCF files */
   if (strcmp (ext, ".xcf") == 0)
@@ -489,7 +490,7 @@ load_image (const CompressorEntry  *compressor,
   GimpImage   *image;
   gchar       *filename;
   const gchar *ext;
-  gchar       *tmpname;
+  GFile       *tmp_file;
 
   filename = g_file_get_path (file);
 
@@ -503,11 +504,11 @@ load_image (const CompressorEntry  *compressor,
     }
 
   /* find a temp name */
-  tmpname = gimp_temp_name (ext + 1);
+  tmp_file = gimp_temp_file (ext + 1);
 
-  if (! compressor->load_fn (filename, tmpname))
+  if (! compressor->load_fn (file, tmp_file))
     {
-      g_free (tmpname);
+      g_object_unref (tmp_file);
       g_free (filename);
       *status = GIMP_PDB_EXECUTION_ERROR;
       return NULL;
@@ -517,10 +518,10 @@ load_image (const CompressorEntry  *compressor,
 
   /* now that we uncompressed it, load the temp file */
 
-  image = gimp_file_load (run_mode, g_file_new_for_path (tmpname));
+  image = gimp_file_load (run_mode, tmp_file);
 
-  g_unlink (tmpname);
-  g_free (tmpname);
+  g_file_delete (tmp_file, NULL, NULL);
+  g_object_unref (tmp_file);
 
   if (image)
     {
@@ -543,11 +544,17 @@ load_image (const CompressorEntry  *compressor,
 }
 
 static gboolean
-valid_file (const gchar *filename)
+valid_file (GFile *file)
 {
-  struct stat buf;
+  gchar       *filename;
+  struct stat  buf;
+  gboolean     valid;
+
+  filename = g_file_get_path (file);
+  valid = g_stat (filename, &buf) == 0 && buf.st_size > 0;
+  g_free (filename);
 
-  return g_stat (filename, &buf) == 0 && buf.st_size > 0;
+  return valid;
 }
 
 static const gchar *
@@ -588,33 +595,35 @@ find_extension (const CompressorEntry *compressor,
 }
 
 static gboolean
-gzip_load (const char *infile,
-           const char *outfile)
+gzip_load (GFile *infile,
+           GFile *outfile)
 {
-  gboolean ret;
-  int      fd;
-  gzFile   in;
-  FILE    *out;
-  char     buf[16384];
-  int      len;
+  gchar    *in_filename  = g_file_get_path (infile);
+  gchar    *out_filename = g_file_get_path (outfile);
+  gboolean  ret;
+  int       fd;
+  gzFile    in;
+  FILE     *out;
+  char      buf[16384];
+  int       len;
 
   ret = FALSE;
   in = NULL;
   out = NULL;
 
-  fd = g_open (infile, O_RDONLY | _O_BINARY, 0);
+  fd = g_open (in_filename, O_RDONLY | _O_BINARY, 0);
   if (fd == -1)
     goto out;
 
   in = gzdopen (fd, "rb");
-  if (!in)
+  if (! in)
     {
       close (fd);
       goto out;
     }
 
-  out = g_fopen (outfile, "wb");
-  if (!out)
+  out = g_fopen (out_filename, "wb");
+  if (! out)
     goto out;
 
   while (TRUE)
@@ -642,13 +651,18 @@ gzip_load (const char *infile,
   if (out)
     fclose (out);
 
+  g_free (in_filename);
+  g_free (out_filename);
+
   return ret;
 }
 
 static gboolean
-gzip_save (const char *infile,
-           const char *outfile)
+gzip_save (GFile *infile,
+           GFile *outfile)
 {
+  gchar    *in_filename  = g_file_get_path (infile);
+  gchar    *out_filename = g_file_get_path (outfile);
   gboolean  ret;
   FILE     *in;
   int       fd;
@@ -661,16 +675,16 @@ gzip_save (const char *infile,
   in = NULL;
   out = NULL;
 
-  in = g_fopen (infile, "rb");
-  if (!in)
+  in = g_fopen (in_filename, "rb");
+  if (! in)
     goto out;
 
-  fd = g_open (outfile, O_CREAT | O_WRONLY | O_TRUNC | _O_BINARY, 0664);
+  fd = g_open (out_filename, O_CREAT | O_WRONLY | O_TRUNC | _O_BINARY, 0664);
   if (fd == -1)
     goto out;
 
   out = gzdopen (fd, "wb");
-  if (!out)
+  if (! out)
     {
       close (fd);
       goto out;
@@ -710,9 +724,11 @@ gzip_save (const char *infile,
 }
 
 static gboolean
-bzip2_load (const char *infile,
-            const char *outfile)
+bzip2_load (GFile *infile,
+           GFile  *outfile)
 {
+  gchar    *in_filename  = g_file_get_path (infile);
+  gchar    *out_filename = g_file_get_path (outfile);
   gboolean  ret;
   int       fd;
   BZFILE   *in;
@@ -724,7 +740,7 @@ bzip2_load (const char *infile,
   in = NULL;
   out = NULL;
 
-  fd = g_open (infile, O_RDONLY | _O_BINARY, 0);
+  fd = g_open (in_filename, O_RDONLY | _O_BINARY, 0);
   if (fd == -1)
     goto out;
 
@@ -735,7 +751,7 @@ bzip2_load (const char *infile,
       goto out;
     }
 
-  out = g_fopen (outfile, "wb");
+  out = g_fopen (out_filename, "wb");
   if (!out)
     goto out;
 
@@ -764,13 +780,18 @@ bzip2_load (const char *infile,
   if (out)
     fclose (out);
 
+  g_free (in_filename);
+  g_free (out_filename);
+
   return ret;
 }
 
 static gboolean
-bzip2_save (const char *infile,
-            const char *outfile)
+bzip2_save (GFile *infile,
+            GFile *outfile)
 {
+  gchar    *in_filename  = g_file_get_path (infile);
+  gchar    *out_filename = g_file_get_path (outfile);
   gboolean  ret;
   FILE     *in;
   int       fd;
@@ -783,11 +804,11 @@ bzip2_save (const char *infile,
   in = NULL;
   out = NULL;
 
-  in = g_fopen (infile, "rb");
+  in = g_fopen (in_filename, "rb");
   if (!in)
     goto out;
 
-  fd = g_open (outfile, O_CREAT | O_WRONLY | O_TRUNC | _O_BINARY, 0664);
+  fd = g_open (out_filename, O_CREAT | O_WRONLY | O_TRUNC | _O_BINARY, 0664);
   if (fd == -1)
     goto out;
 
@@ -828,13 +849,18 @@ bzip2_save (const char *infile,
   if (out)
     BZ2_bzclose (out);
 
+  g_free (in_filename);
+  g_free (out_filename);
+
   return ret;
 }
 
 static gboolean
-xz_load (const char *infile,
-         const char *outfile)
+xz_load (GFile *infile,
+         GFile *outfile)
 {
+  gchar       *in_filename  = g_file_get_path (infile);
+  gchar       *out_filename = g_file_get_path (outfile);
   gboolean     ret;
   FILE        *in;
   FILE        *out;
@@ -848,11 +874,11 @@ xz_load (const char *infile,
   in = NULL;
   out = NULL;
 
-  in = g_fopen (infile, "rb");
+  in = g_fopen (in_filename, "rb");
   if (!in)
     goto out;
 
-  out = g_fopen (outfile, "wb");
+  out = g_fopen (out_filename, "wb");
   if (!out)
     goto out;
 
@@ -916,13 +942,18 @@ xz_load (const char *infile,
   if (out)
     fclose (out);
 
+  g_free (in_filename);
+  g_free (out_filename);
+
   return ret;
 }
 
 static gboolean
-xz_save (const char *infile,
-         const char *outfile)
+xz_save (GFile *infile,
+         GFile *outfile)
 {
+  gchar       *in_filename  = g_file_get_path (infile);
+  gchar       *out_filename = g_file_get_path (outfile);
   gboolean     ret;
   FILE        *in;
   FILE        *out;
@@ -937,12 +968,12 @@ xz_save (const char *infile,
   in = NULL;
   out = NULL;
 
-  in = g_fopen (infile, "rb");
+  in = g_fopen (in_filename, "rb");
   if (!in)
     goto out;
 
   file_size = get_file_info (infile);
-  out = g_fopen (outfile, "wb");
+  out = g_fopen (out_filename, "wb");
   if (!out)
     goto out;
 
@@ -1010,14 +1041,16 @@ xz_save (const char *infile,
   if (out)
     fclose (out);
 
+  g_free (in_filename);
+  g_free (out_filename);
+
   return ret;
 }
 
 /* get file size from a filename */
 static goffset
-get_file_info (const gchar *filename)
+get_file_info (GFile *file)
 {
-  GFile     *file = g_file_new_for_path (filename);
   GFileInfo *info;
   goffset    size = 1;
 
@@ -1033,7 +1066,5 @@ get_file_info (const gchar *filename)
       g_object_unref (info);
     }
 
-  g_object_unref (file);
-
   return size;
 }
diff --git a/plug-ins/common/file-mng.c b/plug-ins/common/file-mng.c
index 3013e91f8d..de1b8e7718 100644
--- a/plug-ins/common/file-mng.c
+++ b/plug-ins/common/file-mng.c
@@ -1075,6 +1075,7 @@ mng_save_image (const gchar  *filename,
 
       gchar           frame_mode;
       int             frame_delay;
+      GFile          *temp_file;
       gchar          *temp_file_name;
       png_structp     pp;
       png_infop       info;
@@ -1218,19 +1219,21 @@ mng_save_image (const gchar  *filename,
             }
         }
 
-      if ((temp_file_name = gimp_temp_name ("mng")) == NULL)
+      if ((temp_file = gimp_temp_file ("mng")) == NULL)
         {
-          g_warning ("gimp_temp_name() failed in mng_save_image()");
+          g_warning ("gimp_temp_file() failed in mng_save_image()");
           goto err3;
         }
 
+      temp_file_name = g_file_get_path (temp_file);
+
       if ((outfile = g_fopen (temp_file_name, "wb")) == NULL)
         {
           g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
                        _("Could not open '%s' for writing: %s"),
-                       gimp_filename_to_utf8 (temp_file_name),
+                       gimp_file_get_utf8_name (temp_file),
                        g_strerror (errno));
-          g_unlink (temp_file_name);
+          g_file_delete (temp_file, NULL, NULL);
           goto err3;
         }
 
@@ -1240,7 +1243,7 @@ mng_save_image (const gchar  *filename,
         {
           g_warning ("Unable to png_create_write_struct() in mng_save_image()");
           fclose (outfile);
-          g_unlink (temp_file_name);
+          g_file_delete (temp_file, NULL, NULL);
           goto err3;
         }
 
@@ -1251,7 +1254,7 @@ mng_save_image (const gchar  *filename,
             ("Unable to png_create_info_struct() in mng_save_image()");
           png_destroy_write_struct (&pp, NULL);
           fclose (outfile);
-          g_unlink (temp_file_name);
+          g_file_delete (temp_file, NULL, NULL);
           goto err3;
         }
 
@@ -1260,7 +1263,7 @@ mng_save_image (const gchar  *filename,
           g_warning ("HRM saving PNG in mng_save_image()");
           png_destroy_write_struct (&pp, &info);
           fclose (outfile);
-          g_unlink (temp_file_name);
+          g_file_delete (temp_file, NULL, NULL);
           goto err3;
         }
 
@@ -1300,7 +1303,7 @@ mng_save_image (const gchar  *filename,
           g_warning ("This can't be!\n");
           png_destroy_write_struct (&pp, &info);
           fclose (outfile);
-          g_unlink (temp_file_name);
+          g_file_delete (temp_file, NULL, NULL);
           goto err3;
         }
 
@@ -1397,13 +1400,14 @@ mng_save_image (const gchar  *filename,
       fclose (outfile);
 
       infile = g_fopen (temp_file_name, "rb");
-      if (NULL == infile)
+
+      if (! infile)
         {
           g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
                        _("Could not open '%s' for reading: %s"),
-                       gimp_filename_to_utf8 (temp_file_name),
+                       gimp_file_get_utf8_name (temp_file),
                        g_strerror (errno));
-          g_unlink (temp_file_name);
+          g_file_delete (temp_file, NULL, NULL);
           goto err3;
         }
 
@@ -1530,7 +1534,7 @@ mng_save_image (const gchar  *filename,
         }
 
       fclose (infile);
-      g_unlink (temp_file_name);
+      g_file_delete (temp_file, NULL, NULL);
     }
 
   if (mng_putchunk_mend (handle) != MNG_NOERROR)
diff --git a/plug-ins/common/file-ps.c b/plug-ins/common/file-ps.c
index f381d97cfe..ab3cfd694a 100644
--- a/plug-ins/common/file-ps.c
+++ b/plug-ins/common/file-ps.c
@@ -1672,7 +1672,7 @@ get_bbox (GFile *file,
   return retval;
 }
 
-static gchar *pnmfile;
+static gchar *pnmfilename;
 
 /* Open the PostScript file. On failure, NULL is returned. */
 /* The filepointer returned will give a PNM-file generated */
@@ -1802,7 +1802,7 @@ ps_open (GFile            *file,
    * using standard output as output file.
    * Thus, use a real output file.
    */
-  pnmfile = gimp_temp_name ("pnm");
+  pnmfilename = g_file_get_path (gimp_temp_file ("pnm"));
 
   /* Build command array */
   cmdA = g_ptr_array_new ();
@@ -1840,7 +1840,7 @@ ps_open (GFile            *file,
     g_ptr_array_add (cmdA, g_strdup ("-dSAFER"));
 
   /* Output file name */
-  g_ptr_array_add (cmdA, g_strdup_printf ("-sOutputFile=%s", pnmfile));
+  g_ptr_array_add (cmdA, g_strdup_printf ("-sOutputFile=%s", pnmfilename));
 
   /* Offset command for gs to get image part with negative x/y-coord. */
   if ((offx != 0) || (offy != 0))
@@ -1892,7 +1892,7 @@ ps_open (GFile            *file,
   /* Don't care about exit status of ghostscript. */
   /* Just try to read what it wrote. */
 
-  fd_popen = g_fopen (pnmfile, "rb");
+  fd_popen = g_fopen (pnmfilename, "rb");
 
   g_ptr_array_free (cmdA, FALSE);
   g_strfreev (pcmdA);
@@ -1907,7 +1907,7 @@ ps_close (FILE *ifp)
 {
  /* If a real outputfile was used, close the file and remove it. */
   fclose (ifp);
-  g_unlink (pnmfile);
+  g_unlink (pnmfilename);
 }
 
 
diff --git a/plug-ins/common/mail.c b/plug-ins/common/mail.c
index c4ff430401..1d5b9a8cc8 100644
--- a/plug-ins/common/mail.c
+++ b/plug-ins/common/mail.c
@@ -100,7 +100,7 @@ static GimpPDBStatusType  send_image              (const gchar      *filename,
 static gboolean           send_dialog             (void);
 static void               mail_entry_callback     (GtkWidget        *widget,
                                                    gchar            *data);
-static gboolean           valid_file              (const gchar      *filename);
+static gboolean           valid_file              (GFile            *file);
 static gchar            * find_extension          (const gchar      *filename);
 
 #ifdef SENDMAIL
@@ -328,6 +328,7 @@ send_image (const gchar  *filename,
 {
   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
   gchar             *ext;
+  GFile             *tmpfile;
   gchar             *tmpname;
 #ifndef SENDMAIL /* xdg-email */
   gchar             *mailcmd[9];
@@ -348,13 +349,14 @@ send_image (const gchar  *filename,
     return GIMP_PDB_CALLING_ERROR;
 
   /* get a temp name with the right extension and save into it. */
-  tmpname = gimp_temp_name (ext + 1);
+  tmpfile = gimp_temp_file (ext + 1);
+  tmpname = g_file_get_path (tmpfile);
 
   if (! (gimp_file_save (run_mode,
                          image,
                          drawable,
-                         g_file_new_for_path (tmpname)) &&
-         valid_file (tmpname)))
+                         tmpfile) &&
+         valid_file (tmpfile)))
     {
       goto error;
     }
@@ -416,19 +418,17 @@ send_image (const gchar  *filename,
        * with g_rename().
        * On the other hand, g_file_move() seems to be more robust.
        */
-      GFile *source = g_file_new_for_path (tmpname);
+      GFile *source = tmpfile;
       GFile *target = g_file_new_for_path (filepath);
 
       if (! g_file_move (source, target, G_FILE_COPY_NONE, NULL, NULL, NULL, &error))
         {
           g_message ("%s", error->message);
           g_clear_error (&error);
-          g_object_unref (source);
           g_object_unref (target);
           goto error;
         }
 
-      g_object_unref (source);
       g_object_unref (target);
     }
 
@@ -521,6 +521,7 @@ cleanup:
 
   g_free (mailcmd[0]);
   g_free (tmpname);
+  g_object_unref (tmpfile);
 
   return status;
 }
@@ -671,11 +672,17 @@ send_dialog (void)
 }
 
 static gboolean
-valid_file (const gchar *filename)
+valid_file (GFile *file)
 {
-  struct stat buf;
+  gchar       *filename;
+  struct stat  buf;
+  gboolean     valid;
 
-  return g_stat (filename, &buf) == 0 && buf.st_size > 0;
+  filename = g_file_get_path (file);
+  valid = g_stat (filename, &buf) == 0 && buf.st_size > 0;
+  g_free (filename);
+
+  return valid;
 }
 
 static gchar *
diff --git a/plug-ins/file-jpeg/jpeg-save.c b/plug-ins/file-jpeg/jpeg-save.c
index a339aa5082..30ac1fd3d5 100644
--- a/plug-ins/file-jpeg/jpeg-save.c
+++ b/plug-ins/file-jpeg/jpeg-save.c
@@ -743,10 +743,7 @@ make_preview (void)
 
   if (jsvals.preview)
     {
-      gchar *tn   = gimp_temp_name ("jpeg");
-      GFile *file = g_file_new_for_path (tn);
-
-      g_free (tn);
+      GFile *file = gimp_temp_file ("jpeg");
 
       if (! undo_touched)
         {
diff --git a/plug-ins/file-raw/file-darktable.c b/plug-ins/file-raw/file-darktable.c
index 1948d2e457..f05d112a41 100644
--- a/plug-ins/file-raw/file-darktable.c
+++ b/plug-ins/file-raw/file-darktable.c
@@ -382,7 +382,8 @@ load_image (GFile        *file,
   gchar     *lua_quoted         = g_shell_quote (lua_script_escaped);
   gchar     *lua_cmd            = g_strdup_printf ("dofile(%s)", lua_quoted);
   gchar     *filename           = g_file_get_path (file);
-  gchar     *filename_out       = gimp_temp_name ("exr");
+  GFile     *file_out           = gimp_temp_file ("exr");
+  gchar     *filename_out       = g_file_get_path (file_out);
   gchar     *export_filename    = g_strdup_printf ("lua/export_on_exit/export_filename=%s",
                                                    filename_out);
 
@@ -439,7 +440,7 @@ load_image (GFile        *file,
                     NULL,
                     error))
     {
-      image = gimp_file_load (run_mode, g_file_new_for_path (filename_out));
+      image = gimp_file_load (run_mode, file_out);
       if (image)
         gimp_image_set_file (image, file);
     }
@@ -477,7 +478,8 @@ load_thumbnail_image (GFile   *file,
   GimpImage *image           = NULL;
 
   gchar  *filename           = g_file_get_path (file);
-  gchar  *filename_out       = gimp_temp_name ("jpg");
+  GFile  *file_out           = gimp_temp_file ("jpg");
+  gchar  *filename_out       = g_file_get_path (file_out);
   gchar  *size               = g_strdup_printf ("%d", thumb_size);
   GFile  *lua_file           = gimp_data_directory_file ("file-raw",
                                                          "file-darktable-get-size.lua",
@@ -531,8 +533,7 @@ load_thumbnail_image (GFile   *file,
     {
       gimp_progress_update (0.5);
 
-      image = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
-                              g_file_new_for_path (filename_out));
+      image = gimp_file_load (GIMP_RUN_NONINTERACTIVE, file_out);
       if (image)
         {
           /* the size reported by raw files isn't precise,
diff --git a/plug-ins/file-raw/file-rawtherapee.c b/plug-ins/file-raw/file-rawtherapee.c
index db9fb4faf2..7ddcbef333 100644
--- a/plug-ins/file-raw/file-rawtherapee.c
+++ b/plug-ins/file-raw/file-rawtherapee.c
@@ -321,7 +321,8 @@ load_image (GFile        *file,
 {
   GimpImage *image              = NULL;
   gchar     *filename           = g_file_get_path (file);
-  gchar     *filename_out       = gimp_temp_name ("tif");
+  GFile     *file_out           = gimp_temp_file ("tif");
+  gchar     *filename_out       = g_file_get_path (file_out);
   gchar     *rawtherapee_stdout = NULL;
 
   gboolean   search_path        = FALSE;
@@ -357,7 +358,7 @@ load_image (GFile        *file,
                     NULL,
                     error))
     {
-      image = gimp_file_load (run_mode, g_file_new_for_path (filename_out));
+      image = gimp_file_load (run_mode, file_out);
       if (image)
         gimp_image_set_file (image, file);
     }
@@ -381,8 +382,10 @@ load_thumbnail_image (GFile   *file,
 {
   GimpImage *image            = NULL;
   gchar     *filename         = g_file_get_path (file);
-  gchar     *filename_out     = gimp_temp_name ("jpg");
-  gchar     *thumb_pp3        = gimp_temp_name ("pp3");
+  GFile     *file_out         = gimp_temp_file ("jpg");
+  gchar     *filename_out     = g_file_get_path (file_out);
+  GFile     *thumb_pp3_file   = gimp_temp_file ("pp3");
+  gchar     *thumb_pp3        = g_file_get_path (thumb_pp3_file);
   FILE      *thumb_pp3_f      = fopen (thumb_pp3, "w");
   gchar     *rawtherapee_stdout = NULL;
   const char *pp3_content =
@@ -477,8 +480,7 @@ load_thumbnail_image (GFile   *file,
     {
       gimp_progress_update (0.5);
 
-      image = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
-                              g_file_new_for_path (filename_out));
+      image = gimp_file_load (GIMP_RUN_NONINTERACTIVE, file_out);
       if (image)
         {
           /* is this needed for thumbnails? */
diff --git a/plug-ins/gfig/gfig.c b/plug-ins/gfig/gfig.c
index a6053cd187..bfd8d8efc1 100644
--- a/plug-ins/gfig/gfig.c
+++ b/plug-ins/gfig/gfig.c
@@ -770,8 +770,9 @@ gfig_save_as_parasite (void)
 GFigObj *
 gfig_load_from_parasite (void)
 {
-  FILE         *fp;
+  GFile        *file;
   gchar        *fname;
+  FILE         *fp;
   GimpParasite *parasite;
   GFigObj      *gfig;
 
@@ -780,14 +781,15 @@ gfig_load_from_parasite (void)
   if (! parasite)
     return NULL;
 
-  fname = gimp_temp_name ("gfigtmp");
+  file  = gimp_temp_file ("gfigtmp");
+  fname = g_file_get_path (file);
 
   fp = g_fopen (fname, "wb");
-  if (!fp)
+  if (! fp)
     {
       g_message (_("Error trying to open temporary file '%s' "
                    "for parasite loading: %s"),
-                 gimp_filename_to_utf8 (fname), g_strerror (errno));
+                 gimp_file_get_utf8_name (file), g_strerror (errno));
       return NULL;
     }
 
@@ -804,6 +806,7 @@ gfig_load_from_parasite (void)
   g_unlink (fname);
 
   g_free (fname);
+  g_object_unref (file);
 
   return gfig;
 }
diff --git a/plug-ins/screenshot/screenshot-gnome-shell.c b/plug-ins/screenshot/screenshot-gnome-shell.c
index c144f32a5b..5354853ad2 100644
--- a/plug-ins/screenshot/screenshot-gnome-shell.c
+++ b/plug-ins/screenshot/screenshot-gnome-shell.c
@@ -81,13 +81,16 @@ screenshot_gnome_shell_shoot (ScreenshotValues  *shootvals,
                               GimpImage        **image,
                               GError           **error)
 {
+  GFile       *file;
   gchar       *filename;
   const gchar *method = NULL;
   GVariant    *args   = NULL;
   GVariant    *retval;
   gboolean     success;
 
-  filename = gimp_temp_name ("png");
+  file = gimp_temp_file ("png");
+
+  filename = g_file_get_path (file);
 
   switch (shootvals->shoot_type)
     {
@@ -157,8 +160,8 @@ screenshot_gnome_shell_shoot (ScreenshotValues  *shootvals,
       break;
     }
 
-  g_free (filename);
-  filename = NULL;
+  g_clear_pointer (&filename, g_free);
+  g_clear_object (&file);
 
   retval = g_dbus_proxy_call_sync (proxy, method, args,
                                    G_DBUS_CALL_FLAGS_NONE,


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