implement disconnecting from a connected daemon

This commit is contained in:
Damien Churchill 2009-03-22 23:52:34 +00:00
parent a0e9fafb8f
commit 2193905fa6
2 changed files with 35 additions and 11 deletions

View File

@ -88,10 +88,18 @@ Deluge.Connections = {
},
onConnect: function(e) {
$clear(Deluge.Connections.running);
Deluge.Connections.Window.hide();
var selected = Deluge.Connections.Grid.getSelectionModel().getSelected();
if (!selected) return;
if (selected.get('status') == _('Connected')) {
Deluge.Client.web.disconnect({
onSuccess: function(result) {
Deluge.Connections.runCheck();
Deluge.Events.fire('disconnect');
}
});
} else {
var id = selected.id;
Deluge.Client.web.connect(id, {
onSuccess: function(methods) {
@ -101,6 +109,9 @@ Deluge.Connections = {
Deluge.Events.fire('connect');
}
});
$clear(Deluge.Connections.running);
Deluge.Connections.Window.hide();
}
},
onGetHosts: function(hosts) {
@ -131,6 +142,12 @@ Deluge.Connections = {
onSelect: function(selModel, rowIndex, record) {
Deluge.Connections.selectedRow = rowIndex;
var button = Deluge.Connections.Window.buttons[1];
if (record.get('status') == _('Connected')) {
button.setText(_('Disconnect'));
} else {
button.setText(_('Connect'));
}
},
onShow: function(window) {

View File

@ -281,6 +281,13 @@ class WebApi(JSONComponent):
d.callback(client.connected())
return d
@export
def disconnect(self):
d = Deferred()
client.disconnect()
d.callback(True)
return d
@export
def update_ui(self, keys, filter_dict):