[gimp] app: manage the system and user gimprc paths as GFiles



commit 3e85deefb58296170e9a0b8384cfb272986eaa5f
Author: Michael Natterer <mitch gimp org>
Date:   Mon Jul 28 15:03:06 2014 +0200

    app: manage the system and user gimprc paths as GFiles

 app/app.c           |    4 +-
 app/app.h           |    4 +-
 app/config/gimprc.c |  108 ++++++++++++++++++++++++--------------------------
 app/config/gimprc.h |    9 ++--
 app/core/gimp.c     |   10 +++-
 app/core/gimp.h     |    4 +-
 app/main.c          |   18 ++++++++-
 7 files changed, 86 insertions(+), 71 deletions(-)
---
diff --git a/app/app.c b/app/app.c
index 783d99d..59384d0 100644
--- a/app/app.c
+++ b/app/app.c
@@ -140,8 +140,8 @@ app_exit (gint status)
 void
 app_run (const gchar         *full_prog_name,
          const gchar        **filenames,
-         const gchar         *alternate_system_gimprc,
-         const gchar         *alternate_gimprc,
+         GFile               *alternate_system_gimprc,
+         GFile               *alternate_gimprc,
          const gchar         *session_name,
          const gchar         *batch_interpreter,
          const gchar        **batch_commands,
diff --git a/app/app.h b/app/app.h
index f3e3793..0a25610 100644
--- a/app/app.h
+++ b/app/app.h
@@ -32,8 +32,8 @@ void  app_exit      (gint                 status) G_GNUC_NORETURN;
 
 void  app_run       (const gchar         *full_prog_name,
                      const gchar        **filenames,
-                     const gchar         *alternate_system_gimprc,
-                     const gchar         *alternate_gimprc,
+                     GFile               *alternate_system_gimprc,
+                     GFile               *alternate_gimprc,
                      const gchar         *session_name,
                      const gchar         *batch_interpreter,
                      const gchar        **batch_commands,
diff --git a/app/config/gimprc.c b/app/config/gimprc.c
index c9a15a2..14981ce 100644
--- a/app/config/gimprc.c
+++ b/app/config/gimprc.c
@@ -93,16 +93,16 @@ gimp_rc_class_init (GimpRcClass *klass)
                                                          G_PARAM_CONSTRUCT));
 
   g_object_class_install_property (object_class, PROP_SYSTEM_GIMPRC,
-                                   g_param_spec_string ("system-gimprc",
+                                   g_param_spec_object ("system-gimprc",
                                                         NULL, NULL,
-                                                        NULL,
+                                                        G_TYPE_FILE,
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_CONSTRUCT));
 
   g_object_class_install_property (object_class, PROP_USER_GIMPRC,
-                                   g_param_spec_string ("user-gimprc",
+                                   g_param_spec_object ("user-gimprc",
                                                         NULL, NULL,
-                                                        NULL,
+                                                        G_TYPE_FILE,
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_CONSTRUCT));
 }
@@ -132,12 +132,13 @@ gimp_rc_finalize (GObject *object)
 
   if (rc->system_gimprc)
     {
-      g_free (rc->system_gimprc);
+      g_object_unref (rc->system_gimprc);
       rc->system_gimprc = NULL;
     }
+
   if (rc->user_gimprc)
     {
-      g_free (rc->user_gimprc);
+      g_object_unref (rc->user_gimprc);
       rc->user_gimprc = NULL;
     }
 
@@ -150,18 +151,7 @@ gimp_rc_set_property (GObject      *object,
                       const GValue *value,
                       GParamSpec   *pspec)
 {
-  GimpRc      *rc       = GIMP_RC (object);
-  const gchar *filename = NULL;
-
-  switch (property_id)
-    {
-    case PROP_SYSTEM_GIMPRC:
-    case PROP_USER_GIMPRC:
-      filename = g_value_get_string (value);
-      break;
-    default:
-      break;
-    }
+  GimpRc *rc = GIMP_RC (object);
 
   switch (property_id)
     {
@@ -170,22 +160,23 @@ gimp_rc_set_property (GObject      *object,
       break;
 
     case PROP_SYSTEM_GIMPRC:
-      g_free (rc->system_gimprc);
+      if (rc->system_gimprc)
+        g_object_unref (rc->system_gimprc);
 
-      if (filename)
-        rc->system_gimprc = g_strdup (filename);
+      if (g_value_get_object (value))
+        rc->system_gimprc = g_value_dup_object (value);
       else
-        rc->system_gimprc = g_build_filename (gimp_sysconf_directory (),
-                                              "gimprc", NULL);
+        rc->system_gimprc = gimp_sysconf_directory_file ("gimprc", NULL);
       break;
 
     case PROP_USER_GIMPRC:
-      g_free (rc->user_gimprc);
+      if (rc->user_gimprc)
+        g_object_unref (rc->user_gimprc);
 
-      if (filename)
-        rc->user_gimprc = g_strdup (filename);
+      if (g_value_get_object (value))
+        rc->user_gimprc = g_value_dup_object (value);
       else
-        rc->user_gimprc = gimp_personal_rc_file ("gimprc");
+        rc->user_gimprc = gimp_directory_file ("gimprc", NULL);
       break;
 
    default:
@@ -208,11 +199,12 @@ gimp_rc_get_property (GObject    *object,
       g_value_set_boolean (value, rc->verbose);
       break;
     case PROP_SYSTEM_GIMPRC:
-      g_value_set_string (value, rc->system_gimprc);
+      g_value_set_object (value, rc->system_gimprc);
       break;
     case PROP_USER_GIMPRC:
-      g_value_set_string (value, rc->user_gimprc);
+      g_value_set_object (value, rc->user_gimprc);
       break;
+
    default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -257,10 +249,10 @@ gimp_rc_load (GimpRc *rc)
 
   if (rc->verbose)
     g_print ("Parsing '%s'\n",
-             gimp_filename_to_utf8 (rc->system_gimprc));
+             gimp_file_get_utf8_name (rc->system_gimprc));
 
-  if (! gimp_config_deserialize_file (GIMP_CONFIG (rc),
-                                      rc->system_gimprc, NULL, &error))
+  if (! gimp_config_deserialize_gfile (GIMP_CONFIG (rc),
+                                       rc->system_gimprc, NULL, &error))
     {
       if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
         g_message ("%s", error->message);
@@ -270,20 +262,16 @@ gimp_rc_load (GimpRc *rc)
 
   if (rc->verbose)
     g_print ("Parsing '%s'\n",
-             gimp_filename_to_utf8 (rc->user_gimprc));
+             gimp_file_get_utf8_name (rc->user_gimprc));
 
-  if (! gimp_config_deserialize_file (GIMP_CONFIG (rc),
-                                      rc->user_gimprc, NULL, &error))
+  if (! gimp_config_deserialize_gfile (GIMP_CONFIG (rc),
+                                       rc->user_gimprc, NULL, &error))
     {
       if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
         {
-          GFile *file;
-
           g_message ("%s", error->message);
 
-          file = g_file_new_for_path (rc->user_gimprc);
-          gimp_config_file_backup_on_error (file, "gimprc", NULL);
-          g_object_unref (file);
+          gimp_config_file_backup_on_error (rc->user_gimprc, "gimprc", NULL);
         }
 
       g_clear_error (&error);
@@ -326,15 +314,22 @@ gimp_rc_notify (GimpRc     *rc,
  * Returns: the new #GimpRc.
  */
 GimpRc *
-gimp_rc_new (const gchar *system_gimprc,
-             const gchar *user_gimprc,
-             gboolean     verbose)
+gimp_rc_new (GFile    *system_gimprc,
+             GFile    *user_gimprc,
+             gboolean  verbose)
 {
-  GimpRc *rc = g_object_new (GIMP_TYPE_RC,
-                             "verbose",       verbose,
-                             "system-gimprc", system_gimprc,
-                             "user-gimprc",   user_gimprc,
-                             NULL);
+  GimpRc *rc;
+
+  g_return_val_if_fail (system_gimprc == NULL || G_IS_FILE (system_gimprc),
+                        NULL);
+  g_return_val_if_fail (user_gimprc == NULL || G_IS_FILE (user_gimprc),
+                        NULL);
+
+  rc = g_object_new (GIMP_TYPE_RC,
+                     "verbose",       verbose,
+                     "system-gimprc", system_gimprc,
+                     "user-gimprc",   user_gimprc,
+                     NULL);
 
   gimp_rc_load (rc);
 
@@ -513,19 +508,20 @@ gimp_rc_save (GimpRc *rc)
 
   global = g_object_new (GIMP_TYPE_RC, NULL);
 
-  gimp_config_deserialize_file (GIMP_CONFIG (global),
-                                rc->system_gimprc, NULL, NULL);
+  gimp_config_deserialize_gfile (GIMP_CONFIG (global),
+                                 rc->system_gimprc, NULL, NULL);
 
-  header = g_strconcat (top, rc->system_gimprc, bottom, NULL);
+  header = g_strconcat (top, gimp_file_get_utf8_name (rc->system_gimprc),
+                        bottom, NULL);
 
   if (rc->verbose)
     g_print ("Writing '%s'\n",
-             gimp_filename_to_utf8 (rc->user_gimprc));
+             gimp_file_get_utf8_name (rc->user_gimprc));
 
-  if (! gimp_config_serialize_to_file (GIMP_CONFIG (rc),
-                                       rc->user_gimprc,
-                                       header, footer, global,
-                                       &error))
+  if (! gimp_config_serialize_to_gfile (GIMP_CONFIG (rc),
+                                        rc->user_gimprc,
+                                        header, footer, global,
+                                        &error))
     {
       g_message ("%s", error->message);
       g_error_free (error);
diff --git a/app/config/gimprc.h b/app/config/gimprc.h
index 65f8d64..d75cc30 100644
--- a/app/config/gimprc.h
+++ b/app/config/gimprc.h
@@ -37,8 +37,8 @@ struct _GimpRc
 {
   GimpPluginConfig  parent_instance;
 
-  gchar            *user_gimprc;
-  gchar            *system_gimprc;
+  GFile            *user_gimprc;
+  GFile            *system_gimprc;
   gboolean          verbose;
   gboolean          autosave;
   guint             save_idle_id;
@@ -51,9 +51,10 @@ struct _GimpRcClass
 
 
 GType     gimp_rc_get_type          (void) G_GNUC_CONST;
-GimpRc  * gimp_rc_new               (const gchar *system_gimprc,
-                                     const gchar *user_gimprc,
+GimpRc  * gimp_rc_new               (GFile       *system_gimprc,
+                                     GFile       *user_gimprc,
                                      gboolean     verbose);
+
 void      gimp_rc_set_autosave      (GimpRc      *gimprc,
                                      gboolean     autosave);
 void      gimp_rc_save              (GimpRc      *gimprc);
diff --git a/app/core/gimp.c b/app/core/gimp.c
index cfaacdc..b199f2f 100644
--- a/app/core/gimp.c
+++ b/app/core/gimp.c
@@ -938,13 +938,17 @@ gimp_edit_config_notify (GObject    *edit_config,
 }
 
 void
-gimp_load_config (Gimp        *gimp,
-                  const gchar *alternate_system_gimprc,
-                  const gchar *alternate_gimprc)
+gimp_load_config (Gimp  *gimp,
+                  GFile *alternate_system_gimprc,
+                  GFile *alternate_gimprc)
 {
   GimpRc *gimprc;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
+  g_return_if_fail (alternate_system_gimprc == NULL ||
+                    G_IS_FILE (alternate_system_gimprc));
+  g_return_if_fail (alternate_gimprc == NULL ||
+                    G_IS_FILE (alternate_gimprc));
   g_return_if_fail (gimp->config == NULL);
   g_return_if_fail (gimp->edit_config == NULL);
 
diff --git a/app/core/gimp.h b/app/core/gimp.h
index 1010de9..265a887 100644
--- a/app/core/gimp.h
+++ b/app/core/gimp.h
@@ -160,8 +160,8 @@ void           gimp_set_show_gui         (Gimp                *gimp,
 gboolean       gimp_get_show_gui         (Gimp                *gimp);
 
 void           gimp_load_config          (Gimp                *gimp,
-                                          const gchar         *alternate_system_gimprc,
-                                          const gchar         *alternate_gimprc);
+                                          GFile               *alternate_system_gimprc,
+                                          GFile               *alternate_gimprc);
 void           gimp_initialize           (Gimp                *gimp,
                                           GimpInitStatusFunc   status_callback);
 void           gimp_restore              (Gimp                *gimp,
diff --git a/app/main.c b/app/main.c
index ab31ec6..c8fa6f6 100644
--- a/app/main.c
+++ b/app/main.c
@@ -286,6 +286,8 @@ main (int    argc,
   GError         *error = NULL;
   const gchar    *abort_message;
   gchar          *basename;
+  GFile          *system_gimprc_file = NULL;
+  GFile          *user_gimprc_file   = NULL;
   gint            i;
 
 #if defined (__GNUC__) && defined (_WIN64)
@@ -449,10 +451,16 @@ main (int    argc,
 
   gimp_init_signal_handlers (stack_trace_mode);
 
+  if (system_gimprc)
+    system_gimprc_file = g_file_new_for_commandline_arg (system_gimprc);
+
+  if (user_gimprc)
+    user_gimprc_file = g_file_new_for_commandline_arg (user_gimprc);
+
   app_run (argv[0],
            filenames,
-           system_gimprc,
-           user_gimprc,
+           system_gimprc_file,
+           user_gimprc_file,
            session_name,
            batch_interpreter,
            batch_commands,
@@ -469,6 +477,12 @@ main (int    argc,
            stack_trace_mode,
            pdb_compat_mode);
 
+  if (system_gimprc_file)
+    g_object_unref (system_gimprc_file);
+
+  if (user_gimprc_file)
+    g_object_unref (user_gimprc_file);
+
   g_strfreev (argv);
 
   g_option_context_free (context);


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