[gconf] Try to use XDG config directory for settings storage
- From: William Jon McCann <mccann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gconf] Try to use XDG config directory for settings storage
- Date: Wed, 25 Apr 2012 19:01:42 +0000 (UTC)
commit fc28caa7be8604e9a39bbe6b78fb79747860bb40
Author: William Jon McCann <jmccann redhat com>
Date: Wed Apr 25 14:10:08 2012 -0400
Try to use XDG config directory for settings storage
And fallback to the original locations if it isn't found.
https://bugzilla.gnome.org/show_bug.cgi?id=674803
doc/gconf/gconf.sgml | 6 ++++--
gconf/default.path.in | 9 ++++++---
gconf/gconf-internals.c | 40 ++++++++++++++++++++++++++++++++++++++++
gconf/gconf.path | 2 +-
gconf/gconfd.c | 10 +++-------
5 files changed, 54 insertions(+), 13 deletions(-)
---
diff --git a/doc/gconf/gconf.sgml b/doc/gconf/gconf.sgml
index 4ea7c87..3b3cceb 100644
--- a/doc/gconf/gconf.sgml
+++ b/doc/gconf/gconf.sgml
@@ -289,8 +289,10 @@
The source configuration file can contain "include" statements and
some magic variables; you can use this to include a .gconf.path file
from the user's home directory. Variables are placed in
- <symbol>$()</symbol>. Two variables are built-in to GConf:
+ <symbol>$()</symbol>. Four variables are built-in to GConf:
<symbol>$(HOME)</symbol> is the user's home directory, and
+ <symbol>$(USERCONFIGDIR)</symbol> is the user's configuration directory, and
+ <symbol>$(DEFAULTUSERSOURCE)</symbol> is the default user source location, and
<symbol>$(USER)</symbol> is the username. You can also access any
environment variable by prepending <symbol>ENV_</symbol> to the
variable name. For example, <symbol>$(ENV_FOO)</symbol> will be
@@ -304,7 +306,7 @@
<programlisting>
# GConf configuration path file with an include statement
xml:readonly:/etc/gconf.xml.mandatory
- include "$(HOME)/.gconf.path"
+ include "$(USERCONFIGDIR)/gconf.path"
xml:readonly:/etc/gconf.xml.defaults
# imaginary, no LDAP backend exists right now
ldap::/foo/bar/whatever/ldap/address
diff --git a/gconf/default.path.in b/gconf/default.path.in
index f03b4aa..b6487ce 100644
--- a/gconf/default.path.in
+++ b/gconf/default.path.in
@@ -14,11 +14,14 @@ xml:readonly:@sysgconfdir@/gconf.xml.mandatory
include @sysgconfdir@/2/local-mandatory.path
# Now see where users want us to look - basically the user can stick arbitrary
-# sources in a ~/.gconf.path file and they're inserted here
+# sources in a ~/.config/gconf.path file and they're inserted here
+include "$(USERCONFIGDIR)/gconf/path"
+# Legacy file location
include "$(HOME)/.gconf.path"
-# Give users a default storage location, ~/.gconf
-xml:readwrite:$(HOME)/.gconf
+# Give users a default storage location,
+# $(USERCONFIGDIR)/gconf (or $(HOME)/.gconf when it exists, for backward compatibility)
+xml:readwrite:$(DEFAULTUSERSOURCE)
# Location for system-wide settings that are set by the defaults mechanism
xml:readonly:@sysgconfdir@/gconf.xml.system
diff --git a/gconf/gconf-internals.c b/gconf/gconf-internals.c
index e07febd..06ef08d 100644
--- a/gconf/gconf-internals.c
+++ b/gconf/gconf-internals.c
@@ -719,6 +719,38 @@ _gconf_win32_get_home_dir (void)
#endif
+static const gchar *
+get_user_source_dir (void)
+{
+ static const gchar *user_source = NULL;
+
+ if (user_source == NULL)
+ {
+ gchar *path_new;
+ gchar *path_old;
+
+ path_new = g_build_filename (g_get_user_config_dir (), "gconf", NULL);
+#ifndef G_OS_WIN32
+ path_old = g_build_filename (g_get_home_dir (), ".gconf", NULL);
+#else
+ path_old = g_build_filename (_gconf_win32_get_home_dir (), ".gconf", NULL);
+#endif
+ if ((g_file_test (path_new, G_FILE_TEST_IS_DIR))
+ || (! g_file_test (path_old, G_FILE_TEST_IS_DIR)))
+ {
+ user_source = path_new;
+ g_free (path_old);
+ }
+ else
+ {
+ g_free (path_new);
+ user_source = path_old;
+ }
+ }
+
+ return user_source;
+}
+
static const gchar*
get_variable(const gchar* varname)
{
@@ -733,6 +765,14 @@ get_variable(const gchar* varname)
return _gconf_win32_get_home_dir ();
#endif
}
+ else if (strcmp(varname, "USERCONFIGDIR") == 0)
+ {
+ return g_get_user_config_dir();
+ }
+ else if (strcmp(varname, "DEFAULTUSERSOURCE") == 0)
+ {
+ return get_user_source_dir();
+ }
else if (strcmp(varname, "USER") == 0)
{
return g_get_user_name();
diff --git a/gconf/gconf.path b/gconf/gconf.path
index fcb859e..4e2a7cf 100644
--- a/gconf/gconf.path
+++ b/gconf/gconf.path
@@ -3,4 +3,4 @@
# bottom, and the first one to have a value for the key (or the first one
# to be writeable) is used to load/store the data.
# You can also use include statements
-xml:readwrite:$(HOME)/.gconf
+xml:readwrite:$(DEFAULTUSERSOURCE)
diff --git a/gconf/gconfd.c b/gconf/gconfd.c
index b6fb103..1ed3d08 100644
--- a/gconf/gconfd.c
+++ b/gconf/gconfd.c
@@ -397,14 +397,10 @@ gconf_server_get_default_sources(void)
if (addresses == NULL)
{
-#ifndef G_OS_WIN32
- const char *home = g_get_home_dir ();
-#else
- const char *home = _gconf_win32_get_home_dir ();
-#endif
+ const char *configdir = g_get_user_config_dir ();
- /* Try using the default address xml:readwrite:$(HOME)/.gconf */
- addresses = g_slist_append(addresses, g_strconcat("xml:readwrite:", home, "/.gconf", NULL));
+ /* Try using the default address xml:readwrite:$(USERCONFIGDIR)/gconf */
+ addresses = g_slist_append(addresses, g_strconcat("xml:readwrite:", configdir, "/gconf", NULL));
gconf_log(GCL_DEBUG, _("No configuration files found. Trying to use the default configuration source `%s'"), (char *)addresses->data);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]