provide source/converter for current service name, current service provider
[enigma2.git] / lib / python / Screens / InfoBarGenerics.py
index 2624209cbe336ef712ad7ded8fd23b2983c2c744..fcce082fbb6f35a39f4852d9269f08ff28fca5db 100644 (file)
@@ -30,6 +30,7 @@ from Screens.MessageBox import MessageBox
 from Screens.MinuteInput import MinuteInput
 from Screens.TimerSelection import TimerSelection
 from Screens.PictureInPicture import PictureInPicture
+from Screens.SubtitleDisplay import SubtitleDisplay
 from ServiceReference import ServiceReference
 
 from Tools import Notifications
@@ -257,9 +258,22 @@ class InfoBarChannelSelection:
                                "zapUp": (self.zapUp, _("previous channel")),
                                "zapDown": (self.zapDown, _("next channel")),
                                "historyBack": (self.historyBack, _("previous channel in history")),
-                               "historyNext": (self.historyNext, _("next channel in history"))
+                               "historyNext": (self.historyNext, _("next channel in history")),
+                               "openServiceList": (self.openServiceList, _("open service list")),
                        })
 
+       def showTvChannelList(self, zap=False):
+               self.servicelist.setModeTv()
+               if zap:
+                       self.servicelist.zap()
+               self.session.execDialog(self.servicelist)
+
+       def showRadioChannelList(self, zap=False):
+               self.servicelist.setModeRadio()
+               if zap:
+                       self.servicelist.zap()
+               self.session.execDialog(self.servicelist)
+
        def firstRun(self):
                self.onShown.remove(self.firstRun)
                config.misc.initialchannelselection.value = 0
@@ -279,6 +293,9 @@ class InfoBarChannelSelection:
        def switchChannelDown(self):
                self.servicelist.moveDown()
                self.session.execDialog(self.servicelist)
+       
+       def openServiceList(self):
+               self.session.execDialog(self.servicelist)
 
        def zapUp(self):
                if currentConfigSelectionElement(config.usage.quickzap_bouquet_change) == "yes":
@@ -680,6 +697,8 @@ class InfoBarSeek:
                
        def unPauseService(self):
                print "unpause"
+               if self.seekstate == self.SEEK_STATE_PLAY:
+                       return 0
                self.setSeekState(self.SEEK_STATE_PLAY);
        
        def doSeek(self, seektime):
@@ -1021,6 +1040,7 @@ class InfoBarExtensions:
        PIPOFF = 1
        MOVEPIP = 2
        PIPSWAP = 3
+       ENABLE_SUBTITLE = 4
 
        def extensions(self):
                list = []
@@ -1030,6 +1050,13 @@ class InfoBarExtensions:
                        list.append((_("Disable Picture in Picture"), self.PIPOFF))
                        list.append((_("Move Picture in Picture"), self.MOVEPIP))
                        list.append((_("Swap services"), self.PIPSWAP))
+               
+               s = self.getCurrentServiceSubtitle()
+               l = s and s.getSubtitleList() or [ ]
+               
+               for x in l:
+                       list.append(("DEBUG: Enable Subtitles: " + x[0], self.ENABLE_SUBTITLE, x[1]))
+               
                self.session.openWithCallback(self.extensionCallback, ChoiceBox, title=_("Please choose an extension..."), list = list)
 
        def extensionCallback(self, answer):
@@ -1055,6 +1082,9 @@ class InfoBarExtensions:
                                
                        elif answer[1] == self.MOVEPIP:
                                self.session.open(PiPSetup, pip = self.pip)
+                       elif answer[1] == self.ENABLE_SUBTITLE:
+                               self.selected_subtitle = answer[2]
+                               self.subtitles_enabled = True
 
 from RecordTimer import parseEvent
 
@@ -1075,7 +1105,7 @@ class InfoBarInstantRecord:
                if entry is not None and entry != -1:
                        self.session.nav.RecordTimer.removeEntry(self.recording[entry])
                        self.recording.remove(self.recording[entry])
-                       
+
        def startInstantRecording(self, limitEvent = False):
                serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
                
@@ -1196,14 +1226,16 @@ class InfoBarAudioSelection:
                audio = service.audioTracks()
                self.audioTracks = audio
                n = audio.getNumberOfTracks()
+               keys = [ "red", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] + [""]*n
+               tlist = []
+               print "tlist:", tlist
                if n > 0:
-#                      self.audioChannel = service.audioChannel()
-#                      config.audio.audiochannel = configElement_nonSave("config.audio.audiochannel", configSelection, self.audioChannel.getCurrentChannel(), (("left", _("Left  >")), ("stereo", _("<  Stereo  >")), ("right", _("<  Right"))))
-                       tlist = []
+                       self.audioChannel = service.audioChannel()
+
                        for x in range(n):
                                i = audio.getTrackInfo(x)
                                language = i.getLanguage()
-                               description = i.getDescription();
+                               description = i.getDescription()
        
                                if len(language) == 3:
                                        if language in LanguageCodes:
@@ -1219,25 +1251,38 @@ class InfoBarAudioSelection:
                        selectedAudio = tlist[0][1]
                        tlist.sort(lambda x,y : cmp(x[0], y[0]))
 
-#                      tlist.insert(0, getConfigListEntry(_("Audio Channel"), config.audio.audiochannel))
-
-                       selection = 0
+                       selection = 2
                        for x in tlist:
                                if x[1] != selectedAudio:
                                        selection += 1
                                else:
                                        break
-                       
-                       self.session.openWithCallback(self.audioSelected, ChoiceBox, title=_("Select audio track"), list = tlist, selection = selection)
+
+                       tlist = [([_("Left"), _("Stereo"), _("Right")][self.audioChannel.getCurrentChannel()], "mode"), ("--", "")] + tlist
+                       self.session.openWithCallback(self.audioSelected, ChoiceBox, title=_("Select audio track"), list = tlist, selection = selection, keys = keys)
                else:
                        del self.audioTracks
 
        def audioSelected(self, audio):
                if audio is not None:
-                       self.audioTracks.selectTrack(audio[1])
+                       if isinstance(audio[1], str):
+                               if audio[1] == "mode":
+                                       keys = ["red", "green", "yellow"]
+                                       selection = self.audioChannel.getCurrentChannel()
+                                       tlist = [(_("left"), 0), (_("stereo"), 1), (_("right"), 2)]
+                                       self.session.openWithCallback(self.modeSelected, ChoiceBox, title=_("Select audio mode"), list = tlist, selection = selection, keys = keys)
+                       else:
+                               del self.audioChannel
+                               if self.session.nav.getCurrentService().audioTracks().getNumberOfTracks() > audio[1]:
+                                       self.audioTracks.selectTrack(audio[1])
+               else:
+                       del self.audioChannel
                del self.audioTracks
-#              del self.audioChannel
-#              del config.audio.audiochannel
+
+       def modeSelected(self, mode):
+               if mode is not None:
+                       self.audioChannel.selectChannel(mode[1])
+               del self.audioChannel
 
 class InfoBarSubserviceSelection:
        def __init__(self):
@@ -1258,8 +1303,8 @@ class InfoBarSubserviceSelection:
        def checkSubservicesAvail(self, ev):
                if ev == iPlayableService.evUpdatedEventInfo:
                        service = self.session.nav.getCurrentService()
-                       subservices = service.subServices()
-                       if subservices.getNumberOfSubservices() == 0:
+                       subservices = service and service.subServices()
+                       if not subservices or subservices.getNumberOfSubservices() == 0:
                                self["SubserviceQuickzapAction"].setEnabled(False)
 
        def nextSubservice(self):
@@ -1270,9 +1315,9 @@ class InfoBarSubserviceSelection:
 
        def changeSubservice(self, direction):
                service = self.session.nav.getCurrentService()
-               subservices = service.subServices()
-               n = subservices.getNumberOfSubservices()
-               if n > 0:
+               subservices = service and service.subServices()
+               n = subservices and subservices.getNumberOfSubservices()
+               if n and n > 0:
                        selection = -1
                        ref = self.session.nav.getCurrentlyPlayingServiceReference()
                        for x in range(n):
@@ -1292,11 +1337,11 @@ class InfoBarSubserviceSelection:
 
        def subserviceSelection(self):
                service = self.session.nav.getCurrentService()
-               subservices = service.subServices()
+               subservices = service and service.subServices()
                
-               n = subservices.getNumberOfSubservices()
+               n = subservices and subservices.getNumberOfSubservices()
                selection = 0
-               if n > 0:
+               if n and n > 0:
                        ref = self.session.nav.getCurrentlyPlayingServiceReference()
                        tlist = []
                        for x in range(n):
@@ -1314,10 +1359,15 @@ class InfoBarSubserviceSelection:
 
 class InfoBarAdditionalInfo:
        def __init__(self):
+               self["NimA"] = Pixmap()
+               self["NimB"] = Pixmap()
+               self["TextActive"] = Pixmap()
                self["DolbyActive"] = Pixmap()
                self["CryptActive"] = Pixmap()
                self["FormatActive"] = Pixmap()
-               
+               self["NimA_Active"] = Pixmap()
+               self["NimB_Active"] = Pixmap()
+
                self["ButtonRed"] = PixmapConditional(withTimer = False)
                self["ButtonRed"].setConnect(lambda: harddiskmanager.HDDCount() > 0)
                self.onLayoutFinish.append(self["ButtonRed"].update)
@@ -1343,6 +1393,19 @@ class InfoBarAdditionalInfo:
                self.onLayoutFinish.append(self["ButtonBlueText"].update)
 
                self.session.nav.event.append(self.gotServiceEvent) # we like to get service events
+               res_mgr = eDVBResourceManagerPtr()
+               if eDVBResourceManager.getInstance(res_mgr) == 0:
+                       res_mgr.frontendUseMaskChanged.get().append(self.tunerUseMaskChanged)
+
+       def tunerUseMaskChanged(self, mask):
+               if mask&1:
+                       self["NimA_Active"].show()
+               else:
+                       self["NimA_Active"].hide()
+               if mask&2:
+                       self["NimB_Active"].show()
+               else:
+                       self["NimB_Active"].hide()
 
        def hideSubServiceIndication(self):
                self["ButtonGreen"].hide()
@@ -1354,15 +1417,25 @@ class InfoBarAdditionalInfo:
 
        def checkFormat(self, service):
                info = service.info()
-               if info is not None:
+               if info:
                        aspect = info.getInfo(iServiceInformation.sAspect)
                        if aspect in [ 3, 4, 7, 8, 0xB, 0xC, 0xF, 0x10 ]:
                                self["FormatActive"].show()
-                       else:
-                               self["FormatActive"].hide()
+                               return
+               self["FormatActive"].hide()
+
+       def checkText(self, service):
+               info = service.info()
+               if info:
+                       tpid = info.getInfo(iServiceInformation.sTXTPID)
+                       if tpid != -1:
+                               self["TextActive"].show()
+                               return
+               self["TextActive"].hide()
 
        def checkSubservices(self, service):
-               if service.subServices().getNumberOfSubservices() > 0:
+               subservices = service.subServices()
+               if subservices and subservices.getNumberOfSubservices() > 0:
                        self.showSubServiceIndication()
                else:
                        self.hideSubServiceIndication()
@@ -1371,7 +1444,7 @@ class InfoBarAdditionalInfo:
                # FIXME
                dolby = False
                audio = service.audioTracks()
-               if audio is not None:
+               if audio:
                        n = audio.getNumberOfTracks()
                        for x in range(n):
                                i = audio.getTrackInfo(x)
@@ -1386,43 +1459,59 @@ class InfoBarAdditionalInfo:
 
        def checkCrypted(self, service):
                info = service.info()
-               if info is not None:
-                       if info.getInfo(iServiceInformation.sIsCrypted) > 0:
-                               self["CryptActive"].show()
-                       else:
-                               self["CryptActive"].hide()
+               if info and info.getInfo(iServiceInformation.sIsCrypted) > 0:
+                       self["CryptActive"].show()
+               else:
+                       self["CryptActive"].hide()
+
+       def checkTunerState(self, service):
+               info = service.frontendInfo()
+               feNumber = info and info.getFrontendInfo(iFrontendInformation.frontendNumber)
+               if feNumber is None:
+                       self["NimA"].hide()
+                       self["NimB"].hide()
+               elif feNumber == 0:
+                       self["NimB"].hide()
+                       self["NimA"].show()
+               elif feNumber == 1:
+                       self["NimA"].hide()
+                       self["NimB"].show()
 
        def gotServiceEvent(self, ev):
                service = self.session.nav.getCurrentService()
-               if ev == iPlayableService.evUpdatedEventInfo:
+               if ev == iPlayableService.evStart:
+                       self.checkTunerState(service)
+               elif ev == iPlayableService.evUpdatedEventInfo:
                        self.checkSubservices(service)
                        self.checkFormat(service)
                elif ev == iPlayableService.evUpdatedInfo:
                        self.checkCrypted(service)
                        self.checkDolby(service)
+                       self.checkText(service)
                elif ev == iPlayableService.evEnd:
                        self.hideSubServiceIndication()
                        self["CryptActive"].hide()
                        self["DolbyActive"].hide()
                        self["FormatActive"].hide()
+                       self["TextActive"].hide()
 
 class InfoBarNotifications:
        def __init__(self):
                self.onExecBegin.append(self.checkNotifications)
                Notifications.notificationAdded.append(self.checkNotificationsIfExecing)
+               self.onClose.append(self.__removeNotification)
+       
+       def __removeNotification(self):
+               Notifications.notificationAdded.remove(self.checkNotificationsIfExecing)
        
        def checkNotificationsIfExecing(self):
-               try:
-                       if self.execing:
-                               self.checkNotifications()
-               except:
-                       print "******************************* A SEVERE ERROR HAPPENED... Someone who understands the code... please fix :) *******"
+               if self.execing:
+                       self.checkNotifications()
 
        def checkNotifications(self):
                if len(Notifications.notifications):
                        n = Notifications.notifications[0]
                        Notifications.notifications = Notifications.notifications[1:]
-                       print "open",n
                        cb = n[0]
                        if cb is not None:
                                self.session.openWithCallback(cb, n[1], *n[2], **n[3])
@@ -1600,3 +1689,50 @@ class InfoBarTeletextPlugin:
 
        def startTeletext(self):
                self.teletext_plugin(session=self.session, service=self.session.nav.getCurrentService())
+
+class InfoBarSubtitleSupport(object):
+       def __init__(self):
+               object.__init__(self)
+               self.subtitle_window = self.session.instantiateDialog(SubtitleDisplay)
+               self.__subtitles_enabled = False
+
+               self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
+                       {
+                               iPlayableService.evStart: self.__serviceStarted,
+                       })
+
+       def __serviceStarted(self):
+               # reenable if it was enabled
+               r = self.__subtitles_enabled
+               self.__subtitles_enabled = False
+               self.__selected_subtitle = None
+               self.setSubtitlesEnable(r)
+
+       def getCurrentServiceSubtitle(self):
+               service = self.session.nav.getCurrentService()
+               return service and service.subtitle()
+       
+       def setSubtitlesEnable(self, enable=True):
+               subtitle = self.getCurrentServiceSubtitle()
+               if enable and self.__selected_subtitle:
+                       if subtitle and not self.__subtitles_enabled:
+                               subtitle.enableSubtitles(self.subtitle_window.instance, self.selected_subtitle)
+                               self.subtitle_window.show()
+                               self.__subtitles_enabled = True
+               else:
+                       if subtitle:
+                               subtitle.disableSubtitles(self.subtitle_window.instance)
+
+                       self.subtitle_window.hide()
+                       self.__subtitles_enabled = False
+
+       def setSelectedSubtitle(self, subtitle):
+               if self.__selected_subtitle != subtitle and self.subtitles_enabled:
+                       # kick
+                       self.__selected_subtitle = subtitle
+                       self.__serviceStarted()
+               else:
+                       self.__selected_subtitle = subtitle
+
+       subtitles_enabled = property(lambda self: self.__subtitles_enabled, setSubtitlesEnable)
+       selected_subtitle = property(lambda self: self.__selected_subtitle, setSelectedSubtitle)