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