Handle non-readable/-writable properties when binding
authorMatthias Clasen <mclasen@redhat.com>
Wed, 21 Apr 2010 16:31:33 +0000 (12:31 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 21 Apr 2010 16:33:55 +0000 (12:33 -0400)
And document readability/writability requirements for binding flags.

gio/gsettings.c
gio/gsettings.h

index 28c3121c10e7560e32be286045a7f35872ff3a69..26c7515269a67fbdd0f0d17dd86dc385da268b91 100644 (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);
index 79d84b51a1b9766a90d039f2a91fd3fbf582754b..440ce03d3105eaac21f18604dc3de7547eb51d62 100644 (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