From 8962868ff902e58456c545478e62796029d1fe5c Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Tue, 1 Sep 2009 21:12:44 -0400 Subject: Relax the EBinding API to reduce GObject casting. Also make it more fault-tolerant by warning about non-existent property names instead of just crashing. --- e-util/e-binding.c | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'e-util/e-binding.c') diff --git a/e-util/e-binding.c b/e-util/e-binding.c index 9d4e83fc3f..a2c37fff71 100644 --- a/e-util/e-binding.c +++ b/e-util/e-binding.c @@ -25,6 +25,17 @@ #include "e-binding.h" +static gpointer +e_binding_warn (GObject *object, + const gchar *property_name) +{ + g_warning ( + "%s instances have no `%s' property to bind to", + G_OBJECT_TYPE_NAME (object), property_name); + + return NULL; +} + static gboolean e_binding_transform_negate (const GValue *src_value, GValue *dst_value) @@ -211,9 +222,9 @@ e_binding_link_init (EBindingLink *link, * removed if one of the objects is finalized. **/ EBinding * -e_binding_new (GObject *src_object, +e_binding_new (gpointer src_object, const gchar *src_property, - GObject *dst_object, + gpointer dst_object, const gchar *dst_property) { return e_binding_new_full ( @@ -243,9 +254,9 @@ e_binding_new (GObject *src_object, * removed if one of the objects is finalized. **/ EBinding * -e_binding_new_full (GObject *src_object, +e_binding_new_full (gpointer src_object, const gchar *src_property, - GObject *dst_object, + gpointer dst_object, const gchar *dst_property, EBindingTransform transform, GDestroyNotify destroy_notify, @@ -263,6 +274,11 @@ e_binding_new_full (GObject *src_object, dst_pspec = g_object_class_find_property ( G_OBJECT_GET_CLASS (dst_object), dst_property); + if (src_pspec == NULL) + return e_binding_warn (src_object, src_property); + if (dst_pspec == NULL) + return e_binding_warn (dst_object, dst_property); + if (transform == NULL) transform = (EBindingTransform) g_value_transform; @@ -298,9 +314,9 @@ e_binding_new_full (GObject *src_object, * removed if one of the objects is finalized. **/ EBinding * -e_binding_new_with_negation (GObject *src_object, +e_binding_new_with_negation (gpointer src_object, const gchar *src_property, - GObject *dst_object, + gpointer dst_object, const gchar *dst_property) { EBindingTransform transform; @@ -346,9 +362,9 @@ e_binding_unbind (EBinding *binding) * removed if one of the objects is finalized. **/ EMutualBinding * -e_mutual_binding_new (GObject *object1, +e_mutual_binding_new (gpointer object1, const gchar *property1, - GObject *object2, + gpointer object2, const gchar *property2) { return e_mutual_binding_new_full ( @@ -382,9 +398,9 @@ e_mutual_binding_new (GObject *object1, * removed if one of the objects is finalized. **/ EMutualBinding * -e_mutual_binding_new_full (GObject *object1, +e_mutual_binding_new_full (gpointer object1, const gchar *property1, - GObject *object2, + gpointer object2, const gchar *property2, EBindingTransform transform, EBindingTransform reverse_transform, @@ -403,6 +419,11 @@ e_mutual_binding_new_full (GObject *object1, pspec2 = g_object_class_find_property ( G_OBJECT_GET_CLASS (object2), property2); + if (pspec1 == NULL) + return e_binding_warn (object1, property1); + if (pspec2 == NULL) + return e_binding_warn (object2, property2); + if (transform == NULL) transform = (EBindingTransform) g_value_transform; @@ -448,9 +469,9 @@ e_mutual_binding_new_full (GObject *object1, * if one of the objects if finalized. **/ EMutualBinding* -e_mutual_binding_new_with_negation (GObject *object1, +e_mutual_binding_new_with_negation (gpointer object1, const gchar *property1, - GObject *object2, + gpointer object2, const gchar *property2) { EBindingTransform transform; -- cgit v1.2.3