Implement bash completion for gsettings
[platform/upstream/glib.git] / gio / gsettings.c
index 7b829f7..b517237 100644 (file)
  * Author: Ryan Lortie <desrt@desrt.ca>
  */
 
+/* Prelude {{{1 */
+#define _GNU_SOURCE
 #include "config.h"
+
 #include <glib.h>
 #include <glibintl.h>
 #include <locale.h>
@@ -36,6 +39,8 @@
 
 #include "gioalias.h"
 
+#include "strinfo.c"
+
 /**
  * SECTION:gsettings
  * @short_description: a high-level API for application settings
@@ -74,7 +79,7 @@
  * utility. The input is a schema description in an XML format that can be
  * described by the following DTD:
  * |[<![CDATA[
- * <!ELEMENT schemalist (schema*) >
+ * <!ELEMENT schemalist (schema|enum)* >
  * <!ATTLIST schemalist gettext-domain #IMPLIED >
  *
  * <!ELEMENT schema (key|child)* >
  *                  path           CDATA #IMPLIED
  *                  gettext-domain CDATA #IMPLIED >
  *
- * <!ELEMENT key (default|summary?|description?|range?|choices?) >
+ * <!-- defines an enumerated type -->
+ * <!-- each value element maps a nick to a numeric value -->
+ * <!ELEMENT enum (value*) >
+ * <!ATTLIST enum id CDATA #REQUIRED >
+ * <!ELEMENT value EMPTY >
+ * <!-- nick must be at least 2 characters long -->
+ * <!-- value must be parsable as a 32-bit integer -->
+ * <!ELEMENT value nick  #REQUIRED
+ *                 value #REQUIRED >
+ *
+ * <!ELEMENT key (default|summary?|description?|range?|choices?|aliases?) >
  * <!-- name can only contain lowercase letters, numbers and '-' -->
  * <!-- type must be a GVariant type string -->
+ * <!-- enum must be the id of an enum that has been defined earlier -->
+ * <!-- exactly one of enum or type must be given -->
  * <!ATTLIST key name CDATA #REQUIRED
- *               type CDATA #REQUIRED >
+ *               type CDATA #IMPLIED
+ *               enum CDATA #IMPLIED >
  *
  * <!-- the default value is specified a a serialized GVariant,
  *      i.e. you have to include the quotes when specifying a string -->
  * <!ELEMENT summary (#PCDATA) >
  * <!ELEMENT description (#PCDATA) >
  *
+ * <!-- range is only allowed for keys with numeric type -->
  * <!ELEMENT range EMPTY >
+ * <!-- min and max must be parseable as values of the key type and min < max -->
  * <!ATTLIST range min CDATA #REQUIRED
  *                 max CDATA #REQUIRED >
  *
+ * <!-- choices is only allowed for keys with string or string array type -->
  * <!ELEMENT choices (choice+) >
- * <!ELEMENT choice (alias?) >
+ * <!-- each choice element specifies one possible value -->
+ * <!ELEMENT choice EMPTY >
  * <!ATTLIST choice value CDATA #REQUIRED >
- * <!ELEMENT choice (alias?) >
+ *
+ * <!-- aliases is only allowed for keys with enumerated type or with choices -->
+ * <!ELEMENT aliases (alias+) >
+ * <!-- each alias element specifies an alias for one of the possible values -->
  * <!ELEMENT alias EMPTY >
- * <!ATTLIST alias value CDATA #REQUIRED >
+ * <!ATTLIST alias value CDATA #REQUIRED
+ *                 target CDATA #REQUIRED >
  *
  * <!ELEMENT child EMPTY >
  * <!ATTLIST child name  CDATA #REQUIRED
  * convention for schema ids is to use a dotted name, similar in
  * style to a DBus bus name, e.g. "org.gnome.font-rendering".
  *
+ * <example><title>Default values</title>
+ * <programlisting><![CDATA[
+ * <schemalist>
+ *   <schema id="org.gtk.test" path="/tests/" gettext-domain="test">
+ *
+ *     <key name="greeting" type="s">
+ *       <default l10n="messages">"Hello, earthlings"</default>
+ *       <summary>A greeting</summary>
+ *       <description>
+ *         Greeting of the invading martians
+ *       </description>
+ *     </key>
+ *
+ *     <key name="box" type="(ii)">
+ *       <default>(20,30)</default>
+ *     </key>
+ *
+ *   </schema>
+ * </schemalist>
+ * ]]></programlisting></example>
+ *
+ * <example><title>Ranges, choices and enumerated types</title>
+ * <programlisting><![CDATA[
+ * <schemalist>
+ *
+ *   <enum id="myenum">
+ *     <value nick="first" value="1"/>
+ *     <value nick="second" value="2"/>
+ *   </enum>
+ *
+ *   <schema id="org.gtk.test">
+ *
+ *     <key name="key-with-range" type="i">
+ *       <range min="1" max="100"/>
+ *       <default>10</default>
+ *     </key>
+ *
+ *     <key name="key-with-choices" type="s">
+ *       <choices>
+ *         <choice value='Elisabeth'/>
+ *         <choice value='Annabeth'/>
+ *         <choice value='Joe'/>
+ *       </choices>
+ *       <aliases>
+ *         <alias value='Anna' target='Annabeth'/>
+ *         <alias value='Beth' target='Elisabeth'/>
+ *       </aliases>
+ *       <default>'Joe'</default>
+ *     </key>
+ *
+ *     <key name='enumerated-key' enum='myenum'>
+ *       <default>'first'</default>
+ *     </key>
+ *
+ *   </schema>
+ * </schemalist>
+ * ]]></programlisting></example>
+ *
  * <refsect2>
  *  <title>Binding</title>
  *   <para>
  *    #G_SETTINGS_BIND_NO_SENSITIVITY flag.
  *   </para>
  *  </refsect2>
- */
+ **/
 
 struct _GSettingsPrivate
 {
@@ -152,7 +236,6 @@ struct _GSettingsPrivate
   GSettingsBackend *backend;
   GSettingsSchema *schema;
   gchar *schema_name;
-  gchar *context;
   gchar *path;
 
   GDelayedSettingsBackend *delayed;
@@ -161,9 +244,8 @@ struct _GSettingsPrivate
 enum
 {
   PROP_0,
-  PROP_BACKEND,
   PROP_SCHEMA,
-  PROP_CONTEXT,
+  PROP_BACKEND,
   PROP_PATH,
   PROP_HAS_UNAPPLIED,
 };
@@ -181,6 +263,7 @@ static guint g_settings_signals[N_SIGNALS];
 
 G_DEFINE_TYPE (GSettings, g_settings, G_TYPE_OBJECT)
 
+/* Signals {{{1 */
 static gboolean
 g_settings_real_change_event (GSettings    *settings,
                               const GQuark *keys,
@@ -341,135 +424,7 @@ settings_backend_path_writable_changed (GSettingsBackend *backend,
                    0, (GQuark) 0, &ignore_this);
 }
 
-static void
-g_settings_constructed (GObject *object)
-{
-  GSettings *settings = G_SETTINGS (object);
-  const gchar *schema_path;
-
-  settings->priv->schema = g_settings_schema_new (settings->priv->schema_name);
-  schema_path = g_settings_schema_get_path (settings->priv->schema);
-
-  if (settings->priv->path && schema_path && strcmp (settings->priv->path, schema_path) != 0)
-    g_error ("settings object created with schema '%s' and path '%s', but "
-             "path '%s' is specified by schema",
-             settings->priv->schema_name, settings->priv->path, schema_path);
-
-  if (settings->priv->path == NULL)
-    {
-      if (schema_path == NULL)
-        g_error ("attempting to create schema '%s' without a path",
-                 settings->priv->schema_name);
-
-      settings->priv->path = g_strdup (schema_path);
-    }
-
-  settings->priv->backend = g_settings_backend_get_with_context (settings->priv->context);
-  g_settings_backend_watch (settings->priv->backend, G_OBJECT (settings),
-                            settings->priv->main_context,
-                            settings_backend_changed,
-                            settings_backend_path_changed,
-                            settings_backend_keys_changed,
-                            settings_backend_writable_changed,
-                            settings_backend_path_writable_changed);
-  g_settings_backend_subscribe (settings->priv->backend,
-                                settings->priv->path);
-}
-
-static void
-g_settings_init (GSettings *settings)
-{
-  settings->priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
-                                                G_TYPE_SETTINGS,
-                                                GSettingsPrivate);
-
-  settings->priv->main_context = g_main_context_get_thread_default ();
-
-  if (settings->priv->main_context == NULL)
-    settings->priv->main_context = g_main_context_default ();
-
-  g_main_context_ref (settings->priv->main_context);
-}
-
-/**
- * g_settings_delay:
- * @settings: a #GSettings object
- *
- * Changes the #GSettings object into 'delay-apply' mode. In this
- * mode, changes to @settings are not immediately propagated to the
- * backend, but kept locally until g_settings_apply() is called.
- *
- * Since: 2.26
- */
-void
-g_settings_delay (GSettings *settings)
-{
-  g_return_if_fail (G_IS_SETTINGS (settings));
-
-  if (settings->priv->delayed)
-    return;
-
-  settings->priv->delayed =
-    g_delayed_settings_backend_new (settings->priv->backend,
-                                    settings,
-                                    settings->priv->main_context);
-  g_settings_backend_unwatch (settings->priv->backend, G_OBJECT (settings));
-  g_object_unref (settings->priv->backend);
-
-  settings->priv->backend = G_SETTINGS_BACKEND (settings->priv->delayed);
-  g_settings_backend_watch (settings->priv->backend, G_OBJECT (settings),
-                            settings->priv->main_context,
-                            settings_backend_changed,
-                            settings_backend_path_changed,
-                            settings_backend_keys_changed,
-                            settings_backend_writable_changed,
-                            settings_backend_path_writable_changed);
-}
-
-/**
- * g_settings_apply:
- * @settings: a #GSettings instance
- *
- * Applies any changes that have been made to the settings.  This
- * function does nothing unless @settings is in 'delay-apply' mode;
- * see g_settings_set_delay_apply().  In the normal case settings are
- * always applied immediately.
- **/
-void
-g_settings_apply (GSettings *settings)
-{
-  if (settings->priv->delayed)
-    {
-      GDelayedSettingsBackend *delayed;
-
-      delayed = G_DELAYED_SETTINGS_BACKEND (settings->priv->backend);
-      g_delayed_settings_backend_apply (delayed);
-    }
-}
-
-/**
- * g_settings_revert:
- * @settings: a #GSettings instance
- *
- * Reverts all non-applied changes to the settings.  This function
- * does nothing unless @settings is in 'delay-apply' mode; see
- * g_settings_set_delay_apply().  In the normal case settings are
- * always applied immediately.
- *
- * Change notifications will be emitted for affected keys.
- **/
-void
-g_settings_revert (GSettings *settings)
-{
-  if (settings->priv->delayed)
-    {
-      GDelayedSettingsBackend *delayed;
-
-      delayed = G_DELAYED_SETTINGS_BACKEND (settings->priv->backend);
-      g_delayed_settings_backend_revert (delayed);
-    }
-}
-
+/* Properties, Construction, Destruction {{{1 */
 static void
 g_settings_set_property (GObject      *object,
                          guint         prop_id,
@@ -489,8 +444,8 @@ g_settings_set_property (GObject      *object,
       settings->priv->path = g_value_dup_string (value);
       break;
 
-    case PROP_CONTEXT:
-      settings->priv->context = g_value_dup_string (value);
+    case PROP_BACKEND:
+      settings->priv->backend = g_value_dup_object (value);
       break;
 
     default:
@@ -498,26 +453,6 @@ g_settings_set_property (GObject      *object,
     }
 }
 
-/**
- * g_settings_get_has_unapplied:
- * @settings: a #GSettings object
- * @returns: %TRUE if @settings has unapplied changes
- *
- * Returns whether the #GSettings object has any unapplied
- * changes.  This can only be the case if it is in 'delayed-apply' mode.
- *
- * Since: 2.26
- */
-gboolean
-g_settings_get_has_unapplied (GSettings *settings)
-{
-  g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
-
-  return settings->priv->delayed &&
-         g_delayed_settings_backend_get_has_unapplied (
-           G_DELAYED_SETTINGS_BACKEND (settings->priv->backend));
-}
-
 static void
 g_settings_get_property (GObject    *object,
                          guint       prop_id,
@@ -542,6 +477,43 @@ g_settings_get_property (GObject    *object,
 }
 
 static void
+g_settings_constructed (GObject *object)
+{
+  GSettings *settings = G_SETTINGS (object);
+  const gchar *schema_path;
+
+  settings->priv->schema = g_settings_schema_new (settings->priv->schema_name);
+  schema_path = g_settings_schema_get_path (settings->priv->schema);
+
+  if (settings->priv->path && schema_path && strcmp (settings->priv->path, schema_path) != 0)
+    g_error ("settings object created with schema '%s' and path '%s', but "
+             "path '%s' is specified by schema",
+             settings->priv->schema_name, settings->priv->path, schema_path);
+
+  if (settings->priv->path == NULL)
+    {
+      if (schema_path == NULL)
+        g_error ("attempting to create schema '%s' without a path",
+                 settings->priv->schema_name);
+
+      settings->priv->path = g_strdup (schema_path);
+    }
+
+  if (settings->priv->backend == NULL)
+    settings->priv->backend = g_settings_backend_get_default ();
+
+  g_settings_backend_watch (settings->priv->backend, G_OBJECT (settings),
+                            settings->priv->main_context,
+                            settings_backend_changed,
+                            settings_backend_path_changed,
+                            settings_backend_keys_changed,
+                            settings_backend_writable_changed,
+                            settings_backend_path_writable_changed);
+  g_settings_backend_subscribe (settings->priv->backend,
+                                settings->priv->path);
+}
+
+static void
 g_settings_finalize (GObject *object)
 {
   GSettings *settings = G_SETTINGS (object);
@@ -556,6 +528,21 @@ g_settings_finalize (GObject *object)
 }
 
 static void
+g_settings_init (GSettings *settings)
+{
+  settings->priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
+                                                G_TYPE_SETTINGS,
+                                                GSettingsPrivate);
+
+  settings->priv->main_context = g_main_context_get_thread_default ();
+
+  if (settings->priv->main_context == NULL)
+    settings->priv->main_context = g_main_context_default ();
+
+  g_main_context_ref (settings->priv->main_context);
+}
+
+static void
 g_settings_class_init (GSettingsClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
@@ -680,11 +667,11 @@ g_settings_class_init (GSettingsClass *class)
    *
    * The name of the context that the settings are stored in.
    */
-  g_object_class_install_property (object_class, PROP_CONTEXT,
-    g_param_spec_string ("context",
-                         P_("Context name"),
-                         P_("The name of the context for this settings object"),
-                         "", G_PARAM_CONSTRUCT_ONLY |
+  g_object_class_install_property (object_class, PROP_BACKEND,
+    g_param_spec_object ("backend",
+                         P_("GSettingsBackend"),
+                         P_("The GSettingsBackend for this settings object"),
+                         G_TYPE_SETTINGS_BACKEND, G_PARAM_CONSTRUCT_ONLY |
                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   /**
@@ -729,108 +716,567 @@ g_settings_class_init (GSettingsClass *class)
 
 }
 
+/* Construction (new, new_with_path, etc.) {{{1 */
 /**
- * g_settings_get_value:
- * @settings: a #GSettings object
- * @key: the key to get the value for
- * @returns: a new #GVariant
+ * g_settings_new:
+ * @schema: the name of the schema
+ * @returns: a new #GSettings object
  *
- * Gets the value that is stored in @settings for @key.
+ * Creates a new #GSettings object with a given schema.
  *
- * It is a programmer error to give a @key that isn't valid for
- * @settings.
+ * Signals on the newly created #GSettings object will be dispatched
+ * via the thread-default #GMainContext in effect at the time of the
+ * call to g_settings_new().  The new #GSettings will hold a reference
+ * on the context.  See g_main_context_push_thread_default().
  *
  * Since: 2.26
  */
-GVariant *
-g_settings_get_value (GSettings   *settings,
-                      const gchar *key)
+GSettings *
+g_settings_new (const gchar *schema)
 {
-  const gchar *unparsed = NULL;
-  GVariant *value, *options;
-  const GVariantType *type;
-  gchar lc_char = '\0';
-  GVariant *sval;
-  gchar *path;
-
-  g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
+  g_return_val_if_fail (schema != NULL, NULL);
 
-  sval = g_settings_schema_get_value (settings->priv->schema, key, &options);
-
-  if G_UNLIKELY (sval == NULL)
-    g_error ("schema '%s' does not contain a key named '%s'",
-             settings->priv->schema_name, key);
+  return g_object_new (G_TYPE_SETTINGS,
+                       "schema", schema,
+                       NULL);
+}
 
-  path = g_strconcat (settings->priv->path, key, NULL);
-  type = g_variant_get_type (sval);
-  value = g_settings_backend_read (settings->priv->backend, path, type, FALSE);
-  g_free (path);
+/**
+ * g_settings_new_with_path:
+ * @schema: the name of the schema
+ * @path: the path to use
+ * @returns: a new #GSettings object
+ *
+ * Creates a new #GSettings object with a given schema and path.
+ *
+ * You only need to do this if you want to directly create a settings
+ * object with a schema that doesn't have a specified path of its own.
+ * That's quite rare.
+ *
+ * It is a programmer error to call this function for a schema that
+ * has an explicitly specified path.
+ *
+ * Since: 2.26
+ */
+GSettings *
+g_settings_new_with_path (const gchar *schema,
+                          const gchar *path)
+{
+  g_return_val_if_fail (schema != NULL, NULL);
+  g_return_val_if_fail (path != NULL, NULL);
 
-  if (options != NULL)
-    {
-      GVariantIter iter;
-      const gchar *option;
-      GVariant *option_value;
+  return g_object_new (G_TYPE_SETTINGS,
+                       "schema", schema,
+                       "path", path,
+                       NULL);
+}
+
+/**
+ * g_settings_new_with_backend:
+ * @schema: the name of the schema
+ * @backend: the #GSettingsBackend to use
+ * @returns: a new #GSettings object
+ *
+ * Creates a new #GSettings object with a given schema and backend.
+ *
+ * Creating settings objects with an different backend allows accessing settings
+ * from a database other than the usual one.  For example, it may make
+ * sense to pass a backend corresponding to the "defaults" settings database on
+ * the system to get a settings object that modifies the system default
+ * settings instead of the settings for this user.
+ *
+ * Since: 2.26
+ */
+GSettings *
+g_settings_new_with_backend (const gchar      *schema,
+                             GSettingsBackend *backend)
+{
+  g_return_val_if_fail (schema != NULL, NULL);
+  g_return_val_if_fail (G_IS_SETTINGS_BACKEND (backend), NULL);
+
+  return g_object_new (G_TYPE_SETTINGS,
+                       "schema", schema,
+                       "backend", backend,
+                       NULL);
+}
+
+/**
+ * g_settings_new_with_backend_and_path:
+ * @schema: the name of the schema
+ * @backend: the #GSettingsBackend to use
+ * @path: the path to use
+ * @returns: a new #GSettings object
+ *
+ * Creates a new #GSettings object with a given schema, backend and
+ * path.
+ *
+ * This is a mix of g_settings_new_with_backend() and
+ * g_settings_new_with_path().
+ *
+ * Since: 2.26
+ */
+GSettings *
+g_settings_new_with_backend_and_path (const gchar      *schema,
+                                      GSettingsBackend *backend,
+                                      const gchar      *path)
+{
+  g_return_val_if_fail (schema != NULL, NULL);
+  g_return_val_if_fail (G_IS_SETTINGS_BACKEND (backend), NULL);
+  g_return_val_if_fail (path != NULL, NULL);
+
+  return g_object_new (G_TYPE_SETTINGS,
+                       "schema", schema,
+                       "backend", backend,
+                       "path", path,
+                       NULL);
+}
+
+/* Internal read/write utilities, enum conversion, validation {{{1 */
+typedef struct
+{
+  GSettings *settings;
+  const gchar *key;
 
-      g_variant_iter_init (&iter, options);
-      while (g_variant_iter_loop (&iter, "{&sv}", &option, &option_value))
+  GSettingsSchema *schema;
+
+  gboolean is_enum;
+  const guint32 *strinfo;
+  gsize strinfo_length;
+
+  const gchar *unparsed;
+  gchar lc_char;
+
+  const GVariantType *type;
+  GVariant *minimum, *maximum;
+  GVariant *default_value;
+} GSettingsKeyInfo;
+
+static void
+g_settings_get_key_info (GSettingsKeyInfo *info,
+                         GSettings        *settings,
+                         const gchar      *key)
+{
+  GVariantIter *iter;
+  GVariant *data;
+  guchar code;
+
+  memset (info, 0, sizeof *info);
+
+  iter = g_settings_schema_get_value (settings->priv->schema, key);
+
+  info->default_value = g_variant_iter_next_value (iter);
+  info->type = g_variant_get_type (info->default_value);
+  info->settings = g_object_ref (settings);
+  info->key = g_intern_string (key);
+
+  while (g_variant_iter_next (iter, "(y*)", &code, &data))
+    {
+      switch (code)
         {
-          if (strcmp (option, "l10n") == 0)
-            g_variant_get (option_value, "(y&s)", &lc_char, &unparsed);
-          else
-            g_warning ("unknown schema extension '%s'", option);
+        case 'l':
+          /* translation requested */
+          g_variant_get (data, "(y&s)", &info->lc_char, &info->unparsed);
+          break;
+
+        case 'e':
+          /* enumerated types, ... */
+          info->is_enum = TRUE;
+        case 'c':
+          /* ..., choices, aliases */
+          info->strinfo = g_variant_get_fixed_array (data,
+                                                     &info->strinfo_length,
+                                                     sizeof (guint32));
+          break;
+
+        case 'r':
+          g_variant_get (data, "(**)", &info->minimum, &info->maximum);
+          break;
+
+        default:
+          g_warning ("unknown schema extension '%c'", code);
+          break;
         }
+
+      g_variant_unref (data);
     }
 
-  if (value && !g_variant_is_of_type (value, type))
+  g_variant_iter_free (iter);
+}
+
+static void
+g_settings_free_key_info (GSettingsKeyInfo *info)
+{
+  if (info->minimum)
+    g_variant_unref (info->minimum);
+
+  if (info->maximum)
+    g_variant_unref (info->maximum);
+
+  g_variant_unref (info->default_value);
+  g_object_unref (info->settings);
+}
+
+static gboolean
+g_settings_write_to_backend (GSettingsKeyInfo *info,
+                             GVariant         *value)
+{
+  gboolean success;
+  gchar *path;
+
+  path = g_strconcat (info->settings->priv->path, info->key, NULL);
+  success = g_settings_backend_write (info->settings->priv->backend,
+                                      path, value, NULL);
+  g_free (path);
+
+  return success;
+}
+
+static gboolean
+g_settings_type_check (GSettingsKeyInfo *info,
+                       GVariant         *value)
+{
+  g_return_val_if_fail (value != NULL, FALSE);
+
+  return g_variant_is_of_type (value, info->type);
+}
+
+static gboolean
+g_settings_range_check (GSettingsKeyInfo *info,
+                        GVariant         *value)
+{
+  if (info->minimum == NULL && info->strinfo == NULL)
+    return TRUE;
+
+  if (g_variant_is_container (value))
     {
-      g_variant_unref (value);
-      value = NULL;
+      gboolean ok = TRUE;
+      GVariantIter iter;
+      GVariant *child;
+
+      g_variant_iter_init (&iter, value);
+      while (ok && (child = g_variant_iter_next_value (&iter)))
+        {
+          ok = g_settings_range_check (info, value);
+          g_variant_unref (child);
+        }
+
+      return ok;
     }
 
-  if (value == NULL && lc_char != '\0')
-  /* we will need to translate the schema default value */
+  if (info->minimum)
     {
-      const gchar *translated;
-      GError *error = NULL;
-      const gchar *domain;
+      return g_variant_compare (info->minimum, value) <= 0 &&
+             g_variant_compare (value, info->maximum) <= 0;
+    }
+
+  return strinfo_is_string_valid (info->strinfo,
+                                  info->strinfo_length,
+                                  g_variant_get_string (value, NULL));
+}
 
-      domain = g_settings_schema_get_gettext_domain (settings->priv->schema);
+static GVariant *
+g_settings_range_fixup (GSettingsKeyInfo *info,
+                        GVariant         *value)
+{
+  const gchar *target;
+
+  if (g_settings_range_check (info, value))
+    return g_variant_ref (value);
+
+  if (info->strinfo == NULL)
+    return NULL;
+
+  if (g_variant_is_container (value))
+    {
+      GVariantBuilder builder;
+      GVariantIter iter;
+      GVariant *child;
 
-      if (lc_char == 't')
-        translated = g_dcgettext (domain, unparsed, LC_TIME);
-      else
-        translated = g_dgettext (domain, unparsed);
+      g_variant_builder_init (&builder, g_variant_get_type (value));
 
-      if (translated != unparsed)
-        /* it was translated, so we need to re-parse it */
+      while ((child = g_variant_iter_next_value (&iter)))
         {
-          value = g_variant_parse (g_variant_get_type (sval),
-                                   translated, NULL, NULL, &error);
+          GVariant *fixed;
 
-          if (value == NULL)
+          fixed = g_settings_range_fixup (info, child);
+          g_variant_unref (child);
+
+          if (fixed == NULL)
             {
-              g_warning ("Failed to parse translated string `%s' for "
-                         "key `%s' in schema `%s': %s", unparsed, key,
-                         settings->priv->schema_name, error->message);
-              g_warning ("Using untranslated default instead.");
-              g_error_free (error);
+              g_variant_builder_clear (&builder);
+              return NULL;
             }
+
+          g_variant_builder_add_value (&builder, fixed);
+          g_variant_unref (fixed);
         }
+
+      return g_variant_ref_sink (g_variant_builder_end (&builder));
+    }
+
+  target = strinfo_string_from_alias (info->strinfo, info->strinfo_length,
+                                      g_variant_get_string (value, NULL));
+  return target ? g_variant_ref_sink (g_variant_new_string (target)) : NULL;
+}
+
+static GVariant *
+g_settings_read_from_backend (GSettingsKeyInfo *info)
+{
+  GVariant *value;
+  GVariant *fixup;
+  gchar *path;
+
+  path = g_strconcat (info->settings->priv->path, info->key, NULL);
+  value = g_settings_backend_read (info->settings->priv->backend,
+                                   path, info->type, FALSE);
+  g_free (path);
+
+  if (value != NULL)
+    {
+      fixup = g_settings_range_fixup (info, value);
+      g_variant_unref (value);
+    }
+  else
+    fixup = NULL;
+
+  return fixup;
+}
+
+static GVariant *
+g_settings_get_translated_default (GSettingsKeyInfo *info)
+{
+  const gchar *translated;
+  GError *error = NULL;
+  const gchar *domain;
+  GVariant *value;
+
+  if (info->lc_char == '\0')
+    /* translation not requested for this key */
+    return NULL;
+
+  domain = g_settings_schema_get_gettext_domain (info->settings->priv->schema);
+
+  if (info->lc_char == 't')
+    translated = g_dcgettext (domain, info->unparsed, LC_TIME);
+  else
+    translated = g_dgettext (domain, info->unparsed);
+
+  if (translated == info->unparsed)
+    /* the default value was not translated */
+    return NULL;
+
+  /* try to parse the translation of the unparsed default */
+  value = g_variant_parse (info->type, translated, NULL, NULL, &error);
+
+  if (value == NULL)
+    {
+      g_warning ("Failed to parse translated string `%s' for "
+                 "key `%s' in schema `%s': %s", info->unparsed, info->key,
+                 info->settings->priv->schema_name, error->message);
+      g_warning ("Using untranslated default instead.");
+      g_error_free (error);
+    }
+
+  else if (!g_settings_range_check (info, value))
+    {
+      g_warning ("Translated default `%s' for key `%s' in schema `%s' "
+                 "is outside of valid range", info->unparsed, info->key,
+                 info->settings->priv->schema_name);
+      g_variant_unref (value);
+      value = NULL;
     }
 
+  return value;
+}
+
+static gint
+g_settings_to_enum (GSettingsKeyInfo *info,
+                    GVariant         *value)
+{
+  gboolean it_worked;
+  guint result;
+
+  it_worked = strinfo_enum_from_string (info->strinfo, info->strinfo_length,
+                                        g_variant_get_string (value, NULL),
+                                        &result);
+
+  /* 'value' can only come from the backend after being filtered for validity,
+   * from the translation after being filtered for validity, or from the schema
+   * itself (which the schema compiler checks for validity).  If this assertion
+   * fails then it's really a bug in GSettings or the schema compiler...
+   */
+  g_assert (it_worked);
+
+  return result;
+}
+
+static GVariant *
+g_settings_from_enum (GSettingsKeyInfo *info,
+                      gint              value)
+{
+  const gchar *string;
+
+  string = strinfo_string_from_enum (info->strinfo,
+                                     info->strinfo_length,
+                                     value);
+
+  if (string == NULL)
+    return NULL;
+
+  return g_variant_ref_sink (g_variant_new_string (string));
+}
+
+/* Public Get/Set API {{{1 (get, get_value, set, set_value) */
+/**
+ * g_settings_get_value:
+ * @settings: a #GSettings object
+ * @key: the key to get the value for
+ * @returns: a new #GVariant
+ *
+ * Gets the value that is stored in @settings for @key.
+ *
+ * It is a programmer error to give a @key that isn't contained in the
+ * schema for @settings.
+ *
+ * Since: 2.26
+ */
+GVariant *
+g_settings_get_value (GSettings   *settings,
+                      const gchar *key)
+{
+  GSettingsKeyInfo info;
+  GVariant *value;
+
+  g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
+  g_return_val_if_fail (key != NULL, NULL);
+
+  g_settings_get_key_info (&info, settings, key);
+  value = g_settings_read_from_backend (&info);
+
+  if (value == NULL)
+    value = g_settings_get_translated_default (&info);
+
   if (value == NULL)
-    /* either translation failed or there was none to do.
-     * use the pre-compiled default.
-     */
-    value = g_variant_ref (sval);
+    value = g_variant_ref (info.default_value);
 
-  g_variant_unref (sval);
+  g_settings_free_key_info (&info);
 
   return value;
 }
 
 /**
+ * g_settings_get_enum:
+ * @settings: a #GSettings object
+ * @key: the key to get the value for
+ * @returns: the enum value
+ *
+ * Gets the value that is stored in @settings for @key and converts it
+ * to the enum value that it represents.
+ *
+ * In order to use this function the type of the value must be a string
+ * and it must be marked in the schema file as an enumerated type.
+ *
+ * It is a programmer error to give a @key that isn't contained in the
+ * schema for @settings or is not marked as an enumerated type.
+ *
+ * If the value stored in the configuration database is not a valid
+ * value for the enumerated type then this function will return the
+ * default value.
+ *
+ * Since: 2.26
+ **/
+gint
+g_settings_get_enum (GSettings   *settings,
+                     const gchar *key)
+{
+  GSettingsKeyInfo info;
+  GVariant *value;
+  gint result;
+
+  g_return_val_if_fail (G_IS_SETTINGS (settings), -1);
+  g_return_val_if_fail (key != NULL, -1);
+
+  g_settings_get_key_info (&info, settings, key);
+
+  if (!info.is_enum)
+    {
+      g_critical ("g_settings_get_enum() called on key `%s' which is not "
+                  "associated with an enumerated type", info.key);
+      g_settings_free_key_info (&info);
+      return -1;
+    }
+
+  value = g_settings_read_from_backend (&info);
+
+  if (value == NULL)
+    value = g_settings_get_translated_default (&info);
+
+  if (value == NULL)
+    value = g_variant_ref (info.default_value);
+
+  result = g_settings_to_enum (&info, value);
+  g_settings_free_key_info (&info);
+  g_variant_unref (value);
+
+  return result;
+}
+
+/**
+ * g_settings_set_enum:
+ * @settings: a #GSettings object
+ * @key: a key, within @settings
+ * @value: an enumerated value
+ * @returns: %TRUE, if the set succeeds
+ *
+ * Looks up the enumerated type nick for @value and writes it to @key,
+ * within @settings.
+ *
+ * It is a programmer error to give a @key that isn't contained in the
+ * schema for @settings or is not marked as an enumerated type, or for
+ * @value not to be a valid value for the named type.
+ *
+ * After performing the write, accessing @key directly
+ * g_settings_get_string() will return the 'nick' associated with
+ * @value.
+ **/
+gboolean
+g_settings_set_enum (GSettings   *settings,
+                     const gchar *key,
+                     gint         value)
+{
+  GSettingsKeyInfo info;
+  GVariant *variant;
+  gboolean success;
+
+  g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
+  g_return_val_if_fail (key != NULL, FALSE);
+
+  g_settings_get_key_info (&info, settings, key);
+
+  if (!info.is_enum)
+    {
+      g_critical ("g_settings_set_enum() called on key `%s' which is not "
+                  "associated with an enumerated type", info.key);
+      return FALSE;
+    }
+
+  if (!(variant = g_settings_from_enum (&info, value)))
+    {
+      g_critical ("g_settings_set_enum(): invalid enum value %d for key `%s' "
+                  "in schema `%s'.  Doing nothing.", value, info.key,
+                  info.settings->priv->schema_name);
+      g_settings_free_key_info (&info);
+      return FALSE;
+    }
+
+  success = g_settings_write_to_backend (&info, variant);
+  g_settings_free_key_info (&info);
+  g_variant_unref (variant);
+
+  return success;
+}
+
+/**
  * g_settings_set_value:
  * @settings: a #GSettings object
  * @key: the name of the key to set
@@ -840,9 +1286,9 @@ g_settings_get_value (GSettings   *settings,
  *
  * Sets @key in @settings to @value.
  *
- * It is a programmer error to give a @key that isn't valid for
- * @settings.  It is a programmer error to give a @value of the
- * incorrect type.
+ * It is a programmer error to give a @key that isn't contained in the
+ * schema for @settings or for @value to have the incorrect type, per
+ * the schema.
  *
  * If @value is floating then this function consumes the reference.
  *
@@ -853,25 +1299,17 @@ g_settings_set_value (GSettings   *settings,
                       const gchar *key,
                       GVariant    *value)
 {
-  gboolean correct_type;
-  gboolean result;
-  GVariant *sval;
-  gchar *path;
+  GSettingsKeyInfo info;
 
   g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
+  g_return_val_if_fail (key != NULL, FALSE);
 
-  sval = g_settings_schema_get_value (settings->priv->schema, key, NULL);
-  correct_type = g_variant_is_of_type (value, g_variant_get_type (sval));
-  g_variant_unref (sval);
+  g_settings_get_key_info (&info, settings, key);
+  g_return_val_if_fail (g_settings_type_check (&info, value), FALSE);
+  g_return_val_if_fail (g_settings_range_check (&info, value), FALSE);
+  g_settings_free_key_info (&info);
 
-  g_return_val_if_fail (correct_type, FALSE);
-
-  path = g_strconcat (settings->priv->path, key, NULL);
-  result = g_settings_backend_write (settings->priv->backend,
-                                     path, value, NULL);
-  g_free (path);
-
-  return result;
+  return g_settings_write_to_backend (&info, value);
 }
 
 /**
@@ -886,9 +1324,9 @@ g_settings_set_value (GSettings   *settings,
  * A convenience function that combines g_settings_get_value() with
  * g_variant_get().
  *
- * It is a programmer error to pass a @key that isn't valid for
- * @settings or a @format_string that doesn't match the type of @key according
- * to the schema of @settings.
+ * It is a programmer error to give a @key that isn't contained in the
+ * schema for @settings or for the #GVariantType of @format to mismatch
+ * the type given in the schema.
  *
  * Since: 2.26
  */
@@ -924,9 +1362,9 @@ g_settings_get (GSettings   *settings,
  * A convenience function that combines g_settings_set_value() with
  * g_variant_new().
  *
- * It is a programmer error to pass a @key that isn't valid for
- * @settings or a @format that doesn't match the type of @key according
- * to the schema of @settings.
+ * It is a programmer error to give a @key that isn't contained in the
+ * schema for @settings or for the #GVariantType of @format to mismatch
+ * the type given in the schema.
  *
  * Since: 2.26
  */
@@ -946,215 +1384,542 @@ g_settings_set (GSettings   *settings,
   return g_settings_set_value (settings, key, value);
 }
 
+/* Convenience API (get, set_string, int, double, boolean, strv) {{{1 */
 /**
- * g_settings_is_writable:
+ * g_settings_get_string:
  * @settings: a #GSettings object
- * @name: the name of a key
- * @returns: %TRUE if the key @name is writable
+ * @key: the key to get the value for
+ * @returns: a newly-allocated string
  *
- * Finds out if a key can be written or not
+ * Gets the value that is stored at @key in @settings.
+ *
+ * A convenience variant of g_settings_get() for strings.
+ *
+ * It is a programmer error to give a @key that isn't specified as
+ * having a string type in the schema for @settings.
  *
  * Since: 2.26
  */
-gboolean
-g_settings_is_writable (GSettings   *settings,
-                        const gchar *name)
+gchar *
+g_settings_get_string (GSettings   *settings,
+                       const gchar *key)
 {
-  gboolean writable;
-  gchar *path;
-
-  g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
+  GVariant *value;
+  gchar *result;
 
-  path = g_strconcat (settings->priv->path, name, NULL);
-  writable = g_settings_backend_get_writable (settings->priv->backend, path);
-  g_free (path);
+  value = g_settings_get_value (settings, key);
+  result = g_variant_dup_string (value, NULL);
+  g_variant_unref (value);
 
-  return writable;
+  return result;
 }
 
 /**
- * g_settings_get_child:
+ * g_settings_set_string:
  * @settings: a #GSettings object
- * @name: the name of the 'child' schema
- * @returns: a 'child' settings object
+ * @key: the name of the key to set
+ * @value: the value to set it to
+ * @returns: %TRUE if setting the key succeeded,
+ *     %FALSE if the key was not writable
  *
- * Creates a 'child' settings object which has a base path of
- * <replaceable>base-path</replaceable>/@name", where
- * <replaceable>base-path</replaceable> is the base path of @settings.
+ * Sets @key in @settings to @value.
  *
- * The schema for the child settings object must have been declared
- * in the schema of @settings using a <tag class="starttag">child</tag> element.
+ * A convenience variant of g_settings_set() for strings.
+ *
+ * It is a programmer error to give a @key that isn't specified as
+ * having a string type in the schema for @settings.
  *
  * Since: 2.26
  */
-GSettings *
-g_settings_get_child (GSettings   *settings,
-                      const gchar *name)
+gboolean
+g_settings_set_string (GSettings   *settings,
+                       const gchar *key,
+                       const gchar *value)
 {
-  const gchar *child_schema;
-  gchar *child_path;
-  gchar *child_name;
-  GSettings *child;
-
-  g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
-
-  child_name = g_strconcat (name, "/", NULL);
-  child_schema = g_settings_schema_get_string (settings->priv->schema,
-                                               child_name);
-  if (child_schema == NULL)
-    g_error ("Schema '%s' has no child '%s'",
-             settings->priv->schema_name, name);
-
-  child_path = g_strconcat (settings->priv->path, child_name, NULL);
-  child = g_object_new (G_TYPE_SETTINGS,
-                        "schema", child_schema,
-                        "path", child_path,
-                        NULL);
-  g_free (child_path);
-  g_free (child_name);
-
-  return child;
+  return g_settings_set_value (settings, key, g_variant_new_string (value));
 }
 
 /**
- * g_settings_new:
- * @schema: the name of the schema
- * @returns: a new #GSettings object
+ * g_settings_get_int:
+ * @settings: a #GSettings object
+ * @key: the key to get the value for
+ * @returns: an integer
  *
- * Creates a new #GSettings object with a given schema.
+ * Gets the value that is stored at @key in @settings.
  *
- * Signals on the newly created #GSettings object will be dispatched
- * via the thread-default #GMainContext in effect at the time of the
- * call to g_settings_new().  The new #GSettings will hold a reference
- * on the context.  See g_main_context_push_thread_default().
+ * A convenience variant of g_settings_get() for 32-bit integers.
+ *
+ * It is a programmer error to give a @key that isn't specified as
+ * having a int32 type in the schema for @settings.
  *
  * Since: 2.26
  */
-GSettings *
-g_settings_new (const gchar *schema)
+gint
+g_settings_get_int (GSettings   *settings,
+                    const gchar *key)
 {
-  return g_object_new (G_TYPE_SETTINGS,
-                       "schema", schema,
-                       NULL);
+  GVariant *value;
+  gint result;
+
+  value = g_settings_get_value (settings, key);
+  result = g_variant_get_int32 (value);
+  g_variant_unref (value);
+
+  return result;
 }
 
 /**
- * g_settings_new_with_path:
- * @schema: the name of the schema
- * @path: the path to use
- * @returns: a new #GSettings object
+ * g_settings_set_int:
+ * @settings: a #GSettings object
+ * @key: the name of the key to set
+ * @value: the value to set it to
+ * @returns: %TRUE if setting the key succeeded,
+ *     %FALSE if the key was not writable
  *
- * Creates a new #GSettings object with a given schema and path.
+ * Sets @key in @settings to @value.
  *
- * You only need to do this if you want to directly create a settings
- * object with a schema that doesn't have a specified path of its own.
- * That's quite rare.
+ * A convenience variant of g_settings_set() for 32-bit integers.
  *
- * It is a programmer error to call this function for a schema that
- * has an explicitly specified path.
+ * It is a programmer error to give a @key that isn't specified as
+ * having a int32 type in the schema for @settings.
  *
  * Since: 2.26
  */
-GSettings *
-g_settings_new_with_path (const gchar *schema,
-                          const gchar *path)
+gboolean
+g_settings_set_int (GSettings   *settings,
+                    const gchar *key,
+                    gint         value)
 {
-  return g_object_new (G_TYPE_SETTINGS,
-                       "schema", schema,
-                       "path", path,
-                       NULL);
+  return g_settings_set_value (settings, key, g_variant_new_int32 (value));
 }
 
 /**
- * g_settings_new_with_context:
- * @schema: the name of the schema
- * @context: the context to use
- * @returns: a new #GSettings object
+ * g_settings_get_double:
+ * @settings: a #GSettings object
+ * @key: the key to get the value for
+ * @returns: a double
  *
- * Creates a new #GSettings object with a given schema and context.
+ * Gets the value that is stored at @key in @settings.
  *
- * Creating settings objects with a context allow accessing settings
- * 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
- * modifies the system default settings instead of the settings for this
- * user.
+ * A convenience variant of g_settings_get() for doubles.
  *
- * 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.
+ * It is a programmer error to give a @key that isn't specified as
+ * having a 'double' type in the schema for @settings.
  *
  * Since: 2.26
  */
-GSettings *
-g_settings_new_with_context (const gchar *schema,
-                             const gchar *context)
+gdouble
+g_settings_get_double (GSettings   *settings,
+                       const gchar *key)
 {
-  return g_object_new (G_TYPE_SETTINGS,
-                       "schema", schema,
-                       "context", context,
-                       NULL);
+  GVariant *value;
+  gdouble result;
+
+  value = g_settings_get_value (settings, key);
+  result = g_variant_get_double (value);
+  g_variant_unref (value);
+
+  return result;
 }
 
 /**
- * g_settings_new_with_context_and_path:
- * @schema: the name of the schema
- * @path: the path to use
- * @returns: a new #GSettings object
+ * g_settings_set_double:
+ * @settings: a #GSettings object
+ * @key: the name of the key to set
+ * @value: the value to set it to
+ * @returns: %TRUE if setting the key succeeded,
+ *     %FALSE if the key was not writable
  *
- * Creates a new #GSettings object with a given schema, context and
- * path.
+ * Sets @key in @settings to @value.
  *
- * This is a mix of g_settings_new_with_context() and
- * g_settings_new_with_path().
+ * A convenience variant of g_settings_set() for doubles.
+ *
+ * It is a programmer error to give a @key that isn't specified as
+ * having a 'double' type in the schema for @settings.
  *
  * Since: 2.26
  */
-GSettings *
-g_settings_new_with_context_and_path (const gchar *schema,
-                                      const gchar *context,
-                                      const gchar *path)
+gboolean
+g_settings_set_double (GSettings   *settings,
+                       const gchar *key,
+                       gdouble      value)
 {
-  return g_object_new (G_TYPE_SETTINGS,
-                       "schema", schema,
-                        "context", context,
-                        "path", path,
-                        NULL);
+  return g_settings_set_value (settings, key, g_variant_new_double (value));
 }
 
-typedef struct
+/**
+ * g_settings_get_boolean:
+ * @settings: a #GSettings object
+ * @key: the key to get the value for
+ * @returns: a boolean
+ *
+ * Gets the value that is stored at @key in @settings.
+ *
+ * A convenience variant of g_settings_get() for booleans.
+ *
+ * It is a programmer error to give a @key that isn't specified as
+ * having a boolean type in the schema for @settings.
+ *
+ * Since: 2.26
+ */
+gboolean
+g_settings_get_boolean (GSettings  *settings,
+                       const gchar *key)
 {
-  GSettings *settings;
-  GObject *object;
+  GVariant *value;
+  gboolean result;
 
-  GSettingsBindGetMapping get_mapping;
-  GSettingsBindSetMapping set_mapping;
-  gpointer user_data;
-  GDestroyNotify destroy;
+  value = g_settings_get_value (settings, key);
+  result = g_variant_get_boolean (value);
+  g_variant_unref (value);
 
-  guint writable_handler_id;
-  guint property_handler_id;
-  const GParamSpec *property;
-  guint key_handler_id;
-  GVariantType *type;
-  const gchar *key;
+  return result;
+}
 
-  /* prevent recursion */
-  gboolean running;
-} GSettingsBinding;
+/**
+ * g_settings_set_boolean:
+ * @settings: a #GSettings object
+ * @key: the name of the key to set
+ * @value: the value to set it to
+ * @returns: %TRUE if setting the key succeeded,
+ *     %FALSE if the key was not writable
+ *
+ * Sets @key in @settings to @value.
+ *
+ * A convenience variant of g_settings_set() for booleans.
+ *
+ * It is a programmer error to give a @key that isn't specified as
+ * having a boolean type in the schema for @settings.
+ *
+ * Since: 2.26
+ */
+gboolean
+g_settings_set_boolean (GSettings  *settings,
+                       const gchar *key,
+                       gboolean     value)
+{
+  return g_settings_set_value (settings, key, g_variant_new_boolean (value));
+}
 
-static void
-g_settings_binding_free (gpointer data)
+/**
+ * g_settings_get_strv:
+ * @settings: a #GSettings object
+ * @key: the key to get the value for
+ * @returns: a newly-allocated, %NULL-terminated array of strings
+ *
+ * Gets the value that is stored at @key in @settings.
+ *
+ * A convenience variant of g_settings_get() for string arrays.
+ *
+ * It is a programmer error to give a @key that isn't specified as
+ * having an array of strings type in the schema for @settings.
+ *
+ * Since: 2.26
+ */
+gchar **
+g_settings_get_strv (GSettings   *settings,
+                     const gchar *key)
 {
-  GSettingsBinding *binding = data;
+  GVariant *value;
+  gchar **result;
 
-  g_assert (!binding->running);
+  value = g_settings_get_value (settings, key);
+  result = g_variant_dup_strv (value, NULL);
+  g_variant_unref (value);
 
-  if (binding->writable_handler_id)
-    g_signal_handler_disconnect (binding->settings,
-                                 binding->writable_handler_id);
+  return result;
+}
 
-  if (binding->key_handler_id)
-    g_signal_handler_disconnect (binding->settings,
+/**
+ * g_settings_set_strv:
+ * @settings: a #GSettings object
+ * @key: the name of the key to set
+ * @value: (allow-none): the value to set it to, or %NULL
+ * @returns: %TRUE if setting the key succeeded,
+ *     %FALSE if the key was not writable
+ *
+ * Sets @key in @settings to @value.
+ *
+ * A convenience variant of g_settings_set() for string arrays.  If
+ * @value is %NULL, then @key is set to be the empty array.
+ *
+ * It is a programmer error to give a @key that isn't specified as
+ * having an array of strings type in the schema for @settings.
+ *
+ * Since: 2.26
+ */
+gboolean
+g_settings_set_strv (GSettings           *settings,
+                     const gchar         *key,
+                     const gchar * const *value)
+{
+  GVariant *array;
+
+  if (value != NULL)
+    array = g_variant_new_strv (value, -1);
+  else
+    array = g_variant_new_strv (NULL, 0);
+
+  return g_settings_set_value (settings, key, array);
+}
+
+/* Delayed apply (delay, apply, revert, get_has_unapplied) {{{1 */
+/**
+ * g_settings_delay:
+ * @settings: a #GSettings object
+ *
+ * Changes the #GSettings object into 'delay-apply' mode. In this
+ * mode, changes to @settings are not immediately propagated to the
+ * backend, but kept locally until g_settings_apply() is called.
+ *
+ * Since: 2.26
+ */
+void
+g_settings_delay (GSettings *settings)
+{
+  g_return_if_fail (G_IS_SETTINGS (settings));
+
+  if (settings->priv->delayed)
+    return;
+
+  settings->priv->delayed =
+    g_delayed_settings_backend_new (settings->priv->backend,
+                                    settings,
+                                    settings->priv->main_context);
+  g_settings_backend_unwatch (settings->priv->backend, G_OBJECT (settings));
+  g_object_unref (settings->priv->backend);
+
+  settings->priv->backend = G_SETTINGS_BACKEND (settings->priv->delayed);
+  g_settings_backend_watch (settings->priv->backend, G_OBJECT (settings),
+                            settings->priv->main_context,
+                            settings_backend_changed,
+                            settings_backend_path_changed,
+                            settings_backend_keys_changed,
+                            settings_backend_writable_changed,
+                            settings_backend_path_writable_changed);
+}
+
+/**
+ * g_settings_apply:
+ * @settings: a #GSettings instance
+ *
+ * Applies any changes that have been made to the settings.  This
+ * function does nothing unless @settings is in 'delay-apply' mode;
+ * see g_settings_set_delay_apply().  In the normal case settings are
+ * always applied immediately.
+ **/
+void
+g_settings_apply (GSettings *settings)
+{
+  if (settings->priv->delayed)
+    {
+      GDelayedSettingsBackend *delayed;
+
+      delayed = G_DELAYED_SETTINGS_BACKEND (settings->priv->backend);
+      g_delayed_settings_backend_apply (delayed);
+    }
+}
+
+/**
+ * g_settings_revert:
+ * @settings: a #GSettings instance
+ *
+ * Reverts all non-applied changes to the settings.  This function
+ * does nothing unless @settings is in 'delay-apply' mode; see
+ * g_settings_set_delay_apply().  In the normal case settings are
+ * always applied immediately.
+ *
+ * Change notifications will be emitted for affected keys.
+ **/
+void
+g_settings_revert (GSettings *settings)
+{
+  if (settings->priv->delayed)
+    {
+      GDelayedSettingsBackend *delayed;
+
+      delayed = G_DELAYED_SETTINGS_BACKEND (settings->priv->backend);
+      g_delayed_settings_backend_revert (delayed);
+    }
+}
+
+/**
+ * g_settings_get_has_unapplied:
+ * @settings: a #GSettings object
+ * @returns: %TRUE if @settings has unapplied changes
+ *
+ * Returns whether the #GSettings object has any unapplied
+ * changes.  This can only be the case if it is in 'delayed-apply' mode.
+ *
+ * Since: 2.26
+ */
+gboolean
+g_settings_get_has_unapplied (GSettings *settings)
+{
+  g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
+
+  return settings->priv->delayed &&
+         g_delayed_settings_backend_get_has_unapplied (
+           G_DELAYED_SETTINGS_BACKEND (settings->priv->backend));
+}
+
+/* Extra API (sync, get_child, is_writable, list_keys) {{{1 */
+/**
+ * g_settings_sync:
+ * @context: the context to sync, or %NULL
+ *
+ * Ensures that all pending operations for the given context are
+ * complete.
+ *
+ * Writes made to a #GSettings are handled asynchronously.  For this
+ * reason, it is very unlikely that the changes have it to disk by the
+ * time g_settings_set() returns.
+ *
+ * This call will block until all of the writes have made it to the
+ * backend.  Since the mainloop is not running, no change notifications
+ * will be dispatched during this call (but some may be queued by the
+ * time the call is done).
+ **/
+void
+g_settings_sync (void)
+{
+  g_settings_backend_sync_default ();
+}
+
+/**
+ * g_settings_is_writable:
+ * @settings: a #GSettings object
+ * @name: the name of a key
+ * @returns: %TRUE if the key @name is writable
+ *
+ * Finds out if a key can be written or not
+ *
+ * Since: 2.26
+ */
+gboolean
+g_settings_is_writable (GSettings   *settings,
+                        const gchar *name)
+{
+  gboolean writable;
+  gchar *path;
+
+  g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
+
+  path = g_strconcat (settings->priv->path, name, NULL);
+  writable = g_settings_backend_get_writable (settings->priv->backend, path);
+  g_free (path);
+
+  return writable;
+}
+
+/**
+ * g_settings_get_child:
+ * @settings: a #GSettings object
+ * @name: the name of the 'child' schema
+ * @returns: a 'child' settings object
+ *
+ * Creates a 'child' settings object which has a base path of
+ * <replaceable>base-path</replaceable>/@name", where
+ * <replaceable>base-path</replaceable> is the base path of @settings.
+ *
+ * The schema for the child settings object must have been declared
+ * in the schema of @settings using a <tag class="starttag">child</tag> element.
+ *
+ * Since: 2.26
+ */
+GSettings *
+g_settings_get_child (GSettings   *settings,
+                      const gchar *name)
+{
+  const gchar *child_schema;
+  gchar *child_path;
+  gchar *child_name;
+  GSettings *child;
+
+  g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
+
+  child_name = g_strconcat (name, "/", NULL);
+  child_schema = g_settings_schema_get_string (settings->priv->schema,
+                                               child_name);
+  if (child_schema == NULL)
+    g_error ("Schema '%s' has no child '%s'",
+             settings->priv->schema_name, name);
+
+  child_path = g_strconcat (settings->priv->path, child_name, NULL);
+  child = g_object_new (G_TYPE_SETTINGS,
+                        "schema", child_schema,
+                        "path", child_path,
+                        NULL);
+  g_free (child_path);
+  g_free (child_name);
+
+  return child;
+}
+
+/**
+ * g_settings_list_keys:
+ * @settings: a #GSettings object
+ * Returns: a list of the keys on @settings
+ *
+ * Introspects the list of keys on @settings.
+ *
+ * You should probably not be calling this function from "normal" code
+ * (since you should already know what keys are in your schema).  This
+ * function is intended for introspection reasons.
+ *
+ * You should free the return value with g_free() when you are done with
+ * it.
+ */
+const gchar **
+g_settings_list_keys (GSettings *settings)
+{
+  const GQuark *keys;
+  const gchar **strv;
+  gint n_keys;
+  gint i;
+
+  keys = g_settings_schema_list (settings->priv->schema, &n_keys);
+  strv = g_new (const gchar *, n_keys + 1);
+  for (i = 0; i < n_keys; i++)
+    strv[i] = g_quark_to_string (keys[i]);
+  strv[i] = NULL;
+
+  return strv;
+}
+
+/* Binding {{{1 */
+typedef struct
+{
+  GSettingsKeyInfo info;
+  GObject *object;
+
+  GSettingsBindGetMapping get_mapping;
+  GSettingsBindSetMapping set_mapping;
+  gpointer user_data;
+  GDestroyNotify destroy;
+
+  guint writable_handler_id;
+  guint property_handler_id;
+  const GParamSpec *property;
+  guint key_handler_id;
+
+  /* prevent recursion */
+  gboolean running;
+} GSettingsBinding;
+
+static void
+g_settings_binding_free (gpointer data)
+{
+  GSettingsBinding *binding = data;
+
+  g_assert (!binding->running);
+
+  if (binding->writable_handler_id)
+    g_signal_handler_disconnect (binding->info.settings,
+                                 binding->writable_handler_id);
+
+  if (binding->key_handler_id)
+    g_signal_handler_disconnect (binding->info.settings,
                                  binding->key_handler_id);
 
   if (g_signal_handler_is_connected (binding->object,
@@ -1162,8 +1927,7 @@ g_settings_binding_free (gpointer data)
   g_signal_handler_disconnect (binding->object,
                                binding->property_handler_id);
 
-  g_variant_type_free (binding->type);
-  g_object_unref (binding->settings);
+  g_settings_free_key_info (&binding->info);
 
   if (binding->destroy)
     binding->destroy (binding->user_data);
@@ -1193,8 +1957,8 @@ g_settings_binding_key_changed (GSettings   *settings,
   GValue value = { 0, };
   GVariant *variant;
 
-  g_assert (settings == binding->settings);
-  g_assert (key == binding->key);
+  g_assert (settings == binding->info.settings);
+  g_assert (key == binding->info.key);
 
   if (binding->running)
     return;
@@ -1202,11 +1966,43 @@ g_settings_binding_key_changed (GSettings   *settings,
   binding->running = TRUE;
 
   g_value_init (&value, binding->property->value_type);
-  variant = g_settings_get_value (settings, key);
-  if (binding->get_mapping (&value, variant, binding->user_data))
-    g_object_set_property (binding->object,
-                           binding->property->name,
-                           &value);
+
+  variant = g_settings_read_from_backend (&binding->info);
+  if (variant && !binding->get_mapping (&value, variant, binding->user_data))
+    {
+      /* silently ignore errors in the user's config database */
+      g_variant_unref (variant);
+      variant = NULL;
+    }
+
+  if (variant == NULL)
+    {
+      variant = g_settings_get_translated_default (&binding->info);
+      if (variant &&
+          !binding->get_mapping (&value, variant, binding->user_data))
+        {
+          /* flag translation errors with a warning */
+          g_warning ("Translated default `%s' for key `%s' in schema `%s' "
+                     "was rejected by the binding mapping function",
+                     binding->info.unparsed, binding->info.key,
+                     binding->info.settings->priv->schema_name);
+          g_variant_unref (variant);
+          variant = NULL;
+        }
+    }
+
+  if (variant == NULL)
+    {
+      variant = g_variant_ref (binding->info.default_value);
+      if (!binding->get_mapping (&value, variant, binding->user_data))
+        g_error ("The schema default value for key `%s' in schema `%s' "
+                 "was rejected by the binding mapping function.",
+                 binding->info.key,
+                 binding->info.settings->priv->schema_name);
+    }
+
+  g_object_set_property (binding->object, binding->property->name, &value);
+  g_variant_unref (variant);
   g_value_unset (&value);
 
   binding->running = FALSE;
@@ -1231,12 +2027,34 @@ g_settings_binding_property_changed (GObject          *object,
 
   g_value_init (&value, pspec->value_type);
   g_object_get_property (object, pspec->name, &value);
-  if ((variant = binding->set_mapping (&value, binding->type,
+  if ((variant = binding->set_mapping (&value, binding->info.type,
                                        binding->user_data)))
     {
-      g_settings_set_value (binding->settings,
-                            binding->key,
-                            g_variant_ref_sink (variant));
+      if (g_variant_is_floating (variant))
+        g_variant_ref_sink (variant);
+
+      if (!g_settings_type_check (&binding->info, variant))
+        {
+          g_critical ("binding mapping function for key `%s' returned "
+                      "GVariant of type `%s' when type `%s' was requested",
+                      binding->info.key, g_variant_get_type_string (variant),
+                      g_variant_type_dup_string (binding->info.type));
+          return;
+        }
+
+      if (!g_settings_range_check (&binding->info, variant))
+        {
+          g_critical ("GObject property `%s' on a `%s' object is out of "
+                      "schema-specified range for key `%s' of `%s': %s",
+                      binding->property->name,
+                      g_type_name (binding->property->owner_type),
+                      binding->info.key,
+                      binding->info.settings->priv->schema_name,
+                      g_variant_print (variant, TRUE));
+          return;
+        }
+
+      g_settings_write_to_backend (&binding->info, variant);
       g_variant_unref (variant);
     }
   g_value_unset (&value);
@@ -1334,9 +2152,8 @@ g_settings_bind_with_mapping (GSettings               *settings,
   objectclass = G_OBJECT_GET_CLASS (object);
 
   binding = g_slice_new0 (GSettingsBinding);
-  binding->settings = g_object_ref (settings);
+  g_settings_get_key_info (&binding->info, settings, key);
   binding->object = object;
-  binding->key = g_intern_string (key);
   binding->property = g_object_class_find_property (objectclass, property);
   binding->user_data = user_data;
   binding->destroy = destroy;
@@ -1352,46 +2169,32 @@ g_settings_bind_with_mapping (GSettings               *settings,
                   property, G_OBJECT_TYPE_NAME (object));
       return;
     }
-
-  if ((flags & G_SETTINGS_BIND_GET) && (binding->property->flags & G_PARAM_WRITABLE) == 0)
-    {
-      g_critical ("g_settings_bind: property '%s' on class '%s' is not writable",
-                  property, G_OBJECT_TYPE_NAME (object));
-      return;
-    }
-  if ((flags & G_SETTINGS_BIND_SET) && (binding->property->flags & G_PARAM_READABLE) == 0)
+
+  if ((flags & G_SETTINGS_BIND_GET) &&
+      (binding->property->flags & G_PARAM_WRITABLE) == 0)
     {
-      g_critical ("g_settings_bind: property '%s' on class '%s' is not readable",
-                  property, G_OBJECT_TYPE_NAME (object));
+      g_critical ("g_settings_bind: property '%s' on class '%s' is not "
+                  "writable", property, G_OBJECT_TYPE_NAME (object));
       return;
     }
-
-  {
-    GVariant *value;
-
-    value = g_settings_schema_get_value (settings->priv->schema, key, NULL);
-    binding->type = g_variant_type_copy (g_variant_get_type (value));
-    if (value)
-      g_variant_unref (value);
-  }
-
-  if (binding->type == NULL)
+  if ((flags & G_SETTINGS_BIND_SET) &&
+      (binding->property->flags & G_PARAM_READABLE) == 0)
     {
-      g_critical ("g_settings_bind: no key '%s' on schema '%s'",
-                  key, settings->priv->schema_name);
+      g_critical ("g_settings_bind: property '%s' on class '%s' is not "
+                  "readable", property, G_OBJECT_TYPE_NAME (object));
       return;
     }
 
   if (((get_mapping == NULL && (flags & G_SETTINGS_BIND_GET)) ||
        (set_mapping == NULL && (flags & G_SETTINGS_BIND_SET))) &&
       !g_settings_mapping_is_compatible (binding->property->value_type,
-                                         binding->type))
+                                         binding->info.type))
     {
-      g_critical ("g_settings_bind: property '%s' on class '%s' has type"
-                  "'%s' which is not compatible with type '%s' of key '%s'"
+      g_critical ("g_settings_bind: property '%s' on class '%s' has type "
+                  "'%s' which is not compatible with type '%s' of key '%s' "
                   "on schema '%s'", property, G_OBJECT_TYPE_NAME (object),
                   g_type_name (binding->property->value_type),
-                  g_variant_type_dup_string (binding->type), key,
+                  g_variant_type_dup_string (binding->info.type), key,
                   settings->priv->schema_name);
       return;
     }
@@ -1405,7 +2208,7 @@ g_settings_bind_with_mapping (GSettings               *settings,
 
       if (sensitive && sensitive->value_type == G_TYPE_BOOLEAN &&
           (sensitive->flags & G_PARAM_WRITABLE))
-        g_settings_bind_writable (settings, binding->key,
+        g_settings_bind_writable (settings, binding->info.key,
                                   object, "sensitive", FALSE);
     }
 
@@ -1430,463 +2233,161 @@ g_settings_bind_with_mapping (GSettings               *settings,
         {
           detailed_signal = g_strdup_printf ("changed::%s", key);
           binding->key_handler_id =
-            g_signal_connect (settings, detailed_signal,
-                              G_CALLBACK (g_settings_binding_key_changed),
-                              binding);
-          g_free (detailed_signal);
-        }
-
-      g_settings_binding_key_changed (settings, binding->key, binding);
-    }
-
-  binding_quark = g_settings_binding_quark (property);
-  g_object_set_qdata_full (object, binding_quark,
-                           binding, g_settings_binding_free);
-}
-
-typedef struct
-{
-  GSettings *settings;
-  gpointer object;
-  const gchar *key;
-  const gchar *property;
-  gboolean inverted;
-  gulong handler_id;
-} GSettingsWritableBinding;
-
-static void
-g_settings_writable_binding_free (gpointer data)
-{
-  GSettingsWritableBinding *binding = data;
-
-  g_signal_handler_disconnect (binding->settings, binding->handler_id);
-  g_object_unref (binding->settings);
-  g_slice_free (GSettingsWritableBinding, binding);
-}
-
-static void
-g_settings_binding_writable_changed (GSettings   *settings,
-                                     const gchar *key,
-                                     gpointer     user_data)
-{
-  GSettingsWritableBinding *binding = user_data;
-  gboolean writable;
-
-  g_assert (settings == binding->settings);
-  g_assert (key == binding->key);
-
-  writable = g_settings_is_writable (settings, key);
-
-  if (binding->inverted)
-    writable = !writable;
-
-  g_object_set (binding->object, binding->property, writable, NULL);
-}
-
-/**
- * g_settings_bind_writable:
- * @settings: a #GSettings object
- * @key: the key to bind
- * @object: a #GObject
- * @property: the name of a boolean property to bind
- * @inverted: whether to 'invert' the value
- *
- * Create a binding between the writability of @key in the
- * @settings object and the property @property of @object.
- * The property must be boolean; "sensitive" or "visible"
- * properties of widgets are the most likely candidates.
- *
- * Writable bindings are always uni-directional; changes of the
- * writability of the setting will be propagated to the object
- * property, not the other way.
- *
- * When the @inverted argument is %TRUE, the binding inverts the
- * value as it passes from the setting to the object, i.e. @property
- * will be set to %TRUE if the key is <emphasis>not</emphasis>
- * writable.
- *
- * Note that the lifecycle of the binding is tied to the object,
- * and that you can have only one binding per object property.
- * If you bind the same property twice on the same object, the second
- * binding overrides the first one.
- *
- * Since: 2.26
- */
-void
-g_settings_bind_writable (GSettings   *settings,
-                          const gchar *key,
-                          gpointer     object,
-                          const gchar *property,
-                          gboolean     inverted)
-{
-  GSettingsWritableBinding *binding;
-  gchar *detailed_signal;
-  GParamSpec *pspec;
-
-  g_return_if_fail (G_IS_SETTINGS (settings));
-
-  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), property);
-  if (pspec == NULL)
-    {
-      g_critical ("g_settings_bind_writable: no property '%s' on class '%s'",
-                  property, G_OBJECT_TYPE_NAME (object));
-      return;
-    }
-  if ((pspec->flags & G_PARAM_WRITABLE) == 0)
-    {
-      g_critical ("g_settings_bind_writable: property '%s' on class '%s' is not writable",
-                  property, G_OBJECT_TYPE_NAME (object));
-      return;
-    }
-
-  binding = g_slice_new (GSettingsWritableBinding);
-  binding->settings = g_object_ref (settings);
-  binding->object = object;
-  binding->key = g_intern_string (key);
-  binding->property = g_intern_string (property);
-  binding->inverted = inverted;
-
-  detailed_signal = g_strdup_printf ("writable-changed::%s", key);
-  binding->handler_id =
-    g_signal_connect (settings, detailed_signal,
-                      G_CALLBACK (g_settings_binding_writable_changed),
-                      binding);
-  g_free (detailed_signal);
-
-  g_object_set_qdata_full (object, g_settings_binding_quark (property),
-                           binding, g_settings_writable_binding_free);
-
-  g_settings_binding_writable_changed (settings, binding->key, binding);
-}
-
-/**
- * g_settings_unbind:
- * @object: the object
- * @property: the property whose binding is removed
- *
- * Removes an existing binding for @property on @object.
- *
- * Note that bindings are automatically removed when the
- * object is finalized, so it is rarely necessary to call this
- * function.
- *
- * Since: 2.26
- */
-void
-g_settings_unbind (gpointer     object,
-                   const gchar *property)
-{
-  GQuark binding_quark;
-
-  binding_quark = g_settings_binding_quark (property);
-  g_object_set_qdata (object, binding_quark, NULL);
-}
-
-/**
- * g_settings_get_string:
- * @settings: a #GSettings object
- * @key: the key to get the value for
- * @returns: a newly-allocated string
- *
- * Gets the value that is stored at @key in @settings.
- *
- * A convenience variant of g_settings_get() for strings.
- *
- * It is a programmer error to pass a @key that isn't valid for
- * @settings or is not of type string.
- *
- * Since: 2.26
- */
-gchar *
-g_settings_get_string (GSettings   *settings,
-                       const gchar *key)
-{
-  GVariant *value;
-  gchar *result;
-
-  value = g_settings_get_value (settings, key);
-  result = g_variant_dup_string (value, NULL);
-  g_variant_unref (value);
-
-  return result;
-}
-
-/**
- * g_settings_set_string:
- * @settings: a #GSettings object
- * @key: the name of the key to set
- * @value: the value to set it to
- * @returns: %TRUE if setting the key succeeded,
- *     %FALSE if the key was not writable
- *
- * Sets @key in @settings to @value.
- *
- * A convenience variant of g_settings_set() for strings.
- *
- * It is a programmer error to pass a @key that isn't valid for
- * @settings or is not of type string.
- *
- * Since: 2.26
- */
-gboolean
-g_settings_set_string (GSettings   *settings,
-                       const gchar *key,
-                       const gchar *value)
-{
-  return g_settings_set_value (settings, key, g_variant_new_string (value));
-}
-
-/**
- * g_settings_get_int:
- * @settings: a #GSettings object
- * @key: the key to get the value for
- * @returns: an integer
- *
- * Gets the value that is stored at @key in @settings.
- *
- * A convenience variant of g_settings_get() for 32-bit integers.
- *
- * It is a programmer error to pass a @key that isn't valid for
- * @settings or is not of type int32.
- *
- * Since: 2.26
- */
-gint
-g_settings_get_int (GSettings   *settings,
-                    const gchar *key)
-{
-  GVariant *value;
-  gint result;
-
-  value = g_settings_get_value (settings, key);
-  result = g_variant_get_int32 (value);
-  g_variant_unref (value);
-
-  return result;
-}
-
-/**
- * g_settings_set_int:
- * @settings: a #GSettings object
- * @key: the name of the key to set
- * @value: the value to set it to
- * @returns: %TRUE if setting the key succeeded,
- *     %FALSE if the key was not writable
- *
- * Sets @key in @settings to @value.
- *
- * A convenience variant of g_settings_set() for 32-bit integers.
- *
- * It is a programmer error to pass a @key that isn't valid for
- * @settings or is not of type int32.
- *
- * Since: 2.26
- */
-gboolean
-g_settings_set_int (GSettings   *settings,
-                    const gchar *key,
-                    gint         value)
-{
-  return g_settings_set_value (settings, key, g_variant_new_int32 (value));
+            g_signal_connect (settings, detailed_signal,
+                              G_CALLBACK (g_settings_binding_key_changed),
+                              binding);
+          g_free (detailed_signal);
+        }
+
+      g_settings_binding_key_changed (settings, binding->info.key, binding);
+    }
+
+  binding_quark = g_settings_binding_quark (property);
+  g_object_set_qdata_full (object, binding_quark,
+                           binding, g_settings_binding_free);
 }
 
-/**
- * g_settings_get_double:
- * @settings: a #GSettings object
- * @key: the key to get the value for
- * @returns: a double
- *
- * Gets the value that is stored at @key in @settings.
- *
- * A convenience variant of g_settings_get() for doubles.
- *
- * It is a programmer error to pass a @key that isn't valid for
- * @settings or is not of type double.
- *
- * Since: 2.26
- */
-gdouble
-g_settings_get_double (GSettings   *settings,
-                       const gchar *key)
+/* Writability binding {{{1 */
+typedef struct
 {
-  GVariant *value;
-  gdouble result;
+  GSettings *settings;
+  gpointer object;
+  const gchar *key;
+  const gchar *property;
+  gboolean inverted;
+  gulong handler_id;
+} GSettingsWritableBinding;
 
-  value = g_settings_get_value (settings, key);
-  result = g_variant_get_double (value);
-  g_variant_unref (value);
+static void
+g_settings_writable_binding_free (gpointer data)
+{
+  GSettingsWritableBinding *binding = data;
 
-  return result;
+  g_signal_handler_disconnect (binding->settings, binding->handler_id);
+  g_object_unref (binding->settings);
+  g_slice_free (GSettingsWritableBinding, binding);
 }
 
-/**
- * g_settings_set_double:
- * @settings: a #GSettings object
- * @key: the name of the key to set
- * @value: the value to set it to
- * @returns: %TRUE if setting the key succeeded,
- *     %FALSE if the key was not writable
- *
- * Sets @key in @settings to @value.
- *
- * A convenience variant of g_settings_set() for doubles.
- *
- * It is a programmer error to pass a @key that isn't valid for
- * @settings or is not of type double.
- *
- * Since: 2.26
- */
-gboolean
-g_settings_set_double (GSettings   *settings,
-                       const gchar *key,
-                       gdouble      value)
+static void
+g_settings_binding_writable_changed (GSettings   *settings,
+                                     const gchar *key,
+                                     gpointer     user_data)
 {
-  return g_settings_set_value (settings, key, g_variant_new_double (value));
-}
+  GSettingsWritableBinding *binding = user_data;
+  gboolean writable;
 
-/**
- * g_settings_get_boolean:
- * @settings: a #GSettings object
- * @key: the key to get the value for
- * @returns: a boolean
- *
- * Gets the value that is stored at @key in @settings.
- *
- * A convenience variant of g_settings_get() for booleans.
- *
- * It is a programmer error to pass a @key that isn't valid for
- * @settings or is not of type boolean.
- *
- * Since: 2.26
- */
-gboolean
-g_settings_get_boolean (GSettings  *settings,
-                       const gchar *key)
-{
-  GVariant *value;
-  gboolean result;
+  g_assert (settings == binding->settings);
+  g_assert (key == binding->key);
 
-  value = g_settings_get_value (settings, key);
-  result = g_variant_get_boolean (value);
-  g_variant_unref (value);
+  writable = g_settings_is_writable (settings, key);
 
-  return result;
-}
+  if (binding->inverted)
+    writable = !writable;
 
-/**
- * g_settings_set_boolean:
- * @settings: a #GSettings object
- * @key: the name of the key to set
- * @value: the value to set it to
- * @returns: %TRUE if setting the key succeeded,
- *     %FALSE if the key was not writable
- *
- * Sets @key in @settings to @value.
- *
- * A convenience variant of g_settings_set() for booleans.
- *
- * It is a programmer error to pass a @key that isn't valid for
- * @settings or is not of type boolean.
- *
- * Since: 2.26
- */
-gboolean
-g_settings_set_boolean (GSettings  *settings,
-                       const gchar *key,
-                       gboolean     value)
-{
-  return g_settings_set_value (settings, key, g_variant_new_boolean (value));
+  g_object_set (binding->object, binding->property, writable, NULL);
 }
 
 /**
- * g_settings_get_strv:
+ * g_settings_bind_writable:
  * @settings: a #GSettings object
- * @key: the key to get the value for
- * @returns: a newly-allocated, %NULL-terminated array of strings
+ * @key: the key to bind
+ * @object: a #GObject
+ * @property: the name of a boolean property to bind
+ * @inverted: whether to 'invert' the value
  *
- * Gets the value that is stored at @key in @settings.
+ * Create a binding between the writability of @key in the
+ * @settings object and the property @property of @object.
+ * The property must be boolean; "sensitive" or "visible"
+ * properties of widgets are the most likely candidates.
  *
- * A convenience variant of g_settings_get() for string arrays.
+ * Writable bindings are always uni-directional; changes of the
+ * writability of the setting will be propagated to the object
+ * property, not the other way.
+ *
+ * When the @inverted argument is %TRUE, the binding inverts the
+ * value as it passes from the setting to the object, i.e. @property
+ * will be set to %TRUE if the key is <emphasis>not</emphasis>
+ * writable.
  *
- * It is a programmer error to pass a @key that isn't valid for
- * @settings or is not of type 'string array'.
+ * Note that the lifecycle of the binding is tied to the object,
+ * and that you can have only one binding per object property.
+ * If you bind the same property twice on the same object, the second
+ * binding overrides the first one.
  *
  * Since: 2.26
  */
-gchar **
-g_settings_get_strv (GSettings   *settings,
-                     const gchar *key)
+void
+g_settings_bind_writable (GSettings   *settings,
+                          const gchar *key,
+                          gpointer     object,
+                          const gchar *property,
+                          gboolean     inverted)
 {
-  GVariant *value;
-  gchar **result;
+  GSettingsWritableBinding *binding;
+  gchar *detailed_signal;
+  GParamSpec *pspec;
 
-  value = g_settings_get_value (settings, key);
-  result = g_variant_dup_strv (value, NULL);
-  g_variant_unref (value);
+  g_return_if_fail (G_IS_SETTINGS (settings));
 
-  return result;
-}
+  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), property);
+  if (pspec == NULL)
+    {
+      g_critical ("g_settings_bind_writable: no property '%s' on class '%s'",
+                  property, G_OBJECT_TYPE_NAME (object));
+      return;
+    }
+  if ((pspec->flags & G_PARAM_WRITABLE) == 0)
+    {
+      g_critical ("g_settings_bind_writable: property '%s' on class '%s' is not writable",
+                  property, G_OBJECT_TYPE_NAME (object));
+      return;
+    }
 
-/**
- * g_settings_set_strv:
- * @settings: a #GSettings object
- * @key: the name of the key to set
- * @value: (allow-none): the value to set it to, or %NULL
- * @returns: %TRUE if setting the key succeeded,
- *     %FALSE if the key was not writable
- *
- * Sets @key in @settings to @value.
- *
- * A convenience variant of g_settings_set() for string arrays.  If
- * @value is %NULL, then @key is set to be the empty array.
- *
- * It is a programmer error to pass a @key that isn't valid for
- * @settings or is not of type 'string array'.
- *
- * Since: 2.26
- */
-gboolean
-g_settings_set_strv (GSettings           *settings,
-                     const gchar         *key,
-                     const gchar * const *value)
-{
-  GVariant *array;
+  binding = g_slice_new (GSettingsWritableBinding);
+  binding->settings = g_object_ref (settings);
+  binding->object = object;
+  binding->key = g_intern_string (key);
+  binding->property = g_intern_string (property);
+  binding->inverted = inverted;
 
-  if (value)
-    array = g_variant_new_strv (value, -1);
-  else
-    array = g_variant_new_strv (NULL, 0);
+  detailed_signal = g_strdup_printf ("writable-changed::%s", key);
+  binding->handler_id =
+    g_signal_connect (settings, detailed_signal,
+                      G_CALLBACK (g_settings_binding_writable_changed),
+                      binding);
+  g_free (detailed_signal);
 
-  return g_settings_set_value (settings, key, array);
+  g_object_set_qdata_full (object, g_settings_binding_quark (property),
+                           binding, g_settings_writable_binding_free);
+
+  g_settings_binding_writable_changed (settings, binding->key, binding);
 }
 
 /**
- * g_settings_sync:
- * @context: the context to sync, or %NULL
+ * g_settings_unbind:
+ * @object: the object
+ * @property: the property whose binding is removed
  *
- * Ensures that all pending operations for the given context are
- * complete.
+ * Removes an existing binding for @property on @object.
  *
- * Writes made to a #GSettings are handled asynchronously.  For this
- * reason, it is very unlikely that the changes have it to disk by the
- * time g_settings_set() returns.
+ * Note that bindings are automatically removed when the
+ * object is finalized, so it is rarely necessary to call this
+ * function.
  *
- * This call will block until all of the writes have made it to the
- * backend.  Since the mainloop is not running, no change notifications
- * will be dispatched during this call (but some may be queued by the
- * time the call is done).
- **/
+ * Since: 2.26
+ */
 void
-g_settings_sync (const gchar *context)
+g_settings_unbind (gpointer     object,
+                   const gchar *property)
 {
-  GSettingsBackend *backend;
-
-  if (context == NULL)
-    context = "";
+  GQuark binding_quark;
 
-  backend = g_settings_backend_get_with_context (context);
-  g_settings_backend_sync (backend);
+  binding_quark = g_settings_binding_quark (property);
+  g_object_set_qdata (object, binding_quark, NULL);
 }
 
+/* Epilogue {{{1 */
 #define __G_SETTINGS_C__
 #include "gioaliasdef.c"
+
+/* vim:set foldmethod=marker: */