1 from enigma import eServiceCenter, eServiceReference, pNavigation, getBestPlayableServiceReference, iPlayableService
2 from Components.ParentalControl import parentalControl
3 from Tools.BoundFunction import boundFunction
7 import NavigationInstance
8 import ServiceReference
10 # TODO: remove pNavgation, eNavigation and rewrite this stuff in python.
13 if NavigationInstance.instance is not None:
14 raise NavigationInstance.instance
16 NavigationInstance.instance = self
17 self.ServiceHandler = eServiceCenter.getInstance()
19 import Navigation as Nav
22 self.pnav = pNavigation()
23 self.pnav.m_event.get().append(self.dispatchEvent)
24 self.pnav.m_record_event.get().append(self.dispatchRecordEvent)
26 self.record_event = [ ]
27 self.currentlyPlayingServiceReference = None
28 self.currentlyPlayingService = None
29 self.RecordTimer = RecordTimer.RecordTimer()
30 self.SleepTimer = SleepTimer.SleepTimer()
32 def dispatchEvent(self, i):
35 if i == iPlayableService.evEnd:
36 self.currentlyPlayingServiceReference = None
37 self.currentlyPlayingService = None
39 def dispatchRecordEvent(self, rec_service, event):
40 # print "record_event", rec_service, event
41 for x in self.record_event:
44 def playService(self, ref, checkParentalControl = True):
45 oldref = self.currentlyPlayingServiceReference
46 if ref and oldref and ref == oldref:
47 print "ignore request to play already running service"
49 print "playing", ref and ref.toString()
53 if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl = False)):
54 if ref.flags & eServiceReference.isGroup:
56 oldref = eServiceReference()
57 playref = getBestPlayableServiceReference(ref, oldref)
58 if not playref or (checkParentalControl and not parentalControl.isServicePlayable(playref, boundFunction(self.playService, checkParentalControl = False))):
63 if self.pnav and not self.pnav.playService(playref):
64 self.currentlyPlayingServiceReference = playref
70 def getCurrentlyPlayingServiceReference(self):
71 return self.currentlyPlayingServiceReference
73 def recordService(self, ref):
75 print "recording service: %s" % (str(ref))
76 if isinstance(ref, ServiceReference.ServiceReference):
79 if ref.flags & eServiceReference.isGroup:
80 ref = getBestPlayableServiceReference(ref, eServiceReference())
81 service = ref and self.pnav and self.pnav.recordService(ref)
83 print "record returned non-zero"
86 def stopRecordService(self, service):
87 ret = self.pnav and self.pnav.stopRecordService(service)
90 def getRecordings(self):
91 return self.pnav and self.pnav.getRecordings()
93 def getCurrentService(self):
94 if not self.currentlyPlayingService:
95 self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
96 return self.currentlyPlayingService
98 def stopService(self):
101 self.pnav.stopService()
104 return self.pnav and self.pnav.pause(p)
106 def recordWithTimer(self, ref, begin, end, name, description, eit):
107 if isinstance(ref, eServiceReference):
108 ref = ServiceReference.ServiceReference(ref)
109 entry = RecordTimer.RecordTimerEntry(ref, begin, end, name, description, eit)
110 self.RecordTimer.record(entry)
114 self.RecordTimer.shutdown()
115 self.ServiceHandler = None
118 def stopUserServices(self):