enigma2 (20120327 rel32 -> 20120430 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 Components.HdmiCec import hdmi_cec
7 from GlobalActions import globalActionMap
8 from enigma import eDVBVolumecontrol
9
10 inStandby = None
11
12 class Standby(Screen):
13         def Power(self):
14                 print "leave standby"
15                 hdmi_cec.otp_source_enable()
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                 }, -1)
46
47                 globalActionMap.setEnabled(False)
48
49                 #mute adc
50                 self.setMute()
51
52                 #hdmi-cec standby
53                 hdmi_cec.ss_standby()
54
55                 self.paused_service = None
56                 self.prev_running_service = None
57                 if self.session.current_dialog:
58                         if self.session.current_dialog.ALLOW_SUSPEND == Screen.SUSPEND_STOPS:
59                                 #get currently playing service reference
60                                 self.prev_running_service = self.session.nav.getCurrentlyPlayingServiceReference()
61                                 #stop actual played dvb-service
62                                 self.session.nav.stopService()
63                         elif self.session.current_dialog.ALLOW_SUSPEND == Screen.SUSPEND_PAUSES:
64                                 self.paused_service = self.session.current_dialog
65                                 self.paused_service.pauseService()
66
67                 #set input to vcr scart
68                 if SystemInfo["ScartSwitch"]:
69                         self.avswitch.setInput("SCART")
70                 else:
71                         self.avswitch.setInput("AUX")
72                 self.onFirstExecBegin.append(self.__onFirstExecBegin)
73                 self.onClose.append(self.__onClose)
74
75         def __onClose(self):
76                 global inStandby
77                 inStandby = None
78                 if self.prev_running_service:
79                         self.session.nav.playService(self.prev_running_service)
80                 elif self.paused_service:
81                         self.paused_service.unPauseService()
82                 self.session.screen["Standby"].boolean = False
83                 globalActionMap.setEnabled(True)
84
85         def __onFirstExecBegin(self):
86                 global inStandby
87                 inStandby = self
88                 self.session.screen["Standby"].boolean = True
89                 config.misc.standbyCounter.value += 1
90
91         def createSummary(self):
92                 return StandbySummary
93
94 class StandbySummary(Screen):
95         skin = """
96         <screen position="0,0" size="132,64">
97                 <widget source="global.CurrentTime" render="Label" position="0,0" size="132,64" font="Regular;40" halign="center">
98                         <convert type="ClockToText" />
99                 </widget>
100                 <widget source="session.RecordState" render="FixedLabel" text=" " position="0,0" size="132,64" zPosition="1" >
101                         <convert type="ConfigEntryTest">config.usage.blinking_display_clock_during_recording,True,CheckSourceBoolean</convert>
102                         <convert type="ConditionalShowHide">Blink</convert>
103                 </widget>
104         </screen>"""
105
106 from enigma import quitMainloop, iRecordableService
107 from Screens.MessageBox import MessageBox
108 from time import time
109 from Components.Task import job_manager
110
111 inTryQuitMainloop = False
112
113 class TryQuitMainloop(MessageBox):
114         def __init__(self, session, retvalue=1, timeout=-1, default_yes = True):
115                 self.retval=retvalue
116                 recordings = session.nav.getRecordings()
117                 jobs = len(job_manager.getPendingJobs())
118                 self.connected = False
119                 reason = ""
120                 next_rec_time = -1
121                 if not recordings:
122                         next_rec_time = session.nav.RecordTimer.getNextRecordingTime()  
123                 if recordings or (next_rec_time > 0 and (next_rec_time - time()) < 360):
124                         reason = _("Recording(s) are in progress or coming up in few seconds!") + '\n'
125                 if jobs:
126                         if jobs == 1:
127                                 job = job_manager.getPendingJobs()[0]
128                                 reason += "%s: %s (%d%%)\n" % (job.getStatustext(), job.name, int(100*job.progress/float(job.end)))
129                         else:
130                                 reason += (_("%d jobs are running in the background!") % jobs) + '\n'
131                 if reason:
132                         if retvalue == 1:
133                                 MessageBox.__init__(self, session, reason+_("Really shutdown now?"), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes)
134                         elif retvalue == 2:
135                                 MessageBox.__init__(self, session, reason+_("Really reboot now?"), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes)
136                         elif retvalue == 4:
137                                 pass
138                         else:
139                                 MessageBox.__init__(self, session, reason+_("Really restart now?"), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes)
140                         self.skinName = "MessageBox"
141                         session.nav.record_event.append(self.getRecordEvent)
142                         self.connected = True
143                         self.onShow.append(self.__onShow)
144                         self.onHide.append(self.__onHide)
145                 else:
146                         self.skin = """<screen position="0,0" size="0,0"/>"""
147                         Screen.__init__(self, session)
148                         self.close(True)
149
150         def getRecordEvent(self, recservice, event):
151                 if event == iRecordableService.evEnd:
152                         recordings = self.session.nav.getRecordings()
153                         if not recordings: # no more recordings exist
154                                 rec_time = self.session.nav.RecordTimer.getNextRecordingTime()
155                                 if rec_time > 0 and (rec_time - time()) < 360:
156                                         self.initTimeout(360) # wait for next starting timer
157                                         self.startTimer()
158                                 else:
159                                         self.close(True) # immediate shutdown
160                 elif event == iRecordableService.evStart:
161                         self.stopTimer()
162
163         def close(self, value):
164                 if self.connected:
165                         self.conntected=False
166                         self.session.nav.record_event.remove(self.getRecordEvent)
167                 if value:
168                         quitMainloop(self.retval)
169                 else:
170                         MessageBox.close(self, True)
171
172         def __onShow(self):
173                 global inTryQuitMainloop
174                 inTryQuitMainloop = True
175
176         def __onHide(self):
177                 global inTryQuitMainloop
178                 inTryQuitMainloop = False