1 from enigma import eServiceCenter, eServiceReference, eTimer, pNavigation, getBestPlayableServiceReference, iPlayableService
2 from Components.ParentalControl import parentalControl
3 from Tools.BoundFunction import boundFunction
4 from Tools.StbHardware import setFPWakeuptime, getFPWakeuptime, getFPWasTimerWakeup
8 import NavigationInstance
9 import ServiceReference
10 from Screens.InfoBar import InfoBar
12 # TODO: remove pNavgation, eNavigation and rewrite this stuff in python.
14 def __init__(self, nextRecordTimerAfterEventActionAuto=False):
15 if NavigationInstance.instance is not None:
16 raise NavigationInstance.instance
18 NavigationInstance.instance = self
19 self.ServiceHandler = eServiceCenter.getInstance()
21 import Navigation as Nav
24 self.pnav = pNavigation()
25 self.pnav.m_event.get().append(self.dispatchEvent)
26 self.pnav.m_record_event.get().append(self.dispatchRecordEvent)
28 self.record_event = [ ]
29 self.currentlyPlayingServiceReference = None
30 self.currentlyPlayingServiceOrGroup = None
31 self.currentlyPlayingService = None
32 self.RecordTimer = RecordTimer.RecordTimer()
33 self.__wasTimerWakeup = False
34 if getFPWasTimerWakeup():
35 self.__wasTimerWakeup = True
36 if nextRecordTimerAfterEventActionAuto:
37 # We need to give the systemclock the chance to sync with the transponder time,
38 # before we will make the decision about whether or not we need to shutdown
39 # after the upcoming recording has completed
40 self.recordshutdowntimer = eTimer()
41 self.recordshutdowntimer.callback.append(self.checkShutdownAfterRecording)
42 self.recordshutdowntimer.start(30000, True)
44 def wasTimerWakeup(self):
45 return self.__wasTimerWakeup
47 def checkShutdownAfterRecording(self):
48 if len(self.getRecordings()) or abs(self.RecordTimer.getNextRecordingTime() - time()) <= 360:
49 if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
50 RecordTimer.RecordTimerEntry.TryQuitMainloop(False) # start shutdown handling
52 def dispatchEvent(self, i):
55 if i == iPlayableService.evEnd:
56 self.currentlyPlayingServiceReference = None
57 self.currentlyPlayingServiceOrGroup = None
58 self.currentlyPlayingService = None
60 def dispatchRecordEvent(self, rec_service, event):
61 # print "record_event", rec_service, event
62 for x in self.record_event:
65 def playService(self, ref, checkParentalControl=True, forceRestart=False):
66 oldref = self.currentlyPlayingServiceReference
67 if ref and oldref and ref == oldref and not forceRestart:
68 print "ignore request to play already running service(1)"
70 print "playing", ref and ref.toString()
74 InfoBarInstance = InfoBar.instance
75 if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl=False, forceRestart=forceRestart)):
76 if ref.flags & eServiceReference.isGroup:
78 oldref = eServiceReference()
79 playref = getBestPlayableServiceReference(ref, oldref)
80 print "playref", playref
81 if playref and oldref and playref == oldref and not forceRestart:
82 print "ignore request to play already running service(2)"
84 if not playref or (checkParentalControl and not parentalControl.isServicePlayable(playref, boundFunction(self.playService, checkParentalControl = False))):
90 self.pnav.stopService()
91 self.currentlyPlayingServiceReference = playref
92 self.currentlyPlayingServiceOrGroup = ref
93 if InfoBarInstance is not None:
94 InfoBarInstance.servicelist.servicelist.setCurrent(ref)
95 if self.pnav.playService(playref):
96 print "Failed to start", playref
97 self.currentlyPlayingServiceReference = None
98 self.currentlyPlayingServiceOrGroup = None
101 InfoBarInstance.servicelist.servicelist.setCurrent(oldref)
104 def getCurrentlyPlayingServiceReference(self):
105 return self.currentlyPlayingServiceReference
107 def getCurrentlyPlayingServiceOrGroup(self):
108 return self.currentlyPlayingServiceOrGroup
110 def recordService(self, ref, simulate=False):
112 if not simulate: print "recording service: %s" % (str(ref))
113 if isinstance(ref, ServiceReference.ServiceReference):
116 if ref.flags & eServiceReference.isGroup:
117 ref = getBestPlayableServiceReference(ref, eServiceReference(), simulate)
118 service = ref and self.pnav and self.pnav.recordService(ref, simulate)
120 print "record returned non-zero"
123 def stopRecordService(self, service):
124 ret = self.pnav and self.pnav.stopRecordService(service)
127 def getRecordings(self, simulate=False):
128 return self.pnav and self.pnav.getRecordings(simulate)
130 def getCurrentService(self):
131 if not self.currentlyPlayingService:
132 self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
133 return self.currentlyPlayingService
135 def stopService(self):
137 self.pnav.stopService()
138 self.currentlyPlayingServiceReference = None
139 self.currentlyPlayingServiceOrGroup = None
142 return self.pnav and self.pnav.pause(p)
145 self.RecordTimer.shutdown()
146 self.ServiceHandler = None
149 def stopUserServices(self):