add mute
[enigma2.git] / lib / python / Screens / InfoBar.py
1 from Screen import Screen
2 from ChannelSelection import ChannelSelection
3 from Components.Clock import Clock
4 from Components.ActionMap import ActionMap
5 from Components.Button import Button
6 from Components.ServiceName import ServiceName
7 from Components.EventInfo import EventInfo
8 from Components.ServicePosition import ServicePosition
9 from Components.config import configfile
10
11 from Screens.MessageBox import MessageBox
12 from Screens.MovieSelection import MovieSelection
13 from Screens.Volume import Volume
14
15 from enigma import *
16
17 import time
18
19 # hack alert!
20 from Menu import MainMenu, mdom
21
22 class InfoBar(Screen):
23         STATE_HIDDEN = 0
24         STATE_HIDING = 1
25         STATE_SHOWING = 2
26         STATE_SHOWN = 3
27         
28         def __init__(self, session):
29                 Screen.__init__(self, session)
30
31                 #instantiate forever
32                 self.servicelist = self.session.instantiateDialog(ChannelSelection)
33                 
34                 self.state = self.STATE_HIDDEN
35                 
36                 self.volumeDialog = self.session.instantiateDialog(Volume)
37                 
38                 self.hideTimer = eTimer()
39                 self.hideTimer.timeout.get().append(self.doTimerHide)
40                 #self.hideTimer.start(1000)
41                 
42                 self.hideVolTimer = eTimer()
43                 self.hideVolTimer.timeout.get().append(self.volHide)
44
45                 self["actions"] = ActionMap( [ "InfobarActions" ], 
46                         {
47                                 "switchChannelUp": self.switchChannelUp,
48                                 "switchChannelDown": self.switchChannelDown,
49                                 "mainMenu": self.mainMenu,
50                                 "zapUp": self.zapUp,
51                                 "zapDown": self.zapDown,
52                                 "volumeUp": self.volUp,
53                                 "volumeDown": self.volDown,
54                                 "volumeMute": self.volMute,
55                                 "instantRecord": self.instantRecord,
56                                 "hide": self.hide,
57                                 "toggleShow": self.toggleShow,
58                                 "showMovies": self.showMovies,
59                                 "quit": self.quit
60                         })
61 #               self["okbutton"] = Button("mainMenu", [self.mainMenu])
62                 
63                 self["CurrentTime"] = Clock()
64                 # ServicePosition(self.session.nav, ServicePosition.TYPE_REMAINING)
65                 # Clock()
66
67                 self["ServiceName"] = ServiceName(self.session.nav)
68                 
69                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
70                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
71
72                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
73                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
74                 
75                 self.recording = None
76                 
77                 self.pos = 0
78         
79         def mainMenu(self):
80                 print "loading mainmenu XML..."
81                 menu = mdom.childNodes[0]
82                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
83                 self.session.open(MainMenu, menu, menu.childNodes)
84
85         def switchChannelUp(self):      
86                 self.servicelist.moveUp()
87                 self.session.execDialog(self.servicelist)
88
89         def switchChannelDown(self):    
90                 self.servicelist.moveDown()
91                 self.session.execDialog(self.servicelist)
92
93         def hide(self): 
94                 self.instance.hide()
95
96         def doTimerHide(self):
97                 if self.state == self.STATE_SHOWN:
98                         self.instance.hide()
99                         self.state = self.STATE_HIDDEN
100
101         def toggleShow(self):
102                 if self.state == self.STATE_SHOWN:
103                         self.instance.hide()
104                         #pls check animation support, sorry
105 #                       self.startHide()
106                         self.state = self.STATE_HIDDEN
107                 else:
108                         self.instance.show()
109 #                       self.startShow()
110                         self.state = self.STATE_SHOWN
111                         #TODO: make it customizable
112                         self.hideTimer.start(5000)
113
114         def     zapUp(self):
115                 self.servicelist.moveUp()
116                 self.servicelist.zap()
117
118         def     zapDown(self):
119                 self.servicelist.moveDown()
120                 self.servicelist.zap()
121
122         def     volUp(self):
123                 eDVBVolumecontrol.getInstance().volumeUp()
124                 self.volumeDialog.instance.show()
125                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
126                 self.hideVolTimer.start(3000)
127
128         def     volDown(self):
129                 eDVBVolumecontrol.getInstance().volumeDown()
130                 self.volumeDialog.instance.show()
131                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
132                 self.hideVolTimer.start(3000)
133                 
134         def volHide(self):
135                 self.volumeDialog.instance.hide()
136
137         def startShow(self):
138                 self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
139                 self.state = self.STATE_SHOWN
140         
141         def startHide(self):
142                 self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
143                 self.state = self.STATE_HIDDEN
144
145         def     volMute(self):
146                 eDVBVolumecontrol.getInstance().volumeToggleMute()
147                 #self.volumeBar.setValue(eDVBVolumecontrol.getInstance().getVolume())
148                 self.volumeDialog.instance.show()
149                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
150                 self.hideVolTimer.start(3000)
151
152         def     quit(self):
153                 configfile.save()
154                 quitMainloop()
155         
156         def stopCurrentRecording(self): 
157                 print "remove entry"
158                 self.session.nav.RecordTimer.removeEntry(self.recording)
159                 self.recording = None
160         
161         def startInstantRecording(self):
162                 serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
163                         
164                 # try to get event info
165                 epg = None
166                 try:
167                         service = self.session.nav.getCurrentService()
168                         info = service.info()
169                         ev = info.getEvent(0)
170                         epg = ev
171                 except:
172                         pass
173                 
174                 # fix me, description. 
175                 self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 30, serviceref, epg, "instant record")
176
177         def recordQuestionCallback(self, answer):
178                 if answer == False:
179                         return
180                 
181                 if self.recording != None:
182                         self.stopCurrentRecording()
183                 else:
184                         self.startInstantRecording()
185
186         def instantRecord(self):
187                 if self.recording != None:
188                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Do you want to stop the current\n(instant) recording?")
189                 else:
190                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Start recording?")
191
192         def showMovies(self):
193                 self.session.open(MovieSelection)