Commit fc28caa7 authored by William Jon McCann's avatar William Jon McCann

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
parent 226de653
......@@ -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
......
......@@ -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
......
......@@ -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();
......
......@@ -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)
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment