[gnome-todo] task-list-eds: Use asynchronous API
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] task-list-eds: Use asynchronous API
- Date: Sat, 20 Jul 2019 22:15:24 +0000 (UTC)
commit b385dec8ed163275d8c280f3a8d1057896d223bc
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sat Jul 20 18:52:08 2019 -0300
task-list-eds: Use asynchronous API
Instead of loading immediately, use an idle-based
asynchronous API to load EDS task lists.
plugins/eds/gtd-provider-eds.c | 61 +++++++++++++++++++++----------
plugins/eds/gtd-task-list-eds.c | 79 ++++++++++++++++++++++++++++++++++++-----
plugins/eds/gtd-task-list-eds.h | 12 +++++--
3 files changed, 121 insertions(+), 31 deletions(-)
---
diff --git a/plugins/eds/gtd-provider-eds.c b/plugins/eds/gtd-provider-eds.c
index 607d589..a3a79a3 100644
--- a/plugins/eds/gtd-provider-eds.c
+++ b/plugins/eds/gtd-provider-eds.c
@@ -113,17 +113,50 @@ ensure_offline_sync (GtdProviderEds *self,
* Callbacks
*/
+static void
+on_task_list_eds_loaded_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ g_autoptr (ESource) default_source = NULL;
+ g_autoptr (GError) error = NULL;
+ GtdProviderEdsPrivate *priv;
+ GtdProviderEds *self;
+ GtdTaskListEds *list;
+ ESource *source;
+
+ self = GTD_PROVIDER_EDS (user_data);
+ priv = gtd_provider_eds_get_instance_private (self);
+ list = gtd_task_list_eds_new_finish (result, &error);
+
+ if (error)
+ {
+ g_warning ("Error creating task list: %s", error->message);
+ return;
+ }
+
+ source = gtd_task_list_eds_get_source (list);
+
+ g_hash_table_add (priv->task_lists, list);
+ g_object_set_data (G_OBJECT (source), "task-list", list);
+
+ /* Check if the current list is the default one */
+ default_source = e_source_registry_ref_default_task_list (priv->source_registry);
+
+ if (default_source == source)
+ g_object_notify (G_OBJECT (self), "default-task-list");
+
+ g_debug ("Task list '%s' successfully connected", e_source_get_display_name (source));
+}
+
static void
on_client_connected_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
- g_autoptr (ESource) default_source = NULL;
- g_autoptr (ESource) parent = NULL;
g_autoptr (GError) error = NULL;
GtdProviderEdsPrivate *priv;
GtdProviderEds *self;
- GtdTaskListEds *list;
ECalClient *client;
ESource *source;
@@ -147,23 +180,13 @@ on_client_connected_cb (GObject *source_object,
ensure_offline_sync (self, source);
- /* parent source's display name is list's origin */
- parent = e_source_registry_ref_source (priv->source_registry, e_source_get_parent (source));
-
/* creates a new task list */
- list = gtd_task_list_eds_new (GTD_PROVIDER (self), source, client);
-
- g_hash_table_add (priv->task_lists, list);
-
- g_object_set_data (G_OBJECT (source), "task-list", list);
-
- /* Check if the current list is the default one */
- default_source = e_source_registry_ref_default_task_list (priv->source_registry);
-
- if (default_source == source)
- g_object_notify (G_OBJECT (self), "default-task-list");
-
- g_debug ("Task list '%s' successfully connected", e_source_get_display_name (source));
+ gtd_task_list_eds_new (GTD_PROVIDER (self),
+ source,
+ client,
+ on_task_list_eds_loaded_cb,
+ priv->cancellable,
+ self);
}
static void
diff --git a/plugins/eds/gtd-task-list-eds.c b/plugins/eds/gtd-task-list-eds.c
index 8d12bd3..748bbdb 100644
--- a/plugins/eds/gtd-task-list-eds.c
+++ b/plugins/eds/gtd-task-list-eds.c
@@ -40,6 +40,13 @@ struct _GtdTaskListEds
GCancellable *cancellable;
};
+typedef struct
+{
+ GtdProvider *provider;
+ ESource *source;
+ ECalClient *client;
+} NewTaskListData;
+
typedef struct
{
GtdTask *child;
@@ -65,6 +72,20 @@ enum
* Auxiliary methods
*/
+static void
+new_task_list_data_free (gpointer data)
+{
+ NewTaskListData *list_data = data;
+
+ if (!list_data)
+ return;
+
+ g_clear_object (&list_data->provider);
+ g_clear_object (&list_data->source);
+ g_clear_object (&list_data->client);
+ g_free (list_data);
+}
+
static PendingSubtaskData*
pending_subtask_data_new (GtdTask *child,
const gchar *parent_uid)
@@ -300,6 +321,25 @@ process_pending_subtasks (GtdTaskListEds *self,
* Callbacks
*/
+static gboolean
+new_task_list_in_idle_cb (gpointer data)
+{
+ g_autoptr (GtdTaskListEds) list_eds = NULL;
+ g_autoptr (GTask) task = data;
+ NewTaskListData *list_data;
+
+ list_data = g_task_get_task_data (task);
+ list_eds = g_object_new (GTD_TYPE_TASK_LIST_EDS,
+ "provider", list_data->provider,
+ "source", list_data->source,
+ "client", list_data->client,
+ NULL);
+
+ g_task_return_pointer (task, g_steal_pointer (&list_eds), NULL);
+
+ return G_SOURCE_REMOVE;
+}
+
static void
on_client_objects_modified_for_migration_cb (GObject *object,
GAsyncResult *result,
@@ -806,16 +846,37 @@ gtd_task_list_eds_init (GtdTaskListEds *self)
self->pending_subtasks = g_ptr_array_new_with_free_func ((GDestroyNotify) pending_subtask_data_free);
}
+void
+gtd_task_list_eds_new (GtdProvider *provider,
+ ESource *source,
+ ECalClient *client,
+ GAsyncReadyCallback callback,
+ GCancellable *cancellable,
+ gpointer user_data)
+{
+ g_autoptr (GTask) task = NULL;
+ NewTaskListData *data;
+
+ data = g_new (NewTaskListData, 1);
+ data->provider = g_object_ref (provider);
+ data->source = g_object_ref (source);
+ data->client = g_object_ref (client);
+
+ task = g_task_new (NULL, cancellable, callback, user_data);
+ g_task_set_task_data (task, data, new_task_list_data_free);
+ g_task_set_source_tag (task, gtd_task_list_eds_new);
+
+ g_idle_add (new_task_list_in_idle_cb, g_steal_pointer (&task));
+}
+
GtdTaskListEds*
-gtd_task_list_eds_new (GtdProvider *provider,
- ESource *source,
- ECalClient *client)
-{
- return g_object_new (GTD_TYPE_TASK_LIST_EDS,
- "provider", provider,
- "source", source,
- "client", client,
- NULL);
+gtd_task_list_eds_new_finish (GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (G_IS_TASK (result), NULL);
+ g_return_val_if_fail (!error || !*error, NULL);
+
+ return g_task_propagate_pointer (G_TASK (result), error);
}
ESource*
diff --git a/plugins/eds/gtd-task-list-eds.h b/plugins/eds/gtd-task-list-eds.h
index 99c400d..7fc2ada 100644
--- a/plugins/eds/gtd-task-list-eds.h
+++ b/plugins/eds/gtd-task-list-eds.h
@@ -30,9 +30,15 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GtdTaskListEds, gtd_task_list_eds, GTD, TASK_LIST_EDS, GtdTaskList)
-GtdTaskListEds* gtd_task_list_eds_new (GtdProvider *provider,
- ESource *source,
- ECalClient *client);
+void gtd_task_list_eds_new (GtdProvider *provider,
+ ESource *source,
+ ECalClient *client,
+ GAsyncReadyCallback callback,
+ GCancellable *cancellable,
+ gpointer user_data);
+
+GtdTaskListEds* gtd_task_list_eds_new_finish (GAsyncResult *result,
+ GError **error);
ESource* gtd_task_list_eds_get_source (GtdTaskListEds *list);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]