Add some parental control improvements (made by Tode)
[enigma2.git] / lib / python / Screens / SubservicesQuickzap.py
index 14b7b3c1372b0d2bc9ca93e8b94006b031335b8e..3bcc3c4641d571f6370141f84db2cdc623b3de16 100644 (file)
@@ -4,15 +4,23 @@ from Components.Label import Label
 
 from Screens.ChoiceBox import ChoiceBox
 from Screens.MessageBox import MessageBox
-from InfoBarGenerics import InfoBarShowHide, InfoBarMenu, InfoBarServiceName, InfoBarInstantRecord, InfoBarTimeshift, InfoBarSeek, InfoBarTimeshiftState, InfoBarExtensions, InfoBarSubtitleSupport
+from InfoBarGenerics import InfoBarShowHide, InfoBarMenu, InfoBarInstantRecord, InfoBarTimeshift, InfoBarSeek, InfoBarTimeshiftState, InfoBarExtensions, InfoBarSubtitleSupport, InfoBarAudioSelection
+from Components.ServiceEventTracker import InfoBarBase
+
+from enigma import eTimer
+
+class SubservicesQuickzap(InfoBarBase, InfoBarShowHide, InfoBarMenu, \
+               InfoBarInstantRecord, InfoBarSeek, InfoBarTimeshift, \
+               InfoBarTimeshiftState, InfoBarExtensions, InfoBarSubtitleSupport, \
+               InfoBarAudioSelection, Screen):
 
-class SubservicesQuickzap(InfoBarShowHide, InfoBarMenu, InfoBarServiceName, InfoBarInstantRecord, InfoBarSeek, InfoBarTimeshift, InfoBarTimeshiftState, InfoBarExtensions, InfoBarSubtitleSupport, Screen):
        def __init__(self, session, subservices):
                Screen.__init__(self, session)
-               for x in [InfoBarShowHide, InfoBarMenu, InfoBarServiceName, InfoBarInstantRecord, InfoBarSeek, InfoBarTimeshift, InfoBarTimeshiftState, InfoBarSubtitleSupport]:
+               for x in InfoBarBase, InfoBarShowHide, InfoBarMenu, \
+                               InfoBarInstantRecord, InfoBarSeek, InfoBarTimeshift, \
+                               InfoBarTimeshiftState, InfoBarSubtitleSupport, \
+                               InfoBarExtensions, InfoBarAudioSelection:
                        x.__init__(self)
-               InfoBarExtensions.__init__(self, useServicePath = False)
-
 
                self.restoreService = self.session.nav.getCurrentlyPlayingServiceReference()
                
@@ -21,9 +29,11 @@ class SubservicesQuickzap(InfoBarShowHide, InfoBarMenu, InfoBarServiceName, Info
                
                self.updateSubservices()
                self.currentlyPlayingSubservice = 0
-               
-               self.onLayoutFinish.append(self.playSubservice)
-                               
+
+               self.timer = eTimer()
+               self.timer.callback.append(self.playSubservice)
+               self.onLayoutFinish.append(self.onLayoutFinished)
+
                self["actions"] = NumberActionMap( [ "InfobarSubserviceQuickzapActions", "NumberActions", "DirectionActions", "ColorActions" ], 
                        {
                                "up": self.showSelection,
@@ -42,10 +52,16 @@ class SubservicesQuickzap(InfoBarShowHide, InfoBarMenu, InfoBarServiceName, Info
                                "8": self.keyNumberGlobal,
                                "9": self.keyNumberGlobal,
                                "0": self.keyNumberGlobal
-                       }, -1)
-
-       
+                       }, 0)
                
+               self.onClose.append(self.__onClose)
+
+       def __onClose(self):
+               self.session.nav.playService(self.restoreService, False)
+
+       def onLayoutFinished(self):
+               self.timer.start(0,True)
+
        def updateSubservices(self):
                self.service = self.session.nav.getCurrentService()
                self.subservices = self.service and self.service.subServices()
@@ -53,40 +69,50 @@ class SubservicesQuickzap(InfoBarShowHide, InfoBarMenu, InfoBarServiceName, Info
        
        def nextSubservice(self):
                self.updateSubservices()
-               if self.currentlyPlayingSubservice == self.n - 1:
-                       self.playSubservice(0)
-               else:
-                       self.playSubservice(self.currentlyPlayingSubservice + 1)
+               if self.n:
+                       if self.currentlyPlayingSubservice >= self.n - 1:
+                               self.playSubservice(0)
+                       else:
+                               self.playSubservice(self.currentlyPlayingSubservice + 1)
        
        def previousSubservice(self):
                self.updateSubservices()
-               if self.currentlyPlayingSubservice == 0:
-                       self.playSubservice(self.n - 1)
-               else:
-                       self.playSubservice(self.currentlyPlayingSubservice - 1)
-       
+               if self.n:
+                       if self.currentlyPlayingSubservice > self.n:
+                               self.currentlyPlayingSubservice = self.n
+                       if self.currentlyPlayingSubservice == 0:
+                               self.playSubservice(self.n - 1)
+                       else:
+                               self.playSubservice(self.currentlyPlayingSubservice - 1)
+
        def getSubserviceIndex(self, service):
                self.updateSubservices()
+               if self.n is None:
+                       return -1
                for x in range(self.n):
                        if service == self.subservices.getSubservice(x):
-                               return self.n
+                               return x
        
        def keyNumberGlobal(self, number):
                print number, "pressed"
                self.updateSubservices()
                if number == 0:
                        self.playSubservice(self.lastservice)
-               elif number <= self.n - 1:
+               elif self.n is not None and number <= self.n - 1:
                        self.playSubservice(number)
        
        def showSelection(self):
                self.updateSubservices()
                tlist = []
-               for x in range(self.n):
-                       i = self.subservices.getSubservice(x)
-                       tlist.append((i.getName(), x))
+               n = self.n or 0
+               if n:
+                       idx = 0
+                       while idx < n:
+                               i = self.subservices.getSubservice(idx)
+                               tlist.append((i.getName(), idx))
+                               idx += 1
 
-               keys = [ "", "1", "2", "3", "4", "5", "6", "7", "8", "9" ] + [""] * self.n
+               keys = [ "", "1", "2", "3", "4", "5", "6", "7", "8", "9" ] + [""] * n
                self.session.openWithCallback(self.subserviceSelected, ChoiceBox, title=_("Please select a subservice..."), list = tlist, selection = self.currentlyPlayingSubservice, keys = keys)
        
        def subserviceSelected(self, service):
@@ -102,7 +128,6 @@ class SubservicesQuickzap(InfoBarShowHide, InfoBarMenu, InfoBarServiceName, Info
        
        def quit(self, answer):
                if answer:
-                       self.session.nav.playService(self.restoreService)
                        self.close()
                
        def playSubservice(self, number = 0):
@@ -111,7 +136,7 @@ class SubservicesQuickzap(InfoBarShowHide, InfoBarMenu, InfoBarServiceName, Info
                        del self.subservices
                        del self.service
                        self.lastservice = self.currentlyPlayingSubservice
-                       self.session.nav.playService(newservice)
+                       self.session.nav.playService(newservice, False)
                        self.currentlyPlayingSubservice = number
                        self.currentSubserviceNumberLabel.setText(str(number))
-                       self.doShow()
\ No newline at end of file
+                       self.doShow()