[gimp] Clean up code around calls to g_file_replace()



commit 849481a86157dca12ab1004bd2ce32237be50b94
Author: Michael Natterer <mitch gimp org>
Date:   Sat Oct 4 02:44:54 2014 +0200

    Clean up code around calls to g_file_replace()
    
    - use G_FILE_CREATE_NONE instead of 0
    - don't put "Could not open <file> for writing: <error>" around the
      returned error, the returned message is already verbose

 app/core/gimp-tags.c                  |    3 +--
 app/core/gimpdata.c                   |    6 ------
 app/core/gimpgradient-save.c          |   10 ++--------
 app/core/gimptagcache.c               |    5 ++---
 app/gui/themes.c                      |    4 +---
 app/tools/gimpimagemaptool-settings.c |   10 ++++------
 app/vectors/gimpvectors-export.c      |   11 ++---------
 app/widgets/gimptextbuffer.c          |   10 ++--------
 app/xcf/xcf.c                         |   11 +++--------
 libgimpconfig/gimpconfigwriter.c      |   27 ++++++++++-----------------
 plug-ins/common/file-csource.c        |    4 +++-
 plug-ins/common/file-gbr.c            |    4 +++-
 plug-ins/common/file-gih.c            |    4 +++-
 plug-ins/common/file-pat.c            |    4 +++-
 plug-ins/common/file-pix.c            |    4 +++-
 plug-ins/common/file-pnm.c            |    4 +++-
 16 files changed, 45 insertions(+), 76 deletions(-)
---
diff --git a/app/core/gimp-tags.c b/app/core/gimp-tags.c
index 40d0cd3..3f01a19 100644
--- a/app/core/gimp-tags.c
+++ b/app/core/gimp-tags.c
@@ -132,8 +132,7 @@ gimp_tags_user_install (void)
                                             NULL, &error));
   if (! output)
     {
-      g_printerr (_("Could not open '%s' for writing: %s"),
-                  gimp_file_get_utf8_name (file), error->message);
+      g_printerr ("%s\n", error->message);
       result = FALSE;
     }
   else if (! g_output_stream_write_all (output,
diff --git a/app/core/gimpdata.c b/app/core/gimpdata.c
index 14dcc63..85073cd 100644
--- a/app/core/gimpdata.c
+++ b/app/core/gimpdata.c
@@ -554,12 +554,6 @@ gimp_data_save (GimpData  *data,
 
           g_object_unref (output);
         }
-      else
-        {
-          g_prefix_error (error,
-                          _("Could not open '%s' for writing: "),
-                          gimp_file_get_utf8_name (private->file));
-        }
     }
 
   if (success)
diff --git a/app/core/gimpgradient-save.c b/app/core/gimpgradient-save.c
index 363d0cc..104d1ae 100644
--- a/app/core/gimpgradient-save.c
+++ b/app/core/gimpgradient-save.c
@@ -137,15 +137,9 @@ gimp_gradient_save_pov (GimpGradient  *gradient,
 
   output = G_OUTPUT_STREAM (g_file_replace (file,
                                             NULL, FALSE, G_FILE_CREATE_NONE,
-                                            NULL, &my_error));
+                                            NULL, error));
   if (! output)
-    {
-      g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
-                   _("Could not open '%s' for writing: %s"),
-                   gimp_file_get_utf8_name (file), my_error->message);
-      g_clear_error (&my_error);
-      return FALSE;
-    }
+    return FALSE;
 
   string = g_string_new ("/* color_map file created by GIMP */\n"
                          "/* http://www.gimp.org/           */\n"
diff --git a/app/core/gimptagcache.c b/app/core/gimptagcache.c
index d73762c..c56ae1a 100644
--- a/app/core/gimptagcache.c
+++ b/app/core/gimptagcache.c
@@ -433,14 +433,13 @@ gimp_tag_cache_save (GimpTagCache *cache)
                                             NULL, &error));
   if (! output)
     {
-      g_printerr (_("Could not open '%s' for writing: %s"),
-                  gimp_file_get_utf8_name (file), error->message);
+      g_printerr ("%s\n", error->message);
     }
   else if (! g_output_stream_write_all (output, buf->str, buf->len,
                                         NULL, NULL, &error) ||
            ! g_output_stream_close (output, NULL, &error))
     {
-      g_printerr (_("Error writing '%s': %s"),
+      g_printerr (_("Error writing '%s': %s\n"),
                   gimp_file_get_utf8_name (file), error->message);
     }
 
diff --git a/app/gui/themes.c b/app/gui/themes.c
index 0e628da..567096b 100644
--- a/app/gui/themes.c
+++ b/app/gui/themes.c
@@ -271,9 +271,7 @@ themes_apply_theme (Gimp        *gimp,
                                             NULL, &error));
   if (! output)
     {
-      gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR,
-                    _("Could not open '%s' for writing: %s"),
-                    gimp_file_get_utf8_name (themerc), error->message);
+      gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
       g_clear_error (&error);
     }
   else
diff --git a/app/tools/gimpimagemaptool-settings.c b/app/tools/gimpimagemaptool-settings.c
index d92e7fc..ae8306b 100644
--- a/app/tools/gimpimagemaptool-settings.c
+++ b/app/tools/gimpimagemaptool-settings.c
@@ -219,12 +219,10 @@ gimp_image_map_tool_settings_export (GimpSettingsBox  *box,
                                             NULL, &error));
   if (! output)
     {
-      gimp_message (GIMP_TOOL (tool)->tool_info->gimp,
-                    G_OBJECT (gimp_tool_gui_get_dialog (tool->gui)),
-                    GIMP_MESSAGE_ERROR,
-                    _("Could not open '%s' for writing: %s"),
-                    gimp_file_get_utf8_name (file),
-                    error->message);
+      gimp_message_literal (GIMP_TOOL (tool)->tool_info->gimp,
+                            G_OBJECT (gimp_tool_gui_get_dialog (tool->gui)),
+                            GIMP_MESSAGE_ERROR,
+                            error->message);
       g_clear_error (&error);
       return FALSE;
     }
diff --git a/app/vectors/gimpvectors-export.c b/app/vectors/gimpvectors-export.c
index f03e288..31d3bee 100644
--- a/app/vectors/gimpvectors-export.c
+++ b/app/vectors/gimpvectors-export.c
@@ -74,16 +74,9 @@ gimp_vectors_export_file (const GimpImage    *image,
 
   output = G_OUTPUT_STREAM (g_file_replace (file,
                                             NULL, FALSE, G_FILE_CREATE_NONE,
-                                            NULL, &my_error));
+                                            NULL, error));
   if (! output)
-    {
-      g_set_error (error, my_error->domain, my_error->code,
-                   _("Could not open '%s' for writing: %s"),
-                   gimp_file_get_utf8_name (file),
-                   my_error->message);
-      g_clear_error (&my_error);
-      return FALSE;
-    }
+    return FALSE;
 
   string = gimp_vectors_export (image, vectors);
 
diff --git a/app/widgets/gimptextbuffer.c b/app/widgets/gimptextbuffer.c
index b1d182a..d1fdc56 100644
--- a/app/widgets/gimptextbuffer.c
+++ b/app/widgets/gimptextbuffer.c
@@ -1486,15 +1486,9 @@ gimp_text_buffer_save (GimpTextBuffer *buffer,
 
   output = G_OUTPUT_STREAM (g_file_replace (file,
                                             NULL, FALSE, G_FILE_CREATE_NONE,
-                                            NULL, &my_error));
+                                            NULL, error));
   if (! output)
-    {
-      g_set_error (error, my_error->domain, my_error->code,
-                   _("Could not open '%s' for writing: %s"),
-                   gimp_file_get_utf8_name (file), my_error->message);
-      g_clear_error (&my_error);
-      return FALSE;
-    }
+    return FALSE;
 
   if (selection_only)
     gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer),
diff --git a/app/xcf/xcf.c b/app/xcf/xcf.c
index 157536a..278670e 100644
--- a/app/xcf/xcf.c
+++ b/app/xcf/xcf.c
@@ -382,8 +382,9 @@ xcf_save_invoker (GimpProcedure         *procedure,
 #endif
   filename = g_file_get_parse_name (file);
 
-  info.output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL,
-                                                 &my_error));
+  info.output = G_OUTPUT_STREAM (g_file_replace (file,
+                                                 NULL, FALSE, G_FILE_CREATE_NONE,
+                                                 NULL, &my_error));
 
   if (info.output)
     {
@@ -420,12 +421,6 @@ xcf_save_invoker (GimpProcedure         *procedure,
       if (progress)
         gimp_progress_end (progress);
     }
-  else
-    {
-      g_propagate_prefixed_error (error, my_error,
-                                  _("Could not open '%s' for writing: "),
-                                  filename);
-    }
 
   g_free (filename);
   g_object_unref (file);
diff --git a/libgimpconfig/gimpconfigwriter.c b/libgimpconfig/gimpconfigwriter.c
index 8d1fdcd..f5f3d23 100644
--- a/libgimpconfig/gimpconfigwriter.c
+++ b/libgimpconfig/gimpconfigwriter.c
@@ -170,37 +170,30 @@ gimp_config_writer_new_gfile (GFile        *file,
 {
   GimpConfigWriter *writer;
   GOutputStream    *output;
-  GError           *my_error = NULL;
 
   g_return_val_if_fail (G_IS_FILE (file), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   if (atomic)
     {
-      output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE,
-                                                G_FILE_CREATE_NONE,
-                                                NULL, &my_error));
+      output = G_OUTPUT_STREAM (g_file_replace (file,
+                                                NULL, FALSE, G_FILE_CREATE_NONE,
+                                                NULL, error));
       if (! output)
-        g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
-                     _("Could not create temporary file for '%s': %s"),
-                     gimp_file_get_utf8_name (file), my_error->message);
+        g_prefix_error (error,
+                        _("Could not create temporary file for '%s': "),
+                        gimp_file_get_utf8_name (file));
     }
   else
     {
-      output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE,
+      output = G_OUTPUT_STREAM (g_file_replace (file,
+                                                NULL, FALSE,
                                                 G_FILE_CREATE_REPLACE_DESTINATION,
-                                                NULL, &my_error));
-      if (! output)
-        g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
-                     _("Could not open '%s' for writing: %s"),
-                     gimp_file_get_utf8_name (file), my_error->message);
+                                                NULL, error));
     }
 
   if (! output)
-    {
-      g_clear_error (&my_error);
-      return NULL;
-    }
+    return NULL;
 
   writer = g_slice_new0 (GimpConfigWriter);
 
diff --git a/plug-ins/common/file-csource.c b/plug-ins/common/file-csource.c
index 26f86c3..08b97fe 100644
--- a/plug-ins/common/file-csource.c
+++ b/plug-ins/common/file-csource.c
@@ -445,7 +445,9 @@ save_image (GFile   *file,
   gint           x, y, pad, n_bytes, bpp;
   gint           drawable_bpp;
 
-  output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
+  output = G_OUTPUT_STREAM (g_file_replace (file,
+                                            NULL, FALSE, G_FILE_CREATE_NONE,
+                                            NULL, error));
   if (output)
     {
       GOutputStream *buffered;
diff --git a/plug-ins/common/file-gbr.c b/plug-ins/common/file-gbr.c
index 1ac51bb..f7470e2 100644
--- a/plug-ins/common/file-gbr.c
+++ b/plug-ins/common/file-gbr.c
@@ -673,7 +673,9 @@ save_image (GFile   *file,
   gimp_progress_init_printf (_("Saving '%s'"),
                              g_file_get_parse_name (file));
 
-  output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
+  output = G_OUTPUT_STREAM (g_file_replace (file,
+                                            NULL, FALSE, G_FILE_CREATE_NONE,
+                                            NULL, error));
   if (! output)
     return FALSE;
 
diff --git a/plug-ins/common/file-gih.c b/plug-ins/common/file-gih.c
index d9c88a4..ff784b2 100644
--- a/plug-ins/common/file-gih.c
+++ b/plug-ins/common/file-gih.c
@@ -1292,7 +1292,9 @@ gih_save_image (GFile    *file,
   gimp_progress_init_printf (_("Saving '%s'"),
                              g_file_get_parse_name (file));
 
-  output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
+  output = G_OUTPUT_STREAM (g_file_replace (file,
+                                            NULL, FALSE, G_FILE_CREATE_NONE,
+                                            NULL, error));
   if (! output)
     return FALSE;
 
diff --git a/plug-ins/common/file-pat.c b/plug-ins/common/file-pat.c
index a78da17..c762737 100644
--- a/plug-ins/common/file-pat.c
+++ b/plug-ins/common/file-pat.c
@@ -517,7 +517,9 @@ save_image (GFile   *file,
   gimp_progress_init_printf (_("Saving '%s'"),
                              g_file_get_parse_name (file));
 
-  output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
+  output = G_OUTPUT_STREAM (g_file_replace (file,
+                                            NULL, FALSE, G_FILE_CREATE_NONE,
+                                            NULL, error));
   if (! output)
     return FALSE;
 
diff --git a/plug-ins/common/file-pix.c b/plug-ins/common/file-pix.c
index e941ee3..9f7fe07 100644
--- a/plug-ins/common/file-pix.c
+++ b/plug-ins/common/file-pix.c
@@ -536,7 +536,9 @@ save_image (GFile   *file,
   gimp_progress_init_printf (_("Saving '%s'"),
                              g_file_get_parse_name (file));
 
-  output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
+  output = G_OUTPUT_STREAM (g_file_replace (file,
+                                            NULL, FALSE, G_FILE_CREATE_NONE,
+                                            NULL, error));
   if (! output)
     return FALSE;
 
diff --git a/plug-ins/common/file-pnm.c b/plug-ins/common/file-pnm.c
index fc8b6a1..c625ab3 100644
--- a/plug-ins/common/file-pnm.c
+++ b/plug-ins/common/file-pnm.c
@@ -1046,7 +1046,9 @@ save_image (GFile     *file,
                              g_file_get_parse_name (file));
 
   /* open the file */
-  output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, 0, NULL, error));
+  output = G_OUTPUT_STREAM (g_file_replace (file,
+                                            NULL, FALSE, G_FILE_CREATE_NONE,
+                                            NULL, error));
   if (! output)
     return FALSE;
 


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