aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2009-09-02 09:12:44 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-09-02 09:12:44 +0800
commit8962868ff902e58456c545478e62796029d1fe5c (patch)
treed43efa77beba51f716a259a3538dd55a38711923 /e-util
parent6b2a55be48922c9fe5c94d654a4d463f23a428f2 (diff)
downloadgsoc2013-evolution-8962868ff902e58456c545478e62796029d1fe5c.tar.gz
gsoc2013-evolution-8962868ff902e58456c545478e62796029d1fe5c.tar.zst
gsoc2013-evolution-8962868ff902e58456c545478e62796029d1fe5c.zip
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.
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-binding.c45
-rw-r--r--e-util/e-binding.h24
2 files changed, 45 insertions, 24 deletions
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;
diff --git a/e-util/e-binding.h b/e-util/e-binding.h
index a36c94ec81..180edc9f49 100644
--- a/e-util/e-binding.h
+++ b/e-util/e-binding.h
@@ -66,39 +66,39 @@ struct _EMutualBinding {
EBindingLink reverse;
};
-EBinding * e_binding_new (GObject *src_object,
+EBinding * e_binding_new (gpointer src_object,
const gchar *src_property,
- GObject *dst_object,
+ gpointer dst_object,
const gchar *dst_property);
-EBinding * e_binding_new_full (GObject *src_object,
+EBinding * 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,
gpointer user_data);
-EBinding * e_binding_new_with_negation (GObject *src_object,
+EBinding * e_binding_new_with_negation (gpointer src_object,
const gchar *src_property,
- GObject *dst_object,
+ gpointer dst_object,
const gchar *dst_property);
void e_binding_unbind (EBinding *binding);
-EMutualBinding *e_mutual_binding_new (GObject *object1,
+EMutualBinding *e_mutual_binding_new (gpointer object1,
const gchar *property1,
- GObject *object2,
+ gpointer object2,
const gchar *property2);
-EMutualBinding *e_mutual_binding_new_full (GObject *object1,
+EMutualBinding *e_mutual_binding_new_full (gpointer object1,
const gchar *property1,
- GObject *object2,
+ gpointer object2,
const gchar *property2,
EBindingTransform transform,
EBindingTransform reverse_transform,
GDestroyNotify destroy_notify,
gpointer user_data);
EMutualBinding *e_mutual_binding_new_with_negation
- (GObject *object1,
+ (gpointer object1,
const gchar *property1,
- GObject *object2,
+ gpointer object2,
const gchar *property2);
void e_mutual_binding_unbind (EMutualBinding *binding);