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