fixes bug #258 (again)
[enigma2.git] / SleepTimer.py
index 891cd2580fc75eb9475f2850e76157095b8d5756..221e8f0b29422826edeb3368fcf24bdd752d7a6d 100644 (file)
@@ -9,6 +9,10 @@ from Components.config import config, ConfigYesNo, ConfigSelection, ConfigSubsec
 from Screens.MessageBox import MessageBox
 import Screens.Standby
 
+config.SleepTimer = ConfigSubsection()
+config.SleepTimer.ask = ConfigYesNo(default = True)
+config.SleepTimer.action = ConfigSelection(default = "shutdown", choices = [("shutdown", _("shutdown")), ("standby", _("standby"))])
+
 class SleepTimerEntry(timer.TimerEntry):
        def __init__(self, begin):
                timer.TimerEntry.__init__(self, int(begin), int(begin))
@@ -45,29 +49,26 @@ class SleepTimerEntry(timer.TimerEntry):
                if answer is not None:
                        if answer and not Screens.Standby.inStandby:
                                Notifications.AddNotification(Screens.Standby.Standby)
-               
+
 class SleepTimer(timer.Timer):
        def __init__(self):
-               config.SleepTimer = ConfigSubsection()
-               config.SleepTimer.ask = ConfigYesNo(default = True)
-               config.SleepTimer.action = ConfigSelection(default = "shutdown", choices = [("shutdown", _("shutdown")), ("standby", _("standby"))])
-               
                timer.Timer.__init__(self)
                self.defaultTime = 30
-               
+
        def setSleepTime(self, sleeptime):
                self.clear()
                self.addTimerEntry(SleepTimerEntry(time.time() + 60 * sleeptime))
 
        def clear(self):
                self.timer_list = []
-               
+
        def getCurrentSleepTime(self):
-               if (self.getNextRecordingTime() == -1):
-                       return self.defaultTime
-               return int(math.ceil((self.getNextRecordingTime() - time.time()) / 60))
+               llen = len(self.timer_list)
+               idx = 0
+               while idx < llen:
+                       timer = self.timer_list[idx]
+                       return int(math.ceil((timer.begin - time.time()) / 60))
+               return self.defaultTime
 
        def isActive(self):
                return len(self.timer_list) > 0
-       
-       
\ No newline at end of file