b298c5d870948f10da64056c1cc213dee47bcaf3
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / Standby.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.config import config
4 from Components.AVSwitch import AVSwitch
5 from Components.SystemInfo import SystemInfo
6 from Tools import Notifications
7 from GlobalActions import globalActionMap
8 import RecordTimer
9 from enigma import eDVBVolumecontrol, eTimer
10
11 inStandby = None
12
13 class Standby(Screen):
14         def Power(self):
15                 print "leave standby"
16                 #set input to encoder
17                 self.avswitch.setInput("ENCODER")
18                 #restart last played service
19                 #unmute adc
20                 self.leaveMute()
21                 #kill me
22                 self.close(True)
23
24         def setMute(self):
25                 if (eDVBVolumecontrol.getInstance().isMuted()):
26                         self.wasMuted = 1
27                         print "mute already active"
28                 else:
29                         self.wasMuted = 0
30                         eDVBVolumecontrol.getInstance().volumeToggleMute()
31
32         def leaveMute(self):
33                 if self.wasMuted == 0:
34                         eDVBVolumecontrol.getInstance().volumeToggleMute()
35
36         def __init__(self, session):
37                 Screen.__init__(self, session)
38                 self.avswitch = AVSwitch()
39
40                 print "enter standby"
41
42                 self["actions"] = ActionMap( [ "StandbyActions" ],
43                 {
44                         "power": self.Power,
45                         "discrete_on": self.Power
46                 }, -1)
47
48                 globalActionMap.setEnabled(False)
49
50                 #mute adc
51                 self.setMute()
52
53                 self.paused_service = None
54                 self.prev_running_service = None
55                 if self.session.current_dialog:
56                         if self.session.current_dialog.ALLOW_SUSPEND == Screen.SUSPEND_STOPS:
57                                 #get currently playing service reference
58                                 self.prev_running_service = self.session.nav.getCurrentlyPlayingServiceOrGroup()
59                                 #stop actual played dvb-service
60                                 self.session.nav.stopService()
61                         elif self.session.current_dialog.ALLOW_SUSPEND == Screen.SUSPEND_PAUSES:
62                                 self.paused_service = self.session.current_dialog
63                                 self.paused_service.pauseService()
64
65                 #set input to vcr scart
66                 if SystemInfo["ScartSwitch"]:
67                         self.avswitch.setInput("SCART")
68                 else:
69                         self.avswitch.setInput("AUX")
70
71                 gotoShutdownTime = int(config.usage.standby_to_shutdown_timer.value)
72                 if gotoShutdownTime:
73                         self.standbyTimeoutTimer = eTimer()
74                         self.standbyTimeoutTimer.callback.append(self.standbyTimeout)
75                         self.standbyTimeoutTimer.startLongTimer(gotoShutdownTime)
76
77                 self.onFirstExecBegin.append(self.__onFirstExecBegin)
78                 self.onClose.append(self.__onClose)
79
80         def __onClose(self):
81                 global inStandby
82                 inStandby = None
83                 if self.prev_running_service:
84                         self.session.nav.playService(self.prev_running_service)
85                 elif self.paused_service:
86                         self.paused_service.unPauseService()
87                 self.session.screen["Standby"].boolean = False
88                 globalActionMap.setEnabled(True)
89                 if RecordTimer.RecordTimerEntry.receiveRecordEvents:
90                         Notifications.RemovePopup(id = "RecordTimerQuitMainloop")
91                         RecordTimer.RecordTimerEntry.stopTryQuitMainloop()
92
93         def __onFirstExecBegin(self):
94                 global inStandby
95                 inStandby = self
96                 self.session.screen["Standby"].boolean = True
97                 config.misc.standbyCounter.value += 1
98
99         def createSummary(self):
100                 return StandbySummary
101
102         def standbyTimeout(self):
103                 from RecordTimer import RecordTimerEntry
104                 RecordTimerEntry.TryQuitMainloop(True)
105
106 class StandbySummary(Screen):
107         skin = """
108         <screen position="0,0" size="132,64">
109                 <widget source="global.CurrentTime" render="Label" position="0,0" size="132,64" font="Regular;40" halign="center">
110                         <convert type="ClockToText" />
111                 </widget>
112                 <widget source="session.RecordState" render="FixedLabel" text=" " position="0,0" size="132,64" zPosition="1" >
113                         <convert type="ConfigEntryTest">config.usage.blinking_display_clock_during_recording,True,CheckSourceBoolean</convert>
114                         <convert type="ConditionalShowHide">Blink</convert>
115                 </widget>
116         </screen>"""
117
118 from enigma import quitMainloop, iRecordableService
119 from Screens.MessageBox import MessageBox
120 from time import time
121 from Components.Task import job_manager
122
123 class QuitMainloopScreen(Screen):
124
125         def __init__(self, session, retvalue=1):
126                 self.skin = """<screen name="QuitMainloopScreen" position="fill" flags="wfNoBorder">
127                                 <ePixmap pixmap="skin_default/icons/input_info.png" position="c-27,c-60" size="53,53" alphatest="on" />
128                                 <widget name="text" position="center,c+5" size="720,100" font="Regular;22" halign="center" />
129                         </screen>"""
130                 Screen.__init__(self, session)
131                 from Components.Label import Label
132                 text = { 1: _("Your receiver is shutting down"),
133                         2: _("Your receiver is rebooting"),
134                         3: _("The user interface of your receiver is restarting"),
135                         4: _("Your frontprocessor will be upgraded\nPlease wait until your receiver reboots\nThis may take a few minutes"),
136                         5: _("The user interface of your receiver is restarting\ndue to an error in mytest.py"),
137                         42: _("Unattended upgrade in progress\nPlease wait until your receiver reboots\nThis may take a few minutes") }.get(retvalue)
138                 self["text"] = Label(text)
139
140 inTryQuitMainloop = False
141
142 class TryQuitMainloop(MessageBox):
143         def __init__(self, session, retvalue=1, timeout=-1, default_yes = False):
144                 self.retval = retvalue
145                 recordings = session.nav.getRecordings()
146                 jobs = len(job_manager.getPendingJobs())
147                 self.connected = False
148                 reason = ""
149                 next_rec_time = -1
150                 if not recordings:
151                         next_rec_time = session.nav.RecordTimer.getNextRecordingTime()
152                 if recordings or (next_rec_time > 0 and (next_rec_time - time()) < 360):
153                         reason = _("Recording(s) are in progress or coming up in few seconds!") + '\n'
154                 if jobs:
155                         if jobs == 1:
156                                 job = job_manager.getPendingJobs()[0]
157                                 reason += "%s: %s (%d%%)\n" % (job.getStatustext(), job.name, int(100*job.progress/float(job.end)))
158                         else:
159                                 reason += (ngettext("%d job is running in the background!", "%d jobs are running in the background!", jobs) % jobs) + '\n'
160                 if reason:
161                         text = { 1: _("Really shutdown now?"),
162                                 2: _("Really reboot now?"),
163                                 3: _("Really restart now?"),
164                                 4: _("Really upgrade the frontprocessor and reboot now?"),
165                                 42: _("Really upgrade your settop box and reboot now?") }.get(retvalue)
166                         if text:
167                                 MessageBox.__init__(self, session, reason+text, type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes)
168                                 self.skinName = "MessageBoxSimple"
169                                 session.nav.record_event.append(self.getRecordEvent)
170                                 self.connected = True
171                                 self.onShow.append(self.__onShow)
172                                 self.onHide.append(self.__onHide)
173                                 return
174                 self.skin = """<screen position="0,0" size="0,0"/>"""
175                 Screen.__init__(self, session)
176                 self.close(True)
177
178         def getRecordEvent(self, recservice, event):
179                 if event == iRecordableService.evEnd:
180                         recordings = self.session.nav.getRecordings()
181                         if not recordings: # no more recordings exist
182                                 rec_time = self.session.nav.RecordTimer.getNextRecordingTime()
183                                 if rec_time > 0 and (rec_time - time()) < 360:
184                                         self.initTimeout(360) # wait for next starting timer
185                                         self.startTimer()
186                                 else:
187                                         self.close(True) # immediate shutdown
188                 elif event == iRecordableService.evStart:
189                         self.stopTimer()
190
191         def close(self, value):
192                 if self.connected:
193                         self.conntected=False
194                         self.session.nav.record_event.remove(self.getRecordEvent)
195                 if value:
196                         self.hide()
197                         if self.retval == 1:
198                                 config.misc.DeepStandby.value = True
199                         self.session.nav.stopService()
200                         self.quitScreen = self.session.instantiateDialog(QuitMainloopScreen,retvalue=self.retval)
201                         self.quitScreen.show()
202                         quitMainloop(self.retval)
203                 else:
204                         MessageBox.close(self, True)
205
206         def __onShow(self):
207                 global inTryQuitMainloop
208                 inTryQuitMainloop = True
209
210         def __onHide(self):
211                 global inTryQuitMainloop
212                 inTryQuitMainloop = False