[gimp] app: For testing, support to override names of "sessionrc" and "dockrc"



commit 091360fac48cf5da796640d1751e3e2770632bbe
Author: Martin Nordholts <martinn src gnome org>
Date:   Mon May 16 07:11:44 2011 +0200

    app: For testing, support to override names of "sessionrc" and "dockrc"
    
    Allow tests to specify specific sessionrc and dockrc files to use, so
    they can share other files in the testing gimpdirc.

 app/dialogs/dialogs.c |   32 ++++++++++++++++++++++----------
 app/gui/session.c     |   17 ++++++++++++-----
 2 files changed, 34 insertions(+), 15 deletions(-)
---
diff --git a/app/dialogs/dialogs.c b/app/dialogs/dialogs.c
index fd6fafe..1154f10 100644
--- a/app/dialogs/dialogs.c
+++ b/app/dialogs/dialogs.c
@@ -464,21 +464,33 @@ dialogs_ensure_factory_entry_on_recent_dock (GimpSessionInfo *info)
     }
 }
 
+static char *
+dialogs_get_dockrc_filepath (void)
+{
+  const gchar *filename;
+
+  filename = g_getenv ("GIMP_TESTING_DOCKRC_NAME");
+  if (! filename)
+    filename = "dockrc";
+
+  return gimp_personal_rc_file (filename);
+}
+
 void
 dialogs_load_recent_docks (Gimp *gimp)
 {
-  gchar  *filename;
+  char   *filepath;
   GError *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
 
-  filename = gimp_personal_rc_file ("dockrc");
+  filepath = dialogs_get_dockrc_filepath ();
 
   if (gimp->be_verbose)
-    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filepath));
 
   if (! gimp_config_deserialize_file (GIMP_CONFIG (global_recent_docks),
-                                      filename,
+                                      filepath,
                                       NULL, &error))
     {
       if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
@@ -496,24 +508,24 @@ dialogs_load_recent_docks (Gimp *gimp)
 
   gimp_list_reverse (GIMP_LIST (global_recent_docks));
 
-  g_free (filename);
+  g_free (filepath);
 }
 
 void
 dialogs_save_recent_docks (Gimp *gimp)
 {
-  gchar  *filename;
+  gchar  *filepath;
   GError *error = NULL;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
 
-  filename = gimp_personal_rc_file ("dockrc");
+  filepath = dialogs_get_dockrc_filepath ();
 
   if (gimp->be_verbose)
-    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
+    g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filepath));
 
   if (! gimp_config_serialize_to_file (GIMP_CONFIG (global_recent_docks),
-                                       filename,
+                                       filepath,
                                        "recently closed docks",
                                        "end of recently closed docks",
                                        NULL, &error))
@@ -522,7 +534,7 @@ dialogs_save_recent_docks (Gimp *gimp)
       g_clear_error (&error);
     }
 
-  g_free (filename);
+  g_free (filepath);
 }
 
 GtkWidget *
diff --git a/app/gui/session.c b/app/gui/session.c
index 0f6fc22..0381dc0 100644
--- a/app/gui/session.c
+++ b/app/gui/session.c
@@ -364,15 +364,22 @@ session_clear (Gimp    *gimp,
 static gchar *
 session_filename (Gimp *gimp)
 {
-  gchar *filename = gimp_personal_rc_file ("sessionrc");
+  const gchar *filename;
+  gchar       *filepath;
+
+  filename = g_getenv ("GIMP_TESTING_SESSIONRC_NAME");
+  if (! filename)
+    filename = "sessionrc";
+
+  filepath = gimp_personal_rc_file (filename);
 
   if (gimp->session_name)
     {
-      gchar *tmp = g_strconcat (filename, ".", gimp->session_name, NULL);
+      gchar *tmp = g_strconcat (filepath, ".", gimp->session_name, NULL);
 
-      g_free (filename);
-      filename = tmp;
+      g_free (filepath);
+      filepath = tmp;
     }
 
-  return filename;
+  return filepath;
 }



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