skip 1 minute with left/right
[enigma2.git] / lib / python / Screens / InfoBarGenerics.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.ActionMap import NumberActionMap
4 from Components.Label import Label
5 from Components.config import configfile
6 from ChannelSelection import ChannelSelection
7
8 from Components.ServiceName import ServiceName
9 from Components.EventInfo import EventInfo
10
11 from EpgSelection import EPGSelection
12
13 from Screens.MessageBox import MessageBox
14 from Screens.Volume import Volume
15 from Screens.Mute import Mute
16 from Screens.Standby import Standby
17
18 #from enigma import eTimer, eDVBVolumecontrol, quitMainloop
19 from enigma import *
20
21 import time
22
23 # hack alert!
24 from Menu import MainMenu, mdom
25
26 class InfoBarVolumeControl:
27         """Volume control, handles volUp, volDown, volMute actions and display 
28         a corresponding dialog"""
29         
30         def __init__(self):
31                 self["VolumeActions"] = ActionMap( ["InfobarVolumeActions"] ,
32                         {
33                                 "volumeUp": self.volUp,
34                                 "volumeDown": self.volDown,
35                                 "volumeMute": self.volMute,
36                         })
37
38                 self.volumeDialog = self.session.instantiateDialog(Volume)
39                 self.muteDialog = self.session.instantiateDialog(Mute)
40
41                 self.hideVolTimer = eTimer()
42                 self.hideVolTimer.timeout.get().append(self.volHide)
43         
44         def     volUp(self):
45                 eDVBVolumecontrol.getInstance().volumeUp()
46                 self.volumeDialog.instance.show()
47                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
48                 self.hideVolTimer.start(3000)
49
50         def     volDown(self):
51                 eDVBVolumecontrol.getInstance().volumeDown()
52                 self.volumeDialog.instance.show()
53                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
54                 self.hideVolTimer.start(3000)
55                 
56         def volHide(self):
57                 self.volumeDialog.instance.hide()
58
59         def     volMute(self):
60                 eDVBVolumecontrol.getInstance().volumeToggleMute()
61                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
62                 
63                 if (eDVBVolumecontrol.getInstance().isMuted()):
64                         self.muteDialog.instance.show()
65                 else:
66                         self.muteDialog.instance.hide()
67
68 class InfoBarShowHide:
69         """ InfoBar show/hide control, accepts toggleShow and hide actions, might start
70         fancy animations. """
71         STATE_HIDDEN = 0
72         STATE_HIDING = 1
73         STATE_SHOWING = 2
74         STATE_SHOWN = 3
75         
76         def __init__(self):
77                 self["ShowHideActions"] = ActionMap( ["InfobarShowHideActions"] ,
78                         {
79                                 "toggleShow": self.toggleShow,
80                                 "hide": self.hide,
81                         })
82
83                 self.state = self.STATE_HIDDEN
84                 
85                 self.hideTimer = eTimer()
86                 self.hideTimer.timeout.get().append(self.doTimerHide)
87                 #self.hideTimer.start(1000)
88
89         def hide(self): 
90                 self.instance.hide()
91
92         def doTimerHide(self):
93                 if self.state == self.STATE_SHOWN:
94                         self.instance.hide()
95                         self.state = self.STATE_HIDDEN
96
97         def toggleShow(self):
98                 if self.state == self.STATE_SHOWN:
99                         self.instance.hide()
100                         #pls check animation support, sorry
101 #                       self.startHide()
102                         self.state = self.STATE_HIDDEN
103                 else:
104                         self.instance.show()
105 #                       self.startShow()
106                         self.state = self.STATE_SHOWN
107                         #TODO: make it customizable
108                         self.hideTimer.start(5000)
109
110         def startShow(self):
111                 self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
112                 self.state = self.STATE_SHOWN
113         
114         def startHide(self):
115                 self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
116                 self.state = self.STATE_HIDDEN
117
118 class NumberZap(Screen):
119         def quit(self):
120                 self.Timer.stop()
121                 self.close()
122
123         def keyOK(self):
124                 self.Timer.stop()
125                 print "do the action here"
126                 self.close()
127
128         def keyNumberGlobal(self, number):
129                 self.Timer.start(3000)          #reset timer
130                 self.field = self.field + str(number)
131                 self["number"].setText(self.field)
132                 if len(self.field) >= 4:
133                         self.keyOK()
134
135         def __init__(self, session, number):
136                 Screen.__init__(self, session)
137                 self.field = str(number)
138                 
139                 self["number"] = Label(self.field)
140
141                 self["actions"] = NumberActionMap( [ "SetupActions" ], 
142                         {
143                                 "cancel": self.quit,
144                                 "ok": self.keyOK,
145                                 "1": self.keyNumberGlobal,
146                                 "2": self.keyNumberGlobal,
147                                 "3": self.keyNumberGlobal,
148                                 "4": self.keyNumberGlobal,
149                                 "5": self.keyNumberGlobal,
150                                 "6": self.keyNumberGlobal,
151                                 "7": self.keyNumberGlobal,
152                                 "8": self.keyNumberGlobal,
153                                 "9": self.keyNumberGlobal,
154                                 "0": self.keyNumberGlobal
155                         })
156
157                 self.Timer = eTimer()
158                 self.Timer.timeout.get().append(self.keyOK)
159                 self.Timer.start(3000)
160
161 class InfoBarPowerKey:
162         """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
163         
164         def __init__(self):
165                 self.powerKeyTimer = eTimer()
166                 self.powerKeyTimer.timeout.get().append(self.powertimer)
167                 self["PowerKeyActions"] = ActionMap( ["PowerKeyActions"],
168                         {
169                                 "powerdown": self.powerdown,
170                                 "powerup": self.powerup,
171                         })
172
173         def powertimer(self):   
174                 print "PowerOff - Now!"
175                 self.quit()
176         
177         def powerdown(self):
178                 self.standbyblocked = 0
179                 self.powerKeyTimer.start(3000)
180
181         def powerup(self):
182                 self.powerKeyTimer.stop()
183                 if self.standbyblocked == 0:
184                         self.standbyblocked = 1
185                         self.session.open(Standby, self)
186
187         def quit(self):
188                 #       self.session.open(Standby, self)
189                 ref = self.session.nav.getCurrentlyPlayingServiceReference()
190                 if ref is not None:
191                         refstr = ref.toString()
192                 else:
193                         refstr = ""     
194                 
195                 #configfile.save()
196                 quitMainloop(0)
197
198
199 class InfoBarNumberZap:
200         """ Handles an initial number for NumberZapping """
201         def __init__(self):
202                 self["NumberZapActions"] = NumberActionMap( [ "NumberZapActions"],
203                         {
204                                 "1": self.keyNumberGlobal,
205                                 "2": self.keyNumberGlobal,
206                                 "3": self.keyNumberGlobal,
207                                 "4": self.keyNumberGlobal,
208                                 "5": self.keyNumberGlobal,
209                                 "6": self.keyNumberGlobal,
210                                 "7": self.keyNumberGlobal,
211                                 "8": self.keyNumberGlobal,
212                                 "9": self.keyNumberGlobal,
213                                 "0": self.keyNumberGlobal,
214                         })
215
216         def keyNumberGlobal(self, number):
217                 print "You pressed number " + str(number)
218                 self.session.open(NumberZap, number)
219
220 class InfoBarChannelSelection:
221         """ ChannelSelection - handles the channelSelection dialog and the initial 
222         channelChange actions which open the channelSelection dialog """
223         def __init__(self):
224                 #instantiate forever
225                 self.servicelist = self.session.instantiateDialog(ChannelSelection)
226
227                 self["ChannelSelectActions"] = ActionMap( ["InfobarChannelSelection"],
228                         {
229                                 "switchChannelUp": self.switchChannelUp,
230                                 "switchChannelDown": self.switchChannelDown,
231                                 "zapUp": self.zapUp,
232                                 "zapDown": self.zapDown,
233                         })
234                         
235         def switchChannelUp(self):      
236                 self.servicelist.moveUp()
237                 self.session.execDialog(self.servicelist)
238
239         def switchChannelDown(self):    
240                 self.servicelist.moveDown()
241                 self.session.execDialog(self.servicelist)
242
243         def     zapUp(self):
244                 self.servicelist.moveUp()
245                 self.servicelist.zap()
246
247         def     zapDown(self):
248                 self.servicelist.moveDown()
249                 self.servicelist.zap()
250
251 class InfoBarMenu:
252         """ Handles a menu action, to open the (main) menu """
253         def __init__(self):
254                 self["MenuActions"] = ActionMap( [ "InfobarMenuActions" ], 
255                         {
256                                 "mainMenu": self.mainMenu,
257                         })
258
259         def mainMenu(self):
260                 print "loading mainmenu XML..."
261                 menu = mdom.childNodes[0]
262                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
263                 self.session.open(MainMenu, menu, menu.childNodes)
264
265 class InfoBarEPG:
266         """ EPG - Opens an EPG list when the showEPGList action fires """
267         def __init__(self):
268                 self["EPGActions"] = ActionMap( [ "InfobarEPGActions" ], 
269                         {
270                                 "showEPGList": self.showEPGList,
271                         })
272
273         def showEPGList(self):
274                 ref=self.session.nav.getCurrentlyPlayingServiceReference()
275                 ptr=eEPGCache.getInstance()
276                 if ptr.startTimeQuery(ref) != -1:
277                         self.session.open(EPGSelection, ref)
278                 else:
279                         print 'no epg for service', ref.toString()
280
281 class InfoBarEvent:     
282         """provides a current/next event info display"""
283         def __init__(self):
284                 self["Event_Now_StartTime"] = EventInfo(self.session.nav, EventInfo.Now_StartTime)
285                 self["Event_Next_StartTime"] = EventInfo(self.session.nav, EventInfo.Next_StartTime)
286                                 
287                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
288                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
289
290                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
291                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
292
293 class InfoBarServiceName:
294         def __init__(self):
295                 self["ServiceName"] = ServiceName(self.session.nav)
296
297 class InfoBarPVR:
298         """handles PVR specific actions like seeking, pause"""
299         def __init__(self):
300                 self["PVRActions"] = ActionMap( [ "InfobarPVRActions" ], 
301                         {
302                                 "pauseService": self.pauseService,
303                                 "unPauseService": self.unPauseService,
304                                 
305                                 "seekFwd": self.seekFwd,
306                                 "seekBack": self.seekBack,
307                         })
308                 
309         def pauseService(self):
310                 self.session.nav.pause(1)
311                 
312         def unPauseService(self):
313                 self.session.nav.pause(0)
314         
315         def doSeek(self, dir, seektime):
316                 service = self.session.nav.getCurrentService()
317                 if service is None:
318                         return
319                 
320                 seekable = service.seek()
321                 if seekable is None:
322                         return
323                 seekable.seekRelative(dir, 90 * seektime)
324
325         def seekFwd(self):
326                 self.doSeek(+1, 60000)
327         
328         def seekBack(self):
329                 self.doSeek(-1, 60000)
330
331 class InfoBarInstantRecord:
332         """Instant Record - handles the instantRecord action in order to 
333         start/stop instant records"""
334         def __init__(self):
335                 self["InstnantRecordActions"] = ActionMap( [ "InfobarInstantRecord" ],
336                         {
337                                 "instantRecord": self.instantRecord,
338                         })
339                 self.recording = None
340
341         def stopCurrentRecording(self): 
342                 self.session.nav.RecordTimer.removeEntry(self.recording)
343                 self.recording = None
344         
345         def startInstantRecording(self):
346                 serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
347                         
348                 # try to get event info
349                 epg = None
350                 try:
351                         service = self.session.nav.getCurrentService()
352                         info = service.info()
353                         ev = info.getEvent(0)
354                         epg = ev
355                 except:
356                         pass
357                 
358                 # fix me, description. 
359                 self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 3600, serviceref, epg, "instant record")
360
361         def recordQuestionCallback(self, answer):
362                 if answer == False:
363                         return
364                 
365                 if self.recording != None:
366                         self.stopCurrentRecording()
367                 else:
368                         self.startInstantRecording()
369
370         def instantRecord(self):
371                 if self.recording != None:
372                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Do you want to stop the current\n(instant) recording?")
373                 else:
374                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Start recording?")
375
376 from Screens.AudioSelection import AudioSelection
377
378 class InfoBarAudioSelection:
379         def __init__(self):
380                 self["AudioSelectionAction"] = ActionMap( [ "InfobarAudioSelectionActions" ], 
381                         {
382                                 "audioSelection": self.audioSelection,
383                         })
384
385         def audioSelection(self):
386                 service = self.session.nav.getCurrentService()
387                 audio = service.audioTracks()
388                 n = audio.getNumberOfTracks()
389                 if n > 0:
390                         self.session.open(AudioSelection, audio)