Author: damoxc
Revision: 4897
Log:
make the stop daemon button actually stop the daemon
Diff:
Modified: trunk/deluge/ui/web/js/deluge-connections.js
===================================================================
--- trunk/deluge/ui/web/js/deluge-connections.js 2009-03-20 18:25:23 UTC
(rev 4896)
+++ trunk/deluge/ui/web/js/deluge-connections.js 2009-03-20 18:26:47 UTC
(rev 4897)
@@ -26,6 +26,10 @@
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.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 @@
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 @@
id: 'stop',
cls: 'x-btn-text-icon',
text: _('Stop Daemon'),
- icon: '/icons/16/error.png'
+ icon: '/icons/16/error.png',
+ handler: Deluge.Connections.onStop
}
]
})
Modified: trunk/deluge/ui/web/json_api.py
===================================================================
--- trunk/deluge/ui/web/json_api.py 2009-03-20 18:25:23 UTC (rev 4896)
+++ trunk/deluge/ui/web/json_api.py 2009-03-20 18:26:47 UTC (rev 4897)
@@ -258,6 +258,11 @@
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 @@
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---