1e8f761fede482936d162ec667a2ee1a631fac31
[enigma2.git] / lib / python / Screens / InfoBar.py
1 from Screen import Screen
2
3 from Screens.MovieSelection import MovieSelection
4 from Screens.ChannelSelection import ChannelSelectionRadio
5 from Screens.ChoiceBox import ChoiceBox
6
7 from Components.Sources.Source import ObsoleteSource
8 from Components.ActionMap import HelpableActionMap
9 from Components.config import config
10 from Components.ServiceEventTracker import ServiceEventTracker
11
12 from Screens.InfoBarGenerics import InfoBarShowHide, \
13         InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarRdsDecoder, \
14         InfoBarEPG, InfoBarEvent, InfoBarServiceName, InfoBarSeek, InfoBarInstantRecord, \
15         InfoBarAudioSelection, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, \
16         InfoBarSubserviceSelection, InfoBarTuner, InfoBarShowMovies, InfoBarTimeshift,  \
17         InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarSimpleEventView, \
18         InfoBarSummarySupport, InfoBarMoviePlayerSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions, \
19         InfoBarSubtitleSupport, InfoBarPiP, InfoBarPlugins, InfoBarSleepTimer, InfoBarServiceErrorPopupSupport
20
21 from Screens.HelpMenu import HelpableScreen
22
23 from enigma import iPlayableService
24
25 class InfoBar(InfoBarShowHide,
26         InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder,
27         InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord, InfoBarAudioSelection, 
28         HelpableScreen, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish,
29         InfoBarSubserviceSelection, InfoBarTuner, InfoBarTimeshift, InfoBarSeek,
30         InfoBarSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions,
31         InfoBarPiP, InfoBarPlugins, InfoBarSubtitleSupport, InfoBarSleepTimer, InfoBarServiceErrorPopupSupport,
32         Screen):
33         
34         ALLOW_SUSPEND = True
35
36         def __init__(self, session):
37                 Screen.__init__(self, session)
38
39                 self["actions"] = HelpableActionMap(self, "InfobarActions",
40                         {
41                                 "showMovies": (self.showMovies, _("Play recorded movies...")),
42                                 "showRadio": (self.showRadio, _("Show the radio player...")),
43                                 "showTv": (self.showTv, _("Show the tv player...")),
44                         }, prio=2)
45                 
46                 for x in HelpableScreen, \
47                                 InfoBarShowHide, \
48                                 InfoBarNumberZap, InfoBarChannelSelection, InfoBarMenu, InfoBarEPG, InfoBarRdsDecoder, \
49                                 InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord, InfoBarAudioSelection, \
50                                 InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarSubserviceSelection, \
51                                 InfoBarTuner, InfoBarTimeshift, InfoBarSeek, InfoBarSummarySupport, InfoBarTimeshiftState, \
52                                 InfoBarTeletextPlugin, InfoBarExtensions, InfoBarPiP, InfoBarSubtitleSupport, InfoBarSleepTimer, \
53                                 InfoBarPlugins, InfoBarServiceErrorPopupSupport:
54                         x.__init__(self)
55
56                 self.helpList.append((self["actions"], "InfobarActions", [("showMovies", _("view recordings..."))]))
57                 self.helpList.append((self["actions"], "InfobarActions", [("showRadio", _("hear radio..."))]))
58
59                 self["CurrentTime"] = ObsoleteSource(new_source = "global.CurrentTime", removal_date = "2008-01")
60
61                 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
62                         {
63                                 iPlayableService.evUpdatedEventInfo: self.__eventInfoChanged
64                         })
65
66                 self.current_begin_time=0
67
68         def __eventInfoChanged(self):
69                 if self.execing:
70                         service = self.session.nav.getCurrentService()
71                         old_begin_time = self.current_begin_time
72                         info = service and service.info()
73                         ptr = info and info.getEvent(0)
74                         self.current_begin_time = ptr and ptr.getBeginTime() or 0
75                         if config.usage.show_infobar_on_event_change.value:
76                                 if old_begin_time and old_begin_time != self.current_begin_time:
77                                         self.doShow()
78
79         def __checkServiceStarted(self):
80                 self.__serviceStarted(True)
81                 self.onExecBegin.remove(self.__checkServiceStarted)
82
83         def serviceStarted(self):  #override from InfoBarShowHide
84                 new = self.servicelist.newServicePlayed()
85                 if self.execing:
86                         InfoBarShowHide.serviceStarted(self)
87                         self.current_begin_time=0
88                 elif not self.__checkServiceStarted in self.onShown and new:
89                         self.onShown.append(self.__checkServiceStarted)
90
91         def __checkServiceStarted(self):
92                 self.serviceStarted()
93                 self.onShown.remove(self.__checkServiceStarted)
94
95         def showTv(self):
96                 self.showTvChannelList(True)
97
98         def showRadio(self):
99                 if config.usage.e1like_radio_mode.value:
100                         self.showRadioChannelList(True)
101                 else:
102                         self.rds_display.hide() # in InfoBarRdsDecoder
103                         self.session.openWithCallback(self.ChannelSelectionRadioClosed, ChannelSelectionRadio, self)
104
105         def ChannelSelectionRadioClosed(self, *arg):
106                 self.rds_display.show()  # in InfoBarRdsDecoder
107
108         def showMovies(self):
109                 self.session.openWithCallback(self.movieSelected, MovieSelection)
110
111         def movieSelected(self, service):
112                 if service is not None:
113                         self.session.open(MoviePlayer, service)
114
115 class MoviePlayer(InfoBarShowHide, \
116                 InfoBarMenu, \
117                 InfoBarServiceName, InfoBarSeek, InfoBarShowMovies, InfoBarAudioSelection, HelpableScreen, InfoBarNotifications,
118                 InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarSimpleEventView,
119                 InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, Screen, InfoBarTeletextPlugin,
120                 InfoBarServiceErrorPopupSupport):
121
122         ENABLE_RESUME_SUPPORT = True
123         ALLOW_SUSPEND = True
124                 
125         def __init__(self, session, service):
126                 Screen.__init__(self, session)
127                 
128                 self["actions"] = HelpableActionMap(self, "MoviePlayerActions",
129                         {
130                                 "leavePlayer": (self.leavePlayer, _("leave movie player..."))
131                         })
132                 
133                 for x in HelpableScreen, InfoBarShowHide, InfoBarMenu, \
134                                 InfoBarServiceName, InfoBarSeek, InfoBarShowMovies, \
135                                 InfoBarAudioSelection, InfoBarNotifications, InfoBarSimpleEventView, \
136                                 InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, \
137                                 InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, \
138                                 InfoBarTeletextPlugin, InfoBarServiceErrorPopupSupport:
139                         x.__init__(self)
140
141                 self.lastservice = self.session.nav.getCurrentlyPlayingServiceReference()
142                 self.session.nav.playService(service)
143
144         def leavePlayer(self):
145                 self.is_closing = True
146
147                 list = []
148                 list.append((_("Yes"), "quit"))
149                 list.append((_("No"), "continue"))
150                 if config.usage.setup_level.index >= 2: # expert+
151                         list.append((_("No, but restart from begin"), "restart"))
152                 self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list)
153
154         def leavePlayerConfirmed(self, answer):
155                 answer = answer and answer[1]
156                 if answer == "quit":
157                         self.session.nav.playService(self.lastservice)
158                         self.close()
159                 elif answer == "restart":
160                         self.doSeek(0)
161
162         def showMovies(self):
163                 ref = self.session.nav.getCurrentlyPlayingServiceReference()
164                 self.session.openWithCallback(self.movieSelected, MovieSelection, ref)
165
166         def movieSelected(self, service):
167                 if service is not None:
168                         self.session.nav.playService(service)