implement ...
Content-type: text/plain

Author: damoxc

Revision: 4903

Log:
        implement a basic add connection window
implement remove connection

Diff:
Modified: trunk/deluge/ui/web/js/deluge-bars.js
===================================================================
--- trunk/deluge/ui/web/js/deluge-bars.js       2009-03-20 20:46:36 UTC (rev 
4902)
+++ trunk/deluge/ui/web/js/deluge-bars.js       2009-03-20 22:36:58 UTC (rev 
4903)
@@ -383,7 +383,7 @@
                        }
                }, this);
                
-               // Perform a cleanup of fitlers that aren't enabled
+               // Perform a cleanup of fitlers that aren't enabled any more
                $each(this.panels.getKeys(), function(filter) {
                        if (!filters.has(filter)) {
                                // We need to remove the panel

Modified: trunk/deluge/ui/web/js/deluge-connections.js
===================================================================
--- trunk/deluge/ui/web/js/deluge-connections.js        2009-03-20 20:46:36 UTC 
(rev 4902)
+++ trunk/deluge/ui/web/js/deluge-connections.js        2009-03-20 22:36:58 UTC 
(rev 4903)
@@ -44,9 +44,35 @@
        },
        
        onAdd: function(button, e) {
-               //Deluge.Connections.Add.show();
+               Deluge.Connections.Add.show();
        },
        
+       onAddHost: function() {
+               var form = Deluge.Connections.Add.items.first();
+               var host = form.items.get('host').getValue();
+               var port = form.items.get('port').getValue();
+               var username = form.items.get('username').getValue();
+               var password = form.items.get('password').getValue();
+               
+               Deluge.Client.web.add_host(host, port, username, password, {
+                       onSuccess: function(result) {
+                               if (!result) {
+                                       Ext.MessageBox.show({
+                        title: _('Error'),
+                        msg: "Unable to add host",
+                        buttons: Ext.MessageBox.OK,
+                        modal: false,
+                        icon: Ext.MessageBox.ERROR,
+                        iconCls: 'x-deluge-icon-error'
+                    });
+                               } else {
+                                       Deluge.Connections.runCheck();
+                               }
+                               Deluge.Connections.Add.hide();
+                       }
+               });
+       },
+       
     onClose: function(e) {
                $clear(Deluge.Connections.running);
                Deluge.Connections.Window.hide();
@@ -74,6 +100,26 @@
                selection.selectRow(Deluge.Connections.selectedRow);
        },
        
+       onRemove: function(button) {
+               var connection = 
Deluge.Connections.Grid.getSelectionModel().getSelected();
+               Deluge.Client.web.remove_host(connection.id, {
+                       onSuccess: function(result) {
+                               if (!result) {
+                                       Ext.MessageBox.show({
+                        title: _('Error'),
+                        msg: result[1],
+                        buttons: Ext.MessageBox.OK,
+                        modal: false,
+                        icon: Ext.MessageBox.ERROR,
+                        iconCls: 'x-deluge-icon-error'
+                    });
+                               } else {
+                                       
Deluge.Connections.Grid.store.remove(connection);
+                               }
+                       }
+               });
+       },
+       
        onSelect: function(selModel, rowIndex, record) {
                Deluge.Connections.selectedRow = rowIndex;
        },
@@ -151,7 +197,8 @@
                                id: 'remove',
                                cls: 'x-btn-text-icon',
                                text: _('Remove'),
-                               icon: '/icons/16/remove.png'
+                               icon: '/icons/16/remove.png',
+                               handler: Deluge.Connections.onRemove
                        }, '->', {
                                id: 'stop',
                                cls: 'x-btn-text-icon',
@@ -163,6 +210,58 @@
        })
 });
 
+Deluge.Connections.Add = new Ext.Window({
+       layout: 'fit',
+    width: 300,
+    height: 220,
+    bodyStyle: 'padding: 10px 5px;',
+    buttonAlign: 'right',
+    closeAction: 'hide',
+    closable: true,
+    plain: true,
+    title: _('Add Connection'),
+    iconCls: 'x-deluge-add-window-icon',
+    items: [new Ext.form.FormPanel({
+               defaultType: 'textfield',
+               id: 'connectionAddForm',
+               baseCls: 'x-plain',
+               labelWidth: 55,
+               items: [{
+                       fieldLabel: _('Host'),
+                       id: 'host',
+                       name: 'host',
+                       anchor: '100%',
+                       listeners: {}
+               },{
+                       fieldLabel: _('Port'),
+                       id: 'port',
+                       name: 'port',
+                       value: '58846',
+                       anchor: '100%',
+                       listeners: {}
+               },{
+                       fieldLabel: _('Username'),
+                       id: 'username',
+                       name: 'username',
+                       anchor: '100%',
+                       listeners: {}
+               },{
+                       fieldLabel: _('Password'),
+                       id: 'password',
+                       name: 'password',
+                       inputType: 'password',
+                       anchor: '100%',
+                       listeners: {}
+               }]
+       })],
+    buttons: [{
+        text: _('Close')
+    },{
+        text: _('Add'),
+               handler: Deluge.Connections.onAddHost
+    }]
+});
+
 Deluge.Connections.Window = new Ext.Window({
     layout: 'fit',
     width: 300,

Modified: trunk/deluge/ui/web/js/deluge-ui.js
===================================================================
--- trunk/deluge/ui/web/js/deluge-ui.js 2009-03-20 20:46:36 UTC (rev 4902)
+++ trunk/deluge/ui/web/js/deluge-ui.js 2009-03-20 22:36:58 UTC (rev 4903)
@@ -46,6 +46,7 @@
                });
 
                Deluge.Login.Window.show();
+               
                Deluge.Events.on("connect", this.onConnect.bindWithEvent(this));
                Deluge.Events.on("disconnect", 
this.onDisconnect.bindWithEvent(this));
                Deluge.Client = new JSON.RPC('/json');

Modified: trunk/deluge/ui/web/json_api.py
===================================================================
--- trunk/deluge/ui/web/json_api.py     2009-03-20 20:46:36 UTC (rev 4902)
+++ trunk/deluge/ui/web/json_api.py     2009-03-20 22:36:58 UTC (rev 4903)
@@ -432,6 +432,12 @@
     
     @export
     def stop_daemon(self, connection_id):
+        """
+        Stops a running daemon.
+
+        :param connection_Id: str, the hash id of the connection
+
+        """
         main_deferred = Deferred()
         host = self.get_host(connection_id)
         if not host:
@@ -456,4 +462,48 @@
             d.addErrback(on_connect_failed)
         except:
             main_deferred.callback((False, "An error occured"))
-        return main_deferred
\ No newline at end of file
+        return main_deferred
+    
+    @export
+    def add_host(self, host, port, username="", password=""):
+        """
+        Adds a host to the list.
+
+        :param host: str, the hostname
+        :param port: int, the port
+        :param username: str, the username to login as
+        :param password: str, the password to login with
+
+        """
+        d = Deferred()
+        # Check to see if there is already an entry for this host and return
+        # if thats the case
+        for entry in self.host_list["hosts"]:
+            if (entry[0], entry[1], entry[2]) == (host, port, username):
+                d.callback(False)
+        
+        # Host isn't in the list, so lets add it
+        connection_id = hashlib.sha1(str(time.time())).hexdigest()
+        self.host_list["hosts"].append([connection_id, host, port, username,
+            password])
+        self.host_list.save()
+        d.callback(True)
+        return d
+    
+    @export
+    def remove_host(self, connection_id):
+        """
+        Removes a host for the list
+
+        :param connection_Id: str, the hash id of the connection
+
+        """
+        d = Deferred()
+        host = self.get_host(connection_id)
+        if host is None:
+            d.callback(False)
+        
+        self.host_list["hosts"].remove(host)
+        self.host_list.save()
+        d.callback(True)
+        return d



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