implement a basic add connection window
implement remove connection
This commit is contained in:
parent
504f2470ba
commit
f9f2a55d93
|
@ -383,7 +383,7 @@ Deluge.SideBar = {
|
|||
}
|
||||
}, 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
|
||||
|
|
|
@ -44,7 +44,33 @@ Deluge.Connections = {
|
|||
},
|
||||
|
||||
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) {
|
||||
|
@ -74,6 +100,26 @@ Deluge.Connections = {
|
|||
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 @@ Deluge.Connections.Grid = new Ext.grid.GridPanel({
|
|||
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.Grid = new Ext.grid.GridPanel({
|
|||
})
|
||||
});
|
||||
|
||||
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,
|
||||
|
|
|
@ -46,6 +46,7 @@ Deluge.Ui = {
|
|||
});
|
||||
|
||||
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');
|
||||
|
|
|
@ -432,6 +432,12 @@ class WebApi(JSONComponent):
|
|||
|
||||
@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 @@ class WebApi(JSONComponent):
|
|||
d.addErrback(on_connect_failed)
|
||||
except:
|
||||
main_deferred.callback((False, "An error occured"))
|
||||
return main_deferred
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue