diff --git a/deluge/ui/web/js/deluge-connections.js b/deluge/ui/web/js/deluge-connections.js index 51b15fad7..899595474 100644 --- a/deluge/ui/web/js/deluge-connections.js +++ b/deluge/ui/web/js/deluge-connections.js @@ -1,11 +1,28 @@ Deluge.Connections = { onClose: function(e) { $clear(Deluge.Connections.running); + Deluge.Connections.Window.hide(); }, onConnect: function(e) { + $clear(Deluge.Connections.running); + Deluge.Connections.Window.hide(); + var selected = Deluge.Connections.Grid.getSelectionModel().getSelected(); + var id = selected.id; + Deluge.Client.web.connect(id, { + onSuccess: function(methods) { + Deluge.Client = new JSON.RPC('/json', { + methods: methods + }); + Deluge.Ui.run(); + } + }); }, + onSelect: function(selModel, rowIndex, record) { + Deluge.Connections.selectedRow = rowIndex; + }, + onShow: function(window) { Deluge.Connections.running = Deluge.Connections.runCheck.periodical(2000); Deluge.Connections.runCheck(); @@ -19,6 +36,8 @@ Deluge.Connections = { onGetHosts: function(hosts) { Deluge.Connections.Store.loadData(hosts); + var selection = Deluge.Connections.Grid.getSelectionModel(); + selection.selectRow(Deluge.Connections.selectedRow); } } @@ -28,7 +47,8 @@ Deluge.Connections.Store = new Ext.data.SimpleStore({ {name: 'host', mapping: 1}, {name: 'port', mapping: 2}, {name: 'version', mapping: 6} - ] + ], + id: 0 }); var renderHost = function(value, p, r) { @@ -44,6 +64,10 @@ Deluge.Connections.Grid = new Ext.grid.GridPanel({ {header: "Version", width: 75, sortable: true, renderer: Deluge.Formatters.plain, dataIndex: 'version'} ], stripeRows: true, + selModel: new Ext.grid.RowSelectionModel({ + singleSelect: true, + listeners: {'rowselect': Deluge.Connections.onSelect} + }), autoExpandColumn: 'host', deferredRender:false, autoScroll:true, @@ -69,6 +93,7 @@ Deluge.Connections.Window = new Ext.Window({ handler: Deluge.Connections.onConnect }], listeners: { + 'hide': Deluge.Connections.onClose, 'show': Deluge.Connections.onShow } }); \ No newline at end of file diff --git a/deluge/ui/web/js/deluge-ui.js b/deluge/ui/web/js/deluge-ui.js index 96e8ce261..6e994bbe3 100644 --- a/deluge/ui/web/js/deluge-ui.js +++ b/deluge/ui/web/js/deluge-ui.js @@ -67,7 +67,7 @@ Deluge.Ui = { ]); }); Deluge.Torrents.store.loadData(torrents); - this.updateStatusBar(data['stats']); + //this.updateStatusBar(data['stats']); this.errorCount = 0; }, diff --git a/deluge/ui/web/server.py b/deluge/ui/web/server.py index 663ee6da5..90e78a8d2 100644 --- a/deluge/ui/web/server.py +++ b/deluge/ui/web/server.py @@ -146,7 +146,8 @@ class JSON(resource.Resource): "web.get_torrent_info": self.get_torrent_info, "web.add_torrents": self.add_torrents, "web.login": self.login, - "web.get_hosts": self.get_hosts + "web.get_hosts": self.get_hosts, + "web.connect": self.connect } for entry in open(common.get_default_config_dir("auth")): parts = entry.split(":") @@ -160,19 +161,23 @@ class JSON(resource.Resource): self.local_username = username self.local_password = password - def connect(self, host="localhost", port=58846, username=None, password=None): + def _connect(self, host="localhost", port=58846, username=None, password=None): """ Connects the client to a daemon """ username = username or self.local_username password = password or self.local_password - d = client.connect(host=host, username=username, password=password) + d = Deferred() + _d = client.connect(host=host, username=username, password=password) def on_get_methods(methods): """ Handles receiving the method names """ self._remote_methods = methods + methods = list(self._remote_methods) + methods.extend(self._local_methods) + d.callback(methods) def on_client_connected(connection_id): """ @@ -181,7 +186,8 @@ class JSON(resource.Resource): """ d = client.daemon.get_method_list() d.addCallback(on_get_methods) - d.addCallback(on_client_connected) + _d.addCallback(on_client_connected) + return d def _exec_local(self, method, params): """ @@ -294,6 +300,16 @@ class JSON(resource.Resource): except Exception, e: return self._on_json_request_failed(e, request) + def connect(self, host_id): + d = Deferred() + def on_connected(methods): + d.callback(methods) + for host in hostlist["hosts"]: + if host_id != host[0]: + continue + self._connect(*host[1:]).addCallback(on_connected) + return d + def update_ui(self, keys, filter_dict, cache_id=None): ui_info = { @@ -406,7 +422,7 @@ class JSON(resource.Resource): d.addErrback(on_info_fail, c) def on_connect_failed(reason, host_id): - print reason + log.exception(reason) hosts[host_id][5] = _("Offline") run_check()