From 59349183631779192ca7992b952e8bea378a254d Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Tue, 17 Jun 2008 00:56:10 +0000 Subject: [PATCH] Another attempt to fix #283 .. revamped how resuming/pausing is done --- deluge/core/torrent.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 9dfa6d343..46be72209 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -437,21 +437,29 @@ class Torrent: """Pause this torrent""" # Turn off auto-management so the torrent will not be unpaused by lt queueing self.handle.auto_managed(False) - - try: - self.handle.pause() - except Exception, e: - log.debug("Unable to pause torrent: %s", e) - return False + if self.handle.is_paused(): + # This torrent was probably paused due to being auto managed by lt + # Since we turned auto_managed off, we should update the state which should + # show it as 'Paused'. We need to emit a torrent_paused signal because + # the torrent_paused alert from libtorrent will not be generated. + self.update_state() + self.signals.emit("torrent_paused", self.torrent_id) + else: + try: + self.handle.pause() + except Exception, e: + log.debug("Unable to pause torrent: %s", e) + return False return True def resume(self): """Resumes this torrent""" - # Update the state first just to make sure we have the most current state - self.update_state() - - if self.state == "Paused" or self.state == "Error": + + if self.handle.is_paused() and self.handle.is_auto_managed(): + log.debug("Torrent is being auto-managed, cannot resume!") + return + else: # Reset the status message just in case of resuming an Error'd torrent self.set_status_message("OK")