[gnome-todo] provider: Introduce :generate_task vfunc



commit ed3cd187163a0b7904fd798608ec155199713acb
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Sep 28 00:02:02 2017 -0300

    provider: Introduce :generate_task vfunc
    
    This vfunc is necessary for when the GtdProvider needs
    to setup the task before it can be used. For example,
    the EDS plugin needs to setup an ECalComponent before
    the GtdTaskEds subclass can be used properly.

 plugins/eds/gtd-provider-eds.c           |   16 +++++++++++++++
 plugins/eds/gtd-provider-eds.h           |    2 +
 plugins/eds/gtd-provider-goa.c           |    7 ++++++
 plugins/eds/gtd-provider-local.c         |    7 ++++++
 plugins/todo-txt/gtd-provider-todo-txt.c |    2 +-
 src/gtd-new-task-row.c                   |    5 +++-
 src/interfaces/gtd-provider.c            |   31 ++++++++++++++++++++++++++++++
 src/interfaces/gtd-provider.h            |    4 +++
 8 files changed, 72 insertions(+), 2 deletions(-)
---
diff --git a/plugins/eds/gtd-provider-eds.c b/plugins/eds/gtd-provider-eds.c
index b9a2a88..000e847 100644
--- a/plugins/eds/gtd-provider-eds.c
+++ b/plugins/eds/gtd-provider-eds.c
@@ -1102,3 +1102,19 @@ gtd_provider_eds_set_default_task_list (GtdProviderEds *provider,
 
   g_object_notify (G_OBJECT (provider), "default-task-list");
 }
+
+GtdTask*
+gtd_provider_eds_generate_task (GtdProviderEds *self)
+{
+  ECalComponent *component;
+  GtdTask *task;
+
+  component = e_cal_component_new ();
+  e_cal_component_set_new_vtype (component, E_CAL_COMPONENT_TODO);
+
+  task = gtd_task_eds_new (component);
+
+  g_object_unref (component);
+
+  return task;
+}
diff --git a/plugins/eds/gtd-provider-eds.h b/plugins/eds/gtd-provider-eds.h
index a5c3f78..59c8226 100644
--- a/plugins/eds/gtd-provider-eds.h
+++ b/plugins/eds/gtd-provider-eds.h
@@ -68,6 +68,8 @@ GtdTaskList*         gtd_provider_eds_get_default_task_list      (GtdProviderEds
 void                 gtd_provider_eds_set_default_task_list      (GtdProviderEds     *provider,
                                                                   GtdTaskList        *list);
 
+GtdTask*             gtd_provider_eds_generate_task              (GtdProviderEds     *self);
+
 G_END_DECLS
 
 #endif /* GTD_PROVIDER_EDS_H */
diff --git a/plugins/eds/gtd-provider-goa.c b/plugins/eds/gtd-provider-goa.c
index 43337d3..19b5f21 100644
--- a/plugins/eds/gtd-provider-goa.c
+++ b/plugins/eds/gtd-provider-goa.c
@@ -176,6 +176,12 @@ gtd_provider_goa_set_default_task_list (GtdProvider *provider,
   gtd_provider_eds_set_default_task_list (GTD_PROVIDER_EDS (provider), list);
 }
 
+static GtdTask*
+gtd_provider_goa_generate_task (GtdProvider *provider)
+{
+  return gtd_provider_eds_generate_task (GTD_PROVIDER_EDS (provider));
+}
+
 static void
 gtd_provider_iface_init (GtdProviderInterface *iface)
 {
@@ -194,6 +200,7 @@ gtd_provider_iface_init (GtdProviderInterface *iface)
   iface->get_task_lists = gtd_provider_goa_get_task_lists;
   iface->get_default_task_list = gtd_provider_goa_get_default_task_list;
   iface->set_default_task_list = gtd_provider_goa_set_default_task_list;
+  iface->generate_task = gtd_provider_goa_generate_task;
 }
 
 static void
diff --git a/plugins/eds/gtd-provider-local.c b/plugins/eds/gtd-provider-local.c
index 245bc0d..e1c356a 100644
--- a/plugins/eds/gtd-provider-local.c
+++ b/plugins/eds/gtd-provider-local.c
@@ -196,6 +196,12 @@ gtd_provider_local_set_default_task_list (GtdProvider *provider,
   gtd_provider_eds_set_default_task_list (GTD_PROVIDER_EDS (provider), list);
 }
 
+static GtdTask*
+gtd_provider_local_generate_task (GtdProvider *provider)
+{
+  return gtd_provider_eds_generate_task (GTD_PROVIDER_EDS (provider));
+}
+
 static void
 gtd_provider_iface_init (GtdProviderInterface *iface)
 {
@@ -214,6 +220,7 @@ gtd_provider_iface_init (GtdProviderInterface *iface)
   iface->get_task_lists = gtd_provider_local_get_task_lists;
   iface->get_default_task_list = gtd_provider_local_get_default_task_list;
   iface->set_default_task_list = gtd_provider_local_set_default_task_list;
+  iface->generate_task = gtd_provider_local_generate_task;
 }
 
 GtdProviderLocal*
diff --git a/plugins/todo-txt/gtd-provider-todo-txt.c b/plugins/todo-txt/gtd-provider-todo-txt.c
index 4f69896..e628981 100644
--- a/plugins/todo-txt/gtd-provider-todo-txt.c
+++ b/plugins/todo-txt/gtd-provider-todo-txt.c
@@ -289,7 +289,7 @@ gtd_provider_todo_txt_load_tasks (GtdProviderTodoTxt *self)
                 }
               else
                 {
-                  parent_task = gtd_task_new ();
+                  parent_task = gtd_provider_generate_task (GTD_PROVIDER (self));
                   gtd_task_set_list (parent_task, list);
                   gtd_task_set_title (parent_task, g_object_get_data (G_OBJECT (task), "root_task_name"));
 
diff --git a/src/gtd-new-task-row.c b/src/gtd-new-task-row.c
index 8c3b9c5..fa97f19 100644
--- a/src/gtd-new-task-row.c
+++ b/src/gtd-new-task-row.c
@@ -136,13 +136,16 @@ default_tasklist_changed_cb (GtdNewTaskRow *self)
 static void
 entry_activated_cb (GtdNewTaskRow *self)
 {
+  GtdProvider *provider;
   GtdTask *new_task;
 
   /* Cannot create empty tasks */
   if (gtk_entry_get_text_length (self->entry) == 0)
     return;
 
-  new_task = gtd_task_new ();
+  provider = gtd_task_list_get_provider (self->selected_tasklist);
+
+  new_task = gtd_provider_generate_task (provider);
   gtd_task_set_title (new_task, gtk_entry_get_text (self->entry));
 
   g_signal_emit (self, signals[CREATE_TASK], 0, new_task, self->selected_tasklist);
diff --git a/src/interfaces/gtd-provider.c b/src/interfaces/gtd-provider.c
index abaa733..d404521 100644
--- a/src/interfaces/gtd-provider.c
+++ b/src/interfaces/gtd-provider.c
@@ -17,6 +17,7 @@
  */
 
 #include "gtd-provider.h"
+#include "gtd-task.h"
 #include "gtd-task-list.h"
 
 /**
@@ -45,9 +46,22 @@ enum
 
 static guint signals[NUM_SIGNALS] = { 0, };
 
+
+/*
+ * Default implementations
+ */
+
+static GtdTask*
+gtd_provider_default_generate_task (GtdProvider *self)
+{
+  return gtd_task_new ();
+}
+
 static void
 gtd_provider_default_init (GtdProviderInterface *iface)
 {
+  iface->generate_task = gtd_provider_default_generate_task;
+
   /**
    * GtdProvider::enabled:
    *
@@ -430,3 +444,20 @@ gtd_provider_set_default_task_list (GtdProvider *provider,
 
   return GTD_PROVIDER_GET_IFACE (provider)->set_default_task_list (provider, list);
 }
+
+/**
+ * gtd_provider_generate_task:
+ * @provider: a #GtdProvider
+ *
+ * Creates a new, empty #GtdTask.
+ *
+ * Returns: (transfer full): a #GtdTask
+ */
+GtdTask*
+gtd_provider_generate_task (GtdProvider *self)
+{
+  g_return_val_if_fail (GTD_IS_PROVIDER (self), NULL);
+  g_return_val_if_fail (GTD_PROVIDER_GET_IFACE (self)->generate_task, NULL);
+
+  return GTD_PROVIDER_GET_IFACE (self)->generate_task (self);
+}
diff --git a/src/interfaces/gtd-provider.h b/src/interfaces/gtd-provider.h
index 874ed7a..ac2d7d1 100644
--- a/src/interfaces/gtd-provider.h
+++ b/src/interfaces/gtd-provider.h
@@ -75,6 +75,8 @@ struct _GtdProviderInterface
 
   void               (*set_default_task_list)                    (GtdProvider        *provider,
                                                                   GtdTaskList        *list);
+
+  GtdTask*           (*generate_task)                            (GtdProvider        *self);
 };
 
 const gchar*         gtd_provider_get_id                         (GtdProvider        *provider);
@@ -114,6 +116,8 @@ GtdTaskList*         gtd_provider_get_default_task_list          (GtdProvider
 void                 gtd_provider_set_default_task_list          (GtdProvider        *provider,
                                                                   GtdTaskList        *list);
 
+GtdTask*             gtd_provider_generate_task                  (GtdProvider        *self);
+
 G_END_DECLS
 
 #endif /* GTD_PROVIDER_H */


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