mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 17:56:17 +01:00
GSettingsBackend API/ABI change
- add list() virtual method - add 'default_value' flag to read() call
This commit is contained in:
parent
9ba690b386
commit
8dddf6499e
@ -42,16 +42,18 @@ G_DEFINE_TYPE (GDelayedSettingsBackend,
|
||||
static GVariant *
|
||||
g_delayed_settings_backend_read (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
const GVariantType *expected_type)
|
||||
const GVariantType *expected_type,
|
||||
gboolean default_value)
|
||||
{
|
||||
GDelayedSettingsBackend *delayed = G_DELAYED_SETTINGS_BACKEND (backend);
|
||||
GVariant *result;
|
||||
|
||||
if ((result = g_tree_lookup (delayed->priv->delayed, key)))
|
||||
if (!default_value &&
|
||||
(result = g_tree_lookup (delayed->priv->delayed, key)))
|
||||
return g_variant_ref (result);
|
||||
|
||||
return g_settings_backend_read (delayed->priv->backend,
|
||||
key, expected_type);
|
||||
key, expected_type, default_value);
|
||||
}
|
||||
static gboolean
|
||||
g_delayed_settings_backend_write (GSettingsBackend *backend,
|
||||
|
@ -1387,6 +1387,7 @@ g_settings_backend_setup_keyfile
|
||||
g_settings_backend_setup
|
||||
g_settings_backend_get_type
|
||||
g_settings_backend_changed
|
||||
g_settings_backend_flatten_tree
|
||||
g_settings_backend_keys_changed
|
||||
g_settings_backend_path_changed
|
||||
g_settings_backend_path_writable_changed
|
||||
|
@ -54,11 +54,15 @@ struct _GKeyfileSettingsBackendPrivate
|
||||
static GVariant *
|
||||
g_keyfile_settings_backend_read (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
const GVariantType *expected_type)
|
||||
const GVariantType *expected_type,
|
||||
gboolean default_value)
|
||||
{
|
||||
GKeyfileSettingsBackend *kf_backend = G_KEYFILE_SETTINGS_BACKEND (backend);
|
||||
GVariant *value;
|
||||
|
||||
if (default_value)
|
||||
return NULL;
|
||||
|
||||
value = g_hash_table_lookup (kf_backend->priv->table, key);
|
||||
|
||||
if (value != NULL)
|
||||
|
@ -48,11 +48,14 @@ G_DEFINE_TYPE_WITH_CODE (GMemorySettingsBackend,
|
||||
static GVariant *
|
||||
g_memory_settings_backend_read (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
const GVariantType *expected_type)
|
||||
const GVariantType *expected_type,
|
||||
gboolean default_value)
|
||||
{
|
||||
GMemorySettingsBackend *memory = G_MEMORY_SETTINGS_BACKEND (backend);
|
||||
GVariant *value;
|
||||
|
||||
GMemorySettingsBackend *memory = G_MEMORY_SETTINGS_BACKEND (backend);
|
||||
if (default_value)
|
||||
return NULL;
|
||||
|
||||
value = g_hash_table_lookup (memory->table, key);
|
||||
|
||||
|
@ -42,7 +42,8 @@ G_DEFINE_TYPE (GNullSettingsBackend,
|
||||
static GVariant *
|
||||
g_null_settings_backend_read (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
const GVariantType *expected_type)
|
||||
const GVariantType *expected_type,
|
||||
gboolean default_value)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -751,7 +751,7 @@ g_settings_get_value (GSettings *settings,
|
||||
|
||||
path = g_strconcat (settings->priv->path, key, NULL);
|
||||
type = g_variant_get_type (sval);
|
||||
value = g_settings_backend_read (settings->priv->backend, path, type);
|
||||
value = g_settings_backend_read (settings->priv->backend, path, type, FALSE);
|
||||
g_free (path);
|
||||
|
||||
if (options != NULL)
|
||||
|
@ -368,17 +368,18 @@ g_settings_backend_path_writable_changed (GSettingsBackend *backend,
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const gchar **keys;
|
||||
GVariant **values;
|
||||
gint prefix_len;
|
||||
gchar *prefix;
|
||||
gchar **items;
|
||||
} GetKeysState;
|
||||
} FlattenState;
|
||||
|
||||
static gboolean
|
||||
tree_get_keys (gpointer key,
|
||||
gpointer value,
|
||||
gpointer user_data)
|
||||
g_settings_backend_flatten_one (gpointer key,
|
||||
gpointer value,
|
||||
gpointer user_data)
|
||||
{
|
||||
GetKeysState *state = user_data;
|
||||
FlattenState *state = user_data;
|
||||
const gchar *skey = key;
|
||||
gint i;
|
||||
|
||||
@ -419,11 +420,60 @@ tree_get_keys (gpointer key,
|
||||
/* save the entire item into the array.
|
||||
* the prefixes will be removed later.
|
||||
*/
|
||||
*state->items++ = key;
|
||||
*state->keys++ = key;
|
||||
|
||||
if (state->values)
|
||||
*state->values++ = value;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_settings_backend_flatten_tree:
|
||||
* @tree: a #GTree containing the changes
|
||||
* @path: the location to save the path
|
||||
* @keys: the location to save the relative keys
|
||||
* @values: the location to save the values, or %NULL
|
||||
*
|
||||
* Calculate the longest common prefix of all keys in a tree and write
|
||||
* out an array of the key names relative to that prefix and,
|
||||
* optionally, the value to store at each of those keys.
|
||||
*
|
||||
* You must free the value returned in @path, @keys and @values using
|
||||
* g_free(). You should not attempt to free or unref the contents of
|
||||
* @keys or @values.
|
||||
*
|
||||
* Since: 2.26
|
||||
**/
|
||||
void
|
||||
g_settings_backend_flatten_tree (GTree *tree,
|
||||
gchar **path,
|
||||
const gchar ***keys,
|
||||
GVariant ***values)
|
||||
{
|
||||
FlattenState state = { 0, };
|
||||
gsize nnodes;
|
||||
gsize i;
|
||||
|
||||
nnodes = g_tree_nnodes (tree);
|
||||
|
||||
*keys = state.keys = g_new (const gchar *, nnodes + 1);
|
||||
state.keys[nnodes] = NULL;
|
||||
|
||||
if (values != NULL)
|
||||
{
|
||||
*values = state.values = g_new (GVariant *, nnodes + 1);
|
||||
state.values[nnodes] = NULL;
|
||||
}
|
||||
|
||||
g_tree_foreach (tree, g_settings_backend_flatten_one, &state);
|
||||
g_return_if_fail (*keys + nnodes == state.keys);
|
||||
|
||||
*path = state.prefix;
|
||||
for (i = 0; i < nnodes; i++)
|
||||
state.keys[i] += state.prefix_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_settings_backend_changed_tree:
|
||||
* @backend: a #GSettingsBackend implementation
|
||||
@ -442,28 +492,18 @@ g_settings_backend_changed_tree (GSettingsBackend *backend,
|
||||
gpointer origin_tag)
|
||||
{
|
||||
GSettingsBackendWatch *watch;
|
||||
GetKeysState state = { 0, };
|
||||
gchar **list;
|
||||
const gchar **keys;
|
||||
gchar *path;
|
||||
|
||||
g_return_if_fail (G_IS_SETTINGS_BACKEND (backend));
|
||||
|
||||
list = g_new (gchar *, g_tree_nnodes (tree) + 1);
|
||||
state.items = list;
|
||||
|
||||
g_tree_foreach (tree, tree_get_keys, &state);
|
||||
g_return_if_fail (list + g_tree_nnodes (tree) == state.items);
|
||||
*state.items = NULL;
|
||||
|
||||
while (state.items-- != list)
|
||||
*state.items += state.prefix_len;
|
||||
g_settings_backend_flatten_tree (tree, &path, &keys, NULL);
|
||||
|
||||
for (watch = backend->priv->watches; watch; watch = watch->next)
|
||||
watch->keys_changed (backend, state.prefix,
|
||||
(const gchar * const *) list,
|
||||
origin_tag, watch->user_data);
|
||||
watch->keys_changed (backend, path, keys, origin_tag, watch->user_data);
|
||||
|
||||
g_free (list);
|
||||
g_free (state.prefix);
|
||||
g_free (path);
|
||||
g_free (keys);
|
||||
}
|
||||
|
||||
/*< private >
|
||||
@ -487,10 +527,11 @@ g_settings_backend_changed_tree (GSettingsBackend *backend,
|
||||
GVariant *
|
||||
g_settings_backend_read (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
const GVariantType *expected_type)
|
||||
const GVariantType *expected_type,
|
||||
gboolean default_value)
|
||||
{
|
||||
return G_SETTINGS_BACKEND_GET_CLASS (backend)
|
||||
->read (backend, key, expected_type);
|
||||
->read (backend, key, expected_type, default_value);
|
||||
}
|
||||
|
||||
/*< private >
|
||||
|
@ -69,7 +69,11 @@ struct _GSettingsBackendClass
|
||||
|
||||
GVariant * (*read) (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
const GVariantType *expected_type);
|
||||
const GVariantType *expected_type,
|
||||
gboolean default_value);
|
||||
gchar ** (*list) (GSettingsBackend *backend,
|
||||
const gchar *path,
|
||||
gsize *length);
|
||||
gboolean (*write) (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
GVariant *value,
|
||||
@ -112,6 +116,10 @@ void g_settings_backend_changed (GSettin
|
||||
void g_settings_backend_path_changed (GSettingsBackend *backend,
|
||||
const gchar *path,
|
||||
gpointer origin_tag);
|
||||
void g_settings_backend_flatten_tree (GTree *tree,
|
||||
gchar **path,
|
||||
const gchar ***keys,
|
||||
GVariant ***values);
|
||||
void g_settings_backend_keys_changed (GSettingsBackend *backend,
|
||||
const gchar *path,
|
||||
gchar const * const *items,
|
||||
|
@ -67,7 +67,8 @@ GTree * g_settings_backend_create_tree (void);
|
||||
G_GNUC_INTERNAL
|
||||
GVariant * g_settings_backend_read (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
const GVariantType *expected_type);
|
||||
const GVariantType *expected_type,
|
||||
gboolean default_value);
|
||||
G_GNUC_INTERNAL
|
||||
gboolean g_settings_backend_write (GSettingsBackend *backend,
|
||||
const gchar *key,
|
||||
|
Loading…
Reference in New Issue
Block a user