[RecordTimer] fix repeat timer issue.
[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         InfoBarHDMI
21
22 profile("LOAD:InitBar_Components")
23 from Components.ActionMap import HelpableActionMap
24 from Components.config import config
25 from Components.ServiceEventTracker import ServiceEventTracker, InfoBarBase
26
27 profile("LOAD:HelpableScreen")
28 from Screens.HelpMenu import HelpableScreen
29
30 class InfoBar(InfoBarBase, InfoBarShowHide,
31         InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder,
32         InfoBarInstantRecord, InfoBarAudioSelection, InfoBarRedButton,
33         HelpableScreen, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarUnhandledKey,
34         InfoBarSubserviceSelection, InfoBarTimeshift, InfoBarSeek,
35         InfoBarSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions,
36         InfoBarPiP, InfoBarPlugins, InfoBarSubtitleSupport, InfoBarServiceErrorPopupSupport, InfoBarJobman,
37         InfoBarHDMI, Screen):
38         
39         ALLOW_SUSPEND = True
40         instance = None
41
42         def __init__(self, session):
43                 Screen.__init__(self, session)
44                 self["actions"] = HelpableActionMap(self, "InfobarActions",
45                         {
46                                 "showMovies": (self.showMovies, _("Play recorded movies...")),
47                                 "showRadio": (self.showRadio, _("Show the radio player...")),
48                                 "showTv": (self.showTv, _("Show the tv player...")),
49                                 "showSubtitle":(self.showSubtitle, _("Show the Subtitle...")),
50                         }, prio=2)
51                 
52                 self.allowPiP = True
53                 
54                 for x in HelpableScreen, \
55                                 InfoBarBase, InfoBarShowHide, \
56                                 InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder, \
57                                 InfoBarInstantRecord, InfoBarAudioSelection, InfoBarRedButton, InfoBarUnhandledKey, \
58                                 InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarSubserviceSelection, \
59                                 InfoBarTimeshift, InfoBarSeek, InfoBarSummarySupport, InfoBarTimeshiftState, \
60                                 InfoBarTeletextPlugin, InfoBarExtensions, InfoBarPiP, InfoBarSubtitleSupport, InfoBarJobman, \
61                                 InfoBarPlugins, InfoBarServiceErrorPopupSupport, InfoBarHDMI:
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                         from Screens.ChannelSelection import ChannelSelectionRadio
115                         self.session.openWithCallback(self.ChannelSelectionRadioClosed, ChannelSelectionRadio, self)
116
117         def ChannelSelectionRadioClosed(self, *arg):
118                 self.rds_display.show()  # in InfoBarRdsDecoder
119
120         def showMovies(self):
121                 from Screens.MovieSelection import MovieSelection
122                 self.session.openWithCallback(self.movieSelected, MovieSelection)
123
124         def movieSelected(self, service):
125                 if service is not None:
126                         self.session.open(MoviePlayer, service)
127
128         def showSubtitle(self):
129                 from Screens.Subtitles import Subtitles
130                 self.session.open(Subtitles)
131
132 class MoviePlayer(InfoBarBase, InfoBarShowHide, \
133                 InfoBarMenu, \
134                 InfoBarSeek, InfoBarShowMovies, InfoBarAudioSelection, HelpableScreen, InfoBarNotifications,
135                 InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarSimpleEventView,
136                 InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, Screen, InfoBarTeletextPlugin,
137                 InfoBarServiceErrorPopupSupport, InfoBarExtensions, InfoBarPlugins, InfoBarPiP, InfoBarHDMI):
138
139         ENABLE_RESUME_SUPPORT = True
140         ALLOW_SUSPEND = True
141                 
142         def __init__(self, session, service):
143                 Screen.__init__(self, session)
144                 
145                 self["actions"] = HelpableActionMap(self, "MoviePlayerActions",
146                         {
147                                 "showSubtitle":(self.showSubtitle, _("Show the Subtitle...")),
148                                 "leavePlayer": (self.leavePlayer, _("leave movie player..."))
149                         })
150                 
151                 self.allowPiP = False
152                 
153                 for x in HelpableScreen, InfoBarShowHide, InfoBarMenu, \
154                                 InfoBarBase, InfoBarSeek, InfoBarShowMovies, \
155                                 InfoBarAudioSelection, InfoBarNotifications, InfoBarSimpleEventView, \
156                                 InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, \
157                                 InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, \
158                                 InfoBarTeletextPlugin, InfoBarServiceErrorPopupSupport, InfoBarExtensions, \
159                                 InfoBarPlugins, InfoBarPiP:
160                         x.__init__(self)
161
162                 self.lastservice = session.nav.getCurrentlyPlayingServiceReference()
163                 session.nav.playService(service)
164                 self.returning = False
165                 self.onClose.append(self.__onClose)
166
167         def __onClose(self):
168                 self.session.nav.playService(self.lastservice)
169
170         def handleLeave(self, how):
171                 self.is_closing = True
172                 if how == "ask":
173                         if config.usage.setup_level.index < 2: # -expert
174                                 list = (
175                                         (_("Yes"), "quit"),
176                                         (_("No"), "continue")
177                                 )
178                         else:
179                                 list = (
180                                         (_("Yes"), "quit"),
181                                         (_("Yes, returning to movie list"), "movielist"),
182                                         (_("Yes, and delete this movie"), "quitanddelete"),
183                                         (_("No"), "continue"),
184                                         (_("No, but restart from begin"), "restart")
185                                 )
186
187                         from Screens.ChoiceBox import ChoiceBox
188                         self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list)
189                 else:
190                         self.leavePlayerConfirmed([True, how])
191
192         def leavePlayer(self):
193                 self.handleLeave(config.usage.on_movie_stop.value)
194
195         def deleteConfirmed(self, answer):
196                 if answer:
197                         self.leavePlayerConfirmed((True, "quitanddeleteconfirmed"))
198
199         def leavePlayerConfirmed(self, answer):
200                 answer = answer and answer[1]
201
202                 if answer in ("quitanddelete", "quitanddeleteconfirmed"):
203                         ref = self.session.nav.getCurrentlyPlayingServiceReference()
204                         from enigma import eServiceCenter
205                         serviceHandler = eServiceCenter.getInstance()
206                         info = serviceHandler.info(ref)
207                         name = info and info.getName(ref) or _("this recording")
208
209                         if answer == "quitanddelete":
210                                 from Screens.MessageBox import MessageBox
211                                 self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete %s?") % name)
212                                 return
213
214                         elif answer == "quitanddeleteconfirmed":
215                                 offline = serviceHandler.offlineOperations(ref)
216                                 if offline.deleteFromDisk(0):
217                                         from Screens.MessageBox import MessageBox
218                                         self.session.openWithCallback(self.close, MessageBox, _("You cannot delete this!"), MessageBox.TYPE_ERROR)
219                                         return
220
221                 if answer in ("quit", "quitanddeleteconfirmed"):
222                         self.close()
223                 elif answer == "movielist":
224                         ref = self.session.nav.getCurrentlyPlayingServiceReference()
225                         self.returning = True
226                         from Screens.MovieSelection import MovieSelection
227                         self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
228                         self.session.nav.stopService()
229                 elif answer == "restart":
230                         self.doSeek(0)
231                         self.setSeekState(self.SEEK_STATE_PLAY)
232
233         def doEofInternal(self, playing):
234                 if not self.execing:
235                         return
236                 if not playing :
237                         return
238                 self.handleLeave(config.usage.on_movie_eof.value)
239
240         def showMovies(self):
241                 ref = self.session.nav.getCurrentlyPlayingServiceReference()
242                 from Screens.MovieSelection import MovieSelection
243                 self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
244
245         def movieSelected(self, service):
246                 if service is not None:
247                         self.is_closing = False
248                         self.session.nav.playService(service)
249                         self.returning = False
250                 elif self.returning:
251                         self.close()
252
253         def showSubtitle(self):
254                 from Screens.Subtitles import Subtitles
255                 self.session.open(Subtitles)