[gnome-todo] task-list-view: add ::default-date property and API



commit 0c48005d076dda35c22d9b931090f049cf1388ae
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Oct 5 20:03:15 2016 -0300

    task-list-view: add ::default-date property and API
    
    The default date is the date tasks are automatically created against.
    This will be used in the future for Today and Scheduled views.

 src/gtd-task-list-view.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++
 src/gtd-task-list-view.h |    5 ++++
 2 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/src/gtd-task-list-view.c b/src/gtd-task-list-view.c
index 13f1a32..590e0b1 100644
--- a/src/gtd-task-list-view.c
+++ b/src/gtd-task-list-view.c
@@ -50,6 +50,7 @@ typedef struct
   gboolean               show_completed;
   GList                 *list;
   GtdTaskList           *task_list;
+  GDateTime             *default_date;
 
   /* color provider */
   GtkCssProvider        *color_provider;
@@ -685,6 +686,9 @@ gtd_task_list_view__create_task (GtdTaskRow *row,
   gtd_task_set_list (task, priv->task_list);
   gtd_task_list_save_task (priv->task_list, task);
 
+  if (priv->default_date)
+    gtd_task_set_due_date (task, priv->default_date);
+
   gtd_manager_create_task (gtd_manager_get_default (), task);
 }
 
@@ -693,7 +697,9 @@ gtd_task_list_view_finalize (GObject *object)
 {
   GtdTaskListViewPrivate *priv = GTD_TASK_LIST_VIEW (object)->priv;
 
+  g_clear_pointer (&priv->default_date, g_date_time_unref);
   g_clear_pointer (&priv->list, g_list_free);
+
   G_OBJECT_CLASS (gtd_task_list_view_parent_class)->finalize (object);
 }
 
@@ -1323,3 +1329,47 @@ gtd_task_list_view_set_sort_func (GtdTaskListView         *view,
                                   NULL);
     }
 }
+
+/**
+ * gtd_task_list_view_get_default_date:
+ * @self: a #GtdTaskListView
+ *
+ * Retrieves the current default date which new tasks are set to.
+ *
+ * Returns: (nullable): a #GDateTime, or %NULL
+ */
+GDateTime*
+gtd_task_list_view_get_default_date (GtdTaskListView *self)
+{
+  GtdTaskListViewPrivate *priv;
+
+  g_return_val_if_fail (GTD_IS_TASK_LIST_VIEW (self), NULL);
+
+  priv = gtd_task_list_view_get_instance_private (self);
+
+  return priv->default_date;
+}
+
+/**
+ * gtd_task_list_view_set_default_date:
+ * @self: a #GtdTaskListView
+ * @default_date: (nullable): the default_date, or %NULL
+ *
+ * Sets the current default date.
+ */
+void
+gtd_task_list_view_set_default_date   (GtdTaskListView *self,
+                                       GDateTime       *default_date)
+{
+  GtdTaskListViewPrivate *priv;
+
+  g_return_if_fail (GTD_IS_TASK_LIST_VIEW (self));
+
+  priv = gtd_task_list_view_get_instance_private (self);
+
+  if (priv->default_date != default_date)
+    {
+      g_clear_pointer (&priv->default_date, g_date_time_unref);
+      priv->default_date = default_date ? g_date_time_ref (default_date) : NULL;
+    }
+}
diff --git a/src/gtd-task-list-view.h b/src/gtd-task-list-view.h
index e8a35b3..9741ecf 100644
--- a/src/gtd-task-list-view.h
+++ b/src/gtd-task-list-view.h
@@ -96,6 +96,11 @@ gboolean                  gtd_task_list_view_get_show_new_task_row (GtdTaskListV
 void                      gtd_task_list_view_set_show_new_task_row (GtdTaskListView        *view,
                                                                     gboolean                
show_new_task_row);
 
+GDateTime*                gtd_task_list_view_get_default_date   (GtdTaskListView     *self);
+
+void                      gtd_task_list_view_set_default_date   (GtdTaskListView     *self,
+                                                                 GDateTime           *default_date);
+
 G_END_DECLS
 
 #endif /* GTD_TASK_LIST_VIEW_H */


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