make the stop daemon button actually stop the daemon
This commit is contained in:
parent
73d0023ef5
commit
9ca7634ec9
|
@ -26,6 +26,10 @@ Deluge.Connections = {
|
|||
Deluge.Events.fire('disconnect');
|
||||
},
|
||||
|
||||
onAdd: function(button, e) {
|
||||
//Deluge.Connections.Add.show();
|
||||
},
|
||||
|
||||
onClose: function(e) {
|
||||
$clear(Deluge.Connections.running);
|
||||
Deluge.Connections.Window.hide();
|
||||
|
@ -69,6 +73,24 @@ Deluge.Connections = {
|
|||
Deluge.Connections.runCheck();
|
||||
},
|
||||
|
||||
onStop: function(button, e) {
|
||||
var connection = Deluge.Connections.Grid.getSelectionModel().getSelected();
|
||||
Deluge.Client.web.stop_daemon(connection.id, {
|
||||
onSuccess: function(result) {
|
||||
if (!result[0]) {
|
||||
Ext.MessageBox.show({
|
||||
title: _('Error'),
|
||||
msg: result[1],
|
||||
buttons: Ext.MessageBox.OK,
|
||||
modal: false,
|
||||
icon: Ext.MessageBox.ERROR,
|
||||
iconCls: 'x-deluge-error'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
runCheck: function() {
|
||||
Deluge.Client.web.get_hosts({
|
||||
onSuccess: Deluge.Connections.onGetHosts
|
||||
|
@ -112,7 +134,8 @@ Deluge.Connections.Grid = new Ext.grid.GridPanel({
|
|||
id: 'add',
|
||||
cls: 'x-btn-text-icon',
|
||||
text: _('Add'),
|
||||
icon: '/icons/16/add.png'
|
||||
icon: '/icons/16/add.png',
|
||||
handler: Deluge.Connections.onAdd
|
||||
}, {
|
||||
id: 'remove',
|
||||
cls: 'x-btn-text-icon',
|
||||
|
@ -122,7 +145,8 @@ Deluge.Connections.Grid = new Ext.grid.GridPanel({
|
|||
id: 'stop',
|
||||
cls: 'x-btn-text-icon',
|
||||
text: _('Stop Daemon'),
|
||||
icon: '/icons/16/error.png'
|
||||
icon: '/icons/16/error.png',
|
||||
handler: Deluge.Connections.onStop
|
||||
}
|
||||
]
|
||||
})
|
||||
|
|
|
@ -258,6 +258,11 @@ class WebApi(JSONComponent):
|
|||
super(WebApi, self).__init__("Web")
|
||||
self.host_list = ConfigManager("hostlist.conf.1.2", DEFAULT_HOSTS)
|
||||
|
||||
def get_host(self, connection_id):
|
||||
for host in self.host_list["hosts"]:
|
||||
if host[0] == connection_id:
|
||||
return host
|
||||
|
||||
@export
|
||||
def connect(self, host_id):
|
||||
d = Deferred()
|
||||
|
@ -424,3 +429,31 @@ class WebApi(JSONComponent):
|
|||
d.addCallback(on_connect, c, host_id)
|
||||
d.addErrback(on_connect_failed, host_id)
|
||||
return main_deferred
|
||||
|
||||
@export
|
||||
def stop_daemon(self, connection_id):
|
||||
main_deferred = Deferred()
|
||||
host = self.get_host(connection_id)
|
||||
if not host:
|
||||
main_deferred.callback((False, _("Daemon doesn't exist")))
|
||||
return main_deferred
|
||||
|
||||
try:
|
||||
def on_connect(connected, c):
|
||||
if not connected:
|
||||
main_deferred.callback((False, _("Daemon not running")))
|
||||
return
|
||||
c.daemon.shutdown()
|
||||
main_deferred.callback((True, ))
|
||||
|
||||
def on_connect_failed(reason):
|
||||
main_deferred.callback((False, reason))
|
||||
|
||||
host, port, user, password = host[1:5]
|
||||
c = Client()
|
||||
d = c.connect(host, port, user, password)
|
||||
d.addCallback(on_connect, c)
|
||||
d.addErrback(on_connect_failed)
|
||||
except:
|
||||
main_deferred.callback((False, "An error occured"))
|
||||
return main_deferred
|
Loading…
Reference in New Issue