aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-misc-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'e-util/e-misc-utils.c')
-rw-r--r--e-util/e-misc-utils.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/e-util/e-misc-utils.c b/e-util/e-misc-utils.c
index f47dc19275..0f935d49af 100644
--- a/e-util/e-misc-utils.c
+++ b/e-util/e-misc-utils.c
@@ -2109,3 +2109,84 @@ e_binding_transform_uid_to_source (GBinding *binding,
return success;
}
+
+/**
+ * e_binding_transform_text_non_null:
+ * @binding: a #GBinding
+ * @source_value: a #GValue of type #G_TYPE_STRING
+ * @target_value: a #GValue of type #G_TYPE_STRING
+ * @user_data: custom user data, unused
+ *
+ * Transforms a text value to a text value which is never NULL;
+ * an empty string is used instead of NULL.
+ *
+ * Returns: %TRUE on success
+ **/
+gboolean
+e_binding_transform_text_non_null (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data)
+{
+ const gchar *str;
+
+ g_return_val_if_fail (G_IS_BINDING (binding), FALSE);
+ g_return_val_if_fail (source_value != NULL, FALSE);
+ g_return_val_if_fail (target_value != NULL, FALSE);
+
+ str = g_value_get_string (source_value);
+ if (!str)
+ str = "";
+
+ g_value_set_string (target_value, str);
+
+ return TRUE;
+}
+
+/**
+ * e_binding_bind_object_text_property:
+ * @source: the source #GObject
+ * @source_property: the text property on the source to bind
+ * @target: the target #GObject
+ * @target_property: the text property on the target to bind
+ * @flags: flags to pass to g_object_bind_property_full()
+ *
+ * Installs a new text property object binding, using g_object_bind_property_full(),
+ * with transform functions to make sure that a NULL pointer is not
+ * passed in either way. Instead of NULL an empty string is used.
+ *
+ * Returns: the #GBinding instance representing the binding between the two #GObject instances;
+ * there applies the same rules to it as for the result of g_object_bind_property_full().
+ **/
+GBinding *
+e_binding_bind_object_text_property (gpointer source,
+ const gchar *source_property,
+ gpointer target,
+ const gchar *target_property,
+ GBindingFlags flags)
+{
+ GObjectClass *klass;
+ GParamSpec *property;
+
+ g_return_val_if_fail (G_IS_OBJECT (source), NULL);
+ g_return_val_if_fail (source_property != NULL, NULL);
+ g_return_val_if_fail (G_IS_OBJECT (target), NULL);
+ g_return_val_if_fail (target_property != NULL, NULL);
+
+ klass = G_OBJECT_GET_CLASS (source);
+ property = g_object_class_find_property (klass, source_property);
+ g_return_val_if_fail (property != NULL, NULL);
+ g_return_val_if_fail (property->value_type == G_TYPE_STRING, NULL);
+
+ klass = G_OBJECT_GET_CLASS (target);
+ property = g_object_class_find_property (klass, target_property);
+ g_return_val_if_fail (property != NULL, NULL);
+ g_return_val_if_fail (property->value_type == G_TYPE_STRING, NULL);
+
+ return g_object_bind_property_full (source, source_property,
+ target, target_property,
+ flags,
+ e_binding_transform_text_non_null,
+ e_binding_transform_text_non_null,
+ NULL, NULL);
+}