Revert "Navigation: Do only go to standby when recording timer is likely"
[openblackhole/openblackhole-enigma2.git] / Navigation.py
index d434641..84ac980 100644 (file)
@@ -1,10 +1,10 @@
 from enigma import eServiceCenter, eServiceReference, eTimer, pNavigation, getBestPlayableServiceReference, iPlayableService
 from Components.ParentalControl import parentalControl
 from Tools.BoundFunction import boundFunction
-from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime, getFPWasTimerWakeup
-from time import time
+from Tools.StbHardware import setFPWakeuptime, getFPWakeuptime, getFPWasTimerWakeup
+from Tools import Notifications
+from time import time, localtime
 import RecordTimer
-import SleepTimer
 import Screens.Standby
 import NavigationInstance
 import ServiceReference
@@ -12,44 +12,41 @@ from Screens.InfoBar import InfoBar
 
 # TODO: remove pNavgation, eNavigation and rewrite this stuff in python.
 class Navigation:
-       def __init__(self, nextRecordTimerAfterEventActionAuto=False):
+       def __init__(self):
                if NavigationInstance.instance is not None:
                        raise NavigationInstance.instance
-               
+
                NavigationInstance.instance = self
                self.ServiceHandler = eServiceCenter.getInstance()
-               
+
                import Navigation as Nav
                Nav.navcore = self
-               
+
                self.pnav = pNavigation()
                self.pnav.m_event.get().append(self.dispatchEvent)
                self.pnav.m_record_event.get().append(self.dispatchRecordEvent)
                self.event = [ ]
                self.record_event = [ ]
                self.currentlyPlayingServiceReference = None
+               self.currentlyPlayingServiceOrGroup = None
                self.currentlyPlayingService = None
                self.RecordTimer = RecordTimer.RecordTimer()
-               if getFPWasTimerWakeup():
-                       if nextRecordTimerAfterEventActionAuto:
-                               # We need to give the systemclock the chance to sync with the transponder time, 
-                               # before we will make the decision about whether or not we need to shutdown 
-                               # after the upcoming recording has completed
-                               self.recordshutdowntimer = eTimer()
-                               self.recordshutdowntimer.callback.append(self.checkShutdownAfterRecording)
-                               self.recordshutdowntimer.start(30000, True)
-               self.SleepTimer = SleepTimer.SleepTimer()
-
-       def checkShutdownAfterRecording(self):
-               if len(self.getRecordings()) or abs(self.RecordTimer.getNextRecordingTime() - time()) <= 360:
-                       if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
-                               RecordTimer.RecordTimerEntry.TryQuitMainloop(False) # start shutdown handling
+               self.__wasTimerWakeup = getFPWasTimerWakeup()
+               if self.__wasTimerWakeup:
+                       if Screens.Standby.inStandby: #In case some plugin did put the receiver already in standby
+                               config.misc.standbyCounter.value = 0
+                       else:
+                               Notifications.AddNotification(Screens.Standby.Standby, StandbyCounterIncrease=False)
+
+       def wasTimerWakeup(self):
+               return self.__wasTimerWakeup
 
        def dispatchEvent(self, i):
                for x in self.event:
                        x(i)
                if i == iPlayableService.evEnd:
                        self.currentlyPlayingServiceReference = None
+                       self.currentlyPlayingServiceOrGroup = None
                        self.currentlyPlayingService = None
 
        def dispatchRecordEvent(self, rec_service, event):
@@ -57,7 +54,7 @@ class Navigation:
                for x in self.record_event:
                        x(rec_service, event)
 
-       def playService(self, ref, checkParentalControl = True, forceRestart = False):
+       def playService(self, ref, checkParentalControl=True, forceRestart=False):
                oldref = self.currentlyPlayingServiceReference
                if ref and oldref and ref == oldref and not forceRestart:
                        print "ignore request to play already running service(1)"
@@ -66,7 +63,8 @@ class Navigation:
                if ref is None:
                        self.stopService()
                        return 0
-               if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl = False)):
+               InfoBarInstance = InfoBar.instance
+               if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl=False, forceRestart=forceRestart)):
                        if ref.flags & eServiceReference.isGroup:
                                if not oldref:
                                        oldref = eServiceReference()
@@ -83,23 +81,24 @@ class Navigation:
                        if self.pnav:
                                self.pnav.stopService()
                                self.currentlyPlayingServiceReference = playref
-                               self.currentlyPlayingSelectedServiceReference = ref
-                               InfoBarInstance = InfoBar.instance
+                               self.currentlyPlayingServiceOrGroup = ref
                                if InfoBarInstance is not None:
                                        InfoBarInstance.servicelist.servicelist.setCurrent(ref)
                                if self.pnav.playService(playref):
                                        print "Failed to start", playref
                                        self.currentlyPlayingServiceReference = None
+                                       self.currentlyPlayingServiceOrGroup = None
                                return 0
-               else:
-                       self.stopService()
+               elif oldref:
+                       InfoBarInstance.servicelist.servicelist.setCurrent(oldref)
                return 1
-       
-       def getCurrentlyPlayingServiceReference(self, selected = True):
-               if selected and self.currentlyPlayingServiceReference:
-                       return self.currentlyPlayingSelectedServiceReference
+
+       def getCurrentlyPlayingServiceReference(self):
                return self.currentlyPlayingServiceReference
 
+       def getCurrentlyPlayingServiceOrGroup(self):
+               return self.currentlyPlayingServiceOrGroup
+
        def recordService(self, ref, simulate=False):
                service = None
                if not simulate: print "recording service: %s" % (str(ref))
@@ -129,6 +128,7 @@ class Navigation:
                if self.pnav:
                        self.pnav.stopService()
                self.currentlyPlayingServiceReference = None
+               self.currentlyPlayingServiceOrGroup = None
 
        def pause(self, p):
                return self.pnav and self.pnav.pause(p)