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