[gnome-todo] gtd-task: add support for completion date



commit 3ddd2a842c13b8daf74b213fd7bb9e2e48d8aa69
Author: Rohit Kaushik <kaushikrohit325 gmail com>
Date:   Tue May 29 00:56:45 2018 +0530

    gtd-task: add support for completion date
    
    save completion date when task is marked as
    complete and unset when unmarked as complete.

 src/gtd-task.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/gtd-task.h |  6 ++++++
 2 files changed, 49 insertions(+)
---
diff --git a/src/gtd-task.c b/src/gtd-task.c
index d6a63be..6011656 100644
--- a/src/gtd-task.c
+++ b/src/gtd-task.c
@@ -43,6 +43,7 @@ typedef struct
   gint             depth;
 
   GDateTime       *creation_date;
+  GDateTime       *completion_date;
   GDateTime       *due_date;
 
   gchar           *title;
@@ -286,6 +287,24 @@ task_list_weak_notified (gpointer  data,
  * GtdTask default implementations
  */
 
+static GDateTime*
+gtd_task_real_get_completion_date (GtdTask *self)
+{
+  GtdTaskPrivate *priv = gtd_task_get_instance_private (self);
+
+  return priv->completion_date ? g_date_time_ref (priv->completion_date) : NULL;
+}
+
+static void
+gtd_task_real_set_completion_date (GtdTask   *self,
+                                   GDateTime *dt)
+{
+  GtdTaskPrivate *priv = gtd_task_get_instance_private (self);
+
+  g_clear_pointer (&priv->completion_date, g_date_time_unref);
+  priv->completion_date = dt ? g_date_time_ref (dt) : NULL;
+}
+
 static gboolean
 gtd_task_real_get_complete (GtdTask *self)
 {
@@ -299,6 +318,10 @@ gtd_task_real_set_complete (GtdTask  *self,
                             gboolean  complete)
 {
   GtdTaskPrivate *priv = gtd_task_get_instance_private (self);
+  GDateTime *dt;
+
+  dt = complete ? g_date_time_new_now_local () : NULL;
+  gtd_task_real_set_completion_date (self, dt);
 
   priv->complete = complete;
 }
@@ -546,6 +569,8 @@ gtd_task_class_init (GtdTaskClass *klass)
   klass->set_complete = gtd_task_real_set_complete;
   klass->get_creation_date = gtd_task_real_get_creation_date;
   klass->set_creation_date = gtd_task_real_set_creation_date;
+  klass->get_completion_date = gtd_task_real_get_completion_date;
+  klass->set_completion_date = gtd_task_real_set_completion_date;
   klass->get_description = gtd_task_real_get_description;
   klass->set_description = gtd_task_real_set_description;
   klass->get_due_date = gtd_task_real_get_due_date;
@@ -842,6 +867,24 @@ gtd_task_set_creation_date (GtdTask   *task,
   g_object_notify (G_OBJECT (task), "complete");
 }
 
+/**
+ * gtd_task_get_completion_date:
+ * @task: a #GtdTask
+ *
+ * Returns the #GDateTime that represents the task's completion date.
+ * Returns %NULL if no date is set.
+ *
+ * Returns: (transfer full)(nullable): the internal #GDateTime or %NULL.
+ * Unreference it after use.
+ */
+GDateTime*
+gtd_task_get_completion_date (GtdTask *task)
+{
+  g_return_val_if_fail (GTD_IS_TASK (task), NULL);
+
+  return GTD_TASK_CLASS (G_OBJECT_GET_CLASS (task))->get_completion_date (task);
+}
+
 /**
  * gtd_task_get_description:
  * @task: a #GtdTask
diff --git a/src/gtd-task.h b/src/gtd-task.h
index 79dd497..c8867a9 100644
--- a/src/gtd-task.h
+++ b/src/gtd-task.h
@@ -41,6 +41,10 @@ struct _GtdTaskClass
   void          (*set_creation_date)                  (GtdTask              *self,
                                                        GDateTime            *dt);
 
+  GDateTime*    (*get_completion_date)                (GtdTask              *self);
+  void          (*set_completion_date)                (GtdTask              *self,
+                                                       GDateTime            *dt);
+
   const gchar*  (*get_description)                    (GtdTask              *self);
   void          (*set_description)                    (GtdTask              *self,
                                                        const gchar          *description);
@@ -84,6 +88,8 @@ GDateTime*          gtd_task_get_creation_date        (GtdTask              *tas
 void                gtd_task_set_creation_date        (GtdTask              *task,
                                                        GDateTime            *dt);
 
+GDateTime*          gtd_task_get_completion_date      (GtdTask              *task);
+
 const gchar*        gtd_task_get_description          (GtdTask              *task);
 
 void                gtd_task_set_description          (GtdTask              *task,


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