summaryrefslogtreecommitdiff
path: root/gio/gsettingsbackend.c
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2011-06-21 18:21:27 -0400
committerDan Winship <danw@gnome.org>2011-10-04 13:20:34 -0400
commit1481b7bca3c24149a2970758bc8762e1318f361e (patch)
treef2c9a026703eb65ea4ec724a385d4bff483a4f20 /gio/gsettingsbackend.c
parent38d21f6d8a761cf211c0e0ca21c394b4824d13f2 (diff)
Add _g_io_module_get_default(), use to simplify other *_get_default()s
Add _g_io_module_get_default(), which implements the figure-out-the-best-available-module-that-is-actually-usable logic, and use that to simplify g_proxy_resolver_get_default(), g_settings_backend_get_default(), g_tls_backend_get_default(), and g_vfs_get_default(). https://bugzilla.gnome.org/show_bug.cgi?id=620932
Diffstat (limited to 'gio/gsettingsbackend.c')
-rw-r--r--gio/gsettingsbackend.c63
1 files changed, 21 insertions, 42 deletions
diff --git a/gio/gsettingsbackend.c b/gio/gsettingsbackend.c
index f824b93e6..a1702412d 100644
--- a/gio/gsettingsbackend.c
+++ b/gio/gsettingsbackend.c
@@ -935,6 +935,22 @@ g_settings_backend_create_tree (void)
g_free, g_settings_backend_variant_unref0);
}
+static gboolean
+g_settings_backend_verify (gpointer impl)
+{
+ GSettingsBackend *backend = impl;
+
+ if (strcmp (G_OBJECT_TYPE_NAME (backend), "GMemorySettingsBackend") == 0 &&
+ g_strcmp0 (g_getenv ("GSETTINGS_BACKEND"), "memory") != 0)
+ {
+ g_message ("Using the 'memory' GSettings backend. Your settings "
+ "will not be saved or shared with other applications.");
+ }
+
+ g_settings_has_backend = TRUE;
+ return TRUE;
+}
+
/**
* g_settings_backend_get_default:
* @returns: (transfer full): the default #GSettingsBackend
@@ -950,49 +966,12 @@ g_settings_backend_create_tree (void)
GSettingsBackend *
g_settings_backend_get_default (void)
{
- static gsize backend;
-
- if (g_once_init_enter (&backend))
- {
- GSettingsBackend *instance;
- GIOExtensionPoint *point;
- GIOExtension *extension;
- GType extension_type;
- GList *extensions;
- const gchar *env;
-
- _g_io_modules_ensure_loaded ();
-
- point = g_io_extension_point_lookup (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME);
- extension = NULL;
-
- if ((env = getenv ("GSETTINGS_BACKEND")))
- {
- extension = g_io_extension_point_get_extension_by_name (point, env);
-
- if (extension == NULL)
- g_warning ("Can't find GSettings backend '%s' given in "
- "GSETTINGS_BACKEND environment variable", env);
- }
-
- if (extension == NULL)
- {
- extensions = g_io_extension_point_get_extensions (point);
- extension = extensions->data;
-
- if (strcmp (g_io_extension_get_name (extension), "memory") == 0)
- g_message ("Using the 'memory' GSettings backend. Your settings "
- "will not be saved or shared with other applications.");
- }
-
- extension_type = g_io_extension_get_type (extension);
- instance = g_object_new (extension_type, NULL);
- g_settings_has_backend = TRUE;
-
- g_once_init_leave (&backend, (gsize) instance);
- }
+ GSettingsBackend *backend;
- return g_object_ref ((void *) backend);
+ backend = _g_io_module_get_default (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME,
+ "GSETTINGS_BACKEND",
+ g_settings_backend_verify);
+ return g_object_ref (backend);
}
/*< private >