summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Jon McCann <jmccann@redhat.com>2012-04-25 14:10:08 -0400
committerWilliam Jon McCann <jmccann@redhat.com>2012-04-25 14:56:50 -0400
commitfc28caa7be8604e9a39bbe6b78fb79747860bb40 (patch)
tree554c50fecb3b916f14cbda8b3529dc69dec046e4
parent226de65365e2d28e92457d54d6fbb5f4f54e94db (diff)
downloadgconf-fc28caa7be8604e9a39bbe6b78fb79747860bb40.tar.gz
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
-rw-r--r--doc/gconf/gconf.sgml6
-rw-r--r--gconf/default.path.in9
-rw-r--r--gconf/gconf-internals.c40
-rw-r--r--gconf/gconf.path2
-rw-r--r--gconf/gconfd.c10
5 files changed, 54 insertions, 13 deletions
diff --git a/doc/gconf/gconf.sgml b/doc/gconf/gconf.sgml
index 4ea7c87b..3b3ccebe 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 f03b4aa3..b6487ceb 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 e07febdd..06ef08da 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 fcb859ea..4e2a7cf5 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 b6fb103f..1ed3d083 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);
}