some service scan improovements
[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 enigma import eDVBVolumecontrol
6
7 inStandby = None
8
9 class Standby(Screen):
10         def Power(self):
11                 print "leave standby"
12                 #set input to encoder
13                 self.avswitch.setInput("ENCODER")
14                 #restart last played service
15                 #unmute adc
16                 self.leaveMute()
17                 #set brightness of lcd
18                 config.lcd.bright.apply()
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                 #mute adc
46                 self.setMute()
47                 #get currently playing service reference
48                 self.prev_running_service = self.session.nav.getCurrentlyPlayingServiceReference()
49                 #stop actual played dvb-service
50                 self.session.nav.stopService()
51                 #set input to vcr scart
52                 self.avswitch.setInput("SCART")
53                 #set lcd brightness to standby value
54                 config.lcd.standby.apply()
55                 self.onShow.append(self.__onShow)
56                 self.onHide.append(self.__onHide)
57                 self.onClose.append(self.__onClose)
58
59         def __onClose(self):
60                 if self.prev_running_service:
61                         self.session.nav.playService(self.prev_running_service)
62
63         def createSummary(self):
64                 return StandbySummary
65
66         def __onShow(self):
67                 global inStandby
68                 inStandby = self
69
70         def __onHide(self):
71                 global inStandby
72                 inStandby = None
73
74 class StandbySummary(Screen):
75         skin = """
76         <screen position="0,0" size="132,64">
77                 <widget source="global.CurrentTime" render="Label" position="0,0" size="132,64" font="Regular;40" halign="center">
78                         <convert type="ClockToText" />
79                 </widget>
80                 <widget source="session.RecordState" render="FixedLabel" text=" " position="0,0" size="132,64" zPosition="1" >
81                         <convert type="ConfigEntryTest">config.usage.blinking_display_clock_during_recording,True,CheckSourceBoolean</convert>
82                         <convert type="ConditionalShowHide">Blink</convert>
83                 </widget>
84         </screen>"""
85
86         def __init__(self, session, parent):
87                 Screen.__init__(self, session)
88
89 from enigma import quitMainloop, iRecordableService
90 from Screens.MessageBox import MessageBox
91 from time import time
92
93 inTryQuitMainloop = False
94
95 class TryQuitMainloop(MessageBox):
96         def __init__(self, session, retvalue=1, timeout=-1):
97                 self.retval=retvalue
98                 recordings = len(session.nav.getRecordings())
99                 self.connected = False
100                 next_rec_time = -1
101                 if not recordings:
102                         next_rec_time = session.nav.RecordTimer.getNextRecordingTime()
103                 if recordings or (next_rec_time > 0 and (next_rec_time - time()) < 360):
104                         if retvalue == 1:
105                                 MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really shutdown now?"), type = MessageBox.TYPE_YESNO, timeout = timeout)
106                         elif retvalue == 2:
107                                 MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really reboot now?"), type = MessageBox.TYPE_YESNO, timeout = timeout)
108                         elif retvalue == 4:
109                                 pass
110                         else:
111                                 MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really restart now?"), type = MessageBox.TYPE_YESNO, timeout = timeout)
112                         self.skinName = "MessageBox"
113                         session.nav.record_event.append(self.getRecordEvent)
114                         self.connected = True
115                         self.onShow.append(self.__onShow)
116                         self.onHide.append(self.__onHide)
117                 else:
118                         self.skin = """<screen position="0,0" size="0,0"/>"""
119                         Screen.__init__(self, session)
120                         self.close(True)
121
122         def getRecordEvent(self, recservice, event):
123                 if event == iRecordableService.evEnd:
124                         recordings = self.session.nav.getRecordings()
125                         if not len(recordings): # no more recordings exist
126                                 rec_time = self.session.nav.RecordTimer.getNextRecordingTime()
127                                 if rec_time > 0 and (rec_time - time()) < 360:
128                                         self.initTimeout(360) # wait for next starting timer
129                                         self.startTimer()
130                                 else:
131                                         self.close(True) # immediate shutdown
132                 elif event == iRecordableService.evStart:
133                         self.stopTimer()
134
135         def close(self, value):
136                 if self.connected:
137                         self.conntected=False
138                         self.session.nav.record_event.remove(self.getRecordEvent)
139                 if value:
140                         quitMainloop(self.retval)
141                 else:
142                         MessageBox.close(self, True)
143
144         def __onShow(self):
145                 global inTryQuitMainloop
146                 inTryQuitMainloop = True
147
148         def __onHide(self):
149                 global inTryQuitMainloop
150                 inTryQuitMainloop = False