1 from enigma import eServiceCenter, eServiceReference, eTimer, pNavigation, getBestPlayableServiceReference, iPlayableService, eActionMap
2 from Components.ParentalControl import parentalControl
3 from Components.config import config
4 from Tools.BoundFunction import boundFunction
5 from Tools.StbHardware import setFPWakeuptime, getFPWakeuptime, getFPWasTimerWakeup
6 from Tools import Notifications
7 from time import time, localtime
10 import NavigationInstance
11 import ServiceReference
12 from Screens.InfoBar import InfoBar
13 from sys import maxint
15 # TODO: remove pNavgation, eNavigation and rewrite this stuff in python.
18 if NavigationInstance.instance is not None:
19 raise NavigationInstance.instance
21 NavigationInstance.instance = self
22 self.ServiceHandler = eServiceCenter.getInstance()
24 import Navigation as Nav
27 self.pnav = pNavigation()
28 self.pnav.m_event.get().append(self.dispatchEvent)
29 self.pnav.m_record_event.get().append(self.dispatchRecordEvent)
31 self.record_event = [ ]
32 self.currentlyPlayingServiceReference = None
33 self.currentlyPlayingServiceOrGroup = None
34 self.currentlyPlayingService = None
35 self.RecordTimer = RecordTimer.RecordTimer()
36 self.__wasTimerWakeup = getFPWasTimerWakeup()
37 if self.__wasTimerWakeup:
38 if Screens.Standby.inStandby: #In case some plugin did put the receiver already in standby
39 config.misc.standbyCounter.value = 0
40 RecordTimer.RecordTimerEntry.setWasInDeepStandby()
42 def wasTimerWakeup(self):
43 return self.__wasTimerWakeup
45 def dispatchEvent(self, i):
48 if i == iPlayableService.evEnd:
49 self.currentlyPlayingServiceReference = None
50 self.currentlyPlayingServiceOrGroup = None
51 self.currentlyPlayingService = None
53 def dispatchRecordEvent(self, rec_service, event):
54 # print "record_event", rec_service, event
55 for x in self.record_event:
58 def playService(self, ref, checkParentalControl=True, forceRestart=False):
59 oldref = self.currentlyPlayingServiceReference
60 if ref and oldref and ref == oldref and not forceRestart:
61 print "ignore request to play already running service(1)"
63 print "playing", ref and ref.toString()
67 InfoBarInstance = InfoBar.instance
68 if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl=False, forceRestart=forceRestart)):
69 if ref.flags & eServiceReference.isGroup:
71 oldref = eServiceReference()
72 playref = getBestPlayableServiceReference(ref, oldref)
73 print "playref", playref
74 if playref and oldref and playref == oldref and not forceRestart:
75 print "ignore request to play already running service(2)"
77 if not playref or (checkParentalControl and not parentalControl.isServicePlayable(playref, boundFunction(self.playService, checkParentalControl = False))):
83 self.pnav.stopService()
84 self.currentlyPlayingServiceReference = playref
85 self.currentlyPlayingServiceOrGroup = ref
86 if InfoBarInstance is not None:
87 InfoBarInstance.servicelist.servicelist.setCurrent(ref)
88 if self.pnav.playService(playref):
89 print "Failed to start", playref
90 self.currentlyPlayingServiceReference = None
91 self.currentlyPlayingServiceOrGroup = None
94 InfoBarInstance.servicelist.servicelist.setCurrent(oldref)
97 def getCurrentlyPlayingServiceReference(self):
98 return self.currentlyPlayingServiceReference
100 def getCurrentlyPlayingServiceOrGroup(self):
101 return self.currentlyPlayingServiceOrGroup
103 def recordService(self, ref, simulate=False):
105 if not simulate: print "recording service: %s" % (str(ref))
106 if isinstance(ref, ServiceReference.ServiceReference):
109 if ref.flags & eServiceReference.isGroup:
110 ref = getBestPlayableServiceReference(ref, eServiceReference(), simulate)
111 service = ref and self.pnav and self.pnav.recordService(ref, simulate)
113 print "record returned non-zero"
116 def stopRecordService(self, service):
117 ret = self.pnav and self.pnav.stopRecordService(service)
120 def getRecordings(self, simulate=False):
121 return self.pnav and self.pnav.getRecordings(simulate)
123 def getCurrentService(self):
124 if not self.currentlyPlayingService:
125 self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
126 return self.currentlyPlayingService
128 def stopService(self):
130 self.pnav.stopService()
131 self.currentlyPlayingServiceReference = None
132 self.currentlyPlayingServiceOrGroup = None
135 return self.pnav and self.pnav.pause(p)
138 self.RecordTimer.shutdown()
139 self.ServiceHandler = None
142 def stopUserServices(self):