[glib/gsettings] add support for "sensitive" property on bindings



commit 0df2a3985e9e92409c22c1c7b7511524747a9cae
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Sep 30 13:42:46 2009 -0400

    add support for "sensitive" property on bindings
    
    if the target object has a boolean property called "sensitive" then this
    property is automatically set according to if the GSettings key being
    bound to is locked or not.  the obvious use here is for GtkWidget.

 gio/gsettings.c |   19 ++++++++++++++++++-
 gio/gsettings.h |    3 ++-
 2 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/gio/gsettings.c b/gio/gsettings.c
index 3eb54f6..e3c985d 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -739,6 +739,7 @@ g_settings_bind (GSettings          *settings,
   GObjectClass *objectclass;
   gchar *detailed_signal;
   GQuark binding_quark;
+  gboolean insensitive;
 
   objectclass = G_OBJECT_GET_CLASS (object);
 
@@ -781,7 +782,23 @@ g_settings_bind (GSettings          *settings,
       return;
     }
 
-  if (flags & G_SETTINGS_BIND_SET)
+  if (~flags & G_SETTINGS_BIND_NO_SENSITIVITY)
+    {
+      GParamSpec *sensitive;
+
+      sensitive = g_object_class_find_property (objectclass, "sensitive");
+      if (sensitive && sensitive->value_type == G_TYPE_BOOLEAN)
+        {
+          insensitive = !g_settings_is_writable (settings, key);
+          g_object_set (object, "sensitive", !insensitive, NULL);
+        }
+      else
+        insensitive = FALSE;
+    }
+  else
+    insensitive = FALSE;
+
+  if (!insensitive && (flags & G_SETTINGS_BIND_SET))
     {
       detailed_signal = g_strdup_printf ("notify::%s", property);
       binding->property_handler_id =
diff --git a/gio/gsettings.h b/gio/gsettings.h
index 03c9f98..5e76adc 100644
--- a/gio/gsettings.h
+++ b/gio/gsettings.h
@@ -54,7 +54,8 @@ typedef enum
 {
   G_SETTINGS_BIND_DEFAULT,
   G_SETTINGS_BIND_GET            = (1<<0),
-  G_SETTINGS_BIND_SET            = (1<<1)
+  G_SETTINGS_BIND_SET            = (1<<1),
+  G_SETTINGS_BIND_NO_SENSITIVITY = (1<<2)
 } GSettingsBindFlags;
 
 G_BEGIN_DECLS



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]