take care of hotplug events just when the infobar is execing (no other menu
[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, InfoBarSeek, InfoBarInstantRecord, \
19         InfoBarAudioSelection, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, \
20         InfoBarSubserviceSelection, 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.ActionMap import HelpableActionMap
27 from Components.config import config
28 from Components.ServiceEventTracker import ServiceEventTracker, InfoBarBase
29
30 profile("LOAD:HelpableScreen")
31 from Screens.HelpMenu import HelpableScreen
32
33 class InfoBar(InfoBarBase, InfoBarShowHide,
34         InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder,
35         InfoBarInstantRecord, InfoBarAudioSelection, 
36         HelpableScreen, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish,
37         InfoBarSubserviceSelection, InfoBarTimeshift, InfoBarSeek,
38         InfoBarSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions,
39         InfoBarPiP, InfoBarPlugins, InfoBarSubtitleSupport, InfoBarSleepTimer, InfoBarServiceErrorPopupSupport,
40         Screen):
41         
42         ALLOW_SUSPEND = True
43         instance = None
44
45         def __init__(self, session):
46                 Screen.__init__(self, session)
47                 self["actions"] = HelpableActionMap(self, "InfobarActions",
48                         {
49                                 "showMovies": (self.showMovies, _("Play recorded movies...")),
50                                 "showRadio": (self.showRadio, _("Show the radio player...")),
51                                 "showTv": (self.showTv, _("Show the tv player...")),
52                         }, prio=2)
53                 
54                 for x in HelpableScreen, \
55                                 InfoBarBase, InfoBarShowHide, \
56                                 InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder, \
57                                 InfoBarInstantRecord, InfoBarAudioSelection, \
58                                 InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarSubserviceSelection, \
59                                 InfoBarTimeshift, InfoBarSeek, InfoBarSummarySupport, InfoBarTimeshiftState, \
60                                 InfoBarTeletextPlugin, InfoBarExtensions, InfoBarPiP, InfoBarSubtitleSupport, InfoBarSleepTimer, \
61                                 InfoBarPlugins, InfoBarServiceErrorPopupSupport:
62                         x.__init__(self)
63
64                 self.helpList.append((self["actions"], "InfobarActions", [("showMovies", _("view recordings..."))]))
65                 self.helpList.append((self["actions"], "InfobarActions", [("showRadio", _("hear radio..."))]))
66
67                 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
68                         {
69                                 iPlayableService.evUpdatedEventInfo: self.__eventInfoChanged
70                         })
71
72                 self.current_begin_time=0
73                 assert InfoBar.instance is None, "class InfoBar is a singleton class and just one instance of this class is allowed!"
74                 InfoBar.instance = self
75
76         def __onClose(self):
77                 InfoBar.instance = None
78
79         def __eventInfoChanged(self):
80                 if self.execing:
81                         service = self.session.nav.getCurrentService()
82                         old_begin_time = self.current_begin_time
83                         info = service and service.info()
84                         ptr = info and info.getEvent(0)
85                         self.current_begin_time = ptr and ptr.getBeginTime() or 0
86                         if config.usage.show_infobar_on_event_change.value:
87                                 if old_begin_time and old_begin_time != self.current_begin_time:
88                                         self.doShow()
89
90         def __checkServiceStarted(self):
91                 self.__serviceStarted(True)
92                 self.onExecBegin.remove(self.__checkServiceStarted)
93
94         def serviceStarted(self):  #override from InfoBarShowHide
95                 new = self.servicelist.newServicePlayed()
96                 if self.execing:
97                         InfoBarShowHide.serviceStarted(self)
98                         self.current_begin_time=0
99                 elif not self.__checkServiceStarted in self.onShown and new:
100                         self.onShown.append(self.__checkServiceStarted)
101
102         def __checkServiceStarted(self):
103                 self.serviceStarted()
104                 self.onShown.remove(self.__checkServiceStarted)
105
106         def showTv(self):
107                 self.showTvChannelList(True)
108
109         def showRadio(self):
110                 if config.usage.e1like_radio_mode.value:
111                         self.showRadioChannelList(True)
112                 else:
113                         self.rds_display.hide() # in InfoBarRdsDecoder
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                 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):
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                 for x in HelpableScreen, InfoBarShowHide, InfoBarMenu, \
145                                 InfoBarBase, InfoBarSeek, InfoBarShowMovies, \
146                                 InfoBarAudioSelection, InfoBarNotifications, InfoBarSimpleEventView, \
147                                 InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, \
148                                 InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, \
149                                 InfoBarTeletextPlugin, InfoBarServiceErrorPopupSupport:
150                         x.__init__(self)
151
152                 self.lastservice = self.session.nav.getCurrentlyPlayingServiceReference()
153                 self.session.nav.playService(service)
154                 self.returning = False
155
156         def leavePlayer(self):
157                 self.is_closing = True
158
159                 if config.usage.on_movie_stop.value == "ask":
160                         list = []
161                         list.append((_("Yes"), "quit"))
162                         if config.usage.setup_level.index >= 2: # expert+
163                                 list.append((_("Yes, returning to movie list"), "movielist"))
164                         list.append((_("No"), "continue"))
165                         if config.usage.setup_level.index >= 2: # expert+
166                                 list.append((_("No, but restart from begin"), "restart"))
167                         self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list)
168                 else:
169                         self.leavePlayerConfirmed([True, config.usage.on_movie_stop.value])
170
171         def leavePlayerConfirmed(self, answer):
172                 answer = answer and answer[1]
173                 if answer == "quit":
174                         self.session.nav.playService(self.lastservice)
175                         config.movielist.last_videodir.cancel()
176                         self.close()
177                 elif answer == "movielist":
178                         ref = self.session.nav.getCurrentlyPlayingServiceReference()
179                         self.returning = True
180                         self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
181                         self.session.nav.playService(self.lastservice)
182                 elif answer == "restart":
183                         self.doSeek(0)
184
185         def doEofInternal(self, playing):
186                 if not self.execing:
187                         return
188                 if not playing :
189                         return
190                 self.is_closing = True
191                 if config.usage.on_movie_eof.value == "ask":
192                         list = []
193                         list.append((_("Yes"), "quit"))
194                         if config.usage.setup_level.index >= 2: # expert+
195                                 list.append((_("Yes, returning to movie list"), "movielist"))
196                         list.append((_("No"), "continue"))
197                         if config.usage.setup_level.index >= 2: # expert+
198                                 list.append((_("No, but restart from begin"), "restart"))
199                         self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list)
200                 else:
201                         self.leavePlayerConfirmed([True, config.usage.on_movie_eof.value])
202
203         def showMovies(self):
204                 ref = self.session.nav.getCurrentlyPlayingServiceReference()
205                 self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
206
207         def movieSelected(self, service):
208                 if service is not None:
209                         self.is_closing = False
210                         self.session.nav.playService(service)
211                         self.returning = False
212                 elif self.returning:
213                         self.close()