[gnome-todo] task: Remove subtasks handling



commit 18d44930d808f6a3e6c6ff745c1a65f12cfbe67e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Apr 21 18:23:15 2021 -0300

    task: Remove subtasks handling
    
    We'll be moving to a more sophisticated method to handle
    task dependencies in the future. For now, remove subtasks
    from GtdTask

 src/core/gtd-task-list.c            | 141 ++------
 src/core/gtd-task.c                 | 644 ------------------------------------
 src/core/gtd-task.h                 |  33 +-
 src/gui/gtd-task-row.c              |  27 +-
 src/plugins/eds/gtd-task-eds.c      |  56 ----
 src/plugins/eds/gtd-task-list-eds.c | 104 ------
 6 files changed, 31 insertions(+), 974 deletions(-)
---
diff --git a/src/core/gtd-task-list.c b/src/core/gtd-task-list.c
index 59240e1a..480ff784 100644
--- a/src/core/gtd-task-list.c
+++ b/src/core/gtd-task-list.c
@@ -155,22 +155,6 @@ add_task (GtdTaskList *self,
   return g_sequence_iter_get_position (iter);
 }
 
-static void
-recursively_add_subtasks (GtdTaskList *self,
-                          GtdTask     *task)
-{
-  GtdTask *aux;
-
-  for (aux = gtd_task_get_first_subtask (task);
-       aux;
-       aux = gtd_task_get_next_sibling (aux))
-    {
-      add_task (self, aux);
-
-      recursively_add_subtasks (self, aux);
-    }
-}
-
 static guint
 remove_task (GtdTaskList *self,
              GtdTask     *task)
@@ -200,22 +184,6 @@ remove_task (GtdTaskList *self,
   return position;
 }
 
-static void
-recursively_remove_subtasks (GtdTaskList *self,
-                             GtdTask     *task)
-{
-  GtdTask *aux;
-
-  for (aux = gtd_task_get_first_subtask (task);
-       aux;
-       aux = gtd_task_get_next_sibling (aux))
-    {
-      remove_task (self, aux);
-
-      recursively_remove_subtasks (self, aux);
-    }
-}
-
 
 /*
  * Callbacks
@@ -758,25 +726,14 @@ void
 gtd_task_list_add_task (GtdTaskList *self,
                         GtdTask     *task)
 {
-  gint64 n_added;
   guint position;
 
   g_assert (GTD_IS_TASK_LIST (self));
   g_assert (GTD_IS_TASK (task));
   g_assert (!gtd_task_list_contains (self, task));
 
-  n_added = gtd_task_get_n_total_subtasks (task) + 1;
   position = add_task (self, task);
-
-  /* Also remove subtasks */
-  recursively_add_subtasks (self, task);
-
-  GTD_TRACE_MSG ("Adding %ld tasks at %u", n_added, position);
-
-  g_list_model_items_changed (G_LIST_MODEL (self),
-                              position,
-                              0,
-                              n_added);
+  g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);
 }
 
 /**
@@ -821,25 +778,14 @@ void
 gtd_task_list_remove_task (GtdTaskList *list,
                            GtdTask     *task)
 {
-  gint64 n_removed;
   guint position;
 
   g_assert (GTD_IS_TASK_LIST (list));
   g_assert (GTD_IS_TASK (task));
   g_assert (gtd_task_list_contains (list, task));
 
-  n_removed = gtd_task_get_n_total_subtasks (task) + 1;
   position = remove_task (list, task);
-
-  /* Also remove subtasks */
-  recursively_remove_subtasks (list, task);
-
-  GTD_TRACE_MSG ("Removing %ld tasks at %u", n_removed, position);
-
-  g_list_model_items_changed (G_LIST_MODEL (list),
-                              position,
-                              n_removed,
-                              0);
+  g_list_model_items_changed (G_LIST_MODEL (list), position, 1, 0);
 }
 
 /**
@@ -943,8 +889,8 @@ gtd_task_list_get_task_by_id (GtdTaskList *self,
  * @task: a #GtdTask
  * @new_position: the new position of @task inside @self
  *
- * Moves @task and all its subtasks to @new_position, and repositions
- * the elements in between as well.
+ * Moves @task to @new_position, and repositions the elements
+ * in between as well.
  *
  * @task must belog to @self.
  */
@@ -953,14 +899,14 @@ gtd_task_list_move_task_to_position (GtdTaskList *self,
                                      GtdTask     *task,
                                      guint        new_position)
 {
+
   GtdTaskListPrivate *priv = gtd_task_list_get_instance_private (self);
+  g_autoptr (GtdTask) task_at_position = NULL;
   GSequenceIter *block_start_iter;
   GSequenceIter *block_end_iter;
   GSequenceIter *new_position_iter;
   gboolean moving_up;
-  guint64 n_subtasks;
   guint block1_start;
-  guint block1_length;
   guint block1_new_start;
   guint block2_start;
   guint block2_length;
@@ -970,7 +916,7 @@ gtd_task_list_move_task_to_position (GtdTaskList *self,
   /*
    * The algorithm divides it in 2 blocks:
    *
-   *  * Block 1: [ @task position → @task position + n_subtasks ]
+   *  * Block 1: @task position
    *  * Block 2: the tasks between Block 1 and @new_position
    *
    * And there are 2 cases we need to deal with:
@@ -986,11 +932,9 @@ gtd_task_list_move_task_to_position (GtdTaskList *self,
   g_return_if_fail (gtd_task_list_contains (self, task));
   g_return_if_fail (g_list_model_get_n_items (G_LIST_MODEL (self)) >= new_position);
 
-  n_subtasks = gtd_task_get_n_total_subtasks (task);
   block1_start = gtd_task_get_position (task);
-  block1_length = n_subtasks + 1;
 
-  g_return_if_fail (new_position < block1_start || new_position >= block1_start + block1_length);
+  g_return_if_fail (new_position < block1_start || new_position >= block1_start + 1);
 
   moving_up = block1_start > new_position;
 
@@ -1003,23 +947,22 @@ gtd_task_list_move_task_to_position (GtdTaskList *self,
       block2_length = block1_start - new_position;
 
       block1_new_start = new_position;
-      block2_new_start = new_position + block1_length;
+      block2_new_start = new_position + 1;
     }
   else
     {
       /*
        * Case 2: Moving down
        */
-      block2_start = block1_start + block1_length;
+      block2_start = block1_start + 1;
       block2_length = new_position - block2_start;
 
-      block1_new_start = new_position - n_subtasks - 1;
-      block2_new_start = block2_start - block1_length;
+      block1_new_start = new_position - 1;
+      block2_new_start = block2_start - 1;
     }
 
-  GTD_TRACE_MSG ("Moving task and subtasks [%u, %u] to %u, and adjusting [%u, %u] to %u",
+  GTD_TRACE_MSG ("Moving task %u to %u, and adjusting [%u, %u] to %u",
                  block1_start,
-                 block1_start + block1_length - 1,
                  block1_new_start,
                  block2_start,
                  block2_start + block2_length - 1,
@@ -1028,22 +971,17 @@ gtd_task_list_move_task_to_position (GtdTaskList *self,
   priv->freeze_counter++;
 
   /* Update Block 1 */
-  for (i = 0; i < block1_length; i++)
-    {
-      g_autoptr (GtdTask) task_at_i = NULL;
+  task_at_position = g_list_model_get_item (G_LIST_MODEL (self), block1_start);
 
-      task_at_i = g_list_model_get_item (G_LIST_MODEL (self), block1_start + i);
-
-      g_signal_handlers_block_by_func (task_at_i, task_changed_cb, self);
-      gtd_task_set_position (task_at_i, block1_new_start + i);
-      g_signal_handlers_unblock_by_func (task_at_i, task_changed_cb, self);
+  g_signal_handlers_block_by_func (task_at_position, task_changed_cb, self);
+  gtd_task_set_position (task_at_position, block1_new_start);
+  g_signal_handlers_unblock_by_func (task_at_position, task_changed_cb, self);
 
-      gtd_provider_update_task (priv->provider,
-                                task_at_i,
-                                NULL,
-                                on_task_updated_cb,
-                                self);
-    }
+  gtd_provider_update_task (priv->provider,
+                            task_at_position,
+                            NULL,
+                            on_task_updated_cb,
+                            self);
 
   /* Update Block 2 */
   for (i = 0; i < block2_length; i++)
@@ -1063,36 +1001,15 @@ gtd_task_list_move_task_to_position (GtdTaskList *self,
                                 self);
     }
 
-  /*
-   * Update the GSequence and emit the signal using the smallest block, to
-   * avoid recreating as many widgets as possible.
-   */
-  if (block1_length < block2_length)
-    {
-      block_start_iter = g_sequence_get_iter_at_pos (priv->sorted_tasks, block1_start);
-      block_end_iter = g_sequence_get_iter_at_pos (priv->sorted_tasks, block1_start + block1_length);
-      new_position_iter = g_sequence_get_iter_at_pos (priv->sorted_tasks, new_position);
+  /* Update the GSequence */
+  block_start_iter = g_sequence_get_iter_at_pos (priv->sorted_tasks, block1_start);
+  block_end_iter = g_sequence_get_iter_at_pos (priv->sorted_tasks, block1_start + 1);
+  new_position_iter = g_sequence_get_iter_at_pos (priv->sorted_tasks, new_position);
 
-      g_sequence_move_range (new_position_iter, block_start_iter, block_end_iter);
+  g_sequence_move_range (new_position_iter, block_start_iter, block_end_iter);
 
-      g_list_model_items_changed (G_LIST_MODEL (self), block1_start, block1_length, 0);
-      g_list_model_items_changed (G_LIST_MODEL (self), block1_new_start, 0, block1_length);
-    }
-  else
-    {
-      block_start_iter = g_sequence_get_iter_at_pos (priv->sorted_tasks, block2_start);
-      block_end_iter = g_sequence_get_iter_at_pos (priv->sorted_tasks, block2_start + block2_length);
-
-      if (moving_up)
-        new_position_iter = g_sequence_get_iter_at_pos (priv->sorted_tasks, block1_start + block1_length);
-      else
-        new_position_iter = g_sequence_get_iter_at_pos (priv->sorted_tasks, block1_start);
-
-      g_sequence_move_range (new_position_iter, block_start_iter, block_end_iter);
-
-      g_list_model_items_changed (G_LIST_MODEL (self), block2_start, block2_length, 0);
-      g_list_model_items_changed (G_LIST_MODEL (self), block2_new_start, 0, block2_length);
-    }
+  g_list_model_items_changed (G_LIST_MODEL (self), block1_start, 1, 0);
+  g_list_model_items_changed (G_LIST_MODEL (self), block1_new_start, 0, 1);
 
   priv->freeze_counter--;
 }
diff --git a/src/core/gtd-task.c b/src/core/gtd-task.c
index 03a14679..6430060a 100644
--- a/src/core/gtd-task.c
+++ b/src/core/gtd-task.c
@@ -46,16 +46,6 @@ typedef struct
 
   gchar           *title;
 
-  GtdTask         *previous_sibling;
-  GtdTask         *next_sibling;
-
-  GtdTask         *parent_task;
-  GtdTask         *first_subtask;
-  GtdTask         *last_subtask;
-  guint64          n_direct_subtasks;
-  guint64          n_total_subtasks;
-  gint             depth;
-
   gint32           priority;
   gint64           position;
   gboolean         complete;
@@ -68,321 +58,16 @@ enum
 {
   PROP_0,
   PROP_COMPLETE,
-  PROP_DEPTH,
   PROP_DESCRIPTION,
   PROP_CREATION_DATE,
   PROP_DUE_DATE,
   PROP_IMPORTANT,
   PROP_LIST,
-  PROP_PARENT,
   PROP_POSITION,
   PROP_TITLE,
   LAST_PROP
 };
 
-enum
-{
-  SUBTASK_ADDED,
-  SUBTASK_REMOVED,
-  N_SIGNALS
-};
-
-static guint signals[N_SIGNALS] = { 0, };
-
-static gboolean
-share_same_ancestor (GtdTask *t1,
-                     GtdTask *t2)
-{
-  GtdTask *p1, *p2;
-  gint depth_difference;
-
-  depth_difference = ABS (gtd_task_get_depth (t1) - gtd_task_get_depth (t2));
-
-  /* Put the tasks at the same depth */
-  if (depth_difference != 0)
-    {
-      gint i;
-
-      for (i = 0; i < depth_difference; i++)
-        {
-          if (gtd_task_get_depth (t1) > gtd_task_get_depth (t2))
-            t1 = gtd_task_get_parent (t1);
-          else
-            t2 = gtd_task_get_parent (t2);
-        }
-    }
-
-  p1 = t1;
-  p2 = t2;
-
-  /* Walk up in the tree, if they match, we found the ancestor */
-  while (p1 && p2)
-    {
-      if (p1 == p2)
-        return TRUE;
-
-      p1 = gtd_task_get_parent (p1);
-      p2 = gtd_task_get_parent (p2);
-    }
-
-  return FALSE;
-}
-
-static GtdTask*
-get_root_task (GtdTask *self)
-{
-  GtdTaskPrivate *priv = gtd_task_get_instance_private (self);
-  GtdTask *aux = self;
-
-  while (priv->parent_task)
-    {
-      aux = priv->parent_task;
-      priv = gtd_task_get_instance_private (aux);
-    }
-
-  return aux;
-}
-
-static void
-append_subtask (GtdTask *self,
-                GtdTask *subtask)
-{
-  GtdTaskPrivate *priv, *subtask_priv;
-
-  priv = gtd_task_get_instance_private (self);
-  subtask_priv = gtd_task_get_instance_private (subtask);
-
-  subtask_priv->previous_sibling = priv->last_subtask;
-
-  if (priv->last_subtask)
-    {
-      GtdTaskPrivate *last_subtask_priv = gtd_task_get_instance_private (priv->last_subtask);
-      last_subtask_priv->next_sibling = subtask;
-    }
-
-  priv->last_subtask = subtask;
-
-  if (!priv->first_subtask)
-    priv->first_subtask = subtask;
-}
-
-static void
-remove_subtask (GtdTask *self,
-                GtdTask *subtask)
-{
-  GtdTaskPrivate *priv, *subtask_priv;
-
-  priv = gtd_task_get_instance_private (self);
-  subtask_priv = gtd_task_get_instance_private (subtask);
-
-  if (subtask_priv->previous_sibling)
-    {
-      GtdTaskPrivate *previous_subtask_sibling_priv = gtd_task_get_instance_private 
(subtask_priv->previous_sibling);
-      previous_subtask_sibling_priv->next_sibling = subtask_priv->next_sibling;
-    }
-  else
-    {
-      /*
-       * This is the first subtask, so advance the parent's first subtask
-       * to the next one (which might be NULL).
-       */
-      priv->first_subtask = subtask_priv->next_sibling;
-    }
-
-  if (subtask_priv->next_sibling)
-    {
-      GtdTaskPrivate *next_subtask_sibling_priv = gtd_task_get_instance_private (subtask_priv->next_sibling);
-      next_subtask_sibling_priv->previous_sibling = subtask_priv->previous_sibling;
-    }
-  else
-    {
-      /*
-       * This is the last subtask, so rewind the parent's last subtask to
-       * the previous one (which might be NULL).
-       */
-      priv->last_subtask = subtask_priv->previous_sibling;
-    }
-}
-
-static gint
-compare_by_subtasks (GtdTask **t1,
-                     GtdTask **t2)
-{
-  GtdTask *task1, *task2;
-
-  task1 = *t1;
-  task2 = *t2;
-
-  if (!task1 && !task2)
-    return  0;
-  if (!task1)
-    return  1;
-  if (!task2)
-    return -1;
-
-  if (share_same_ancestor (task1, task2))
-    {
-      gint depth_difference;
-
-      depth_difference = ABS (gtd_task_get_depth (task1) - gtd_task_get_depth (task2));
-
-      if (gtd_task_is_subtask (task1, task2))
-        {
-          return -1;
-        }
-      else if (gtd_task_is_subtask (task2, task1))
-        {
-          return 1;
-        }
-      else
-        {
-          GtdTask *p1, *p2;
-          gint i;
-
-          for (i = depth_difference; i > 0; i--)
-            {
-              if (gtd_task_get_depth (task1) > gtd_task_get_depth (task2))
-                task1 = gtd_task_get_parent (task1);
-              else
-                task2 = gtd_task_get_parent (task2);
-            }
-
-          p1 = task1;
-          p2 = task2;
-
-          /* Walk up in the tree, if they match, we found the ancestor */
-          while (gtd_task_get_parent (p1) && gtd_task_get_parent (p2))
-            {
-              if (gtd_task_get_parent (p1) == gtd_task_get_parent (p2))
-                break;
-
-              p1 = gtd_task_get_parent (p1);
-              p2 = gtd_task_get_parent (p2);
-            }
-
-          *t1 = p1;
-          *t2 = p2;
-        }
-    }
-  else
-    {
-      /*
-       * If either t1 or t2 have a parent, we have to compare them
-       * solely based on the root task of the subtask tree.
-       */
-      *t1 = get_root_task (task1);
-      *t2 = get_root_task (task2);
-    }
-
-  return 0;
-}
-
-static void
-set_depth (GtdTask *self,
-           gint     depth)
-{
-  GtdTaskPrivate *priv = gtd_task_get_instance_private (self);
-  GtdTask *aux;
-
-  priv->depth = depth;
-  g_object_notify (G_OBJECT (self), "depth");
-
-  aux = priv->first_subtask;
-  while (aux)
-    {
-      GtdTaskPrivate *aux_priv = gtd_task_get_instance_private (aux);
-
-      set_depth (aux, depth + 1);
-      aux = aux_priv->next_sibling;
-    }
-}
-
-static void
-update_total_subtasks_counters (GtdTask *self,
-                                gint64   total_difference)
-{
-  GtdTask *aux;
-
-  aux = self;
-  while (aux)
-    {
-      GtdTaskPrivate *aux_priv = gtd_task_get_instance_private (aux);
-
-      aux_priv->n_total_subtasks += total_difference;
-
-      aux = aux_priv->parent_task;
-    }
-}
-
-static void
-real_add_subtask (GtdTask *self,
-                  GtdTask *subtask)
-{
-  GtdTaskPrivate *priv, *subtask_priv;
-
-  GTD_ENTRY;
-
-  g_assert (!gtd_task_is_subtask (self, subtask));
-
-  priv = gtd_task_get_instance_private (self);
-  subtask_priv = gtd_task_get_instance_private (subtask);
-
-  /* First, remove the subtask from it's parent's subtasks list */
-  if (subtask_priv->parent_task)
-    gtd_task_remove_subtask (subtask_priv->parent_task, subtask);
-
-  /* Append to this task's list of subtasks */
-  append_subtask (self, subtask);
-
-  /* Update counters */
-  priv->n_direct_subtasks += 1;
-  update_total_subtasks_counters (self, subtask_priv->n_total_subtasks + 1);
-
-  GTD_TRACE_MSG ("Task %p is now subtask of %p", subtask, self);
-
-  /* Update the subtask's parent property */
-  subtask_priv->next_sibling = NULL;
-  subtask_priv->parent_task = self;
-
-  g_object_notify (G_OBJECT (subtask), "parent");
-
-  /* And also the task's depth */
-  set_depth (subtask, priv->depth + 1);
-
-  GTD_EXIT;
-}
-
-static void
-real_remove_subtask (GtdTask *self,
-                     GtdTask *subtask)
-{
-  GtdTaskPrivate *priv, *subtask_priv;
-
-  g_assert (gtd_task_is_subtask (self, subtask));
-
-  priv = gtd_task_get_instance_private (self);
-  subtask_priv = gtd_task_get_instance_private (subtask);
-
-  /* Detach subtask from the linked list of subtasks */
-  remove_subtask (self, subtask);
-
-  /* Update counters */
-  priv->n_direct_subtasks -= 1;
-  update_total_subtasks_counters (self, -subtask_priv->n_total_subtasks - 1);
-
-  GTD_TRACE_MSG ("Task %p was detached from %p", subtask, self);
-
-  /* Update the subtask's parent and siblings */
-  subtask_priv->previous_sibling = NULL;
-  subtask_priv->next_sibling = NULL;
-  subtask_priv->parent_task = NULL;
-
-  g_object_notify (G_OBJECT (subtask), "parent");
-
-  /* And also the task's depth */
-  set_depth (subtask, 0);
-}
-
 static void
 task_list_weak_notified (gpointer  data,
                          GObject  *where_the_object_was)
@@ -586,10 +271,6 @@ gtd_task_get_property (GObject    *object,
       g_value_set_boxed (value, gtd_task_get_creation_date (self));
       break;
 
-    case PROP_DEPTH:
-      g_value_set_uint (value, priv->depth);
-      break;
-
     case PROP_DESCRIPTION:
       g_value_set_string (value, gtd_task_get_description (self));
       break;
@@ -608,10 +289,6 @@ gtd_task_get_property (GObject    *object,
       g_value_set_object (value, priv->list);
       break;
 
-    case PROP_PARENT:
-      g_value_set_object (value, priv->parent_task);
-      break;
-
     case PROP_POSITION:
       g_value_set_int64 (value, gtd_task_get_position (self));
       break;
@@ -693,8 +370,6 @@ gtd_task_class_init (GtdTaskClass *klass)
   klass->set_position = gtd_task_real_set_position;
   klass->get_title = gtd_task_real_get_title;
   klass->set_title = gtd_task_real_set_title;
-  klass->subtask_added = real_add_subtask;
-  klass->subtask_removed = real_remove_subtask;
 
   object_class->finalize = gtd_task_finalize;
   object_class->get_property = gtd_task_get_property;
@@ -729,22 +404,6 @@ gtd_task_class_init (GtdTaskClass *klass)
                             G_TYPE_DATE_TIME,
                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
-  /**
-   * GtdTask::depth:
-   *
-   * The depth of the task inside the subtask tree.
-   */
-  g_object_class_install_property (
-        object_class,
-        PROP_DEPTH,
-        g_param_spec_uint ("depth",
-                           "Depth of the task",
-                           "The depth of the task inside the subtasks tree.",
-                           0,
-                           G_MAXUINT,
-                           0,
-                           G_PARAM_READABLE));
-
   /**
    * GtdTask::description:
    *
@@ -802,20 +461,6 @@ gtd_task_class_init (GtdTaskClass *klass)
                              GTD_TYPE_TASK_LIST,
                              G_PARAM_READWRITE));
 
-  /**
-   * GtdTask::parent:
-   *
-   * The parent of the task.
-   */
-  g_object_class_install_property (
-        object_class,
-        PROP_PARENT,
-        g_param_spec_object ("parent",
-                              "Parent of the task",
-                              "The GtdTask that is parent of this task.",
-                              GTD_TYPE_TASK,
-                              G_PARAM_READABLE));
-
   /**
    * GtdTask::position:
    *
@@ -845,39 +490,6 @@ gtd_task_class_init (GtdTaskClass *klass)
                              "The title of the task",
                              NULL,
                              G_PARAM_READWRITE));
-
-  /* Signals */
-  /**
-   * GtdTask:subtask-added:
-   *
-   * Emited when a subtask is added to @self.
-   */
-  signals[SUBTASK_ADDED] = g_signal_new ("subtask-added",
-                                         GTD_TYPE_TASK,
-                                         G_SIGNAL_RUN_LAST,
-                                         G_STRUCT_OFFSET (GtdTaskClass, subtask_added),
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         G_TYPE_NONE,
-                                         1,
-                                         GTD_TYPE_TASK);
-
-  /**
-   * GtdTask:subtask-removed:
-   *
-   * Emited when a subtask is removed from @self.
-   */
-  signals[SUBTASK_REMOVED] = g_signal_new ("subtask-removed",
-                                           GTD_TYPE_TASK,
-                                           G_SIGNAL_RUN_LAST,
-                                           G_STRUCT_OFFSET (GtdTaskClass, subtask_removed),
-                                           NULL,
-                                           NULL,
-                                           NULL,
-                                           G_TYPE_NONE,
-                                           1,
-                                           GTD_TYPE_TASK);
 }
 
 static void
@@ -1294,12 +906,6 @@ gtd_task_compare (GtdTask *t1,
         return retval;
     }
 
-  /* Compare by subtask hierarchy */
-  retval = compare_by_subtasks (&t1, &t2);
-
-  if (retval != 0)
-    return retval;
-
   /* Compare by due date */
   dt1 = gtd_task_get_due_date (t1);
   dt2 = gtd_task_get_due_date (t2);
@@ -1354,256 +960,6 @@ gtd_task_compare (GtdTask *t1,
   return retval;
 }
 
-/**
- * gtd_task_get_parent:
- * @self: a #GtdTask
- *
- * Retrieves the parent task of @self, or %NULL if none is set.
- *
- * Returns: (transfer none)(nullable): the #GtdTask that is parent of @self
- */
-GtdTask*
-gtd_task_get_parent (GtdTask *self)
-{
-  GtdTaskPrivate *priv;
-
-  g_return_val_if_fail (GTD_IS_TASK (self), NULL);
-
-  priv = gtd_task_get_instance_private (self);
-
-  return priv->parent_task;
-}
-
-/**
- * gtd_task_add_subtask:
- * @self: a #GtdTask
- * @subtask: the subtask to be added to @self
- *
- * Adds @subtask as a subtask of @self.
- */
-void
-gtd_task_add_subtask (GtdTask *self,
-                      GtdTask *subtask)
-{
-  g_return_if_fail (GTD_IS_TASK (self));
-  g_return_if_fail (GTD_IS_TASK (subtask));
-  g_return_if_fail (!gtd_task_is_subtask (self, subtask));
-
-  g_signal_emit (self, signals[SUBTASK_ADDED], 0, subtask);
-}
-
-/**
- * gtd_task_remove_subtask:
- * @self: a #GtdTask
- * @subtask: the subtask to be removed to @self
- *
- * Removes @subtask from @self.
- */
-void
-gtd_task_remove_subtask (GtdTask *self,
-                         GtdTask *subtask)
-{
-  g_return_if_fail (GTD_IS_TASK (self));
-  g_return_if_fail (GTD_IS_TASK (subtask));
-  g_return_if_fail (gtd_task_is_subtask (self, subtask));
-
-  g_signal_emit (self, signals[SUBTASK_REMOVED], 0, subtask);
-}
-
-/**
- * gtd_task_is_subtask:
- * @self: a #GtdTask
- * @subtask: a #GtdTask
- *
- * Checks if @subtask is a subtask of @self, directly or indirectly.
- *
- * Returns: %TRUE is @subtask is a subtask of @self, %FALSE otherwise
- */
-gboolean
-gtd_task_is_subtask (GtdTask *self,
-                     GtdTask *subtask)
-{
-  GtdTask *aux;
-
-  g_return_val_if_fail (GTD_IS_TASK (self), FALSE);
-  g_return_val_if_fail (GTD_IS_TASK (subtask), FALSE);
-
-  aux = subtask;
-  while (aux)
-    {
-      GtdTaskPrivate *aux_priv = gtd_task_get_instance_private (aux);
-
-      if (aux == self)
-        return TRUE;
-
-      aux = aux_priv->parent_task;
-    }
-
-  return FALSE;
-}
-
-/**
- * gtd_task_get_depth:
- * @self: a #GtdTask
- *
- * Retrieves the depth of @self in the subtasks tree.
- *
- * Returns: the depth of the task.
- */
-gint
-gtd_task_get_depth (GtdTask *self)
-{
-  GtdTaskPrivate *priv;
-
-  g_return_val_if_fail (GTD_IS_TASK (self), 0);
-
-  priv = gtd_task_get_instance_private (self);
-
-  return priv->depth;
-}
-
-/**
- * gtd_task_get_first_subtask:
- * @self: a #GtdTaskList
- *
- * Return the first subtask of @self. This is useful for
- * copy-less iteration, for example:
- *
- * |[<!-- language="C" -->
- * for (aux = gtd_task_get_first_subtask (task);
- *      aux;
- *      aux = gtd_task_get_next_sibling (aux))
- *   {
- *     // Do something with aux
- *   }
- * ]|
- *
- * The siblings have no particular order. See also
- * gtd_task_get_previous_sibling() and gtd_task_get_next_sibling().
- *
- * Returns: (nullable): the first subtask of @self
- */
-GtdTask*
-gtd_task_get_first_subtask (GtdTask *self)
-{
-  GtdTaskPrivate *priv;
-
-  g_return_val_if_fail (GTD_IS_TASK (self), 0);
-
-  priv = gtd_task_get_instance_private (self);
-
-  return priv->first_subtask;
-}
-
-/**
- * gtd_task_get_previous_sibling:
- * @self: a #GtdTaskList
- *
- * Retrieves the previous sibling of @self. This is useful for
- * copy-less iteration.
- *
- * Only subtasks have a previous and a next sibling set. Root
- * tasks depend do not have them, and it is a programming error
- * to assume so.
- *
- * The siblings have no particular order. It is a programming
- * error to assume that siblings are sorted.
- *
- * Returns: (nullable): the previous sibling of @self
- */
-GtdTask*
-gtd_task_get_previous_sibling (GtdTask *self)
-{
-  GtdTaskPrivate *priv;
-
-  g_return_val_if_fail (GTD_IS_TASK (self), 0);
-
-  priv = gtd_task_get_instance_private (self);
-
-  return priv->previous_sibling;
-}
-
-/**
- * gtd_task_get_next_sibling:
- * @self: a #GtdTaskList
- *
- * Retrieves the next sibling of @self. This is useful for
- * copy-less iteration, for example:
- *
- * |[<!-- language="C" -->
- * for (aux = gtd_task_get_first_subtask (task);
- *      aux;
- *      aux = gtd_task_get_next_sibling (aux))
- *   {
- *     // Do something with aux
- *   }
- * ]|
- *
- * Only subtasks have a previous and a next sibling set. Root
- * tasks depend do not have them, and it is a programming error
- * to assume so.
- *
- * The siblings have no particular order. It is a programming
- * error to assume that siblings are sorted.
- *
- * Returns: (nullable): the next sibling of @self
- */
-GtdTask*
-gtd_task_get_next_sibling (GtdTask *self)
-{
-  GtdTaskPrivate *priv;
-
-  g_return_val_if_fail (GTD_IS_TASK (self), 0);
-
-  priv = gtd_task_get_instance_private (self);
-
-  return priv->next_sibling;
-}
-
-/**
- * gtd_task_get_n_direct_subtasks:
- * @self: a #GtdTaskList
- *
- * Returns the number of only direct subtasks of this
- * task. This number is updated when adding and removing
- * subtasks, and cached.
- *
- * Returns: the number of direct subtasks of @self
- */
-guint64
-gtd_task_get_n_direct_subtasks (GtdTask *self)
-{
-  GtdTaskPrivate *priv;
-
-  g_return_val_if_fail (GTD_IS_TASK (self), 0);
-
-  priv = gtd_task_get_instance_private (self);
-
-  return priv->n_direct_subtasks;
-}
-
-/**
- * gtd_task_get_n_total_subtasks:
- * @self: a #GtdTaskList
- *
- * Returns the number of direct and indirect subtasks of
- * this task. This number is updated when adding and removing
- * subtasks, and cached.
- *
- * Returns: the number of direct and indirect subtasks of @self
- */
-guint64
-gtd_task_get_n_total_subtasks (GtdTask *self)
-{
-  GtdTaskPrivate *priv;
-
-  g_return_val_if_fail (GTD_IS_TASK (self), 0);
-
-  priv = gtd_task_get_instance_private (self);
-
-  return priv->n_total_subtasks;
-}
-
 /**
  * gtd_task_get_provider:
  * @self: a #GtdTaskList
diff --git a/src/core/gtd-task.h b/src/core/gtd-task.h
index 2390e26b..170f4a2e 100644
--- a/src/core/gtd-task.h
+++ b/src/core/gtd-task.h
@@ -65,15 +65,7 @@ struct _GtdTaskClass
   void          (*set_title)                          (GtdTask              *self,
                                                        const gchar          *title);
 
-  /*< signals >*/
-
-  void          (*subtask_added)                      (GtdTask              *self,
-                                                       GtdTask              *subtask);
-
-  void          (*subtask_removed)                    (GtdTask              *self,
-                                                       GtdTask              *subtask);
-
-  gpointer       padding[6];
+  gpointer       padding[8];
 };
 
 GtdTask*            gtd_task_new                      (void);
@@ -123,29 +115,6 @@ void                gtd_task_set_title                (GtdTask              *tas
 gint                gtd_task_compare                  (GtdTask              *t1,
                                                        GtdTask              *t2);
 
-GtdTask*            gtd_task_get_parent               (GtdTask              *self);
-
-void                gtd_task_add_subtask              (GtdTask              *self,
-                                                       GtdTask              *subtask);
-
-void                gtd_task_remove_subtask           (GtdTask              *self,
-                                                       GtdTask              *subtask);
-
-gboolean            gtd_task_is_subtask               (GtdTask              *self,
-                                                       GtdTask              *subtask);
-
-gint                gtd_task_get_depth                (GtdTask              *self);
-
-GtdTask*            gtd_task_get_first_subtask        (GtdTask              *self);
-
-GtdTask*            gtd_task_get_previous_sibling     (GtdTask              *self);
-
-GtdTask*            gtd_task_get_next_sibling         (GtdTask              *self);
-
-guint64             gtd_task_get_n_direct_subtasks    (GtdTask              *self);
-
-guint64             gtd_task_get_n_total_subtasks     (GtdTask              *self);
-
 GtdProvider*        gtd_task_get_provider             (GtdTask              *self);
 
 G_END_DECLS
diff --git a/src/gui/gtd-task-row.c b/src/gui/gtd-task-row.c
index 116a8dad..0301ccee 100644
--- a/src/gui/gtd-task-row.c
+++ b/src/gui/gtd-task-row.c
@@ -357,19 +357,6 @@ on_complete_changed_cb (GtdTaskRow *self,
   g_signal_handlers_unblock_by_func (self->done_check, on_complete_check_toggled_cb, self);
 }
 
-static void
-on_depth_changed_cb (GtdTaskRow *self,
-                     GParamSpec *pspec,
-                     GtdTask    *task)
-{
-  gint margin = 0;
-
-  if (self->handle_subtasks)
-    margin = 32 * gtd_task_get_depth (task);
-
-  gtk_widget_set_margin_start (self->content_box, margin);
-}
-
 static void
 on_task_important_changed_cb (GtdTask    *task,
                               GParamSpec *pspec,
@@ -466,10 +453,7 @@ gtd_task_row_dispose (GObject *object)
   g_clear_pointer (&self->bindings, g_ptr_array_unref);
 
   if (task)
-    {
-      g_signal_handlers_disconnect_by_func (task, on_depth_changed_cb, self);
-      g_signal_handlers_disconnect_by_func (task, on_complete_changed_cb, self);
-    }
+    g_signal_handlers_disconnect_by_func (task, on_complete_changed_cb, self);
 
   G_OBJECT_CLASS (gtd_task_row_parent_class)->dispose (object);
 }
@@ -700,7 +684,6 @@ gtd_task_row_set_task (GtdTaskRow *self,
   if (old_task)
     {
       g_signal_handlers_disconnect_by_func (old_task, on_complete_changed_cb, self);
-      g_signal_handlers_disconnect_by_func (old_task, on_depth_changed_cb, self);
       g_signal_handlers_disconnect_by_func (old_task, on_task_important_changed_cb, self);
       g_signal_handlers_disconnect_by_func (old_task, on_star_widget_activated_cb, self);
       g_ptr_array_set_size (self->bindings, 0);
@@ -750,13 +733,6 @@ gtd_task_row_set_task (GtdTaskRow *self,
                                self,
                                G_CONNECT_SWAPPED);
 
-      on_depth_changed_cb (self, NULL, task);
-      g_signal_connect_object (task,
-                               "notify::depth",
-                               G_CALLBACK (on_depth_changed_cb),
-                               self,
-                               G_CONNECT_SWAPPED);
-
       on_task_important_changed_cb (task, NULL, self);
       g_signal_connect_object (task,
                                "notify::important",
@@ -845,7 +821,6 @@ gtd_task_row_set_handle_subtasks (GtdTaskRow *self,
 
   gtk_widget_set_visible (self->dnd_box, handle_subtasks);
   gtk_widget_set_visible (self->dnd_icon, handle_subtasks);
-  on_depth_changed_cb (self, NULL, self->task);
 
   g_object_notify (G_OBJECT (self), "handle-subtasks");
 }
diff --git a/src/plugins/eds/gtd-task-eds.c b/src/plugins/eds/gtd-task-eds.c
index 2fb3a5c9..e48e89ab 100644
--- a/src/plugins/eds/gtd-task-eds.c
+++ b/src/plugins/eds/gtd-task-eds.c
@@ -484,60 +484,6 @@ gtd_task_eds_set_title (GtdTask     *task,
   e_cal_component_text_free (new_summary);
 }
 
-static void
-gtd_task_eds_subtask_added (GtdTask *task,
-                            GtdTask *subtask)
-{
-  const gchar *uid;
-  ECalComponent *comp;
-  ICalComponent *ical_comp;
-  ICalProperty *property;
-  GtdTaskEds *subtask_self;
-  GtdTaskEds *self;
-
-  self = GTD_TASK_EDS (task);
-  subtask_self = GTD_TASK_EDS (subtask);
-
-  /* Hook with parent's :subtask_added */
-  GTD_TASK_CLASS (gtd_task_eds_parent_class)->subtask_added (task, subtask);
-
-  uid = e_cal_component_get_uid (self->new_component);
-  comp = subtask_self->new_component;
-  ical_comp = e_cal_component_get_icalcomponent (comp);
-  property = i_cal_component_get_first_property (ical_comp, I_CAL_RELATEDTO_PROPERTY);
-
-  if (property)
-    i_cal_property_set_relatedto (property, uid);
-  else
-    i_cal_component_take_property (ical_comp, i_cal_property_new_relatedto (uid));
-
-  g_clear_object (&property);
-}
-
-static void
-gtd_task_eds_subtask_removed (GtdTask *task,
-                              GtdTask *subtask)
-{
-  ICalComponent *ical_comp;
-  ICalProperty *property;
-  GtdTaskEds *subtask_self;
-
-  subtask_self = GTD_TASK_EDS (subtask);
-
-  /* Hook with parent's :subtask_removed */
-  GTD_TASK_CLASS (gtd_task_eds_parent_class)->subtask_removed (task, subtask);
-
-  /* Remove the parent link from the subtask's component */
-  ical_comp = e_cal_component_get_icalcomponent (subtask_self->new_component);
-  property = i_cal_component_get_first_property (ical_comp, I_CAL_RELATEDTO_PROPERTY);
-
-  if (!property)
-    return;
-
-  i_cal_component_remove_property (ical_comp, property);
-  g_object_unref (property);
-}
-
 
 /*
  * GObject overrides
@@ -619,8 +565,6 @@ gtd_task_eds_class_init (GtdTaskEdsClass *klass)
   task_class->set_position = gtd_task_eds_set_position;
   task_class->get_title = gtd_task_eds_get_title;
   task_class->set_title = gtd_task_eds_set_title;
-  task_class->subtask_added = gtd_task_eds_subtask_added;
-  task_class->subtask_removed = gtd_task_eds_subtask_removed;
 
   gtd_object_class->get_uid = gtd_task_eds_get_uid;
   gtd_object_class->set_uid = gtd_task_eds_set_uid;
diff --git a/src/plugins/eds/gtd-task-list-eds.c b/src/plugins/eds/gtd-task-list-eds.c
index 619676d4..fcde62bd 100644
--- a/src/plugins/eds/gtd-task-list-eds.c
+++ b/src/plugins/eds/gtd-task-list-eds.c
@@ -35,8 +35,6 @@ struct _GtdTaskListEds
   ECalClientView     *client_view;
   ESource            *source;
 
-  GPtrArray           *pending_subtasks;
-
   GCancellable       *cancellable;
 };
 
@@ -47,12 +45,6 @@ typedef struct
   ECalClient         *client;
 } NewTaskListData;
 
-typedef struct
-{
-  GtdTask            *child;
-  gchar              *parent_uid;
-} PendingSubtaskData;
-
 static void          on_client_objects_modified_for_migration_cb (GObject            *object,
                                                                   GAsyncResult       *result,
                                                                   gpointer            user_data);
@@ -86,26 +78,6 @@ new_task_list_data_free (gpointer data)
   g_free (list_data);
 }
 
-static PendingSubtaskData*
-pending_subtask_data_new (GtdTask     *child,
-                          const gchar *parent_uid)
-{
-  PendingSubtaskData *data;
-
-  data = g_new0 (PendingSubtaskData, 1);
-  data->child = child;
-  data->parent_uid = g_strdup (parent_uid);
-
-  return data;
-}
-
-static void
-pending_subtask_data_free (PendingSubtaskData *data)
-{
-  g_free (data->parent_uid);
-  g_free (data);
-}
-
 static void
 update_changed_tasks (GtdTaskListEds *self,
                       GHashTable     *changed_tasks)
@@ -252,70 +224,6 @@ maybe_migrate_todo_api_version (GtdTaskListEds *self)
   GTD_EXIT;
 }
 
-static void
-setup_parent_task (GtdTaskListEds *self,
-                   GtdTask        *task)
-{
-  ECalComponent *component;
-  ICalComponent *ical_comp;
-  ICalProperty *property;
-  GtdTask *parent_task;
-  const gchar *parent_uid;
-
-  component = gtd_task_eds_get_component (GTD_TASK_EDS (task));
-  ical_comp = e_cal_component_get_icalcomponent (component);
-  property = i_cal_component_get_first_property (ical_comp, I_CAL_RELATEDTO_PROPERTY);
-
-  if (!property)
-    return;
-
-  parent_uid = i_cal_property_get_relatedto (property);
-  parent_task = gtd_task_list_get_task_by_id (GTD_TASK_LIST (self), parent_uid);
-
-  /* Nothing to do, parent task is already set */
-  if (gtd_task_get_parent (task) == parent_task)
-    return;
-
-  if (parent_task)
-    {
-      gtd_task_add_subtask (parent_task, task);
-    }
-  else
-    {
-      PendingSubtaskData *data;
-
-      data = pending_subtask_data_new (task, parent_uid);
-
-      g_ptr_array_add (self->pending_subtasks, data);
-    }
-
-  g_object_unref (property);
-}
-
-static void
-process_pending_subtasks (GtdTaskListEds *self,
-                          GtdTask        *task)
-{
-  const gchar *uid;
-  guint i;
-
-  uid = gtd_object_get_uid (GTD_OBJECT (task));
-
-  for (i = 0; i < self->pending_subtasks->len; i++)
-    {
-      PendingSubtaskData *data;
-
-      data = g_ptr_array_index (self->pending_subtasks, i);
-
-      if (g_strcmp0 (uid, data->parent_uid) == 0)
-        {
-          gtd_task_add_subtask (task, data->child);
-          g_ptr_array_remove (self->pending_subtasks, data);
-          i--;
-        }
-    }
-}
-
 
 /*
  * Callbacks
@@ -689,16 +597,6 @@ gtd_task_list_eds_set_archived (GtdTaskList *list,
   GTD_EXIT;
 }
 
-static void
-gtd_task_list_eds_task_added (GtdTaskList *list,
-                              GtdTask     *task)
-{
-  GtdTaskListEds *self = GTD_TASK_LIST_EDS (list);
-
-  process_pending_subtasks (self, task);
-  setup_parent_task (self, task);
-}
-
 
 /*
  * GtdObject overrides
@@ -803,7 +701,6 @@ gtd_task_list_eds_class_init (GtdTaskListEdsClass *klass)
 
   task_list_class->get_archived = gtd_task_list_eds_get_archived;
   task_list_class->set_archived = gtd_task_list_eds_set_archived;
-  task_list_class->task_added = gtd_task_list_eds_task_added;
 
   gtd_object_class->get_uid = gtd_task_list_eds_get_uid;
   gtd_object_class->set_uid = gtd_task_list_eds_set_uid;
@@ -843,7 +740,6 @@ gtd_task_list_eds_class_init (GtdTaskListEdsClass *klass)
 static void
 gtd_task_list_eds_init (GtdTaskListEds *self)
 {
-  self->pending_subtasks = g_ptr_array_new_with_free_func ((GDestroyNotify) pending_subtask_data_free);
 }
 
 void


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