7e059c5ccae17d812fe5d29bb134fd5823d44807
[enigma2.git] / lib / python / Screens / InfoBar.py
1 from Screen import Screen
2 from EpgSelection import EPGSelection
3 from ChannelSelection import ChannelSelection
4 from Components.Clock import Clock
5 from Components.ActionMap import ActionMap
6 from Components.ActionMap import NumberActionMap
7 from Components.Button import Button
8 from Components.ServiceName import ServiceName
9 from Components.EventInfo import EventInfo
10 from Components.ServicePosition import ServicePosition
11 from Components.config import configfile
12 from Components.Label import Label
13
14 from Screens.MessageBox import MessageBox
15 from Screens.MovieSelection import MovieSelection
16 from Screens.Volume import Volume
17 from Screens.Mute import Mute
18 from Screens.Standby import Standby
19 from Screens.AudioSelection import AudioSelection
20
21 from ServiceReference import ServiceReference
22
23 from enigma import *
24
25 import time
26
27 # hack alert!
28 from Menu import MainMenu, mdom
29
30 class NumberZap(Screen):
31         def quit(self):
32                 self.Timer.stop()
33                 self.close()
34
35         def keyOK(self):
36                 self.Timer.stop()
37                 print "do the action here"
38                 self.close()
39
40         def keyNumberGlobal(self, number):
41                 self.Timer.start(3000)          #reset timer
42                 self.field = self.field + str(number)
43                 self["number"].setText(self.field)
44                 if len(self.field) >= 4:
45                         self.keyOK()
46
47         def __init__(self, session, number):
48                 Screen.__init__(self, session)
49                 self.field = str(number)
50                 
51                 self["number"] = Label(self.field)
52
53                 self["actions"] = NumberActionMap( [ "SetupActions" ], 
54                         {
55                                 "cancel": self.quit,
56                                 "ok": self.keyOK,
57                                 "1": self.keyNumberGlobal,
58                                 "2": self.keyNumberGlobal,
59                                 "3": self.keyNumberGlobal,
60                                 "4": self.keyNumberGlobal,
61                                 "5": self.keyNumberGlobal,
62                                 "6": self.keyNumberGlobal,
63                                 "7": self.keyNumberGlobal,
64                                 "8": self.keyNumberGlobal,
65                                 "9": self.keyNumberGlobal,
66                                 "0": self.keyNumberGlobal
67                         })
68
69                 self.Timer = eTimer()
70                 self.Timer.timeout.get().append(self.keyOK)
71                 self.Timer.start(3000)
72
73
74 class InfoBar(Screen):
75         STATE_HIDDEN = 0
76         STATE_HIDING = 1
77         STATE_SHOWING = 2
78         STATE_SHOWN = 3
79         
80         def __init__(self, session):
81                 Screen.__init__(self, session)
82
83                 #instantiate forever
84                 self.servicelist = self.session.instantiateDialog(ChannelSelection)
85                 
86                 self.state = self.STATE_HIDDEN
87                 
88                 self.volumeDialog = self.session.instantiateDialog(Volume)
89                 self.muteDialog = self.session.instantiateDialog(Mute)
90                 
91                 self.hideTimer = eTimer()
92                 self.hideTimer.timeout.get().append(self.doTimerHide)
93                 #self.hideTimer.start(1000)
94                 
95                 self.hideVolTimer = eTimer()
96                 self.hideVolTimer.timeout.get().append(self.volHide)
97                 
98                 self.powerKeyTimer = eTimer()
99                 self.powerKeyTimer.timeout.get().append(self.powertimer)
100
101                 #self["actions"] = ActionMap( [ "InfobarActions" ], 
102                 self["actions"] = NumberActionMap( [ "InfobarActions" ], 
103                         {
104                                 "switchChannelUp": self.switchChannelUp,
105                                 "switchChannelDown": self.switchChannelDown,
106                                 "mainMenu": self.mainMenu,
107                                 "zapUp": self.zapUp,
108                                 "zapDown": self.zapDown,
109                                 "volumeUp": self.volUp,
110                                 "volumeDown": self.volDown,
111                                 "volumeMute": self.volMute,
112                                 "instantRecord": self.instantRecord,
113                                 "hide": self.hide,
114                                 "toggleShow": self.toggleShow,
115                                 "showMovies": self.showMovies,
116                                 #"quit": self.quit,
117                                 "powerdown": self.powerdown,
118                                 "powerup": self.powerup,
119                                 "1": self.keyNumberGlobal,
120                                 "2": self.keyNumberGlobal,
121                                 "3": self.keyNumberGlobal,
122                                 "4": self.keyNumberGlobal,
123                                 "5": self.keyNumberGlobal,
124                                 "6": self.keyNumberGlobal,
125                                 "7": self.keyNumberGlobal,
126                                 "8": self.keyNumberGlobal,
127                                 "9": self.keyNumberGlobal,
128                                 "0": self.keyNumberGlobal,
129                                 "showEPGList": self.showEPGList,
130                                 
131                                 "pauseService": self.pauseService,
132                                 "unPauseService": self.unPauseService,
133                                 
134                                 "seekFwd": self.seekFwd,
135                                 "seekBack": self.seekBack,
136                                 
137                                 "audioSelection": self.audioSelection,
138                         })
139 #               self["okbutton"] = Button("mainMenu", [self.mainMenu])
140                 
141                 self["CurrentTime"] = Clock()
142                 # ServicePosition(self.session.nav, ServicePosition.TYPE_REMAINING)
143                 # Clock()
144
145                 self["ServiceName"] = ServiceName(self.session.nav)
146                 
147                 self["Event_Now_StartTime"] = EventInfo(self.session.nav, EventInfo.Now_StartTime)
148                 self["Event_Next_StartTime"] = EventInfo(self.session.nav, EventInfo.Next_StartTime)
149                                 
150                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
151                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
152
153                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
154                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
155                 
156                 self.recording = None
157                 
158                 self.pos = 0
159         
160         def mainMenu(self):
161                 print "loading mainmenu XML..."
162                 menu = mdom.childNodes[0]
163                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
164                 self.session.open(MainMenu, menu, menu.childNodes)
165
166         def powertimer(self):   
167                 print "PowerOff - Now!"
168                 self.quit()
169         
170         def powerdown(self):
171                 self.standbyblocked = 0
172                 self.powerKeyTimer.start(3000)
173
174         def powerup(self):
175                 self.powerKeyTimer.stop()
176                 if self.standbyblocked == 0:
177                         self.standbyblocked = 1
178                         self.session.open(Standby, self)
179                         
180
181         def keyNumberGlobal(self, number):
182                 print "You pressed number " + str(number)
183                 self.session.open(NumberZap, number)
184
185         def switchChannelUp(self):      
186                 self.servicelist.moveUp()
187                 self.session.execDialog(self.servicelist)
188
189         def switchChannelDown(self):    
190                 self.servicelist.moveDown()
191                 self.session.execDialog(self.servicelist)
192
193         def hide(self): 
194                 self.instance.hide()
195
196         def doTimerHide(self):
197                 if self.state == self.STATE_SHOWN:
198                         self.instance.hide()
199                         self.state = self.STATE_HIDDEN
200
201         def toggleShow(self):
202                 if self.state == self.STATE_SHOWN:
203                         self.instance.hide()
204                         #pls check animation support, sorry
205 #                       self.startHide()
206                         self.state = self.STATE_HIDDEN
207                 else:
208                         self.instance.show()
209 #                       self.startShow()
210                         self.state = self.STATE_SHOWN
211                         #TODO: make it customizable
212                         self.hideTimer.start(5000)
213
214         def     zapUp(self):
215                 self.servicelist.moveUp()
216                 self.servicelist.zap()
217
218         def     zapDown(self):
219                 self.servicelist.moveDown()
220                 self.servicelist.zap()
221
222         def     volUp(self):
223                 eDVBVolumecontrol.getInstance().volumeUp()
224                 self.volumeDialog.instance.show()
225                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
226                 self.hideVolTimer.start(3000)
227
228         def     volDown(self):
229                 eDVBVolumecontrol.getInstance().volumeDown()
230                 self.volumeDialog.instance.show()
231                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
232                 self.hideVolTimer.start(3000)
233                 
234         def volHide(self):
235                 self.volumeDialog.instance.hide()
236
237         def startShow(self):
238                 self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
239                 self.state = self.STATE_SHOWN
240         
241         def startHide(self):
242                 self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
243                 self.state = self.STATE_HIDDEN
244
245         def     volMute(self):
246                 eDVBVolumecontrol.getInstance().volumeToggleMute()
247                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
248                 
249                 if (eDVBVolumecontrol.getInstance().isMuted()):
250                         self.muteDialog.instance.show()
251                 else:
252                         self.muteDialog.instance.hide()
253
254         def showEPGList(self):
255                 ref=self.session.nav.getCurrentlyPlayingServiceReference()
256                 ptr=eEPGCache.getInstance()
257                 if ptr.startTimeQuery(ref) != -1:
258                         self.session.open(EPGSelection, ref)
259                 else:
260                         print 'no epg for service', ref.toString()
261
262         def quit(self):
263                 #       self.session.open(Standby, self)
264                 configfile.save()
265                 quitMainloop(0)
266         
267         def stopCurrentRecording(self): 
268                 print "remove entry"
269                 self.session.nav.RecordTimer.removeEntry(self.recording)
270                 self.recording = None
271         
272         def startInstantRecording(self):
273                 serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
274                         
275                 # try to get event info
276                 epg = None
277                 try:
278                         service = self.session.nav.getCurrentService()
279                         info = service.info()
280                         ev = info.getEvent(0)
281                         epg = ev
282                 except:
283                         pass
284                 
285                 # fix me, description. 
286                 self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 3600, serviceref, epg, "instant record")
287
288         def recordQuestionCallback(self, answer):
289                 if answer == False:
290                         return
291                 
292                 if self.recording != None:
293                         self.stopCurrentRecording()
294                 else:
295                         self.startInstantRecording()
296
297         def instantRecord(self):
298                 if self.recording != None:
299                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Do you want to stop the current\n(instant) recording?")
300                 else:
301                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Start recording?")
302
303         def showMovies(self):
304                 self.session.open(MovieSelection)
305
306         def pauseService(self):
307                 self.session.nav.pause(1)
308                 
309         def unPauseService(self):
310                 self.session.nav.pause(0)
311         
312         def doSeek(self, dir, seektime):
313                 service = self.session.nav.getCurrentService()
314                 if service is None:
315                         return
316                 
317                 seekable = service.seek()
318                 if seekable is None:
319                         return
320                 seekable.seekRelative(dir, 90 * seektime)
321
322         def seekFwd(self):
323                 self.doSeek(+1, 10000)
324         
325         def seekBack(self):
326                 self.doSeek(-1, 10000)
327
328         def audioSelection(self):
329                 service = self.session.nav.getCurrentService()
330                 audio = service.audioTracks()
331                 n = audio.getNumberOfTracks()
332                 if n > 0:
333                         self.session.open(AudioSelection, audio)