show dolby, crypt and format status in the infobar - we don't have functionality...
[enigma2.git] / lib / python / Screens / InfoBarGenerics.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap, HelpableActionMap
3 from Components.ActionMap import NumberActionMap
4 from Components.Label import Label
5 from Components.config import configfile, configsequencearg
6 from Components.config import config, configElement, ConfigSubsection, configSequence
7 from ChannelSelection import ChannelSelection
8
9 from Components.Pixmap import PixmapConditional
10 from Components.BlinkingPixmap import BlinkingPixmapConditional
11 from Components.ServiceName import ServiceName
12 from Components.EventInfo import EventInfo
13
14 from ServiceReference import ServiceReference
15 from EpgSelection import EPGSelection
16
17 from Screens.MessageBox import MessageBox
18 from Screens.Volume import Volume
19 from Screens.Mute import Mute
20 from Screens.Standby import Standby
21 from Screens.EventView import EventView
22
23 #from enigma import eTimer, eDVBVolumecontrol, quitMainloop
24 from enigma import *
25
26 import time
27 import os
28
29 # hack alert!
30 from Menu import MainMenu, mdom
31
32 class InfoBarVolumeControl:
33         """Volume control, handles volUp, volDown, volMute actions and display 
34         a corresponding dialog"""
35         def __init__(self):
36                 config.audio = ConfigSubsection()
37                 config.audio.volume = configElement("config.audio.volume", configSequence, [5], configsequencearg.get("INTEGER", (0, 100)))
38
39                 self["VolumeActions"] = ActionMap( ["InfobarVolumeActions"] ,
40                         {
41                                 "volumeUp": self.volUp,
42                                 "volumeDown": self.volDown,
43                                 "volumeMute": self.volMute,
44                         })
45
46                 self.volumeDialog = self.session.instantiateDialog(Volume)
47                 self.muteDialog = self.session.instantiateDialog(Mute)
48
49                 self.hideVolTimer = eTimer()
50                 self.hideVolTimer.timeout.get().append(self.volHide)
51
52                 vol = config.audio.volume.value[0]
53                 self.volumeDialog.setValue(vol)
54                 eDVBVolumecontrol.getInstance().setVolume(vol, vol)
55         
56         def volSave(self):
57                 config.audio.volume.value = eDVBVolumecontrol.getInstance().getVolume()
58                 config.audio.volume.save()
59                 
60         def     volUp(self):
61                 eDVBVolumecontrol.getInstance().volumeUp()
62                 self.volumeDialog.instance.show()
63                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
64                 self.volSave()
65                 self.hideVolTimer.start(3000)
66
67         def     volDown(self):
68                 eDVBVolumecontrol.getInstance().volumeDown()
69                 self.volumeDialog.instance.show()
70                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
71                 self.volSave()
72                 self.hideVolTimer.start(3000)
73                 
74         def volHide(self):
75                 self.volumeDialog.instance.hide()
76
77         def     volMute(self):
78                 eDVBVolumecontrol.getInstance().volumeToggleMute()
79                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
80                 
81                 if (eDVBVolumecontrol.getInstance().isMuted()):
82                         self.muteDialog.instance.show()
83                 else:
84                         self.muteDialog.instance.hide()
85
86 class InfoBarShowHide:
87         """ InfoBar show/hide control, accepts toggleShow and hide actions, might start
88         fancy animations. """
89         STATE_HIDDEN = 0
90         STATE_HIDING = 1
91         STATE_SHOWING = 2
92         STATE_SHOWN = 3
93         
94         def __init__(self):
95                 self["ShowHideActions"] = ActionMap( ["InfobarShowHideActions"] ,
96                         {
97                                 "toggleShow": self.toggleShow,
98                                 "hide": self.hide,
99                         })
100
101                 self.state = self.STATE_SHOWN
102                 
103                 self.onExecBegin.append(self.show)
104                 self.onClose.append(self.delHideTimer)
105                 
106                 self.hideTimer = eTimer()
107                 self.hideTimer.timeout.get().append(self.doTimerHide)
108                 self.hideTimer.start(5000)
109
110         def delHideTimer(self):
111                 del self.hideTimer
112
113         def hide(self): 
114                 self.instance.hide()
115                 
116         def show(self):
117                 self.state = self.STATE_SHOWN
118                 self.hideTimer.stop()
119                 self.hideTimer.start(5000)
120
121         def doTimerHide(self):
122                 self.hideTimer.stop()
123                 if self.state == self.STATE_SHOWN:
124                         self.instance.hide()
125                         self.state = self.STATE_HIDDEN
126
127         def toggleShow(self):
128                 if self.state == self.STATE_SHOWN:
129                         self.instance.hide()
130                         #pls check animation support, sorry
131 #                       self.startHide()
132                         self.hideTimer.stop()
133                         self.state = self.STATE_HIDDEN
134                 elif self.state == self.STATE_HIDDEN:
135                         self.instance.show()
136                         self.show()
137                         
138         def startShow(self):
139                 self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
140                 self.state = self.STATE_SHOWN
141         
142         def startHide(self):
143                 self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
144                 self.state = self.STATE_HIDDEN
145
146 class NumberZap(Screen):
147         def quit(self):
148                 self.Timer.stop()
149                 self.close(0)
150
151         def keyOK(self):
152                 self.Timer.stop()
153                 self.close(int(self["number"].getText()))
154
155         def keyNumberGlobal(self, number):
156                 self.Timer.start(3000)          #reset timer
157                 self.field = self.field + str(number)
158                 self["number"].setText(self.field)
159                 if len(self.field) >= 4:
160                         self.keyOK()
161
162         def __init__(self, session, number):
163                 Screen.__init__(self, session)
164                 self.field = str(number)
165
166                 self["channel"] = Label(_("Channel:"))
167
168                 self["number"] = Label(self.field)
169
170                 self["actions"] = NumberActionMap( [ "SetupActions" ], 
171                         {
172                                 "cancel": self.quit,
173                                 "ok": self.keyOK,
174                                 "1": self.keyNumberGlobal,
175                                 "2": self.keyNumberGlobal,
176                                 "3": self.keyNumberGlobal,
177                                 "4": self.keyNumberGlobal,
178                                 "5": self.keyNumberGlobal,
179                                 "6": self.keyNumberGlobal,
180                                 "7": self.keyNumberGlobal,
181                                 "8": self.keyNumberGlobal,
182                                 "9": self.keyNumberGlobal,
183                                 "0": self.keyNumberGlobal
184                         })
185
186                 self.Timer = eTimer()
187                 self.Timer.timeout.get().append(self.keyOK)
188                 self.Timer.start(3000)
189
190 class InfoBarPowerKey:
191         """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
192         
193         def __init__(self):
194                 self.powerKeyTimer = eTimer()
195                 self.powerKeyTimer.timeout.get().append(self.powertimer)
196                 self["PowerKeyActions"] = HelpableActionMap(self, "PowerKeyActions",
197                         {
198                                 "powerdown": self.powerdown,
199                                 "powerup": self.powerup,
200                                 "discreteStandby": (self.standby, "Go standby"),
201                                 "discretePowerOff": (self.quit, "Go to deep standby"),
202                         })
203
204         def powertimer(self):   
205                 print "PowerOff - Now!"
206                 self.quit()
207         
208         def powerdown(self):
209                 self.standbyblocked = 0
210                 self.powerKeyTimer.start(3000)
211
212         def powerup(self):
213                 self.powerKeyTimer.stop()
214                 if self.standbyblocked == 0:
215                         self.standbyblocked = 1
216                         self.standby()
217
218         def standby(self):
219                 self.session.open(Standby, self)
220
221         def quit(self):
222                 # halt
223                 quitMainloop(1)
224
225 class InfoBarNumberZap:
226         """ Handles an initial number for NumberZapping """
227         def __init__(self):
228                 self["NumberZapActions"] = NumberActionMap( [ "NumberZapActions"],
229                         {
230                                 "1": self.keyNumberGlobal,
231                                 "2": self.keyNumberGlobal,
232                                 "3": self.keyNumberGlobal,
233                                 "4": self.keyNumberGlobal,
234                                 "5": self.keyNumberGlobal,
235                                 "6": self.keyNumberGlobal,
236                                 "7": self.keyNumberGlobal,
237                                 "8": self.keyNumberGlobal,
238                                 "9": self.keyNumberGlobal,
239                                 "0": self.keyNumberGlobal,
240                         })
241
242         def keyNumberGlobal(self, number):
243 #               print "You pressed number " + str(number)
244                 self.session.openWithCallback(self.numberEntered, NumberZap, number)
245
246         def numberEntered(self, retval):
247 #               print self.servicelist
248                 if retval > 0:
249                         self.servicelist.zapToNumber(retval)
250
251 class InfoBarChannelSelection:
252         """ ChannelSelection - handles the channelSelection dialog and the initial 
253         channelChange actions which open the channelSelection dialog """
254         def __init__(self):
255                 #instantiate forever
256                 self.servicelist = self.session.instantiateDialog(ChannelSelection)
257
258                 self["ChannelSelectActions"] = HelpableActionMap(self, "InfobarChannelSelection",
259                         {
260                                 "switchChannelUp": self.switchChannelUp,
261                                 "switchChannelDown": self.switchChannelDown,
262                                 "zapUp": (self.zapUp, _("next channel")),
263                                 "zapDown": (self.zapDown, _("previous channel")),
264                         })
265                         
266         def switchChannelUp(self):      
267                 self.servicelist.moveUp()
268                 self.session.execDialog(self.servicelist)
269
270         def switchChannelDown(self):    
271                 self.servicelist.moveDown()
272                 self.session.execDialog(self.servicelist)
273
274         def     zapUp(self):
275                 self.servicelist.moveUp()
276                 self.servicelist.zap()
277                 self.instance.show()
278                 self.show()
279
280         def     zapDown(self):
281                 self.servicelist.moveDown()
282                 self.servicelist.zap()
283                 self.instance.show()
284                 self.show()
285                 
286 class InfoBarMenu:
287         """ Handles a menu action, to open the (main) menu """
288         def __init__(self):
289                 self["MenuActions"] = HelpableActionMap(self, "InfobarMenuActions", 
290                         {
291                                 "mainMenu": (self.mainMenu, "Enter main menu..."),
292                         })
293
294         def mainMenu(self):
295                 print "loading mainmenu XML..."
296                 menu = mdom.childNodes[0]
297                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
298                 self.session.open(MainMenu, menu, menu.childNodes)
299
300 class InfoBarEPG:
301         """ EPG - Opens an EPG list when the showEPGList action fires """
302         def __init__(self):
303                 self["EPGActions"] = HelpableActionMap(self, "InfobarEPGActions", 
304                         {
305                                 "showEPGList": (self.showEPGList, _("show EPG...")),
306                         })
307
308         def showEPGList(self):
309                 ref=self.session.nav.getCurrentlyPlayingServiceReference()
310                 ptr=eEPGCache.getInstance()
311                 if ptr.startTimeQuery(ref) != -1:
312                         self.session.open(EPGSelection, ref)
313                 else: # try to show now/next
314                         print 'no epg for service', ref.toString()
315                         try:
316                                 self.epglist = [ ]
317                                 service = self.session.nav.getCurrentService()
318                                 info = service.info()
319                                 ptr=info.getEvent(0)
320                                 if ptr:
321                                         self.epglist.append(ptr)
322                                 ptr=info.getEvent(1)
323                                 if ptr:
324                                         self.epglist.append(ptr)
325                                 if len(self.epglist) > 0:
326                                         self.session.open(EventView, self.epglist[0], ServiceReference(ref), self.eventViewCallback)
327                         except:
328                                 pass
329
330         def eventViewCallback(self, setEvent, val): #used for now/next displaying
331                 if len(self.epglist) > 1:
332                         tmp = self.epglist[0]
333                         self.epglist[0]=self.epglist[1]
334                         self.epglist[1]=tmp
335                         setEvent(self.epglist[0])
336
337 class InfoBarEvent:
338         """provides a current/next event info display"""
339         def __init__(self):
340                 self["Event_Now_StartTime"] = EventInfo(self.session.nav, EventInfo.Now_StartTime)
341                 self["Event_Next_StartTime"] = EventInfo(self.session.nav, EventInfo.Next_StartTime)
342                                 
343                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
344                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
345
346                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
347                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
348
349 class InfoBarServiceName:
350         def __init__(self):
351                 self["ServiceName"] = ServiceName(self.session.nav)
352
353 class InfoBarPVR:
354         """handles PVR specific actions like seeking, pause"""
355         def __init__(self):
356                 self["PVRActions"] = HelpableActionMap(self, "InfobarPVRActions", 
357                         {
358                                 "pauseService": (self.pauseService, "pause"),
359                                 "unPauseService": (self.unPauseService, "continue"),
360                                 
361                                 "seekFwd": (self.seekFwd, "skip forward"),
362                                 "seekBack": (self.seekBack, "skip backward"),
363                         })
364                 
365         def pauseService(self):
366                 self.session.nav.pause(1)
367                 
368         def unPauseService(self):
369                 self.session.nav.pause(0)
370         
371         def doSeek(self, dir, seektime):
372                 service = self.session.nav.getCurrentService()
373                 if service is None:
374                         return
375                 
376                 seekable = service.seek()
377                 if seekable is None:
378                         return
379                 seekable.seekRelative(dir, 90 * seektime)
380
381         def seekFwd(self):
382                 self.doSeek(+1, 60000)
383         
384         def seekBack(self):
385                 self.doSeek(-1, 60000)
386
387 class InfoBarInstantRecord:
388         """Instant Record - handles the instantRecord action in order to 
389         start/stop instant records"""
390         def __init__(self):
391                 self["InstantRecordActions"] = HelpableActionMap(self, "InfobarInstantRecord",
392                         {
393                                 "instantRecord": (self.instantRecord, "Instant Record..."),
394                         })
395                 self.recording = None
396                 
397                 self["BlinkingPoint"] = BlinkingPixmapConditional()
398                 self.onShown.append(self["BlinkingPoint"].hidePixmap)
399
400         def stopCurrentRecording(self): 
401                 self.session.nav.RecordTimer.removeEntry(self.recording)
402                 self.recording = None
403                         
404         def startInstantRecording(self):
405                 serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
406                         
407                 # try to get event info
408                 epg = None
409                 try:
410                         service = self.session.nav.getCurrentService()
411                         info = service.info()
412                         ev = info.getEvent(0)
413                         epg = ev
414                 except:
415                         pass
416                 
417                 # fix me, description. 
418                 self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 3600, serviceref, epg, "instant record")
419                 self.recording.dontSave = True
420                 
421                 self["BlinkingPoint"].setConnect(lambda: self.recording.isRunning())
422                 
423         def isInstantRecordRunning(self):
424                 if self.recording != None:
425                         if self.recording.isRunning():
426                                 return True
427                 return False
428
429         def recordQuestionCallback(self, answer):
430                 if answer == False:
431                         return
432                 
433                 if self.isInstantRecordRunning():
434                         self.stopCurrentRecording()
435                 else:
436                         self.startInstantRecording()
437
438         def instantRecord(self):
439                 try:
440                         stat = os.stat("/hdd/movies")
441                 except:
442                         self.session.open(MessageBox, "No HDD found!")
443                         return
444         
445                 if self.isInstantRecordRunning():
446                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, _("Do you want to stop the current\n(instant) recording?"))
447                 else:
448                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, _("Start recording?"))
449
450 from Screens.AudioSelection import AudioSelection
451
452 class InfoBarAudioSelection:
453         def __init__(self):
454                 self["AudioSelectionAction"] = HelpableActionMap(self, "InfobarAudioSelectionActions", 
455                         {
456                                 "audioSelection": (self.audioSelection, "Audio Options..."),
457                         })
458
459         def audioSelection(self):
460                 service = self.session.nav.getCurrentService()
461                 audio = service.audioTracks()
462                 n = audio.getNumberOfTracks()
463                 if n > 0:
464                         self.session.open(AudioSelection, audio)
465
466 class InfoBarAdditionalInfo:
467         def __init__(self):
468                 self["DolbyActive"] = PixmapConditional()
469                 # TODO: get the info from c++ somehow
470                 self["DolbyActive"].setConnect(lambda: False)
471                 
472                 self["CryptActive"] = PixmapConditional()
473                 # TODO: get the info from c++ somehow
474                 self["CryptActive"].setConnect(lambda: False)
475                 
476                 self["FormatActive"] = PixmapConditional()
477                 # TODO: get the info from c++ somehow
478                 self["FormatActive"].setConnect(lambda: False)