[gnome-todo/wip/gbsneto/plugins] manager: add GtdManager::get_default() method



commit a1d67e3b6ed20abe3c8972e77ec1dc9d22099ac2
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Dec 12 18:59:29 2015 -0200

    manager: add GtdManager::get_default() method

 src/gtd-application.c |    2 +-
 src/gtd-manager.c     |   20 ++++++++++++++++++++
 src/gtd-manager.h     |    2 ++
 3 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/src/gtd-application.c b/src/gtd-application.c
index d990fc3..43acf3e 100644
--- a/src/gtd-application.c
+++ b/src/gtd-application.c
@@ -241,7 +241,7 @@ gtd_application_startup (GApplication *application)
   GtdApplicationPrivate *priv = GTD_APPLICATION (application)->priv;
 
   /* manager */
-  priv->manager = gtd_manager_new ();
+  priv->manager = gtd_manager_get_default ();
 
   /* app menu */
   g_application_set_resource_base_path (application, "/org/gnome/todo");
diff --git a/src/gtd-manager.c b/src/gtd-manager.c
index 8269b9e..3a543fb 100644
--- a/src/gtd-manager.c
+++ b/src/gtd-manager.c
@@ -79,6 +79,9 @@ const gchar *supported_providers[] = {
   NULL
 };
 
+/* Singleton instance */
+GtdManager *gtd_manager_instance = NULL;
+
 enum
 {
   DEFAULT_STORAGE_CHANGED,
@@ -1320,6 +1323,23 @@ gtd_manager_init (GtdManager *self)
   self->priv->today_tasks_list = g_object_new (GTD_TYPE_TASK_LIST, NULL);
 }
 
+/**
+ * gtd_manager_get_default:
+ *
+ * Retrieves the singleton #GtdManager instance. You should always
+ * use this function instead of @gtd_manager_new.
+ *
+ * Returns: (transfer none): the singleton #GtdManager instance.
+ */
+GtdManager*
+gtd_manager_get_default (void)
+{
+  if (!gtd_manager_instance)
+    gtd_manager_instance = gtd_manager_new ();
+
+  return gtd_manager_instance;
+}
+
 GtdManager*
 gtd_manager_new (void)
 {
diff --git a/src/gtd-manager.h b/src/gtd-manager.h
index 12a33b1..f4625e3 100644
--- a/src/gtd-manager.h
+++ b/src/gtd-manager.h
@@ -35,6 +35,8 @@ G_DECLARE_FINAL_TYPE (GtdManager, gtd_manager, GTD, MANAGER, GtdObject)
 
 GtdManager*             gtd_manager_new                   (void);
 
+GtdManager*             gtd_manager_get_default           (void);
+
 ESourceRegistry*        gtd_manager_get_source_registry   (GtdManager           *manager);
 
 GList*                  gtd_manager_get_task_lists        (GtdManager           *manager);


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