Add Screensaver that currently appears when services are paused
[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                 self.onChangedEntry = [ ]
18
19                 self["key_red"] = StaticText(_("Cancel"))
20                 self["key_green"] = StaticText(_("Save"))
21                 self["description"] = Label("")
22
23                 self.list = []
24                 self.list.append(getConfigListEntry(_("Sleeptimer"),
25                         config.usage.sleep_timer,
26                         _("Configure the duration in minutes and action (shut down or standby) for the sleeptimer. Select this entry and click OK or green to start/stop the sleeptimer")))
27                 self.list.append(getConfigListEntry(_("Action when receiver is not controlled"),
28                         config.usage.inactivity_timer,
29                         _("Configure the duration in hours and action (shut down or standby) when the receiver is not controlled.")))
30                 self.list.append(getConfigListEntry(_("Screensaver"),
31                         config.usage.screen_saver,
32                         _("Configure the duration in minutes for the screensaver")))
33
34                 ConfigListScreen.__init__(self, self.list, session = session)
35                 
36                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
37                 {
38                     "green": self.ok,
39                     "red": self.cancel,
40                     "cancel": self.cancel,
41                     "ok": self.ok,
42                 }, -2)
43
44                 self.onLayoutFinish.append(self.layoutFinished)
45
46         def layoutFinished(self):
47                 self.setTitle(self.setup_title)
48
49         def ok(self):
50                 config.usage.sleep_timer.save()
51                 config.usage.inactivity_timer.save()
52                 if self.getCurrentEntry() == _("Sleeptimer"):
53                         sleepTimer = config.usage.sleep_timer.value
54                         if sleepTimer == "event_shutdown":
55                                 sleepTimer = -self.currentEventTime()
56                         elif sleepTimer == "event_standby":
57                                 sleepTimer = self.currentEventTime()
58                         else:
59                                 sleepTimer = int(sleepTimer)
60                         InfoBar.instance.setSleepTimer(sleepTimer)
61                         self.close(True)
62                 self.close()
63
64         def cancel(self, answer = None):
65                 if answer is None:
66                         if self["config"].isChanged():
67                                 self.session.openWithCallback(self.cancel, MessageBox, _("Really close without saving settings?"))
68                         else:
69                                 self.close()
70                 elif answer:
71                         for x in self["config"].list:
72                                 x[1].cancel()
73                         self.close()
74
75         def getCurrentEntry(self):
76                 return self["config"].getCurrent()[0]
77
78         def getCurrentValue(self):
79                 return str(self["config"].getCurrent()[1].getText())
80
81         def getCurrentDescription(self):
82                 return self["config"].getCurrent() and len(self["config"].getCurrent()) > 2 and self["config"].getCurrent()[2] or ""
83
84         def createSummary(self):
85                 from Screens.Setup import SetupSummary
86                 return SetupSummary
87
88         def currentEventTime(self):
89                 remaining = 0
90                 ref = self.session.nav.getCurrentlyPlayingServiceOrGroup()
91                 if ref:
92                         path = ref.getPath()
93                         if path: # Movie
94                                 service = self.session.nav.getCurrentService()
95                                 seek = service and service.seek()
96                                 if seek:
97                                         length = seek.getLength()
98                                         position = seek.getPlayPosition()
99                                         if length and position:
100                                                 remaining = length[1] - position[1]
101                                                 if remaining > 0:
102                                                         remaining = remaining / 90000
103                         else: # DVB
104                                 epg = eEPGCache.getInstance()
105                                 event = epg.lookupEventTime(ref, -1, 0)
106                                 if event:
107                                         now = int(time())
108                                         start = event.getBeginTime()
109                                         duration = event.getDuration()
110                                         end = start + duration
111                                         remaining = end - now
112                 return remaining + config.recording.margin_after.value * 60