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