[#1330] [Core] Fix pausing and resuming session

* The paused state of torrents is now correctly stored on shutdown if the session is paused.
 * core.pause_all_torrents now uses libtorrent session.pause and resume_all_torrents also refreshes
   all torrents' state. This fixes only torrents that changed state being updated so queued torrents
   would be incorrectly displayed as paused.
 * Scheduler and Blocklist now use updated core methods rather than calling libtorrent directly.
This commit is contained in:
Calum Lind 2015-09-27 00:31:20 +01:00
parent eab7850ed6
commit 7315255831
4 changed files with 18 additions and 12 deletions

View File

@ -409,15 +409,18 @@ class Core(component.Component):
@export @export
def pause_all_torrents(self): def pause_all_torrents(self):
"""Pause all torrents in the session""" """Pause all torrents in the session"""
for torrent in self.torrentmanager.torrents.values(): if not self.session.is_paused():
torrent.pause() self.session.pause()
component.get("EventManager").emit(SessionPausedEvent())
@export @export
def resume_all_torrents(self): def resume_all_torrents(self):
"""Resume all torrents in the session""" """Resume all torrents in the session"""
for torrent in self.torrentmanager.torrents.values(): if self.session.is_paused():
torrent.resume() self.session.resume()
component.get("EventManager").emit(SessionResumedEvent()) for torrent in self.torrentmanager.torrents.values():
torrent.update_state()
component.get("EventManager").emit(SessionResumedEvent())
@export @export
def resume_torrent(self, torrent_ids): def resume_torrent(self, torrent_ids):

View File

@ -674,9 +674,12 @@ class TorrentManager(component.Component):
state = TorrentManagerState() state = TorrentManagerState()
# Create the state for each Torrent and append to the list # Create the state for each Torrent and append to the list
for torrent in self.torrents.values(): for torrent in self.torrents.values():
paused = False if self.session.is_paused():
if torrent.state == "Paused": paused = torrent.handle.is_paused()
elif torrent.state == "Paused":
paused = True paused = True
else:
paused = False
torrent_state = TorrentState( torrent_state = TorrentState(
torrent.torrent_id, torrent.torrent_id,

View File

@ -425,12 +425,12 @@ class Core(CorePluginBase):
def pause_session(self): def pause_session(self):
if not self.core.session.is_paused(): if not self.core.session.is_paused():
self.core.session.pause() self.core.pause_all_torrents()
self.need_to_resume_session = True self.need_to_resume_session = True
else: else:
self.need_to_resume_session = False self.need_to_resume_session = False
def resume_session(self, result): def resume_session(self, result):
self.core.session.resume() self.core.resume_all_torrents()
self.need_to_resume_session = False self.need_to_resume_session = False
return result return result

View File

@ -129,7 +129,7 @@ class Core(CorePluginBase):
for setting in CONTROLLED_SETTINGS: for setting in CONTROLLED_SETTINGS:
core_config.apply_set_functions(setting) core_config.apply_set_functions(setting)
# Resume the session if necessary # Resume the session if necessary
component.get("Core").session.resume() component.get("Core").resume_all_torrents()
def do_schedule(self, timer=True): def do_schedule(self, timer=True):
""" """
@ -153,10 +153,10 @@ class Core(CorePluginBase):
settings.active_seeds = self.config["low_active_up"] settings.active_seeds = self.config["low_active_up"]
session.set_settings(settings) session.set_settings(settings)
# Resume the session if necessary # Resume the session if necessary
component.get("Core").session.resume() component.get("Core").resume_all_torrents()
elif state == "Red": elif state == "Red":
# This is Red (Stop), so pause the libtorrent session # This is Red (Stop), so pause the libtorrent session
component.get("Core").session.pause() component.get("Core").pause_all_torrents()
if state != self.state: if state != self.state:
# The state has changed since last update so we need to emit an event # The state has changed since last update so we need to emit an event