ChannelSelection: fix zapBack if use "Enable OK as preview in channel selection"
[openblackhole/openblackhole-enigma2.git] / Navigation.py
index b94685c..02c641e 100644 (file)
@@ -1,6 +1,7 @@
-from enigma import eServiceCenter, eServiceReference, eTimer, pNavigation, getBestPlayableServiceReference, iPlayableService, eActionMap
+from enigma import eServiceCenter, eServiceReference, eTimer, pNavigation, getBestPlayableServiceReference, iPlayableService, eActionMap, setPreferredTuner, eStreamServer
 from Components.ParentalControl import parentalControl
-from Components.config import config
+from Components.SystemInfo import SystemInfo
+from Components.config import config, configfile
 from Tools.BoundFunction import boundFunction
 from Tools.StbHardware import setFPWakeuptime, getFPWakeuptime, getFPWasTimerWakeup
 from Tools import Notifications
@@ -34,10 +35,21 @@ class Navigation:
                self.currentlyPlayingService = None
                self.RecordTimer = RecordTimer.RecordTimer()
                self.__wasTimerWakeup = getFPWasTimerWakeup()
+               startup_to_standby = config.usage.startup_to_standby.value
+               wakeup_time_type = config.misc.prev_wakeup_time_type.value
                if self.__wasTimerWakeup:
-                       if Screens.Standby.inStandby: #In case some plugin did put the receiver already in standby
-                               config.misc.standbyCounter.value = 0
                        RecordTimer.RecordTimerEntry.setWasInDeepStandby()
+               if config.misc.RestartUI.value:
+                       config.misc.RestartUI.value = False
+                       config.misc.RestartUI.save()
+                       configfile.save()
+               elif startup_to_standby == "yes" or self.__wasTimerWakeup and config.misc.prev_wakeup_time.value and ((wakeup_time_type == 0 or wakeup_time_type == 1) or ( wakeup_time_type == 3 and startup_to_standby == "except")):
+                       if not Screens.Standby.inTryQuitMainloop:
+                               Notifications.AddNotification(Screens.Standby.Standby)
+               if config.misc.prev_wakeup_time.value:
+                       config.misc.prev_wakeup_time.value = 0
+                       config.misc.prev_wakeup_time.save()
+                       configfile.save()
 
        def wasTimerWakeup(self):
                return self.__wasTimerWakeup
@@ -55,43 +67,72 @@ class Navigation:
                for x in self.record_event:
                        x(rec_service, event)
 
-       def playService(self, ref, checkParentalControl=True, forceRestart=False):
-               oldref = self.currentlyPlayingServiceReference
+       def playService(self, ref, checkParentalControl=True, forceRestart=False, adjust=True):
+               oldref = self.currentlyPlayingServiceOrGroup
                if ref and oldref and ref == oldref and not forceRestart:
                        print "ignore request to play already running service(1)"
-                       return 0
+                       return 1
                print "playing", ref and ref.toString()
                if ref is None:
                        self.stopService()
                        return 0
-               InfoBarInstance = InfoBar.instance
-               if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl=False, forceRestart=forceRestart)):
+               from Components.ServiceEventTracker import InfoBarCount
+               InfoBarInstance = InfoBarCount == 1 and InfoBar.instance
+               if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl=False, forceRestart=forceRestart, adjust=adjust)):
                        if ref.flags & eServiceReference.isGroup:
-                               if not oldref:
-                                       oldref = eServiceReference()
+                               oldref = self.currentlyPlayingServiceReference or eServiceReference()
                                playref = getBestPlayableServiceReference(ref, oldref)
                                print "playref", playref
                                if playref and oldref and playref == oldref and not forceRestart:
                                        print "ignore request to play already running service(2)"
-                                       return 0
-                               if not playref or (checkParentalControl and not parentalControl.isServicePlayable(playref, boundFunction(self.playService, checkParentalControl = False))):
+                                       return 1
+                               if not playref:
+                                       alternativeref = getBestPlayableServiceReference(ref, eServiceReference(), True)
                                        self.stopService()
+                                       if alternativeref and self.pnav and self.pnav.playService(alternativeref):
+                                               print "Failed to start", alternativeref
                                        return 0
+                               elif checkParentalControl and not parentalControl.isServicePlayable(playref, boundFunction(self.playService, checkParentalControl = False)):
+                                       if self.currentlyPlayingServiceOrGroup and InfoBarInstance and InfoBarInstance.servicelist.servicelist.setCurrent(self.currentlyPlayingServiceOrGroup, adjust):
+                                               self.currentlyPlayingServiceOrGroup = InfoBarInstance.servicelist.servicelist.getCurrent()
+                                       return 1
                        else:
                                playref = ref
                        if self.pnav:
                                self.pnav.stopService()
                                self.currentlyPlayingServiceReference = playref
                                self.currentlyPlayingServiceOrGroup = ref
-                               if InfoBarInstance is not None:
-                                       InfoBarInstance.servicelist.servicelist.setCurrent(ref)
+                               if InfoBarInstance and InfoBarInstance.servicelist.servicelist.setCurrent(ref, adjust):
+                                       self.currentlyPlayingServiceOrGroup = InfoBarInstance.servicelist.servicelist.getCurrent()
+                               setPriorityFrontend = False
+                               if SystemInfo["DVB-T_priority_tuner_available"] or SystemInfo["DVB-C_priority_tuner_available"] or SystemInfo["DVB-S_priority_tuner_available"]:
+                                       str_service = playref.toString()
+                                       if '%3a//' not in str_service and not str_service.rsplit(":", 1)[1].startswith("/"):
+                                               type_service = playref.getUnsignedData(4) >> 16
+                                               if type_service == 0xEEEE:
+                                                       if config.usage.frontend_priority_dvbt.value != "-2":
+                                                               if config.usage.frontend_priority_dvbt.value != config.usage.frontend_priority.value:
+                                                                       setPreferredTuner(int(config.usage.frontend_priority_dvbt.value))
+                                                                       setPriorityFrontend = True
+                                               elif type_service == 0xFFFF:
+                                                       if config.usage.frontend_priority_dvbc.value != "-2":
+                                                               if config.usage.frontend_priority_dvbc.value != config.usage.frontend_priority.value:
+                                                                       setPreferredTuner(int(config.usage.frontend_priority_dvbc.value))
+                                                                       setPriorityFrontend = True
+                                               else:
+                                                       if config.usage.frontend_priority_dvbs.value != "-2":
+                                                               if config.usage.frontend_priority_dvbs.value != config.usage.frontend_priority.value:
+                                                                       setPreferredTuner(int(config.usage.frontend_priority_dvbs.value))
+                                                                       setPriorityFrontend = True
                                if self.pnav.playService(playref):
                                        print "Failed to start", playref
                                        self.currentlyPlayingServiceReference = None
                                        self.currentlyPlayingServiceOrGroup = None
+                               if setPriorityFrontend:
+                                       setPreferredTuner(int(config.usage.frontend_priority.value))
                                return 0
-               elif oldref:
-                       InfoBarInstance.servicelist.servicelist.setCurrent(oldref)
+               elif oldref and InfoBarInstance and InfoBarInstance.servicelist.servicelist.setCurrent(oldref, adjust):
+                       self.currentlyPlayingServiceOrGroup = InfoBarInstance.servicelist.servicelist.getCurrent()
                return 1
 
        def getCurrentlyPlayingServiceReference(self):
@@ -141,3 +182,6 @@ class Navigation:
 
        def stopUserServices(self):
                self.stopService()
+
+       def getClientsStreaming(self):
+               return eStreamServer.getInstance() and eStreamServer.getInstance().getConnectedClients()