[gimp] libgimpbase: Support changing GIMP2_DIRECTORY at run-time
- From: Martin Nordholts <martinn src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gimp] libgimpbase: Support changing GIMP2_DIRECTORY at run-time
- Date: Fri, 29 Jan 2010 17:33:36 +0000 (UTC)
commit 5d9dde1d479bf153f63ee9c03571069fcb8266b2
Author: Martin Nordholts <martinn src gnome org>
Date: Fri Jan 29 17:47:30 2010 +0100
libgimpbase: Support changing GIMP2_DIRECTORY at run-time
In order to be able to change GIMP2_DIRECTORY during run-time, check
for changes to GIMP2_DIRECTORY in gimp_directory().
This is typically useful in test case where you could read from one
GIMP2_DIRECTORY at start-up and then write to a different
GIMP2_DIRECTORY at shut down.
The documentation for this function does not suggest that the value is
cached and thus the old behavior can be considered a bug. It is hard
to imagine why anyone would change GIMP2_DIRECTORY at run-time in a
script for example and *not* expect gimp_directory() to return the
updated gimp_dir.
libgimpbase/gimpenv.c | 42 ++++++++++++++++++++++++++++++++++++++----
1 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/libgimpbase/gimpenv.c b/libgimpbase/gimpenv.c
index d2448ba..bdbfda0 100644
--- a/libgimpbase/gimpenv.c
+++ b/libgimpbase/gimpenv.c
@@ -151,16 +151,50 @@ gimp_env_init (gboolean plug_in)
const gchar *
gimp_directory (void)
{
- static gchar *gimp_dir = NULL;
+ static gchar *gimp_dir = NULL;
+ static gchar *last_env_gimp_dir = NULL;
const gchar *env_gimp_dir;
const gchar *home_dir;
+ env_gimp_dir = g_getenv ("GIMP2_DIRECTORY");
+
if (gimp_dir)
- return gimp_dir;
+ {
+ gboolean gimp2_directory_changed = FALSE;
- env_gimp_dir = g_getenv ("GIMP2_DIRECTORY");
- home_dir = g_get_home_dir ();
+ /* We have constructed the gimp_dir already. We can return
+ * gimp_dir unless some parameter gimp_dir depends on has
+ * changed. For now we just check for changes to GIMP2_DIRECTORY
+ */
+ gimp2_directory_changed =
+ (env_gimp_dir == NULL &&
+ last_env_gimp_dir != NULL) ||
+ (env_gimp_dir != NULL &&
+ last_env_gimp_dir == NULL) ||
+ (env_gimp_dir != NULL &&
+ last_env_gimp_dir != NULL &&
+ strcmp (env_gimp_dir, last_env_gimp_dir) != 0);
+
+ if (! gimp2_directory_changed)
+ {
+ return gimp_dir;
+ }
+ else
+ {
+ /* Free the old gimp_dir and go on to update it */
+ g_free (gimp_dir);
+ gimp_dir = NULL;
+ }
+ }
+
+ /* Remember the GIMP2_DIRECTORY to next invocation so we can check
+ * if it changes
+ */
+ g_free (last_env_gimp_dir);
+ last_env_gimp_dir = g_strdup (env_gimp_dir);
+
+ home_dir = g_get_home_dir ();
if (env_gimp_dir)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]