fix the formatting and change it so the events manager is started on the login event

This commit is contained in:
Damien Churchill 2010-01-23 15:38:07 +00:00
parent 42cbf4f5c6
commit 39341f623f
1 changed files with 42 additions and 35 deletions

View File

@ -41,52 +41,59 @@ Copyright:
(function() { (function() {
Events = Ext.extend(Ext.util.Observable, { Events = Ext.extend(Ext.util.Observable, {
constructor: function() { constructor: function() {
this.toRegister = []; this.toRegister = [];
this.on('login', this.onLogin, this);
Events.superclass.constructor.call(this); Events.superclass.constructor.call(this);
}, },
addListener: function(eventName, fn, scope, o) { addListener: function(eventName, fn, scope, o) {
this.addEvents(eventName); this.addEvents(eventName);
if (/[A-Z]/.test(eventName.substring(0, 1))) { if (/[A-Z]/.test(eventName.substring(0, 1))) {
if (!Deluge.Client) { if (!Deluge.Client) {
this.toRegister.push(eventName); this.toRegister.push(eventName);
} else { } else {
Deluge.Client.web.register_event_listener(eventName); Deluge.Client.web.register_event_listener(eventName);
} }
} }
Events.superclass.addListener.call(this, eventName, fn, scope, o); Events.superclass.addListener.call(this, eventName, fn, scope, o);
}, },
poll: function() { poll: function() {
Deluge.Client.web.get_events({ Deluge.Client.web.get_events({
success: this.onPollSuccess, success: this.onPollSuccess,
scope: this scope: this
}); });
}, },
start: function() { start: function() {
Ext.each(this.toRegister, function(eventName) { Ext.each(this.toRegister, function(eventName) {
Deluge.Client.web.register_event_listener(eventName); Deluge.Client.web.register_event_listener(eventName);
}); });
this.poll = this.poll.bind(this); this.poll = this.poll.bind(this);
this.running = setInterval(this.poll, 2000); this.running = setInterval(this.poll, 2000);
this.poll(); this.poll();
}, },
stop: function() { stop: function() {
if (this.running) { if (this.running) {
clearInterval(this.running); clearInterval(this.running);
} }
}, },
onPollSuccess: function(events) { onLogin: function() {
if (!events) return; this.start();
Ext.each(events, function(event) { this.on('PluginEnabledEvent', this.onPluginEnabled, this);
var name = event[0], args = event[1]; this.on('PluginDisabledEvent', this.onPluginDisabled, this);
args.splice(0, 0, name); },
this.fireEvent.apply(this, args);
}, this); onPollSuccess: function(events) {
} if (!events) return;
Ext.each(events, function(event) {
var name = event[0], args = event[1];
args.splice(0, 0, name);
this.fireEvent.apply(this, args);
}, this);
}
}); });
Events.prototype.on = Events.prototype.addListener Events.prototype.on = Events.prototype.addListener
Events.prototype.fire = Events.prototype.fireEvent Events.prototype.fire = Events.prototype.fireEvent