mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
Add pausing and resuming of components. This stops the update() timer
for the component and restarts it upon resume.
This commit is contained in:
parent
26b8fcf086
commit
f1808a0cc3
2 changed files with 57 additions and 11 deletions
|
@ -36,7 +36,8 @@ from deluge.log import LOG as log
|
||||||
|
|
||||||
COMPONENT_STATE = [
|
COMPONENT_STATE = [
|
||||||
"Stopped",
|
"Stopped",
|
||||||
"Started"
|
"Started",
|
||||||
|
"Paused"
|
||||||
]
|
]
|
||||||
|
|
||||||
class Component:
|
class Component:
|
||||||
|
@ -67,7 +68,17 @@ class Component:
|
||||||
gobject.source_remove(self._timer)
|
gobject.source_remove(self._timer)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def _pause(self):
|
||||||
|
self._state = COMPONENT_STATE.index("Paused")
|
||||||
|
try:
|
||||||
|
gobject.source_remove(self._timer)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _resume(self):
|
||||||
|
self._start()
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -126,7 +137,28 @@ class ComponentRegistry:
|
||||||
log.debug("Stopping component %s..", component)
|
log.debug("Stopping component %s..", component)
|
||||||
self.components[component].stop()
|
self.components[component].stop()
|
||||||
self.components[component]._stop()
|
self.components[component]._stop()
|
||||||
|
|
||||||
|
def pause(self):
|
||||||
|
"""Pauses all components. Stops calling update()"""
|
||||||
|
for component in self.components.keys():
|
||||||
|
self.pause_component(component)
|
||||||
|
|
||||||
|
def pause_component(self, component):
|
||||||
|
if self.components[component].get_state() not in \
|
||||||
|
[COMPONENT_STATE.index("Paused"), COMPONENT_STATE.index("Stopped")]:
|
||||||
|
log.debug("Pausing component %s..", component)
|
||||||
|
self.components[component]._pause()
|
||||||
|
|
||||||
|
def resume(self):
|
||||||
|
"""Resumes all components. Starts calling update()"""
|
||||||
|
for component in self.components.keys():
|
||||||
|
self.resume_component(component)
|
||||||
|
|
||||||
|
def resume_component(self, component):
|
||||||
|
if self.components[component].get_state() == COMPONENT_STATE.index("Paused"):
|
||||||
|
log.debug("Resuming component %s..", component)
|
||||||
|
self.components[component]._resume()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Updates all components"""
|
"""Updates all components"""
|
||||||
for component in self.components.keys():
|
for component in self.components.keys():
|
||||||
|
@ -170,6 +202,20 @@ def stop(component=None):
|
||||||
else:
|
else:
|
||||||
_ComponentRegistry.stop_component(component)
|
_ComponentRegistry.stop_component(component)
|
||||||
|
|
||||||
|
def pause(component=None):
|
||||||
|
"""Pauses all or specificed components"""
|
||||||
|
if component == None:
|
||||||
|
_ComponentRegistry.pause()
|
||||||
|
else:
|
||||||
|
_ComponentRegistry.pause_component(component)
|
||||||
|
|
||||||
|
def resume(component=None):
|
||||||
|
"""Resumes all or specificed components"""
|
||||||
|
if component == None:
|
||||||
|
_ComponentRegistry.resume()
|
||||||
|
else:
|
||||||
|
_ComponentRegistry.resume_component(component)
|
||||||
|
|
||||||
def update():
|
def update():
|
||||||
"""Updates all components"""
|
"""Updates all components"""
|
||||||
_ComponentRegistry.update()
|
_ComponentRegistry.update()
|
||||||
|
|
|
@ -78,8 +78,8 @@ class MainWindow(component.Component):
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
try:
|
try:
|
||||||
component.start("TorrentView")
|
component.resume("TorrentView")
|
||||||
component.start("StatusBar")
|
component.resume("StatusBar")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -88,8 +88,8 @@ class MainWindow(component.Component):
|
||||||
self.window.show()
|
self.window.show()
|
||||||
|
|
||||||
def hide(self):
|
def hide(self):
|
||||||
component.stop("TorrentView")
|
component.pause("TorrentView")
|
||||||
component.stop("StatusBar")
|
component.pause("StatusBar")
|
||||||
self.window.hide()
|
self.window.hide()
|
||||||
|
|
||||||
def present(self):
|
def present(self):
|
||||||
|
@ -135,14 +135,14 @@ class MainWindow(component.Component):
|
||||||
if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED:
|
if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED:
|
||||||
if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED:
|
if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED:
|
||||||
log.debug("MainWindow is minimized..")
|
log.debug("MainWindow is minimized..")
|
||||||
component.stop("TorrentView")
|
component.pause("TorrentView")
|
||||||
component.stop("StatusBar")
|
component.pause("StatusBar")
|
||||||
self.is_minimized = True
|
self.is_minimized = True
|
||||||
else:
|
else:
|
||||||
log.debug("MainWindow is not minimized..")
|
log.debug("MainWindow is not minimized..")
|
||||||
try:
|
try:
|
||||||
component.start("TorrentView")
|
component.resume("TorrentView")
|
||||||
component.start("StatusBar")
|
component.resume("StatusBar")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self.is_minimized = False
|
self.is_minimized = False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue