[gnome-todo] manager: Retire gtd_manager_get_task_lists()



commit 7ede540bdb7e5d712f80b4f7da528ccf07389e5f
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Sep 12 20:25:06 2018 -0300

    manager: Retire gtd_manager_get_task_lists()
    
    Fully replace it by gtd_manager_get_task_lists_model().

 plugins/background/gtd-plugin-background.c | 16 ++++++++++------
 src/engine/gtd-manager.c                   | 21 ---------------------
 src/engine/gtd-manager.h                   |  2 --
 src/sidebar/gtd-sidebar.c                  | 13 +++++++++----
 4 files changed, 19 insertions(+), 33 deletions(-)
---
diff --git a/plugins/background/gtd-plugin-background.c b/plugins/background/gtd-plugin-background.c
index 9ff4684..ae141bc 100644
--- a/plugins/background/gtd-plugin-background.c
+++ b/plugins/background/gtd-plugin-background.c
@@ -178,27 +178,31 @@ static GList*
 get_tasks_for_today (guint *n_events)
 {
   g_autoptr (GDateTime) now;
+  GListModel *lists;
   GtdManager *manager;
-  GList *task_lists, *l;
   GList *result;
   guint n_tasks;
+  guint i;
 
   now = g_date_time_new_now_local ();
   result = NULL;
   n_tasks = 0;
   manager = gtd_manager_get_default ();
-  task_lists = gtd_manager_get_task_lists (manager);
+  lists = gtd_manager_get_task_lists_model (manager);
 
-  for (l = task_lists; l != NULL; l = l->next)
+  for (i = 0; i < g_list_model_get_n_items (lists); i++)
     {
-      guint i;
+      g_autoptr (GListModel) list = NULL;
+      guint j;
 
-      for (i = 0; i < g_list_model_get_n_items (l->data); i++)
+      list = g_list_model_get_item (lists, i);
+
+      for (j = 0; j < g_list_model_get_n_items (list); j++)
         {
           GDateTime *due_date;
           GtdTask *task;
 
-          task = g_list_model_get_item (l->data, i);
+          task = g_list_model_get_item (list, j);
 
           due_date = gtd_task_get_due_date (task);
 
diff --git a/src/engine/gtd-manager.c b/src/engine/gtd-manager.c
index 4ebc380..723b2b1 100644
--- a/src/engine/gtd-manager.c
+++ b/src/engine/gtd-manager.c
@@ -59,7 +59,6 @@ struct _GtdManager
   GListModel         *lists_model;
   GListModel         *tasks_model;
 
-  GList              *tasklists;
   GList              *providers;
   GList              *panels;
   GtdProvider        *default_provider;
@@ -178,8 +177,6 @@ on_list_added_cb (GtdProvider *provider,
                   GtdTaskList *list,
                   GtdManager  *self)
 {
-  self->tasklists = g_list_append (self->tasklists, list);
-
   gtd_list_store_insert_sorted (GTD_LIST_STORE (self->lists_model),
                                 list,
                                 (GCompareDataFunc) compare_lists_cb,
@@ -223,8 +220,6 @@ on_list_removed_cb (GtdProvider *provider,
   if (!list)
       return;
 
-  self->tasklists = g_list_remove (self->tasklists, list);
-
   gtd_list_store_remove (GTD_LIST_STORE (self->lists_model), list);
 
   g_signal_handlers_disconnect_by_func (list,
@@ -647,22 +642,6 @@ gtd_manager_new (void)
   return g_object_new (GTD_TYPE_MANAGER, NULL);
 }
 
-/**
- * gtd_manager_get_task_lists:
- * @manager: a #GtdManager
- *
- * Retrieves the list of #GtdTaskList already loaded.
- *
- * Returns: (transfer container) (element-type Gtd.TaskList): a newly allocated list of #GtdTaskList, or 
%NULL if none.
- */
-GList*
-gtd_manager_get_task_lists (GtdManager *self)
-{
-  g_return_val_if_fail (GTD_IS_MANAGER (self), NULL);
-
-  return g_list_copy (self->tasklists);
-}
-
 /**
  * gtd_manager_get_providers:
  * @manager: a #GtdManager
diff --git a/src/engine/gtd-manager.h b/src/engine/gtd-manager.h
index 07fd001..ccba2ac 100644
--- a/src/engine/gtd-manager.h
+++ b/src/engine/gtd-manager.h
@@ -40,8 +40,6 @@ GtdManager*          gtd_manager_new                             (void);
 
 GtdManager*          gtd_manager_get_default                     (void);
 
-GList*               gtd_manager_get_task_lists                  (GtdManager         *manager);
-
 GList*               gtd_manager_get_providers                   (GtdManager         *manager);
 
 GList*               gtd_manager_get_panels                      (GtdManager         *manager);
diff --git a/src/sidebar/gtd-sidebar.c b/src/sidebar/gtd-sidebar.c
index 750fc48..5619adf 100644
--- a/src/sidebar/gtd-sidebar.c
+++ b/src/sidebar/gtd-sidebar.c
@@ -420,10 +420,11 @@ gtd_sidebar_constructed (GObject *object)
 {
   g_autoptr (GList) providers = NULL;
   g_autoptr (GList) panels = NULL;
-  g_autoptr (GList) lists = NULL;
+  GListModel *lists;
   GtdManager *manager;
   GtdSidebar *self;
   GList *l;
+  guint i;
 
   self = (GtdSidebar *)object;
   manager = gtd_manager_get_default ();
@@ -449,10 +450,14 @@ gtd_sidebar_constructed (GObject *object)
   g_signal_connect (manager, "provider-removed", G_CALLBACK (on_provider_removed_cb), self);
 
   /* Add task lists */
-  lists = gtd_manager_get_task_lists (manager);
+  lists = gtd_manager_get_task_lists_model (manager);
 
-  for (l = lists; l; l = l->next)
-    add_task_list (self, l->data);
+  for (i = 0; i < g_list_model_get_n_items (lists); i++)
+    {
+      g_autoptr (GtdTaskList) list = g_list_model_get_item (lists, i);
+
+      add_task_list (self, list);
+    }
 
   g_signal_connect (manager, "list-added", G_CALLBACK (on_task_list_added_cb), self);
   g_signal_connect (manager, "list-removed", G_CALLBACK (on_task_list_removed_cb), self);


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