[evolution] Bug #684425 - Do not pass NULL text to gtk_entry_set_text()



commit 3bd387bc25f784a259d2a99c997884bd36aee3e7
Author: Milan Crha <mcrha redhat com>
Date:   Fri Apr 11 10:49:15 2014 +0200

    Bug #684425 - Do not pass NULL text to gtk_entry_set_text()

 e-util/e-misc-utils.c                              |   81 ++++++++++++++++++++
 e-util/e-misc-utils.h                              |   13 +++
 e-util/e-source-config.c                           |    7 +-
 mail/e-mail-config-assistant.c                     |    4 +-
 mail/e-mail-config-defaults-page.c                 |    4 +-
 mail/e-mail-config-identity-page.c                 |   10 +-
 mail/e-mail-config-provider-page.c                 |    2 +-
 mail/e-mail-config-security-page.c                 |    6 +-
 mail/e-mail-config-welcome-page.c                  |    3 +-
 .../book-config-ldap/evolution-book-config-ldap.c  |    8 +-
 .../evolution-cal-config-caldav.c                  |    2 +-
 .../mail-config/e-mail-config-remote-accounts.c    |    4 +-
 .../mail-config/e-mail-config-sendmail-backend.c   |    5 +-
 modules/mail-config/e-mail-config-smtp-backend.c   |    4 +-
 .../e-mail-config-import-progress-page.c           |    2 +-
 15 files changed, 126 insertions(+), 29 deletions(-)
---
diff --git a/e-util/e-misc-utils.c b/e-util/e-misc-utils.c
index f47dc19..0f935d4 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 1a0e734..f5b6c29 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 65b41fe..57baf44 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 |
diff --git a/mail/e-mail-config-assistant.c b/mail/e-mail-config-assistant.c
index 1078fc2..5688494 100644
--- a/mail/e-mail-config-assistant.c
+++ b/mail/e-mail-config-assistant.c
@@ -728,7 +728,7 @@ mail_config_assistant_constructed (GObject *object)
        e_mail_config_assistant_add_page (assistant, page);
        assistant->priv->receiving_page = g_object_ref (page);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                mail_identity_extension, "address",
                page, "email-address",
                G_BINDING_SYNC_CREATE);
@@ -811,7 +811,7 @@ mail_config_assistant_constructed (GObject *object)
        e_mail_config_assistant_add_page (assistant, page);
        assistant->priv->sending_page = g_object_ref (page);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                mail_identity_extension, "address",
                page, "email-address",
                G_BINDING_SYNC_CREATE);
diff --git a/mail/e-mail-config-defaults-page.c b/mail/e-mail-config-defaults-page.c
index 7298e09..5e85d64 100644
--- a/mail/e-mail-config-defaults-page.c
+++ b/mail/e-mail-config-defaults-page.c
@@ -573,7 +573,7 @@ mail_config_defaults_page_constructed (GObject *object)
        page->priv->drafts_button = widget;  /* not referenced */
        gtk_widget_show (widget);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                composition_ext, "drafts-folder",
                widget, "folder-uri",
                G_BINDING_BIDIRECTIONAL |
@@ -602,7 +602,7 @@ mail_config_defaults_page_constructed (GObject *object)
                gtk_widget_set_sensitive (widget, FALSE);
        }
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                submission_ext, "sent-folder",
                widget, "folder-uri",
                G_BINDING_BIDIRECTIONAL |
diff --git a/mail/e-mail-config-identity-page.c b/mail/e-mail-config-identity-page.c
index 6c9072f..5526105 100644
--- a/mail/e-mail-config-identity-page.c
+++ b/mail/e-mail-config-identity-page.c
@@ -323,7 +323,7 @@ mail_config_identity_page_constructed (GObject *object)
        gtk_grid_attach (GTK_GRID (container), widget, 1, 2, 1, 1);
        gtk_widget_show (widget);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                source, "display-name",
                widget, "text",
                G_BINDING_BIDIRECTIONAL |
@@ -369,7 +369,7 @@ mail_config_identity_page_constructed (GObject *object)
        gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 1, 1);
        gtk_widget_show (widget);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                extension, "name",
                widget, "text",
                G_BINDING_BIDIRECTIONAL |
@@ -401,7 +401,7 @@ mail_config_identity_page_constructed (GObject *object)
        gtk_grid_attach (GTK_GRID (container), widget, 1, 2, 1, 1);
        gtk_widget_show (widget);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                extension, "address",
                widget, "text",
                G_BINDING_BIDIRECTIONAL |
@@ -452,7 +452,7 @@ mail_config_identity_page_constructed (GObject *object)
        gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 2, 1);
        gtk_widget_show (widget);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                extension, "reply-to",
                widget, "text",
                G_BINDING_BIDIRECTIONAL |
@@ -479,7 +479,7 @@ mail_config_identity_page_constructed (GObject *object)
        gtk_grid_attach (GTK_GRID (container), widget, 1, 2, 2, 1);
        gtk_widget_show (widget);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                extension, "organization",
                widget, "text",
                G_BINDING_BIDIRECTIONAL |
diff --git a/mail/e-mail-config-provider-page.c b/mail/e-mail-config-provider-page.c
index 0bd0033..32c5473 100644
--- a/mail/e-mail-config-provider-page.c
+++ b/mail/e-mail-config-provider-page.c
@@ -343,7 +343,7 @@ mail_config_provider_page_add_entry (EMailConfigProviderPage *page,
        gtk_box_pack_start (GTK_BOX (hbox), input, TRUE, TRUE, 0);
        gtk_widget_show (input);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                settings, entry->name,
                input, "text",
                G_BINDING_BIDIRECTIONAL |
diff --git a/mail/e-mail-config-security-page.c b/mail/e-mail-config-security-page.c
index 4f0dc4b..74c1251 100644
--- a/mail/e-mail-config-security-page.c
+++ b/mail/e-mail-config-security-page.c
@@ -405,7 +405,7 @@ mail_config_security_page_constructed (GObject *object)
        g_warn_if_fail (GTK_IS_ENTRY (widget));
 #endif /* HAVE_LIBCRYPTUI */
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                openpgp_ext, "key-id",
                widget, "text",
                G_BINDING_SYNC_CREATE |
@@ -525,7 +525,7 @@ mail_config_security_page_constructed (GObject *object)
        gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 1, 1);
        gtk_widget_show (widget);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                smime_ext, "signing-certificate",
                widget, "text",
                G_BINDING_BIDIRECTIONAL |
@@ -631,7 +631,7 @@ mail_config_security_page_constructed (GObject *object)
        gtk_grid_attach (GTK_GRID (container), widget, 1, 4, 1, 1);
        gtk_widget_show (widget);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                smime_ext, "encryption-certificate",
                widget, "text",
                G_BINDING_BIDIRECTIONAL |
diff --git a/mail/e-mail-config-welcome-page.c b/mail/e-mail-config-welcome-page.c
index 4459a23..3f00c0f 100644
--- a/mail/e-mail-config-welcome-page.c
+++ b/mail/e-mail-config-welcome-page.c
@@ -20,6 +20,7 @@
 #include <config.h>
 #include <glib/gi18n-lib.h>
 
+#include <e-util/e-util.h>
 #include <libebackend/libebackend.h>
 
 #define E_MAIL_CONFIG_WELCOME_PAGE_GET_PRIVATE(obj) \
@@ -123,7 +124,7 @@ mail_config_welcome_page_constructed (GObject *object)
        gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
        gtk_widget_show (widget);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                page, "text",
                widget, "label",
                G_BINDING_BIDIRECTIONAL |
diff --git a/modules/book-config-ldap/evolution-book-config-ldap.c 
b/modules/book-config-ldap/evolution-book-config-ldap.c
index 7e6880b..feb0167 100644
--- a/modules/book-config-ldap/evolution-book-config-ldap.c
+++ b/modules/book-config-ldap/evolution-book-config-ldap.c
@@ -849,7 +849,7 @@ book_config_ldap_insert_widgets (ESourceConfigBackend *backend,
        is_new_source = !e_source_has_extension (scratch_source, extension_name);
        extension = e_source_get_extension (scratch_source, extension_name);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                extension, "host",
                context->host_entry, "text",
                G_BINDING_BIDIRECTIONAL |
@@ -870,7 +870,7 @@ book_config_ldap_insert_widgets (ESourceConfigBackend *backend,
                context->port_combo, "changed",
                G_CALLBACK (book_config_ldap_port_combo_changed), NULL);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                extension, "user",
                context->auth_entry, "text",
                G_BINDING_BIDIRECTIONAL |
@@ -899,7 +899,7 @@ book_config_ldap_insert_widgets (ESourceConfigBackend *backend,
 
        widget = gtk_bin_get_child (GTK_BIN (context->search_base_combo));
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                extension, "root-dn",
                widget, "text",
                G_BINDING_BIDIRECTIONAL |
@@ -911,7 +911,7 @@ book_config_ldap_insert_widgets (ESourceConfigBackend *backend,
                G_BINDING_BIDIRECTIONAL |
                G_BINDING_SYNC_CREATE);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                extension, "filter",
                context->search_filter_entry, "text",
                G_BINDING_BIDIRECTIONAL |
diff --git a/modules/cal-config-caldav/evolution-cal-config-caldav.c 
b/modules/cal-config-caldav/evolution-cal-config-caldav.c
index e6b73a4..5cd165e 100644
--- a/modules/cal-config-caldav/evolution-cal-config-caldav.c
+++ b/modules/cal-config-caldav/evolution-cal-config-caldav.c
@@ -261,7 +261,7 @@ cal_config_caldav_insert_widgets (ESourceConfigBackend *backend,
                G_BINDING_BIDIRECTIONAL |
                G_BINDING_SYNC_CREATE);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                extension, "email-address",
                context->email_entry, "text",
                G_BINDING_BIDIRECTIONAL |
diff --git a/modules/mail-config/e-mail-config-remote-accounts.c 
b/modules/mail-config/e-mail-config-remote-accounts.c
index 23b3098..15a3d3b 100644
--- a/modules/mail-config/e-mail-config-remote-accounts.c
+++ b/modules/mail-config/e-mail-config-remote-accounts.c
@@ -258,7 +258,7 @@ mail_config_remote_backend_insert_widgets (EMailConfigServiceBackend *backend,
        remote_backend->auth_check = widget;  /* do not reference */
        gtk_widget_show (widget);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                settings, "host",
                remote_backend->host_entry, "text",
                G_BINDING_BIDIRECTIONAL |
@@ -284,7 +284,7 @@ mail_config_remote_backend_insert_widgets (EMailConfigServiceBackend *backend,
                remote_backend->port_entry, "security-method",
                G_BINDING_SYNC_CREATE);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                settings, "user",
                remote_backend->user_entry, "text",
                G_BINDING_BIDIRECTIONAL |
diff --git a/modules/mail-config/e-mail-config-sendmail-backend.c 
b/modules/mail-config/e-mail-config-sendmail-backend.c
index 8508d02..365c20f 100644
--- a/modules/mail-config/e-mail-config-sendmail-backend.c
+++ b/modules/mail-config/e-mail-config-sendmail-backend.c
@@ -22,6 +22,7 @@
 #include <glib/gi18n-lib.h>
 
 #include <camel/camel.h>
+#include <e-util/e-util.h>
 #include <libebackend/libebackend.h>
 
 #include "e-mail-config-sendmail-backend.h"
@@ -139,7 +140,7 @@ mail_config_sendmail_backend_insert_widgets (EMailConfigServiceBackend *backend,
                G_BINDING_BIDIRECTIONAL |
                G_BINDING_SYNC_CREATE);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                settings, "custom-binary",
                custom_binary_entry, "text",
                G_BINDING_BIDIRECTIONAL |
@@ -156,7 +157,7 @@ mail_config_sendmail_backend_insert_widgets (EMailConfigServiceBackend *backend,
                G_BINDING_BIDIRECTIONAL |
                G_BINDING_SYNC_CREATE);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                settings, "custom-args",
                custom_args_entry, "text",
                G_BINDING_BIDIRECTIONAL |
diff --git a/modules/mail-config/e-mail-config-smtp-backend.c 
b/modules/mail-config/e-mail-config-smtp-backend.c
index 71ae6f5..368ffd8 100644
--- a/modules/mail-config/e-mail-config-smtp-backend.c
+++ b/modules/mail-config/e-mail-config-smtp-backend.c
@@ -240,7 +240,7 @@ mail_config_smtp_backend_insert_widgets (EMailConfigServiceBackend *backend,
        port = camel_network_settings_get_port (
                CAMEL_NETWORK_SETTINGS (settings));
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                settings, "host",
                priv->host_entry, "text",
                G_BINDING_BIDIRECTIONAL |
@@ -266,7 +266,7 @@ mail_config_smtp_backend_insert_widgets (EMailConfigServiceBackend *backend,
                priv->port_entry, "security-method",
                G_BINDING_SYNC_CREATE);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                settings, "user",
                priv->user_entry, "text",
                G_BINDING_BIDIRECTIONAL |
diff --git a/modules/startup-wizard/e-mail-config-import-progress-page.c 
b/modules/startup-wizard/e-mail-config-import-progress-page.c
index 5d96a16..14280b7 100644
--- a/modules/startup-wizard/e-mail-config-import-progress-page.c
+++ b/modules/startup-wizard/e-mail-config-import-progress-page.c
@@ -199,7 +199,7 @@ mail_config_import_progress_page_constructed (GObject *object)
        page->priv->progress_bar = widget;  /* not referenced */
        gtk_widget_show (widget);
 
-       g_object_bind_property (
+       e_binding_bind_object_text_property (
                activity, "text",
                widget, "text",
                G_BINDING_SYNC_CREATE);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]