1 from enigma import eServiceCenter, eServiceReference, pNavigation, getBestPlayableServiceReference
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):
36 def dispatchRecordEvent(self, rec_service, event):
37 # print "record_event", rec_service, event
38 for x in self.record_event:
41 def playService(self, ref, checkParentalControl = True):
42 oldref = self.currentlyPlayingServiceReference
43 if ref and oldref and ref == oldref:
44 print "ignore request to play already running service"
46 print "playing", ref and ref.toString()
47 self.currentlyPlayingServiceReference = None
48 self.currentlyPlayingService = None
52 if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl = False)):
53 if ref.flags & eServiceReference.isGroup:
55 oldref = eServiceReference()
56 playref = getBestPlayableServiceReference(ref, oldref)
57 if not playref or (checkParentalControl and not parentalControl.isServicePlayable(playref, boundFunction(self.playService, checkParentalControl = False))):
62 if self.pnav and not self.pnav.playService(playref):
63 self.currentlyPlayingServiceReference = playref
69 def getCurrentlyPlayingServiceReference(self):
70 return self.currentlyPlayingServiceReference
72 def recordService(self, ref):
74 print "recording service: %s" % (str(ref))
75 if isinstance(ref, ServiceReference.ServiceReference):
78 if ref.flags & eServiceReference.isGroup:
79 ref = getBestPlayableServiceReference(ref, eServiceReference())
80 service = ref and self.pnav and self.pnav.recordService(ref)
82 print "record returned non-zero"
85 def stopRecordService(self, service):
86 ret = self.pnav and self.pnav.stopRecordService(service)
89 def getRecordings(self):
90 return self.pnav and self.pnav.getRecordings()
92 def getCurrentService(self):
93 if not self.currentlyPlayingService:
94 self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
95 return self.currentlyPlayingService
97 def stopService(self):
100 self.pnav.stopService()
101 self.currentlyPlayingService = None
102 self.currentlyPlayingServiceReference = None
105 return self.pnav and self.pnav.pause(p)
107 def recordWithTimer(self, ref, begin, end, name, description, eit):
108 if isinstance(ref, eServiceReference):
109 ref = ServiceReference.ServiceReference(ref)
110 entry = RecordTimer.RecordTimerEntry(ref, begin, end, name, description, eit)
111 self.RecordTimer.record(entry)
115 self.RecordTimer.shutdown()
116 self.ServiceHandler = None
119 def stopUserServices(self):