Cleanup the GSettingsBackend API

This is a substantial ABI break.  Rebuild dconf.
This commit is contained in:
Ryan Lortie 2010-07-22 18:39:50 -04:00
parent aed440815e
commit d5bd531d96
9 changed files with 125 additions and 74 deletions

View File

@ -151,7 +151,7 @@ add_to_tree (gpointer key,
}
static gboolean
g_delayed_settings_backend_write_keys (GSettingsBackend *backend,
g_delayed_settings_backend_write_tree (GSettingsBackend *backend,
GTree *tree,
gpointer origin_tag)
{
@ -198,14 +198,6 @@ g_delayed_settings_backend_reset (GSettingsBackend *backend,
g_delayed_settings_backend_notify_unapplied (delayed);
}
static void
g_delayed_settings_backend_reset_path (GSettingsBackend *backend,
const gchar *path,
gpointer origin_tag)
{
/* deal with this... */
}
static void
g_delayed_settings_backend_subscribe (GSettingsBackend *backend,
const char *name)
@ -254,7 +246,7 @@ g_delayed_settings_backend_apply (GDelayedSettingsBackend *delayed)
g_static_mutex_lock (&delayed->priv->lock);
tmp = delayed->priv->delayed;
delayed->priv->delayed = g_settings_backend_create_tree ();
success = g_settings_backend_write_keys (delayed->priv->backend,
success = g_settings_backend_write_tree (delayed->priv->backend,
tmp, delayed->priv);
g_static_mutex_unlock (&delayed->priv->lock);
@ -446,9 +438,8 @@ g_delayed_settings_backend_class_init (GDelayedSettingsBackendClass *class)
backend_class->read = g_delayed_settings_backend_read;
backend_class->write = g_delayed_settings_backend_write;
backend_class->write_keys = g_delayed_settings_backend_write_keys;
backend_class->write_tree = g_delayed_settings_backend_write_tree;
backend_class->reset = g_delayed_settings_backend_reset;
backend_class->reset_path = g_delayed_settings_backend_reset_path;
backend_class->get_writable = g_delayed_settings_backend_get_writable;
backend_class->subscribe = g_delayed_settings_backend_subscribe;
backend_class->unsubscribe = g_delayed_settings_backend_unsubscribe;

View File

@ -293,7 +293,7 @@ g_keyfile_settings_backend_check_one (gpointer key,
}
static gboolean
g_keyfile_settings_backend_write_many (GSettingsBackend *backend,
g_keyfile_settings_backend_write_tree (GSettingsBackend *backend,
GTree *tree,
gpointer origin_tag)
{
@ -338,19 +338,6 @@ g_keyfile_settings_backend_write (GSettingsBackend *backend,
return success;
}
static void
g_keyfile_settings_backend_reset_path (GSettingsBackend *backend,
const gchar *path,
gpointer origin_tag)
{
GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
if (set_to_keyfile (kfsb, path, NULL))
g_keyfile_settings_backend_keyfile_write (kfsb);
g_settings_backend_path_changed (backend, path, origin_tag);
}
static void
g_keyfile_settings_backend_reset (GSettingsBackend *backend,
const gchar *key,
@ -545,9 +532,8 @@ g_keyfile_settings_backend_class_init (GKeyfileSettingsBackendClass *class)
class->read = g_keyfile_settings_backend_read;
class->write = g_keyfile_settings_backend_write;
class->write_keys = g_keyfile_settings_backend_write_many;
class->write_tree = g_keyfile_settings_backend_write_tree;
class->reset = g_keyfile_settings_backend_reset;
class->reset_path = g_keyfile_settings_backend_reset_path;
class->get_writable = g_keyfile_settings_backend_get_writable;
class->get_permission = g_keyfile_settings_backend_get_permission;
/* No need to implement subscribed/unsubscribe: the only point would be to

View File

@ -104,7 +104,7 @@ g_memory_settings_backend_write_one (gpointer key,
}
static gboolean
g_memory_settings_backend_write_keys (GSettingsBackend *backend,
g_memory_settings_backend_write_tree (GSettingsBackend *backend,
GTree *tree,
gpointer origin_tag)
{
@ -168,7 +168,7 @@ g_memory_settings_backend_class_init (GMemorySettingsBackendClass *class)
backend_class->read = g_memory_settings_backend_read;
backend_class->write = g_memory_settings_backend_write;
backend_class->write_keys = g_memory_settings_backend_write_keys;
backend_class->write_tree = g_memory_settings_backend_write_tree;
backend_class->reset = g_memory_settings_backend_reset;
backend_class->get_writable = g_memory_settings_backend_get_writable;
backend_class->get_permission = g_memory_settings_backend_get_permission;

View File

@ -58,7 +58,7 @@ g_null_settings_backend_write (GSettingsBackend *backend,
}
static gboolean
g_null_settings_backend_write_keys (GSettingsBackend *backend,
g_null_settings_backend_write_tree (GSettingsBackend *backend,
GTree *tree,
gpointer origin_tag)
{
@ -72,13 +72,6 @@ g_null_settings_backend_reset (GSettingsBackend *backend,
{
}
static void
g_null_settings_backend_reset_path (GSettingsBackend *backend,
const gchar *path,
gpointer origin_tag)
{
}
static gboolean
g_null_settings_backend_get_writable (GSettingsBackend *backend,
const gchar *name)
@ -105,9 +98,8 @@ g_null_settings_backend_class_init (GNullSettingsBackendClass *class)
backend_class->read = g_null_settings_backend_read;
backend_class->write = g_null_settings_backend_write;
backend_class->write_keys = g_null_settings_backend_write_keys;
backend_class->write_tree = g_null_settings_backend_write_tree;
backend_class->reset = g_null_settings_backend_reset;
backend_class->reset_path = g_null_settings_backend_reset_path;
backend_class->get_writable = g_null_settings_backend_get_writable;
backend_class->get_permission = g_null_settings_backend_get_permission;
}

View File

@ -80,6 +80,7 @@ usage (gint *argc,
" help Show this information\n"
" get Get the value of a key\n"
" set Set the value of a key\n"
" reset Reset the value of a key\n"
" monitor Monitor a key for changes\n"
" writable Check if a key is writable\n"
"\n"
@ -420,6 +421,102 @@ handle_set (gint *argc,
return ret;
}
static gint
handle_reset (gint *argc,
gchar **argv[],
gboolean request_completion,
gchar *completion_cur,
gchar *completion_prev)
{
gchar *schema;
gchar *path;
gchar *key;
GSettings *settings;
GOptionContext *context;
GOptionEntry entries[] = {
{ "path", 'p', 0, G_OPTION_ARG_STRING, &path, N_("Specify the path for the schema"), N_("PATH") },
{ NULL }
};
GError *error;
gint ret = 1;
modify_argv0_for_command (argc, argv, "reset");
context = g_option_context_new (_("SCHEMA KEY VALUE"));
g_option_context_set_help_enabled (context, FALSE);
g_option_context_set_summary (context, _("Sets KEY to its default value"));
g_option_context_set_description (context,
_("Arguments:\n"
" SCHEMA The id of the schema\n"
" KEY The name of the key\n"));
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
settings = NULL;
path = NULL;
schema = NULL;
key = NULL;
error = NULL;
if (!g_option_context_parse (context, argc, argv, NULL))
{
if (!request_completion)
{
gchar *s;
s = g_option_context_get_help (context, FALSE, NULL);
g_printerr ("%s", s);
g_free (s);
goto out;
}
}
if (*argc > 1)
schema = (*argv)[1];
if (*argc > 2)
key = (*argv)[2];
if (request_completion && completion_cur[0] == '-')
{
list_options (context, completion_cur);
ret = 0;
goto out;
}
if (request_completion && !schema_exists (schema))
{
list_schemas (schema);
ret = 0;
goto out;
}
if (path)
settings = g_settings_new_with_path (schema, path);
else
settings = g_settings_new (schema);
if (request_completion && !key_exists (settings, key))
{
list_keys (settings, key);
ret = 0;
goto out;
}
if (!request_completion)
{
g_settings_reset (settings, key);
g_settings_sync ();
ret = 0;
}
out:
if (settings)
g_object_unref (settings);
g_option_context_free (context);
return ret;
}
static gint
handle_writable (gint *argc,
gchar **argv[],
@ -635,6 +732,7 @@ handle_monitor (gint *argc,
return ret;
}
int
main (int argc, char *argv[])
{
@ -671,6 +769,8 @@ main (int argc, char *argv[])
ret = handle_get (&argc, &argv, request_completion, completion_cur, completion_prev);
else if (g_strcmp0 (command, "set") == 0)
ret = handle_set (&argc, &argv, request_completion, completion_cur, completion_prev);
else if (g_strcmp0 (command, "reset") == 0)
ret = handle_reset (&argc, &argv, request_completion, completion_cur, completion_prev);
else if (g_strcmp0 (command, "monitor") == 0)
ret = handle_monitor (&argc, &argv, request_completion, completion_cur, completion_prev);
else if (g_strcmp0 (command, "writable") == 0)
@ -725,7 +825,7 @@ main (int argc, char *argv[])
{
if (request_completion)
{
g_print ("help \nget \nmonitor \nwritable \nset \n");
g_print ("help \nget \nmonitor \nwritable \nset \nreset \n");
ret = 0;
}
else

View File

@ -827,12 +827,12 @@ g_settings_backend_write (GSettingsBackend *backend,
* old values.
*/
gboolean
g_settings_backend_write_keys (GSettingsBackend *backend,
g_settings_backend_write_tree (GSettingsBackend *backend,
GTree *tree,
gpointer origin_tag)
{
return G_SETTINGS_BACKEND_GET_CLASS (backend)
->write_keys (backend, tree, origin_tag);
->write_tree (backend, tree, origin_tag);
}
/*< private >
@ -854,24 +854,6 @@ g_settings_backend_reset (GSettingsBackend *backend,
->reset (backend, key, origin_tag);
}
/*< private >
* g_settings_backend_reset_path:
* @backend: a #GSettingsBackend implementation
* @name: the name of a key or path
* @origin_tag: the origin tag
*
* "Resets" the named path. This means that every key under the path is
* reset.
*/
void
g_settings_backend_reset_path (GSettingsBackend *backend,
const gchar *path,
gpointer origin_tag)
{
G_SETTINGS_BACKEND_GET_CLASS (backend)
->reset_path (backend, path, origin_tag);
}
/*< private >
* g_settings_backend_get_writable:
* @backend: a #GSettingsBackend implementation

View File

@ -69,26 +69,21 @@ struct _GSettingsBackendClass
const gchar *key,
const GVariantType *expected_type,
gboolean default_value);
gchar ** (*list) (GSettingsBackend *backend,
const gchar *path,
gchar **resets,
gsize n_resets,
gsize *length);
gboolean (*get_writable) (GSettingsBackend *backend,
const gchar *key);
gboolean (*write) (GSettingsBackend *backend,
const gchar *key,
GVariant *value,
gpointer origin_tag);
gboolean (*write_keys) (GSettingsBackend *backend,
gboolean (*write_tree) (GSettingsBackend *backend,
GTree *tree,
gpointer origin_tag);
void (*reset) (GSettingsBackend *backend,
const gchar *key,
gpointer origin_tag);
void (*reset_path) (GSettingsBackend *backend,
const gchar *path,
gpointer origin_tag);
gboolean (*get_writable) (GSettingsBackend *backend,
const gchar *key);
void (*subscribe) (GSettingsBackend *backend,
const gchar *name);
void (*unsubscribe) (GSettingsBackend *backend,
@ -98,7 +93,7 @@ struct _GSettingsBackendClass
GPermission * (*get_permission) (GSettingsBackend *backend,
const gchar *path);
gpointer padding[7];
gpointer padding[24];
};
struct _GSettingsBackend

View File

@ -72,7 +72,7 @@ gboolean g_settings_backend_write (GSettin
GVariant *value,
gpointer origin_tag);
G_GNUC_INTERNAL
gboolean g_settings_backend_write_keys (GSettingsBackend *backend,
gboolean g_settings_backend_write_tree (GSettingsBackend *backend,
GTree *tree,
gpointer origin_tag);
G_GNUC_INTERNAL

View File

@ -55,6 +55,11 @@ test_basic (void)
g_free (str);
str = NULL;
g_settings_reset (settings, "greeting");
str = g_settings_get_string (settings, "greeting");
g_assert_cmpstr (str, ==, "Hello, earthlings");
g_free (str);
g_settings_set (settings, "greeting", "s", "this is the end");
g_object_unref (settings);
}