[evolution-data-server/evolution-data-server-3-12] Disabling/enabling Collection master source doesn't update children properly



commit aeb9f3ede7e0f50cde68d4c87d97ec36d71d8cd7
Author: Milan Crha <mcrha redhat com>
Date:   Wed Oct 29 20:39:25 2014 +0100

    Disabling/enabling Collection master source doesn't update children properly
    
    Calendar, contacts and mail related children sources depend on two
    parent's properties, one is for the sub-part enabled state and another
    is the 'enabled' property of the parent ESource. Such children
    sources listen for change of their sub-part only, which might reflect
    incorrect value of the child's enabled state. This could be fixed
    on the server side on load of the children, but the change was not
    noticed, thus the ESource was not saved and the client side loaded
    the ESource with an old value from the disk.

 libebackend/e-collection-backend.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/libebackend/e-collection-backend.c b/libebackend/e-collection-backend.c
index d41998d..bf1e3ff 100644
--- a/libebackend/e-collection-backend.c
+++ b/libebackend/e-collection-backend.c
@@ -71,6 +71,7 @@ struct _ECollectionBackendPrivate {
 
        gulong source_added_handler_id;
        gulong source_removed_handler_id;
+       gulong notify_enabled_handler_id;
 };
 
 enum {
@@ -478,6 +479,28 @@ collection_backend_source_removed_cb (ESourceRegistryServer *server,
        g_object_unref (parent_source);
 }
 
+static void
+collection_backend_source_enabled_cb (ESource *source,
+                                     GParamSpec *spec,
+                                     EBackend *backend)
+{
+       ESource *collection_source;
+       GObject *collection;
+
+       g_return_if_fail (E_IS_COLLECTION_BACKEND (backend));
+
+       collection_source = e_backend_get_source (E_BACKEND (backend));
+       collection = e_source_get_extension (collection_source, E_SOURCE_EXTENSION_COLLECTION);
+
+       /* Some child sources depend on both sub-part enabled and the main
+          ESource::enabled state, thus if the main's ESource::enabled
+          changes, then also notify the change of the sub-parts, thus
+          child's enabled property is properly recalculated. */
+       g_object_notify (collection, "calendar-enabled");
+       g_object_notify (collection, "contacts-enabled");
+       g_object_notify (collection, "mail-enabled");
+}
+
 static gboolean
 collection_backend_populate_idle_cb (gpointer user_data)
 {
@@ -630,6 +653,15 @@ collection_backend_dispose (GObject *object)
                g_object_unref (server);
        }
 
+       if (priv->notify_enabled_handler_id) {
+               ESource *source = e_backend_get_source (E_BACKEND (object));
+
+               if (source)
+                       g_signal_handler_disconnect (source, priv->notify_enabled_handler_id);
+
+               priv->notify_enabled_handler_id = 0;
+       }
+
        g_mutex_lock (&priv->children_lock);
        g_hash_table_remove_all (priv->children);
        g_mutex_unlock (&priv->children_lock);
@@ -742,6 +774,9 @@ collection_backend_constructed (GObject *object)
 
        g_object_unref (server);
 
+       backend->priv->notify_enabled_handler_id = g_signal_connect (source, "notify::enabled",
+               G_CALLBACK (collection_backend_source_enabled_cb), backend);
+
        /* Populate the newly-added collection from an idle callback
         * so persistent child sources have a chance to be added first. */
 


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