more improvements to the connection manager, ui actually starts running after a connect now.

This commit is contained in:
Damien Churchill 2009-02-16 23:27:12 +00:00
parent b6dee74dd5
commit 1ff29a134c
3 changed files with 48 additions and 7 deletions

View File

@ -1,9 +1,26 @@
Deluge.Connections = { Deluge.Connections = {
onClose: function(e) { onClose: function(e) {
$clear(Deluge.Connections.running); $clear(Deluge.Connections.running);
Deluge.Connections.Window.hide();
}, },
onConnect: function(e) { 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) { onShow: function(window) {
@ -19,6 +36,8 @@ Deluge.Connections = {
onGetHosts: function(hosts) { onGetHosts: function(hosts) {
Deluge.Connections.Store.loadData(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: 'host', mapping: 1},
{name: 'port', mapping: 2}, {name: 'port', mapping: 2},
{name: 'version', mapping: 6} {name: 'version', mapping: 6}
] ],
id: 0
}); });
var renderHost = function(value, p, r) { 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'} {header: "Version", width: 75, sortable: true, renderer: Deluge.Formatters.plain, dataIndex: 'version'}
], ],
stripeRows: true, stripeRows: true,
selModel: new Ext.grid.RowSelectionModel({
singleSelect: true,
listeners: {'rowselect': Deluge.Connections.onSelect}
}),
autoExpandColumn: 'host', autoExpandColumn: 'host',
deferredRender:false, deferredRender:false,
autoScroll:true, autoScroll:true,
@ -69,6 +93,7 @@ Deluge.Connections.Window = new Ext.Window({
handler: Deluge.Connections.onConnect handler: Deluge.Connections.onConnect
}], }],
listeners: { listeners: {
'hide': Deluge.Connections.onClose,
'show': Deluge.Connections.onShow 'show': Deluge.Connections.onShow
} }
}); });

View File

@ -67,7 +67,7 @@ Deluge.Ui = {
]); ]);
}); });
Deluge.Torrents.store.loadData(torrents); Deluge.Torrents.store.loadData(torrents);
this.updateStatusBar(data['stats']); //this.updateStatusBar(data['stats']);
this.errorCount = 0; this.errorCount = 0;
}, },

View File

@ -146,7 +146,8 @@ class JSON(resource.Resource):
"web.get_torrent_info": self.get_torrent_info, "web.get_torrent_info": self.get_torrent_info,
"web.add_torrents": self.add_torrents, "web.add_torrents": self.add_torrents,
"web.login": self.login, "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")): for entry in open(common.get_default_config_dir("auth")):
parts = entry.split(":") parts = entry.split(":")
@ -160,19 +161,23 @@ class JSON(resource.Resource):
self.local_username = username self.local_username = username
self.local_password = password 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 Connects the client to a daemon
""" """
username = username or self.local_username username = username or self.local_username
password = password or self.local_password 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): def on_get_methods(methods):
""" """
Handles receiving the method names Handles receiving the method names
""" """
self._remote_methods = methods self._remote_methods = methods
methods = list(self._remote_methods)
methods.extend(self._local_methods)
d.callback(methods)
def on_client_connected(connection_id): def on_client_connected(connection_id):
""" """
@ -181,7 +186,8 @@ class JSON(resource.Resource):
""" """
d = client.daemon.get_method_list() d = client.daemon.get_method_list()
d.addCallback(on_get_methods) d.addCallback(on_get_methods)
d.addCallback(on_client_connected) _d.addCallback(on_client_connected)
return d
def _exec_local(self, method, params): def _exec_local(self, method, params):
""" """
@ -294,6 +300,16 @@ class JSON(resource.Resource):
except Exception, e: except Exception, e:
return self._on_json_request_failed(e, request) 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): def update_ui(self, keys, filter_dict, cache_id=None):
ui_info = { ui_info = {
@ -406,7 +422,7 @@ class JSON(resource.Resource):
d.addErrback(on_info_fail, c) d.addErrback(on_info_fail, c)
def on_connect_failed(reason, host_id): def on_connect_failed(reason, host_id):
print reason log.exception(reason)
hosts[host_id][5] = _("Offline") hosts[host_id][5] = _("Offline")
run_check() run_check()