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