fixes to scheduler from ben

This commit is contained in:
Marcos Pinto 2007-11-13 03:18:44 +00:00
parent c4c8539401
commit 97f2f244ae
1 changed files with 18 additions and 13 deletions

View File

@ -45,22 +45,23 @@ class plugin_Scheduler:
self.prevhour = now[3] self.prevhour = now[3]
self._state(self.status) self._state(self.status)
self.interface.apply_prefs()
def unload(self): def unload(self):
self.status = -1
self.resume() self.resume()
self.unlimit() self.unlimit()
def _getglobals(self): def _getglobals(self):
# Grab changes in global config # Only run if plugin is not paused
gdl = self.config.get("max_download_speed") if self.status < 2:
gul = self.config.get("max_upload_speed") gdl = self.config.get("max_download_speed")
if self.status == 0 and (self.dlmax != gdl or self.ulmax != gul): gul = self.config.get("max_upload_speed")
self.dlmax = gdl if self.status == 0 and (self.dlmax != gdl or self.ulmax != gul):
self.ulmax = gul self.dlmax = gdl
elif self.status == 1 and (self.dllimit != gdl or self.ullimit != gul): self.ulmax = gul
self.dllimit = gdl elif self.status == 1 and (self.dllimit != gdl or self.ullimit != gul):
self.ullimit = gul self.dllimit = gdl
self.ullimit = gul
def _state(self,state): def _state(self,state):
if state == 0: if state == 0:
@ -73,16 +74,21 @@ class plugin_Scheduler:
if state < 2 and self.status == 2: if state < 2 and self.status == 2:
self.resume() self.resume()
self.status = state self.status = state
# Update the settings
self.interface.apply_prefs()
def update(self): def update(self):
# Only do stuff if the status is valid
if self.status < 0:
return
# Apply any changes that have been made to the global config
self._getglobals() self._getglobals()
now = time.localtime(time.time()) now = time.localtime(time.time())
if now[3] != self.prevhour: if now[3] != self.prevhour:
self.prevhour = now[3] self.prevhour = now[3]
if not self.status == self.button_state[now[3]][now[6]]: if not self.status == self.button_state[now[3]][now[6]]:
self._state(self.button_state[now[3]][now[6]]) self._state(self.button_state[now[3]][now[6]])
self.interface.apply_prefs()
def pause(self): def pause(self):
self.prevact = self.config.get("max_active_torrents") self.prevact = self.config.get("max_active_torrents")
@ -227,7 +233,6 @@ class plugin_Scheduler:
now = time.localtime(time.time()) now = time.localtime(time.time())
self._state(self.button_state[now[3]][now[6]]) self._state(self.button_state[now[3]][now[6]])
self.interface.apply_prefs()
writer = open(self.conf_file, "wb") writer = open(self.conf_file, "wb")
pickle.dump([drawing.button_state,[self.dllimit, self.ullimit, self.dlmax, self.ulmax]], writer) pickle.dump([drawing.button_state,[self.dllimit, self.ullimit, self.dlmax, self.ulmax]], writer)