diff --git a/deluge/ui/web/js/deluge-connections.js b/deluge/ui/web/js/deluge-connections.js index 5334ba685..358967f4c 100644 --- a/deluge/ui/web/js/deluge-connections.js +++ b/deluge/ui/web/js/deluge-connections.js @@ -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 } ] }) diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py index 72dec31e5..1d1f4cf1b 100644 --- a/deluge/ui/web/json_api.py +++ b/deluge/ui/web/json_api.py @@ -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() @@ -423,4 +428,32 @@ class WebApi(JSONComponent): d = c.connect(host, port, user, password) 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 \ No newline at end of file