[gimp] app: use the new gimp_personal_rc_gfile() in lots of places



commit 98e7ec090bbd882a490f5e054ab032b158422432
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jul 1 19:54:50 2014 +0200

    app: use the new gimp_personal_rc_gfile() in lots of places
    
    and pass the GFile to the newly added GFile-based GimpConfig,
    GimpScanner etc. functions. This is starting to make sense now...

 app/core/gimp-contexts.c      |   58 ++++++++++++------------
 app/core/gimp-modules.c       |   22 +++++-----
 app/core/gimp-parasites.c     |   28 ++++++------
 app/core/gimp-templates.c     |   71 ++++++++++++++++-------------
 app/core/gimp-units.c         |   59 ++++++++++++++----------
 app/core/gimptooloptions.c    |   17 +++----
 app/dialogs/dialogs.c         |   40 ++++++++--------
 app/gui/color-history.c       |   30 ++++++------
 app/gui/session.c             |   99 +++++++++++++++++++++++------------------
 app/tools/gimp-tools.c        |   32 +++++++-------
 app/widgets/gimpcontrollers.c |   42 +++++++++--------
 app/widgets/gimpdevices.c     |   68 +++++++++++++---------------
 12 files changed, 297 insertions(+), 269 deletions(-)
---
diff --git a/app/core/gimp-contexts.c b/app/core/gimp-contexts.c
index 94d8d5d..bcb8224 100644
--- a/app/core/gimp-contexts.c
+++ b/app/core/gimp-contexts.c
@@ -19,10 +19,7 @@
 
 #include "config.h"
 
-#include <errno.h>
-
 #include <gdk-pixbuf/gdk-pixbuf.h>
-#include <glib/gstdio.h>
 #include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
@@ -31,6 +28,7 @@
 #include "core-types.h"
 
 #include "gimp.h"
+#include "gimperror.h"
 #include "gimp-contexts.h"
 #include "gimpcontext.h"
 
@@ -74,21 +72,23 @@ gboolean
 gimp_contexts_load (Gimp    *gimp,
                     GError **error)
 {
-  gchar    *filename;
+  GFile    *file;
   GError   *my_error = NULL;
   gboolean  success;
 
   g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  filename = gimp_personal_rc_file ("contextrc");
+  file = gimp_personal_rc_gfile ("contextrc");
 
   if (gimp->be_verbose)
-    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
+
+  success = gimp_config_deserialize_gfile (GIMP_CONFIG (gimp_get_user_context (gimp)),
+                                           file,
+                                           NULL, &my_error);
 
-  success = gimp_config_deserialize_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
-                                          filename,
-                                          NULL, &my_error);
+  g_object_unref (file);
 
   if (! success)
     {
@@ -103,8 +103,6 @@ gimp_contexts_load (Gimp    *gimp,
         }
     }
 
-  g_free (filename);
-
   return success;
 }
 
@@ -112,24 +110,24 @@ gboolean
 gimp_contexts_save (Gimp    *gimp,
                     GError **error)
 {
-  gchar    *filename;
+  GFile    *file;
   gboolean  success;
 
   g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  filename = gimp_personal_rc_file ("contextrc");
+  file = gimp_personal_rc_gfile ("contextrc");
 
   if (gimp->be_verbose)
-    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
 
-  success = gimp_config_serialize_to_file (GIMP_CONFIG (gimp_get_user_context (gimp)),
-                                           filename,
-                                           "GIMP user context",
-                                           "end of user context",
-                                           NULL, error);
+  success = gimp_config_serialize_to_gfile (GIMP_CONFIG (gimp_get_user_context (gimp)),
+                                            file,
+                                            "GIMP user context",
+                                            "end of user context",
+                                            NULL, error);
 
-  g_free (filename);
+  g_object_unref (file);
 
   return success;
 }
@@ -138,22 +136,26 @@ gboolean
 gimp_contexts_clear (Gimp    *gimp,
                      GError **error)
 {
-  gchar    *filename;
-  gboolean  success = TRUE;
+  GFile    *file;
+  GError   *my_error = NULL;
+  gboolean  success  = TRUE;
 
   g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
 
-  filename = gimp_personal_rc_file ("contextrc");
+  file = gimp_personal_rc_gfile ("contextrc");
 
-  if (g_unlink (filename) != 0 && errno != ENOENT)
+  if (! g_file_delete (file, NULL, &my_error) &&
+      my_error->code != G_IO_ERROR_NOT_FOUND)
     {
-      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
-                   _("Deleting \"%s\" failed: %s"),
-                   gimp_filename_to_utf8 (filename), g_strerror (errno));
       success = FALSE;
+
+      g_set_error (error, GIMP_ERROR, GIMP_FAILED,
+                   _("Deleting \"%s\" failed: %s"),
+                   gimp_file_get_utf8_name (file), my_error->message);
     }
 
-  g_free (filename);
+  g_clear_error (&my_error);
+  g_object_unref (file);
 
   return success;
 }
diff --git a/app/core/gimp-modules.c b/app/core/gimp-modules.c
index 57de9c3..645a886 100644
--- a/app/core/gimp-modules.c
+++ b/app/core/gimp-modules.c
@@ -63,7 +63,7 @@ gimp_modules_exit (Gimp *gimp)
 void
 gimp_modules_load (Gimp *gimp)
 {
-  gchar    *filename;
+  GFile    *file;
   gchar    *path;
   GScanner *scanner;
   gchar    *module_load_inhibit = NULL;
@@ -76,13 +76,13 @@ gimp_modules_load (Gimp *gimp)
   /* FIXME, gimp->be_verbose is not yet initialized in init() */
   gimp->module_db->verbose = gimp->be_verbose;
 
-  filename = gimp_personal_rc_file ("modulerc");
+  file = gimp_personal_rc_gfile ("modulerc");
 
   if (gimp->be_verbose)
-    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
 
-  scanner = gimp_scanner_new_file (filename, NULL);
-  g_free (filename);
+  scanner = gimp_scanner_new_gfile (file, NULL);
+  g_object_unref (file);
 
   if (scanner)
     {
@@ -182,7 +182,7 @@ gimp_modules_unload (Gimp *gimp)
       GimpConfigWriter *writer;
       GString          *str;
       const gchar      *p;
-      gchar            *filename;
+      GFile            *file;
       GError           *error = NULL;
 
       str = g_string_new (NULL);
@@ -192,14 +192,14 @@ gimp_modules_unload (Gimp *gimp)
       else
         p = "";
 
-      filename = gimp_personal_rc_file ("modulerc");
+      file = gimp_personal_rc_gfile ("modulerc");
 
       if (gimp->be_verbose)
-        g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
+        g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
 
-      writer = gimp_config_writer_new_file (filename, TRUE,
-                                            "GIMP modulerc", &error);
-      g_free (filename);
+      writer = gimp_config_writer_new_gfile (file, TRUE,
+                                             "GIMP modulerc", &error);
+      g_object_unref (file);
 
       if (writer)
         {
diff --git a/app/core/gimp-parasites.c b/app/core/gimp-parasites.c
index 639bff6..cc9f414 100644
--- a/app/core/gimp-parasites.c
+++ b/app/core/gimp-parasites.c
@@ -114,18 +114,18 @@ gimp_parasite_shift_parent (GimpParasite *parasite)
 void
 gimp_parasiterc_load (Gimp *gimp)
 {
-  gchar  *filename;
+  GFile  *file;
   GError *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
 
-  filename = gimp_personal_rc_file ("parasiterc");
+  file = gimp_personal_rc_gfile ("parasiterc");
 
   if (gimp->be_verbose)
-    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
 
-  if (! gimp_config_deserialize_file (GIMP_CONFIG (gimp->parasites),
-                                      filename, NULL, &error))
+  if (! gimp_config_deserialize_gfile (GIMP_CONFIG (gimp->parasites),
+                                       file, NULL, &error))
     {
       if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
         gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
@@ -133,7 +133,7 @@ gimp_parasiterc_load (Gimp *gimp)
       g_error_free (error);
     }
 
-  g_free (filename);
+  g_object_unref (file);
 }
 
 void
@@ -146,25 +146,25 @@ gimp_parasiterc_save (Gimp *gimp)
   const gchar *footer =
     "end of parasiterc";
 
-  gchar  *filename;
+  GFile  *file;
   GError *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
   g_return_if_fail (GIMP_IS_PARASITE_LIST (gimp->parasites));
 
-  filename = gimp_personal_rc_file ("parasiterc");
+  file = gimp_personal_rc_gfile ("parasiterc");
 
   if (gimp->be_verbose)
-    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
 
-  if (! gimp_config_serialize_to_file (GIMP_CONFIG (gimp->parasites),
-                                       filename,
-                                       header, footer, NULL,
-                                       &error))
+  if (! gimp_config_serialize_to_gfile (GIMP_CONFIG (gimp->parasites),
+                                        file,
+                                        header, footer, NULL,
+                                        &error))
     {
       gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
       g_error_free (error);
     }
 
-  g_free (filename);
+  g_object_unref (file);
 }
diff --git a/app/core/gimp-templates.c b/app/core/gimp-templates.c
index bb44ec6..0c28831 100644
--- a/app/core/gimp-templates.c
+++ b/app/core/gimp-templates.c
@@ -38,30 +38,33 @@
 void
 gimp_templates_load (Gimp *gimp)
 {
-  gchar  *filename;
+  GFile  *file;
   GError *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
   g_return_if_fail (GIMP_IS_LIST (gimp->templates));
 
-  filename = gimp_personal_rc_file ("templaterc");
+  file = gimp_personal_rc_gfile ("templaterc");
 
   if (gimp->be_verbose)
-    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
 
-  if (! gimp_config_deserialize_file (GIMP_CONFIG (gimp->templates),
-                                      filename, NULL, &error))
+  if (! gimp_config_deserialize_gfile (GIMP_CONFIG (gimp->templates),
+                                       file, NULL, &error))
     {
       if (error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
         {
+          gchar *tmp;
+
           g_clear_error (&error);
-          g_free (filename);
+          g_object_unref (file);
 
-          filename = g_build_filename (gimp_sysconf_directory (),
-                                       "templaterc", NULL);
+          tmp = g_build_filename (gimp_sysconf_directory (), "templaterc", NULL);
+          file = g_file_new_for_path (tmp);
+          g_free (tmp);
 
-          if (! gimp_config_deserialize_file (GIMP_CONFIG (gimp->templates),
-                                              filename, NULL, &error))
+          if (! gimp_config_deserialize_gfile (GIMP_CONFIG (gimp->templates),
+                                               file, NULL, &error))
             {
               gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR,
                                     error->message);
@@ -77,7 +80,7 @@ gimp_templates_load (Gimp *gimp)
 
   gimp_list_reverse (GIMP_LIST (gimp->templates));
 
-  g_free (filename);
+  g_object_unref (file);
 }
 
 void
@@ -90,27 +93,27 @@ gimp_templates_save (Gimp *gimp)
   const gchar *footer =
     "end of templaterc";
 
-  gchar  *filename;
+  GFile  *file;
   GError *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
   g_return_if_fail (GIMP_IS_LIST (gimp->templates));
 
-  filename = gimp_personal_rc_file ("templaterc");
+  file = gimp_personal_rc_gfile ("templaterc");
 
   if (gimp->be_verbose)
-    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
 
-  if (! gimp_config_serialize_to_file (GIMP_CONFIG (gimp->templates),
-                                       filename,
-                                       header, footer, NULL,
-                                       &error))
+  if (! gimp_config_serialize_to_gfile (GIMP_CONFIG (gimp->templates),
+                                        file,
+                                        header, footer, NULL,
+                                        &error))
     {
       gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
       g_error_free (error);
     }
 
-  g_free (filename);
+  g_object_unref (file);
 }
 
 
@@ -170,13 +173,17 @@ void
 gimp_templates_migrate (const gchar *olddir)
 {
   GimpContainer *templates = gimp_list_new (GIMP_TYPE_TEMPLATE, TRUE);
-  gchar         *filename  = gimp_personal_rc_file ("templaterc");
+  GFile         *file      = gimp_personal_rc_gfile ("templaterc");
 
-  if (gimp_config_deserialize_file (GIMP_CONFIG (templates), filename,
-                                    NULL, NULL))
+  if (gimp_config_deserialize_gfile (GIMP_CONFIG (templates), file,
+                                     NULL, NULL))
     {
-      gchar *tmp = g_build_filename (gimp_sysconf_directory (),
-                                     "templaterc", NULL);
+      gchar *tmp;
+      GFile *sysconf_file;
+
+      tmp = g_build_filename (gimp_sysconf_directory (), "templaterc", NULL);
+      sysconf_file = g_file_new_for_path (tmp);
+      g_free (tmp);
 
       if (olddir && (strstr (olddir, "2.0") || strstr (olddir, "2.2")))
         {
@@ -190,24 +197,24 @@ gimp_templates_migrate (const gchar *olddir)
 
           class->get_child_by_name = gimp_templates_migrate_get_child_by_name;
 
-          gimp_config_deserialize_file (GIMP_CONFIG (templates),
-                                        tmp, NULL, NULL);
+          gimp_config_deserialize_gfile (GIMP_CONFIG (templates),
+                                         sysconf_file, NULL, NULL);
 
           class->get_child_by_name = func;
         }
       else
         {
-          gimp_config_deserialize_file (GIMP_CONFIG (templates),
-                                        tmp, NULL, NULL);
+          gimp_config_deserialize_gfile (GIMP_CONFIG (templates),
+                                         sysconf_file, NULL, NULL);
         }
 
-      g_free (tmp);
+      g_object_unref (sysconf_file);
 
       gimp_list_reverse (GIMP_LIST (templates));
 
-      gimp_config_serialize_to_file (GIMP_CONFIG (templates), filename,
-                                     NULL, NULL, NULL, NULL);
+      gimp_config_serialize_to_gfile (GIMP_CONFIG (templates), file,
+                                      NULL, NULL, NULL, NULL);
     }
 
-  g_free (filename);
+  g_object_unref (file);
 }
diff --git a/app/core/gimp-units.c b/app/core/gimp-units.c
index d1a2eac..8032854 100644
--- a/app/core/gimp-units.c
+++ b/app/core/gimp-units.c
@@ -83,33 +83,38 @@ enum
 void
 gimp_unitrc_load (Gimp *gimp)
 {
-  gchar      *filename;
+  GFile      *file;
   GScanner   *scanner;
   GTokenType  token;
   GError     *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
 
-  filename = gimp_personal_rc_file ("unitrc");
+  file = gimp_personal_rc_gfile ("unitrc");
 
   if (gimp->be_verbose)
-    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
 
-  scanner = gimp_scanner_new_file (filename, &error);
+  scanner = gimp_scanner_new_gfile (file, &error);
 
   if (! scanner && error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
     {
+      gchar *tmp;
+
       g_clear_error (&error);
-      g_free (filename);
+      g_object_unref (file);
+
+      tmp = g_build_filename (gimp_sysconf_directory (), "unitrc", NULL);
+      file = g_file_new_for_path (tmp);
+      g_free (tmp);
 
-      filename = g_build_filename (gimp_sysconf_directory (), "unitrc", NULL);
-      scanner = gimp_scanner_new_file (filename, NULL);
+      scanner = gimp_scanner_new_gfile (file, NULL);
     }
 
   if (! scanner)
     {
       g_clear_error (&error);
-      g_free (filename);
+      g_object_unref (file);
       return;
     }
 
@@ -162,6 +167,8 @@ gimp_unitrc_load (Gimp *gimp)
 
   if (token != G_TOKEN_LEFT_PAREN)
     {
+      gchar *tmp;
+
       g_scanner_get_next_token (scanner);
       g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
                              _("fatal parse error"), TRUE);
@@ -169,41 +176,43 @@ gimp_unitrc_load (Gimp *gimp)
       gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
       g_clear_error (&error);
 
-      gimp_config_file_backup_on_error (filename, "unitrc", NULL);
+      tmp = g_file_get_path (file);
+      gimp_config_file_backup_on_error (tmp, "unitrc", NULL);
+      g_free (tmp);
     }
 
   gimp_scanner_destroy (scanner);
-  g_free (filename);
+  g_object_unref (file);
 }
 
 void
 gimp_unitrc_save (Gimp *gimp)
 {
   GimpConfigWriter *writer;
-  gchar            *filename;
+  GFile            *file;
   gint              i;
   GError           *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
 
-  filename = gimp_personal_rc_file ("unitrc");
+  file = gimp_personal_rc_gfile ("unitrc");
 
   if (gimp->be_verbose)
-    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
 
   writer =
-    gimp_config_writer_new_file (filename,
-                                 TRUE,
-                                 "GIMP units\n\n"
-                                 "This file contains the user unit database. "
-                                 "You can edit this list with the unit "
-                                 "editor. You are not supposed to edit it "
-                                 "manually, but of course you can do.\n"
-                                 "This file will be entirely rewritten each "
-                                 "time you exit.",
-                                 NULL);
-
-  g_free (filename);
+    gimp_config_writer_new_gfile (file,
+                                  TRUE,
+                                  "GIMP units\n\n"
+                                  "This file contains the user unit database. "
+                                  "You can edit this list with the unit "
+                                  "editor. You are not supposed to edit it "
+                                  "manually, but of course you can do.\n"
+                                  "This file will be entirely rewritten each "
+                                  "time you exit.",
+                                  NULL);
+
+  g_object_unref (file);
 
   if (!writer)
     return;
diff --git a/app/core/gimptooloptions.c b/app/core/gimptooloptions.c
index 017b2f9..30cd5e4 100644
--- a/app/core/gimptooloptions.c
+++ b/app/core/gimptooloptions.c
@@ -369,20 +369,17 @@ gimp_tool_options_delete (GimpToolOptions  *tool_options,
   if (tool_options->tool_info->gimp->be_verbose)
     g_print ("Deleting '%s'\n", gimp_file_get_utf8_name (file));
 
-  if (! g_file_delete (file, NULL, &my_error))
+  if (! g_file_delete (file, NULL, &my_error) &&
+      my_error->code != G_IO_ERROR_NOT_FOUND)
     {
-      if (my_error->code != G_IO_ERROR_NOT_FOUND)
-        {
-          success = FALSE;
-
-          g_set_error (error, GIMP_ERROR, GIMP_FAILED,
-                       _("Deleting \"%s\" failed: %s"),
-                       gimp_file_get_utf8_name (file), my_error->message);
-        }
+      success = FALSE;
 
-      g_clear_error (&my_error);
+      g_set_error (error, GIMP_ERROR, GIMP_FAILED,
+                   _("Deleting \"%s\" failed: %s"),
+                   gimp_file_get_utf8_name (file), my_error->message);
     }
 
+  g_clear_error (&my_error);
   g_object_unref (file);
 
   return success;
diff --git a/app/dialogs/dialogs.c b/app/dialogs/dialogs.c
index c48d9ff..88a991d 100644
--- a/app/dialogs/dialogs.c
+++ b/app/dialogs/dialogs.c
@@ -569,8 +569,8 @@ dialogs_ensure_factory_entry_on_recent_dock (GimpSessionInfo *info)
     }
 }
 
-static char *
-dialogs_get_dockrc_filename (void)
+static GFile *
+dialogs_get_dockrc_file (void)
 {
   const gchar *basename;
 
@@ -578,25 +578,25 @@ dialogs_get_dockrc_filename (void)
   if (! basename)
     basename = "dockrc";
 
-  return gimp_personal_rc_file (basename);
+  return gimp_personal_rc_gfile (basename);
 }
 
 void
 dialogs_load_recent_docks (Gimp *gimp)
 {
-  gchar  *filename;
+  GFile  *file;
   GError *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
 
-  filename = dialogs_get_dockrc_filename ();
+  file = dialogs_get_dockrc_file ();
 
   if (gimp->be_verbose)
-    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
 
-  if (! gimp_config_deserialize_file (GIMP_CONFIG (global_recent_docks),
-                                      filename,
-                                      NULL, &error))
+  if (! gimp_config_deserialize_gfile (GIMP_CONFIG (global_recent_docks),
+                                       file,
+                                       NULL, &error))
     {
       if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
         gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
@@ -604,6 +604,8 @@ dialogs_load_recent_docks (Gimp *gimp)
       g_clear_error (&error);
     }
 
+  g_object_unref (file);
+
   /* In GIMP 2.6 dockrc did not contain the factory entries for the
    * session infos, so set that up manually if needed
    */
@@ -612,34 +614,32 @@ dialogs_load_recent_docks (Gimp *gimp)
                           NULL);
 
   gimp_list_reverse (GIMP_LIST (global_recent_docks));
-
-  g_free (filename);
 }
 
 void
 dialogs_save_recent_docks (Gimp *gimp)
 {
-  gchar  *filename;
+  GFile  *file;
   GError *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
 
-  filename = dialogs_get_dockrc_filename ();
+  file = dialogs_get_dockrc_file ();
 
   if (gimp->be_verbose)
-    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
 
-  if (! gimp_config_serialize_to_file (GIMP_CONFIG (global_recent_docks),
-                                       filename,
-                                       "recently closed docks",
-                                       "end of recently closed docks",
-                                       NULL, &error))
+  if (! gimp_config_serialize_to_gfile (GIMP_CONFIG (global_recent_docks),
+                                        file,
+                                        "recently closed docks",
+                                        "end of recently closed docks",
+                                        NULL, &error))
     {
       gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
       g_clear_error (&error);
     }
 
-  g_free (filename);
+  g_object_unref (file);
 }
 
 GtkWidget *
diff --git a/app/gui/color-history.c b/app/gui/color-history.c
index 90d6a6d..4e3286a 100644
--- a/app/gui/color-history.c
+++ b/app/gui/color-history.c
@@ -52,23 +52,23 @@ void
 color_history_save (Gimp *gimp)
 {
   GimpConfigWriter *writer;
-  gchar            *filename;
+  GFile            *file;
   gint              i;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
 
-  filename = gimp_personal_rc_file ("colorrc");
+  file = gimp_personal_rc_gfile ("colorrc");
 
   if (gimp->be_verbose)
-    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
 
-  writer = gimp_config_writer_new_file (filename,
-                                        TRUE,
-                                        "GIMP colorrc\n\n"
-                                        "This file holds a list of "
-                                        "recently used colors.",
-                                        NULL);
-  g_free (filename);
+  writer = gimp_config_writer_new_gfile (file,
+                                         TRUE,
+                                         "GIMP colorrc\n\n"
+                                         "This file holds a list of "
+                                         "recently used colors.",
+                                         NULL);
+  g_object_unref (file);
 
   if (!writer)
     return;
@@ -105,19 +105,19 @@ color_history_save (Gimp *gimp)
 void
 color_history_restore (Gimp *gimp)
 {
-  gchar      *filename;
+  GFile      *file;
   GScanner   *scanner;
   GTokenType  token;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
 
-  filename = gimp_personal_rc_file ("colorrc");
+  file = gimp_personal_rc_gfile ("colorrc");
 
   if (gimp->be_verbose)
-    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
 
-  scanner = gimp_scanner_new_file (filename, NULL);
-  g_free (filename);
+  scanner = gimp_scanner_new_gfile (file, NULL);
+  g_object_unref (file);
 
   if (! scanner)
     return;
diff --git a/app/gui/session.c b/app/gui/session.c
index 1674edb..d6349d3 100644
--- a/app/gui/session.c
+++ b/app/gui/session.c
@@ -20,10 +20,6 @@
 
 #include "config.h"
 
-#include <errno.h>
-#include <string.h>
-
-#include <glib/gstdio.h>
 #include <gtk/gtk.h>
 
 #include "libgimpbase/gimpbase.h"
@@ -35,6 +31,7 @@
 #include "config/gimpguiconfig.h"
 
 #include "core/gimp.h"
+#include "core/gimperror.h"
 
 #include "widgets/gimpdialogfactory.h"
 #include "widgets/gimpsessioninfo.h"
@@ -58,7 +55,7 @@ enum
 };
 
 
-static gchar * session_filename (Gimp *gimp);
+static GFile * session_file (Gimp *gimp);
 
 
 /*  private variables  */
@@ -71,36 +68,40 @@ static gboolean   sessionrc_deleted = FALSE;
 void
 session_init (Gimp *gimp)
 {
-  gchar      *filename;
+  GFile      *file;
   GScanner   *scanner;
   GTokenType  token;
   GError     *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
 
-  filename = session_filename (gimp);
+  file = session_file (gimp);
 
-  scanner = gimp_scanner_new_file (filename, &error);
+  scanner = gimp_scanner_new_gfile (file, &error);
 
   if (! scanner && error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
     {
+      gchar *tmp;
+
       g_clear_error (&error);
-      g_free (filename);
+      g_object_unref (file);
 
-      filename = g_build_filename (gimp_sysconf_directory (),
-                                   "sessionrc", NULL);
-      scanner = gimp_scanner_new_file (filename, NULL);
+      tmp = g_build_filename (gimp_sysconf_directory (), "sessionrc", NULL);
+      file = g_file_new_for_path (tmp);
+      g_free (tmp);
+
+      scanner = gimp_scanner_new_gfile (file, NULL);
     }
 
   if (! scanner)
     {
       g_clear_error (&error);
-      g_free (filename);
+      g_object_unref (file);
       return;
     }
 
   if (gimp->be_verbose)
-    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
 
   g_scanner_scope_add_symbol (scanner, 0, "session-info",
                               GINT_TO_POINTER (SESSION_INFO));
@@ -297,14 +298,18 @@ session_init (Gimp *gimp)
 
   if (error)
     {
+      gchar *tmp;
+
       gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
       g_clear_error (&error);
 
-      gimp_config_file_backup_on_error (filename, "sessionrc", NULL);
+      tmp = g_file_get_path (file);
+      gimp_config_file_backup_on_error (tmp, "sessionrc", NULL);
+      g_free (tmp);
     }
 
   gimp_scanner_destroy (scanner);
-  g_free (filename);
+  g_object_unref (file);
 
   dialogs_load_recent_docks (gimp);
 }
@@ -341,7 +346,7 @@ session_save (Gimp     *gimp,
               gboolean  always_save)
 {
   GimpConfigWriter *writer;
-  gchar            *filename;
+  GFile            *file;
   GError           *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
@@ -349,25 +354,25 @@ session_save (Gimp     *gimp,
   if (sessionrc_deleted && ! always_save)
     return;
 
-  filename = session_filename (gimp);
+  file = session_file (gimp);
 
   if (gimp->be_verbose)
-    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
 
   writer =
-    gimp_config_writer_new_file (filename,
-                                 TRUE,
-                                 "GIMP sessionrc\n\n"
-                                 "This file takes session-specific info "
-                                 "(that is info, you want to keep between "
-                                 "two GIMP sessions).  You are not supposed "
-                                 "to edit it manually, but of course you "
-                                 "can do.  The sessionrc will be entirely "
-                                 "rewritten every time you quit GIMP.  "
-                                 "If this file isn't found, defaults are "
-                                 "used.",
-                                 NULL);
-  g_free (filename);
+    gimp_config_writer_new_gfile (file,
+                                  TRUE,
+                                  "GIMP sessionrc\n\n"
+                                  "This file takes session-specific info "
+                                  "(that is info, you want to keep between "
+                                  "two GIMP sessions).  You are not supposed "
+                                  "to edit it manually, but of course you "
+                                  "can do.  The sessionrc will be entirely "
+                                  "rewritten every time you quit GIMP.  "
+                                  "If this file isn't found, defaults are "
+                                  "used.",
+                                  NULL);
+  g_object_unref (file);
 
   if (!writer)
     return;
@@ -412,37 +417,42 @@ gboolean
 session_clear (Gimp    *gimp,
                GError **error)
 {
-  gchar    *filename;
-  gboolean  success = TRUE;
+  GFile    *file;
+  GError   *my_error = NULL;
+  gboolean  success  = TRUE;
 
   g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  filename = session_filename (gimp);
+  file = session_file (gimp);
 
-  if (g_unlink (filename) != 0 && errno != ENOENT)
+  if (! g_file_delete (file, NULL, &my_error) &&
+      my_error->code != G_IO_ERROR_NOT_FOUND)
     {
-      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
-                  _("Deleting \"%s\" failed: %s"),
-                   gimp_filename_to_utf8 (filename), g_strerror (errno));
       success = FALSE;
+
+      g_set_error (error, GIMP_ERROR, GIMP_FAILED,
+                   _("Deleting \"%s\" failed: %s"),
+                   gimp_file_get_utf8_name (file), my_error->message);
     }
   else
     {
       sessionrc_deleted = TRUE;
     }
 
-  g_free (filename);
+  g_clear_error (&my_error);
+  g_object_unref (file);
 
   return success;
 }
 
 
-static gchar *
-session_filename (Gimp *gimp)
+static GFile *
+session_file (Gimp *gimp)
 {
   const gchar *basename;
   gchar       *filename;
+  GFile       *file;
 
   basename = g_getenv ("GIMP_TESTING_SESSIONRC_NAME");
   if (! basename)
@@ -458,5 +468,8 @@ session_filename (Gimp *gimp)
       filename = tmp;
     }
 
-  return filename;
+  file = g_file_new_for_path (filename);
+  g_free (filename);
+
+  return file;
 }
diff --git a/app/tools/gimp-tools.c b/app/tools/gimp-tools.c
index dd56ed3..cba6ea7 100644
--- a/app/tools/gimp-tools.c
+++ b/app/tools/gimp-tools.c
@@ -258,7 +258,7 @@ gimp_tools_restore (Gimp *gimp)
 {
   GimpContainer *gimp_list;
   GimpObject    *object;
-  gchar         *filename;
+  GFile         *file;
   GList         *list;
   GError        *error = NULL;
 
@@ -266,13 +266,13 @@ gimp_tools_restore (Gimp *gimp)
 
   gimp_list = gimp_list_new (GIMP_TYPE_TOOL_INFO, FALSE);
 
-  filename = gimp_personal_rc_file ("toolrc");
+  file = gimp_personal_rc_gfile ("toolrc");
 
   if (gimp->be_verbose)
-    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
 
-  if (gimp_config_deserialize_file (GIMP_CONFIG (gimp_list), filename,
-                                    NULL, NULL))
+  if (gimp_config_deserialize_gfile (GIMP_CONFIG (gimp_list), file,
+                                     NULL, NULL))
     {
       gint n = gimp_container_get_n_children (gimp->tool_info_list);
       gint i;
@@ -302,7 +302,7 @@ gimp_tools_restore (Gimp *gimp)
         }
     }
 
-  g_free (filename);
+  g_object_unref (file);
   g_object_unref (gimp_list);
 
   /* make the generic operation tool invisible by default */
@@ -383,7 +383,7 @@ gimp_tools_save (Gimp     *gimp,
                  gboolean  save_tool_options,
                  gboolean  always_save)
 {
-  gchar *filename;
+  GFile *file;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
 
@@ -411,17 +411,17 @@ gimp_tools_save (Gimp     *gimp,
         }
     }
 
-  filename = gimp_personal_rc_file ("toolrc");
+  file = gimp_personal_rc_gfile ("toolrc");
 
   if (gimp->be_verbose)
-    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
-
-  gimp_config_serialize_to_file (GIMP_CONFIG (gimp->tool_info_list),
-                                 filename,
-                                 "GIMP toolrc",
-                                 "end of toolrc",
-                                 NULL, NULL);
-  g_free (filename);
+    g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
+
+  gimp_config_serialize_to_gfile (GIMP_CONFIG (gimp->tool_info_list),
+                                  file,
+                                  "GIMP toolrc",
+                                  "end of toolrc",
+                                  NULL, NULL);
+  g_object_unref (file);
 }
 
 gboolean
diff --git a/app/widgets/gimpcontrollers.c b/app/widgets/gimpcontrollers.c
index 9d6a198..e2d7f13 100644
--- a/app/widgets/gimpcontrollers.c
+++ b/app/widgets/gimpcontrollers.c
@@ -130,7 +130,7 @@ gimp_controllers_restore (Gimp          *gimp,
                           GimpUIManager *ui_manager)
 {
   GimpControllerManager *manager;
-  gchar                 *filename;
+  GFile                 *file;
   GError                *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
@@ -143,24 +143,28 @@ gimp_controllers_restore (Gimp          *gimp,
 
   manager->ui_manager = g_object_ref (ui_manager);
 
-  filename = gimp_personal_rc_file ("controllerrc");
+  file = gimp_personal_rc_gfile ("controllerrc");
 
   if (gimp->be_verbose)
-    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
 
-  if (! gimp_config_deserialize_file (GIMP_CONFIG (manager->controllers),
-                                      filename, NULL, &error))
+  if (! gimp_config_deserialize_gfile (GIMP_CONFIG (manager->controllers),
+                                       file, NULL, &error))
     {
       if (error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
         {
+          gchar *tmp;
+
           g_clear_error (&error);
-          g_free (filename);
+          g_object_unref (file);
 
-          filename = g_build_filename (gimp_sysconf_directory (),
-                                       "controllerrc", NULL);
+          tmp = g_build_filename (gimp_sysconf_directory (),
+                                  "controllerrc", NULL);
+          file = g_file_new_for_path (tmp);
+          g_free (tmp);
 
-          if (! gimp_config_deserialize_file (GIMP_CONFIG (manager->controllers),
-                                              filename, NULL, &error))
+          if (! gimp_config_deserialize_gfile (GIMP_CONFIG (manager->controllers),
+                                               file, NULL, &error))
             {
               gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR,
                                     error->message);
@@ -176,7 +180,7 @@ gimp_controllers_restore (Gimp          *gimp,
 
   gimp_list_reverse (GIMP_LIST (manager->controllers));
 
-  g_free (filename);
+  g_object_unref (file);
 }
 
 void
@@ -190,7 +194,7 @@ gimp_controllers_save (Gimp *gimp)
     "end of controllerrc";
 
   GimpControllerManager *manager;
-  gchar                 *filename;
+  GFile                 *file;
   GError                *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
@@ -199,21 +203,21 @@ gimp_controllers_save (Gimp *gimp)
 
   g_return_if_fail (manager != NULL);
 
-  filename = gimp_personal_rc_file ("controllerrc");
+  file = gimp_personal_rc_gfile ("controllerrc");
 
   if (gimp->be_verbose)
-    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
 
-  if (! gimp_config_serialize_to_file (GIMP_CONFIG (manager->controllers),
-                                       filename,
-                                       header, footer, NULL,
-                                       &error))
+  if (! gimp_config_serialize_to_gfile (GIMP_CONFIG (manager->controllers),
+                                        file,
+                                        header, footer, NULL,
+                                        &error))
     {
       gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
       g_error_free (error);
     }
 
-  g_free (filename);
+  g_object_unref (file);
 }
 
 GimpContainer *
diff --git a/app/widgets/gimpdevices.c b/app/widgets/gimpdevices.c
index 497c332..4d822f6 100644
--- a/app/widgets/gimpdevices.c
+++ b/app/widgets/gimpdevices.c
@@ -17,11 +17,6 @@
 
 #include "config.h"
 
-#include <errno.h>
-
-#undef GSEAL_ENABLE
-
-#include <glib/gstdio.h>
 #include <gegl.h>
 #include <gtk/gtk.h>
 
@@ -29,14 +24,11 @@
 #include "libgimpconfig/gimpconfig.h"
 #include "libgimpbase/gimpbase.h"
 
-#ifdef G_OS_WIN32
-#include "libgimpbase/gimpwin32-io.h"
-#endif
-
 #include "widgets-types.h"
 
 #include "core/gimp.h"
 #include "core/gimpdatafactory.h"
+#include "core/gimperror.h"
 #include "core/gimpgradient.h"
 #include "core/gimplist.h"
 #include "core/gimppattern.h"
@@ -96,7 +88,7 @@ gimp_devices_restore (Gimp *gimp)
   GimpContext       *user_context;
   GimpDeviceInfo    *current_device;
   GList             *list;
-  gchar             *filename;
+  GFile             *file;
   GError            *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
@@ -119,15 +111,15 @@ gimp_devices_restore (Gimp *gimp)
       gimp_device_info_set_default_tool (device_info);
     }
 
-  filename = gimp_personal_rc_file ("devicerc");
+  file = gimp_personal_rc_gfile ("devicerc");
 
   if (gimp->be_verbose)
-    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
 
-  if (! gimp_config_deserialize_file (GIMP_CONFIG (manager),
-                                      filename,
-                                      gimp,
-                                      &error))
+  if (! gimp_config_deserialize_gfile (GIMP_CONFIG (manager),
+                                       file,
+                                       gimp,
+                                       &error))
     {
       if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
         gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
@@ -136,7 +128,7 @@ gimp_devices_restore (Gimp *gimp)
       /* don't bail out here */
     }
 
-  g_free (filename);
+  g_object_unref (file);
 
   current_device = gimp_device_manager_get_current_device (manager);
 
@@ -150,7 +142,7 @@ gimp_devices_save (Gimp     *gimp,
                    gboolean  always_save)
 {
   GimpDeviceManager *manager;
-  gchar             *filename;
+  GFile             *file;
   GError            *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
@@ -162,23 +154,23 @@ gimp_devices_save (Gimp     *gimp,
   if (devicerc_deleted && ! always_save)
     return;
 
-  filename = gimp_personal_rc_file ("devicerc");
+  file = gimp_personal_rc_gfile ("devicerc");
 
   if (gimp->be_verbose)
-    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
-
-  if (! gimp_config_serialize_to_file (GIMP_CONFIG (manager),
-                                       filename,
-                                       "GIMP devicerc",
-                                       "end of devicerc",
-                                       NULL,
-                                       &error))
+    g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
+
+  if (! gimp_config_serialize_to_gfile (GIMP_CONFIG (manager),
+                                        file,
+                                        "GIMP devicerc",
+                                        "end of devicerc",
+                                        NULL,
+                                        &error))
     {
       gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
       g_error_free (error);
     }
 
-  g_free (filename);
+  g_object_unref (file);
 
   devicerc_deleted = FALSE;
 }
@@ -188,8 +180,9 @@ gimp_devices_clear (Gimp    *gimp,
                     GError **error)
 {
   GimpDeviceManager *manager;
-  gchar             *filename;
-  gboolean           success = TRUE;
+  GFile             *file;
+  GError            *my_error = NULL;
+  gboolean           success  = TRUE;
 
   g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
 
@@ -197,21 +190,24 @@ gimp_devices_clear (Gimp    *gimp,
 
   g_return_val_if_fail (GIMP_IS_DEVICE_MANAGER (manager), FALSE);
 
-  filename = gimp_personal_rc_file ("devicerc");
+  file = gimp_personal_rc_gfile ("devicerc");
 
-  if (g_unlink (filename) != 0 && errno != ENOENT)
+  if (! g_file_delete (file, NULL, &my_error) &&
+      my_error->code != G_IO_ERROR_NOT_FOUND)
     {
-      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
-                  _("Deleting \"%s\" failed: %s"),
-                   gimp_filename_to_utf8 (filename), g_strerror (errno));
       success = FALSE;
+
+      g_set_error (error, GIMP_ERROR, GIMP_FAILED,
+                   _("Deleting \"%s\" failed: %s"),
+                   gimp_file_get_utf8_name (file), my_error->message);
     }
   else
     {
       devicerc_deleted = TRUE;
     }
 
-  g_free (filename);
+  g_clear_error (&my_error);
+  g_object_unref (file);
 
   return success;
 }



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