From faf3f963222b1438aea847883b0c62df7642c33d Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Wed, 3 Dec 2014 16:34:24 +0000 Subject: [PATCH] [#2250] [WebUI] [Console] Use new core.remove_torrents method --- deluge/ui/console/commands/rm.py | 10 ++++- deluge/ui/console/modes/torrent_actions.py | 16 +++++-- deluge/ui/web/js/deluge-all/RemoveWindow.js | 46 ++++++++++----------- deluge/ui/web/js/deluge-all/TorrentGrid.js | 4 +- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/deluge/ui/console/commands/rm.py b/deluge/ui/console/commands/rm.py index 0a6e7ccd8..82e8331c6 100644 --- a/deluge/ui/console/commands/rm.py +++ b/deluge/ui/console/commands/rm.py @@ -34,8 +34,14 @@ class Command(BaseCommand): for arg in args: torrent_ids.extend(self.console.match_torrent(arg)) - for torrent_id in torrent_ids: - client.core.remove_torrent(torrent_id, options["remove_data"]) + def on_removed_finished(errors): + if errors: + self.console.write("Error(s) occured when trying to delete torrent(s).") + for t_id, e_msg in errors: + self.console.write("Error removing torrent %s : %s" % (t_id, e_msg)) + + d = client.core.remove_torrents(torrent_ids, options["remove_data"]) + d.addCallback(on_removed_finished) def complete(self, line): # We use the ConsoleUI torrent tab complete method diff --git a/deluge/ui/console/modes/torrent_actions.py b/deluge/ui/console/modes/torrent_actions.py index f27c6b31a..108ee6d1b 100644 --- a/deluge/ui/console/modes/torrent_actions.py +++ b/deluge/ui/console/modes/torrent_actions.py @@ -146,10 +146,18 @@ def torrent_action(idx, data, mode, ids): return mode.clear_marks() - wd = data["remove_files"] - for tid in ids: - log.debug("Removing torrent: %s, %d", tid, wd) - client.core.remove_torrent(tid, wd).addErrback(action_error, mode) + remove_data = data["remove_files"] + + def on_removed_finished(errors): + if errors: + error_msgs = "" + for t_id, e_msg in errors: + error_msgs += "Error removing torrent %s : %s\n" % (t_id, e_msg) + mode.report_message("Error(s) occured when trying to delete torrent(s).", error_msgs) + mode.refresh() + + d = client.core.remove_torrents(ids, remove_data) + d.addCallback(on_removed_finished) def got_status(status): return (status["name"], status["state"]) diff --git a/deluge/ui/web/js/deluge-all/RemoveWindow.js b/deluge/ui/web/js/deluge-all/RemoveWindow.js index 43e872dd3..d40aa88af 100644 --- a/deluge/ui/web/js/deluge-all/RemoveWindow.js +++ b/deluge/ui/web/js/deluge-all/RemoveWindow.js @@ -1,6 +1,6 @@ /*! * Deluge.RemoveWindow.js - * + * * Copyright (c) Damien Churchill 2009-2010 * * This program is free software; you can redistribute it and/or modify @@ -35,61 +35,61 @@ * @extends Ext.Window */ Deluge.RemoveWindow = Ext.extend(Ext.Window, { - + title: _('Remove Torrent'), layout: 'fit', width: 350, height: 100, - + buttonAlign: 'right', closeAction: 'hide', closable: true, iconCls: 'x-deluge-remove-window-icon', plain: true, - + bodyStyle: 'padding: 5px; padding-left: 10px;', html: 'Are you sure you wish to remove the torrent (s)?', - + initComponent: function() { Deluge.RemoveWindow.superclass.initComponent.call(this); this.addButton(_('Cancel'), this.onCancel, this); this.addButton(_('Remove With Data'), this.onRemoveData, this); this.addButton(_('Remove Torrent'), this.onRemove, this); }, - + remove: function(removeData) { - Ext.each(this.torrentIds, function(torrentId) { - deluge.client.core.remove_torrent(torrentId, removeData, { - success: function() { - this.onRemoved(torrentId); - }, - scope: this, - torrentId: torrentId - }); - }, this); - + deluge.client.core.remove_torrents(this.torrentIds, removeData, { + success: function(result) { + if (result) { + console.log("Error(s) occured when trying to delete torrent(s)."); + } + this.onRemoved(this.torrentIds); + }, + scope: this, + torrentIds: this.torrentIds + }); }, - + show: function(ids) { Deluge.RemoveWindow.superclass.show.call(this); this.torrentIds = ids; }, - + onCancel: function() { this.hide(); this.torrentIds = null; }, - + onRemove: function() { this.remove(false); }, - + onRemoveData: function() { this.remove(true); }, - - onRemoved: function(torrentId) { - deluge.events.fire('torrentRemoved', torrentId); + + onRemoved: function(torrentIds) { + deluge.events.fire('torrentsRemoved', torrentIds); this.hide(); deluge.ui.update(); } diff --git a/deluge/ui/web/js/deluge-all/TorrentGrid.js b/deluge/ui/web/js/deluge-all/TorrentGrid.js index 9d43995e5..afb6bc2bf 100644 --- a/deluge/ui/web/js/deluge-all/TorrentGrid.js +++ b/deluge/ui/web/js/deluge-all/TorrentGrid.js @@ -347,7 +347,7 @@ initComponent: function() { Deluge.TorrentGrid.superclass.initComponent.call(this); - deluge.events.on('torrentRemoved', this.onTorrentRemoved, this); + deluge.events.on('torrentsRemoved', this.onTorrentsRemoved, this); deluge.events.on('disconnect', this.onDisconnect, this); this.on('rowcontextmenu', function(grid, rowIndex, e) { @@ -459,7 +459,7 @@ }, // private - onTorrentRemoved: function(torrentIds) { + onTorrentsRemoved: function(torrentIds) { var selModel = this.getSelectionModel(); Ext.each(torrentIds, function(torrentId) { var record = this.getStore().getById(torrentId);