mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-24 03:02:10 +01:00
really disruptive breaking of stuff
This commit is contained in:
parent
171d293b6f
commit
c993002c2d
@ -18,14 +18,14 @@ enum
|
||||
{
|
||||
PROP_NONE,
|
||||
PROP_BACKEND,
|
||||
PROP_BASE_PATH,
|
||||
PROP_HAS_UNAPPLIED
|
||||
};
|
||||
|
||||
struct _GDelayedSettingsBackendPrivate {
|
||||
GSettingsBackend *backend;
|
||||
guint handler_id;
|
||||
gchar *base_path;
|
||||
guint writable_changed_handler_id;
|
||||
guint keys_changed_handler_id;
|
||||
guint changed_handler_id;
|
||||
GTree *delayed;
|
||||
};
|
||||
|
||||
@ -33,35 +33,46 @@ G_DEFINE_TYPE (GDelayedSettingsBackend,
|
||||
g_delayed_settings_backend,
|
||||
G_TYPE_SETTINGS_BACKEND)
|
||||
|
||||
static gboolean
|
||||
g_delayed_settings_backend_add_to_tree (gpointer key,
|
||||
gpointer value,
|
||||
gpointer user_data)
|
||||
static void
|
||||
g_delayed_settings_backend_write (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
GVariant *value,
|
||||
gpointer origin_tag)
|
||||
{
|
||||
gpointer *args = user_data;
|
||||
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
|
||||
gboolean was_empty;
|
||||
|
||||
g_tree_insert (args[0],
|
||||
g_strjoin (NULL, args[1], key, NULL),
|
||||
g_variant_ref (value));
|
||||
was_empty = g_tree_nnodes (delayed->priv->delayed) == 0;
|
||||
g_tree_insert (delayed->priv->delayed, g_strdup (key),
|
||||
g_variant_ref_sink (value));
|
||||
g_settings_backend_changed (backend, key, origin_tag);
|
||||
|
||||
if (was_empty)
|
||||
g_object_notify (G_OBJECT (delayed), "has-unapplied");
|
||||
}
|
||||
|
||||
static gboolean
|
||||
add_to_tree (gpointer key,
|
||||
gpointer value,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_tree_insert (user_data, g_strdup (key), g_variant_ref (value));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
g_delayed_settings_backend_write (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
GTree *tree,
|
||||
gpointer origin_tag)
|
||||
g_delayed_settings_backend_keys_write (GSettingsBackend *backend,
|
||||
GTree *tree,
|
||||
gpointer origin_tag)
|
||||
{
|
||||
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
|
||||
gconstpointer args[2] = { delayed->priv->delayed, prefix };
|
||||
gboolean was_empty;
|
||||
|
||||
was_empty = g_tree_nnodes (delayed->priv->delayed) == 0;
|
||||
|
||||
g_tree_foreach (tree, g_delayed_settings_backend_add_to_tree, args);
|
||||
g_tree_foreach (tree, add_to_tree, delayed->priv->delayed);
|
||||
|
||||
g_settings_backend_changed_tree (backend, prefix, tree, origin_tag);
|
||||
g_settings_backend_changed_tree (backend, tree, origin_tag);
|
||||
|
||||
if (was_empty)
|
||||
g_object_notify (G_OBJECT (delayed), "has-unapplied");
|
||||
@ -73,18 +84,13 @@ g_delayed_settings_backend_read (GSettingsBackend *backend,
|
||||
const GVariantType *expected_type)
|
||||
{
|
||||
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
|
||||
GVariant *result = NULL;
|
||||
gchar *path;
|
||||
GVariant *result;
|
||||
|
||||
if ((result = g_tree_lookup (delayed->priv->delayed, key)))
|
||||
return g_variant_ref (result);
|
||||
|
||||
path = g_strconcat (delayed->priv->base_path, key, NULL);
|
||||
result = g_settings_backend_read (delayed->priv->backend,
|
||||
path, expected_type);
|
||||
g_free (path);
|
||||
|
||||
return result;
|
||||
return g_settings_backend_read (delayed->priv->backend,
|
||||
key, expected_type);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -102,10 +108,8 @@ g_delayed_settings_backend_apply (GDelayedSettingsBackend *delayed)
|
||||
|
||||
tmp = delayed->priv->delayed;
|
||||
delayed->priv->delayed = g_settings_backend_create_tree ();
|
||||
|
||||
g_settings_backend_write (delayed->priv->backend,
|
||||
delayed->priv->base_path,
|
||||
tmp, delayed->priv);
|
||||
g_settings_backend_write_keys (delayed->priv->backend,
|
||||
tmp, delayed->priv);
|
||||
g_tree_unref (tmp);
|
||||
|
||||
g_object_notify (G_OBJECT (delayed), "has-unapplied");
|
||||
@ -121,8 +125,7 @@ g_delayed_settings_backend_revert (GDelayedSettingsBackend *delayed)
|
||||
|
||||
tmp = delayed->priv->delayed;
|
||||
delayed->priv->delayed = g_settings_backend_create_tree ();
|
||||
g_settings_backend_changed_tree (G_SETTINGS_BACKEND (delayed),
|
||||
"", tmp, NULL);
|
||||
g_settings_backend_changed_tree (G_SETTINGS_BACKEND (delayed), tmp, NULL);
|
||||
g_tree_destroy (tmp);
|
||||
|
||||
g_object_notify (G_OBJECT (delayed), "has-unapplied");
|
||||
@ -134,14 +137,8 @@ g_delayed_settings_backend_get_writable (GSettingsBackend *backend,
|
||||
const gchar *name)
|
||||
{
|
||||
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
|
||||
gboolean sensitive;
|
||||
gchar *path;
|
||||
|
||||
path = g_strconcat (delayed->priv->base_path, name, NULL);
|
||||
sensitive = g_settings_backend_get_writable (delayed->priv->backend, path);
|
||||
g_free (path);
|
||||
|
||||
return sensitive;
|
||||
return g_settings_backend_get_writable (delayed->priv->backend, name);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -183,61 +180,45 @@ g_delayed_settings_backend_set_property (GObject *object, guint prop_id,
|
||||
delayed->priv->backend = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_BASE_PATH:
|
||||
g_assert (delayed->priv->base_path == NULL);
|
||||
delayed->priv->base_path = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
g_delayed_settings_backend_backend_changed (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
const gchar * const *items,
|
||||
gint n_items,
|
||||
gpointer origin_tag,
|
||||
gpointer user_data)
|
||||
delayed_backend_changed (GSettingsBackend *backend,
|
||||
const gchar *name,
|
||||
gpointer origin_tag,
|
||||
gpointer user_data)
|
||||
{
|
||||
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (user_data);
|
||||
|
||||
if (origin_tag == delayed->priv)
|
||||
return;
|
||||
if (origin_tag != delayed->priv)
|
||||
g_settings_backend_changed (backend, name, origin_tag);
|
||||
}
|
||||
|
||||
if (g_str_has_prefix (prefix, delayed->priv->base_path))
|
||||
{
|
||||
g_settings_backend_changed (G_SETTINGS_BACKEND (delayed),
|
||||
prefix + strlen (delayed->priv->base_path),
|
||||
items, n_items, origin_tag);
|
||||
}
|
||||
static void
|
||||
delayed_backend_keys_changed (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
const gchar * const *items,
|
||||
gpointer origin_tag,
|
||||
gpointer user_data)
|
||||
{
|
||||
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (user_data);
|
||||
|
||||
else if (g_str_has_prefix (delayed->priv->base_path, prefix))
|
||||
{
|
||||
const gchar **my_items;
|
||||
const gchar *relative;
|
||||
gint relative_length;
|
||||
gint i, j;
|
||||
if (origin_tag != delayed->priv)
|
||||
g_settings_backend_keys_changed (backend, prefix, items, origin_tag);
|
||||
}
|
||||
|
||||
relative = delayed->priv->base_path + strlen (prefix);
|
||||
relative_length = strlen (relative);
|
||||
|
||||
my_items = g_new (const gchar *, n_items + 1);
|
||||
|
||||
for (i = j = 0; i < n_items; i++)
|
||||
if (g_str_has_prefix (items[i], relative))
|
||||
my_items[j++] = items[i] + relative_length;
|
||||
my_items[j] = NULL;
|
||||
|
||||
if (j > 0)
|
||||
g_settings_backend_changed (G_SETTINGS_BACKEND (delayed),
|
||||
"", my_items, j, origin_tag);
|
||||
g_free (my_items);
|
||||
}
|
||||
|
||||
else
|
||||
/* do nothing */;
|
||||
static void
|
||||
delayed_backend_writable_changed (GSettingsBackend *backend,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
/* XXX: maybe drop keys from the delayed-apply settings
|
||||
* if they became non-writable?
|
||||
*/
|
||||
g_settings_backend_writable_changed (backend, name);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -246,15 +227,21 @@ g_delayed_settings_backend_constructed (GObject *object)
|
||||
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (object);
|
||||
|
||||
g_assert (delayed->priv->backend != NULL);
|
||||
g_assert (delayed->priv->base_path != NULL);
|
||||
|
||||
delayed->priv->handler_id =
|
||||
delayed->priv->changed_handler_id =
|
||||
g_signal_connect (delayed->priv->backend, "changed",
|
||||
G_CALLBACK (g_delayed_settings_backend_backend_changed),
|
||||
G_CALLBACK (delayed_backend_changed),
|
||||
delayed);
|
||||
|
||||
g_settings_backend_subscribe (delayed->priv->backend,
|
||||
delayed->priv->base_path);
|
||||
delayed->priv->keys_changed_handler_id =
|
||||
g_signal_connect (delayed->priv->backend, "keys-changed",
|
||||
G_CALLBACK (delayed_backend_keys_changed),
|
||||
delayed);
|
||||
|
||||
delayed->priv->writable_changed_handler_id =
|
||||
g_signal_connect (delayed->priv->backend, "writable-changed",
|
||||
G_CALLBACK (delayed_backend_writable_changed),
|
||||
delayed);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -263,11 +250,12 @@ g_delayed_settings_backend_finalize (GObject *object)
|
||||
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (object);
|
||||
|
||||
g_signal_handler_disconnect (delayed->priv->backend,
|
||||
delayed->priv->handler_id);
|
||||
g_settings_backend_unsubscribe (delayed->priv->backend,
|
||||
delayed->priv->base_path);
|
||||
delayed->priv->changed_handler_id);
|
||||
g_signal_handler_disconnect (delayed->priv->backend,
|
||||
delayed->priv->keys_changed_handler_id);
|
||||
g_signal_handler_disconnect (delayed->priv->backend,
|
||||
delayed->priv->writable_changed_handler_id);
|
||||
g_object_unref (delayed->priv->backend);
|
||||
g_free (delayed->priv->base_path);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -294,11 +282,6 @@ g_delayed_settings_backend_class_init (GDelayedSettingsBackendClass *class)
|
||||
G_TYPE_SETTINGS_BACKEND, G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_BASE_PATH,
|
||||
g_param_spec_string ("base-path", "base path", "base",
|
||||
"", G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_HAS_UNAPPLIED,
|
||||
g_param_spec_boolean ("has-unapplied", "has unapplied", "unapplied",
|
||||
FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
@ -316,13 +299,10 @@ g_delayed_settings_backend_init (GDelayedSettingsBackend *delayed)
|
||||
}
|
||||
|
||||
GSettingsBackend *
|
||||
g_delayed_settings_backend_new (GSettingsBackend *backend,
|
||||
const gchar *base_path)
|
||||
g_delayed_settings_backend_new (GSettingsBackend *backend)
|
||||
{
|
||||
return g_object_new (G_TYPE_DELAYED_SETTINGS_BACKEND,
|
||||
"backend", backend,
|
||||
"base-path", base_path,
|
||||
NULL);
|
||||
"backend", backend, NULL);
|
||||
}
|
||||
|
||||
#define _gsettingsdelayedbackend_c_
|
||||
|
@ -48,8 +48,7 @@ struct _GDelayedSettingsBackend
|
||||
G_BEGIN_DECLS
|
||||
|
||||
GType g_delayed_settings_backend_get_type (void);
|
||||
GSettingsBackend * g_delayed_settings_backend_new (GSettingsBackend *backend,
|
||||
const gchar *base_path);
|
||||
GSettingsBackend * g_delayed_settings_backend_new (GSettingsBackend *backend);
|
||||
void g_delayed_settings_backend_revert (GDelayedSettingsBackend *delayed);
|
||||
void g_delayed_settings_backend_apply (GDelayedSettingsBackend *delayed);
|
||||
gboolean g_delayed_settings_backend_get_has_unapplied (GDelayedSettingsBackend *delayed);
|
||||
|
@ -5,4 +5,5 @@ VOID:OBJECT,OBJECT,ENUM
|
||||
BOOLEAN:OBJECT,OBJECT
|
||||
VOID:STRING,BOXED,BOXED
|
||||
VOID:STRING,BOXED,POINTER
|
||||
VOID:STRING,POINTER
|
||||
VOID:POINTER,INT
|
||||
|
@ -187,11 +187,7 @@ g_settings_set_delay_apply (GSettings *settings,
|
||||
|
||||
g_assert (delayed);
|
||||
|
||||
backend = g_delayed_settings_backend_new (settings->priv->backend,
|
||||
settings->priv->base_path);
|
||||
g_settings_backend_subscribe (backend, "");
|
||||
g_settings_backend_unsubscribe (settings->priv->backend,
|
||||
settings->priv->base_path);
|
||||
backend = g_delayed_settings_backend_new (settings->priv->backend);
|
||||
g_signal_handler_disconnect (settings->priv->backend,
|
||||
settings->priv->handler_id);
|
||||
g_object_unref (settings->priv->backend);
|
||||
@ -707,7 +703,6 @@ g_settings_set_value (GSettings *settings,
|
||||
{
|
||||
gboolean correct_type;
|
||||
GVariant *sval;
|
||||
GTree *tree;
|
||||
|
||||
sval = g_settings_schema_get_value (settings->priv->schema, key, NULL);
|
||||
correct_type = g_variant_is_of_type (value, g_variant_get_type (sval));
|
||||
@ -715,10 +710,7 @@ g_settings_set_value (GSettings *settings,
|
||||
|
||||
g_return_if_fail (correct_type);
|
||||
|
||||
tree = g_settings_backend_create_tree ();
|
||||
g_tree_insert (tree, strdup (key), g_variant_ref_sink (value));
|
||||
g_settings_backend_write (settings->priv->backend, key, tree, NULL);
|
||||
g_tree_unref (tree);
|
||||
g_settings_backend_write (settings->priv->backend, key, value, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,11 +1,24 @@
|
||||
/*
|
||||
* Copyright © 2009 Codethink Limited
|
||||
* Copyright © 2009, 2010 Codethink Limited
|
||||
* Copyright © 2010 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of version 3 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the licence, or (at your option) any later version.
|
||||
*
|
||||
* See the included COPYING file for more information.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Ryan Lortie <desrt@desrt.ca>
|
||||
* Matthias Clasen <mclasen@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@ -29,6 +42,8 @@ struct _GSettingsBackendPrivate
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (GSettingsBackend, g_settings_backend, G_TYPE_OBJECT)
|
||||
|
||||
static guint writable_changed_signal;
|
||||
static guint keys_changed_signal;
|
||||
static guint changed_signal;
|
||||
|
||||
enum {
|
||||
@ -57,6 +72,48 @@ enum {
|
||||
* suitable trees.
|
||||
**/
|
||||
|
||||
/**
|
||||
* g_settings_backend_changed:
|
||||
* @backend: a #GSettingsBackend implementation
|
||||
* @name: the name of the key or path that changed
|
||||
* @origin_tag: the origin tag
|
||||
*
|
||||
* Emits the changed signal on @backend. This function should only be
|
||||
* called by the implementation itself, to indicate that a change has
|
||||
* occurred.
|
||||
*
|
||||
* @name may refer to a specific single key (ie: not ending in '/') or
|
||||
* may refer to a set of keys (ie: ending in '/'). In the case that it
|
||||
* ends in '/' then any key under that path may have been changed.
|
||||
*
|
||||
* The implementation must call this function during any call to
|
||||
* g_settings_backend_write(), before the call returns (except in the
|
||||
* case that no keys are actually changed). It may not rely on the
|
||||
* existence of a mainloop for dispatching the signal later.
|
||||
*
|
||||
* The implementation may call this function at any other time it likes
|
||||
* in response to other events (such as changes occuring outside of the
|
||||
* program). These calls may originate from a mainloop or may originate
|
||||
* in response to any other action (including from calls to
|
||||
* g_settings_backend_write()).
|
||||
*
|
||||
* In the case that this call is in response to a call to
|
||||
* g_settings_backend_write() then @origin_tag must be set to the same
|
||||
* value that was passed to that call.
|
||||
*
|
||||
* Since: 2.26
|
||||
**/
|
||||
void
|
||||
g_settings_backend_changed (GSettingsBackend *backend,
|
||||
const gchar *name,
|
||||
gpointer origin_tag)
|
||||
{
|
||||
g_return_if_fail (backend != NULL);
|
||||
g_return_if_fail (name != NULL);
|
||||
|
||||
g_signal_emit (backend, changed_signal, 0, name, origin_tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_settings_backend_changed:
|
||||
* @backend: a #GSettingsBackend implementation
|
||||
@ -92,19 +149,23 @@ enum {
|
||||
* Since: 2.26
|
||||
*/
|
||||
void
|
||||
g_settings_backend_changed (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
gchar const * const *items,
|
||||
gint n_items,
|
||||
gpointer origin_tag)
|
||||
g_settings_backend_keys_changed (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
gchar const * const *items,
|
||||
gpointer origin_tag)
|
||||
{
|
||||
if (n_items == -1)
|
||||
for (n_items = 0; items[n_items]; n_items++);
|
||||
g_return_if_fail (backend != NULL);
|
||||
g_return_if_fail (prefix != NULL);
|
||||
g_return_if_fail (items != NULL);
|
||||
|
||||
g_signal_emit (backend, keys_changed_signal, 0, prefix, items, origin_tag);
|
||||
}
|
||||
|
||||
g_assert (items[n_items] == NULL);
|
||||
|
||||
g_signal_emit (backend, changed_signal, 0,
|
||||
prefix, items, n_items, origin_tag);
|
||||
void
|
||||
g_settings_backend_writable_changed (GSettingsBackend *backend,
|
||||
const gchar *name)
|
||||
{
|
||||
g_signal_emit (backend, writable_changed_signal, 0, name);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -130,7 +191,6 @@ g_settings_backend_append_to_list (gpointer key,
|
||||
**/
|
||||
void
|
||||
g_settings_backend_changed_tree (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
GTree *tree,
|
||||
gpointer origin_tag)
|
||||
{
|
||||
@ -147,7 +207,7 @@ g_settings_backend_changed_tree (GSettingsBackend *backend,
|
||||
}
|
||||
|
||||
g_signal_emit (backend, changed_signal, 0,
|
||||
prefix, list, g_tree_nnodes (tree), origin_tag);
|
||||
"", list, g_tree_nnodes (tree), origin_tag);
|
||||
g_free (list);
|
||||
}
|
||||
|
||||
@ -183,18 +243,47 @@ g_settings_backend_read (GSettingsBackend *backend,
|
||||
/**
|
||||
* g_settings_backend_write:
|
||||
* @backend: a #GSettingsBackend implementation
|
||||
* @prefix: the longest common prefix
|
||||
* @key: the name of the key
|
||||
* @value: a #GVariant value to write to this key
|
||||
* @origin_tag: the origin tag
|
||||
*
|
||||
* Writes exactly one key.
|
||||
*
|
||||
* This call does not fail. During this call a
|
||||
* #GSettingsBackend::changed signal will be emitted if the value of the
|
||||
* key has changed. The updated key value will be visible to any signal
|
||||
* callbacks.
|
||||
*
|
||||
* One possible method that an implementation might deal with failures is
|
||||
* to emit a second "changed" signal (either during this call, or later)
|
||||
* to indicate that the affected keys have suddenly "changed back" to their
|
||||
* old values.
|
||||
*
|
||||
* Since: 2.26
|
||||
**/
|
||||
void
|
||||
g_settings_backend_write (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
GVariant *value,
|
||||
gpointer origin_tag)
|
||||
{
|
||||
G_SETTINGS_BACKEND_GET_CLASS (backend)
|
||||
->write (backend, key, value, origin_tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_settings_backend_write_keys:
|
||||
* @backend: a #GSettingsBackend implementation
|
||||
* @values: a #GTree containing key-value pairs to write
|
||||
* @origin_tag: the origin tag
|
||||
*
|
||||
* Writes one or more keys. This call will never block.
|
||||
*
|
||||
* For each item in @values, a key is written. The key to be written is
|
||||
* @prefix prepended to the key used in the tree. The value stored in
|
||||
* the tree is expected to be a #GVariant instance. It must either be
|
||||
* the case that @prefix is equal to "" or ends in "/" or that @values
|
||||
* contains exactly one item, with a key of "". @prefix need not be the
|
||||
* largest possible prefix.
|
||||
* The key of each item in the tree is the key name to write to and the
|
||||
* value is a #GVariant to write. The proper type of #GTree for this
|
||||
* call can be created with g_settings_backend_create_tree(). This call
|
||||
* might take a reference to the tree; you must not modified the #GTree
|
||||
* after passing it to this call.
|
||||
*
|
||||
* This call does not fail. During this call a #GSettingsBackend::changed
|
||||
* signal will be emitted if any keys have been changed. The new values of
|
||||
@ -208,13 +297,12 @@ g_settings_backend_read (GSettingsBackend *backend,
|
||||
* Since: 2.26
|
||||
**/
|
||||
void
|
||||
g_settings_backend_write (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
GTree *values,
|
||||
gpointer origin_tag)
|
||||
g_settings_backend_write_keys (GSettingsBackend *backend,
|
||||
GTree *tree,
|
||||
gpointer origin_tag)
|
||||
{
|
||||
G_SETTINGS_BACKEND_GET_CLASS (backend)
|
||||
->write (backend, prefix, values, origin_tag);
|
||||
->write_keys (backend, tree, origin_tag);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -362,21 +450,21 @@ g_settings_backend_class_init (GSettingsBackendClass *class)
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
value_changed_signal =
|
||||
g_signal_new ("value-changed", G_TYPE_SETTINGS_BACKEND,
|
||||
changed_signal =
|
||||
g_signal_new ("changed", G_TYPE_SETTINGS_BACKEND,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GSettingsBackendClass, value_changed),
|
||||
G_STRUCT_OFFSET (GSettingsBackendClass, changed),
|
||||
NULL, NULL,
|
||||
_gio_marshal_VOID__STRING_POINTER, G_TYPE_NONE,
|
||||
2, G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE |
|
||||
G_TYPE_POINTER);
|
||||
|
||||
multiple_changed_signal =
|
||||
g_signal_new ("multiple-changed", G_TYPE_SETTINGS_BACKEND,
|
||||
keys_changed_signal =
|
||||
g_signal_new ("keys-changed", G_TYPE_SETTINGS_BACKEND,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GSettingsBackendClass, multiple_changed),
|
||||
G_STRUCT_OFFSET (GSettingsBackendClass, keys_changed),
|
||||
NULL, NULL,
|
||||
_gio_marshal_VOID__STRING_BOXED_INT_POINTER, G_TYPE_NONE,
|
||||
_gio_marshal_VOID__STRING_BOXED_POINTER, G_TYPE_NONE,
|
||||
3, G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
|
||||
G_TYPE_STRV | G_SIGNAL_TYPE_STATIC_SCOPE, G_TYPE_POINTER);
|
||||
|
||||
@ -466,11 +554,14 @@ get_default_backend (const gchar *context)
|
||||
|
||||
if (context)
|
||||
{
|
||||
GSettingsBackendClass *backend_class;
|
||||
GTypeClass *class;
|
||||
|
||||
class = g_io_extension_ref_class (extension);
|
||||
backend_class = G_SETTINGS_BACKEND_CLASS (class);
|
||||
|
||||
if (!g_settings_backend_class_supports_context (G_SETTINGS_BACKEND_CLASS (class), context))
|
||||
if (backend_class->supports_context != NULL &&
|
||||
!backend_class->supports_context (context))
|
||||
{
|
||||
g_type_class_unref (class);
|
||||
return NULL;
|
||||
@ -569,16 +660,8 @@ g_settings_backend_supports_context (const gchar *context)
|
||||
static void
|
||||
g_settings_backend_init (GSettingsBackend *backend)
|
||||
{
|
||||
backend->priv = g_type_instance_get_private (backend, G_TYPE_SETTINGS_BACKEND);
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_settings_backend_class_supports_context (GSettingsBackendClass *klass,
|
||||
const gchar *context)
|
||||
{
|
||||
if (klass->supports_context)
|
||||
return (klass->supports_context) (klass, context);
|
||||
|
||||
return TRUE;
|
||||
backend->priv = G_TYPE_INSTANCE_GET_PRIVATE (backend,
|
||||
G_TYPE_SETTINGS_BACKEND,
|
||||
GSettingsBackendPrivate);
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,24 @@
|
||||
/*
|
||||
* Copyright © 2009 Codethink Limited
|
||||
* Copyright © 2009, 2010 Codethink Limited
|
||||
* Copyright © 2010 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of version 3 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the licence, or (at your option) any later version.
|
||||
*
|
||||
* See the included COPYING file for more information.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Ryan Lortie <desrt@desrt.ca>
|
||||
* Matthias Clasen <mclasen@redhat.com>
|
||||
*/
|
||||
|
||||
#ifndef __G_SETTINGS_BACKEND_H__
|
||||
@ -42,28 +55,35 @@ struct _GSettingsBackendClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
void (*changed) (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
gchar const * const *names,
|
||||
gint names_len,
|
||||
gpointer origin_tag);
|
||||
void (*changed) (GSettingsBackend *backend,
|
||||
const gchar *name,
|
||||
gpointer origin_tag);
|
||||
void (*keys_changed) (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
gchar const * const *names,
|
||||
gpointer origin_tag);
|
||||
void (*writable_changed) (GSettingsBackend *backend,
|
||||
const gchar *name);
|
||||
|
||||
GVariant * (*read) (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
const GVariantType *expected_type);
|
||||
void (*write) (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
GTree *tree,
|
||||
gpointer origin_tag);
|
||||
gboolean (*get_writable) (GSettingsBackend *backend,
|
||||
const gchar *name);
|
||||
void (*subscribe) (GSettingsBackend *backend,
|
||||
const gchar *name);
|
||||
void (*unsubscribe) (GSettingsBackend *backend,
|
||||
const gchar *name);
|
||||
|
||||
gboolean (*supports_context) (GSettingsBackendClass *klass,
|
||||
const gchar *context);
|
||||
GVariant * (*read) (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
const GVariantType *expected_type);
|
||||
void (*write) (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
GVariant *value,
|
||||
gpointer origin_tag);
|
||||
void (*write_keys) (GSettingsBackend *backend,
|
||||
GTree *tree,
|
||||
gpointer origin_tag);
|
||||
gboolean (*get_writable) (GSettingsBackend *backend,
|
||||
const gchar *name);
|
||||
void (*subscribe) (GSettingsBackend *backend,
|
||||
const gchar *name);
|
||||
void (*unsubscribe) (GSettingsBackend *backend,
|
||||
const gchar *name);
|
||||
|
||||
gboolean (*supports_context) (const gchar *context);
|
||||
};
|
||||
|
||||
struct _GSettingsBackend
|
||||
@ -82,10 +102,12 @@ GTree * g_settings_backend_create_tree (void);
|
||||
GVariant * g_settings_backend_read (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
const GVariantType *expected_type);
|
||||
|
||||
void g_settings_backend_write (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
GTree *values,
|
||||
const gchar *key,
|
||||
GVariant *value,
|
||||
gpointer origin_tag);
|
||||
void g_settings_backend_write_keys (GSettingsBackend *backend,
|
||||
GTree *tree,
|
||||
gpointer origin_tag);
|
||||
|
||||
gboolean g_settings_backend_get_writable (GSettingsBackend *backend,
|
||||
@ -97,18 +119,18 @@ void g_settings_backend_subscribe (GSettin
|
||||
const char *name);
|
||||
|
||||
void g_settings_backend_changed (GSettingsBackend *backend,
|
||||
const gchar *path,
|
||||
gpointer origin_tag);
|
||||
void g_settings_backend_writable_changed (GSettingsBackend *backend,
|
||||
const gchar *path);
|
||||
void g_settings_backend_keys_changed (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
gchar const * const *items,
|
||||
gint n_items,
|
||||
gpointer origin_tag);
|
||||
void g_settings_backend_changed_tree (GSettingsBackend *backend,
|
||||
const gchar *prefix,
|
||||
GTree *tree,
|
||||
gpointer origin_tag);
|
||||
|
||||
gboolean g_settings_backend_class_supports_context (GSettingsBackendClass *klass,
|
||||
const gchar *context);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_SETTINGS_BACKEND_H__ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user