[gnome-todo] gtd-task: Add creation date property



commit 506b7dc3100afad71f999f78419136881aaa9ceb
Author: Isaque Galdino <igaldino gmail com>
Date:   Thu Feb 18 01:46:51 2016 -0200

    gtd-task: Add creation date property
    
    It was requested to add another sort by creation time.
    
    gtd-task didn't keep record of that information, so it was necessary to
    add a new property to handle that.
    
    EDS prevents creation time field to be updated by the user agent, so it
    was added only a method to recover that information and not to set it.
    
    It was also noticed during some tests that some services like Google
    don't return a sane creation time. That seems to be a problem between
    EDS and Google.
    
    This commit also changes the sorting order:
    - Standard Order: complete > priority > due-date > creation-date > title
    - Scheduled Panel Order: due-date > completed > priority >
                             creation-date > title
    
    https://bugzilla.gnome.org/show_bug.cgi?id=759878

 plugins/eds/gtd-panel-scheduled.c |   48 +++++++++++++++++++++--
 src/gtd-task.c                    |   74 +++++++++++++++++++++++++++++++++++++
 src/gtd-task.h                    |    2 +
 3 files changed, 119 insertions(+), 5 deletions(-)
---
diff --git a/plugins/eds/gtd-panel-scheduled.c b/plugins/eds/gtd-panel-scheduled.c
index 420483e..ffbc7cb 100644
--- a/plugins/eds/gtd-panel-scheduled.c
+++ b/plugins/eds/gtd-panel-scheduled.c
@@ -209,12 +209,16 @@ gtd_panel_scheduled_sort_func (GtkListBoxRow     *row1,
   gchar *t1;
   gchar *t2;
 
-  dt1 = dt2 = NULL;
+  if (!row1_task && !row2_task)
+    return  0;
+  if (!row1_task)
+    return  1;
+  if (!row2_task)
+    return -1;
 
-  if (row1_task)
-    dt1 = gtd_task_get_due_date (row1_task);
-  if (row2_task)
-    dt2 = gtd_task_get_due_date (row2_task);
+  /* First, compare by ::due-date. */
+  dt1 = gtd_task_get_due_date (row1_task);
+  dt2 = gtd_task_get_due_date (row2_task);
 
   if (!dt1 && !dt2)
     retval = 0;
@@ -231,6 +235,40 @@ gtd_panel_scheduled_sort_func (GtkListBoxRow     *row1,
   if (retval != 0)
     return retval;
 
+  /* Second, compare by ::complete. */
+  retval = gtd_task_get_complete (row1_task) -
+           gtd_task_get_complete (row2_task);
+
+  if (retval != 0)
+    return retval;
+
+  /* Third, compare by ::priority. */
+  retval = gtd_task_get_priority (row1_task) -
+           gtd_task_get_priority (row2_task);
+
+  if (retval != 0)
+    return retval;
+
+  /* Fourth, compare by ::creation-date. */
+  dt1 = gtd_task_get_creation_date (row1_task);
+  dt2 = gtd_task_get_creation_date (row2_task);
+
+  if (!dt1 && !dt2)
+    retval =  0;
+  else if (!dt1)
+    retval =  1;
+  else if (!dt2)
+    retval = -1;
+  else
+    retval = g_date_time_compare (dt1, dt2);
+
+  g_clear_pointer (&dt1, g_date_time_unref);
+  g_clear_pointer (&dt2, g_date_time_unref);
+
+  if (retval != 0)
+    return retval;
+
+  /* Finally, compare by ::title. */
   t1 = t2 = NULL;
 
   t1 = g_utf8_casefold (gtd_task_get_title (row1_task), -1);
diff --git a/src/gtd-task.c b/src/gtd-task.c
index 547d9c2..807d40c 100644
--- a/src/gtd-task.c
+++ b/src/gtd-task.c
@@ -39,6 +39,7 @@ enum
   PROP_COMPLETE,
   PROP_COMPONENT,
   PROP_DESCRIPTION,
+  PROP_CREATION_DATE,
   PROP_DUE_DATE,
   PROP_LIST,
   PROP_PRIORITY,
@@ -140,6 +141,10 @@ gtd_task_get_property (GObject    *object,
       g_value_set_object (value, priv->component);
       break;
 
+    case PROP_CREATION_DATE:
+      g_value_set_boxed (value, gtd_task_get_creation_date (self));
+      break;
+
     case PROP_DESCRIPTION:
       g_value_set_string (value, gtd_task_get_description (self));
       break;
@@ -263,6 +268,20 @@ gtd_task_class_init (GtdTaskClass *klass)
                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
   /**
+   * GtdTask::creation-date:
+   *
+   * The @GDateTime that represents the time in which the task was created.
+   */
+  g_object_class_install_property (
+        object_class,
+        PROP_CREATION_DATE,
+        g_param_spec_boxed ("creation-date",
+                            "Creation date of the task",
+                            "The day the task was created.",
+                            G_TYPE_DATE_TIME,
+                            G_PARAM_READABLE));
+
+  /**
    * GtdTask::description:
    *
    * Description of the task.
@@ -482,6 +501,40 @@ gtd_task_set_complete (GtdTask  *task,
 }
 
 /**
+ * gtd_task_get_creation_date:
+ * @task: a #GtdTask
+ *
+ * Returns the #GDateTime that represents the task's creation date.
+ * The value is referenced for thread safety. Returns %NULL if
+ * no date is set.
+ *
+ * Returns: (transfer full): the internal #GDateTime referenced
+ * for thread safety, or %NULL. Unreference it after use.
+ */
+GDateTime*
+gtd_task_get_creation_date (GtdTask *task)
+{
+  GtdTaskPrivate *priv;
+  icaltimetype *idt;
+  GDateTime *dt;
+
+  g_return_val_if_fail (GTD_IS_TASK (task), NULL);
+  priv = gtd_task_get_instance_private (task);
+
+  idt = NULL;
+  dt = NULL;
+
+  e_cal_component_get_created (priv->component, &idt);
+
+  if (idt)
+    dt = gtd_task__convert_icaltime (idt);
+
+  g_clear_pointer (&idt, e_cal_component_free_icaltimetype);
+
+  return dt;
+}
+
+/**
  * gtd_task_get_description:
  * @task: a #GtdTask
  *
@@ -964,6 +1017,27 @@ gtd_task_compare (GtdTask *t1,
     return retval;
 
   /*
+   * Fourth, compare by ::creation-date.
+   */
+  dt1 = gtd_task_get_creation_date (t1);
+  dt2 = gtd_task_get_creation_date (t2);
+
+  if (!dt1 && !dt2)
+    retval =  0;
+  else if (!dt1)
+    retval =  1;
+  else if (!dt2)
+    retval = -1;
+  else
+    retval = g_date_time_compare (dt1, dt2);
+
+  g_clear_pointer (&dt1, g_date_time_unref);
+  g_clear_pointer (&dt2, g_date_time_unref);
+
+  if (retval != 0)
+    return retval;
+
+  /*
    * If they're equal up to now, compare by title.
    */
   txt1 = txt2 = NULL;
diff --git a/src/gtd-task.h b/src/gtd-task.h
index 8dde2c8..eb8b76a 100644
--- a/src/gtd-task.h
+++ b/src/gtd-task.h
@@ -46,6 +46,8 @@ void                gtd_task_set_complete             (GtdTask              *tas
 
 ECalComponent*      gtd_task_get_component            (GtdTask              *task);
 
+GDateTime*          gtd_task_get_creation_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]