From 5b87af0e46e00ff87a0ff8e080e7d2010cd8bc80 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 2 May 2009 02:07:11 +0000 Subject: [PATCH] Fix per-torrent move on completed stuff - patch from Plisk --- deluge/core/core.py | 8 ++++---- deluge/core/torrent.py | 7 +++++++ deluge/core/torrentmanager.py | 15 ++++++++++++--- deluge/ui/gtkui/options_tab.py | 14 +++++++------- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/deluge/core/core.py b/deluge/core/core.py index b247dff92..b659c1386 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -564,14 +564,14 @@ class Core(component.Component): return self.torrentmanager[torrent_id].set_remove_at_ratio(value) @export - def set_torrent_move_on_completed(self, torrent_id, value): + def set_torrent_move_completed(self, torrent_id, value): """Sets the torrent to be moved when completed""" - return self.torrentmanager[torrent_id].set_move_on_completed(value) + return self.torrentmanager[torrent_id].set_move_completed(value) @export - def set_torrent_move_on_completed_path(self, torrent_id, value): + def set_torrent_move_completed_path(self, torrent_id, value): """Sets the path for the torrent to be moved when completed""" - return self.torrentmanager[torrent_id].set_move_on_completed_path(value) + return self.torrentmanager[torrent_id].set_move_completed_path(value) @export def block_ip_range(self, range): diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 829e993d1..927cc4375 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -180,6 +180,7 @@ class Torrent: # Various torrent options self.handle.resolve_countries(True) + self.set_options(self.options) # Status message holds error info about the torrent @@ -272,6 +273,12 @@ class Torrent: def set_remove_at_ratio(self, remove_at_ratio): self.options["remove_at_ratio"] = remove_at_ratio + def set_move_completed(self, move_completed): + self.options["move_completed"] = move_completed + + def set_move_completed_path(self, move_completed_path): + self.options["move_completed_path"] = move_completed_path + def set_file_priorities(self, file_priorities): if len(file_priorities) != len(self.files): log.debug("file_priorities len != num_files") diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 1eed23ea7..d0983b3d6 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -73,6 +73,8 @@ class TorrentState: stop_ratio=2.00, stop_at_ratio=False, remove_at_ratio=False, + move_completed=False, + move_completed_path=None, magnet=None, time_added=-1 ): @@ -99,6 +101,8 @@ class TorrentState: self.stop_ratio = stop_ratio self.stop_at_ratio = stop_at_ratio self.remove_at_ratio = remove_at_ratio + self.move_completed = move_completed + self.move_completed_path = move_completed_path class TorrentManagerState: def __init__(self): @@ -296,6 +300,8 @@ class TorrentManager(component.Component): options["compact_allocation"] = state.compact options["download_location"] = state.save_path options["auto_managed"] = state.auto_managed + options["move_completed"] = state.move_completed + options["move_completed_path"] = state.move_completed_path options["add_paused"] = state.paused if not state.magnet: @@ -477,10 +483,11 @@ class TorrentManager(component.Component): # Try to use an old state try: - if dir(state.torrents[0]) != dir(TorrentState()): - for attr in (set(dir(TorrentState())) - set(dir(state.torrents[0]))): + state_tmp = TorrentState() + if dir(state.torrents[0]) != dir(state_tmp): + for attr in (set(dir(state_tmp)) - set(dir(state.torrents[0]))): for s in state.torrents: - setattr(s, attr, getattr(TorrentState(), attr, None)) + setattr(s, attr, getattr(state_tmp, attr, None)) except Exception, e: log.warning("Unable to update state file to a compatible version: %s", e) @@ -533,6 +540,8 @@ class TorrentManager(component.Component): torrent.options["stop_ratio"], torrent.options["stop_at_ratio"], torrent.options["remove_at_ratio"], + torrent.options["move_completed"], + torrent.options["move_completed_path"], torrent.magnet, torrent.time_added ) diff --git a/deluge/ui/gtkui/options_tab.py b/deluge/ui/gtkui/options_tab.py index a687bdea9..1f1d0200c 100644 --- a/deluge/ui/gtkui/options_tab.py +++ b/deluge/ui/gtkui/options_tab.py @@ -165,13 +165,13 @@ class OptionsTab(Tab): if self.chk_remove_at_ratio.get_active() != self.prev_status["remove_at_ratio"]: client.core.set_torrent_remove_at_ratio(self.prev_torrent_id, self.chk_remove_at_ratio.get_active()) if self.chk_move_completed.get_active() != self.prev_status["move_on_completed"]: - client.core.set_torrent_move_on_completed(self.prev_torrent_id, self.chk_move_completed.get_active()) - if self.chk_move_completed.get_active(): - if client.is_localhost(): - path = self.filechooser_move_completed.get_current_folder() - else: - path = self.entry_move_completed.get_text() - client.core.set_torrent_move_on_completed_path(self.prev_torrent_id, path) + client.core.set_torrent_move_completed(self.prev_torrent_id, self.chk_move_completed.get_active()) + if self.chk_move_completed.get_active(): + if client.is_localhost(): + path = self.filechooser_move_completed.get_current_folder() + else: + path = self.entry_move_completed.get_text() + client.core.set_torrent_move_completed_path(self.prev_torrent_id, path) def _on_button_edit_trackers_clicked(self, button):