From ac08425ee30b67081241d82ad5ab3d781a61f6e0 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 24 Nov 2007 01:38:17 +0000 Subject: [PATCH] Add remove torrent dialog. --- TODO | 1 - deluge/core/core.py | 4 +- deluge/core/torrentmanager.py | 24 ++++++- deluge/ui/client.py | 4 +- .../gtkui/glade/remove_torrent_dialog.glade | 66 ++++++++++++++----- deluge/ui/gtkui/menubar.py | 7 +- 6 files changed, 82 insertions(+), 24 deletions(-) diff --git a/TODO b/TODO index f93910f83..7a6176eb2 100644 --- a/TODO +++ b/TODO @@ -13,7 +13,6 @@ * Hide open folder if not localhost * Add classic/normal mode to preferences * Implement 'Classic' mode -* Add remove torrent dialog and ability to remove data * Tray tooltip * Add torrentfiles location config option * Add autoload folder diff --git a/deluge/core/core.py b/deluge/core/core.py index fa96b0bb8..bcd721f46 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -275,9 +275,9 @@ class Core( # Add the torrent to session return self.export_add_torrent_file(filename, save_path, filedump) - def export_remove_torrent(self, torrent_id): + def export_remove_torrent(self, torrent_id, remove_torrent, remove_data): log.debug("Removing torrent %s from the core.", torrent_id) - if self.torrents.remove(torrent_id): + if self.torrents.remove(torrent_id, remove_torrent, remove_data): # Run the plugin hooks for 'post_torrent_remove' self.plugins.run_post_torrent_remove(torrent_id) # Emit the torrent_removed signal diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 6bde4360b..c10e80e36 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -250,19 +250,39 @@ class TorrentManager: return filedump - def remove(self, torrent_id): + def remove(self, torrent_id, remove_torrent, remove_data): """Remove a torrent from the manager""" try: # Remove from libtorrent session - self.session.remove_torrent(self.torrents[torrent_id].handle, 0) + option = 0 + # Remove data if set + if remove_data: + option = 1 + self.session.remove_torrent(self.torrents[torrent_id].handle, + option) except (RuntimeError, KeyError), e: log.warning("Error removing torrent: %s", e) return False + # Remove the .torrent file if requested + if remove_torrent: + try: + torrent_file = os.path.join( + self.config["torrentfiles_location"], + self.torrents[torrent_id].filename) + os.remove(torrent_file) + except Exception, e: + log.warning("Unable to remove .torrent file: %s", e) + + # Remove the .fastresume if it exists + self.delete_fastresume(torrent_id) + + # Remove the torrent from deluge's session try: del self.torrents[torrent_id] except KeyError, ValueError: return False + # Save the session state self.save_state() return True diff --git a/deluge/ui/client.py b/deluge/ui/client.py index d8e2a133f..8f0ae6290 100644 --- a/deluge/ui/client.py +++ b/deluge/ui/client.py @@ -188,12 +188,12 @@ def add_torrent_url(torrent_url): else: log.warning("Invalid URL %s", torrent_url) -def remove_torrent(torrent_ids): +def remove_torrent(torrent_ids, remove_torrent=False, remove_data=False): """Removes torrent_ids from the core.. Expects a list of torrent_ids""" log.debug("Attempting to removing torrents: %s", torrent_ids) try: for torrent_id in torrent_ids: - get_core().remove_torrent(torrent_id) + get_core().remove_torrent(torrent_id, remove_torrent, remove_data) except (AttributeError, socket.error): set_core_uri(None) diff --git a/deluge/ui/gtkui/glade/remove_torrent_dialog.glade b/deluge/ui/gtkui/glade/remove_torrent_dialog.glade index 6591dba4d..5b1fb7f2d 100644 --- a/deluge/ui/gtkui/glade/remove_torrent_dialog.glade +++ b/deluge/ui/gtkui/glade/remove_torrent_dialog.glade @@ -1,11 +1,12 @@ - + + 350 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 5 - Remove Torrents + Remove Torrent False GTK_WIN_POS_CENTER_ON_PARENT GDK_WINDOW_TYPE_HINT_DIALOG @@ -30,7 +31,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK gtk-dialog-warning - 6 + 5 False @@ -41,7 +42,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - <big><b>Remove Torrents?</b></big> + <big><b>Remove Torrent(s)?</b></big> True @@ -57,28 +58,23 @@ - + True - True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Delete .torrent files - 0 - True False - False 1 - + True - True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Delete saved data - 0 - True + 0 + 10 + <b>Options</b> + True False @@ -86,6 +82,46 @@ 2 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 15 + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Delete .torrent file(s) + 0 + True + + + + + 3 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 15 + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Delete saved data + 0 + True + + + + + 4 + + False diff --git a/deluge/ui/gtkui/menubar.py b/deluge/ui/gtkui/menubar.py index 79a7851ae..c13c60955 100644 --- a/deluge/ui/gtkui/menubar.py +++ b/deluge/ui/gtkui/menubar.py @@ -191,8 +191,11 @@ class MenuBar(component.Component): def on_menuitem_remove_activate(self, data=None): log.debug("on_menuitem_remove_activate") - client.remove_torrent( - component.get("TorrentView").get_selected_torrents()) + from removetorrentdialog import RemoveTorrentDialog + RemoveTorrentDialog( + component.get("TorrentView").get_selected_torrents()).run() + #client.remove_torrent( + # component.get("TorrentView").get_selected_torrents()) def on_menuitem_recheck_activate(self, data=None): log.debug("on_menuitem_recheck_activate")