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: a 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_string (value, settings->priv->path);
442 case PROP_HAS_UNAPPLIED:
443 g_value_set_boolean (value, g_settings_get_has_unapplied (settings));
447 g_assert_not_reached ();
451 static const GSettingsListenerVTable listener_vtable = {
452 settings_backend_changed,
453 settings_backend_path_changed,
454 settings_backend_keys_changed,
455 settings_backend_writable_changed,
456 settings_backend_path_writable_changed
460 g_settings_constructed (GObject *object)
462 GSettings *settings = G_SETTINGS (object);
463 const gchar *schema_path;
465 settings->priv->schema = g_settings_schema_new (settings->priv->schema_name);
466 schema_path = g_settings_schema_get_path (settings->priv->schema);
468 if (settings->priv->path && schema_path && strcmp (settings->priv->path, schema_path) != 0)
469 g_error ("settings object created with schema '%s' and path '%s', but "
470 "path '%s' is specified by schema",
471 settings->priv->schema_name, settings->priv->path, schema_path);
473 if (settings->priv->path == NULL)
475 if (schema_path == NULL)
476 g_error ("attempting to create schema '%s' without a path",
477 settings->priv->schema_name);
479 settings->priv->path = g_strdup (schema_path);
482 if (settings->priv->backend == NULL)
483 settings->priv->backend = g_settings_backend_get_default ();
485 g_settings_backend_watch (settings->priv->backend,
486 &listener_vtable, G_OBJECT (settings),
487 settings->priv->main_context);
488 g_settings_backend_subscribe (settings->priv->backend,
489 settings->priv->path);
493 g_settings_finalize (GObject *object)
495 GSettings *settings = G_SETTINGS (object);
497 g_settings_backend_unsubscribe (settings->priv->backend,
498 settings->priv->path);
499 g_main_context_unref (settings->priv->main_context);
500 g_object_unref (settings->priv->backend);
501 g_object_unref (settings->priv->schema);
502 g_free (settings->priv->schema_name);
503 g_free (settings->priv->path);
505 G_OBJECT_CLASS (g_settings_parent_class)->finalize (object);
509 g_settings_init (GSettings *settings)
511 settings->priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
515 settings->priv->main_context = g_main_context_get_thread_default ();
517 if (settings->priv->main_context == NULL)
518 settings->priv->main_context = g_main_context_default ();
520 g_main_context_ref (settings->priv->main_context);
524 g_settings_class_init (GSettingsClass *class)
526 GObjectClass *object_class = G_OBJECT_CLASS (class);
528 class->writable_change_event = g_settings_real_writable_change_event;
529 class->change_event = g_settings_real_change_event;
531 object_class->set_property = g_settings_set_property;
532 object_class->get_property = g_settings_get_property;
533 object_class->constructed = g_settings_constructed;
534 object_class->finalize = g_settings_finalize;
536 g_type_class_add_private (object_class, sizeof (GSettingsPrivate));
539 * GSettings::changed:
540 * @settings: the object on which the signal was emitted
541 * @key: the name of the key that changed
543 * The "changed" signal is emitted when a key has potentially changed.
544 * You should call one of the g_settings_get() calls to check the new
547 * This signal supports detailed connections. You can connect to the
548 * detailed signal "changed::x" in order to only receive callbacks
549 * when key "x" changes.
551 g_settings_signals[SIGNAL_CHANGED] =
552 g_signal_new ("changed", G_TYPE_SETTINGS,
553 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
554 G_STRUCT_OFFSET (GSettingsClass, changed),
555 NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE,
556 1, G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
559 * GSettings::change-event:
560 * @settings: the object on which the signal was emitted
561 * @keys: an array of #GQuark<!-- -->s for the changed keys, or %NULL
562 * @n_keys: the length of the @keys array, or 0
563 * @returns: %TRUE to stop other handlers from being invoked for the
564 * event. FALSE to propagate the event further.
566 * The "change-event" signal is emitted once per change event that
567 * affects this settings object. You should connect to this signal
568 * only if you are interested in viewing groups of changes before they
569 * are split out into multiple emissions of the "changed" signal.
570 * For most use cases it is more appropriate to use the "changed" signal.
572 * In the event that the change event applies to one or more specified
573 * keys, @keys will be an array of #GQuark of length @n_keys. In the
574 * event that the change event applies to the #GSettings object as a
575 * whole (ie: potentially every key has been changed) then @keys will
576 * be %NULL and @n_keys will be 0.
578 * The default handler for this signal invokes the "changed" signal
579 * for each affected key. If any other connected handler returns
580 * %TRUE then this default functionality will be supressed.
582 g_settings_signals[SIGNAL_CHANGE_EVENT] =
583 g_signal_new ("change-event", G_TYPE_SETTINGS,
585 G_STRUCT_OFFSET (GSettingsClass, change_event),
586 g_signal_accumulator_true_handled, NULL,
587 _gio_marshal_BOOL__POINTER_INT,
588 G_TYPE_BOOLEAN, 2, G_TYPE_POINTER, G_TYPE_INT);
591 * GSettings::writable-changed:
592 * @settings: the object on which the signal was emitted
595 * The "writable-changed" signal is emitted when the writability of a
596 * key has potentially changed. You should call
597 * g_settings_is_writable() in order to determine the new status.
599 * This signal supports detailed connections. You can connect to the
600 * detailed signal "writable-changed::x" in order to only receive
601 * callbacks when the writability of "x" changes.
603 g_settings_signals[SIGNAL_WRITABLE_CHANGED] =
604 g_signal_new ("writable-changed", G_TYPE_SETTINGS,
605 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
606 G_STRUCT_OFFSET (GSettingsClass, changed),
607 NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE,
608 1, G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
611 * GSettings::writable-change-event:
612 * @settings: the object on which the signal was emitted
613 * @key: the quark of the key, or 0
614 * @returns: %TRUE to stop other handlers from being invoked for the
615 * event. FALSE to propagate the event further.
617 * The "writable-change-event" signal is emitted once per writability
618 * change event that affects this settings object. You should connect
619 * to this signal if you are interested in viewing groups of changes
620 * before they are split out into multiple emissions of the
621 * "writable-changed" signal. For most use cases it is more
622 * appropriate to use the "writable-changed" signal.
624 * In the event that the writability change applies only to a single
625 * key, @key will be set to the #GQuark for that key. In the event
626 * that the writability change affects the entire settings object,
629 * The default handler for this signal invokes the "writable-changed"
630 * and "changed" signals for each affected key. This is done because
631 * changes in writability might also imply changes in value (if for
632 * example, a new mandatory setting is introduced). If any other
633 * connected handler returns %TRUE then this default functionality
636 g_settings_signals[SIGNAL_WRITABLE_CHANGE_EVENT] =
637 g_signal_new ("writable-change-event", G_TYPE_SETTINGS,
639 G_STRUCT_OFFSET (GSettingsClass, writable_change_event),
640 g_signal_accumulator_true_handled, NULL,
641 _gio_marshal_BOOLEAN__UINT, G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
646 * The name of the context that the settings are stored in.
648 g_object_class_install_property (object_class, PROP_BACKEND,
649 g_param_spec_object ("backend",
650 P_("GSettingsBackend"),
651 P_("The GSettingsBackend for this settings object"),
652 G_TYPE_SETTINGS_BACKEND, G_PARAM_CONSTRUCT_ONLY |
653 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
658 * The name of the schema that describes the types of keys
659 * for this #GSettings object.
661 g_object_class_install_property (object_class, PROP_SCHEMA,
662 g_param_spec_string ("schema",
664 P_("The name of the schema for this settings object"),
666 G_PARAM_CONSTRUCT_ONLY |
667 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
672 * The path within the backend where the settings are stored.
674 g_object_class_install_property (object_class, PROP_PATH,
675 g_param_spec_string ("path",
677 P_("The path within the backend where the settings are"),
679 G_PARAM_CONSTRUCT_ONLY |
680 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
683 * GSettings:has-unapplied:
685 * If this property is %TRUE, the #GSettings object has outstanding
686 * changes that will be applied when g_settings_apply() is called.
688 g_object_class_install_property (object_class, PROP_HAS_UNAPPLIED,
689 g_param_spec_boolean ("has-unapplied",
690 P_("Has unapplied changes"),
691 P_("TRUE if there are outstanding changes to apply()"),
693 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
697 /* Construction (new, new_with_path, etc.) {{{1 */
700 * @schema: the name of the schema
701 * @returns: a new #GSettings object
703 * Creates a new #GSettings object with a given schema.
705 * Signals on the newly created #GSettings object will be dispatched
706 * via the thread-default #GMainContext in effect at the time of the
707 * call to g_settings_new(). The new #GSettings will hold a reference
708 * on the context. See g_main_context_push_thread_default().
713 g_settings_new (const gchar *schema)
715 g_return_val_if_fail (schema != NULL, NULL);
717 return g_object_new (G_TYPE_SETTINGS,
723 * g_settings_new_with_path:
724 * @schema: the name of the schema
725 * @path: the path to use
726 * @returns: a new #GSettings object
728 * Creates a new #GSettings object with a given schema and path.
730 * You only need to do this if you want to directly create a settings
731 * object with a schema that doesn't have a specified path of its own.
734 * It is a programmer error to call this function for a schema that
735 * has an explicitly specified path.
740 g_settings_new_with_path (const gchar *schema,
743 g_return_val_if_fail (schema != NULL, NULL);
744 g_return_val_if_fail (path != NULL, NULL);
746 return g_object_new (G_TYPE_SETTINGS,
753 * g_settings_new_with_backend:
754 * @schema: the name of the schema
755 * @backend: the #GSettingsBackend to use
756 * @returns: a new #GSettings object
758 * Creates a new #GSettings object with a given schema and backend.
760 * Creating settings objects with an different backend allows accessing settings
761 * from a database other than the usual one. For example, it may make
762 * sense to pass a backend corresponding to the "defaults" settings database on
763 * the system to get a settings object that modifies the system default
764 * settings instead of the settings for this user.
769 g_settings_new_with_backend (const gchar *schema,
770 GSettingsBackend *backend)
772 g_return_val_if_fail (schema != NULL, NULL);
773 g_return_val_if_fail (G_IS_SETTINGS_BACKEND (backend), NULL);
775 return g_object_new (G_TYPE_SETTINGS,
782 * g_settings_new_with_backend_and_path:
783 * @schema: the name of the schema
784 * @backend: the #GSettingsBackend to use
785 * @path: the path to use
786 * @returns: a new #GSettings object
788 * Creates a new #GSettings object with a given schema, backend and
791 * This is a mix of g_settings_new_with_backend() and
792 * g_settings_new_with_path().
797 g_settings_new_with_backend_and_path (const gchar *schema,
798 GSettingsBackend *backend,
801 g_return_val_if_fail (schema != NULL, NULL);
802 g_return_val_if_fail (G_IS_SETTINGS_BACKEND (backend), NULL);
803 g_return_val_if_fail (path != NULL, NULL);
805 return g_object_new (G_TYPE_SETTINGS,
812 /* Internal read/write utilities, enum/flags conversion, validation {{{1 */
818 GSettingsSchema *schema;
823 const guint32 *strinfo;
824 gsize strinfo_length;
826 const gchar *unparsed;
829 const GVariantType *type;
830 GVariant *minimum, *maximum;
831 GVariant *default_value;
835 endian_fixup (GVariant **value)
837 #if G_BYTE_ORDER == G_BIG_ENDIAN
840 tmp = g_variant_byteswap (*value);
841 g_variant_unref (*value);
847 g_settings_get_key_info (GSettingsKeyInfo *info,
855 memset (info, 0, sizeof *info);
857 iter = g_settings_schema_get_value (settings->priv->schema, key);
859 info->default_value = g_variant_iter_next_value (iter);
860 endian_fixup (&info->default_value);
861 info->type = g_variant_get_type (info->default_value);
862 info->settings = g_object_ref (settings);
863 info->key = g_intern_string (key);
865 while (g_variant_iter_next (iter, "(y*)", &code, &data))
870 /* translation requested */
871 g_variant_get (data, "(y&s)", &info->lc_char, &info->unparsed);
875 /* enumerated types... */
876 info->is_enum = TRUE;
881 info->is_flags = TRUE;
885 /* ..., choices, aliases */
886 info->strinfo = g_variant_get_fixed_array (data,
887 &info->strinfo_length,
892 g_variant_get (data, "(**)", &info->minimum, &info->maximum);
893 endian_fixup (&info->minimum);
894 endian_fixup (&info->maximum);
898 g_warning ("unknown schema extension '%c'", code);
902 g_variant_unref (data);
905 g_variant_iter_free (iter);
909 g_settings_free_key_info (GSettingsKeyInfo *info)
912 g_variant_unref (info->minimum);
915 g_variant_unref (info->maximum);
917 g_variant_unref (info->default_value);
918 g_object_unref (info->settings);
922 g_settings_write_to_backend (GSettingsKeyInfo *info,
928 path = g_strconcat (info->settings->priv->path, info->key, NULL);
929 success = g_settings_backend_write (info->settings->priv->backend,
937 g_settings_type_check (GSettingsKeyInfo *info,
940 g_return_val_if_fail (value != NULL, FALSE);
942 return g_variant_is_of_type (value, info->type);
946 g_settings_key_info_range_check (GSettingsKeyInfo *info,
949 if (info->minimum == NULL && info->strinfo == NULL)
952 if (g_variant_is_container (value))
958 g_variant_iter_init (&iter, value);
959 while (ok && (child = g_variant_iter_next_value (&iter)))
961 ok = g_settings_key_info_range_check (info, child);
962 g_variant_unref (child);
970 return g_variant_compare (info->minimum, value) <= 0 &&
971 g_variant_compare (value, info->maximum) <= 0;
974 return strinfo_is_string_valid (info->strinfo,
975 info->strinfo_length,
976 g_variant_get_string (value, NULL));
980 g_settings_range_fixup (GSettingsKeyInfo *info,
985 if (g_settings_key_info_range_check (info, value))
986 return g_variant_ref (value);
988 if (info->strinfo == NULL)
991 if (g_variant_is_container (value))
993 GVariantBuilder builder;
997 g_variant_iter_init (&iter, value);
998 g_variant_builder_init (&builder, g_variant_get_type (value));
1000 while ((child = g_variant_iter_next_value (&iter)))
1004 fixed = g_settings_range_fixup (info, child);
1005 g_variant_unref (child);
1009 g_variant_builder_clear (&builder);
1013 g_variant_builder_add_value (&builder, fixed);
1014 g_variant_unref (fixed);
1017 return g_variant_ref_sink (g_variant_builder_end (&builder));
1020 target = strinfo_string_from_alias (info->strinfo, info->strinfo_length,
1021 g_variant_get_string (value, NULL));
1022 return target ? g_variant_ref_sink (g_variant_new_string (target)) : NULL;
1026 g_settings_read_from_backend (GSettingsKeyInfo *info)
1032 path = g_strconcat (info->settings->priv->path, info->key, NULL);
1033 value = g_settings_backend_read (info->settings->priv->backend,
1034 path, info->type, FALSE);
1039 fixup = g_settings_range_fixup (info, value);
1040 g_variant_unref (value);
1049 g_settings_get_translated_default (GSettingsKeyInfo *info)
1051 const gchar *translated;
1052 GError *error = NULL;
1053 const gchar *domain;
1056 if (info->lc_char == '\0')
1057 /* translation not requested for this key */
1060 domain = g_settings_schema_get_gettext_domain (info->settings->priv->schema);
1062 if (info->lc_char == 't')
1063 translated = g_dcgettext (domain, info->unparsed, LC_TIME);
1065 translated = g_dgettext (domain, info->unparsed);
1067 if (translated == info->unparsed)
1068 /* the default value was not translated */
1071 /* try to parse the translation of the unparsed default */
1072 value = g_variant_parse (info->type, translated, NULL, NULL, &error);
1076 g_warning ("Failed to parse translated string `%s' for "
1077 "key `%s' in schema `%s': %s", info->unparsed, info->key,
1078 info->settings->priv->schema_name, error->message);
1079 g_warning ("Using untranslated default instead.");
1080 g_error_free (error);
1083 else if (!g_settings_key_info_range_check (info, value))
1085 g_warning ("Translated default `%s' for key `%s' in schema `%s' "
1086 "is outside of valid range", info->unparsed, info->key,
1087 info->settings->priv->schema_name);
1088 g_variant_unref (value);
1096 g_settings_to_enum (GSettingsKeyInfo *info,
1102 it_worked = strinfo_enum_from_string (info->strinfo, info->strinfo_length,
1103 g_variant_get_string (value, NULL),
1106 /* 'value' can only come from the backend after being filtered for validity,
1107 * from the translation after being filtered for validity, or from the schema
1108 * itself (which the schema compiler checks for validity). If this assertion
1109 * fails then it's really a bug in GSettings or the schema compiler...
1111 g_assert (it_worked);
1117 g_settings_from_enum (GSettingsKeyInfo *info,
1120 const gchar *string;
1122 string = strinfo_string_from_enum (info->strinfo,
1123 info->strinfo_length,
1129 return g_variant_new_string (string);
1133 g_settings_to_flags (GSettingsKeyInfo *info,
1141 g_variant_iter_init (&iter, value);
1142 while (g_variant_iter_next (&iter, "&s", &flag))
1147 it_worked = strinfo_enum_from_string (info->strinfo,
1148 info->strinfo_length,
1150 /* as in g_settings_to_enum() */
1151 g_assert (it_worked);
1153 result |= flag_value;
1160 g_settings_from_flags (GSettingsKeyInfo *info,
1163 GVariantBuilder builder;
1166 g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
1168 for (i = 0; i < 32; i++)
1169 if (value & (1u << i))
1171 const gchar *string;
1173 string = strinfo_string_from_enum (info->strinfo,
1174 info->strinfo_length,
1179 g_variant_builder_clear (&builder);
1183 g_variant_builder_add (&builder, "s", string);
1186 return g_variant_builder_end (&builder);
1189 /* Public Get/Set API {{{1 (get, get_value, set, set_value, get_mapped) */
1191 * g_settings_get_value:
1192 * @settings: a #GSettings object
1193 * @key: the key to get the value for
1194 * @returns: a new #GVariant
1196 * Gets the value that is stored in @settings for @key.
1198 * It is a programmer error to give a @key that isn't contained in the
1199 * schema for @settings.
1204 g_settings_get_value (GSettings *settings,
1207 GSettingsKeyInfo info;
1210 g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
1211 g_return_val_if_fail (key != NULL, NULL);
1213 g_settings_get_key_info (&info, settings, key);
1214 value = g_settings_read_from_backend (&info);
1217 value = g_settings_get_translated_default (&info);
1220 value = g_variant_ref (info.default_value);
1222 g_settings_free_key_info (&info);
1228 * g_settings_get_enum:
1229 * @settings: a #GSettings object
1230 * @key: the key to get the value for
1231 * @returns: the enum value
1233 * Gets the value that is stored in @settings for @key and converts it
1234 * to the enum value that it represents.
1236 * In order to use this function the type of the value must be a string
1237 * and it must be marked in the schema file as an enumerated type.
1239 * It is a programmer error to give a @key that isn't contained in the
1240 * schema for @settings or is not marked as an enumerated type.
1242 * If the value stored in the configuration database is not a valid
1243 * value for the enumerated type then this function will return the
1249 g_settings_get_enum (GSettings *settings,
1252 GSettingsKeyInfo info;
1256 g_return_val_if_fail (G_IS_SETTINGS (settings), -1);
1257 g_return_val_if_fail (key != NULL, -1);
1259 g_settings_get_key_info (&info, settings, key);
1263 g_critical ("g_settings_get_enum() called on key `%s' which is not "
1264 "associated with an enumerated type", info.key);
1265 g_settings_free_key_info (&info);
1269 value = g_settings_read_from_backend (&info);
1272 value = g_settings_get_translated_default (&info);
1275 value = g_variant_ref (info.default_value);
1277 result = g_settings_to_enum (&info, value);
1278 g_settings_free_key_info (&info);
1279 g_variant_unref (value);
1285 * g_settings_set_enum:
1286 * @settings: a #GSettings object
1287 * @key: a key, within @settings
1288 * @value: an enumerated value
1289 * @returns: %TRUE, if the set succeeds
1291 * Looks up the enumerated type nick for @value and writes it to @key,
1294 * It is a programmer error to give a @key that isn't contained in the
1295 * schema for @settings or is not marked as an enumerated type, or for
1296 * @value not to be a valid value for the named type.
1298 * After performing the write, accessing @key directly with
1299 * g_settings_get_string() will return the 'nick' associated with
1303 g_settings_set_enum (GSettings *settings,
1307 GSettingsKeyInfo info;
1311 g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
1312 g_return_val_if_fail (key != NULL, FALSE);
1314 g_settings_get_key_info (&info, settings, key);
1318 g_critical ("g_settings_set_enum() called on key `%s' which is not "
1319 "associated with an enumerated type", info.key);
1323 if (!(variant = g_settings_from_enum (&info, value)))
1325 g_critical ("g_settings_set_enum(): invalid enum value %d for key `%s' "
1326 "in schema `%s'. Doing nothing.", value, info.key,
1327 info.settings->priv->schema_name);
1328 g_settings_free_key_info (&info);
1332 success = g_settings_write_to_backend (&info, variant);
1333 g_settings_free_key_info (&info);
1339 * g_settings_get_flags:
1340 * @settings: a #GSettings object
1341 * @key: the key to get the value for
1342 * @returns: the flags value
1344 * Gets the value that is stored in @settings for @key and converts it
1345 * to the flags value that it represents.
1347 * In order to use this function the type of the value must be an array
1348 * of strings and it must be marked in the schema file as an flags type.
1350 * It is a programmer error to give a @key that isn't contained in the
1351 * schema for @settings or is not marked as a flags type.
1353 * If the value stored in the configuration database is not a valid
1354 * value for the flags type then this function will return the default
1360 g_settings_get_flags (GSettings *settings,
1363 GSettingsKeyInfo info;
1367 g_return_val_if_fail (G_IS_SETTINGS (settings), -1);
1368 g_return_val_if_fail (key != NULL, -1);
1370 g_settings_get_key_info (&info, settings, key);
1374 g_critical ("g_settings_get_flags() called on key `%s' which is not "
1375 "associated with a flags type", info.key);
1376 g_settings_free_key_info (&info);
1380 value = g_settings_read_from_backend (&info);
1383 value = g_settings_get_translated_default (&info);
1386 value = g_variant_ref (info.default_value);
1388 result = g_settings_to_flags (&info, value);
1389 g_settings_free_key_info (&info);
1390 g_variant_unref (value);
1396 * g_settings_set_flags:
1397 * @settings: a #GSettings object
1398 * @key: a key, within @settings
1399 * @value: a flags value
1400 * @returns: %TRUE, if the set succeeds
1402 * Looks up the flags type nicks for the bits specified by @value, puts
1403 * them in an array of strings and writes the array to @key, withing
1406 * It is a programmer error to give a @key that isn't contained in the
1407 * schema for @settings or is not marked as a flags type, or for @value
1408 * to contain any bits that are not value for the named type.
1410 * After performing the write, accessing @key directly with
1411 * g_settings_get_strv() will return an array of 'nicks'; one for each
1415 g_settings_set_flags (GSettings *settings,
1419 GSettingsKeyInfo info;
1423 g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
1424 g_return_val_if_fail (key != NULL, FALSE);
1426 g_settings_get_key_info (&info, settings, key);
1430 g_critical ("g_settings_set_flags() called on key `%s' which is not "
1431 "associated with a flags type", info.key);
1435 if (!(variant = g_settings_from_flags (&info, value)))
1437 g_critical ("g_settings_set_flags(): invalid flags value 0x%08x "
1438 "for key `%s' in schema `%s'. Doing nothing.",
1439 value, info.key, info.settings->priv->schema_name);
1440 g_settings_free_key_info (&info);
1444 success = g_settings_write_to_backend (&info, variant);
1445 g_settings_free_key_info (&info);
1451 * g_settings_set_value:
1452 * @settings: a #GSettings object
1453 * @key: the name of the key to set
1454 * @value: a #GVariant of the correct type
1455 * @returns: %TRUE if setting the key succeeded,
1456 * %FALSE if the key was not writable
1458 * Sets @key in @settings to @value.
1460 * It is a programmer error to give a @key that isn't contained in the
1461 * schema for @settings or for @value to have the incorrect type, per
1464 * If @value is floating then this function consumes the reference.
1469 g_settings_set_value (GSettings *settings,
1473 GSettingsKeyInfo info;
1475 g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
1476 g_return_val_if_fail (key != NULL, FALSE);
1478 g_settings_get_key_info (&info, settings, key);
1480 if (!g_settings_type_check (&info, value))
1482 g_critical ("g_settings_set_value: key '%s' in '%s' expects type '%s', but a GVariant of type '%s' was given",
1484 settings->priv->schema_name,
1485 g_variant_type_peek_string (info.type),
1486 g_variant_get_type_string (value));
1491 if (!g_settings_key_info_range_check (&info, value))
1493 g_warning ("g_settings_set_value: value for key '%s' in schema '%s' "
1494 "is outside of valid range",
1496 settings->priv->schema_name);
1501 g_settings_free_key_info (&info);
1503 return g_settings_write_to_backend (&info, value);
1508 * @settings: a #GSettings object
1509 * @key: the key to get the value for
1510 * @format: a #GVariant format string
1511 * @...: arguments as per @format
1513 * Gets the value that is stored at @key in @settings.
1515 * A convenience function that combines g_settings_get_value() with
1518 * It is a programmer error to give a @key that isn't contained in the
1519 * schema for @settings or for the #GVariantType of @format to mismatch
1520 * the type given in the schema.
1525 g_settings_get (GSettings *settings,
1527 const gchar *format,
1533 value = g_settings_get_value (settings, key);
1535 va_start (ap, format);
1536 g_variant_get_va (value, format, NULL, &ap);
1539 g_variant_unref (value);
1544 * @settings: a #GSettings object
1545 * @key: the name of the key to set
1546 * @format: a #GVariant format string
1547 * @...: arguments as per @format
1548 * @returns: %TRUE if setting the key succeeded,
1549 * %FALSE if the key was not writable
1551 * Sets @key in @settings to @value.
1553 * A convenience function that combines g_settings_set_value() with
1556 * It is a programmer error to give a @key that isn't contained in the
1557 * schema for @settings or for the #GVariantType of @format to mismatch
1558 * the type given in the schema.
1563 g_settings_set (GSettings *settings,
1565 const gchar *format,
1571 va_start (ap, format);
1572 value = g_variant_new_va (format, NULL, &ap);
1575 return g_settings_set_value (settings, key, value);
1579 * g_settings_get_mapped:
1580 * @settings: a #GSettings object
1581 * @key: the key to get the value for
1582 * @mapping: the function to map the value in the settings database to
1583 * the value used by the application
1584 * @user_data: user data for @mapping
1585 * @returns: (transfer full): the result, which may be %NULL
1587 * Gets the value that is stored at @key in @settings, subject to
1588 * application-level validation/mapping.
1590 * You should use this function when the application needs to perform
1591 * some processing on the value of the key (for example, parsing). The
1592 * @mapping function performs that processing. If the function
1593 * indicates that the processing was unsuccessful (due to a parse error,
1594 * for example) then the mapping is tried again with another value.
1596 * This allows a robust 'fall back to defaults' behaviour to be
1597 * implemented somewhat automatically.
1599 * The first value that is tried is the user's setting for the key. If
1600 * the mapping function fails to map this value, other values may be
1601 * tried in an unspecified order (system or site defaults, translated
1602 * schema default values, untranslated schema default values, etc).
1604 * If the mapping function fails for all possible values, one additional
1605 * attempt is made: the mapping function is called with a %NULL value.
1606 * If the mapping function still indicates failure at this point then
1607 * the application will be aborted.
1609 * The result parameter for the @mapping function is pointed to a
1610 * #gpointer which is initially set to %NULL. The same pointer is given
1611 * to each invocation of @mapping. The final value of that #gpointer is
1612 * what is returned by this function. %NULL is valid; it is returned
1613 * just as any other value would be.
1616 g_settings_get_mapped (GSettings *settings,
1618 GSettingsGetMapping mapping,
1621 gpointer result = NULL;
1622 GSettingsKeyInfo info;
1626 g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
1627 g_return_val_if_fail (key != NULL, NULL);
1628 g_return_val_if_fail (mapping != NULL, NULL);
1630 g_settings_get_key_info (&info, settings, key);
1632 if ((value = g_settings_read_from_backend (&info)))
1634 okay = mapping (value, &result, user_data);
1635 g_variant_unref (value);
1636 if (okay) goto okay;
1639 if ((value = g_settings_get_translated_default (&info)))
1641 okay = mapping (value, &result, user_data);
1642 g_variant_unref (value);
1643 if (okay) goto okay;
1646 if (mapping (info.default_value, &result, user_data))
1649 if (!mapping (NULL, &result, user_data))
1650 g_error ("The mapping function given to g_settings_get_mapped() for key "
1651 "`%s' in schema `%s' returned FALSE when given a NULL value.",
1652 key, settings->priv->schema_name);
1655 g_settings_free_key_info (&info);
1660 /* Convenience API (get, set_string, int, double, boolean, strv) {{{1 */
1662 * g_settings_get_string:
1663 * @settings: a #GSettings object
1664 * @key: the key to get the value for
1665 * @returns: a newly-allocated string
1667 * Gets the value that is stored at @key in @settings.
1669 * A convenience variant of g_settings_get() for strings.
1671 * It is a programmer error to give a @key that isn't specified as
1672 * having a string type in the schema for @settings.
1677 g_settings_get_string (GSettings *settings,
1683 value = g_settings_get_value (settings, key);
1684 result = g_variant_dup_string (value, NULL);
1685 g_variant_unref (value);
1691 * g_settings_set_string:
1692 * @settings: a #GSettings object
1693 * @key: the name of the key to set
1694 * @value: the value to set it to
1695 * @returns: %TRUE if setting the key succeeded,
1696 * %FALSE if the key was not writable
1698 * Sets @key in @settings to @value.
1700 * A convenience variant of g_settings_set() for strings.
1702 * It is a programmer error to give a @key that isn't specified as
1703 * having a string type in the schema for @settings.
1708 g_settings_set_string (GSettings *settings,
1712 return g_settings_set_value (settings, key, g_variant_new_string (value));
1716 * g_settings_get_int:
1717 * @settings: a #GSettings object
1718 * @key: the key to get the value for
1719 * @returns: an integer
1721 * Gets the value that is stored at @key in @settings.
1723 * A convenience variant of g_settings_get() for 32-bit integers.
1725 * It is a programmer error to give a @key that isn't specified as
1726 * having a int32 type in the schema for @settings.
1731 g_settings_get_int (GSettings *settings,
1737 value = g_settings_get_value (settings, key);
1738 result = g_variant_get_int32 (value);
1739 g_variant_unref (value);
1745 * g_settings_set_int:
1746 * @settings: a #GSettings object
1747 * @key: the name of the key to set
1748 * @value: the value to set it to
1749 * @returns: %TRUE if setting the key succeeded,
1750 * %FALSE if the key was not writable
1752 * Sets @key in @settings to @value.
1754 * A convenience variant of g_settings_set() for 32-bit integers.
1756 * It is a programmer error to give a @key that isn't specified as
1757 * having a int32 type in the schema for @settings.
1762 g_settings_set_int (GSettings *settings,
1766 return g_settings_set_value (settings, key, g_variant_new_int32 (value));
1770 * g_settings_get_double:
1771 * @settings: a #GSettings object
1772 * @key: the key to get the value for
1773 * @returns: a double
1775 * Gets the value that is stored at @key in @settings.
1777 * A convenience variant of g_settings_get() for doubles.
1779 * It is a programmer error to give a @key that isn't specified as
1780 * having a 'double' type in the schema for @settings.
1785 g_settings_get_double (GSettings *settings,
1791 value = g_settings_get_value (settings, key);
1792 result = g_variant_get_double (value);
1793 g_variant_unref (value);
1799 * g_settings_set_double:
1800 * @settings: a #GSettings object
1801 * @key: the name of the key to set
1802 * @value: the value to set it to
1803 * @returns: %TRUE if setting the key succeeded,
1804 * %FALSE if the key was not writable
1806 * Sets @key in @settings to @value.
1808 * A convenience variant of g_settings_set() for doubles.
1810 * It is a programmer error to give a @key that isn't specified as
1811 * having a 'double' type in the schema for @settings.
1816 g_settings_set_double (GSettings *settings,
1820 return g_settings_set_value (settings, key, g_variant_new_double (value));
1824 * g_settings_get_boolean:
1825 * @settings: a #GSettings object
1826 * @key: the key to get the value for
1827 * @returns: a boolean
1829 * Gets the value that is stored at @key in @settings.
1831 * A convenience variant of g_settings_get() for booleans.
1833 * It is a programmer error to give a @key that isn't specified as
1834 * having a boolean type in the schema for @settings.
1839 g_settings_get_boolean (GSettings *settings,
1845 value = g_settings_get_value (settings, key);
1846 result = g_variant_get_boolean (value);
1847 g_variant_unref (value);
1853 * g_settings_set_boolean:
1854 * @settings: a #GSettings object
1855 * @key: the name of the key to set
1856 * @value: the value to set it to
1857 * @returns: %TRUE if setting the key succeeded,
1858 * %FALSE if the key was not writable
1860 * Sets @key in @settings to @value.
1862 * A convenience variant of g_settings_set() for booleans.
1864 * It is a programmer error to give a @key that isn't specified as
1865 * having a boolean type in the schema for @settings.
1870 g_settings_set_boolean (GSettings *settings,
1874 return g_settings_set_value (settings, key, g_variant_new_boolean (value));
1878 * g_settings_get_strv:
1879 * @settings: a #GSettings object
1880 * @key: the key to get the value for
1881 * @returns: a newly-allocated, %NULL-terminated array of strings
1883 * A convenience variant of g_settings_get() for string arrays.
1885 * It is a programmer error to give a @key that isn't specified as
1886 * having an array of strings type in the schema for @settings.
1888 * Returns: (array zero-terminated=1) (transfer full): the value that is
1889 * stored at @key in @settings.
1894 g_settings_get_strv (GSettings *settings,
1900 value = g_settings_get_value (settings, key);
1901 result = g_variant_dup_strv (value, NULL);
1902 g_variant_unref (value);
1908 * g_settings_set_strv:
1909 * @settings: a #GSettings object
1910 * @key: the name of the key to set
1911 * @value: (allow-none) (array zero-terminated=1): the value to set it to, or %NULL
1912 * @returns: %TRUE if setting the key succeeded,
1913 * %FALSE if the key was not writable
1915 * Sets @key in @settings to @value.
1917 * A convenience variant of g_settings_set() for string arrays. If
1918 * @value is %NULL, then @key is set to be the empty array.
1920 * It is a programmer error to give a @key that isn't specified as
1921 * having an array of strings type in the schema for @settings.
1926 g_settings_set_strv (GSettings *settings,
1928 const gchar * const *value)
1933 array = g_variant_new_strv (value, -1);
1935 array = g_variant_new_strv (NULL, 0);
1937 return g_settings_set_value (settings, key, array);
1940 /* Delayed apply (delay, apply, revert, get_has_unapplied) {{{1 */
1943 * @settings: a #GSettings object
1945 * Changes the #GSettings object into 'delay-apply' mode. In this
1946 * mode, changes to @settings are not immediately propagated to the
1947 * backend, but kept locally until g_settings_apply() is called.
1952 g_settings_delay (GSettings *settings)
1954 g_return_if_fail (G_IS_SETTINGS (settings));
1956 if (settings->priv->delayed)
1959 settings->priv->delayed =
1960 g_delayed_settings_backend_new (settings->priv->backend,
1962 settings->priv->main_context);
1963 g_settings_backend_unwatch (settings->priv->backend, G_OBJECT (settings));
1964 g_object_unref (settings->priv->backend);
1966 settings->priv->backend = G_SETTINGS_BACKEND (settings->priv->delayed);
1967 g_settings_backend_watch (settings->priv->backend,
1968 &listener_vtable, G_OBJECT (settings),
1969 settings->priv->main_context);
1974 * @settings: a #GSettings instance
1976 * Applies any changes that have been made to the settings. This
1977 * function does nothing unless @settings is in 'delay-apply' mode;
1978 * see g_settings_delay(). In the normal case settings are always
1979 * applied immediately.
1982 g_settings_apply (GSettings *settings)
1984 if (settings->priv->delayed)
1986 GDelayedSettingsBackend *delayed;
1988 delayed = G_DELAYED_SETTINGS_BACKEND (settings->priv->backend);
1989 g_delayed_settings_backend_apply (delayed);
1994 * g_settings_revert:
1995 * @settings: a #GSettings instance
1997 * Reverts all non-applied changes to the settings. This function
1998 * does nothing unless @settings is in 'delay-apply' mode; see
1999 * g_settings_delay(). In the normal case settings are always applied
2002 * Change notifications will be emitted for affected keys.
2005 g_settings_revert (GSettings *settings)
2007 if (settings->priv->delayed)
2009 GDelayedSettingsBackend *delayed;
2011 delayed = G_DELAYED_SETTINGS_BACKEND (settings->priv->backend);
2012 g_delayed_settings_backend_revert (delayed);
2017 * g_settings_get_has_unapplied:
2018 * @settings: a #GSettings object
2019 * @returns: %TRUE if @settings has unapplied changes
2021 * Returns whether the #GSettings object has any unapplied
2022 * changes. This can only be the case if it is in 'delayed-apply' mode.
2027 g_settings_get_has_unapplied (GSettings *settings)
2029 g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
2031 return settings->priv->delayed &&
2032 g_delayed_settings_backend_get_has_unapplied (
2033 G_DELAYED_SETTINGS_BACKEND (settings->priv->backend));
2036 /* Extra API (reset, sync, get_child, is_writable, list_*, ranges) {{{1 */
2039 * @settings: a #GSettings object
2040 * @key: the name of a key
2042 * Resets @key to its default value.
2044 * This call resets the key, as much as possible, to its default value.
2045 * That might the value specified in the schema or the one set by the
2049 g_settings_reset (GSettings *settings,
2054 path = g_strconcat (settings->priv->path, key, NULL);
2055 g_settings_backend_reset (settings->priv->backend, path, NULL);
2062 * Ensures that all pending operations for the given are complete for
2063 * the default backend.
2065 * Writes made to a #GSettings are handled asynchronously. For this
2066 * reason, it is very unlikely that the changes have it to disk by the
2067 * time g_settings_set() returns.
2069 * This call will block until all of the writes have made it to the
2070 * backend. Since the mainloop is not running, no change notifications
2071 * will be dispatched during this call (but some may be queued by the
2072 * time the call is done).
2075 g_settings_sync (void)
2077 g_settings_backend_sync_default ();
2081 * g_settings_is_writable:
2082 * @settings: a #GSettings object
2083 * @name: the name of a key
2084 * @returns: %TRUE if the key @name is writable
2086 * Finds out if a key can be written or not
2091 g_settings_is_writable (GSettings *settings,
2097 g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
2099 path = g_strconcat (settings->priv->path, name, NULL);
2100 writable = g_settings_backend_get_writable (settings->priv->backend, path);
2107 * g_settings_get_child:
2108 * @settings: a #GSettings object
2109 * @name: the name of the 'child' schema
2110 * @returns: (transfer full): a 'child' settings object
2112 * Creates a 'child' settings object which has a base path of
2113 * <replaceable>base-path</replaceable>/@name", where
2114 * <replaceable>base-path</replaceable> is the base path of @settings.
2116 * The schema for the child settings object must have been declared
2117 * in the schema of @settings using a <tag class="starttag">child</tag> element.
2122 g_settings_get_child (GSettings *settings,
2125 const gchar *child_schema;
2130 g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
2132 child_name = g_strconcat (name, "/", NULL);
2133 child_schema = g_settings_schema_get_string (settings->priv->schema,
2135 if (child_schema == NULL)
2136 g_error ("Schema '%s' has no child '%s'",
2137 settings->priv->schema_name, name);
2139 child_path = g_strconcat (settings->priv->path, child_name, NULL);
2140 child = g_object_new (G_TYPE_SETTINGS,
2141 "schema", child_schema,
2144 g_free (child_path);
2145 g_free (child_name);
2151 * g_settings_list_keys:
2152 * @settings: a #GSettings object
2153 * @returns: (transfer full) (element-type utf8): a list of the keys on @settings
2155 * Introspects the list of keys on @settings.
2157 * You should probably not be calling this function from "normal" code
2158 * (since you should already know what keys are in your schema). This
2159 * function is intended for introspection reasons.
2161 * You should free the return value with g_strfreev() when you are done
2165 g_settings_list_keys (GSettings *settings)
2172 keys = g_settings_schema_list (settings->priv->schema, &n_keys);
2173 strv = g_new (gchar *, n_keys + 1);
2174 for (i = j = 0; i < n_keys; i++)
2176 const gchar *key = g_quark_to_string (keys[i]);
2178 if (!g_str_has_suffix (key, "/"))
2179 strv[j++] = g_strdup (key);
2187 * g_settings_list_children:
2188 * @settings: a #GSettings object
2189 * @returns: (transfer full) (element-type utf8): a list of the children on @settings
2191 * Gets the list of children on @settings.
2193 * The list is exactly the list of strings for which it is not an error
2194 * to call g_settings_get_child().
2196 * For GSettings objects that are lists, this value can change at any
2197 * time and you should connect to the "children-changed" signal to watch
2198 * for those changes. Note that there is a race condition here: you may
2199 * request a child after listing it only for it to have been destroyed
2200 * in the meantime. For this reason, g_settings_get_child() may return
2201 * %NULL even for a child that was listed by this function.
2203 * For GSettings objects that are not lists, you should probably not be
2204 * calling this function from "normal" code (since you should already
2205 * know what children are in your schema). This function may still be
2206 * useful there for introspection reasons, however.
2208 * You should free the return value with g_strfreev() when you are done
2212 g_settings_list_children (GSettings *settings)
2219 keys = g_settings_schema_list (settings->priv->schema, &n_keys);
2220 strv = g_new (gchar *, n_keys + 1);
2221 for (i = j = 0; i < n_keys; i++)
2223 const gchar *key = g_quark_to_string (keys[i]);
2225 if (g_str_has_suffix (key, "/"))
2227 gint length = strlen (key);
2229 strv[j] = g_memdup (key, length);
2230 strv[j][length - 1] = '\0';
2240 * g_settings_get_range:
2241 * @settings: a #GSettings
2242 * @key: the key to query the range of
2243 * @returns: a #GVariant describing the range
2245 * Queries the range of a key.
2247 * This function will return a #GVariant that fully describes the range
2248 * of values that are valid for @key.
2250 * The type of #GVariant returned is <literal>(sv)</literal>. The
2251 * string describes the type of range restriction in effect. The type
2252 * and meaning of the value contained in the variant depends on the
2255 * If the string is <literal>'type'</literal> then the variant contains
2256 * an empty array. The element type of that empty array is the expected
2257 * type of value and all values of that type are valid.
2259 * If the string is <literal>'enum'</literal> then the variant contains
2260 * an array enumerating the possible values. Each item in the array is
2261 * a possible valid value and no other values are valid.
2263 * If the string is <literal>'flags'</literal> then the variant contains
2264 * an array. Each item in the array is a value that may appear zero or
2265 * one times in an array to be used as the value for this key. For
2266 * example, if the variant contained the array <literal>['x',
2267 * 'y']</literal> then the valid values for the key would be
2268 * <literal>[]</literal>, <literal>['x']</literal>,
2269 * <literal>['y']</literal>, <literal>['x', 'y']</literal> and
2270 * <literal>['y', 'x']</literal>.
2272 * Finally, if the string is <literal>'range'</literal> then the variant
2273 * contains a pair of like-typed values -- the minimum and maximum
2274 * permissible values for this key.
2276 * This information should not be used by normal programs. It is
2277 * considered to be a hint for introspection purposes. Normal programs
2278 * should already know what is permitted by their own schema. The
2279 * format may change in any way in the future -- but particularly, new
2280 * forms may be added to the possibilities described above.
2282 * It is a programmer error to give a @key that isn't contained in the
2283 * schema for @settings.
2285 * You should free the returned value with g_variant_unref() when it is
2291 g_settings_get_range (GSettings *settings,
2294 GSettingsKeyInfo info;
2298 g_settings_get_key_info (&info, settings, key);
2302 range = g_variant_new ("(**)", info.minimum, info.maximum);
2305 else if (info.strinfo)
2307 range = strinfo_enumerate (info.strinfo, info.strinfo_length);
2308 type = info.is_flags ? "flags" : "enum";
2312 range = g_variant_new_array (info.type, NULL, 0);
2316 g_settings_free_key_info (&info);
2318 return g_variant_ref_sink (g_variant_new ("(sv)", type, range));
2322 * g_settings_range_check:
2323 * @settings: a #GSettings
2324 * @key: the key to check
2325 * @value: the value to check
2326 * @returns: %TRUE if @value is valid for @key
2328 * Checks if the given @value is of the correct type and within the
2329 * permitted range for @key.
2331 * This API is not intended to be used by normal programs -- they should
2332 * already know what is permitted by their own schemas. This API is
2333 * meant to be used by programs such as editors or commandline tools.
2335 * It is a programmer error to give a @key that isn't contained in the
2336 * schema for @settings.
2341 g_settings_range_check (GSettings *settings,
2345 GSettingsKeyInfo info;
2348 g_settings_get_key_info (&info, settings, key);
2349 good = g_settings_type_check (&info, value) &&
2350 g_settings_key_info_range_check (&info, value);
2351 g_settings_free_key_info (&info);
2359 GSettingsKeyInfo info;
2362 GSettingsBindGetMapping get_mapping;
2363 GSettingsBindSetMapping set_mapping;
2365 GDestroyNotify destroy;
2367 guint writable_handler_id;
2368 guint property_handler_id;
2369 const GParamSpec *property;
2370 guint key_handler_id;
2372 /* prevent recursion */
2377 g_settings_binding_free (gpointer data)
2379 GSettingsBinding *binding = data;
2381 g_assert (!binding->running);
2383 if (binding->writable_handler_id)
2384 g_signal_handler_disconnect (binding->info.settings,
2385 binding->writable_handler_id);
2387 if (binding->key_handler_id)
2388 g_signal_handler_disconnect (binding->info.settings,
2389 binding->key_handler_id);
2391 if (g_signal_handler_is_connected (binding->object,
2392 binding->property_handler_id))
2393 g_signal_handler_disconnect (binding->object,
2394 binding->property_handler_id);
2396 g_settings_free_key_info (&binding->info);
2398 if (binding->destroy)
2399 binding->destroy (binding->user_data);
2401 g_slice_free (GSettingsBinding, binding);
2405 g_settings_binding_quark (const char *property)
2410 tmp = g_strdup_printf ("gsettingsbinding-%s", property);
2411 quark = g_quark_from_string (tmp);
2418 g_settings_binding_key_changed (GSettings *settings,
2422 GSettingsBinding *binding = user_data;
2423 GValue value = { 0, };
2426 g_assert (settings == binding->info.settings);
2427 g_assert (key == binding->info.key);
2429 if (binding->running)
2432 binding->running = TRUE;
2434 g_value_init (&value, binding->property->value_type);
2436 variant = g_settings_read_from_backend (&binding->info);
2437 if (variant && !binding->get_mapping (&value, variant, binding->user_data))
2439 /* silently ignore errors in the user's config database */
2440 g_variant_unref (variant);
2444 if (variant == NULL)
2446 variant = g_settings_get_translated_default (&binding->info);
2448 !binding->get_mapping (&value, variant, binding->user_data))
2450 /* flag translation errors with a warning */
2451 g_warning ("Translated default `%s' for key `%s' in schema `%s' "
2452 "was rejected by the binding mapping function",
2453 binding->info.unparsed, binding->info.key,
2454 binding->info.settings->priv->schema_name);
2455 g_variant_unref (variant);
2460 if (variant == NULL)
2462 variant = g_variant_ref (binding->info.default_value);
2463 if (!binding->get_mapping (&value, variant, binding->user_data))
2464 g_error ("The schema default value for key `%s' in schema `%s' "
2465 "was rejected by the binding mapping function.",
2467 binding->info.settings->priv->schema_name);
2470 g_object_set_property (binding->object, binding->property->name, &value);
2471 g_variant_unref (variant);
2472 g_value_unset (&value);
2474 binding->running = FALSE;
2478 g_settings_binding_property_changed (GObject *object,
2479 const GParamSpec *pspec,
2482 GSettingsBinding *binding = user_data;
2483 GValue value = { 0, };
2486 g_assert (object == binding->object);
2487 g_assert (pspec == binding->property);
2489 if (binding->running)
2492 binding->running = TRUE;
2494 g_value_init (&value, pspec->value_type);
2495 g_object_get_property (object, pspec->name, &value);
2496 if ((variant = binding->set_mapping (&value, binding->info.type,
2497 binding->user_data)))
2499 if (g_variant_is_floating (variant))
2500 g_variant_ref_sink (variant);
2502 if (!g_settings_type_check (&binding->info, variant))
2504 g_critical ("binding mapping function for key `%s' returned "
2505 "GVariant of type `%s' when type `%s' was requested",
2506 binding->info.key, g_variant_get_type_string (variant),
2507 g_variant_type_dup_string (binding->info.type));
2511 if (!g_settings_key_info_range_check (&binding->info, variant))
2513 g_critical ("GObject property `%s' on a `%s' object is out of "
2514 "schema-specified range for key `%s' of `%s': %s",
2515 binding->property->name,
2516 g_type_name (binding->property->owner_type),
2518 binding->info.settings->priv->schema_name,
2519 g_variant_print (variant, TRUE));
2523 g_settings_write_to_backend (&binding->info, variant);
2524 g_variant_unref (variant);
2526 g_value_unset (&value);
2528 binding->running = FALSE;
2532 g_settings_bind_invert_boolean_get_mapping (GValue *value,
2536 g_value_set_boolean (value, !g_variant_get_boolean (variant));
2541 g_settings_bind_invert_boolean_set_mapping (const GValue *value,
2542 const GVariantType *expected_type,
2545 return g_variant_new_boolean (!g_value_get_boolean (value));
2550 * @settings: a #GSettings object
2551 * @key: the key to bind
2552 * @object: a #GObject
2553 * @property: the name of the property to bind
2554 * @flags: flags for the binding
2556 * Create a binding between the @key in the @settings object
2557 * and the property @property of @object.
2559 * The binding uses the default GIO mapping functions to map
2560 * between the settings and property values. These functions
2561 * handle booleans, numeric types and string types in a
2562 * straightforward way. Use g_settings_bind_with_mapping() if
2563 * you need a custom mapping, or map between types that are not
2564 * supported by the default mapping functions.
2566 * Unless the @flags include %G_SETTINGS_BIND_NO_SENSITIVITY, this
2567 * function also establishes a binding between the writability of
2568 * @key and the "sensitive" property of @object (if @object has
2569 * a boolean property by that name). See g_settings_bind_writable()
2570 * for more details about writable bindings.
2572 * Note that the lifecycle of the binding is tied to the object,
2573 * and that you can have only one binding per object property.
2574 * If you bind the same property twice on the same object, the second
2575 * binding overrides the first one.
2580 g_settings_bind (GSettings *settings,
2583 const gchar *property,
2584 GSettingsBindFlags flags)
2586 GSettingsBindGetMapping get_mapping = NULL;
2587 GSettingsBindSetMapping set_mapping = NULL;
2589 if (flags & G_SETTINGS_BIND_INVERT_BOOLEAN)
2591 get_mapping = g_settings_bind_invert_boolean_get_mapping;
2592 set_mapping = g_settings_bind_invert_boolean_set_mapping;
2594 /* can't pass this flag to g_settings_bind_with_mapping() */
2595 flags &= ~G_SETTINGS_BIND_INVERT_BOOLEAN;
2598 g_settings_bind_with_mapping (settings, key, object, property, flags,
2599 get_mapping, set_mapping, NULL, NULL);
2603 * g_settings_bind_with_mapping:
2604 * @settings: a #GSettings object
2605 * @key: the key to bind
2606 * @object: a #GObject
2607 * @property: the name of the property to bind
2608 * @flags: flags for the binding
2609 * @get_mapping: a function that gets called to convert values
2610 * from @settings to @object, or %NULL to use the default GIO mapping
2611 * @set_mapping: a function that gets called to convert values
2612 * from @object to @settings, or %NULL to use the default GIO mapping
2613 * @user_data: data that gets passed to @get_mapping and @set_mapping
2614 * @destroy: #GDestroyNotify function for @user_data
2616 * Create a binding between the @key in the @settings object
2617 * and the property @property of @object.
2619 * The binding uses the provided mapping functions to map between
2620 * settings and property values.
2622 * Note that the lifecycle of the binding is tied to the object,
2623 * and that you can have only one binding per object property.
2624 * If you bind the same property twice on the same object, the second
2625 * binding overrides the first one.
2630 g_settings_bind_with_mapping (GSettings *settings,
2633 const gchar *property,
2634 GSettingsBindFlags flags,
2635 GSettingsBindGetMapping get_mapping,
2636 GSettingsBindSetMapping set_mapping,
2638 GDestroyNotify destroy)
2640 GSettingsBinding *binding;
2641 GObjectClass *objectclass;
2642 gchar *detailed_signal;
2643 GQuark binding_quark;
2645 g_return_if_fail (G_IS_SETTINGS (settings));
2646 g_return_if_fail (~flags & G_SETTINGS_BIND_INVERT_BOOLEAN);
2648 objectclass = G_OBJECT_GET_CLASS (object);
2650 binding = g_slice_new0 (GSettingsBinding);
2651 g_settings_get_key_info (&binding->info, settings, key);
2652 binding->object = object;
2653 binding->property = g_object_class_find_property (objectclass, property);
2654 binding->user_data = user_data;
2655 binding->destroy = destroy;
2656 binding->get_mapping = get_mapping ? get_mapping : g_settings_get_mapping;
2657 binding->set_mapping = set_mapping ? set_mapping : g_settings_set_mapping;
2659 if (!(flags & (G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET)))
2660 flags |= G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET;
2662 if (binding->property == NULL)
2664 g_critical ("g_settings_bind: no property '%s' on class '%s'",
2665 property, G_OBJECT_TYPE_NAME (object));
2669 if ((flags & G_SETTINGS_BIND_GET) &&
2670 (binding->property->flags & G_PARAM_WRITABLE) == 0)
2672 g_critical ("g_settings_bind: property '%s' on class '%s' is not "
2673 "writable", property, G_OBJECT_TYPE_NAME (object));
2676 if ((flags & G_SETTINGS_BIND_SET) &&
2677 (binding->property->flags & G_PARAM_READABLE) == 0)
2679 g_critical ("g_settings_bind: property '%s' on class '%s' is not "
2680 "readable", property, G_OBJECT_TYPE_NAME (object));
2684 if (get_mapping == g_settings_bind_invert_boolean_get_mapping)
2686 /* g_settings_bind_invert_boolean_get_mapping() is a private
2687 * function, so if we are here it means that g_settings_bind() was
2688 * called with G_SETTINGS_BIND_INVERT_BOOLEAN.
2690 * Ensure that both sides are boolean.
2693 if (binding->property->value_type != G_TYPE_BOOLEAN)
2695 g_critical ("g_settings_bind: G_SETTINGS_BIND_INVERT_BOOLEAN "
2696 "was specified, but property `%s' on type `%s' has "
2697 "type `%s'", property, G_OBJECT_TYPE_NAME (object),
2698 g_type_name ((binding->property->value_type)));
2702 if (!g_variant_type_equal (binding->info.type, G_VARIANT_TYPE_BOOLEAN))
2704 g_critical ("g_settings_bind: G_SETTINGS_BIND_INVERT_BOOLEAN "
2705 "was specified, but key `%s' on schema `%s' has "
2706 "type `%s'", key, settings->priv->schema_name,
2707 g_variant_type_dup_string (binding->info.type));
2713 else if (((get_mapping == NULL && (flags & G_SETTINGS_BIND_GET)) ||
2714 (set_mapping == NULL && (flags & G_SETTINGS_BIND_SET))) &&
2715 !g_settings_mapping_is_compatible (binding->property->value_type,
2716 binding->info.type))
2718 g_critical ("g_settings_bind: property '%s' on class '%s' has type "
2719 "'%s' which is not compatible with type '%s' of key '%s' "
2720 "on schema '%s'", property, G_OBJECT_TYPE_NAME (object),
2721 g_type_name (binding->property->value_type),
2722 g_variant_type_dup_string (binding->info.type), key,
2723 settings->priv->schema_name);
2727 if ((flags & G_SETTINGS_BIND_SET) &&
2728 (~flags & G_SETTINGS_BIND_NO_SENSITIVITY))
2730 GParamSpec *sensitive;
2732 sensitive = g_object_class_find_property (objectclass, "sensitive");
2734 if (sensitive && sensitive->value_type == G_TYPE_BOOLEAN &&
2735 (sensitive->flags & G_PARAM_WRITABLE))
2736 g_settings_bind_writable (settings, binding->info.key,
2737 object, "sensitive", FALSE);
2740 if (flags & G_SETTINGS_BIND_SET)
2742 detailed_signal = g_strdup_printf ("notify::%s", property);
2743 binding->property_handler_id =
2744 g_signal_connect (object, detailed_signal,
2745 G_CALLBACK (g_settings_binding_property_changed),
2747 g_free (detailed_signal);
2749 if (~flags & G_SETTINGS_BIND_GET)
2750 g_settings_binding_property_changed (object,
2755 if (flags & G_SETTINGS_BIND_GET)
2757 if (~flags & G_SETTINGS_BIND_GET_NO_CHANGES)
2759 detailed_signal = g_strdup_printf ("changed::%s", key);
2760 binding->key_handler_id =
2761 g_signal_connect (settings, detailed_signal,
2762 G_CALLBACK (g_settings_binding_key_changed),
2764 g_free (detailed_signal);
2767 g_settings_binding_key_changed (settings, binding->info.key, binding);
2770 binding_quark = g_settings_binding_quark (property);
2771 g_object_set_qdata_full (object, binding_quark,
2772 binding, g_settings_binding_free);
2775 /* Writability binding {{{1 */
2778 GSettings *settings;
2781 const gchar *property;
2784 } GSettingsWritableBinding;
2787 g_settings_writable_binding_free (gpointer data)
2789 GSettingsWritableBinding *binding = data;
2791 g_signal_handler_disconnect (binding->settings, binding->handler_id);
2792 g_object_unref (binding->settings);
2793 g_slice_free (GSettingsWritableBinding, binding);
2797 g_settings_binding_writable_changed (GSettings *settings,
2801 GSettingsWritableBinding *binding = user_data;
2804 g_assert (settings == binding->settings);
2805 g_assert (key == binding->key);
2807 writable = g_settings_is_writable (settings, key);
2809 if (binding->inverted)
2810 writable = !writable;
2812 g_object_set (binding->object, binding->property, writable, NULL);
2816 * g_settings_bind_writable:
2817 * @settings: a #GSettings object
2818 * @key: the key to bind
2819 * @object: a #GObject
2820 * @property: the name of a boolean property to bind
2821 * @inverted: whether to 'invert' the value
2823 * Create a binding between the writability of @key in the
2824 * @settings object and the property @property of @object.
2825 * The property must be boolean; "sensitive" or "visible"
2826 * properties of widgets are the most likely candidates.
2828 * Writable bindings are always uni-directional; changes of the
2829 * writability of the setting will be propagated to the object
2830 * property, not the other way.
2832 * When the @inverted argument is %TRUE, the binding inverts the
2833 * value as it passes from the setting to the object, i.e. @property
2834 * will be set to %TRUE if the key is <emphasis>not</emphasis>
2837 * Note that the lifecycle of the binding is tied to the object,
2838 * and that you can have only one binding per object property.
2839 * If you bind the same property twice on the same object, the second
2840 * binding overrides the first one.
2845 g_settings_bind_writable (GSettings *settings,
2848 const gchar *property,
2851 GSettingsWritableBinding *binding;
2852 gchar *detailed_signal;
2855 g_return_if_fail (G_IS_SETTINGS (settings));
2857 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), property);
2860 g_critical ("g_settings_bind_writable: no property '%s' on class '%s'",
2861 property, G_OBJECT_TYPE_NAME (object));
2864 if ((pspec->flags & G_PARAM_WRITABLE) == 0)
2866 g_critical ("g_settings_bind_writable: property '%s' on class '%s' is not writable",
2867 property, G_OBJECT_TYPE_NAME (object));
2871 binding = g_slice_new (GSettingsWritableBinding);
2872 binding->settings = g_object_ref (settings);
2873 binding->object = object;
2874 binding->key = g_intern_string (key);
2875 binding->property = g_intern_string (property);
2876 binding->inverted = inverted;
2878 detailed_signal = g_strdup_printf ("writable-changed::%s", key);
2879 binding->handler_id =
2880 g_signal_connect (settings, detailed_signal,
2881 G_CALLBACK (g_settings_binding_writable_changed),
2883 g_free (detailed_signal);
2885 g_object_set_qdata_full (object, g_settings_binding_quark (property),
2886 binding, g_settings_writable_binding_free);
2888 g_settings_binding_writable_changed (settings, binding->key, binding);
2892 * g_settings_unbind:
2893 * @object: the object
2894 * @property: the property whose binding is removed
2896 * Removes an existing binding for @property on @object.
2898 * Note that bindings are automatically removed when the
2899 * object is finalized, so it is rarely necessary to call this
2905 g_settings_unbind (gpointer object,
2906 const gchar *property)
2908 GQuark binding_quark;
2910 binding_quark = g_settings_binding_quark (property);
2911 g_object_set_qdata (object, binding_quark, NULL);
2916 /* vim:set foldmethod=marker: */