From ccf9361490fa3684b22e52655e3236b2cd28a517 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 21 Apr 2010 12:31:33 -0400 Subject: [PATCH] Handle non-readable/-writable properties when binding And document readability/writability requirements for binding flags. --- gio/gsettings.c | 31 ++++++++++++++++++++++++++++++- gio/gsettings.h | 6 ++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/gio/gsettings.c b/gio/gsettings.c index 28c3121c1..26c751526 100644 --- a/gio/gsettings.c +++ b/gio/gsettings.c @@ -1326,6 +1326,19 @@ g_settings_bind_with_mapping (GSettings *settings, return; } + if ((flags & G_SETTINGS_BIND_GET) && (binding->property->flags & G_PARAM_WRITABLE) == 0) + { + g_critical ("g_settings_bind: property '%s' on class '%s' is not writable", + property, G_OBJECT_TYPE_NAME (object)); + return; + } + if ((flags & G_SETTINGS_BIND_SET) && (binding->property->flags & G_PARAM_READABLE) == 0) + { + g_critical ("g_settings_bind: property '%s' on class '%s' is not readable", + property, G_OBJECT_TYPE_NAME (object)); + return; + } + { GVariant *value; @@ -1363,7 +1376,8 @@ g_settings_bind_with_mapping (GSettings *settings, sensitive = g_object_class_find_property (objectclass, "sensitive"); - if (sensitive && sensitive->value_type == G_TYPE_BOOLEAN) + if (sensitive && sensitive->value_type == G_TYPE_BOOLEAN && + (sensitive->flags & G_PARAM_WRITABLE)) g_settings_bind_writable (settings, binding->key, object, "sensitive", FALSE); } @@ -1479,6 +1493,21 @@ g_settings_bind_writable (GSettings *settings, { GSettingsWritableBinding *binding; gchar *detailed_signal; + GParamSpec *pspec; + + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), property); + if (pspec == NULL) + { + g_critical ("g_settings_bind_writable: no property '%s' on class '%s'", + property, G_OBJECT_TYPE_NAME (object)); + return; + } + if ((pspec->flags & G_PARAM_WRITABLE) == 0) + { + g_critical ("g_settings_bind_writable: property '%s' on class '%s' is not writable", + property, G_OBJECT_TYPE_NAME (object)); + return; + } binding = g_slice_new (GSettingsWritableBinding); binding->settings = g_object_ref (settings); diff --git a/gio/gsettings.h b/gio/gsettings.h index 79d84b51a..440ce03d3 100644 --- a/gio/gsettings.h +++ b/gio/gsettings.h @@ -164,8 +164,10 @@ typedef gboolean (*GSettingsBindGetMapping) (GValue /** * GSettingsBindFlags: * @G_SETTINGS_BIND_DEFAULT: Equivalent to G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET - * @G_SETTINGS_BIND_GET: Update the #GObject property when the setting changes - * @G_SETTINGS_BIND_SET: Update the setting when the #GObject property changes + * @G_SETTINGS_BIND_GET: Update the #GObject property when the setting changes. + * It is an error to use this flag if the property is not writable. + * @G_SETTINGS_BIND_SET: Update the setting when the #GObject property changes. + * It is an error to use this flag if the property is not readable. * @G_SETTINGS_BIND_NO_SENSITIVITY: Do not try to bind a "sensitivity" property to the writability of the setting * @G_SETTINGS_BIND_GET_NO_CHANGES: When set in addition to #G_SETTINGS_BIND_GET, set the #GObject property * value initially from the setting, but do not listen for changes of the setting