[gnome-todo] plugin-manager: clear ::activate & ::deactivate usage



commit 5cc49b5a2ab1447ada7844956502b095675660c5
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Feb 3 14:58:36 2016 -0200

    plugin-manager: clear ::activate & ::deactivate usage

 src/interfaces/gtd-activatable.c |    9 ++++++++
 src/plugin/gtd-plugin-manager.c  |   40 ++++++++++++++++++++++++-------------
 2 files changed, 35 insertions(+), 14 deletions(-)
---
diff --git a/src/interfaces/gtd-activatable.c b/src/interfaces/gtd-activatable.c
index 521957a..73dedbc 100644
--- a/src/interfaces/gtd-activatable.c
+++ b/src/interfaces/gtd-activatable.c
@@ -152,6 +152,10 @@ gtd_activatable_default_init (GtdActivatableInterface *iface)
  * Activates the extension. This is the starting point where
  * the implementation does everything it needs to do. Avoid
  * doing it earlier than this call.
+ *
+ * This function is called after the extension is loaded and
+ * the signals are connected. If you want to do anything before
+ * that, the _init function should be used instead.
  */
 void
 gtd_activatable_activate (GtdActivatable *activatable)
@@ -168,6 +172,11 @@ gtd_activatable_activate (GtdActivatable *activatable)
  *
  * Deactivates the extension. Here, the extension should remove
  * all providers and panels it set.
+ *
+ * This function is called before the extension is removed. At
+ * this point, the plugin manager already removed all providers
+ * and widgets this extension exported. If you want to do anything
+ * after the extension is removed, use GObject::finalize instead.
  */
 void
 gtd_activatable_deactivate (GtdActivatable *activatable)
diff --git a/src/plugin/gtd-plugin-manager.c b/src/plugin/gtd-plugin-manager.c
index db3a4b0..d8a9ac5 100644
--- a/src/plugin/gtd-plugin-manager.c
+++ b/src/plugin/gtd-plugin-manager.c
@@ -197,10 +197,33 @@ on_plugin_unloaded (PeasEngine       *engine,
   for (l = extension_providers; l != NULL; l = l->next)
     on_provider_removed (activatable, l->data, self);
 
+  /* Deactivates the extension */
+  gtd_activatable_deactivate (activatable);
+
   /* Emit the signal */
   g_signal_emit (self, signals[PLUGIN_UNLOADED], 0, info, activatable);
 
+  /* Disconnect old signals */
+  g_signal_handlers_disconnect_by_func (activatable,
+                                        on_panel_added,
+                                        self);
+
+  g_signal_handlers_disconnect_by_func (activatable,
+                                        on_panel_removed,
+                                        self);
+
+  g_signal_handlers_disconnect_by_func (activatable,
+                                        on_provider_added,
+                                        self);
+
+  g_signal_handlers_disconnect_by_func (activatable,
+                                        on_provider_removed,
+                                        self);
+
   g_hash_table_remove (self->info_to_extension, info);
+
+  /* Destroy the extension */
+  g_clear_object (&activatable);
 }
 
 static void
@@ -212,13 +235,7 @@ on_plugin_loaded (PeasEngine       *engine,
     {
       GtdActivatable *activatable;
       PeasExtension *extension;
-      GtdManager *manager;
       const GList *l;
-      gchar **active_extensions;
-
-      manager = gtd_manager_get_default ();
-      active_extensions = g_settings_get_strv (gtd_manager_get_settings (manager),
-                                               "active-extensions");
 
       /*
        * Actually create the plugin object,
@@ -232,12 +249,6 @@ on_plugin_loaded (PeasEngine       *engine,
       /* All extensions shall be GtdActivatable impls */
       activatable = GTD_ACTIVATABLE (extension);
 
-      if (g_strv_contains ((const gchar* const*) active_extensions,
-                           peas_plugin_info_get_module_name (info)))
-        {
-          gtd_activatable_activate (activatable);
-        }
-
       g_hash_table_insert (self->info_to_extension,
                            info,
                            extension);
@@ -270,10 +281,11 @@ on_plugin_loaded (PeasEngine       *engine,
                         G_CALLBACK (on_panel_removed),
                         self);
 
+      /* Activate extension */
+      gtd_activatable_activate (activatable);
+
       /* Emit the signal */
       g_signal_emit (self, signals[PLUGIN_LOADED], 0, info, extension);
-
-      g_strfreev (active_extensions);
     }
 }
 


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