[gnome-todo/wip/gbsneto/plugins: 9/10] manager: complete construction before load plugin



commit 676ce6658c8ede80f3822d2009dc0b5b7801faf4
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Dec 27 23:07:23 2015 -0200

    manager: complete construction before load plugin
    
    By loading plugins while construction, GtdManager
    ends up being loaded once when calling ::get_default().
    
    To fix that, wait for construction to be finished and
    then call ::load_plugins. Since I don't want anyone
    else loading plugins, this is a protected function.

 src/Makefile.am             |    1 +
 src/gtd-application.c       |    2 +
 src/gtd-manager-protected.h |   30 +++++++++++++++++++++
 src/gtd-manager.c           |   61 ++++++++++++++++++++++++++----------------
 src/gtd-plugin-manager.c    |    9 +++++-
 src/gtd-plugin-manager.h    |    2 +
 6 files changed, 81 insertions(+), 24 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 01ef745..f47b0f2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -49,6 +49,7 @@ gnome_todo_SOURCES = \
        gtd-initial-setup-window.h \
        gtd-manager.c \
        gtd-manager.h \
+       gtd-manager-protected.h \
        gtd-object.c \
        gtd-object.h \
        gtd-plugin-manager.c \
diff --git a/src/gtd-application.c b/src/gtd-application.c
index 1de11ef..116244d 100644
--- a/src/gtd-application.c
+++ b/src/gtd-application.c
@@ -23,6 +23,7 @@
 #include "gtd-application.h"
 #include "gtd-initial-setup-window.h"
 #include "gtd-manager.h"
+#include "gtd-manager-protected.h"
 #include "gtd-window.h"
 
 #include <glib.h>
@@ -244,6 +245,7 @@ gtd_application_startup (GApplication *application)
 
   /* manager */
   priv->manager = gtd_manager_get_default ();
+  gtd_manager_load_plugins (priv->manager);
 
   /* app menu */
   g_application_set_resource_base_path (application, "/org/gnome/todo");
diff --git a/src/gtd-manager-protected.h b/src/gtd-manager-protected.h
new file mode 100644
index 0000000..c4346a9
--- /dev/null
+++ b/src/gtd-manager-protected.h
@@ -0,0 +1,30 @@
+/* gtd-manager-protected.h
+ *
+ * Copyright (C) 2015 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTD_MANAGER_PROTECTED_H
+#define GTD_MANAGER_PROTECTED_H
+
+#include "gtd-types.h"
+
+G_BEGIN_DECLS
+
+void                 gtd_manager_load_plugins                    (GtdManager         *manager);
+
+G_END_DECLS
+
+#endif /* GTD_MANAGER_PROTECTED_H */
diff --git a/src/gtd-manager.c b/src/gtd-manager.c
index d110ed1..eb8a291 100644
--- a/src/gtd-manager.c
+++ b/src/gtd-manager.c
@@ -19,6 +19,7 @@
 #include "interfaces/gtd-provider.h"
 #include "interfaces/gtd-panel.h"
 #include "gtd-manager.h"
+#include "gtd-manager-protected.h"
 #include "gtd-plugin-manager.h"
 #include "gtd-task.h"
 #include "gtd-task-list.h"
@@ -452,29 +453,6 @@ gtd_manager_init (GtdManager *self)
 {
   self->priv = gtd_manager_get_instance_private (self);
   self->priv->settings = g_settings_new ("org.gnome.todo");
-
-  /* plugin manager */
-  self->priv->plugin_manager = gtd_plugin_manager_new ();
-
-  g_signal_connect (self->priv->plugin_manager,
-                    "panel-registered",
-                    G_CALLBACK (gtd_manager__panel_added),
-                    self);
-
-  g_signal_connect (self->priv->plugin_manager,
-                    "panel-unregistered",
-                    G_CALLBACK (gtd_manager__panel_removed),
-                    self);
-
-  g_signal_connect (self->priv->plugin_manager,
-                    "provider-registered",
-                    G_CALLBACK (gtd_manager__provider_added),
-                    self);
-
-  g_signal_connect (self->priv->plugin_manager,
-                    "provider-unregistered",
-                    G_CALLBACK (gtd_manager__provider_removed),
-                    self);
 }
 
 /**
@@ -816,3 +794,40 @@ gtd_manager_emit_error_message (GtdManager  *manager,
                            primary_message,
                            secondary_message);
 }
+
+void
+gtd_manager_load_plugins (GtdManager *manager)
+{
+  GtdManagerPrivate *priv = gtd_manager_get_instance_private (manager);
+
+  /*
+   * Avoid loading plugins more than once.
+   */
+  if (priv->plugin_manager)
+    return;
+
+  /* plugin manager */
+  priv->plugin_manager = gtd_plugin_manager_new ();
+
+  g_signal_connect (priv->plugin_manager,
+                    "panel-registered",
+                    G_CALLBACK (gtd_manager__panel_added),
+                    manager);
+
+  g_signal_connect (priv->plugin_manager,
+                    "panel-unregistered",
+                    G_CALLBACK (gtd_manager__panel_removed),
+                    manager);
+
+  g_signal_connect (priv->plugin_manager,
+                    "provider-registered",
+                    G_CALLBACK (gtd_manager__provider_added),
+                    manager);
+
+  g_signal_connect (priv->plugin_manager,
+                    "provider-unregistered",
+                    G_CALLBACK (gtd_manager__provider_removed),
+                    manager);
+
+  gtd_plugin_manager_load_plugins (priv->plugin_manager);
+}
diff --git a/src/gtd-plugin-manager.c b/src/gtd-plugin-manager.c
index df7a6ad..8407118 100644
--- a/src/gtd-plugin-manager.c
+++ b/src/gtd-plugin-manager.c
@@ -181,6 +181,8 @@ on_plugin_loaded (PeasEngine       *engine,
                   PeasPluginInfo   *info,
                   GtdPluginManager *self)
 {
+  g_message ("%s", G_STRFUNC);
+
   if (peas_engine_provides_extension (engine, info, GTD_TYPE_ACTIVATABLE))
     {
       GtdActivatable *activatable;
@@ -309,7 +311,6 @@ gtd_plugin_manager_init (GtdPluginManager *self)
   gtd_object_set_ready (GTD_OBJECT (self), FALSE);
 
   setup_engine (self);
-  setup_plugins (self);
 
   gtd_object_set_ready (GTD_OBJECT (self), TRUE);
 }
@@ -319,3 +320,9 @@ gtd_plugin_manager_new (void)
 {
   return g_object_new (GTD_TYPE_PLUGIN_MANAGER, NULL);
 }
+
+void
+gtd_plugin_manager_load_plugins (GtdPluginManager *self)
+{
+  setup_plugins (self);
+}
diff --git a/src/gtd-plugin-manager.h b/src/gtd-plugin-manager.h
index f7b1a74..772006e 100644
--- a/src/gtd-plugin-manager.h
+++ b/src/gtd-plugin-manager.h
@@ -32,6 +32,8 @@ G_DECLARE_FINAL_TYPE (GtdPluginManager, gtd_plugin_manager, GTD, PLUGIN_MANAGER,
 
 GtdPluginManager*    gtd_plugin_manager_new                      (void);
 
+void                 gtd_plugin_manager_load_plugins             (GtdPluginManager   *self);
+
 G_END_DECLS
 
 #endif /* GTD_PLUGIN_MANAGER_H */


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