fix showing of infobar on servicechange via servicelist
[enigma2.git] / lib / python / Screens / ChannelSelection.py
index e2dbd6b5e7eeeb6b24e9a93972d000bfeebf293e..eb6f90593775dc7ae2a693856e50de7c7ea28acc 100644 (file)
@@ -1,7 +1,7 @@
 from Screen import Screen
 from Components.Button import Button
 from Components.ServiceList import ServiceList
-from Components.ActionMap import NumberActionMap, ActionMap
+from Components.ActionMap import NumberActionMap, ActionMap, HelpableActionMap
 from Components.MenuList import MenuList
 from Components.ServiceEventTracker import ServiceEventTracker
 from EpgSelection import EPGSelection
@@ -11,11 +11,14 @@ from Screens.FixedMenu import FixedMenu
 from Tools.NumericalTextInput import NumericalTextInput
 from Components.NimManager import nimmanager
 from Components.Sources.Clock import Clock
+from Components.Sources.RdsDecoder import RdsDecoder
 from Components.Input import Input
 from Components.ParentalControl import parentalControl
+from Components.Pixmap import Pixmap
 from Screens.InputBox import InputBox, PinInput
 from Screens.MessageBox import MessageBox
 from Screens.ServiceInfo import ServiceInfo
+from Screens.RdsDisplay import RassInteractive
 from ServiceReference import ServiceReference
 from Tools.BoundFunction import boundFunction
 from re import *
@@ -36,9 +39,7 @@ class BouquetSelector(Screen):
                                "ok": self.okbuttonClick,
                                "cancel": self.cancelClick
                        })
-               entrys = [ ]
-               for x in bouquets:
-                       entrys.append((x[0], x[1]))
+               entrys = [ (x[0], x[1]) for x in bouquets ]
                self["menu"] = MenuList(entrys, enableWrapAround)
 
        def getCurrent(self):
@@ -62,6 +63,10 @@ OFF = 0
 EDIT_BOUQUET = 1
 EDIT_ALTERNATIVES = 2
 
+def apend_when_current_valid(current, menu, args):
+       if current and current.valid():
+               menu.append(args)
+
 class ChannelContextMenu(Screen):
        def __init__(self, session, csel):
                Screen.__init__(self, session)
@@ -75,71 +80,72 @@ class ChannelContextMenu(Screen):
                        })
                menu = [ ]
 
+               current = csel.getCurrentSelection()
                current_root = csel.getRoot()
-               current_sel_path = csel.getCurrentSelection().getPath()
-               current_sel_flags = csel.getCurrentSelection().flags
+               current_sel_path = current.getPath()
+               current_sel_flags = current.flags
                inBouquetRootList = current_root and current_root.getPath().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
                inBouquet = csel.getMutableList() is not None
                haveBouquets = config.usage.multibouquet.value
 
-               if not (len(current_sel_path) or current_sel_flags & eServiceReference.isDirectory):
-                       menu.append((_("show transponder info"), self.showServiceInformations))
+               if not (len(current_sel_path) or current_sel_flags & (eServiceReference.isDirectory|eServiceReference.isMarker)):
+                       apend_when_current_valid(current, menu, (_("show transponder info"), self.showServiceInformations))
                if csel.bouquet_mark_edit == OFF and not csel.movemode:
                        if not inBouquetRootList:
                                isPlayable = not (current_sel_flags & (eServiceReference.isMarker|eServiceReference.isDirectory))
                                if isPlayable:
                                        if config.ParentalControl.configured.value:
                                                if parentalControl.getProtectionLevel(csel.getCurrentSelection().toCompareString()) == -1:
-                                                       menu.append((_("add to parental protection"), boundFunction(self.addParentalProtection, csel.getCurrentSelection())))
+                                                       apend_when_current_valid(current, menu, (_("add to parental protection"), boundFunction(self.addParentalProtection, csel.getCurrentSelection())))
                                                else:
-                                                       menu.append((_("remove from parental protection"), boundFunction(self.removeParentalProtection, csel.getCurrentSelection())))
+                                                       apend_when_current_valid(current, menu, (_("remove from parental protection"), boundFunction(self.removeParentalProtection, csel.getCurrentSelection())))
                                        if haveBouquets:
-                                               menu.append((_("add service to bouquet"), self.addServiceToBouquetSelected))
+                                               apend_when_current_valid(current, menu, (_("add service to bouquet"), self.addServiceToBouquetSelected))
                                        else:
-                                               menu.append((_("add service to favourites"), self.addServiceToBouquetSelected))
+                                               apend_when_current_valid(current, menu, (_("add service to favourites"), self.addServiceToBouquetSelected))
                                else:
                                        if haveBouquets:
                                                if not inBouquet and current_sel_path.find("PROVIDERS") == -1:
-                                                       menu.append((_("copy to bouquets"), self.copyCurrentToBouquetList))
+                                                       apend_when_current_valid(current, menu, (_("copy to bouquets"), self.copyCurrentToBouquetList))
                                        if current_sel_path.find("flags == %d" %(FLAG_SERVICE_NEW_FOUND)) != -1:
-                                               menu.append((_("remove all new found flags"), self.removeAllNewFoundFlags))
+                                               apend_when_current_valid(current, menu, (_("remove all new found flags"), self.removeAllNewFoundFlags))
                                if inBouquet:
-                                       menu.append((_("remove entry"), self.removeCurrentService))
+                                       apend_when_current_valid(current, menu, (_("remove entry"), self.removeCurrentService))
                                if current_root and current_root.getPath().find("flags == %d" %(FLAG_SERVICE_NEW_FOUND)) != -1:
-                                       menu.append((_("remove new found flag"), self.removeNewFoundFlag))
+                                       apend_when_current_valid(current, menu, (_("remove new found flag"), self.removeNewFoundFlag))
                        else:
                                        menu.append((_("add bouquet"), self.showBouquetInputBox))
-                                       menu.append((_("remove entry"), self.removeBouquet))
+                                       apend_when_current_valid(current, menu, (_("remove entry"), self.removeBouquet))
 
                if inBouquet: # current list is editable?
                        if csel.bouquet_mark_edit == OFF:
                                if not csel.movemode:
-                                       menu.append((_("enable move mode"), self.toggleMoveMode))
+                                       apend_when_current_valid(current, menu, (_("enable move mode"), self.toggleMoveMode))
                                        if not inBouquetRootList and current_root and not (current_root.flags & eServiceReference.isGroup):
                                                menu.append((_("add marker"), self.showMarkerInputBox))
                                                if haveBouquets:
-                                                       menu.append((_("enable bouquet edit"), self.bouquetMarkStart))
+                                                       apend_when_current_valid(current, menu, (_("enable bouquet edit"), self.bouquetMarkStart))
                                                else:
-                                                       menu.append((_("enable favourite edit"), self.bouquetMarkStart))
+                                                       apend_when_current_valid(current, menu, (_("enable favourite edit"), self.bouquetMarkStart))
                                                if current_sel_flags & eServiceReference.isGroup:
-                                                       menu.append((_("edit alternatives"), self.editAlternativeServices))
-                                                       menu.append((_("show alternatives"), self.showAlternativeServices))
-                                                       menu.append((_("remove all alternatives"), self.removeAlternativeServices))
-                                               else:
-                                                       menu.append((_("add alternatives"), self.addAlternativeServices))
+                                                       apend_when_current_valid(current, menu, (_("edit alternatives"), self.editAlternativeServices))
+                                                       apend_when_current_valid(current, menu, (_("show alternatives"), self.showAlternativeServices))
+                                                       apend_when_current_valid(current, menu, (_("remove all alternatives"), self.removeAlternativeServices))
+                                               elif not current_sel_flags & eServiceReference.isMarker:
+                                                       apend_when_current_valid(current, menu, (_("add alternatives"), self.addAlternativeServices))
                                else:
-                                       menu.append((_("disable move mode"), self.toggleMoveMode))
+                                       apend_when_current_valid(current, menu, (_("disable move mode"), self.toggleMoveMode))
                        else:
                                if csel.bouquet_mark_edit == EDIT_BOUQUET:
                                        if haveBouquets:
-                                               menu.append((_("end bouquet edit"), self.bouquetMarkEnd))
-                                               menu.append((_("abort bouquet edit"), self.bouquetMarkAbort))
+                                               apend_when_current_valid(current, menu, (_("end bouquet edit"), self.bouquetMarkEnd))
+                                               apend_when_current_valid(current, menu, (_("abort bouquet edit"), self.bouquetMarkAbort))
                                        else:
-                                               menu.append((_("end favourites edit"), self.bouquetMarkEnd))
-                                               menu.append((_("abort favourites edit"), self.bouquetMarkAbort))
+                                               apend_when_current_valid(current, menu, (_("end favourites edit"), self.bouquetMarkEnd))
+                                               apend_when_current_valid(current, menu, (_("abort favourites edit"), self.bouquetMarkAbort))
                                else:
-                                               menu.append((_("end alternatives edit"), self.bouquetMarkEnd))
-                                               menu.append((_("abort alternatives edit"), self.bouquetMarkAbort))
+                                               apend_when_current_valid(current, menu, (_("end alternatives edit"), self.bouquetMarkEnd))
+                                               apend_when_current_valid(current, menu, (_("abort alternatives edit"), self.bouquetMarkAbort))
 
                menu.append((_("back"), self.cancelClick))
                self["menu"] = MenuList(menu)
@@ -358,9 +364,9 @@ class ChannelSelectionEdit:
                        name = cur_service.getServiceName()
                        print "NAME", name
                        if self.mode == MODE_TV:
-                               str = '1:134:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET \"alternatives.%s.tv\" ORDER BY bouquet'%(self.buildBouquetID(name))
+                               str = '1:134:1:0:0:0:0:0:0:0:FROM BOUQUET \"alternatives.%s.tv\" ORDER BY bouquet'%(self.buildBouquetID(name))
                        else:
-                               str = '1:134:2:0:0:0:0:0:0:0:(type == 2) FROM BOUQUET \"alternatives.%s.radio\" ORDER BY bouquet'%(self.buildBouquetID(name))
+                               str = '1:134:2:0:0:0:0:0:0:0:FROM BOUQUET \"alternatives.%s.radio\" ORDER BY bouquet'%(self.buildBouquetID(name))
                        new_ref = ServiceReference(str)
                        if not mutableBouquet.addService(new_ref.ref, cur_service.ref):
                                mutableBouquet.removeService(cur_service.ref)
@@ -650,17 +656,9 @@ class ChannelSelectionBase(Screen):
                        })
                self.recallBouquetMode()
 
-       def appendDVBTypes(self, ref):
-               path = ref.getPath()
-               pos = path.find(' FROM BOUQUET')
-               if pos != -1:
-                       return eServiceReference(self.service_types + path[pos:])
-               return ref
-
        def getBouquetNumOffset(self, bouquet):
                if not config.usage.multibouquet.value:
                        return 0
-               bouquet = self.appendDVBTypes(bouquet)
                str = bouquet.toString()
                offsetCount = 0
                if not self.bouquetNumOffsetCache.has_key(str):
@@ -668,7 +666,7 @@ class ChannelSelectionBase(Screen):
                        bouquetlist = serviceHandler.list(self.bouquet_root)
                        if not bouquetlist is None:
                                while True:
-                                       bouquetIterator = self.appendDVBTypes(bouquetlist.getNext())
+                                       bouquetIterator = bouquetlist.getNext()
                                        if not bouquetIterator.valid(): #end of list
                                                break
                                        self.bouquetNumOffsetCache[bouquetIterator.toString()]=offsetCount
@@ -689,13 +687,13 @@ class ChannelSelectionBase(Screen):
                if self.mode == MODE_TV:
                        self.service_types = service_types_tv
                        if config.usage.multibouquet.value:
-                               self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet'
+                               self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "bouquets.tv" ORDER BY bouquet'
                        else:
                                self.bouquet_rootstr = '%s FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet'%(self.service_types)
                else:
                        self.service_types = service_types_radio
                        if config.usage.multibouquet.value:
-                               self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.radio" ORDER BY bouquet'
+                               self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "bouquets.radio" ORDER BY bouquet'
                        else:
                                self.bouquet_rootstr = '%s FROM BOUQUET "userbouquet.favourites.radio" ORDER BY bouquet'%(self.service_types)
                self.bouquet_root = eServiceReference(self.bouquet_rootstr)
@@ -725,13 +723,11 @@ class ChannelSelectionBase(Screen):
        def setRoot(self, root, justSet=False):
                path = root.getPath()
                inBouquetRootList = path.find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
-               pos = path.find(' FROM BOUQUET')
+               pos = path.find('FROM BOUQUET')
                isBouquet = (pos != -1) and (root.flags & eServiceReference.isDirectory)
                if not inBouquetRootList and isBouquet:
                        self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
                        self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
-                       refstr = self.service_types + path[pos:]
-                       root = eServiceReference(refstr)
                else:
                        self.servicelist.setMode(ServiceList.MODE_NORMAL)
                self.servicelist.setRoot(root, justSet)
@@ -858,27 +854,27 @@ class ChannelSelectionBase(Screen):
                                                                break
                                                        orbpos = service.getUnsignedData(4) >> 16
                                                        if service.getPath().find("FROM PROVIDER") != -1:
-                                                               service_name = _("Providers")
+                                                               service_type = _("Providers")
                                                        elif service.getPath().find("flags == %d" %(FLAG_SERVICE_NEW_FOUND)) != -1:
-                                                               service_name = _("New")
+                                                               service_type = _("New")
                                                        else:
-                                                               service_name = _("Services")
+                                                               service_type = _("Services")
                                                        try:
-                                                               service_name += str(' - %s'%(nimmanager.getSatDescription(orbpos)))
-                                                               service.setName(service_name) # why we need this cast?
+                                                               # why we need this cast?
+                                                               service_name = str(nimmanager.getSatDescription(orbpos))
                                                        except:
                                                                if orbpos == 0xFFFF: #Cable
-                                                                       n = ("%s (%s)") % (service_name, _("Cable"))
+                                                                       service_name = _("Cable")
                                                                elif orbpos == 0xEEEE: #Terrestrial
-                                                                       n = ("%s (%s)") % (service_name, _("Terrestrial"))
+                                                                       service_name = _("Terrestrial")
                                                                else:
                                                                        if orbpos > 1800: # west
                                                                                orbpos = 3600 - orbpos
                                                                                h = _("W")
                                                                        else:
                                                                                h = _("E")
-                                                                       n = ("%s (%d.%d" + h + ")") % (service_name, orbpos / 10, orbpos % 10)
-                                                               service.setName(n)
+                                                                       service_name = ("%d.%d" + h) % (orbpos / 10, orbpos % 10)
+                                                       service.setName("%s - %s" % (service_name, service_type))
                                                        self.servicelist.addService(service)
                                                self.servicelist.finishFill()
                                                if prev is not None:
@@ -914,7 +910,9 @@ class ChannelSelectionBase(Screen):
                                self.enterPath(ref)
 
        def inBouquet(self):
-               return self.isBasePathEqual(self.bouquet_root)
+               if len(self.servicePath) > 0 and self.servicePath[0] == self.bouquet_root:
+                       return True
+               return False
 
        def atBegin(self):
                return self.servicelist.atBegin()
@@ -1056,6 +1054,7 @@ class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelect
                self.lastroot = config.tv.lastroot
                self.revertMode = None
                config.usage.multibouquet.addNotifier(self.multibouquet_config_changed)
+               self.new_service_played = False
 
        def multibouquet_config_changed(self, val):
                self.recallBouquetMode()
@@ -1131,12 +1130,18 @@ class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelect
                ref = self.session.nav.getCurrentlyPlayingServiceReference()
                nref = self.getCurrentSelection()
                if ref is None or ref != nref:
+                       self.new_service_played = True
                        self.session.nav.playService(nref)
                        self.saveRoot()
                        self.saveChannel(nref)
                        config.servicelist.lastmode.save()
                        self.addToHistory(nref)
 
+       def newServicePlayed(self):
+               ret = self.new_service_played
+               self.new_service_played = False
+               return ret
+
        def addToHistory(self, ref):
                if self.servicePath is not None:
                        tmp=self.servicePath[:]
@@ -1263,32 +1268,32 @@ class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelect
                self.revertMode = None
                self.close(None)
 
-from Screens.InfoBarGenerics import InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord, InfoBarRadioText
+from Screens.InfoBarGenerics import InfoBarEvent, InfoBarServiceName
 
-class RadioInfoBar(Screen, InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord):
+class RadioInfoBar(Screen, InfoBarEvent, InfoBarServiceName):
        def __init__(self, session):
                Screen.__init__(self, session)
                InfoBarEvent.__init__(self)
                InfoBarServiceName.__init__(self)
-               InfoBarInstantRecord.__init__(self)
                self["CurrentTime"] = Clock()
+               self["RdsDecoder"] = RdsDecoder(self.session.nav)
+               self["BlinkingPoint"] = Pixmap()
+               self["BlinkingPoint"].hide()
 
-class ChannelSelectionRadio(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG, InfoBarRadioText):
-
+class ChannelSelectionRadio(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
        ALLOW_SUSPEND = True
 
-       def __init__(self, session):
+       def __init__(self, session, infobar):
                ChannelSelectionBase.__init__(self, session)
                ChannelSelectionEdit.__init__(self)
                ChannelSelectionEPG.__init__(self)
-               InfoBarRadioText.__init__(self)
-
+               self.infobar = infobar
                config.radio = ConfigSubsection();
                config.radio.lastservice = ConfigText()
                config.radio.lastroot = ConfigText()
                self.onLayoutFinish.append(self.onCreate)
 
-               self.info = session.instantiateDialog(RadioInfoBar)
+               self.info = session.instantiateDialog(RadioInfoBar) # our simple infobar
 
                self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
                        {
@@ -1304,6 +1309,37 @@ class ChannelSelectionRadio(ChannelSelectionBase, ChannelSelectionEdit, ChannelS
                                iPlayableService.evEnd: self.__evServiceEnd
                        })
 
+########## RDS Radiotext / Rass Support BEGIN
+               self.infobar = infobar # reference to real infobar (the one and only)
+               self["RdsDecoder"] = self.info["RdsDecoder"]
+               self["RdsActions"] = HelpableActionMap(self, "InfobarRdsActions",
+               {
+                       "startRassInteractive": (self.startRassInteractive, _("View Rass interactive..."))
+               },-1)
+               self["RdsActions"].setEnabled(False)
+               infobar.rds_display.onRassInteractivePossibilityChanged.append(self.RassInteractivePossibilityChanged)
+
+       def startRassInteractive(self):
+               self.info.hide();
+               self.infobar.rass_interactive = self.session.openWithCallback(self.RassInteractiveClosed, RassInteractive)
+
+       def RassInteractiveClosed(self):
+               self.info.show()
+               self.infobar.rass_interactive = None
+               self.infobar.RassSlidePicChanged()
+
+       def RassInteractivePossibilityChanged(self, state):
+               self["RdsActions"].setEnabled(state)
+########## RDS Radiotext / Rass Support END
+
+       def closeRadio(self):
+               self.infobar.rds_display.onRassInteractivePossibilityChanged.remove(self.RassInteractivePossibilityChanged)
+               self.info.hide()
+               #set previous tv service
+               lastservice=eServiceReference(config.tv.lastservice.value)
+               self.session.nav.playService(lastservice)
+               self.close(None)
+
        def __evServiceStart(self):
                service = self.session.nav.getCurrentService()
                if service:
@@ -1378,13 +1414,6 @@ class ChannelSelectionRadio(ChannelSelectionBase, ChannelSelectionEdit, ChannelS
                                        config.radio.lastservice.save()
                                self.saveRoot()
 
-       def closeRadio(self):
-               self.info.hide()
-               #set previous tv service
-               lastservice=eServiceReference(config.tv.lastservice.value)
-               self.session.nav.playService(lastservice)
-               self.close(None)
-
 class SimpleChannelSelection(ChannelSelectionBase):
        def __init__(self, session, title):
                ChannelSelectionBase.__init__(self, session)