[evolution-data-server] Bug #678901 - Fake ESource::changed notifications



commit c982babcd69d1059ecbe01d2de9bade4073d9859
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jul 3 11:17:51 2012 +0200

    Bug #678901 - Fake ESource::changed notifications

 camel/providers/imap/camel-imap-settings.c |    3 ++
 libedataserver/e-source-extension.c        |    5 +--
 libedataserver/e-source.c                  |   43 ++++++++++++++++++++++++++--
 3 files changed, 45 insertions(+), 6 deletions(-)
---
diff --git a/camel/providers/imap/camel-imap-settings.c b/camel/providers/imap/camel-imap-settings.c
index fabc08b..b2f2797 100644
--- a/camel/providers/imap/camel-imap-settings.c
+++ b/camel/providers/imap/camel-imap-settings.c
@@ -632,6 +632,9 @@ camel_imap_settings_init (CamelImapSettings *settings)
 {
 	settings->priv = CAMEL_IMAP_SETTINGS_GET_PRIVATE (settings);
 	settings->priv->property_lock = g_mutex_new ();
+
+	/* The default namespace is an empty string. */
+	settings->priv->namespace = g_strdup ("");
 }
 
 /**
diff --git a/libedataserver/e-source-extension.c b/libedataserver/e-source-extension.c
index 330fe7d..961d789 100644
--- a/libedataserver/e-source-extension.c
+++ b/libedataserver/e-source-extension.c
@@ -131,9 +131,8 @@ source_extension_notify (GObject *object,
 static void
 source_extension_constructed (GObject *object)
 {
-	/* This allows subclasses to chain up safely since GObject
-	 * does not implement this method, and we might want to do
-	 * something here in the future. */
+	/* Chain up to parent's constructed() method. */
+	G_OBJECT_CLASS (e_source_extension_parent_class)->constructed (object);
 }
 
 static void
diff --git a/libedataserver/e-source.c b/libedataserver/e-source.c
index 1e1357e..e60ef7a 100644
--- a/libedataserver/e-source.c
+++ b/libedataserver/e-source.c
@@ -115,6 +115,7 @@ struct _ESourcePrivate {
 
 	GSource *changed;
 	GMutex *changed_lock;
+	guint ignore_changed_signal;
 
 	GMutex *property_lock;
 
@@ -1044,6 +1045,10 @@ source_initable_init (GInitable *initable,
 		EDBusObject *dbus_object;
 		EDBusSource *dbus_source;
 
+		g_mutex_lock (source->priv->changed_lock);
+		source->priv->ignore_changed_signal++;
+		g_mutex_unlock (source->priv->changed_lock);
+
 		dbus_object = E_DBUS_OBJECT (source->priv->dbus_object);
 
 		/* An EDBusObject lacking an EDBusSource
@@ -1086,12 +1091,20 @@ source_initable_init (GInitable *initable,
 
 		g_object_unref (dbus_source);
 
+		g_mutex_lock (source->priv->changed_lock);
+		source->priv->ignore_changed_signal--;
+		g_mutex_unlock (source->priv->changed_lock);
+
 	/* No D-Bus object implies we're configuring a new source,
 	 * so generate a new unique identifier (UID) for it. */
 	} else {
 		source->priv->uid = e_uid_new ();
 	}
 
+	/* if this is set on class_init, then it is invoked each
+	   time during construction, which is not desired */
+	G_OBJECT_GET_CLASS (source)->notify = source_notify;
+
 	return success;
 }
 
@@ -1107,7 +1120,6 @@ e_source_class_init (ESourceClass *class)
 	object_class->get_property = source_get_property;
 	object_class->dispose = source_dispose;
 	object_class->finalize = source_finalize;
-	object_class->notify = source_notify;
 
 	class->remove_sync = source_remove_sync;
 	class->remove = source_remove;
@@ -1284,6 +1296,10 @@ e_source_init (ESource *source)
 	source->priv->key_file = g_key_file_new ();
 	source->priv->extensions = extensions;
 
+	/* changed signal is disabled by default,
+	   to avoid notifications during creation */
+	source->priv->ignore_changed_signal = 1;
+
 	g_static_rec_mutex_init (&source->priv->lock);
 }
 
@@ -1314,14 +1330,26 @@ e_source_new (GDBusObject *dbus_object,
               GMainContext *main_context,
               GError **error)
 {
+	ESource *source;
+
 	if (dbus_object != NULL)
 		g_return_val_if_fail (E_DBUS_IS_OBJECT (dbus_object), NULL);
 
-	return g_initable_new (
+	source = g_initable_new (
 		E_TYPE_SOURCE, NULL, error,
 		"dbus-object", dbus_object,
 		"main-context", main_context,
 		NULL);
+
+	/* changed signal is disabled by default,
+	   to avoid notifications during creation;
+	   unlock it here
+	*/
+	g_mutex_lock (source->priv->changed_lock);
+	source->priv->ignore_changed_signal--;
+	g_mutex_unlock (source->priv->changed_lock);
+
+	return source;
 }
 
 /**
@@ -1396,7 +1424,8 @@ e_source_changed (ESource *source)
 	g_return_if_fail (E_IS_SOURCE (source));
 
 	g_mutex_lock (source->priv->changed_lock);
-	if (source->priv->changed == NULL) {
+	if (!source->priv->ignore_changed_signal &&
+	    source->priv->changed == NULL) {
 		source->priv->changed = g_idle_source_new ();
 		g_source_set_callback (
 			source->priv->changed,
@@ -1691,6 +1720,10 @@ e_source_get_extension (ESource *source,
 
 	/* Create a new instance of the appropriate GType. */
 	if (class != NULL) {
+		g_mutex_lock (source->priv->changed_lock);
+		source->priv->ignore_changed_signal++;
+		g_mutex_unlock (source->priv->changed_lock);
+
 		extension = g_object_new (
 			G_TYPE_FROM_CLASS (class),
 			"source", source, NULL);
@@ -1701,6 +1734,10 @@ e_source_get_extension (ESource *source,
 		g_hash_table_insert (
 			source->priv->extensions,
 			g_strdup (extension_name), extension);
+
+		g_mutex_lock (source->priv->changed_lock);
+		source->priv->ignore_changed_signal--;
+		g_mutex_unlock (source->priv->changed_lock);
 	} else {
 		/* XXX Tie this into a debug setting for ESources. */
 #ifdef DEBUG



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