disable ePyObject refcount debug by default
[enigma2.git] / SleepTimer.py
1 import timer
2 import time
3 import math
4
5 from enigma import quitMainloop
6
7 from Tools import Notifications
8
9 from Components.config import config, ConfigYesNo, ConfigSelection, ConfigSubsection
10
11 from Screens.MessageBox import MessageBox
12 from Screens.Standby import Standby
13
14 class SleepTimerEntry(timer.TimerEntry):
15         def __init__(self, begin):
16                 timer.TimerEntry.__init__(self, int(begin), int(begin))
17                 
18                 self.prepare_time = 0
19                 
20         def getNextActivation(self):
21                 return self.begin
22                 
23         def activate(self):
24                 if self.state == self.StateRunning:
25                         if config.SleepTimer.action.value == "shutdown":
26                                 if config.SleepTimer.ask.value:
27                                         Notifications.AddNotificationWithCallback(self.shutdown, MessageBox, _("A sleep timer want's to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
28                                 else:
29                                         self.shutdown(True)
30                         elif config.SleepTimer.action.value == "standby":
31                                 if config.SleepTimer.ask.value:
32                                         Notifications.AddNotificationWithCallback(self.standby, MessageBox, _("A sleep timer want's to set your\nDreambox to standby. Do that now?"), timeout = 20)
33                                 else:
34                                         self.standby(True)
35
36                 return True
37                 
38         def shouldSkip(self):
39                 return False
40         
41         def shutdown(self, answer):
42                 if answer is not None:
43                         if answer:
44                                 quitMainloop(1)
45
46         def standby(self, answer):
47                 if answer is not None:
48                         if answer:
49                                 Notifications.AddNotification(Standby, self)
50                 
51 class SleepTimer(timer.Timer):
52         def __init__(self):
53                 config.SleepTimer = ConfigSubsection()
54                 config.SleepTimer.ask = ConfigYesNo(default = True)
55                 config.SleepTimer.action = ConfigSelection(default = "shutdown", choices = [("shutdown", _("shutdown")), ("standby", _("standby"))])
56                 
57                 timer.Timer.__init__(self)
58                 self.defaultTime = 30
59                 
60         def setSleepTime(self, sleeptime):
61                 self.clear()
62                 self.addTimerEntry(SleepTimerEntry(time.time() + 60 * sleeptime))
63
64         def clear(self):
65                 self.timer_list = []
66                 
67         def getCurrentSleepTime(self):
68                 if (self.getNextRecordingTime() == -1):
69                         return self.defaultTime
70                 return int(math.ceil((self.getNextRecordingTime() - time.time()) / 60))
71
72         def isActive(self):
73                 return len(self.timer_list) > 0
74         
75