Module: deluge
Branch: master
Commit: 7e12222d33e424e7611b2bac701262a4ee5e5c96

Author: Damien Churchill <[email protected]>
Date:   Sat Apr 24 01:40:34 2010 +0100

create a plugin registration system to allow for plugin loading on the fly
remove the plugin event handlers from the event manager
fix enabling/disabling plugins when the preferences page hasn't been rendered 
yet

---

 deluge/ui/web/js/deluge-all/Deluge.js              |   28 ++++++++++++++++++++
 deluge/ui/web/js/deluge-all/EventsManager.js       |    2 -
 deluge/ui/web/js/deluge-all/UI.js                  |   27 ++++++++++++------
 .../web/js/deluge-all/preferences/PluginsPage.js   |    2 +
 4 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/deluge/ui/web/js/deluge-all/Deluge.js 
b/deluge/ui/web/js/deluge-all/Deluge.js
index 96810be..de82dd7 100644
--- a/deluge/ui/web/js/deluge-all/Deluge.js
+++ b/deluge/ui/web/js/deluge-all/Deluge.js
@@ -87,6 +87,9 @@ Ext.USE_NATIVE_JSON = true;
 
 // Create the Deluge namespace
 Ext.apply(Deluge, {
+
+       // private
+       pluginStore: {},
        
        // private
        progressTpl:    '<div class="x-progress-wrap x-progress-renderered">' +
@@ -117,6 +120,31 @@ Ext.apply(Deluge, {
                var barWidth = progressWidth - 1;
                var textWidth = ((progressWidth - modifier) > 0 ? progressWidth 
- modifier : 0);
                return String.format(Deluge.progressTpl, text, width, barWidth, 
textWidth);
+       },
+
+       /**
+        * Constructs a new instance of the specified plugin.
+        * @param {String} name The plugin name to create
+        */
+       createPlugin: function(name) {
+               return new Deluge.pluginStore[name]();
+       },
+
+       /**
+        * Check to see if a plugin has been registered.
+        * @param {String} name The plugin name to check
+        */
+       hasPlugin: function(name) {
+               return (Deluge.pluginStore[name]) ? true : false;
+       },
+
+       /**
+        * Register a plugin with the Deluge interface.
+        * @param {String} name The plugin name to register
+        * @param {Plugin} plugin The plugin to register
+        */
+       registerPlugin: function(name, plugin) {
+               Deluge.pluginStore[name] = plugin;
        }
        
 });
diff --git a/deluge/ui/web/js/deluge-all/EventsManager.js 
b/deluge/ui/web/js/deluge-all/EventsManager.js
index df669ff..0981d43 100644
--- a/deluge/ui/web/js/deluge-all/EventsManager.js
+++ b/deluge/ui/web/js/deluge-all/EventsManager.js
@@ -88,8 +88,6 @@ Deluge.EventsManager = Ext.extend(Ext.util.Observable, {
        // private
        onLogin: function() {
                this.start();
-               this.on('PluginEnabledEvent', this.onPluginEnabled, this);
-               this.on('PluginDisabledEvent', this.onPluginDisabled, this);
        },
 
        onGetEventsSuccess: function(events) {
diff --git a/deluge/ui/web/js/deluge-all/UI.js 
b/deluge/ui/web/js/deluge-all/UI.js
index 5ec69cc..a73a8c6 100644
--- a/deluge/ui/web/js/deluge-all/UI.js
+++ b/deluge/ui/web/js/deluge-all/UI.js
@@ -81,8 +81,9 @@ deluge.ui = {
                        url: deluge.config.base + 'json'
                });
        
-               for (var plugin in Deluge.plugins) {
-                       plugin = new Deluge.plugins[plugin]();
+               // enable all the already active plugins
+               for (var plugin in Deluge.pluginStore) {
+                       plugin = Deluge.createPlugin(plugin);
                        plugin.enable();
                        deluge.plugins[plugin.name] = plugin;
                }
@@ -161,14 +162,19 @@ deluge.ui = {
        },
 
        onPluginEnabled: function(pluginName) {
-               deluge.client.web.get_plugin_resources(pluginName, {
-                       success: this.onGotPluginResources,
-                       scope: this
-               })
+               alert('enabled ' + pluginName);
+               if (deluge.plugins[pluginName]) {
+                       deluge.plugins[pluginName].enable();
+               } else {
+                       deluge.client.web.get_plugin_resources(pluginName, {
+                               success: this.onGotPluginResources,
+                               scope: this
+                       });
+               }
        },
 
        onGotPluginResources: function(resources) {
-               var scripts = (deluge.debug) ? resources.debug_scripts : 
resources.scripts;
+               var scripts = (Deluge.debug) ? resources.debug_scripts : 
resources.scripts;
                Ext.each(scripts, function(script) {
                        Ext.ux.JSLoader({
                                url: script,
@@ -179,15 +185,18 @@ deluge.ui = {
        },
 
        onPluginDisabled: function(pluginName) {
+               alert('disabled ' + pluginName);
                deluge.plugins[pluginName].disable();
        },
 
        onPluginLoaded: function(options) {
                // This could happen if the plugin has multiple scripts
-               if (!deluge.plugins[options.pluginName]) return;
+               if (!Deluge.hasPlugin(options.pluginName)) return;
 
                // Enable the plugin
-               deluge.plugins[options.pluginName].enable();
+               plugin = Deluge.createPlugin(options.pluginName);
+               plugin.enable();
+               deluge.plugins[plugin.name] = plugin;
        },
 
        /**
diff --git a/deluge/ui/web/js/deluge-all/preferences/PluginsPage.js 
b/deluge/ui/web/js/deluge-all/preferences/PluginsPage.js
index 63da922..c805cba 100644
--- a/deluge/ui/web/js/deluge-all/preferences/PluginsPage.js
+++ b/deluge/ui/web/js/deluge-all/preferences/PluginsPage.js
@@ -310,6 +310,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
 
        onPluginEnabled: function(pluginName) {
                var index = this.grid.getStore().find('plugin', pluginName);
+               if (index == -1) return;
                var plugin = this.grid.getStore().getAt(index);
                plugin.set('enabled', true);
                plugin.commit();
@@ -317,6 +318,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
        
        onPluginDisabled: function(pluginName) {
                var index = this.grid.getStore().find('plugin', pluginName);
+               if (index == -1) return;
                var plugin = this.grid.getStore().getAt(index);
                plugin.set('enabled', false);
                plugin.commit();

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to