volume-control:
[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
43                 self["actions"] = ActionMap( [ "InfobarActions" ], 
44                         {
45                                 "switchChannelUp": self.switchChannelUp,
46                                 "switchChannelDown": self.switchChannelDown,
47                                 "mainMenu": self.mainMenu,
48                                 "zapUp": self.zapUp,
49                                 "zapDown": self.zapDown,
50                                 "volumeUp": self.volUp,
51                                 "volumeDown": self.volDown,
52                                 "volumeMute": self.volMute,
53                                 "instantRecord": self.instantRecord,
54                                 "hide": self.hide,
55                                 "toggleShow": self.toggleShow,
56                                 "showMovies": self.showMovies,
57                                 "quit": self.quit
58                         })
59 #               self["okbutton"] = Button("mainMenu", [self.mainMenu])
60                 
61                 self["CurrentTime"] = Clock()
62                 # ServicePosition(self.session.nav, ServicePosition.TYPE_REMAINING)
63                 # Clock()
64
65                 self["ServiceName"] = ServiceName(self.session.nav)
66                 
67                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
68                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
69
70                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
71                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
72                 
73                 self.recording = None
74                 
75                 self.pos = 0
76         
77         def mainMenu(self):
78                 print "loading mainmenu XML..."
79                 menu = mdom.childNodes[0]
80                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
81                 self.session.open(MainMenu, menu, menu.childNodes)
82
83         def switchChannelUp(self):      
84                 self.servicelist.moveUp()
85                 self.session.execDialog(self.servicelist)
86
87         def switchChannelDown(self):    
88                 self.servicelist.moveDown()
89                 self.session.execDialog(self.servicelist)
90
91         def hide(self): 
92                 self.instance.hide()
93
94         def doTimerHide(self):
95                 if self.state == self.STATE_SHOWN:
96                         self.instance.hide()
97                         self.state = self.STATE_HIDDEN
98
99         def toggleShow(self):
100                 if self.state == self.STATE_SHOWN:
101                         self.instance.hide()
102                         #pls check animation support, sorry
103 #                       self.startHide()
104                         self.state = self.STATE_HIDDEN
105                 else:
106                         self.instance.show()
107 #                       self.startShow()
108                         self.state = self.STATE_SHOWN
109                         #TODO: make it customizable
110                         self.hideTimer.start(5000)
111
112         def     zapUp(self):
113                 self.servicelist.moveUp()
114                 self.servicelist.zap()
115
116         def     zapDown(self):
117                 self.servicelist.moveDown()
118                 self.servicelist.zap()
119
120         def     volUp(self):
121                 eDVBVolumecontrol.getInstance().volumeUp()
122                 self.volumeDialog.instance.show()
123                 #self.volumeDialog.instance.setValue(eDVBVolumecontrol.getInstance().getVolume())
124                 self.hideVolTimer = eTimer()
125                 self.hideVolTimer.timeout.get().append(self.volHide)
126                 self.hideVolTimer.start(3000)
127
128         def     volDown(self):
129                 eDVBVolumecontrol.getInstance().volumeDown()
130                 #self.volumeDialog.instance.volumeBar.setValue(eDVBVolumecontrol.getInstance().getVolume())
131                 self.volumeDialog.instance.show()
132                 self.hideVolTimer = eTimer()
133                 self.hideVolTimer.timeout.get().append(self.volHide)
134                 self.hideVolTimer.start(3000)
135                 
136         def volHide(self):
137                 self.volumeDialog.instance.hide()
138
139         def startShow(self):
140                 self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
141                 self.state = self.STATE_SHOWN
142         
143         def startHide(self):
144                 self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
145                 self.state = self.STATE_HIDDEN
146
147         def     volMute(self):
148                 eDVBVolumecontrol.getInstance().volumeToggleMute()
149                 self.volumeBar.setValue(eDVBVolumecontrol.getInstance().getVolume())
150
151         def     quit(self):
152                 configfile.save()
153                 quitMainloop()
154         
155         def stopCurrentRecording(self): 
156                 print "remove entry"
157                 self.session.nav.RecordTimer.removeEntry(self.recording)
158                 self.recording = None
159         
160         def startInstantRecording(self):
161                 serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
162                         
163                 # try to get event info
164                 epg = None
165                 try:
166                         service = self.session.nav.getCurrentService()
167                         info = service.info()
168                         ev = info.getEvent(0)
169                         epg = ev
170                 except:
171                         pass
172                 
173                 # fix me, description. 
174                 self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 30, serviceref, epg, "instant record")
175
176         def recordQuestionCallback(self, answer):
177                 if answer == False:
178                         return
179                 
180                 if self.recording != None:
181                         self.stopCurrentRecording()
182                 else:
183                         self.startInstantRecording()
184
185         def instantRecord(self):
186                 if self.recording != None:
187                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Do you want to stop the current\n(instant) recording?")
188                 else:
189                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Start recording?")
190
191         def showMovies(self):
192                 self.session.open(MovieSelection)