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