[gnome-todo/wip/gbsneto/subtasks] task: add ::has-subtasks property and API



commit 5a6f663f3c6fba617e44ff477a31ea18a4faf9e0
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Oct 21 00:20:51 2016 -0200

    task: add ::has-subtasks property and API

 src/gtd-task.c |   41 +++++++++++++++++++++++++++++++++++++++++
 src/gtd-task.h |    2 ++
 2 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/src/gtd-task.c b/src/gtd-task.c
index e3452ac..7a7f198 100644
--- a/src/gtd-task.c
+++ b/src/gtd-task.c
@@ -58,6 +58,7 @@ enum
   PROP_DESCRIPTION,
   PROP_CREATION_DATE,
   PROP_DUE_DATE,
+  PROP_HAS_SUBTASKS,
   PROP_LIST,
   PROP_PARENT,
   PROP_PRIORITY,
@@ -294,6 +295,7 @@ real_add_subtask (GtdTask *self,
   /* Update the subtask's parent property */
   subtask_priv->parent = self;
   g_object_notify (G_OBJECT (subtask), "parent");
+  g_object_notify (G_OBJECT (subtask), "has-subtasks");
 
   /* And also the task's depth */
   set_depth (subtask, priv->depth + 1);
@@ -333,6 +335,7 @@ real_remove_subtask (GtdTask *self,
   /* Update the subtask's parent property */
   subtask_priv->parent = NULL;
   g_object_notify (G_OBJECT (subtask), "parent");
+  g_object_notify (G_OBJECT (subtask), "has-subtasks");
 
   /* And also the task's depth */
   set_depth (subtask, 0);
@@ -429,6 +432,10 @@ gtd_task_get_property (GObject    *object,
       g_value_set_boxed (value, gtd_task_get_due_date (self));
       break;
 
+    case PROP_HAS_SUBTASKS:
+      g_value_set_boolean (value, priv->subtasks != NULL);
+      break;
+
     case PROP_LIST:
       g_value_set_object (value, priv->list);
       break;
@@ -626,6 +633,20 @@ gtd_task_class_init (GtdTaskClass *klass)
                             G_PARAM_READWRITE));
 
   /**
+   * GtdTask::has-subtask:
+   *
+   * @TRUE if the task has subtasks or @FALSE otherwise.
+   */
+  g_object_class_install_property (
+        object_class,
+        PROP_HAS_SUBTASKS,
+        g_param_spec_boolean ("has-subtasks",
+                              "Whether the task has subtasks",
+                              "Whether the task has subtasks or not",
+                              FALSE,
+                              G_PARAM_READABLE));
+
+  /**
    * GtdTask::list:
    *
    * The @GtdTaskList that contains this task.
@@ -1449,6 +1470,26 @@ gtd_task_get_parent (GtdTask *self)
 }
 
 /**
+ * gtd_task_has_subtasks:
+ * @self: a #GtdTask
+ *
+ * Retrieves whether @self has subtasks or not.
+ *
+ * Returns: %TRUE if @self has subtasks, @FALSE otherwise.
+ */
+gboolean
+gtd_task_has_subtasks (GtdTask *self)
+{
+  GtdTaskPrivate *priv;
+
+  g_return_val_if_fail (GTD_IS_TASK (self), FALSE);
+
+  priv = gtd_task_get_instance_private (self);
+
+  return priv->subtasks != NULL;
+}
+
+/**
  * gtd_task_get_subtasks:
  * @self: a #GtdTask
  *
diff --git a/src/gtd-task.h b/src/gtd-task.h
index 6e2f7b5..fe89bdd 100644
--- a/src/gtd-task.h
+++ b/src/gtd-task.h
@@ -89,6 +89,8 @@ gint                gtd_task_compare                  (GtdTask              *t1,
 
 GtdTask*            gtd_task_get_parent               (GtdTask              *self);
 
+gboolean            gtd_task_has_subtasks             (GtdTask              *self);
+
 GList*              gtd_task_get_subtasks             (GtdTask              *self);
 
 void                gtd_task_add_subtask              (GtdTask              *self,


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