TnyAccount: Prevent unnecessary signal emission.



This patch adds some checks that stop TnyAccount's set() functions from
emitting its changed signal when nothing has actually changed. I notice
that the GtkTreeView cell_data_func callbacks in modest are still being
called too often, even with this patch, but at least this removes this
possible cause for that.

In modest this problem even caused an infinite loop of signalling and
setting.

-- 
murrayc murrayc com
www.murrayc.com
www.openismus.com
Index: libtinymail-camel/tny-camel-account.c
===================================================================
--- libtinymail-camel/tny-camel-account.c	(revision 2695)
+++ libtinymail-camel/tny-camel-account.c	(working copy)
@@ -496,12 +496,30 @@
 	TNY_CAMEL_ACCOUNT_GET_CLASS (self)->set_url_string_func (self, url_string);
 }
 
+/* Simplify checks for NULLs: */
+static gboolean
+strings_are_equal (const gchar *a, const gchar *b)
+{
+	if (!a && !b)
+		return TRUE;
+	if (a && b)
+	{
+		return (strcmp (a, b) == 0);
+	}
+	else
+		return FALSE;
+}
+
 static void
 tny_camel_account_set_url_string_default (TnyAccount *self, const gchar *url_string)
 {
 	TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self);
 	gboolean changed = FALSE;
 
+	/* Ignore this if it is not a change: */
+	if (strings_are_equal (priv->url_string, url_string))
+		return;
+
 	g_static_rec_mutex_lock (priv->service_lock);
 
 	if (!url_string)
@@ -557,6 +575,10 @@
 {
 	TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self);
 
+	/* Ignore this if it is not a change: */
+	if (strings_are_equal (priv->name, name))
+		return;
+
 	if (priv->name)
 		g_free (priv->name);
 	priv->name = g_strdup (name);
@@ -799,6 +821,10 @@
 {
 	TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self);
 
+	/* Ignore this if it is not a change: */
+	if (strings_are_equal (priv->id, id))
+		return;
+
 	if (priv->id)
 		g_free (priv->id);
 	priv->id = g_strdup (id);
@@ -820,6 +846,10 @@
 	TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self);
 	gboolean changed = FALSE;
 
+	/* Ignore this if it is not a change: */
+	if (strings_are_equal (priv->mech, mech))
+		return;
+
 	g_static_rec_mutex_lock (priv->service_lock);
 
 	priv->custom_url_string = FALSE;
@@ -861,6 +891,10 @@
 	TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self);
 	gboolean changed = FALSE;
 
+	/* Ignore this if it is not a change: */
+	if (strings_are_equal (priv->proto, proto))
+		return;
+
 	g_static_rec_mutex_lock (priv->service_lock);
 
 	priv->custom_url_string = FALSE;
@@ -902,6 +936,10 @@
 	TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self);
 	gboolean changed = FALSE;
 
+	/* Ignore this if it is not a change: */
+	if (strings_are_equal (priv->user, user))
+		return;
+
 	g_static_rec_mutex_lock (priv->service_lock);
 
 	priv->custom_url_string = FALSE;
@@ -944,6 +982,10 @@
 	TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self);
 	gboolean changed = FALSE;
 
+	/* Ignore this if it is not a change: */
+	if (strings_are_equal (priv->host, host))
+		return;
+
 	g_static_rec_mutex_lock (priv->service_lock);
 
 	priv->custom_url_string = FALSE;
@@ -988,6 +1030,10 @@
 	TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self);
 	gboolean changed = FALSE;
 
+	/* Ignore this if it is not a change: */
+	if (port == priv->port)
+		return;
+
 	g_static_rec_mutex_lock (priv->service_lock);
 
 	priv->custom_url_string = FALSE;
@@ -1023,6 +1069,10 @@
 	gboolean reconf_if = FALSE;
 	gboolean changed = FALSE;
 
+	/* Ignore this if it is not a change: */
+	if (get_pass_func == priv->get_pass_func)
+		return;
+
 	g_static_rec_mutex_lock (priv->service_lock);
 
 	if (priv->get_pass_func != get_pass_func)
@@ -1056,6 +1106,10 @@
 	gboolean reconf_if = FALSE;
 	gboolean changed = FALSE;
 
+	/* Ignore this if it is not a change: */
+	if (get_forget_pass_func == priv->forget_pass_func)
+		return;
+
 	g_static_rec_mutex_lock (priv->service_lock);
 
 	if (priv->forget_pass_func != get_forget_pass_func)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 2695)
+++ ChangeLog	(working copy)
@@ -1,3 +1,19 @@
+2007-09-04  Murray Cumming  <murrayc murrayc com>
+
+	* libtinymail-camel/tny-camel-account.c:
+	(tny_camel_account_set_url_string_default),
+	(tny_camel_account_set_name_default),
+	(tny_camel_account_set_id_default),
+	(tny_camel_account_set_secure_auth_mech_default),
+	(tny_camel_account_set_proto_default),
+	(tny_camel_account_set_user_default),
+	(tny_camel_account_set_hostname_default),
+	(tny_camel_account_set_port_default),
+	(tny_camel_account_set_pass_func_default),
+	(tny_camel_account_set_forget_pass_func_default): Check that the input 
+	is differnt to the existing value, to avoid unnecessarily signalling that 
+	the account has changed.
+
 2007-09-04  Sergio Villar Senin  <svillar igalia com>
 
 	* libtinymail-camel/tny-camel-folder.c: fixed the default function


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