Remove obsoleted inChangedEntry declaration
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / SleepTimerEdit.py
1 from Screens.InfoBar import InfoBar
2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Components.ActionMap import ActionMap
5 from Components.ConfigList import ConfigListScreen
6 from Components.Label import Label
7 from Components.Sources.StaticText import StaticText
8 from Components.config import config, getConfigListEntry
9 from enigma import eEPGCache
10 from time import time
11
12 class SleepTimerEdit(ConfigListScreen, Screen):
13         def __init__(self, session):
14                 Screen.__init__(self, session)
15                 self.skinName = ["SleepTimerSetup", "Setup"]
16                 self.setup_title = _("SleepTimer Configuration")
17
18                 self["key_red"] = StaticText(_("Cancel"))
19                 self["key_green"] = StaticText(_("Save"))
20                 self["description"] = Label("")
21
22                 self.list = []
23                 ConfigListScreen.__init__(self, self.list, session = session)
24                 self.createSetup()
25                 
26                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
27                 {
28                     "green": self.ok,
29                     "red": self.cancel,
30                     "cancel": self.cancel,
31                     "ok": self.ok,
32                 }, -2)
33
34                 self.onLayoutFinish.append(self.layoutFinished)
35
36         def layoutFinished(self):
37                 self.setTitle(self.setup_title)
38
39         def createSetup(self):
40                 self.list = []
41                 self.list.append(getConfigListEntry(_("Sleeptimer"),
42                         config.usage.sleep_timer,
43                         _("Configure the duration in minutes and action, which could be shut down or standby, for the sleeptimer. Select this entry and click OK or green to start/stop the sleeptimer")))
44                 self.list.append(getConfigListEntry(_("Inactivity Sleeptimer"),
45                         config.usage.inactivity_timer,
46                         _("Configure the duration in hours and action, which could be shut down or standby, when the receiver is not controlled.")))
47                 if int(config.usage.inactivity_timer.value):
48                         self.list.append(getConfigListEntry(_("Specify timeframe to ignore inactivity sleeptimer"),
49                                 config.usage.inactivity_timer_blocktime,
50                                 _("When enabled you can specify a timeframe were the inactivity sleeptimer is ignored. Not the detection is disabled during this timeframe but the inactivity timeout is disabled")))
51                         if config.usage.inactivity_timer_blocktime.value:
52                                 self.list.append(getConfigListEntry(_("Start time to ignore inactivity sleeptimer"),
53                                         config.usage.inactivity_timer_blocktime_begin,
54                                         _("Specify the start time when the inactivity sleeptimer should be ignored")))
55                                 self.list.append(getConfigListEntry(_("End time to ignore inactivity sleeptimer"),
56                                         config.usage.inactivity_timer_blocktime_end,
57                                         _("Specify the end time until the inactivity sleeptimer should be ignored")))
58                 self.list.append(getConfigListEntry(_("Shutdown when in Standby"),
59                         config.usage.standby_to_shutdown_timer,
60                         _("Configure the duration when the receiver should go to shut down in case the receiver is in standby mode.")))
61
62                 self["config"].list = self.list
63                 self["config"].l.setList(self.list)
64
65         def ok(self):
66                 config.usage.sleep_timer.save()
67                 config.usage.inactivity_timer.save()
68                 config.usage.inactivity_timer_blocktime.save()
69                 config.usage.inactivity_timer_blocktime_begin.save()
70                 config.usage.inactivity_timer_blocktime_end.save()
71                 config.usage.standby_to_shutdown_timer.save()
72                 if self.getCurrentEntry() == _("Sleeptimer"):
73                         sleepTimer = config.usage.sleep_timer.value
74                         if sleepTimer == "event_shutdown":
75                                 sleepTimer = -self.currentEventTime()
76                         elif sleepTimer == "event_standby":
77                                 sleepTimer = self.currentEventTime()
78                         else:
79                                 sleepTimer = int(sleepTimer)
80                         InfoBar.instance.setSleepTimer(sleepTimer)
81                         self.close(True)
82                 self.close()
83
84         def cancel(self, answer = None):
85                 if answer is None:
86                         if self["config"].isChanged():
87                                 self.session.openWithCallback(self.cancel, MessageBox, _("Really close without saving settings?"))
88                         else:
89                                 self.close()
90                 elif answer:
91                         for x in self["config"].list:
92                                 x[1].cancel()
93                         self.close()
94
95         def keyLeft(self):
96                 ConfigListScreen.keyLeft(self)
97                 self.createSetup()
98
99         def keyRight(self):
100                 ConfigListScreen.keyRight(self)
101                 self.createSetup()
102
103         def currentEventTime(self):
104                 remaining = 0
105                 ref = self.session.nav.getCurrentlyPlayingServiceOrGroup()
106                 if ref:
107                         path = ref.getPath()
108                         if path: # Movie
109                                 service = self.session.nav.getCurrentService()
110                                 seek = service and service.seek()
111                                 if seek:
112                                         length = seek.getLength()
113                                         position = seek.getPlayPosition()
114                                         if length and position:
115                                                 remaining = length[1] - position[1]
116                                                 if remaining > 0:
117                                                         remaining = remaining / 90000
118                         else: # DVB
119                                 epg = eEPGCache.getInstance()
120                                 event = epg.lookupEventTime(ref, -1, 0)
121                                 if event:
122                                         now = int(time())
123                                         start = event.getBeginTime()
124                                         duration = event.getDuration()
125                                         end = start + duration
126                                         remaining = end - now
127                 return remaining + config.recording.margin_after.value * 60