[gimp] plug-ins: more g_file_get_path() changed to g_file_peek_path().



commit e61adec2328aed5708fc30aa7f0f14b2b11c5207
Author: Jehan <jehan girinstud io>
Date:   Fri Oct 1 22:58:14 2021 +0200

    plug-ins: more g_file_get_path() changed to g_file_peek_path().
    
    Also some g_unlink() changed into g_file_delete().
    
    And a g_file_get_path() followed by g_path_get_basename() changed into
    g_file_get_basename() only.

 plug-ins/common/cml-explorer.c         | 14 ++++++++------
 plug-ins/common/file-gif-load.c        |  5 +----
 plug-ins/common/file-jp2-load.c        |  5 +----
 plug-ins/common/file-sunras.c          | 12 +++---------
 plug-ins/common/file-xbm.c             | 10 ++--------
 plug-ins/file-ico/ico-save.c           |  8 ++------
 plug-ins/file-psd/psd-image-res-load.c |  5 +----
 plug-ins/file-raw/file-darktable.c     | 25 ++++++++-----------------
 plug-ins/file-raw/file-rawtherapee.c   | 24 ++++++++----------------
 9 files changed, 34 insertions(+), 74 deletions(-)
---
diff --git a/plug-ins/common/cml-explorer.c b/plug-ins/common/cml-explorer.c
index 03ba7ef21b..7ea796b14c 100644
--- a/plug-ins/common/cml-explorer.c
+++ b/plug-ins/common/cml-explorer.c
@@ -582,14 +582,16 @@ explorer_run (GimpProcedure        *procedure,
       {
         const gchar *uri      = GIMP_VALUES_GET_STRING (args, 0);
         GFile       *file     = g_file_new_for_uri (uri);
-        gchar       *filename = g_file_get_path (file);
 
-        if (! CML_load_parameter_file (filename, FALSE))
-          return gimp_procedure_new_return_values (procedure,
-                                                   GIMP_PDB_CALLING_ERROR,
-                                                   NULL);
+        if (! CML_load_parameter_file (g_file_peek_path (file), FALSE))
+          {
+            g_object_unref (file);
+
+            return gimp_procedure_new_return_values (procedure,
+                                                     GIMP_PDB_CALLING_ERROR,
+                                                     NULL);
+          }
 
-        g_free (filename);
         g_object_unref (file);
       }
       break;
diff --git a/plug-ins/common/file-gif-load.c b/plug-ins/common/file-gif-load.c
index 24bcaf7e2c..9708a8af6e 100644
--- a/plug-ins/common/file-gif-load.c
+++ b/plug-ins/common/file-gif-load.c
@@ -382,7 +382,6 @@ load_image (GFile     *file,
             GError   **error)
 {
   FILE      *fd;
-  gchar     *filename;
   guchar     buf[16];
   guchar     c;
   CMap       localColorMap;
@@ -397,9 +396,7 @@ load_image (GFile     *file,
   gimp_progress_init_printf (_("Opening '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  fd = g_fopen (filename, "rb");
-  g_free (filename);
+  fd = g_fopen (g_file_peek_path (file), "rb");
 
   if (! fd)
     {
diff --git a/plug-ins/common/file-jp2-load.c b/plug-ins/common/file-jp2-load.c
index 988e17bf59..0e27100588 100644
--- a/plug-ins/common/file-jp2-load.c
+++ b/plug-ins/common/file-jp2-load.c
@@ -1057,7 +1057,6 @@ load_image (GFile             *file,
             gboolean          *profile_loaded,
             GError           **error)
 {
-  gchar             *filename;
   opj_stream_t      *stream     = NULL;
   opj_codec_t       *codec      = NULL;
   opj_dparameters_t  parameters;
@@ -1085,9 +1084,7 @@ load_image (GFile             *file,
   gimp_progress_init_printf (_("Opening '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  stream = opj_stream_create_default_file_stream (filename, OPJ_TRUE);
-  g_free (filename);
+  stream = opj_stream_create_default_file_stream (g_file_peek_path (file), OPJ_TRUE);
 
   if (! stream)
     {
diff --git a/plug-ins/common/file-sunras.c b/plug-ins/common/file-sunras.c
index 30f3a3d2bc..ffcd0c4c44 100644
--- a/plug-ins/common/file-sunras.c
+++ b/plug-ins/common/file-sunras.c
@@ -440,7 +440,6 @@ load_image (GFile   *file,
             GError **error)
 {
   GimpImage       *image;
-  gchar           *filename;
   FILE            *ifp;
   L_SUNFILEHEADER  sunhdr;
   guchar          *suncolmap = NULL;
@@ -448,9 +447,7 @@ load_image (GFile   *file,
   gimp_progress_init_printf (_("Opening '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  ifp = g_fopen (filename, "rb");
-  g_free (filename);
+  ifp = g_fopen (g_file_peek_path (file), "rb");
 
   if (! ifp)
     {
@@ -496,7 +493,7 @@ load_image (GFile   *file,
 #ifdef DEBUG
       {
         int j, ncols;
-        printf ("File %s\n", g_file_get_path (file));
+        printf ("File %s\n", g_file_peek_path (file));
         ncols = sunhdr.l_ras_maplength/3;
         for (j=0; j < ncols; j++)
           printf ("Entry 0x%08x: 0x%04x,  0x%04x, 0x%04x\n",
@@ -595,7 +592,6 @@ save_image (GFile         *file,
             GObject       *config,
             GError       **error)
 {
-  gchar         *filename;
   FILE          *ofp;
   GimpImageType  drawable_type;
   gboolean       rle;
@@ -631,9 +627,7 @@ save_image (GFile         *file,
                              gimp_file_get_utf8_name (file));
 
   /* Open the output file. */
-  filename = g_file_get_path (file);
-  ofp = g_fopen (filename, "wb");
-  g_free (filename);
+  ofp = g_fopen (g_file_peek_path (file), "wb");
 
   if (! ofp)
     {
diff --git a/plug-ins/common/file-xbm.c b/plug-ins/common/file-xbm.c
index fc556e6bf1..2b3d62e70b 100644
--- a/plug-ins/common/file-xbm.c
+++ b/plug-ins/common/file-xbm.c
@@ -297,13 +297,10 @@ static gchar *
 init_prefix (GFile   *file,
              GObject *config)
 {
-  gchar *filename;
   gchar *p, *prefix;
   gint   len;
 
-  filename = g_file_get_path (file);
-  prefix = g_path_get_basename (filename);
-  g_free (filename);
+  prefix = g_file_get_basename (file);
 
   g_object_set (config,
                 "prefix", NULL,
@@ -719,7 +716,6 @@ static GimpImage *
 load_image (GFile   *file,
             GError **error)
 {
-  gchar      *filename;
   FILE       *fp;
   GeglBuffer *buffer;
   GimpImage  *image;
@@ -743,9 +739,7 @@ load_image (GFile   *file,
   gimp_progress_init_printf (_("Opening '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  fp = g_fopen (filename, "rb");
-  g_free (filename);
+  fp = g_fopen (g_file_peek_path (file), "rb");
 
   if (! fp)
     {
diff --git a/plug-ins/file-ico/ico-save.c b/plug-ins/file-ico/ico-save.c
index a87b219012..4f8bf1c927 100644
--- a/plug-ins/file-ico/ico-save.c
+++ b/plug-ins/file-ico/ico-save.c
@@ -1066,9 +1066,7 @@ ico_save_image (GFile      *file,
                 gint32      run_mode,
                 GError    **error)
 {
-  gchar *filename;
-  FILE  *fp;
-
+  FILE          *fp;
   GList         *iter;
   gint           width;
   gint           height;
@@ -1093,9 +1091,7 @@ ico_save_image (GFile      *file,
   gimp_progress_init_printf (_("Exporting '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  fp = g_fopen (filename, "wb");
-  g_free (filename);
+  fp = g_fopen (g_file_peek_path (file), "wb");
 
   if (! fp)
     {
diff --git a/plug-ins/file-psd/psd-image-res-load.c b/plug-ins/file-psd/psd-image-res-load.c
index fd96af0eeb..dea0e864a4 100644
--- a/plug-ins/file-psd/psd-image-res-load.c
+++ b/plug-ins/file-psd/psd-image-res-load.c
@@ -977,7 +977,6 @@ load_resource_1033 (const PSDimageres  *res_a,
   struct jpeg_decompress_struct cinfo;
   struct jpeg_error_mgr         jerr;
 
-  gchar                *filename;
   FILE                 *f;
   ThumbnailInfo         thumb_info;
   GeglBuffer           *buffer;
@@ -1028,9 +1027,7 @@ load_resource_1033 (const PSDimageres  *res_a,
   /* Load Jpeg RGB thumbnail info */
 
   /* Open input also as a FILE. */
-  filename = g_file_get_path (file);
-  f = g_fopen (filename, "rb");
-  g_free (filename);
+  f = g_fopen (g_file_peek_path (file), "rb");
 
   if (! f)
     return -1;
diff --git a/plug-ins/file-raw/file-darktable.c b/plug-ins/file-raw/file-darktable.c
index d81125f8e1..4e9ffa87f3 100644
--- a/plug-ins/file-raw/file-darktable.c
+++ b/plug-ins/file-raw/file-darktable.c
@@ -377,15 +377,12 @@ load_image (GFile        *file,
   GFile     *lua_file           = gimp_data_directory_file ("file-raw",
                                                             "file-darktable-export-on-exit.lua",
                                                             NULL);
-  gchar     *lua_script         = g_file_get_path (lua_file);
-  gchar     *lua_script_escaped = g_strescape (lua_script, "");
+  gchar     *lua_script_escaped = g_strescape (g_file_peek_path (lua_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);
   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);
+                                                   g_file_peek_path (file_out));
 
   gchar *darktable_stdout    = NULL;
   gchar *darktable_stderr    = NULL;
@@ -407,12 +404,11 @@ load_image (GFile        *file,
       "--luacmd",  lua_cmd,
       "--conf",    "plugins/lighttable/export/icctype=3",
       "--conf",    export_filename,
-      (gchar *) filename,
+      (gchar *) g_file_peek_path (file),
       NULL
     };
 
   g_object_unref (lua_file);
-  g_free (lua_script);
   g_free (lua_script_escaped);
   g_free (lua_quoted);
 
@@ -465,9 +461,8 @@ load_image (GFile        *file,
   g_free (darktable_stdout);
   g_free (darktable_stderr);
 
-  g_unlink (filename_out);
+  g_file_delete (file_out, NULL, NULL);
   g_free (lua_cmd);
-  g_free (filename_out);
   g_free (export_filename);
   g_free (exec_path);
 
@@ -485,15 +480,12 @@ load_thumbnail_image (GFile   *file,
 {
   GimpImage *image           = NULL;
 
-  gchar  *filename           = g_file_get_path (file);
   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",
                                                          NULL);
-  gchar  *lua_script         = g_file_get_path (lua_file);
-  gchar  *lua_script_escaped = g_strescape (lua_script, "");
+  gchar  *lua_script_escaped = g_strescape (g_file_peek_path (lua_file), "");
   gchar  *lua_quoted         = g_shell_quote (lua_script_escaped);
   gchar  *lua_cmd            = g_strdup_printf ("dofile(%s)", lua_quoted);
   gchar  *darktable_stdout   = NULL;
@@ -507,7 +499,8 @@ load_thumbnail_image (GFile   *file,
   gchar    *argv[] =
     {
       exec_path,
-      (gchar *) filename, filename_out,
+      (gchar *) g_file_peek_path (file),
+      (gchar *) g_file_peek_path (file_out),
       "--width",          size,
       "--height",         size,
       "--hq",             "false",
@@ -518,7 +511,6 @@ load_thumbnail_image (GFile   *file,
     };
 
   g_object_unref (lua_file);
-  g_free (lua_script);
   g_free (lua_script_escaped);
   g_free (lua_quoted);
 
@@ -560,8 +552,7 @@ load_thumbnail_image (GFile   *file,
 
   gimp_progress_update (1.0);
 
-  g_unlink (filename_out);
-  g_free (filename_out);
+  g_file_delete (file_out, NULL, NULL);
   g_free (size);
   g_free (lua_cmd);
   g_free (darktable_stdout);
diff --git a/plug-ins/file-raw/file-rawtherapee.c b/plug-ins/file-raw/file-rawtherapee.c
index 7ddcbef333..e11fcc38c8 100644
--- a/plug-ins/file-raw/file-rawtherapee.c
+++ b/plug-ins/file-raw/file-rawtherapee.c
@@ -320,9 +320,7 @@ load_image (GFile        *file,
             GError      **error)
 {
   GimpImage *image              = NULL;
-  gchar     *filename           = g_file_get_path (file);
   GFile     *file_out           = gimp_temp_file ("tif");
-  gchar     *filename_out       = g_file_get_path (file_out);
   gchar     *rawtherapee_stdout = NULL;
 
   gboolean   search_path        = FALSE;
@@ -337,8 +335,8 @@ load_image (GFile        *file,
     {
       exec_path,
       "-gimp",
-      (gchar *) filename,
-      filename_out,
+      (gchar *) g_file_peek_path (file),
+      (gchar *) g_file_peek_path (file_out),
       NULL
     };
 
@@ -367,8 +365,7 @@ load_image (GFile        *file,
   g_free (rawtherapee_stdout);
   g_free (exec_path);
 
-  g_unlink (filename_out);
-  g_free (filename_out);
+  g_file_delete (file_out, NULL, NULL);
 
   gimp_progress_update (1.0);
 
@@ -381,12 +378,9 @@ load_thumbnail_image (GFile   *file,
                       GError **error)
 {
   GimpImage *image            = NULL;
-  gchar     *filename         = g_file_get_path (file);
   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");
+  FILE      *thumb_pp3_f      = fopen (g_file_peek_path (thumb_pp3_file), "w");
   gchar     *rawtherapee_stdout = NULL;
   const char *pp3_content =
     "[Version]\n"
@@ -443,13 +437,13 @@ load_thumbnail_image (GFile   *file,
   gchar *argv[] =
     {
       exec_path,
-      "-o", filename_out,
+      "-o", (gchar *) g_file_peek_path (file_out),
       "-d",
       "-s",
       "-j",
-      "-p", thumb_pp3,
+      "-p", (gchar *) g_file_peek_path (thumb_pp3_file),
       "-f",
-      "-c", (char *) filename,
+      "-c", (gchar *) g_file_peek_path (file),
       NULL
     };
 
@@ -493,9 +487,7 @@ load_thumbnail_image (GFile   *file,
   if (thumb_pp3_f)
     fclose (thumb_pp3_f);
 
-  g_unlink (thumb_pp3);
-  g_free (filename_out);
-  g_free (thumb_pp3);
+  g_file_delete (thumb_pp3_file, NULL, NULL);
   g_free (rawtherapee_stdout);
   g_free (exec_path);
 


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