aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2014-04-11 16:49:15 +0800
committerMilan Crha <mcrha@redhat.com>2014-04-11 16:49:15 +0800
commit3bd387bc25f784a259d2a99c997884bd36aee3e7 (patch)
treeb176bd81f8f54b3b080d973e0672aceb26c26d75 /e-util
parent0d1eef0daddb38ccad1fc9caa99d32f4e84bb100 (diff)
downloadgsoc2013-evolution-3bd387bc25f784a259d2a99c997884bd36aee3e7.tar
gsoc2013-evolution-3bd387bc25f784a259d2a99c997884bd36aee3e7.tar.gz
gsoc2013-evolution-3bd387bc25f784a259d2a99c997884bd36aee3e7.tar.bz2
gsoc2013-evolution-3bd387bc25f784a259d2a99c997884bd36aee3e7.tar.lz
gsoc2013-evolution-3bd387bc25f784a259d2a99c997884bd36aee3e7.tar.xz
gsoc2013-evolution-3bd387bc25f784a259d2a99c997884bd36aee3e7.tar.zst
gsoc2013-evolution-3bd387bc25f784a259d2a99c997884bd36aee3e7.zip
Bug #684425 - Do not pass NULL text to gtk_entry_set_text()
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-misc-utils.c81
-rw-r--r--e-util/e-misc-utils.h13
-rw-r--r--e-util/e-source-config.c7
3 files changed, 98 insertions, 3 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);
+}
diff --git a/e-util/e-misc-utils.h b/e-util/e-misc-utils.h
index 1a0e734dec..f5b6c29bcd 100644
--- a/e-util/e-misc-utils.h
+++ b/e-util/e-misc-utils.h
@@ -184,6 +184,19 @@ gboolean e_binding_transform_uid_to_source
GValue *target_value,
ESourceRegistry *registry);
+gboolean e_binding_transform_text_non_null
+ (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer user_data);
+
+GBinding * e_binding_bind_object_text_property
+ (gpointer source,
+ const gchar *source_property,
+ gpointer target,
+ const gchar *target_property,
+ GBindingFlags flags);
+
G_END_DECLS
#endif /* E_MISC_UTILS_H */
diff --git a/e-util/e-source-config.c b/e-util/e-source-config.c
index 65b41fee66..57baf44ce8 100644
--- a/e-util/e-source-config.c
+++ b/e-util/e-source-config.c
@@ -24,6 +24,7 @@
#include "e-interval-chooser.h"
#include "e-marshal.h"
+#include "e-misc-utils.h"
#include "e-source-config-backend.h"
#define E_SOURCE_CONFIG_GET_PRIVATE(obj) \
@@ -769,12 +770,12 @@ static void
source_config_init_candidate (ESourceConfig *config,
ESource *scratch_source)
{
- g_object_bind_property (
+ e_binding_bind_object_text_property (
scratch_source, "display-name",
config->priv->name_label, "label",
G_BINDING_SYNC_CREATE);
- g_object_bind_property (
+ e_binding_bind_object_text_property (
scratch_source, "display-name",
config->priv->name_entry, "text",
G_BINDING_BIDIRECTIONAL |
@@ -1463,7 +1464,7 @@ e_source_config_add_user_entry (ESourceConfig *config,
config, scratch_source, _("User"), widget);
gtk_widget_show (widget);
- g_object_bind_property (
+ e_binding_bind_object_text_property (
extension, "user",
widget, "text",
G_BINDING_BIDIRECTIONAL |