mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-11 00:13:13 +02:00
Bug 621266 - GSettings "context" clarification
Remove the concept of "context" in favour of dealing with GSettingsBackend directly.
This commit is contained in:
parent
b3cc28bc34
commit
6c3ae976e6
@ -1420,12 +1420,7 @@ g_file_descriptor_based_get_fd
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if IN_HEADER(__G_SETTINGS_BACKEND_H__)
|
#if IN_HEADER(__G_SETTINGS_BACKEND_H__)
|
||||||
#if IN_FILE(__G_KEYFILE_SETTINGS_BACKEND_C__)
|
|
||||||
g_settings_backend_setup_keyfile
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if IN_FILE(__G_SETTINGS_BACKEND_C__)
|
#if IN_FILE(__G_SETTINGS_BACKEND_C__)
|
||||||
g_settings_backend_setup
|
|
||||||
g_settings_backend_get_type
|
g_settings_backend_get_type
|
||||||
g_settings_backend_changed
|
g_settings_backend_changed
|
||||||
g_settings_backend_flatten_tree
|
g_settings_backend_flatten_tree
|
||||||
@ -1451,8 +1446,8 @@ g_settings_get_type
|
|||||||
g_settings_get_value
|
g_settings_get_value
|
||||||
g_settings_is_writable
|
g_settings_is_writable
|
||||||
g_settings_new
|
g_settings_new
|
||||||
g_settings_new_with_context
|
g_settings_new_with_backend
|
||||||
g_settings_new_with_context_and_path
|
g_settings_new_with_backend_and_path
|
||||||
g_settings_new_with_path
|
g_settings_new_with_path
|
||||||
g_settings_revert
|
g_settings_revert
|
||||||
g_settings_set
|
g_settings_set
|
||||||
|
@ -515,7 +515,7 @@ g_keyfile_settings_backend_class_init (GKeyfileSettingsBackendClass *class)
|
|||||||
g_type_class_add_private (class, sizeof (GKeyfileSettingsBackendPrivate));
|
g_type_class_add_private (class, sizeof (GKeyfileSettingsBackendPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
static GKeyfileSettingsBackend *
|
GSettingsBackend *
|
||||||
g_keyfile_settings_backend_new (const gchar *filename)
|
g_keyfile_settings_backend_new (const gchar *filename)
|
||||||
{
|
{
|
||||||
GKeyfileSettingsBackend *kf_backend;
|
GKeyfileSettingsBackend *kf_backend;
|
||||||
@ -536,42 +536,7 @@ g_keyfile_settings_backend_new (const gchar *filename)
|
|||||||
|
|
||||||
g_keyfile_settings_backend_keyfile_reload (kf_backend);
|
g_keyfile_settings_backend_keyfile_reload (kf_backend);
|
||||||
|
|
||||||
return kf_backend;
|
return G_SETTINGS_BACKEND (kf_backend);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* g_settings_backend_setup_keyfile:
|
|
||||||
* @context: a context string (not %NULL or "")
|
|
||||||
* @filename: a filename
|
|
||||||
*
|
|
||||||
* Sets up a keyfile for use with #GSettings.
|
|
||||||
*
|
|
||||||
* If you create a #GSettings with its context property set to @context
|
|
||||||
* then the settings will be stored in the keyfile at @filename. See
|
|
||||||
* g_settings_new_with_context().
|
|
||||||
*
|
|
||||||
* The keyfile must be setup before any settings objects are created
|
|
||||||
* for the named context.
|
|
||||||
*
|
|
||||||
* It is not possible to specify a keyfile for the default context.
|
|
||||||
*
|
|
||||||
* If the path leading up to @filename does not exist, it will be
|
|
||||||
* recursively created with user-only permissions. If the keyfile is
|
|
||||||
* not writable, any #GSettings objects created using @context will
|
|
||||||
* return %FALSE for any calls to g_settings_is_writable() and any
|
|
||||||
* attempts to write will fail.
|
|
||||||
*
|
|
||||||
* Since: 2.26
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
g_settings_backend_setup_keyfile (const gchar *context,
|
|
||||||
const gchar *filename)
|
|
||||||
{
|
|
||||||
GKeyfileSettingsBackend *kf_backend;
|
|
||||||
|
|
||||||
kf_backend = g_keyfile_settings_backend_new (filename);
|
|
||||||
g_settings_backend_setup (context, G_SETTINGS_BACKEND (kf_backend));
|
|
||||||
g_object_unref (kf_backend);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define __G_KEYFILE_SETTINGS_BACKEND_C__
|
#define __G_KEYFILE_SETTINGS_BACKEND_C__
|
||||||
|
@ -236,7 +236,6 @@ struct _GSettingsPrivate
|
|||||||
GSettingsBackend *backend;
|
GSettingsBackend *backend;
|
||||||
GSettingsSchema *schema;
|
GSettingsSchema *schema;
|
||||||
gchar *schema_name;
|
gchar *schema_name;
|
||||||
gchar *context;
|
|
||||||
gchar *path;
|
gchar *path;
|
||||||
|
|
||||||
GDelayedSettingsBackend *delayed;
|
GDelayedSettingsBackend *delayed;
|
||||||
@ -245,9 +244,8 @@ struct _GSettingsPrivate
|
|||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_BACKEND,
|
|
||||||
PROP_SCHEMA,
|
PROP_SCHEMA,
|
||||||
PROP_CONTEXT,
|
PROP_BACKEND,
|
||||||
PROP_PATH,
|
PROP_PATH,
|
||||||
PROP_HAS_UNAPPLIED,
|
PROP_HAS_UNAPPLIED,
|
||||||
};
|
};
|
||||||
@ -446,8 +444,8 @@ g_settings_set_property (GObject *object,
|
|||||||
settings->priv->path = g_value_dup_string (value);
|
settings->priv->path = g_value_dup_string (value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_CONTEXT:
|
case PROP_BACKEND:
|
||||||
settings->priv->context = g_value_dup_string (value);
|
settings->priv->backend = g_value_dup_object (value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -501,7 +499,9 @@ g_settings_constructed (GObject *object)
|
|||||||
settings->priv->path = g_strdup (schema_path);
|
settings->priv->path = g_strdup (schema_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
settings->priv->backend = g_settings_backend_get_with_context (settings->priv->context);
|
if (settings->priv->backend == NULL)
|
||||||
|
settings->priv->backend = g_settings_backend_get_default ();
|
||||||
|
|
||||||
g_settings_backend_watch (settings->priv->backend, G_OBJECT (settings),
|
g_settings_backend_watch (settings->priv->backend, G_OBJECT (settings),
|
||||||
settings->priv->main_context,
|
settings->priv->main_context,
|
||||||
settings_backend_changed,
|
settings_backend_changed,
|
||||||
@ -524,7 +524,6 @@ g_settings_finalize (GObject *object)
|
|||||||
g_object_unref (settings->priv->backend);
|
g_object_unref (settings->priv->backend);
|
||||||
g_object_unref (settings->priv->schema);
|
g_object_unref (settings->priv->schema);
|
||||||
g_free (settings->priv->schema_name);
|
g_free (settings->priv->schema_name);
|
||||||
g_free (settings->priv->context);
|
|
||||||
g_free (settings->priv->path);
|
g_free (settings->priv->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,11 +667,11 @@ g_settings_class_init (GSettingsClass *class)
|
|||||||
*
|
*
|
||||||
* The name of the context that the settings are stored in.
|
* The name of the context that the settings are stored in.
|
||||||
*/
|
*/
|
||||||
g_object_class_install_property (object_class, PROP_CONTEXT,
|
g_object_class_install_property (object_class, PROP_BACKEND,
|
||||||
g_param_spec_string ("context",
|
g_param_spec_object ("backend",
|
||||||
P_("Context name"),
|
P_("GSettingsBackend"),
|
||||||
P_("The name of the context for this settings object"),
|
P_("The GSettingsBackend for this settings object"),
|
||||||
"", G_PARAM_CONSTRUCT_ONLY |
|
G_TYPE_SETTINGS_BACKEND, G_PARAM_CONSTRUCT_ONLY |
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -773,66 +772,63 @@ g_settings_new_with_path (const gchar *schema,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_settings_new_with_context:
|
* g_settings_new_with_backend:
|
||||||
* @schema: the name of the schema
|
* @schema: the name of the schema
|
||||||
* @context: the context to use
|
* @backend: the #GSettingsBackend to use
|
||||||
* @returns: a new #GSettings object
|
* @returns: a new #GSettings object
|
||||||
*
|
*
|
||||||
* Creates a new #GSettings object with a given schema and context.
|
* Creates a new #GSettings object with a given schema and backend.
|
||||||
*
|
*
|
||||||
* Creating settings objects with a context allow accessing settings
|
* Creating settings objects with an different backend allows accessing settings
|
||||||
* from a database other than the usual one. For example, it may make
|
* from a database other than the usual one. For example, it may make
|
||||||
* sense to specify "defaults" in order to get a settings object that
|
* sense to pass a backend corresponding to teh "defaults" settings database on
|
||||||
* modifies the system default settings instead of the settings for this
|
* the system to get a settings object that modifies the system default
|
||||||
* user.
|
* settings instead of the settings for this user.
|
||||||
*
|
|
||||||
* It is a programmer error to call this function for an unsupported
|
|
||||||
* context. Use g_settings_supports_context() to determine if a context
|
|
||||||
* is supported if you are unsure.
|
|
||||||
*
|
*
|
||||||
* Since: 2.26
|
* Since: 2.26
|
||||||
*/
|
*/
|
||||||
GSettings *
|
GSettings *
|
||||||
g_settings_new_with_context (const gchar *schema,
|
g_settings_new_with_backend (const gchar *schema,
|
||||||
const gchar *context)
|
GSettingsBackend *backend)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (schema != NULL, NULL);
|
g_return_val_if_fail (schema != NULL, NULL);
|
||||||
g_return_val_if_fail (context != NULL, NULL);
|
g_return_val_if_fail (G_IS_SETTINGS_BACKEND (backend), NULL);
|
||||||
|
|
||||||
return g_object_new (G_TYPE_SETTINGS,
|
return g_object_new (G_TYPE_SETTINGS,
|
||||||
"schema", schema,
|
"schema", schema,
|
||||||
"context", context,
|
"backend", backend,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_settings_new_with_context_and_path:
|
* g_settings_new_with_backend_and_path:
|
||||||
* @schema: the name of the schema
|
* @schema: the name of the schema
|
||||||
|
* @backend: the #GSettingsBackend to use
|
||||||
* @path: the path to use
|
* @path: the path to use
|
||||||
* @returns: a new #GSettings object
|
* @returns: a new #GSettings object
|
||||||
*
|
*
|
||||||
* Creates a new #GSettings object with a given schema, context and
|
* Creates a new #GSettings object with a given schema, backend and
|
||||||
* path.
|
* path.
|
||||||
*
|
*
|
||||||
* This is a mix of g_settings_new_with_context() and
|
* This is a mix of g_settings_new_with_backend() and
|
||||||
* g_settings_new_with_path().
|
* g_settings_new_with_path().
|
||||||
*
|
*
|
||||||
* Since: 2.26
|
* Since: 2.26
|
||||||
*/
|
*/
|
||||||
GSettings *
|
GSettings *
|
||||||
g_settings_new_with_context_and_path (const gchar *schema,
|
g_settings_new_with_backend_and_path (const gchar *schema,
|
||||||
const gchar *context,
|
GSettingsBackend *backend,
|
||||||
const gchar *path)
|
const gchar *path)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (schema != NULL, NULL);
|
g_return_val_if_fail (schema != NULL, NULL);
|
||||||
g_return_val_if_fail (context != NULL, NULL);
|
g_return_val_if_fail (G_IS_SETTINGS_BACKEND (backend), NULL);
|
||||||
g_return_val_if_fail (path != NULL, NULL);
|
g_return_val_if_fail (path != NULL, NULL);
|
||||||
|
|
||||||
return g_object_new (G_TYPE_SETTINGS,
|
return g_object_new (G_TYPE_SETTINGS,
|
||||||
"schema", schema,
|
"schema", schema,
|
||||||
"context", context,
|
"backend", backend,
|
||||||
"path", path,
|
"path", path,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Internal read/write utilities, enum conversion, validation {{{1 */
|
/* Internal read/write utilities, enum conversion, validation {{{1 */
|
||||||
@ -1784,15 +1780,9 @@ g_settings_get_has_unapplied (GSettings *settings)
|
|||||||
* time the call is done).
|
* time the call is done).
|
||||||
**/
|
**/
|
||||||
void
|
void
|
||||||
g_settings_sync (const gchar *context)
|
g_settings_sync (void)
|
||||||
{
|
{
|
||||||
GSettingsBackend *backend;
|
g_settings_backend_sync_default ();
|
||||||
|
|
||||||
if (context == NULL)
|
|
||||||
context = "";
|
|
||||||
|
|
||||||
backend = g_settings_backend_get_with_context (context);
|
|
||||||
g_settings_backend_sync (backend);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,11 +73,10 @@ GType g_settings_get_type (void);
|
|||||||
GSettings * g_settings_new (const gchar *schema);
|
GSettings * g_settings_new (const gchar *schema);
|
||||||
GSettings * g_settings_new_with_path (const gchar *schema,
|
GSettings * g_settings_new_with_path (const gchar *schema,
|
||||||
const gchar *path);
|
const gchar *path);
|
||||||
gboolean g_settings_supports_context (const gchar *context);
|
GSettings * g_settings_new_with_backend (const gchar *schema,
|
||||||
GSettings * g_settings_new_with_context (const gchar *schema,
|
GSettingsBackend *backend);
|
||||||
const gchar *context);
|
GSettings * g_settings_new_with_backend_and_path (const gchar *schema,
|
||||||
GSettings * g_settings_new_with_context_and_path (const gchar *schema,
|
GSettingsBackend *backend,
|
||||||
const gchar *context,
|
|
||||||
const gchar *path);
|
const gchar *path);
|
||||||
|
|
||||||
gboolean g_settings_set_value (GSettings *settings,
|
gboolean g_settings_set_value (GSettings *settings,
|
||||||
@ -135,7 +134,7 @@ void g_settings_delay (GSettin
|
|||||||
void g_settings_apply (GSettings *settings);
|
void g_settings_apply (GSettings *settings);
|
||||||
void g_settings_revert (GSettings *settings);
|
void g_settings_revert (GSettings *settings);
|
||||||
gboolean g_settings_get_has_unapplied (GSettings *settings);
|
gboolean g_settings_get_has_unapplied (GSettings *settings);
|
||||||
void g_settings_sync (const gchar *context);
|
void g_settings_sync ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GSettingsBindSetMapping:
|
* GSettingsBindSetMapping:
|
||||||
|
@ -1038,136 +1038,61 @@ g_settings_backend_create_tree (void)
|
|||||||
g_free, (GDestroyNotify) g_variant_unref);
|
g_free, (GDestroyNotify) g_variant_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gpointer
|
|
||||||
get_default_backend (const gchar *context)
|
|
||||||
{
|
|
||||||
GIOExtension *extension = NULL;
|
|
||||||
GIOExtensionPoint *point;
|
|
||||||
GList *extensions;
|
|
||||||
const gchar *env;
|
|
||||||
GType type;
|
|
||||||
|
|
||||||
_g_io_modules_ensure_loaded ();
|
|
||||||
|
|
||||||
point = g_io_extension_point_lookup (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (extensions == NULL)
|
|
||||||
g_error ("No GSettingsBackend implementations exist.");
|
|
||||||
|
|
||||||
extension = extensions->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context[0] != '\0') /* (context != "") */
|
|
||||||
{
|
|
||||||
GSettingsBackendClass *backend_class;
|
|
||||||
GTypeClass *class;
|
|
||||||
|
|
||||||
class = g_io_extension_ref_class (extension);
|
|
||||||
backend_class = G_SETTINGS_BACKEND_CLASS (class);
|
|
||||||
|
|
||||||
if (backend_class->supports_context == NULL ||
|
|
||||||
!backend_class->supports_context (context))
|
|
||||||
{
|
|
||||||
g_type_class_unref (class);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_type_class_unref (class);
|
|
||||||
}
|
|
||||||
|
|
||||||
type = g_io_extension_get_type (extension);
|
|
||||||
|
|
||||||
return g_object_new (type, "context", context, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static GHashTable *g_settings_backends;
|
|
||||||
|
|
||||||
/*< private >
|
/*< private >
|
||||||
* g_settings_backend_get_with_context:
|
* g_settings_backend_get_default:
|
||||||
* @context: a context that might be used by the backend to determine
|
|
||||||
* which storage to use, or %NULL to use the default storage
|
|
||||||
* @returns: the default #GSettingsBackend
|
* @returns: the default #GSettingsBackend
|
||||||
*
|
*
|
||||||
* Returns the default #GSettingsBackend. It is possible to override
|
* Returns the default #GSettingsBackend. It is possible to override
|
||||||
* the default by setting the <envar>GSETTINGS_BACKEND</envar>
|
* the default by setting the <envar>GSETTINGS_BACKEND</envar>
|
||||||
* environment variable to the name of a settings backend.
|
* environment variable to the name of a settings backend.
|
||||||
*
|
*
|
||||||
* The @context parameter can be used to indicate that a different
|
* The user gets a reference to the backend.
|
||||||
* than the default storage is desired. E.g. the DConf backend lets
|
|
||||||
* you use "user", "system", "defaults" and "login" as contexts.
|
|
||||||
*
|
|
||||||
* If @context is not supported by the implementation, this function
|
|
||||||
* returns an instance of the #GSettingsMemoryBackend.
|
|
||||||
* See g_settings_backend_supports_context(),
|
|
||||||
*
|
|
||||||
* The user does not own the return value and it must not be freed.
|
|
||||||
*/
|
*/
|
||||||
GSettingsBackend *
|
GSettingsBackend *
|
||||||
g_settings_backend_get_with_context (const gchar *context)
|
g_settings_backend_get_default (void)
|
||||||
{
|
{
|
||||||
GSettingsBackend *backend;
|
static gsize backend;
|
||||||
|
|
||||||
g_return_val_if_fail (context != NULL, NULL);
|
if (g_once_init_enter (&backend))
|
||||||
|
|
||||||
_g_io_modules_ensure_extension_points_registered ();
|
|
||||||
|
|
||||||
if (g_settings_backends == NULL)
|
|
||||||
g_settings_backends = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
|
|
||||||
backend = g_hash_table_lookup (g_settings_backends, context);
|
|
||||||
|
|
||||||
if (!backend)
|
|
||||||
{
|
{
|
||||||
backend = get_default_backend (context);
|
GSettingsBackend *instance;
|
||||||
|
GIOExtensionPoint *point;
|
||||||
|
GIOExtension *extension;
|
||||||
|
GType extension_type;
|
||||||
|
GList *extensions;
|
||||||
|
const gchar *env;
|
||||||
|
|
||||||
if (!backend)
|
_g_io_modules_ensure_loaded ();
|
||||||
backend = g_null_settings_backend_new ();
|
|
||||||
|
|
||||||
g_hash_table_insert (g_settings_backends, g_strdup (context), backend);
|
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);
|
||||||
|
|
||||||
|
if (extensions == NULL)
|
||||||
|
g_error ("No GSettingsBackend implementations exist.");
|
||||||
|
|
||||||
|
extension = extensions->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
extension_type = g_io_extension_get_type (extension);
|
||||||
|
instance = g_object_new (extension_type, NULL);
|
||||||
|
|
||||||
|
g_once_init_leave (&backend, (gsize) instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_object_ref (backend);
|
return g_object_ref ((void *) backend);
|
||||||
}
|
|
||||||
|
|
||||||
/*< private >
|
|
||||||
* g_settings_backend_supports_context:
|
|
||||||
* @context: a context string that might be passed to
|
|
||||||
* g_settings_backend_new_with_context()
|
|
||||||
* @returns: #TRUE if @context is supported
|
|
||||||
*
|
|
||||||
* Determines if the given context is supported by the default
|
|
||||||
* GSettingsBackend implementation.
|
|
||||||
*/
|
|
||||||
gboolean
|
|
||||||
g_settings_backend_supports_context (const gchar *context)
|
|
||||||
{
|
|
||||||
GSettingsBackend *backend;
|
|
||||||
|
|
||||||
g_return_val_if_fail (context != NULL, FALSE);
|
|
||||||
|
|
||||||
backend = get_default_backend (context);
|
|
||||||
|
|
||||||
if (backend)
|
|
||||||
{
|
|
||||||
g_object_unref (backend);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*< private >
|
/*< private >
|
||||||
@ -1194,54 +1119,19 @@ g_settings_backend_get_permission (GSettingsBackend *backend,
|
|||||||
return g_simple_permission_new (TRUE);
|
return g_simple_permission_new (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* g_settings_backend_setup:
|
|
||||||
* @context: a context string (not %NULL or "")
|
|
||||||
* @backend: a #GSettingsBackend
|
|
||||||
*
|
|
||||||
* Sets up @backend for use with #GSettings.
|
|
||||||
*
|
|
||||||
* If you create a #GSettings with its context property set to @context
|
|
||||||
* then it will use the backend given to this function. See
|
|
||||||
* g_settings_new_with_context().
|
|
||||||
*
|
|
||||||
* The backend must be set up before any settings objects are created
|
|
||||||
* for the named context.
|
|
||||||
*
|
|
||||||
* It is not possible to specify a backend for the default context.
|
|
||||||
*
|
|
||||||
* This function takes a reference on @backend and never releases it.
|
|
||||||
*
|
|
||||||
* Since: 2.26
|
|
||||||
**/
|
|
||||||
void
|
|
||||||
g_settings_backend_setup (const gchar *context,
|
|
||||||
GSettingsBackend *backend)
|
|
||||||
{
|
|
||||||
g_return_if_fail (context[0] != '\0');
|
|
||||||
g_return_if_fail (G_IS_SETTINGS_BACKEND (backend));
|
|
||||||
|
|
||||||
if (g_settings_backends == NULL)
|
|
||||||
g_settings_backends = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
|
|
||||||
if (g_hash_table_lookup (g_settings_backends, context))
|
|
||||||
g_error ("A GSettingsBackend already exists for context '%s'", context);
|
|
||||||
|
|
||||||
g_hash_table_insert (g_settings_backends,
|
|
||||||
g_strdup (context),
|
|
||||||
g_object_ref (backend));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*< private >
|
/*< private >
|
||||||
* g_settings_backend_sync:
|
* g_settings_backend_sync_default:
|
||||||
* @backend: a #GSettingsBackend
|
|
||||||
*
|
*
|
||||||
* Syncs the backend.
|
* Syncs the default backend.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
g_settings_backend_sync (GSettingsBackend *backend)
|
g_settings_backend_sync_default (void)
|
||||||
{
|
{
|
||||||
GSettingsBackendClass *class = G_SETTINGS_BACKEND_GET_CLASS (backend);
|
GSettingsBackendClass *class;
|
||||||
|
GSettingsBackend *backend;
|
||||||
|
|
||||||
|
backend = g_settings_backend_get_default ();
|
||||||
|
class = G_SETTINGS_BACKEND_GET_CLASS (backend);
|
||||||
|
|
||||||
if (class->sync)
|
if (class->sync)
|
||||||
class->sync (backend);
|
class->sync (backend);
|
||||||
|
@ -111,36 +111,33 @@ struct _GSettingsBackend
|
|||||||
GSettingsBackendPrivate *priv;
|
GSettingsBackendPrivate *priv;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType g_settings_backend_get_type (void);
|
GType g_settings_backend_get_type (void);
|
||||||
|
|
||||||
void g_settings_backend_setup (const gchar *context,
|
void g_settings_backend_changed (GSettingsBackend *backend,
|
||||||
GSettingsBackend *backend);
|
|
||||||
void g_settings_backend_setup_keyfile (const gchar *context,
|
|
||||||
const gchar *filename);
|
|
||||||
|
|
||||||
void g_settings_backend_changed (GSettingsBackend *backend,
|
|
||||||
const gchar *key,
|
const gchar *key,
|
||||||
gpointer origin_tag);
|
gpointer origin_tag);
|
||||||
void g_settings_backend_path_changed (GSettingsBackend *backend,
|
void g_settings_backend_path_changed (GSettingsBackend *backend,
|
||||||
const gchar *path,
|
const gchar *path,
|
||||||
gpointer origin_tag);
|
gpointer origin_tag);
|
||||||
void g_settings_backend_flatten_tree (GTree *tree,
|
void g_settings_backend_flatten_tree (GTree *tree,
|
||||||
gchar **path,
|
gchar **path,
|
||||||
const gchar ***keys,
|
const gchar ***keys,
|
||||||
GVariant ***values);
|
GVariant ***values);
|
||||||
void g_settings_backend_keys_changed (GSettingsBackend *backend,
|
void g_settings_backend_keys_changed (GSettingsBackend *backend,
|
||||||
const gchar *path,
|
const gchar *path,
|
||||||
gchar const * const *items,
|
gchar const * const *items,
|
||||||
gpointer origin_tag);
|
gpointer origin_tag);
|
||||||
|
|
||||||
void g_settings_backend_path_writable_changed(GSettingsBackend *backend,
|
void g_settings_backend_path_writable_changed (GSettingsBackend *backend,
|
||||||
const gchar *path);
|
const gchar *path);
|
||||||
void g_settings_backend_writable_changed (GSettingsBackend *backend,
|
void g_settings_backend_writable_changed (GSettingsBackend *backend,
|
||||||
const gchar *key);
|
const gchar *key);
|
||||||
void g_settings_backend_changed_tree (GSettingsBackend *backend,
|
void g_settings_backend_changed_tree (GSettingsBackend *backend,
|
||||||
GTree *tree,
|
GTree *tree,
|
||||||
gpointer origin_tag);
|
gpointer origin_tag);
|
||||||
|
|
||||||
|
GSettingsBackend * g_keyfile_settings_backend_new (const gchar *filename);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __G_SETTINGS_BACKEND_H__ */
|
#endif /* __G_SETTINGS_BACKEND_H__ */
|
||||||
|
@ -60,50 +60,48 @@ void g_settings_backend_unwatch (GSettin
|
|||||||
GObject *target);
|
GObject *target);
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
gboolean g_settings_backend_supports_context (const gchar *context);
|
GTree * g_settings_backend_create_tree (void);
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
GSettingsBackend * g_settings_backend_get_with_context (const gchar *context);
|
GVariant * g_settings_backend_read (GSettingsBackend *backend,
|
||||||
G_GNUC_INTERNAL
|
|
||||||
GTree * g_settings_backend_create_tree (void);
|
|
||||||
G_GNUC_INTERNAL
|
|
||||||
GVariant * g_settings_backend_read (GSettingsBackend *backend,
|
|
||||||
const gchar *key,
|
const gchar *key,
|
||||||
const GVariantType *expected_type,
|
const GVariantType *expected_type,
|
||||||
gboolean default_value);
|
gboolean default_value);
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
gboolean g_settings_backend_write (GSettingsBackend *backend,
|
gboolean g_settings_backend_write (GSettingsBackend *backend,
|
||||||
const gchar *key,
|
const gchar *key,
|
||||||
GVariant *value,
|
GVariant *value,
|
||||||
gpointer origin_tag);
|
gpointer origin_tag);
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
gboolean g_settings_backend_write_keys (GSettingsBackend *backend,
|
gboolean g_settings_backend_write_keys (GSettingsBackend *backend,
|
||||||
GTree *tree,
|
GTree *tree,
|
||||||
gpointer origin_tag);
|
gpointer origin_tag);
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
void g_settings_backend_reset (GSettingsBackend *backend,
|
void g_settings_backend_reset (GSettingsBackend *backend,
|
||||||
const gchar *key,
|
const gchar *key,
|
||||||
gpointer origin_tag);
|
gpointer origin_tag);
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
void g_settings_backend_reset_path (GSettingsBackend *backend,
|
void g_settings_backend_reset_path (GSettingsBackend *backend,
|
||||||
const gchar *path,
|
const gchar *path,
|
||||||
gpointer origin_tag);
|
gpointer origin_tag);
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
gboolean g_settings_backend_get_writable (GSettingsBackend *backend,
|
gboolean g_settings_backend_get_writable (GSettingsBackend *backend,
|
||||||
const char *key);
|
const char *key);
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
void g_settings_backend_unsubscribe (GSettingsBackend *backend,
|
void g_settings_backend_unsubscribe (GSettingsBackend *backend,
|
||||||
const char *name);
|
const char *name);
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
void g_settings_backend_subscribe (GSettingsBackend *backend,
|
void g_settings_backend_subscribe (GSettingsBackend *backend,
|
||||||
const char *name);
|
const char *name);
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
GPermission * g_settings_backend_get_permission (GSettingsBackend *backend,
|
GPermission * g_settings_backend_get_permission (GSettingsBackend *backend,
|
||||||
const gchar *path);
|
const gchar *path);
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
GMainContext * g_settings_backend_get_active_context (void);
|
GMainContext * g_settings_backend_get_active_context (void);
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
void g_settings_backend_sync (GSettingsBackend *backend);
|
GSettingsBackend * g_settings_backend_get_default (void);
|
||||||
|
G_GNUC_INTERNAL
|
||||||
|
void g_settings_backend_sync_default (void);
|
||||||
|
|
||||||
#endif /* __G_SETTINGS_BACKEND_INTERNAL_H__ */
|
#endif /* __G_SETTINGS_BACKEND_INTERNAL_H__ */
|
||||||
|
@ -344,9 +344,10 @@ else
|
|||||||
glib_compile_schemas=$(top_builddir)/gio/glib-compile-schemas
|
glib_compile_schemas=$(top_builddir)/gio/glib-compile-schemas
|
||||||
endif
|
endif
|
||||||
|
|
||||||
DISTCLEANFILES = \
|
DISTCLEANFILES = \
|
||||||
applications/mimeinfo.cache \
|
applications/mimeinfo.cache \
|
||||||
de/LC_MESSAGES/test.mo \
|
org.gtk.test.enums.xml \
|
||||||
test.mo \
|
de/LC_MESSAGES/test.mo \
|
||||||
gsettings.store \
|
test.mo \
|
||||||
|
gsettings.store \
|
||||||
gschemas.compiled
|
gschemas.compiled
|
||||||
|
@ -1120,15 +1120,16 @@ test_no_write_binding (void)
|
|||||||
static void
|
static void
|
||||||
test_keyfile (void)
|
test_keyfile (void)
|
||||||
{
|
{
|
||||||
|
GSettingsBackend *kf_backend;
|
||||||
GSettings *settings;
|
GSettings *settings;
|
||||||
GKeyFile *keyfile;
|
GKeyFile *keyfile;
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
g_remove ("gsettings.store");
|
g_remove ("gsettings.store");
|
||||||
|
|
||||||
g_settings_backend_setup_keyfile ("blah", "gsettings.store");
|
kf_backend = g_keyfile_settings_backend_new ("gsettings.store");
|
||||||
|
settings = g_settings_new_with_backend ("org.gtk.test", kf_backend);
|
||||||
settings = g_settings_new_with_context ("org.gtk.test", "blah");
|
g_object_unref (kf_backend);
|
||||||
|
|
||||||
g_settings_set (settings, "greeting", "s", "see if this works");
|
g_settings_set (settings, "greeting", "s", "see if this works");
|
||||||
|
|
||||||
@ -1390,7 +1391,7 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
result = g_test_run ();
|
result = g_test_run ();
|
||||||
|
|
||||||
g_settings_sync (NULL);
|
g_settings_sync ();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user