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.DreamboxHardware import setFPWakeuptime, getFPWakeuptime, getFPWasTimerWakeup
9 import NavigationInstance
10 import ServiceReference
11 from Screens.InfoBar import InfoBar
13 # TODO: remove pNavgation, eNavigation and rewrite this stuff in python.
15 def __init__(self, nextRecordTimerAfterEventActionAuto=False):
16 if NavigationInstance.instance is not None:
17 raise NavigationInstance.instance
19 NavigationInstance.instance = self
20 self.ServiceHandler = eServiceCenter.getInstance()
22 import Navigation as Nav
25 self.pnav = pNavigation()
26 self.pnav.m_event.get().append(self.dispatchEvent)
27 self.pnav.m_record_event.get().append(self.dispatchRecordEvent)
29 self.record_event = [ ]
30 self.currentlyPlayingServiceReference = None
31 self.currentlyPlayingService = None
32 self.RecordTimer = RecordTimer.RecordTimer()
33 if getFPWasTimerWakeup():
34 if nextRecordTimerAfterEventActionAuto:
35 # We need to give the systemclock the chance to sync with the transponder time,
36 # before we will make the decision about whether or not we need to shutdown
37 # after the upcoming recording has completed
38 self.recordshutdowntimer = eTimer()
39 self.recordshutdowntimer.callback.append(self.checkShutdownAfterRecording)
40 self.recordshutdowntimer.start(30000, True)
41 self.SleepTimer = SleepTimer.SleepTimer()
43 def checkShutdownAfterRecording(self):
44 if len(self.getRecordings()) or abs(self.RecordTimer.getNextRecordingTime() - time()) <= 360:
45 if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
46 RecordTimer.RecordTimerEntry.TryQuitMainloop(False) # start shutdown handling
48 def dispatchEvent(self, i):
51 if i == iPlayableService.evEnd:
52 self.currentlyPlayingServiceReference = None
53 self.currentlyPlayingService = None
55 def dispatchRecordEvent(self, rec_service, event):
56 # print "record_event", rec_service, event
57 for x in self.record_event:
60 def playService(self, ref, checkParentalControl = True, forceRestart = False):
61 oldref = self.currentlyPlayingServiceReference
62 if ref and oldref and ref == oldref and not forceRestart:
63 print "ignore request to play already running service(1)"
65 print "playing", ref and ref.toString()
69 if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl = False)):
70 if ref.flags & eServiceReference.isGroup:
72 oldref = eServiceReference()
73 playref = getBestPlayableServiceReference(ref, oldref)
74 print "playref", playref
75 if playref and oldref and playref == oldref and not forceRestart:
76 print "ignore request to play already running service(2)"
78 if not playref or (checkParentalControl and not parentalControl.isServicePlayable(playref, boundFunction(self.playService, checkParentalControl = False))):
84 self.pnav.stopService()
85 self.currentlyPlayingServiceReference = playref
86 InfoBarInstance = InfoBar.instance
87 if InfoBarInstance is not None:
88 InfoBarInstance.servicelist.servicelist.setCurrent(ref)
89 if self.pnav.playService(playref):
90 print "Failed to start", playref
91 self.currentlyPlayingServiceReference = None
97 def getCurrentlyPlayingServiceReference(self):
98 return self.currentlyPlayingServiceReference
100 def recordService(self, ref, simulate=False):
102 if not simulate: print "recording service: %s" % (str(ref))
103 if isinstance(ref, ServiceReference.ServiceReference): ref = ref.ref
105 if ref.flags & eServiceReference.isGroup:
106 ref = getBestPlayableServiceReference(ref, eServiceReference(), simulate)
107 service = ref and self.pnav and self.pnav.recordService(ref, simulate)
109 print "record returned non-zero"
112 def stopRecordService(self, service):
113 ret = self.pnav and self.pnav.stopRecordService(service)
116 def getRecordings(self, simulate=False):
117 return self.pnav and self.pnav.getRecordings(simulate)
119 def getCurrentService(self):
120 if not self.currentlyPlayingService:
121 self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
122 return self.currentlyPlayingService
124 def stopService(self):
126 self.pnav.stopService()
129 return self.pnav and self.pnav.pause(p)
132 self.RecordTimer.shutdown()
133 self.ServiceHandler = None
136 def stopUserServices(self):