Handle non-readable/-writable properties when binding

And document readability/writability requirements for binding flags.
This commit is contained in:
Matthias Clasen 2010-04-21 12:31:33 -04:00
parent 8a988e8e88
commit ccf9361490
2 changed files with 34 additions and 3 deletions

View File

@ -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);

View File

@ -164,8 +164,10 @@ typedef gboolean (*GSettingsBindGetMapping) (GValue
/**
* GSettingsBindFlags:
* @G_SETTINGS_BIND_DEFAULT: Equivalent to <literal>G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET</literal>
* @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