movieplayer_select.patch by Moritz Venn
[enigma2.git] / lib / python / Screens / InfoBar.py
1 from Tools.Profile import profile, profile_final
2
3 from Screen import Screen
4
5 profile("LOAD:enigma")
6 from enigma import iPlayableService
7
8 profile("LOAD:ChannelSelectionRadio")
9 from Screens.ChannelSelection import ChannelSelectionRadio
10 profile("LOAD:MovieSelection")
11 from Screens.MovieSelection import MovieSelection
12 profile("LOAD:ChoiceBox")
13 from Screens.ChoiceBox import ChoiceBox
14
15 profile("LOAD:InfoBarGenerics")
16 from Screens.InfoBarGenerics import InfoBarShowHide, \
17         InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarRdsDecoder, \
18         InfoBarEPG, InfoBarEvent, InfoBarServiceName, InfoBarSeek, InfoBarInstantRecord, \
19         InfoBarAudioSelection, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, \
20         InfoBarSubserviceSelection, InfoBarTuner, InfoBarShowMovies, InfoBarTimeshift,  \
21         InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarSimpleEventView, \
22         InfoBarSummarySupport, InfoBarMoviePlayerSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions, \
23         InfoBarSubtitleSupport, InfoBarPiP, InfoBarPlugins, InfoBarSleepTimer, InfoBarServiceErrorPopupSupport
24
25 profile("LOAD:InitBar_Components")
26 from Components.Sources.Source import ObsoleteSource
27 from Components.ActionMap import HelpableActionMap
28 from Components.config import config
29 from Components.ServiceEventTracker import ServiceEventTracker
30
31 profile("LOAD:HelpableScreen")
32 from Screens.HelpMenu import HelpableScreen
33
34 class InfoBar(InfoBarShowHide,
35         InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder,
36         InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord, InfoBarAudioSelection, 
37         HelpableScreen, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish,
38         InfoBarSubserviceSelection, InfoBarTuner, InfoBarTimeshift, InfoBarSeek,
39         InfoBarSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions,
40         InfoBarPiP, InfoBarPlugins, InfoBarSubtitleSupport, InfoBarSleepTimer, InfoBarServiceErrorPopupSupport,
41         Screen):
42         
43         ALLOW_SUSPEND = True
44
45         def __init__(self, session):
46                 Screen.__init__(self, session)
47
48                 self["actions"] = HelpableActionMap(self, "InfobarActions",
49                         {
50                                 "showMovies": (self.showMovies, _("Play recorded movies...")),
51                                 "showRadio": (self.showRadio, _("Show the radio player...")),
52                                 "showTv": (self.showTv, _("Show the tv player...")),
53                         }, prio=2)
54                 
55                 for x in HelpableScreen, \
56                                 InfoBarShowHide, \
57                                 InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder, \
58                                 InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord, InfoBarAudioSelection, \
59                                 InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarSubserviceSelection, \
60                                 InfoBarTuner, InfoBarTimeshift, InfoBarSeek, InfoBarSummarySupport, InfoBarTimeshiftState, \
61                                 InfoBarTeletextPlugin, InfoBarExtensions, InfoBarPiP, InfoBarSubtitleSupport, InfoBarSleepTimer, \
62                                 InfoBarPlugins, InfoBarServiceErrorPopupSupport:
63                         x.__init__(self)
64
65                 self.helpList.append((self["actions"], "InfobarActions", [("showMovies", _("view recordings..."))]))
66                 self.helpList.append((self["actions"], "InfobarActions", [("showRadio", _("hear radio..."))]))
67
68                 self["CurrentTime"] = ObsoleteSource(new_source = "global.CurrentTime", removal_date = "2008-01")
69
70                 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
71                         {
72                                 iPlayableService.evUpdatedEventInfo: self.__eventInfoChanged
73                         })
74
75                 self.current_begin_time=0
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                         self.session.openWithCallback(self.ChannelSelectionRadioClosed, ChannelSelectionRadio, self)
113
114         def ChannelSelectionRadioClosed(self, *arg):
115                 self.rds_display.show()  # in InfoBarRdsDecoder
116
117         def showMovies(self):
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(InfoBarShowHide, \
125                 InfoBarMenu, \
126                 InfoBarServiceName, InfoBarSeek, InfoBarShowMovies, InfoBarAudioSelection, HelpableScreen, InfoBarNotifications,
127                 InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarSimpleEventView,
128                 InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, Screen, InfoBarTeletextPlugin,
129                 InfoBarServiceErrorPopupSupport):
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                                 InfoBarServiceName, InfoBarSeek, InfoBarShowMovies, \
144                                 InfoBarAudioSelection, InfoBarNotifications, InfoBarSimpleEventView, \
145                                 InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, \
146                                 InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, \
147                                 InfoBarTeletextPlugin, InfoBarServiceErrorPopupSupport:
148                         x.__init__(self)
149
150                 self.lastservice = self.session.nav.getCurrentlyPlayingServiceReference()
151                 self.session.nav.playService(service)
152                 self.returning = False
153
154         def leavePlayer(self):
155                 self.is_closing = True
156
157                 if config.usage.on_movie_stop.value == "ask":
158                         list = []
159                         list.append((_("Yes"), "quit"))
160                         if config.usage.setup_level.index >= 2: # expert+
161                                 list.append((_("Yes, returning to movie list"), "movielist"))
162                         list.append((_("No"), "continue"))
163                         if config.usage.setup_level.index >= 2: # expert+
164                                 list.append((_("No, but restart from begin"), "restart"))
165                         self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list)
166                 else:
167                         self.leavePlayerConfirmed([True, config.usage.on_movie_stop.value])
168
169         def leavePlayerConfirmed(self, answer):
170                 answer = answer and answer[1]
171                 if answer == "quit":
172                         self.session.nav.playService(self.lastservice)
173                         config.movielist.last_videodir.cancel()
174                         self.close()
175                 elif answer == "movielist":
176                         ref = self.session.nav.getCurrentlyPlayingServiceReference()
177                         self.returning = True
178                         self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
179                         self.session.nav.playService(self.lastservice)
180                 elif answer == "restart":
181                         self.doSeek(0)
182
183         def doEofInternal(self, playing):
184                 if not playing:
185                         return
186                 self.is_closing = True
187                 if config.usage.on_movie_eof.value == "ask":
188                         list = []
189                         list.append((_("Yes"), "quit"))
190                         if config.usage.setup_level.index >= 2: # expert+
191                                 list.append((_("Yes, returning to movie list"), "movielist"))
192                         list.append((_("No"), "continue"))
193                         if config.usage.setup_level.index >= 2: # expert+
194                                 list.append((_("No, but restart from begin"), "restart"))
195                         self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list)
196                 else:
197                         self.leavePlayerConfirmed([True, config.usage.on_movie_eof.value])
198
199         def showMovies(self):
200                 ref = self.session.nav.getCurrentlyPlayingServiceReference()
201                 self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
202
203         def movieSelected(self, service):
204                 if service is not None:
205                         self.is_closing = False
206                         self.session.nav.playService(service)
207                         self.returning = False
208                 elif self.returning:
209                         self.close()