[libdazzle] properties-group: track read/write state of properties



commit bb36cb4f8b1e38dee758b4c86dc932f2ebf4034e
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 13 15:55:12 2017 -0700

    properties-group: track read/write state of properties
    
    We can probably try to be more clever with enabled state, but
    that will require further testing. Such as, can actions update
    their state if not enabled (ie: you can't activate/change-state)
    and expect consumers to use that properly?

 src/actions/dzl-properties-group.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/src/actions/dzl-properties-group.c b/src/actions/dzl-properties-group.c
index 98045ae..dcc5a5c 100644
--- a/src/actions/dzl-properties-group.c
+++ b/src/actions/dzl-properties-group.c
@@ -82,7 +82,9 @@ typedef struct
   const GVariantType *state_type;
   const gchar        *property_name;
   GType               property_type;
-  DzlPropertiesFlags  flags;
+  DzlPropertiesFlags  flags : 8;
+  guint               can_read : 1;
+  guint               can_write : 1;
 } Mapping;
 
 enum {
@@ -102,6 +104,9 @@ get_action_state (GObject       *object,
   g_assert (G_IS_OBJECT (object));
   g_assert (mapping != NULL);
 
+  if (!mapping->can_read)
+    return NULL;
+
   g_value_init (&value, mapping->property_type);
   g_object_get_property (object, mapping->property_name, &value);
 
@@ -341,6 +346,12 @@ dzl_properties_group_change_action_state (GActionGroup *group,
         {
           g_auto(GValue) value = G_VALUE_INIT;
 
+          if (!mapping->can_write)
+            {
+              g_warning ("property is not writable, ignoring request to change state");
+              break;
+            }
+
           switch (mapping->property_type)
             {
             case G_TYPE_INT:
@@ -792,6 +803,8 @@ dzl_properties_group_add_property_full (DzlPropertiesGroup *self,
   mapping.property_name = pspec->name;
   mapping.property_type = pspec->value_type;
   mapping.flags = flags;
+  mapping.can_read = !!(pspec->flags & G_PARAM_READABLE);
+  mapping.can_write = !!(pspec->flags & G_PARAM_WRITABLE);
 
   /* we already warned, ignore this */
   if (mapping.state_type == NULL)


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