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