[gnome-todo/wip/gbsneto/plugins: 60/62] provider-eds: add timeout to add tasklists



commit 598a36fadb7806d0ea983b195bf0c38ea0df67cf
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Jan 14 21:02:29 2016 -0200

    provider-eds: add timeout to add tasklists
    
    As asked by Milan Crha, since we can't guarantee
    the ordering of signal hooks, wait a small time
    before actually adding the tasklist.

 plugins/eds/gtd-provider-eds.c |   41 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 3 deletions(-)
---
diff --git a/plugins/eds/gtd-provider-eds.c b/plugins/eds/gtd-provider-eds.c
index f008350..c6ffd23 100644
--- a/plugins/eds/gtd-provider-eds.c
+++ b/plugins/eds/gtd-provider-eds.c
@@ -205,12 +205,21 @@ gtd_provider_eds_on_client_connected (GObject      *source_object,
 
 }
 
-static void
-gtd_provider_eds_load_source (GtdProviderEds *provider,
-                              ESource        *source)
+typedef struct
+{
+  GtdProviderEds *provider;
+  ESource        *source;
+} LoadSourceData;
+
+static gboolean
+gtd_provider_eds_load_source_cb (LoadSourceData *data)
 {
   GtdProviderEdsPrivate *priv;
+  GtdProviderEds *provider;
+  ESource *source;
 
+  provider = data->provider;
+  source = data->source;
   priv = gtd_provider_eds_get_instance_private (provider);
 
   if (e_source_has_extension (source, E_SOURCE_EXTENSION_TASK_LIST) &&
@@ -224,6 +233,32 @@ gtd_provider_eds_load_source (GtdProviderEds *provider,
                             gtd_provider_eds_on_client_connected,
                             provider);
     }
+
+  g_free (data);
+
+  return G_SOURCE_REMOVE;
+}
+
+static void
+gtd_provider_eds_load_source (GtdProviderEds *provider,
+                              ESource        *source)
+{
+  LoadSourceData *data;
+
+  data = g_new0 (LoadSourceData, 1);
+  data->provider = provider;
+  data->source = source;
+
+  /* HACK: I really don't like to use arbitrary timeouts on
+   * my code, but we have absolutely no guarantees that
+   * ESourceRegistry::source-added was emited to the other
+   * objects before. So Milan Crha told me to add this timeout
+   * and "guarantee" that other objects will receive the
+   * signal.
+   */
+  g_timeout_add (1000,
+                 (GSourceFunc) gtd_provider_eds_load_source_cb,
+                 data);
 }
 
 static void


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