2 * Copyright © 2009, 2010 Codethink Limited
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the licence, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * Author: Ryan Lortie <desrt@desrt.ca>
30 #include "gsettings.h"
32 #include "gdelayedsettingsbackend.h"
33 #include "gsettingsbackendinternal.h"
34 #include "gsettings-mapping.h"
35 #include "gio-marshal.h"
36 #include "gsettingsschema.h"
45 * @short_description: High-level API for application settings
47 * The #GSettings class provides a convenient API for storing and retrieving
48 * application settings.
50 * When creating a GSettings instance, you have to specify a schema
51 * that describes the keys in your settings and their types and default
52 * values, as well as some other information.
54 * Normally, a schema has as fixed path that determines where the settings
55 * are stored in the conceptual global tree of settings. However, schemas
56 * can also be 'relocatable', i.e. not equipped with a fixed path. This is
57 * useful e.g. when the schema describes an 'account', and you want to be
58 * able to store a arbitrary number of accounts.
60 * Unlike other configuration systems (like GConf), GSettings does not
61 * restrict keys to basic types like strings and numbers. GSettings stores
62 * values as #GVariant, and allows any #GVariantType for keys. Key names
63 * are restricted to lowercase characters, numbers and '-'. Furthermore,
64 * the names must begin with a lowercase character, must not end
65 * with a '-', and must not contain consecutive dashes. Key names can
66 * be up to 32 characters long.
68 * Similar to GConf, the default values in GSettings schemas can be
69 * localized, but the localized values are stored in gettext catalogs
70 * and looked up with the domain that is specified in the
71 * <tag class="attribute">gettext-domain</tag> attribute of the
72 * <tag class="starttag">schemalist</tag> or <tag class="starttag">schema</tag>
73 * elements and the category that is specified in the l10n attribute of the
74 * <tag class="starttag">key</tag> element.
76 * GSettings uses schemas in a compact binary form that is created
77 * by the <link linkend="glib-compile-schemas">glib-compile-schemas</link>
78 * utility. The input is a schema description in an XML format that can be
79 * described by the following DTD:
80 * |[<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/gschema.dtd"><xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback></xi:include>]|
82 * At runtime, schemas are identified by their id (as specified
83 * in the <tag class="attribute">id</tag> attribute of the
84 * <tag class="starttag">schema</tag> element). The
85 * convention for schema ids is to use a dotted name, similar in
86 * style to a DBus bus name, e.g. "org.gnome.font-rendering".
88 * In addition to #GVariant types, keys can have types that have enumerated
89 * types. These can be described by a <tag class="starttag">choice</tag>,
90 * <tag class="starttag">enum</tag> or <tag class="starttag">flags</tag> element, see
91 * <xref linkend="schema-enumerated"/>. The underlying type of
92 * such a key is string, but you can use g_settings_get_enum(),
93 * g_settings_set_enum(), g_settings_get_flags(), g_settings_set_flags()
94 * access the numeric values corresponding to the string value of enum
97 * <example id="schema-default-values"><title>Default values</title>
98 * <programlisting><![CDATA[
100 * <schema id="org.gtk.test" path="/tests/" gettext-domain="test">
102 * <key name="greeting" type="s">
103 * <default l10n="messages">"Hello, earthlings"</default>
104 * <summary>A greeting</summary>
106 * Greeting of the invading martians
110 * <key name="box" type="(ii)">
111 * <default>(20,30)</default>
116 * ]]></programlisting></example>
118 * <example id="schema-enumerated"><title>Ranges, choices and enumerated types</title>
119 * <programlisting><![CDATA[
123 * <value nick="first" value="1"/>
124 * <value nick="second" value="2"/>
127 * <enum id="myflags">
128 * <value nick="flag1" value="1"/>
129 * <value nick="flag2" value="2"/>
130 * <value nick="flag3" value="4"/>
133 * <schema id="org.gtk.test">
135 * <key name="key-with-range" type="i">
136 * <range min="1" max="100"/>
137 * <default>10</default>
140 * <key name="key-with-choices" type="s">
142 * <choice value='Elisabeth'/>
143 * <choice value='Annabeth'/>
144 * <choice value='Joe'/>
147 * <alias value='Anna' target='Annabeth'/>
148 * <alias value='Beth' target='Elisabeth'/>
150 * <default>'Joe'</default>
153 * <key name='enumerated-key' enum='myenum'>
154 * <default>'first'</default>
157 * <key name='flags-key' flags='myflags'>
158 * <default>["flag1",flag2"]</default>
162 * ]]></programlisting></example>
165 * <title>Vendor overrides</title>
167 * Default values are defined in the schemas that get installed by
168 * an application. Sometimes, it is necessary for a vendor or distributor
169 * to adjust these defaults. Since patching the XML source for the schema
170 * is inconvenient and error-prone,
171 * <link linkend="glib-compile-schemas">glib-compile-schemas</link> reads
172 * so-called 'vendor override' files. These are keyfiles in the same
173 * directory as the XML schema sources which can override default values.
174 * The schema id serves as the group name in the key file, and the values
175 * are expected in serialized GVariant form, as in the following example:
176 * <informalexample><programlisting>
180 * </programlisting></informalexample>
185 * <title>Binding</title>
187 * A very convenient feature of GSettings lets you bind #GObject properties
188 * directly to settings, using g_settings_bind(). Once a GObject property
189 * has been bound to a setting, changes on either side are automatically
190 * propagated to the other side. GSettings handles details like
191 * mapping between GObject and GVariant types, and preventing infinite
195 * This makes it very easy to hook up a preferences dialog to the
196 * underlying settings. To make this even more convenient, GSettings
197 * looks for a boolean property with the name "sensitivity" and
198 * automatically binds it to the writability of the bound setting.
199 * If this 'magic' gets in the way, it can be suppressed with the
200 * #G_SETTINGS_BIND_NO_SENSITIVITY flag.
205 struct _GSettingsPrivate
207 /* where the signals go... */
208 GMainContext *main_context;
210 GSettingsBackend *backend;
211 GSettingsSchema *schema;
215 GDelayedSettingsBackend *delayed;
229 SIGNAL_WRITABLE_CHANGE_EVENT,
230 SIGNAL_WRITABLE_CHANGED,
236 static guint g_settings_signals[N_SIGNALS];
238 G_DEFINE_TYPE (GSettings, g_settings, G_TYPE_OBJECT)
242 g_settings_real_change_event (GSettings *settings,
249 keys = g_settings_schema_list (settings->priv->schema, &n_keys);
251 for (i = 0; i < n_keys; i++)
252 g_signal_emit (settings, g_settings_signals[SIGNAL_CHANGED],
253 keys[i], g_quark_to_string (keys[i]));
259 g_settings_real_writable_change_event (GSettings *settings,
262 const GQuark *keys = &key;
267 keys = g_settings_schema_list (settings->priv->schema, &n_keys);
269 for (i = 0; i < n_keys; i++)
270 g_signal_emit (settings, g_settings_signals[SIGNAL_WRITABLE_CHANGED],
271 keys[i], g_quark_to_string (keys[i]));
277 settings_backend_changed (GObject *target,
278 GSettingsBackend *backend,
282 GSettings *settings = G_SETTINGS (target);
283 gboolean ignore_this;
286 g_assert (settings->priv->backend == backend);
288 for (i = 0; key[i] == settings->priv->path[i]; i++);
290 if (settings->priv->path[i] == '\0' &&
291 g_settings_schema_has_key (settings->priv->schema, key + i))
295 quark = g_quark_from_string (key + i);
296 g_signal_emit (settings, g_settings_signals[SIGNAL_CHANGE_EVENT],
297 0, &quark, 1, &ignore_this);
302 settings_backend_path_changed (GObject *target,
303 GSettingsBackend *backend,
307 GSettings *settings = G_SETTINGS (target);
308 gboolean ignore_this;
310 g_assert (settings->priv->backend == backend);
312 if (g_str_has_prefix (settings->priv->path, path))
313 g_signal_emit (settings, g_settings_signals[SIGNAL_CHANGE_EVENT],
314 0, NULL, 0, &ignore_this);
318 settings_backend_keys_changed (GObject *target,
319 GSettingsBackend *backend,
321 const gchar * const *items,
324 GSettings *settings = G_SETTINGS (target);
325 gboolean ignore_this;
328 g_assert (settings->priv->backend == backend);
330 for (i = 0; settings->priv->path[i] &&
331 settings->priv->path[i] == path[i]; i++);
338 for (j = 0; items[j]; j++)
340 const gchar *item = items[j];
343 for (k = 0; item[k] == settings->priv->path[i + k]; k++);
345 if (settings->priv->path[i + k] == '\0' &&
346 g_settings_schema_has_key (settings->priv->schema, item + k))
347 quarks[l++] = g_quark_from_string (item + k);
349 /* "256 quarks ought to be enough for anybody!"
350 * If this bites you, I'm sorry. Please file a bug.
356 g_signal_emit (settings, g_settings_signals[SIGNAL_CHANGE_EVENT],
357 0, quarks, l, &ignore_this);
362 settings_backend_writable_changed (GObject *target,
363 GSettingsBackend *backend,
366 GSettings *settings = G_SETTINGS (target);
367 gboolean ignore_this;
370 g_assert (settings->priv->backend == backend);
372 for (i = 0; key[i] == settings->priv->path[i]; i++);
374 if (settings->priv->path[i] == '\0' &&
375 g_settings_schema_has_key (settings->priv->schema, key + i))
376 g_signal_emit (settings, g_settings_signals[SIGNAL_WRITABLE_CHANGE_EVENT],
377 0, g_quark_from_string (key + i), &ignore_this);
381 settings_backend_path_writable_changed (GObject *target,
382 GSettingsBackend *backend,
385 GSettings *settings = G_SETTINGS (target);
386 gboolean ignore_this;
388 g_assert (settings->priv->backend == backend);
390 if (g_str_has_prefix (settings->priv->path, path))
391 g_signal_emit (settings, g_settings_signals[SIGNAL_WRITABLE_CHANGE_EVENT],
392 0, (GQuark) 0, &ignore_this);
395 /* Properties, Construction, Destruction {{{1 */
397 g_settings_set_property (GObject *object,
402 GSettings *settings = G_SETTINGS (object);
407 g_assert (settings->priv->schema_name == NULL);
408 settings->priv->schema_name = g_value_dup_string (value);
412 settings->priv->path = g_value_dup_string (value);
416 settings->priv->backend = g_value_dup_object (value);
420 g_assert_not_reached ();
425 g_settings_get_property (GObject *object,
430 GSettings *settings = G_SETTINGS (object);
435 g_value_set_string (value, settings->priv->schema_name);
439 g_value_set_object (value, settings->priv->backend);
443 g_value_set_string (value, settings->priv->path);
446 case PROP_HAS_UNAPPLIED:
447 g_value_set_boolean (value, g_settings_get_has_unapplied (settings));
451 g_assert_not_reached ();
455 static const GSettingsListenerVTable listener_vtable = {
456 settings_backend_changed,
457 settings_backend_path_changed,
458 settings_backend_keys_changed,
459 settings_backend_writable_changed,
460 settings_backend_path_writable_changed
464 g_settings_constructed (GObject *object)
466 GSettings *settings = G_SETTINGS (object);
467 const gchar *schema_path;
469 settings->priv->schema = g_settings_schema_new (settings->priv->schema_name);
470 schema_path = g_settings_schema_get_path (settings->priv->schema);
472 if (settings->priv->path && schema_path && strcmp (settings->priv->path, schema_path) != 0)
473 g_error ("settings object created with schema '%s' and path '%s', but "
474 "path '%s' is specified by schema",
475 settings->priv->schema_name, settings->priv->path, schema_path);
477 if (settings->priv->path == NULL)
479 if (schema_path == NULL)
480 g_error ("attempting to create schema '%s' without a path",
481 settings->priv->schema_name);
483 settings->priv->path = g_strdup (schema_path);
486 if (settings->priv->backend == NULL)
487 settings->priv->backend = g_settings_backend_get_default ();
489 g_settings_backend_watch (settings->priv->backend,
490 &listener_vtable, G_OBJECT (settings),
491 settings->priv->main_context);
492 g_settings_backend_subscribe (settings->priv->backend,
493 settings->priv->path);
497 g_settings_finalize (GObject *object)
499 GSettings *settings = G_SETTINGS (object);
501 g_settings_backend_unsubscribe (settings->priv->backend,
502 settings->priv->path);
503 g_main_context_unref (settings->priv->main_context);
504 g_object_unref (settings->priv->backend);
505 g_object_unref (settings->priv->schema);
506 g_free (settings->priv->schema_name);
507 g_free (settings->priv->path);
509 G_OBJECT_CLASS (g_settings_parent_class)->finalize (object);
513 g_settings_init (GSettings *settings)
515 settings->priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
519 settings->priv->main_context = g_main_context_get_thread_default ();
521 if (settings->priv->main_context == NULL)
522 settings->priv->main_context = g_main_context_default ();
524 g_main_context_ref (settings->priv->main_context);
528 g_settings_class_init (GSettingsClass *class)
530 GObjectClass *object_class = G_OBJECT_CLASS (class);
532 class->writable_change_event = g_settings_real_writable_change_event;
533 class->change_event = g_settings_real_change_event;
535 object_class->set_property = g_settings_set_property;
536 object_class->get_property = g_settings_get_property;
537 object_class->constructed = g_settings_constructed;
538 object_class->finalize = g_settings_finalize;
540 g_type_class_add_private (object_class, sizeof (GSettingsPrivate));
543 * GSettings::changed:
544 * @settings: the object on which the signal was emitted
545 * @key: the name of the key that changed
547 * The "changed" signal is emitted when a key has potentially changed.
548 * You should call one of the g_settings_get() calls to check the new
551 * This signal supports detailed connections. You can connect to the
552 * detailed signal "changed::x" in order to only receive callbacks
553 * when key "x" changes.
555 g_settings_signals[SIGNAL_CHANGED] =
556 g_signal_new ("changed", G_TYPE_SETTINGS,
557 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
558 G_STRUCT_OFFSET (GSettingsClass, changed),
559 NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE,
560 1, G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
563 * GSettings::change-event:
564 * @settings: the object on which the signal was emitted
565 * @keys: an array of #GQuark<!-- -->s for the changed keys, or %NULL
566 * @n_keys: the length of the @keys array, or 0
567 * @returns: %TRUE to stop other handlers from being invoked for the
568 * event. FALSE to propagate the event further.
570 * The "change-event" signal is emitted once per change event that
571 * affects this settings object. You should connect to this signal
572 * only if you are interested in viewing groups of changes before they
573 * are split out into multiple emissions of the "changed" signal.
574 * For most use cases it is more appropriate to use the "changed" signal.
576 * In the event that the change event applies to one or more specified
577 * keys, @keys will be an array of #GQuark of length @n_keys. In the
578 * event that the change event applies to the #GSettings object as a
579 * whole (ie: potentially every key has been changed) then @keys will
580 * be %NULL and @n_keys will be 0.
582 * The default handler for this signal invokes the "changed" signal
583 * for each affected key. If any other connected handler returns
584 * %TRUE then this default functionality will be supressed.
586 g_settings_signals[SIGNAL_CHANGE_EVENT] =
587 g_signal_new ("change-event", G_TYPE_SETTINGS,
589 G_STRUCT_OFFSET (GSettingsClass, change_event),
590 g_signal_accumulator_true_handled, NULL,
591 _gio_marshal_BOOL__POINTER_INT,
592 G_TYPE_BOOLEAN, 2, G_TYPE_POINTER, G_TYPE_INT);
595 * GSettings::writable-changed:
596 * @settings: the object on which the signal was emitted
599 * The "writable-changed" signal is emitted when the writability of a
600 * key has potentially changed. You should call
601 * g_settings_is_writable() in order to determine the new status.
603 * This signal supports detailed connections. You can connect to the
604 * detailed signal "writable-changed::x" in order to only receive
605 * callbacks when the writability of "x" changes.
607 g_settings_signals[SIGNAL_WRITABLE_CHANGED] =
608 g_signal_new ("writable-changed", G_TYPE_SETTINGS,
609 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
610 G_STRUCT_OFFSET (GSettingsClass, changed),
611 NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE,
612 1, G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
615 * GSettings::writable-change-event:
616 * @settings: the object on which the signal was emitted
617 * @key: the quark of the key, or 0
618 * @returns: %TRUE to stop other handlers from being invoked for the
619 * event. FALSE to propagate the event further.
621 * The "writable-change-event" signal is emitted once per writability
622 * change event that affects this settings object. You should connect
623 * to this signal if you are interested in viewing groups of changes
624 * before they are split out into multiple emissions of the
625 * "writable-changed" signal. For most use cases it is more
626 * appropriate to use the "writable-changed" signal.
628 * In the event that the writability change applies only to a single
629 * key, @key will be set to the #GQuark for that key. In the event
630 * that the writability change affects the entire settings object,
633 * The default handler for this signal invokes the "writable-changed"
634 * and "changed" signals for each affected key. This is done because
635 * changes in writability might also imply changes in value (if for
636 * example, a new mandatory setting is introduced). If any other
637 * connected handler returns %TRUE then this default functionality
640 g_settings_signals[SIGNAL_WRITABLE_CHANGE_EVENT] =
641 g_signal_new ("writable-change-event", G_TYPE_SETTINGS,
643 G_STRUCT_OFFSET (GSettingsClass, writable_change_event),
644 g_signal_accumulator_true_handled, NULL,
645 _gio_marshal_BOOLEAN__UINT, G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
650 * The name of the context that the settings are stored in.
652 g_object_class_install_property (object_class, PROP_BACKEND,
653 g_param_spec_object ("backend",
654 P_("GSettingsBackend"),
655 P_("The GSettingsBackend for this settings object"),
656 G_TYPE_SETTINGS_BACKEND, G_PARAM_CONSTRUCT_ONLY |
657 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
662 * The name of the schema that describes the types of keys
663 * for this #GSettings object.
665 g_object_class_install_property (object_class, PROP_SCHEMA,
666 g_param_spec_string ("schema",
668 P_("The name of the schema for this settings object"),
670 G_PARAM_CONSTRUCT_ONLY |
671 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
676 * The path within the backend where the settings are stored.
678 g_object_class_install_property (object_class, PROP_PATH,
679 g_param_spec_string ("path",
681 P_("The path within the backend where the settings are"),
683 G_PARAM_CONSTRUCT_ONLY |
684 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
687 * GSettings:has-unapplied:
689 * If this property is %TRUE, the #GSettings object has outstanding
690 * changes that will be applied when g_settings_apply() is called.
692 g_object_class_install_property (object_class, PROP_HAS_UNAPPLIED,
693 g_param_spec_boolean ("has-unapplied",
694 P_("Has unapplied changes"),
695 P_("TRUE if there are outstanding changes to apply()"),
697 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
701 /* Construction (new, new_with_path, etc.) {{{1 */
704 * @schema: the name of the schema
705 * @returns: a new #GSettings object
707 * Creates a new #GSettings object with a given schema.
709 * Signals on the newly created #GSettings object will be dispatched
710 * via the thread-default #GMainContext in effect at the time of the
711 * call to g_settings_new(). The new #GSettings will hold a reference
712 * on the context. See g_main_context_push_thread_default().
717 g_settings_new (const gchar *schema)
719 g_return_val_if_fail (schema != NULL, NULL);
721 return g_object_new (G_TYPE_SETTINGS,
727 * g_settings_new_with_path:
728 * @schema: the name of the schema
729 * @path: the path to use
730 * @returns: a new #GSettings object
732 * Creates a new #GSettings object with a given schema and path.
734 * You only need to do this if you want to directly create a settings
735 * object with a schema that doesn't have a specified path of its own.
738 * It is a programmer error to call this function for a schema that
739 * has an explicitly specified path.
744 g_settings_new_with_path (const gchar *schema,
747 g_return_val_if_fail (schema != NULL, NULL);
748 g_return_val_if_fail (path != NULL, NULL);
750 return g_object_new (G_TYPE_SETTINGS,
757 * g_settings_new_with_backend:
758 * @schema: the name of the schema
759 * @backend: the #GSettingsBackend to use
760 * @returns: a new #GSettings object
762 * Creates a new #GSettings object with a given schema and backend.
764 * Creating settings objects with an different backend allows accessing settings
765 * from a database other than the usual one. For example, it may make
766 * sense to pass a backend corresponding to the "defaults" settings database on
767 * the system to get a settings object that modifies the system default
768 * settings instead of the settings for this user.
773 g_settings_new_with_backend (const gchar *schema,
774 GSettingsBackend *backend)
776 g_return_val_if_fail (schema != NULL, NULL);
777 g_return_val_if_fail (G_IS_SETTINGS_BACKEND (backend), NULL);
779 return g_object_new (G_TYPE_SETTINGS,
786 * g_settings_new_with_backend_and_path:
787 * @schema: the name of the schema
788 * @backend: the #GSettingsBackend to use
789 * @path: the path to use
790 * @returns: a new #GSettings object
792 * Creates a new #GSettings object with a given schema, backend and
795 * This is a mix of g_settings_new_with_backend() and
796 * g_settings_new_with_path().
801 g_settings_new_with_backend_and_path (const gchar *schema,
802 GSettingsBackend *backend,
805 g_return_val_if_fail (schema != NULL, NULL);
806 g_return_val_if_fail (G_IS_SETTINGS_BACKEND (backend), NULL);
807 g_return_val_if_fail (path != NULL, NULL);
809 return g_object_new (G_TYPE_SETTINGS,
816 /* Internal read/write utilities, enum/flags conversion, validation {{{1 */
822 GSettingsSchema *schema;
827 const guint32 *strinfo;
828 gsize strinfo_length;
830 const gchar *unparsed;
833 const GVariantType *type;
834 GVariant *minimum, *maximum;
835 GVariant *default_value;
839 endian_fixup (GVariant **value)
841 #if G_BYTE_ORDER == G_BIG_ENDIAN
844 tmp = g_variant_byteswap (*value);
845 g_variant_unref (*value);
851 g_settings_get_key_info (GSettingsKeyInfo *info,
859 memset (info, 0, sizeof *info);
861 iter = g_settings_schema_get_value (settings->priv->schema, key);
863 info->default_value = g_variant_iter_next_value (iter);
864 endian_fixup (&info->default_value);
865 info->type = g_variant_get_type (info->default_value);
866 info->settings = g_object_ref (settings);
867 info->key = g_intern_string (key);
869 while (g_variant_iter_next (iter, "(y*)", &code, &data))
874 /* translation requested */
875 g_variant_get (data, "(y&s)", &info->lc_char, &info->unparsed);
879 /* enumerated types... */
880 info->is_enum = TRUE;
885 info->is_flags = TRUE;
889 /* ..., choices, aliases */
890 info->strinfo = g_variant_get_fixed_array (data,
891 &info->strinfo_length,
896 g_variant_get (data, "(**)", &info->minimum, &info->maximum);
897 endian_fixup (&info->minimum);
898 endian_fixup (&info->maximum);
902 g_warning ("unknown schema extension '%c'", code);
906 g_variant_unref (data);
909 g_variant_iter_free (iter);
913 g_settings_free_key_info (GSettingsKeyInfo *info)
916 g_variant_unref (info->minimum);
919 g_variant_unref (info->maximum);
921 g_variant_unref (info->default_value);
922 g_object_unref (info->settings);
926 g_settings_write_to_backend (GSettingsKeyInfo *info,
932 path = g_strconcat (info->settings->priv->path, info->key, NULL);
933 success = g_settings_backend_write (info->settings->priv->backend,
941 g_settings_type_check (GSettingsKeyInfo *info,
944 g_return_val_if_fail (value != NULL, FALSE);
946 return g_variant_is_of_type (value, info->type);
950 g_settings_key_info_range_check (GSettingsKeyInfo *info,
953 if (info->minimum == NULL && info->strinfo == NULL)
956 if (g_variant_is_container (value))
962 g_variant_iter_init (&iter, value);
963 while (ok && (child = g_variant_iter_next_value (&iter)))
965 ok = g_settings_key_info_range_check (info, child);
966 g_variant_unref (child);
974 return g_variant_compare (info->minimum, value) <= 0 &&
975 g_variant_compare (value, info->maximum) <= 0;
978 return strinfo_is_string_valid (info->strinfo,
979 info->strinfo_length,
980 g_variant_get_string (value, NULL));
984 g_settings_range_fixup (GSettingsKeyInfo *info,
989 if (g_settings_key_info_range_check (info, value))
990 return g_variant_ref (value);
992 if (info->strinfo == NULL)
995 if (g_variant_is_container (value))
997 GVariantBuilder builder;
1001 g_variant_iter_init (&iter, value);
1002 g_variant_builder_init (&builder, g_variant_get_type (value));
1004 while ((child = g_variant_iter_next_value (&iter)))
1008 fixed = g_settings_range_fixup (info, child);
1009 g_variant_unref (child);
1013 g_variant_builder_clear (&builder);
1017 g_variant_builder_add_value (&builder, fixed);
1018 g_variant_unref (fixed);
1021 return g_variant_ref_sink (g_variant_builder_end (&builder));
1024 target = strinfo_string_from_alias (info->strinfo, info->strinfo_length,
1025 g_variant_get_string (value, NULL));
1026 return target ? g_variant_ref_sink (g_variant_new_string (target)) : NULL;
1030 g_settings_read_from_backend (GSettingsKeyInfo *info)
1036 path = g_strconcat (info->settings->priv->path, info->key, NULL);
1037 value = g_settings_backend_read (info->settings->priv->backend,
1038 path, info->type, FALSE);
1043 fixup = g_settings_range_fixup (info, value);
1044 g_variant_unref (value);
1053 g_settings_get_translated_default (GSettingsKeyInfo *info)
1055 const gchar *translated;
1056 GError *error = NULL;
1057 const gchar *domain;
1060 if (info->lc_char == '\0')
1061 /* translation not requested for this key */
1064 domain = g_settings_schema_get_gettext_domain (info->settings->priv->schema);
1066 if (info->lc_char == 't')
1067 translated = g_dcgettext (domain, info->unparsed, LC_TIME);
1069 translated = g_dgettext (domain, info->unparsed);
1071 if (translated == info->unparsed)
1072 /* the default value was not translated */
1075 /* try to parse the translation of the unparsed default */
1076 value = g_variant_parse (info->type, translated, NULL, NULL, &error);
1080 g_warning ("Failed to parse translated string `%s' for "
1081 "key `%s' in schema `%s': %s", info->unparsed, info->key,
1082 info->settings->priv->schema_name, error->message);
1083 g_warning ("Using untranslated default instead.");
1084 g_error_free (error);
1087 else if (!g_settings_key_info_range_check (info, value))
1089 g_warning ("Translated default `%s' for key `%s' in schema `%s' "
1090 "is outside of valid range", info->unparsed, info->key,
1091 info->settings->priv->schema_name);
1092 g_variant_unref (value);
1100 g_settings_to_enum (GSettingsKeyInfo *info,
1106 it_worked = strinfo_enum_from_string (info->strinfo, info->strinfo_length,
1107 g_variant_get_string (value, NULL),
1110 /* 'value' can only come from the backend after being filtered for validity,
1111 * from the translation after being filtered for validity, or from the schema
1112 * itself (which the schema compiler checks for validity). If this assertion
1113 * fails then it's really a bug in GSettings or the schema compiler...
1115 g_assert (it_worked);
1121 g_settings_from_enum (GSettingsKeyInfo *info,
1124 const gchar *string;
1126 string = strinfo_string_from_enum (info->strinfo,
1127 info->strinfo_length,
1133 return g_variant_new_string (string);
1137 g_settings_to_flags (GSettingsKeyInfo *info,
1145 g_variant_iter_init (&iter, value);
1146 while (g_variant_iter_next (&iter, "&s", &flag))
1151 it_worked = strinfo_enum_from_string (info->strinfo,
1152 info->strinfo_length,
1154 /* as in g_settings_to_enum() */
1155 g_assert (it_worked);
1157 result |= flag_value;
1164 g_settings_from_flags (GSettingsKeyInfo *info,
1167 GVariantBuilder builder;
1170 g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
1172 for (i = 0; i < 32; i++)
1173 if (value & (1u << i))
1175 const gchar *string;
1177 string = strinfo_string_from_enum (info->strinfo,
1178 info->strinfo_length,
1183 g_variant_builder_clear (&builder);
1187 g_variant_builder_add (&builder, "s", string);
1190 return g_variant_builder_end (&builder);
1193 /* Public Get/Set API {{{1 (get, get_value, set, set_value, get_mapped) */
1195 * g_settings_get_value:
1196 * @settings: a #GSettings object
1197 * @key: the key to get the value for
1198 * @returns: a new #GVariant
1200 * Gets the value that is stored in @settings for @key.
1202 * It is a programmer error to give a @key that isn't contained in the
1203 * schema for @settings.
1208 g_settings_get_value (GSettings *settings,
1211 GSettingsKeyInfo info;
1214 g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
1215 g_return_val_if_fail (key != NULL, NULL);
1217 g_settings_get_key_info (&info, settings, key);
1218 value = g_settings_read_from_backend (&info);
1221 value = g_settings_get_translated_default (&info);
1224 value = g_variant_ref (info.default_value);
1226 g_settings_free_key_info (&info);
1232 * g_settings_get_enum:
1233 * @settings: a #GSettings object
1234 * @key: the key to get the value for
1235 * @returns: the enum value
1237 * Gets the value that is stored in @settings for @key and converts it
1238 * to the enum value that it represents.
1240 * In order to use this function the type of the value must be a string
1241 * and it must be marked in the schema file as an enumerated type.
1243 * It is a programmer error to give a @key that isn't contained in the
1244 * schema for @settings or is not marked as an enumerated type.
1246 * If the value stored in the configuration database is not a valid
1247 * value for the enumerated type then this function will return the
1253 g_settings_get_enum (GSettings *settings,
1256 GSettingsKeyInfo info;
1260 g_return_val_if_fail (G_IS_SETTINGS (settings), -1);
1261 g_return_val_if_fail (key != NULL, -1);
1263 g_settings_get_key_info (&info, settings, key);
1267 g_critical ("g_settings_get_enum() called on key `%s' which is not "
1268 "associated with an enumerated type", info.key);
1269 g_settings_free_key_info (&info);
1273 value = g_settings_read_from_backend (&info);
1276 value = g_settings_get_translated_default (&info);
1279 value = g_variant_ref (info.default_value);
1281 result = g_settings_to_enum (&info, value);
1282 g_settings_free_key_info (&info);
1283 g_variant_unref (value);
1289 * g_settings_set_enum:
1290 * @settings: a #GSettings object
1291 * @key: a key, within @settings
1292 * @value: an enumerated value
1293 * @returns: %TRUE, if the set succeeds
1295 * Looks up the enumerated type nick for @value and writes it to @key,
1298 * It is a programmer error to give a @key that isn't contained in the
1299 * schema for @settings or is not marked as an enumerated type, or for
1300 * @value not to be a valid value for the named type.
1302 * After performing the write, accessing @key directly with
1303 * g_settings_get_string() will return the 'nick' associated with
1307 g_settings_set_enum (GSettings *settings,
1311 GSettingsKeyInfo info;
1315 g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
1316 g_return_val_if_fail (key != NULL, FALSE);
1318 g_settings_get_key_info (&info, settings, key);
1322 g_critical ("g_settings_set_enum() called on key `%s' which is not "
1323 "associated with an enumerated type", info.key);
1327 if (!(variant = g_settings_from_enum (&info, value)))
1329 g_critical ("g_settings_set_enum(): invalid enum value %d for key `%s' "
1330 "in schema `%s'. Doing nothing.", value, info.key,
1331 info.settings->priv->schema_name);
1332 g_settings_free_key_info (&info);
1336 success = g_settings_write_to_backend (&info, variant);
1337 g_settings_free_key_info (&info);
1343 * g_settings_get_flags:
1344 * @settings: a #GSettings object
1345 * @key: the key to get the value for
1346 * @returns: the flags value
1348 * Gets the value that is stored in @settings for @key and converts it
1349 * to the flags value that it represents.
1351 * In order to use this function the type of the value must be an array
1352 * of strings and it must be marked in the schema file as an flags type.
1354 * It is a programmer error to give a @key that isn't contained in the
1355 * schema for @settings or is not marked as a flags type.
1357 * If the value stored in the configuration database is not a valid
1358 * value for the flags type then this function will return the default
1364 g_settings_get_flags (GSettings *settings,
1367 GSettingsKeyInfo info;
1371 g_return_val_if_fail (G_IS_SETTINGS (settings), -1);
1372 g_return_val_if_fail (key != NULL, -1);
1374 g_settings_get_key_info (&info, settings, key);
1378 g_critical ("g_settings_get_flags() called on key `%s' which is not "
1379 "associated with a flags type", info.key);
1380 g_settings_free_key_info (&info);
1384 value = g_settings_read_from_backend (&info);
1387 value = g_settings_get_translated_default (&info);
1390 value = g_variant_ref (info.default_value);
1392 result = g_settings_to_flags (&info, value);
1393 g_settings_free_key_info (&info);
1394 g_variant_unref (value);
1400 * g_settings_set_flags:
1401 * @settings: a #GSettings object
1402 * @key: a key, within @settings
1403 * @value: a flags value
1404 * @returns: %TRUE, if the set succeeds
1406 * Looks up the flags type nicks for the bits specified by @value, puts
1407 * them in an array of strings and writes the array to @key, withing
1410 * It is a programmer error to give a @key that isn't contained in the
1411 * schema for @settings or is not marked as a flags type, or for @value
1412 * to contain any bits that are not value for the named type.
1414 * After performing the write, accessing @key directly with
1415 * g_settings_get_strv() will return an array of 'nicks'; one for each
1419 g_settings_set_flags (GSettings *settings,
1423 GSettingsKeyInfo info;
1427 g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
1428 g_return_val_if_fail (key != NULL, FALSE);
1430 g_settings_get_key_info (&info, settings, key);
1434 g_critical ("g_settings_set_flags() called on key `%s' which is not "
1435 "associated with a flags type", info.key);
1439 if (!(variant = g_settings_from_flags (&info, value)))
1441 g_critical ("g_settings_set_flags(): invalid flags value 0x%08x "
1442 "for key `%s' in schema `%s'. Doing nothing.",
1443 value, info.key, info.settings->priv->schema_name);
1444 g_settings_free_key_info (&info);
1448 success = g_settings_write_to_backend (&info, variant);
1449 g_settings_free_key_info (&info);
1455 * g_settings_set_value:
1456 * @settings: a #GSettings object
1457 * @key: the name of the key to set
1458 * @value: a #GVariant of the correct type
1459 * @returns: %TRUE if setting the key succeeded,
1460 * %FALSE if the key was not writable
1462 * Sets @key in @settings to @value.
1464 * It is a programmer error to give a @key that isn't contained in the
1465 * schema for @settings or for @value to have the incorrect type, per
1468 * If @value is floating then this function consumes the reference.
1473 g_settings_set_value (GSettings *settings,
1477 GSettingsKeyInfo info;
1479 g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
1480 g_return_val_if_fail (key != NULL, FALSE);
1482 g_settings_get_key_info (&info, settings, key);
1484 if (!g_settings_type_check (&info, value))
1486 g_critical ("g_settings_set_value: key '%s' in '%s' expects type '%s', but a GVariant of type '%s' was given",
1488 settings->priv->schema_name,
1489 g_variant_type_peek_string (info.type),
1490 g_variant_get_type_string (value));
1495 if (!g_settings_key_info_range_check (&info, value))
1497 g_warning ("g_settings_set_value: value for key '%s' in schema '%s' "
1498 "is outside of valid range",
1500 settings->priv->schema_name);
1505 g_settings_free_key_info (&info);
1507 return g_settings_write_to_backend (&info, value);
1512 * @settings: a #GSettings object
1513 * @key: the key to get the value for
1514 * @format: a #GVariant format string
1515 * @...: arguments as per @format
1517 * Gets the value that is stored at @key in @settings.
1519 * A convenience function that combines g_settings_get_value() with
1522 * It is a programmer error to give a @key that isn't contained in the
1523 * schema for @settings or for the #GVariantType of @format to mismatch
1524 * the type given in the schema.
1529 g_settings_get (GSettings *settings,
1531 const gchar *format,
1537 value = g_settings_get_value (settings, key);
1539 va_start (ap, format);
1540 g_variant_get_va (value, format, NULL, &ap);
1543 g_variant_unref (value);
1548 * @settings: a #GSettings object
1549 * @key: the name of the key to set
1550 * @format: a #GVariant format string
1551 * @...: arguments as per @format
1552 * @returns: %TRUE if setting the key succeeded,
1553 * %FALSE if the key was not writable
1555 * Sets @key in @settings to @value.
1557 * A convenience function that combines g_settings_set_value() with
1560 * It is a programmer error to give a @key that isn't contained in the
1561 * schema for @settings or for the #GVariantType of @format to mismatch
1562 * the type given in the schema.
1567 g_settings_set (GSettings *settings,
1569 const gchar *format,
1575 va_start (ap, format);
1576 value = g_variant_new_va (format, NULL, &ap);
1579 return g_settings_set_value (settings, key, value);
1583 * g_settings_get_mapped:
1584 * @settings: a #GSettings object
1585 * @key: the key to get the value for
1586 * @mapping: the function to map the value in the settings database to
1587 * the value used by the application
1588 * @user_data: user data for @mapping
1589 * @returns: (transfer full): the result, which may be %NULL
1591 * Gets the value that is stored at @key in @settings, subject to
1592 * application-level validation/mapping.
1594 * You should use this function when the application needs to perform
1595 * some processing on the value of the key (for example, parsing). The
1596 * @mapping function performs that processing. If the function
1597 * indicates that the processing was unsuccessful (due to a parse error,
1598 * for example) then the mapping is tried again with another value.
1600 * This allows a robust 'fall back to defaults' behaviour to be
1601 * implemented somewhat automatically.
1603 * The first value that is tried is the user's setting for the key. If
1604 * the mapping function fails to map this value, other values may be
1605 * tried in an unspecified order (system or site defaults, translated
1606 * schema default values, untranslated schema default values, etc).
1608 * If the mapping function fails for all possible values, one additional
1609 * attempt is made: the mapping function is called with a %NULL value.
1610 * If the mapping function still indicates failure at this point then
1611 * the application will be aborted.
1613 * The result parameter for the @mapping function is pointed to a
1614 * #gpointer which is initially set to %NULL. The same pointer is given
1615 * to each invocation of @mapping. The final value of that #gpointer is
1616 * what is returned by this function. %NULL is valid; it is returned
1617 * just as any other value would be.
1620 g_settings_get_mapped (GSettings *settings,
1622 GSettingsGetMapping mapping,
1625 gpointer result = NULL;
1626 GSettingsKeyInfo info;
1630 g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
1631 g_return_val_if_fail (key != NULL, NULL);
1632 g_return_val_if_fail (mapping != NULL, NULL);
1634 g_settings_get_key_info (&info, settings, key);
1636 if ((value = g_settings_read_from_backend (&info)))
1638 okay = mapping (value, &result, user_data);
1639 g_variant_unref (value);
1640 if (okay) goto okay;
1643 if ((value = g_settings_get_translated_default (&info)))
1645 okay = mapping (value, &result, user_data);
1646 g_variant_unref (value);
1647 if (okay) goto okay;
1650 if (mapping (info.default_value, &result, user_data))
1653 if (!mapping (NULL, &result, user_data))
1654 g_error ("The mapping function given to g_settings_get_mapped() for key "
1655 "`%s' in schema `%s' returned FALSE when given a NULL value.",
1656 key, settings->priv->schema_name);
1659 g_settings_free_key_info (&info);
1664 /* Convenience API (get, set_string, int, double, boolean, strv) {{{1 */
1666 * g_settings_get_string:
1667 * @settings: a #GSettings object
1668 * @key: the key to get the value for
1669 * @returns: a newly-allocated string
1671 * Gets the value that is stored at @key in @settings.
1673 * A convenience variant of g_settings_get() for strings.
1675 * It is a programmer error to give a @key that isn't specified as
1676 * having a string type in the schema for @settings.
1681 g_settings_get_string (GSettings *settings,
1687 value = g_settings_get_value (settings, key);
1688 result = g_variant_dup_string (value, NULL);
1689 g_variant_unref (value);
1695 * g_settings_set_string:
1696 * @settings: a #GSettings object
1697 * @key: the name of the key to set
1698 * @value: the value to set it to
1699 * @returns: %TRUE if setting the key succeeded,
1700 * %FALSE if the key was not writable
1702 * Sets @key in @settings to @value.
1704 * A convenience variant of g_settings_set() for strings.
1706 * It is a programmer error to give a @key that isn't specified as
1707 * having a string type in the schema for @settings.
1712 g_settings_set_string (GSettings *settings,
1716 return g_settings_set_value (settings, key, g_variant_new_string (value));
1720 * g_settings_get_int:
1721 * @settings: a #GSettings object
1722 * @key: the key to get the value for
1723 * @returns: an integer
1725 * Gets the value that is stored at @key in @settings.
1727 * A convenience variant of g_settings_get() for 32-bit integers.
1729 * It is a programmer error to give a @key that isn't specified as
1730 * having a int32 type in the schema for @settings.
1735 g_settings_get_int (GSettings *settings,
1741 value = g_settings_get_value (settings, key);
1742 result = g_variant_get_int32 (value);
1743 g_variant_unref (value);
1749 * g_settings_set_int:
1750 * @settings: a #GSettings object
1751 * @key: the name of the key to set
1752 * @value: the value to set it to
1753 * @returns: %TRUE if setting the key succeeded,
1754 * %FALSE if the key was not writable
1756 * Sets @key in @settings to @value.
1758 * A convenience variant of g_settings_set() for 32-bit integers.
1760 * It is a programmer error to give a @key that isn't specified as
1761 * having a int32 type in the schema for @settings.
1766 g_settings_set_int (GSettings *settings,
1770 return g_settings_set_value (settings, key, g_variant_new_int32 (value));
1774 * g_settings_get_double:
1775 * @settings: a #GSettings object
1776 * @key: the key to get the value for
1777 * @returns: a double
1779 * Gets the value that is stored at @key in @settings.
1781 * A convenience variant of g_settings_get() for doubles.
1783 * It is a programmer error to give a @key that isn't specified as
1784 * having a 'double' type in the schema for @settings.
1789 g_settings_get_double (GSettings *settings,
1795 value = g_settings_get_value (settings, key);
1796 result = g_variant_get_double (value);
1797 g_variant_unref (value);
1803 * g_settings_set_double:
1804 * @settings: a #GSettings object
1805 * @key: the name of the key to set
1806 * @value: the value to set it to
1807 * @returns: %TRUE if setting the key succeeded,
1808 * %FALSE if the key was not writable
1810 * Sets @key in @settings to @value.
1812 * A convenience variant of g_settings_set() for doubles.
1814 * It is a programmer error to give a @key that isn't specified as
1815 * having a 'double' type in the schema for @settings.
1820 g_settings_set_double (GSettings *settings,
1824 return g_settings_set_value (settings, key, g_variant_new_double (value));
1828 * g_settings_get_boolean:
1829 * @settings: a #GSettings object
1830 * @key: the key to get the value for
1831 * @returns: a boolean
1833 * Gets the value that is stored at @key in @settings.
1835 * A convenience variant of g_settings_get() for booleans.
1837 * It is a programmer error to give a @key that isn't specified as
1838 * having a boolean type in the schema for @settings.
1843 g_settings_get_boolean (GSettings *settings,
1849 value = g_settings_get_value (settings, key);
1850 result = g_variant_get_boolean (value);
1851 g_variant_unref (value);
1857 * g_settings_set_boolean:
1858 * @settings: a #GSettings object
1859 * @key: the name of the key to set
1860 * @value: the value to set it to
1861 * @returns: %TRUE if setting the key succeeded,
1862 * %FALSE if the key was not writable
1864 * Sets @key in @settings to @value.
1866 * A convenience variant of g_settings_set() for booleans.
1868 * It is a programmer error to give a @key that isn't specified as
1869 * having a boolean type in the schema for @settings.
1874 g_settings_set_boolean (GSettings *settings,
1878 return g_settings_set_value (settings, key, g_variant_new_boolean (value));
1882 * g_settings_get_strv:
1883 * @settings: a #GSettings object
1884 * @key: the key to get the value for
1885 * @returns: a newly-allocated, %NULL-terminated array of strings
1887 * A convenience variant of g_settings_get() for string arrays.
1889 * It is a programmer error to give a @key that isn't specified as
1890 * having an array of strings type in the schema for @settings.
1892 * Returns: (array zero-terminated=1) (transfer full): the value that is
1893 * stored at @key in @settings.
1898 g_settings_get_strv (GSettings *settings,
1904 value = g_settings_get_value (settings, key);
1905 result = g_variant_dup_strv (value, NULL);
1906 g_variant_unref (value);
1912 * g_settings_set_strv:
1913 * @settings: a #GSettings object
1914 * @key: the name of the key to set
1915 * @value: (allow-none) (array zero-terminated=1): the value to set it to, or %NULL
1916 * @returns: %TRUE if setting the key succeeded,
1917 * %FALSE if the key was not writable
1919 * Sets @key in @settings to @value.
1921 * A convenience variant of g_settings_set() for string arrays. If
1922 * @value is %NULL, then @key is set to be the empty array.
1924 * It is a programmer error to give a @key that isn't specified as
1925 * having an array of strings type in the schema for @settings.
1930 g_settings_set_strv (GSettings *settings,
1932 const gchar * const *value)
1937 array = g_variant_new_strv (value, -1);
1939 array = g_variant_new_strv (NULL, 0);
1941 return g_settings_set_value (settings, key, array);
1944 /* Delayed apply (delay, apply, revert, get_has_unapplied) {{{1 */
1947 * @settings: a #GSettings object
1949 * Changes the #GSettings object into 'delay-apply' mode. In this
1950 * mode, changes to @settings are not immediately propagated to the
1951 * backend, but kept locally until g_settings_apply() is called.
1956 g_settings_delay (GSettings *settings)
1958 g_return_if_fail (G_IS_SETTINGS (settings));
1960 if (settings->priv->delayed)
1963 settings->priv->delayed =
1964 g_delayed_settings_backend_new (settings->priv->backend,
1966 settings->priv->main_context);
1967 g_settings_backend_unwatch (settings->priv->backend, G_OBJECT (settings));
1968 g_object_unref (settings->priv->backend);
1970 settings->priv->backend = G_SETTINGS_BACKEND (settings->priv->delayed);
1971 g_settings_backend_watch (settings->priv->backend,
1972 &listener_vtable, G_OBJECT (settings),
1973 settings->priv->main_context);
1978 * @settings: a #GSettings instance
1980 * Applies any changes that have been made to the settings. This
1981 * function does nothing unless @settings is in 'delay-apply' mode;
1982 * see g_settings_delay(). In the normal case settings are always
1983 * applied immediately.
1986 g_settings_apply (GSettings *settings)
1988 if (settings->priv->delayed)
1990 GDelayedSettingsBackend *delayed;
1992 delayed = G_DELAYED_SETTINGS_BACKEND (settings->priv->backend);
1993 g_delayed_settings_backend_apply (delayed);
1998 * g_settings_revert:
1999 * @settings: a #GSettings instance
2001 * Reverts all non-applied changes to the settings. This function
2002 * does nothing unless @settings is in 'delay-apply' mode; see
2003 * g_settings_delay(). In the normal case settings are always applied
2006 * Change notifications will be emitted for affected keys.
2009 g_settings_revert (GSettings *settings)
2011 if (settings->priv->delayed)
2013 GDelayedSettingsBackend *delayed;
2015 delayed = G_DELAYED_SETTINGS_BACKEND (settings->priv->backend);
2016 g_delayed_settings_backend_revert (delayed);
2021 * g_settings_get_has_unapplied:
2022 * @settings: a #GSettings object
2023 * @returns: %TRUE if @settings has unapplied changes
2025 * Returns whether the #GSettings object has any unapplied
2026 * changes. This can only be the case if it is in 'delayed-apply' mode.
2031 g_settings_get_has_unapplied (GSettings *settings)
2033 g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
2035 return settings->priv->delayed &&
2036 g_delayed_settings_backend_get_has_unapplied (
2037 G_DELAYED_SETTINGS_BACKEND (settings->priv->backend));
2040 /* Extra API (reset, sync, get_child, is_writable, list_*, ranges) {{{1 */
2043 * @settings: a #GSettings object
2044 * @key: the name of a key
2046 * Resets @key to its default value.
2048 * This call resets the key, as much as possible, to its default value.
2049 * That might the value specified in the schema or the one set by the
2053 g_settings_reset (GSettings *settings,
2058 path = g_strconcat (settings->priv->path, key, NULL);
2059 g_settings_backend_reset (settings->priv->backend, path, NULL);
2066 * Ensures that all pending operations for the given are complete for
2067 * the default backend.
2069 * Writes made to a #GSettings are handled asynchronously. For this
2070 * reason, it is very unlikely that the changes have it to disk by the
2071 * time g_settings_set() returns.
2073 * This call will block until all of the writes have made it to the
2074 * backend. Since the mainloop is not running, no change notifications
2075 * will be dispatched during this call (but some may be queued by the
2076 * time the call is done).
2079 g_settings_sync (void)
2081 g_settings_backend_sync_default ();
2085 * g_settings_is_writable:
2086 * @settings: a #GSettings object
2087 * @name: the name of a key
2088 * @returns: %TRUE if the key @name is writable
2090 * Finds out if a key can be written or not
2095 g_settings_is_writable (GSettings *settings,
2101 g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
2103 path = g_strconcat (settings->priv->path, name, NULL);
2104 writable = g_settings_backend_get_writable (settings->priv->backend, path);
2111 * g_settings_get_child:
2112 * @settings: a #GSettings object
2113 * @name: the name of the 'child' schema
2114 * @returns: (transfer full): a 'child' settings object
2116 * Creates a 'child' settings object which has a base path of
2117 * <replaceable>base-path</replaceable>/@name", where
2118 * <replaceable>base-path</replaceable> is the base path of @settings.
2120 * The schema for the child settings object must have been declared
2121 * in the schema of @settings using a <tag class="starttag">child</tag> element.
2126 g_settings_get_child (GSettings *settings,
2129 const gchar *child_schema;
2134 g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
2136 child_name = g_strconcat (name, "/", NULL);
2137 child_schema = g_settings_schema_get_string (settings->priv->schema,
2139 if (child_schema == NULL)
2140 g_error ("Schema '%s' has no child '%s'",
2141 settings->priv->schema_name, name);
2143 child_path = g_strconcat (settings->priv->path, child_name, NULL);
2144 child = g_object_new (G_TYPE_SETTINGS,
2145 "schema", child_schema,
2148 g_free (child_path);
2149 g_free (child_name);
2155 * g_settings_list_keys:
2156 * @settings: a #GSettings object
2157 * @returns: (transfer full) (element-type utf8): a list of the keys on @settings
2159 * Introspects the list of keys on @settings.
2161 * You should probably not be calling this function from "normal" code
2162 * (since you should already know what keys are in your schema). This
2163 * function is intended for introspection reasons.
2165 * You should free the return value with g_strfreev() when you are done
2169 g_settings_list_keys (GSettings *settings)
2176 keys = g_settings_schema_list (settings->priv->schema, &n_keys);
2177 strv = g_new (gchar *, n_keys + 1);
2178 for (i = j = 0; i < n_keys; i++)
2180 const gchar *key = g_quark_to_string (keys[i]);
2182 if (!g_str_has_suffix (key, "/"))
2183 strv[j++] = g_strdup (key);
2191 * g_settings_list_children:
2192 * @settings: a #GSettings object
2193 * @returns: (transfer full) (element-type utf8): a list of the children on @settings
2195 * Gets the list of children on @settings.
2197 * The list is exactly the list of strings for which it is not an error
2198 * to call g_settings_get_child().
2200 * For GSettings objects that are lists, this value can change at any
2201 * time and you should connect to the "children-changed" signal to watch
2202 * for those changes. Note that there is a race condition here: you may
2203 * request a child after listing it only for it to have been destroyed
2204 * in the meantime. For this reason, g_settings_get_child() may return
2205 * %NULL even for a child that was listed by this function.
2207 * For GSettings objects that are not lists, you should probably not be
2208 * calling this function from "normal" code (since you should already
2209 * know what children are in your schema). This function may still be
2210 * useful there for introspection reasons, however.
2212 * You should free the return value with g_strfreev() when you are done
2216 g_settings_list_children (GSettings *settings)
2223 keys = g_settings_schema_list (settings->priv->schema, &n_keys);
2224 strv = g_new (gchar *, n_keys + 1);
2225 for (i = j = 0; i < n_keys; i++)
2227 const gchar *key = g_quark_to_string (keys[i]);
2229 if (g_str_has_suffix (key, "/"))
2231 gint length = strlen (key);
2233 strv[j] = g_memdup (key, length);
2234 strv[j][length - 1] = '\0';
2244 * g_settings_get_range:
2245 * @settings: a #GSettings
2246 * @key: the key to query the range of
2247 * @returns: a #GVariant describing the range
2249 * Queries the range of a key.
2251 * This function will return a #GVariant that fully describes the range
2252 * of values that are valid for @key.
2254 * The type of #GVariant returned is <literal>(sv)</literal>. The
2255 * string describes the type of range restriction in effect. The type
2256 * and meaning of the value contained in the variant depends on the
2259 * If the string is <literal>'type'</literal> then the variant contains
2260 * an empty array. The element type of that empty array is the expected
2261 * type of value and all values of that type are valid.
2263 * If the string is <literal>'enum'</literal> then the variant contains
2264 * an array enumerating the possible values. Each item in the array is
2265 * a possible valid value and no other values are valid.
2267 * If the string is <literal>'flags'</literal> then the variant contains
2268 * an array. Each item in the array is a value that may appear zero or
2269 * one times in an array to be used as the value for this key. For
2270 * example, if the variant contained the array <literal>['x',
2271 * 'y']</literal> then the valid values for the key would be
2272 * <literal>[]</literal>, <literal>['x']</literal>,
2273 * <literal>['y']</literal>, <literal>['x', 'y']</literal> and
2274 * <literal>['y', 'x']</literal>.
2276 * Finally, if the string is <literal>'range'</literal> then the variant
2277 * contains a pair of like-typed values -- the minimum and maximum
2278 * permissible values for this key.
2280 * This information should not be used by normal programs. It is
2281 * considered to be a hint for introspection purposes. Normal programs
2282 * should already know what is permitted by their own schema. The
2283 * format may change in any way in the future -- but particularly, new
2284 * forms may be added to the possibilities described above.
2286 * It is a programmer error to give a @key that isn't contained in the
2287 * schema for @settings.
2289 * You should free the returned value with g_variant_unref() when it is
2295 g_settings_get_range (GSettings *settings,
2298 GSettingsKeyInfo info;
2302 g_settings_get_key_info (&info, settings, key);
2306 range = g_variant_new ("(**)", info.minimum, info.maximum);
2309 else if (info.strinfo)
2311 range = strinfo_enumerate (info.strinfo, info.strinfo_length);
2312 type = info.is_flags ? "flags" : "enum";
2316 range = g_variant_new_array (info.type, NULL, 0);
2320 g_settings_free_key_info (&info);
2322 return g_variant_ref_sink (g_variant_new ("(sv)", type, range));
2326 * g_settings_range_check:
2327 * @settings: a #GSettings
2328 * @key: the key to check
2329 * @value: the value to check
2330 * @returns: %TRUE if @value is valid for @key
2332 * Checks if the given @value is of the correct type and within the
2333 * permitted range for @key.
2335 * This API is not intended to be used by normal programs -- they should
2336 * already know what is permitted by their own schemas. This API is
2337 * meant to be used by programs such as editors or commandline tools.
2339 * It is a programmer error to give a @key that isn't contained in the
2340 * schema for @settings.
2345 g_settings_range_check (GSettings *settings,
2349 GSettingsKeyInfo info;
2352 g_settings_get_key_info (&info, settings, key);
2353 good = g_settings_type_check (&info, value) &&
2354 g_settings_key_info_range_check (&info, value);
2355 g_settings_free_key_info (&info);
2363 GSettingsKeyInfo info;
2366 GSettingsBindGetMapping get_mapping;
2367 GSettingsBindSetMapping set_mapping;
2369 GDestroyNotify destroy;
2371 guint writable_handler_id;
2372 guint property_handler_id;
2373 const GParamSpec *property;
2374 guint key_handler_id;
2376 /* prevent recursion */
2381 g_settings_binding_free (gpointer data)
2383 GSettingsBinding *binding = data;
2385 g_assert (!binding->running);
2387 if (binding->writable_handler_id)
2388 g_signal_handler_disconnect (binding->info.settings,
2389 binding->writable_handler_id);
2391 if (binding->key_handler_id)
2392 g_signal_handler_disconnect (binding->info.settings,
2393 binding->key_handler_id);
2395 if (g_signal_handler_is_connected (binding->object,
2396 binding->property_handler_id))
2397 g_signal_handler_disconnect (binding->object,
2398 binding->property_handler_id);
2400 g_settings_free_key_info (&binding->info);
2402 if (binding->destroy)
2403 binding->destroy (binding->user_data);
2405 g_slice_free (GSettingsBinding, binding);
2409 g_settings_binding_quark (const char *property)
2414 tmp = g_strdup_printf ("gsettingsbinding-%s", property);
2415 quark = g_quark_from_string (tmp);
2422 g_settings_binding_key_changed (GSettings *settings,
2426 GSettingsBinding *binding = user_data;
2427 GValue value = { 0, };
2430 g_assert (settings == binding->info.settings);
2431 g_assert (key == binding->info.key);
2433 if (binding->running)
2436 binding->running = TRUE;
2438 g_value_init (&value, binding->property->value_type);
2440 variant = g_settings_read_from_backend (&binding->info);
2441 if (variant && !binding->get_mapping (&value, variant, binding->user_data))
2443 /* silently ignore errors in the user's config database */
2444 g_variant_unref (variant);
2448 if (variant == NULL)
2450 variant = g_settings_get_translated_default (&binding->info);
2452 !binding->get_mapping (&value, variant, binding->user_data))
2454 /* flag translation errors with a warning */
2455 g_warning ("Translated default `%s' for key `%s' in schema `%s' "
2456 "was rejected by the binding mapping function",
2457 binding->info.unparsed, binding->info.key,
2458 binding->info.settings->priv->schema_name);
2459 g_variant_unref (variant);
2464 if (variant == NULL)
2466 variant = g_variant_ref (binding->info.default_value);
2467 if (!binding->get_mapping (&value, variant, binding->user_data))
2468 g_error ("The schema default value for key `%s' in schema `%s' "
2469 "was rejected by the binding mapping function.",
2471 binding->info.settings->priv->schema_name);
2474 g_object_set_property (binding->object, binding->property->name, &value);
2475 g_variant_unref (variant);
2476 g_value_unset (&value);
2478 binding->running = FALSE;
2482 g_settings_binding_property_changed (GObject *object,
2483 const GParamSpec *pspec,
2486 GSettingsBinding *binding = user_data;
2487 GValue value = { 0, };
2490 g_assert (object == binding->object);
2491 g_assert (pspec == binding->property);
2493 if (binding->running)
2496 binding->running = TRUE;
2498 g_value_init (&value, pspec->value_type);
2499 g_object_get_property (object, pspec->name, &value);
2500 if ((variant = binding->set_mapping (&value, binding->info.type,
2501 binding->user_data)))
2503 if (g_variant_is_floating (variant))
2504 g_variant_ref_sink (variant);
2506 if (!g_settings_type_check (&binding->info, variant))
2508 g_critical ("binding mapping function for key `%s' returned "
2509 "GVariant of type `%s' when type `%s' was requested",
2510 binding->info.key, g_variant_get_type_string (variant),
2511 g_variant_type_dup_string (binding->info.type));
2515 if (!g_settings_key_info_range_check (&binding->info, variant))
2517 g_critical ("GObject property `%s' on a `%s' object is out of "
2518 "schema-specified range for key `%s' of `%s': %s",
2519 binding->property->name,
2520 g_type_name (binding->property->owner_type),
2522 binding->info.settings->priv->schema_name,
2523 g_variant_print (variant, TRUE));
2527 g_settings_write_to_backend (&binding->info, variant);
2528 g_variant_unref (variant);
2530 g_value_unset (&value);
2532 binding->running = FALSE;
2536 g_settings_bind_invert_boolean_get_mapping (GValue *value,
2540 g_value_set_boolean (value, !g_variant_get_boolean (variant));
2545 g_settings_bind_invert_boolean_set_mapping (const GValue *value,
2546 const GVariantType *expected_type,
2549 return g_variant_new_boolean (!g_value_get_boolean (value));
2554 * @settings: a #GSettings object
2555 * @key: the key to bind
2556 * @object: (type GObject.Object): a #GObject
2557 * @property: the name of the property to bind
2558 * @flags: flags for the binding
2560 * Create a binding between the @key in the @settings object
2561 * and the property @property of @object.
2563 * The binding uses the default GIO mapping functions to map
2564 * between the settings and property values. These functions
2565 * handle booleans, numeric types and string types in a
2566 * straightforward way. Use g_settings_bind_with_mapping() if
2567 * you need a custom mapping, or map between types that are not
2568 * supported by the default mapping functions.
2570 * Unless the @flags include %G_SETTINGS_BIND_NO_SENSITIVITY, this
2571 * function also establishes a binding between the writability of
2572 * @key and the "sensitive" property of @object (if @object has
2573 * a boolean property by that name). See g_settings_bind_writable()
2574 * for more details about writable bindings.
2576 * Note that the lifecycle of the binding is tied to the object,
2577 * and that you can have only one binding per object property.
2578 * If you bind the same property twice on the same object, the second
2579 * binding overrides the first one.
2584 g_settings_bind (GSettings *settings,
2587 const gchar *property,
2588 GSettingsBindFlags flags)
2590 GSettingsBindGetMapping get_mapping = NULL;
2591 GSettingsBindSetMapping set_mapping = NULL;
2593 if (flags & G_SETTINGS_BIND_INVERT_BOOLEAN)
2595 get_mapping = g_settings_bind_invert_boolean_get_mapping;
2596 set_mapping = g_settings_bind_invert_boolean_set_mapping;
2598 /* can't pass this flag to g_settings_bind_with_mapping() */
2599 flags &= ~G_SETTINGS_BIND_INVERT_BOOLEAN;
2602 g_settings_bind_with_mapping (settings, key, object, property, flags,
2603 get_mapping, set_mapping, NULL, NULL);
2607 * g_settings_bind_with_mapping:
2608 * @settings: a #GSettings object
2609 * @key: the key to bind
2610 * @object: (type GObject.Object): a #GObject
2611 * @property: the name of the property to bind
2612 * @flags: flags for the binding
2613 * @get_mapping: a function that gets called to convert values
2614 * from @settings to @object, or %NULL to use the default GIO mapping
2615 * @set_mapping: a function that gets called to convert values
2616 * from @object to @settings, or %NULL to use the default GIO mapping
2617 * @user_data: data that gets passed to @get_mapping and @set_mapping
2618 * @destroy: #GDestroyNotify function for @user_data
2620 * Create a binding between the @key in the @settings object
2621 * and the property @property of @object.
2623 * The binding uses the provided mapping functions to map between
2624 * settings and property values.
2626 * Note that the lifecycle of the binding is tied to the object,
2627 * and that you can have only one binding per object property.
2628 * If you bind the same property twice on the same object, the second
2629 * binding overrides the first one.
2634 g_settings_bind_with_mapping (GSettings *settings,
2637 const gchar *property,
2638 GSettingsBindFlags flags,
2639 GSettingsBindGetMapping get_mapping,
2640 GSettingsBindSetMapping set_mapping,
2642 GDestroyNotify destroy)
2644 GSettingsBinding *binding;
2645 GObjectClass *objectclass;
2646 gchar *detailed_signal;
2647 GQuark binding_quark;
2649 g_return_if_fail (G_IS_SETTINGS (settings));
2650 g_return_if_fail (~flags & G_SETTINGS_BIND_INVERT_BOOLEAN);
2652 objectclass = G_OBJECT_GET_CLASS (object);
2654 binding = g_slice_new0 (GSettingsBinding);
2655 g_settings_get_key_info (&binding->info, settings, key);
2656 binding->object = object;
2657 binding->property = g_object_class_find_property (objectclass, property);
2658 binding->user_data = user_data;
2659 binding->destroy = destroy;
2660 binding->get_mapping = get_mapping ? get_mapping : g_settings_get_mapping;
2661 binding->set_mapping = set_mapping ? set_mapping : g_settings_set_mapping;
2663 if (!(flags & (G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET)))
2664 flags |= G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET;
2666 if (binding->property == NULL)
2668 g_critical ("g_settings_bind: no property '%s' on class '%s'",
2669 property, G_OBJECT_TYPE_NAME (object));
2673 if ((flags & G_SETTINGS_BIND_GET) &&
2674 (binding->property->flags & G_PARAM_WRITABLE) == 0)
2676 g_critical ("g_settings_bind: property '%s' on class '%s' is not "
2677 "writable", property, G_OBJECT_TYPE_NAME (object));
2680 if ((flags & G_SETTINGS_BIND_SET) &&
2681 (binding->property->flags & G_PARAM_READABLE) == 0)
2683 g_critical ("g_settings_bind: property '%s' on class '%s' is not "
2684 "readable", property, G_OBJECT_TYPE_NAME (object));
2688 if (get_mapping == g_settings_bind_invert_boolean_get_mapping)
2690 /* g_settings_bind_invert_boolean_get_mapping() is a private
2691 * function, so if we are here it means that g_settings_bind() was
2692 * called with G_SETTINGS_BIND_INVERT_BOOLEAN.
2694 * Ensure that both sides are boolean.
2697 if (binding->property->value_type != G_TYPE_BOOLEAN)
2699 g_critical ("g_settings_bind: G_SETTINGS_BIND_INVERT_BOOLEAN "
2700 "was specified, but property `%s' on type `%s' has "
2701 "type `%s'", property, G_OBJECT_TYPE_NAME (object),
2702 g_type_name ((binding->property->value_type)));
2706 if (!g_variant_type_equal (binding->info.type, G_VARIANT_TYPE_BOOLEAN))
2708 g_critical ("g_settings_bind: G_SETTINGS_BIND_INVERT_BOOLEAN "
2709 "was specified, but key `%s' on schema `%s' has "
2710 "type `%s'", key, settings->priv->schema_name,
2711 g_variant_type_dup_string (binding->info.type));
2717 else if (((get_mapping == NULL && (flags & G_SETTINGS_BIND_GET)) ||
2718 (set_mapping == NULL && (flags & G_SETTINGS_BIND_SET))) &&
2719 !g_settings_mapping_is_compatible (binding->property->value_type,
2720 binding->info.type))
2722 g_critical ("g_settings_bind: property '%s' on class '%s' has type "
2723 "'%s' which is not compatible with type '%s' of key '%s' "
2724 "on schema '%s'", property, G_OBJECT_TYPE_NAME (object),
2725 g_type_name (binding->property->value_type),
2726 g_variant_type_dup_string (binding->info.type), key,
2727 settings->priv->schema_name);
2731 if ((flags & G_SETTINGS_BIND_SET) &&
2732 (~flags & G_SETTINGS_BIND_NO_SENSITIVITY))
2734 GParamSpec *sensitive;
2736 sensitive = g_object_class_find_property (objectclass, "sensitive");
2738 if (sensitive && sensitive->value_type == G_TYPE_BOOLEAN &&
2739 (sensitive->flags & G_PARAM_WRITABLE))
2740 g_settings_bind_writable (settings, binding->info.key,
2741 object, "sensitive", FALSE);
2744 if (flags & G_SETTINGS_BIND_SET)
2746 detailed_signal = g_strdup_printf ("notify::%s", property);
2747 binding->property_handler_id =
2748 g_signal_connect (object, detailed_signal,
2749 G_CALLBACK (g_settings_binding_property_changed),
2751 g_free (detailed_signal);
2753 if (~flags & G_SETTINGS_BIND_GET)
2754 g_settings_binding_property_changed (object,
2759 if (flags & G_SETTINGS_BIND_GET)
2761 if (~flags & G_SETTINGS_BIND_GET_NO_CHANGES)
2763 detailed_signal = g_strdup_printf ("changed::%s", key);
2764 binding->key_handler_id =
2765 g_signal_connect (settings, detailed_signal,
2766 G_CALLBACK (g_settings_binding_key_changed),
2768 g_free (detailed_signal);
2771 g_settings_binding_key_changed (settings, binding->info.key, binding);
2774 binding_quark = g_settings_binding_quark (property);
2775 g_object_set_qdata_full (object, binding_quark,
2776 binding, g_settings_binding_free);
2779 /* Writability binding {{{1 */
2782 GSettings *settings;
2785 const gchar *property;
2788 } GSettingsWritableBinding;
2791 g_settings_writable_binding_free (gpointer data)
2793 GSettingsWritableBinding *binding = data;
2795 g_signal_handler_disconnect (binding->settings, binding->handler_id);
2796 g_object_unref (binding->settings);
2797 g_slice_free (GSettingsWritableBinding, binding);
2801 g_settings_binding_writable_changed (GSettings *settings,
2805 GSettingsWritableBinding *binding = user_data;
2808 g_assert (settings == binding->settings);
2809 g_assert (key == binding->key);
2811 writable = g_settings_is_writable (settings, key);
2813 if (binding->inverted)
2814 writable = !writable;
2816 g_object_set (binding->object, binding->property, writable, NULL);
2820 * g_settings_bind_writable:
2821 * @settings: a #GSettings object
2822 * @key: the key to bind
2823 * @object: (type GObject.Object):a #GObject
2824 * @property: the name of a boolean property to bind
2825 * @inverted: whether to 'invert' the value
2827 * Create a binding between the writability of @key in the
2828 * @settings object and the property @property of @object.
2829 * The property must be boolean; "sensitive" or "visible"
2830 * properties of widgets are the most likely candidates.
2832 * Writable bindings are always uni-directional; changes of the
2833 * writability of the setting will be propagated to the object
2834 * property, not the other way.
2836 * When the @inverted argument is %TRUE, the binding inverts the
2837 * value as it passes from the setting to the object, i.e. @property
2838 * will be set to %TRUE if the key is <emphasis>not</emphasis>
2841 * Note that the lifecycle of the binding is tied to the object,
2842 * and that you can have only one binding per object property.
2843 * If you bind the same property twice on the same object, the second
2844 * binding overrides the first one.
2849 g_settings_bind_writable (GSettings *settings,
2852 const gchar *property,
2855 GSettingsWritableBinding *binding;
2856 gchar *detailed_signal;
2859 g_return_if_fail (G_IS_SETTINGS (settings));
2861 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), property);
2864 g_critical ("g_settings_bind_writable: no property '%s' on class '%s'",
2865 property, G_OBJECT_TYPE_NAME (object));
2868 if ((pspec->flags & G_PARAM_WRITABLE) == 0)
2870 g_critical ("g_settings_bind_writable: property '%s' on class '%s' is not writable",
2871 property, G_OBJECT_TYPE_NAME (object));
2875 binding = g_slice_new (GSettingsWritableBinding);
2876 binding->settings = g_object_ref (settings);
2877 binding->object = object;
2878 binding->key = g_intern_string (key);
2879 binding->property = g_intern_string (property);
2880 binding->inverted = inverted;
2882 detailed_signal = g_strdup_printf ("writable-changed::%s", key);
2883 binding->handler_id =
2884 g_signal_connect (settings, detailed_signal,
2885 G_CALLBACK (g_settings_binding_writable_changed),
2887 g_free (detailed_signal);
2889 g_object_set_qdata_full (object, g_settings_binding_quark (property),
2890 binding, g_settings_writable_binding_free);
2892 g_settings_binding_writable_changed (settings, binding->key, binding);
2896 * g_settings_unbind:
2897 * @object: the object
2898 * @property: the property whose binding is removed
2900 * Removes an existing binding for @property on @object.
2902 * Note that bindings are automatically removed when the
2903 * object is finalized, so it is rarely necessary to call this
2909 g_settings_unbind (gpointer object,
2910 const gchar *property)
2912 GQuark binding_quark;
2914 binding_quark = g_settings_binding_quark (property);
2915 g_object_set_qdata (object, binding_quark, NULL);
2920 /* vim:set foldmethod=marker: */