[libdazzle] properties-group: add helper to add all properties
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] properties-group: add helper to add all properties
- Date: Fri, 7 Jul 2017 21:21:04 +0000 (UTC)
commit adc4c33d5b3b728358212f535c142f36dc1ef0d6
Author: Christian Hergert <chergert redhat com>
Date: Fri Jul 7 14:20:14 2017 -0700
properties-group: add helper to add all properties
In very simple cases, you might just want to add all properties
from a GObject. dzl_properties_group_add_all_properties() will
do that for you. It does not, however, allow control over
additional flags.
src/actions/dzl-properties-group.c | 55 ++++++++++++++++++++++++++++++++++++
src/actions/dzl-properties-group.h | 21 +++++++------
2 files changed, 66 insertions(+), 10 deletions(-)
---
diff --git a/src/actions/dzl-properties-group.c b/src/actions/dzl-properties-group.c
index c00816b..fb0718f 100644
--- a/src/actions/dzl-properties-group.c
+++ b/src/actions/dzl-properties-group.c
@@ -638,6 +638,9 @@ dzl_properties_group_init (DzlPropertiesGroup *self)
* action name mapping for this group. Until you've called this,
* no actions are mapped.
*
+ * Note that #DzlPropertiesGroup only holds a weak reference to
+ * @object and therefore you must keep @object alive elsewhere.
+ *
* Returns: (transfer full): A #DzlPropertiesGroup
*
* Since: 3.26
@@ -764,3 +767,55 @@ dzl_properties_group_remove (DzlPropertiesGroup *self,
}
}
}
+
+/**
+ * dzl_properties_group_add_all_properties:
+ * @self: A #DzlPropertiesGroup
+ *
+ * This function will try to add all properties found on the target
+ * instance to the group. Only properties that are supported by the
+ * #DzlPropertiesGroup will be added.
+ *
+ * The action name of all added properties will be identical to their
+ * property name.
+ *
+ * Since: 3.26
+ */
+void
+dzl_properties_group_add_all_properties (DzlPropertiesGroup *self)
+{
+ g_autoptr(GObject) object = NULL;
+ g_autofree GParamSpec **pspec = NULL;
+ GObjectClass *object_class;
+ guint n_pspec = 0;
+
+ g_return_if_fail (DZL_IS_PROPERTIES_GROUP (self));
+
+ object = g_weak_ref_get (&self->object_ref);
+
+ if (object == NULL)
+ {
+ g_warning ("Cannot add properties, object has already been disposed");
+ return;
+ }
+
+ object_class = G_OBJECT_GET_CLASS (object);
+ pspec = g_object_class_list_properties (object_class, &n_pspec);
+
+ for (guint i = 0; i < n_pspec; i++)
+ {
+ switch (pspec[i]->value_type)
+ {
+ case G_TYPE_BOOLEAN:
+ case G_TYPE_DOUBLE:
+ case G_TYPE_INT:
+ case G_TYPE_STRING:
+ case G_TYPE_UINT:
+ dzl_properties_group_add_property (self, pspec[i]->name, pspec[i]->name);
+ break;
+
+ default:
+ break;
+ }
+ }
+}
diff --git a/src/actions/dzl-properties-group.h b/src/actions/dzl-properties-group.h
index b769cce..f30d748 100644
--- a/src/actions/dzl-properties-group.h
+++ b/src/actions/dzl-properties-group.h
@@ -32,15 +32,16 @@ typedef enum
DZL_PROPERTIES_FLAGS_STATEFUL_BOOLEANS = 1 << 0,
} DzlPropertiesFlags;
-DzlPropertiesGroup *dzl_properties_group_new (GObject *object);
-void dzl_properties_group_add_property (DzlPropertiesGroup *self,
- const gchar *name,
- const gchar *property_name);
-void dzl_properties_group_add_property_full (DzlPropertiesGroup *self,
- const gchar *name,
- const gchar *property_name,
- DzlPropertiesFlags flags);
-void dzl_properties_group_remove (DzlPropertiesGroup *self,
- const gchar *name);
+DzlPropertiesGroup *dzl_properties_group_new (GObject *object);
+void dzl_properties_group_add_property (DzlPropertiesGroup *self,
+ const gchar *name,
+ const gchar *property_name);
+void dzl_properties_group_add_property_full (DzlPropertiesGroup *self,
+ const gchar *name,
+ const gchar *property_name,
+ DzlPropertiesFlags flags);
+void dzl_properties_group_add_all_properties (DzlPropertiesGroup *self);
+void dzl_properties_group_remove (DzlPropertiesGroup *self,
+ const gchar *name);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]