Author: damoxc

Revision: 5744

Log:
        extend the Deluge.Events class to include support for subscribing to 
the remote events

Diff:
Modified: trunk/deluge/ui/web/js/Deluge.Events.js
===================================================================
--- trunk/deluge/ui/web/js/Deluge.Events.js     2009-09-14 15:41:12 UTC (rev 
5743)
+++ trunk/deluge/ui/web/js/Deluge.Events.js     2009-09-14 15:55:36 UTC (rev 
5744)
@@ -39,7 +39,6 @@
  */
 
 (function() {
-
     Events = Ext.extend(Ext.util.Observable, {
         constructor: function() {
             Events.superclass.constructor.call(this);
@@ -47,8 +46,39 @@
         
         addListener: function(eventName, fn, scope, o) {
             this.addEvents(eventName);
+           if (/[A-Z]/.test(eventName.substring(0, 1))) {
+               Deluge.Client.web.register_event_listener(eventName);
+           }
             Events.superclass.addListener.call(this, eventName, fn, scope, o);
-        }
+        },
+       
+       poll: function() {
+           Deluge.Client.web.get_events({
+               success: this.onPollSuccess,
+               scope: this
+           });
+       },
+       
+       start: function() {
+           this.poll = this.poll.bind(this);
+           this.running = setInterval(this.poll, 2000);
+           this.poll();
+       },
+       
+       stop: function() {
+           if (this.running) {
+               clearInterval(this.running); 
+           }
+       },
+       
+       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.fire = Events.prototype.fireEvent

Modified: trunk/deluge/ui/web/js/Deluge.UI.js
===================================================================
--- trunk/deluge/ui/web/js/Deluge.UI.js 2009-09-14 15:41:12 UTC (rev 5743)
+++ trunk/deluge/ui/web/js/Deluge.UI.js 2009-09-14 15:55:36 UTC (rev 5744)
@@ -82,6 +82,7 @@
                
                Deluge.Client.on('connected', function(e) {
                        Deluge.Login.show();
+                       Deluge.Events.start();
                }, this, {single: true});
                
                this.update = this.update.bind(this);
@@ -156,11 +157,11 @@
         * Stop the Deluge UI polling the server and clear the interface.
         */
        stop: function() {
-               if (this.running) {
-            clearInterval(this.running);
-            this.running = false;
-                       Deluge.Torrents.getStore().loadData([]);
-        }
+           if (this.running) {
+               clearInterval(this.running);
+               this.running = false;
+               Deluge.Torrents.getStore().loadData([]);
+           }
        }
 }
 



--~--~---------~--~----~------------~-------~--~----~
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