working on move, edit mode and add remove service to context menu
[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.standbyblocked = 0
169                 self.powerKeyTimer.start(3000)
170
171         def powerup(self):
172                 self.powerKeyTimer.stop()
173                 if self.standbyblocked == 0:
174                         self.standbyblocked = 1
175                         self.session.open(Standby, self)
176                         
177
178         def keyNumberGlobal(self, number):
179                 print "You pressed number " + str(number)
180                 self.session.open(NumberZap, number)
181
182         def switchChannelUp(self):      
183                 self.servicelist.moveUp()
184                 self.session.execDialog(self.servicelist)
185
186         def switchChannelDown(self):    
187                 self.servicelist.moveDown()
188                 self.session.execDialog(self.servicelist)
189
190         def hide(self): 
191                 self.instance.hide()
192
193         def doTimerHide(self):
194                 if self.state == self.STATE_SHOWN:
195                         self.instance.hide()
196                         self.state = self.STATE_HIDDEN
197
198         def toggleShow(self):
199                 if self.state == self.STATE_SHOWN:
200                         self.instance.hide()
201                         #pls check animation support, sorry
202 #                       self.startHide()
203                         self.state = self.STATE_HIDDEN
204                 else:
205                         self.instance.show()
206 #                       self.startShow()
207                         self.state = self.STATE_SHOWN
208                         #TODO: make it customizable
209                         self.hideTimer.start(5000)
210
211         def     zapUp(self):
212                 self.servicelist.moveUp()
213                 self.servicelist.zap()
214
215         def     zapDown(self):
216                 self.servicelist.moveDown()
217                 self.servicelist.zap()
218
219         def     volUp(self):
220                 eDVBVolumecontrol.getInstance().volumeUp()
221                 self.volumeDialog.instance.show()
222                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
223                 self.hideVolTimer.start(3000)
224
225         def     volDown(self):
226                 eDVBVolumecontrol.getInstance().volumeDown()
227                 self.volumeDialog.instance.show()
228                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
229                 self.hideVolTimer.start(3000)
230                 
231         def volHide(self):
232                 self.volumeDialog.instance.hide()
233
234         def startShow(self):
235                 self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
236                 self.state = self.STATE_SHOWN
237         
238         def startHide(self):
239                 self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
240                 self.state = self.STATE_HIDDEN
241
242         def     volMute(self):
243                 eDVBVolumecontrol.getInstance().volumeToggleMute()
244                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
245                 
246                 if (eDVBVolumecontrol.getInstance().isMuted()):
247                         self.muteDialog.instance.show()
248                 else:
249                         self.muteDialog.instance.hide()
250
251         def showEPGList(self):
252                 ref=self.session.nav.getCurrentlyPlayingServiceReference()
253                 ptr=eEPGCache.getInstance()
254                 if ptr.startTimeQuery(ref) != -1:
255                         self.session.open(EPGSelection, ref)
256                 else:
257                         print 'no epg for service', ref.toString()
258
259         def quit(self):
260                 #       self.session.open(Standby, self)
261                 configfile.save()
262                 quitMainloop()
263         
264         def stopCurrentRecording(self): 
265                 print "remove entry"
266                 self.session.nav.RecordTimer.removeEntry(self.recording)
267                 self.recording = None
268         
269         def startInstantRecording(self):
270                 serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
271                         
272                 # try to get event info
273                 epg = None
274                 try:
275                         service = self.session.nav.getCurrentService()
276                         info = service.info()
277                         ev = info.getEvent(0)
278                         epg = ev
279                 except:
280                         pass
281                 
282                 # fix me, description. 
283                 self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 3600, serviceref, epg, "instant record")
284
285         def recordQuestionCallback(self, answer):
286                 if answer == False:
287                         return
288                 
289                 if self.recording != None:
290                         self.stopCurrentRecording()
291                 else:
292                         self.startInstantRecording()
293
294         def instantRecord(self):
295                 if self.recording != None:
296                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Do you want to stop the current\n(instant) recording?")
297                 else:
298                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Start recording?")
299
300         def showMovies(self):
301                 self.session.open(MovieSelection)
302
303         def pauseService(self):
304                 self.session.nav.pause(1)
305                 
306         def unPauseService(self):
307                 self.session.nav.pause(0)
308         
309         def doSeek(self, dir, seektime):
310                 service = self.session.nav.getCurrentService()
311                 if service is None:
312                         return
313                 
314                 seekable = service.seek()
315                 if seekable is None:
316                         return
317                 seekable.seekRelative(dir, 90 * seektime)
318
319         def seekFwd(self):
320                 self.doSeek(+1, 10000)
321         
322         def seekBack(self):
323                 self.doSeek(-1, 10000)