enigma2 20131118 (master) -> 20140214 (master)
[enigma2.git] / usr / lib / enigma2 / 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 GlobalActions import globalActionMap
7 from enigma import eDVBVolumecontrol, eDVBLocalTimeHandler, eServiceReference
8
9 inStandby = None
10
11 class Standby(Screen):
12         def Power(self):
13                 print "leave standby"
14                 #set input to encoder
15                 self.avswitch.setInput("ENCODER")
16                 #restart last played service
17                 #unmute adc
18                 self.leaveMute()
19                 #kill me
20                 self.close(True)
21
22         def setMute(self):
23                 if (eDVBVolumecontrol.getInstance().isMuted()):
24                         self.wasMuted = 1
25                         print "mute already active"
26                 else:   
27                         self.wasMuted = 0
28                         eDVBVolumecontrol.getInstance().volumeToggleMute()
29
30         def leaveMute(self):
31                 if self.wasMuted == 0:
32                         eDVBVolumecontrol.getInstance().volumeToggleMute()
33
34         def __init__(self, session):
35                 Screen.__init__(self, session)
36                 self.avswitch = AVSwitch()
37
38                 print "enter standby"
39
40                 self["actions"] = ActionMap( [ "StandbyActions" ],
41                 {
42                         "power": self.Power
43                 }, -1)
44
45                 globalActionMap.setEnabled(False)
46
47                 #mute adc
48                 self.setMute()
49
50                 self.paused_service = None
51                 self.prev_running_service = None
52                 self.connected_time_handler = False
53
54                 if self.session.current_dialog:
55                         if self.session.current_dialog.ALLOW_SUSPEND == Screen.SUSPEND_STOPS:
56                                 #get currently playing service reference
57                                 self.prev_running_service = self.session.nav.getCurrentlyPlayingServiceReference()
58                                 #stop actual played dvb-service
59                                 self.session.nav.stopService()
60                         elif self.session.current_dialog.ALLOW_SUSPEND == Screen.SUSPEND_PAUSES:
61                                 self.paused_service = self.session.current_dialog
62                                 self.paused_service.pauseService()
63
64                 #set input to vcr scart
65                 if SystemInfo["ScartSwitch"]:
66                         self.avswitch.setInput("SCART")
67                 else:
68                         self.avswitch.setInput("AUX")
69                 self.onFirstExecBegin.append(self.__onFirstExecBegin)
70                 self.onClose.append(self.__onClose)
71
72                 if config.misc.standbyCounter.value == 0 and config.misc.useTransponderTime.value:
73                         th = eDVBLocalTimeHandler.getInstance()
74                         if not th.ready():
75                                 refstr = config.servicelist.lastmode.value == 'tv' and config.tv.lastservice.value or config.radio.lastservice.value
76                                 ref = eServiceReference(refstr)
77                                 if ref.valid():
78                                         th.m_timeUpdated.get().append(self.timeReady)
79                                         self.connected_time_handler = True
80                                         self.session.nav.playService(ref)
81
82         def timeReady(self):
83                 if self.connected_time_handler:
84                         th = eDVBLocalTimeHandler.getInstance()
85                         th.m_timeUpdated.get().remove(self.timeReady)
86                         self.connected_time_handler = False
87                         self.session.nav.stopService()
88
89         def __onClose(self):
90                 global inStandby
91                 inStandby = None
92
93                 self.timeReady()
94
95                 if not self.session.shutdown:
96                         if self.prev_running_service:
97                                 self.session.nav.playService(self.prev_running_service)
98                         elif self.paused_service:
99                                 self.paused_service.unPauseService()
100                 self.session.screen["Standby"].boolean = False
101                 globalActionMap.setEnabled(True)
102
103         def __onFirstExecBegin(self):
104                 global inStandby
105                 inStandby = self
106                 self.session.screen["Standby"].boolean = True
107                 config.misc.standbyCounter.value += 1
108
109         def createSummary(self):
110                 return StandbySummary
111
112 class StandbySummary(Screen):
113         skin = """
114         <screen position="0,0" size="132,64">
115                 <widget source="global.CurrentTime" render="Label" position="0,0" size="132,64" font="Regular;40" halign="center">
116                         <convert type="ClockToText" />
117                 </widget>
118                 <widget source="session.RecordState" render="FixedLabel" text=" " position="0,0" size="132,64" zPosition="1" >
119                         <convert type="ConfigEntryTest">config.usage.blinking_display_clock_during_recording,True,CheckSourceBoolean</convert>
120                         <convert type="ConditionalShowHide">Blink</convert>
121                 </widget>
122         </screen>"""
123
124 from enigma import quitMainloop, iRecordableService
125 from Screens.MessageBox import MessageBox
126 from time import time
127 from Components.Task import job_manager
128
129 inTryQuitMainloop = False
130
131 class TryQuitMainloop(MessageBox):
132         def __init__(self, session, retvalue=1, timeout=-1, default_yes = True):
133                 self.retval=retvalue
134                 recordings = session.nav.getRecordings()
135                 jobs = len(job_manager.getPendingJobs())
136                 self.connected = False
137                 reason = ""
138                 next_rec_time = -1
139                 if not recordings:
140                         next_rec_time = session.nav.RecordTimer.getNextRecordingTime()  
141                 if recordings or (next_rec_time > 0 and (next_rec_time - time()) < 360):
142                         reason = _("Recording(s) are in progress or coming up in few seconds!") + '\n'
143                 if jobs:
144                         if jobs == 1:
145                                 job = job_manager.getPendingJobs()[0]
146                                 reason += "%s: %s (%d%%)\n" % (job.getStatustext(), job.name, int(100*job.progress/float(job.end)))
147                         else:
148                                 reason += (_("%d jobs are running in the background!") % jobs) + '\n'
149                 if reason:
150                         if retvalue == 1:
151                                 MessageBox.__init__(self, session, reason+_("Really shutdown now?"), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes)
152                         elif retvalue == 2:
153                                 MessageBox.__init__(self, session, reason+_("Really reboot now?"), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes)
154                         elif retvalue == 4:
155                                 pass
156                         else:
157                                 MessageBox.__init__(self, session, reason+_("Really restart now?"), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes)
158                         self.skinName = "MessageBox"
159                         session.nav.record_event.append(self.getRecordEvent)
160                         self.connected = True
161                         self.onShow.append(self.__onShow)
162                         self.onHide.append(self.__onHide)
163                 else:
164                         self.skin = """<screen name="TryQuitMainloop" position="0,0" size="0,0" flags="wfNoBorder"/>"""
165                         Screen.__init__(self, session)
166                         self.close(True)
167
168         def getRecordEvent(self, recservice, event):
169                 if event == iRecordableService.evEnd:
170                         recordings = self.session.nav.getRecordings()
171                         if not recordings: # no more recordings exist
172                                 rec_time = self.session.nav.RecordTimer.getNextRecordingTime()
173                                 if rec_time > 0 and (rec_time - time()) < 360:
174                                         self.initTimeout(360) # wait for next starting timer
175                                         self.startTimer()
176                                 else:
177                                         self.close(True) # immediate shutdown
178                 elif event == iRecordableService.evStart:
179                         self.stopTimer()
180
181         def close(self, value):
182                 if self.connected:
183                         self.conntected=False
184                         self.session.nav.record_event.remove(self.getRecordEvent)
185                 if value:
186                         quitMainloop(self.retval)
187                 else:
188                         MessageBox.close(self, True)
189
190         def __onShow(self):
191                 global inTryQuitMainloop
192                 inTryQuitMainloop = True
193
194         def __onHide(self):
195                 global inTryQuitMainloop
196                 inTryQuitMainloop = False