414572238651665cd58f4ae322bda71b326e9af5
[vuplus_dvbapp] / lib / python / Screens / InfoBar.py
1 from Tools.Profile import profile
2
3 # workaround for required config entry dependencies.
4 from Screens.MovieSelection import MovieSelection
5
6 from Screen import Screen
7
8 profile("LOAD:enigma")
9 from enigma import iPlayableService
10
11 profile("LOAD:InfoBarGenerics")
12 from Screens.InfoBarGenerics import InfoBarShowHide, \
13         InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarRdsDecoder, \
14         InfoBarEPG, InfoBarSeek, InfoBarInstantRecord, InfoBarRedButton, \
15         InfoBarAudioSelection, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarUnhandledKey, \
16         InfoBarSubserviceSelection, InfoBarShowMovies, InfoBarTimeshift,  \
17         InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarSimpleEventView, \
18         InfoBarSummarySupport, InfoBarMoviePlayerSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions, \
19         InfoBarSubtitleSupport, InfoBarPiP, InfoBarPlugins, InfoBarServiceErrorPopupSupport, InfoBarJobman
20
21 profile("LOAD:InitBar_Components")
22 from Components.ActionMap import HelpableActionMap
23 from Components.config import config
24 from Components.ServiceEventTracker import ServiceEventTracker, InfoBarBase
25
26 profile("LOAD:HelpableScreen")
27 from Screens.HelpMenu import HelpableScreen
28
29 class InfoBar(InfoBarBase, InfoBarShowHide,
30         InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder,
31         InfoBarInstantRecord, InfoBarAudioSelection, InfoBarRedButton,
32         HelpableScreen, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarUnhandledKey,
33         InfoBarSubserviceSelection, InfoBarTimeshift, InfoBarSeek,
34         InfoBarSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions,
35         InfoBarPiP, InfoBarPlugins, InfoBarSubtitleSupport, InfoBarServiceErrorPopupSupport, InfoBarJobman,
36         Screen):
37         
38         ALLOW_SUSPEND = True
39         instance = None
40
41         def __init__(self, session):
42                 Screen.__init__(self, session)
43                 self["actions"] = HelpableActionMap(self, "InfobarActions",
44                         {
45                                 "showMovies": (self.showMovies, _("Play recorded movies...")),
46                                 "showRadio": (self.showRadio, _("Show the radio player...")),
47                                 "showTv": (self.showTv, _("Show the tv player...")),
48                                 "showSubtitle":(self.showSubtitle, _("Show the Subtitle...")),
49                         }, prio=2)
50                 
51                 self.allowPiP = True
52                 
53                 for x in HelpableScreen, \
54                                 InfoBarBase, InfoBarShowHide, \
55                                 InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder, \
56                                 InfoBarInstantRecord, InfoBarAudioSelection, InfoBarRedButton, InfoBarUnhandledKey, \
57                                 InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarSubserviceSelection, \
58                                 InfoBarTimeshift, InfoBarSeek, InfoBarSummarySupport, InfoBarTimeshiftState, \
59                                 InfoBarTeletextPlugin, InfoBarExtensions, InfoBarPiP, InfoBarSubtitleSupport, InfoBarJobman, \
60                                 InfoBarPlugins, InfoBarServiceErrorPopupSupport:
61                         x.__init__(self)
62
63                 self.helpList.append((self["actions"], "InfobarActions", [("showMovies", _("view recordings..."))]))
64                 self.helpList.append((self["actions"], "InfobarActions", [("showRadio", _("hear radio..."))]))
65
66                 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
67                         {
68                                 iPlayableService.evUpdatedEventInfo: self.__eventInfoChanged
69                         })
70
71                 self.current_begin_time=0
72                 assert InfoBar.instance is None, "class InfoBar is a singleton class and just one instance of this class is allowed!"
73                 InfoBar.instance = self
74
75         def __onClose(self):
76                 InfoBar.instance = None
77
78         def __eventInfoChanged(self):
79                 if self.execing:
80                         service = self.session.nav.getCurrentService()
81                         old_begin_time = self.current_begin_time
82                         info = service and service.info()
83                         ptr = info and info.getEvent(0)
84                         self.current_begin_time = ptr and ptr.getBeginTime() or 0
85                         if config.usage.show_infobar_on_event_change.value:
86                                 if old_begin_time and old_begin_time != self.current_begin_time:
87                                         self.doShow()
88
89         def __checkServiceStarted(self):
90                 self.__serviceStarted(True)
91                 self.onExecBegin.remove(self.__checkServiceStarted)
92
93         def serviceStarted(self):  #override from InfoBarShowHide
94                 new = self.servicelist.newServicePlayed()
95                 if self.execing:
96                         InfoBarShowHide.serviceStarted(self)
97                         self.current_begin_time=0
98                 elif not self.__checkServiceStarted in self.onShown and new:
99                         self.onShown.append(self.__checkServiceStarted)
100
101         def __checkServiceStarted(self):
102                 self.serviceStarted()
103                 self.onShown.remove(self.__checkServiceStarted)
104
105         def showTv(self):
106                 self.showTvChannelList(True)
107
108         def showRadio(self):
109                 if config.usage.e1like_radio_mode.value:
110                         self.showRadioChannelList(True)
111                 else:
112                         self.rds_display.hide() # in InfoBarRdsDecoder
113                         from Screens.ChannelSelection import ChannelSelectionRadio
114                         self.session.openWithCallback(self.ChannelSelectionRadioClosed, ChannelSelectionRadio, self)
115
116         def ChannelSelectionRadioClosed(self, *arg):
117                 self.rds_display.show()  # in InfoBarRdsDecoder
118
119         def showMovies(self):
120                 from Screens.MovieSelection import MovieSelection
121                 self.session.openWithCallback(self.movieSelected, MovieSelection)
122
123         def movieSelected(self, service):
124                 if service is not None:
125                         self.session.open(MoviePlayer, service)
126
127         def showSubtitle(self):
128                 from Screens.Subtitles import Subtitles
129                 self.session.open(Subtitles)
130
131 class MoviePlayer(InfoBarBase, InfoBarShowHide, \
132                 InfoBarMenu, \
133                 InfoBarSeek, InfoBarShowMovies, InfoBarAudioSelection, HelpableScreen, InfoBarNotifications,
134                 InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarSimpleEventView,
135                 InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, Screen, InfoBarTeletextPlugin,
136                 InfoBarServiceErrorPopupSupport, InfoBarExtensions, InfoBarPlugins, InfoBarPiP):
137
138         ENABLE_RESUME_SUPPORT = True
139         ALLOW_SUSPEND = True
140                 
141         def __init__(self, session, service):
142                 Screen.__init__(self, session)
143                 
144                 self["actions"] = HelpableActionMap(self, "MoviePlayerActions",
145                         {
146                                 "showSubtitle":(self.showSubtitle, _("Show the Subtitle...")),
147                                 "leavePlayer": (self.leavePlayer, _("leave movie player..."))
148                         })
149                 
150                 self.allowPiP = False
151                 
152                 for x in HelpableScreen, InfoBarShowHide, InfoBarMenu, \
153                                 InfoBarBase, InfoBarSeek, InfoBarShowMovies, \
154                                 InfoBarAudioSelection, InfoBarNotifications, InfoBarSimpleEventView, \
155                                 InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, \
156                                 InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, \
157                                 InfoBarTeletextPlugin, InfoBarServiceErrorPopupSupport, InfoBarExtensions, \
158                                 InfoBarPlugins, InfoBarPiP:
159                         x.__init__(self)
160
161                 self.lastservice = session.nav.getCurrentlyPlayingServiceReference()
162                 session.nav.playService(service)
163                 self.returning = False
164                 self.onClose.append(self.__onClose)
165
166         def __onClose(self):
167                 self.session.nav.playService(self.lastservice)
168
169         def handleLeave(self, how):
170                 self.is_closing = True
171                 if how == "ask":
172                         if config.usage.setup_level.index < 2: # -expert
173                                 list = (
174                                         (_("Yes"), "quit"),
175                                         (_("No"), "continue")
176                                 )
177                         else:
178                                 list = (
179                                         (_("Yes"), "quit"),
180                                         (_("Yes, returning to movie list"), "movielist"),
181                                         (_("Yes, and delete this movie"), "quitanddelete"),
182                                         (_("No"), "continue"),
183                                         (_("No, but restart from begin"), "restart")
184                                 )
185
186                         from Screens.ChoiceBox import ChoiceBox
187                         self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list)
188                 else:
189                         self.leavePlayerConfirmed([True, how])
190
191         def leavePlayer(self):
192                 self.handleLeave(config.usage.on_movie_stop.value)
193
194         def deleteConfirmed(self, answer):
195                 if answer:
196                         self.leavePlayerConfirmed((True, "quitanddeleteconfirmed"))
197
198         def leavePlayerConfirmed(self, answer):
199                 answer = answer and answer[1]
200
201                 if answer in ("quitanddelete", "quitanddeleteconfirmed"):
202                         ref = self.session.nav.getCurrentlyPlayingServiceReference()
203                         from enigma import eServiceCenter
204                         serviceHandler = eServiceCenter.getInstance()
205                         info = serviceHandler.info(ref)
206                         name = info and info.getName(ref) or _("this recording")
207
208                         if answer == "quitanddelete":
209                                 from Screens.MessageBox import MessageBox
210                                 self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete %s?") % name)
211                                 return
212
213                         elif answer == "quitanddeleteconfirmed":
214                                 offline = serviceHandler.offlineOperations(ref)
215                                 if offline.deleteFromDisk(0):
216                                         from Screens.MessageBox import MessageBox
217                                         self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
218                                         return
219
220                 if answer in ("quit", "quitanddeleteconfirmed"):
221                         self.close()
222                 elif answer == "movielist":
223                         ref = self.session.nav.getCurrentlyPlayingServiceReference()
224                         self.returning = True
225                         from Screens.MovieSelection import MovieSelection
226                         self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
227                         self.session.nav.stopService()
228                 elif answer == "restart":
229                         self.doSeek(0)
230                         self.setSeekState(self.SEEK_STATE_PLAY)
231
232         def doEofInternal(self, playing):
233                 if not self.execing:
234                         return
235                 if not playing :
236                         return
237                 self.handleLeave(config.usage.on_movie_eof.value)
238
239         def showMovies(self):
240                 ref = self.session.nav.getCurrentlyPlayingServiceReference()
241                 from Screens.MovieSelection import MovieSelection
242                 self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
243
244         def movieSelected(self, service):
245                 if service is not None:
246                         self.is_closing = False
247                         self.session.nav.playService(service)
248                         self.returning = False
249                 elif self.returning:
250                         self.close()
251
252         def showSubtitle(self):
253                 from Screens.Subtitles import Subtitles
254                 self.session.open(Subtitles)