1 from enigma import eServiceCenter, eServiceReference, eTimer, pNavigation, getBestPlayableServiceReference, iPlayableService, eActionMap
2 from Components.ParentalControl import parentalControl
3 from Components.config import config, configfile
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 RecordTimer.RecordTimerEntry.setWasInDeepStandby()
39 if config.misc.RestartUI.value:
40 config.misc.RestartUI.value = False
41 config.misc.RestartUI.save()
43 elif config.usage.startup_to_standby.value or self.__wasTimerWakeup:
44 Notifications.AddNotification(Screens.Standby.Standby)
46 def wasTimerWakeup(self):
47 return self.__wasTimerWakeup
49 def dispatchEvent(self, i):
52 if i == iPlayableService.evEnd:
53 self.currentlyPlayingServiceReference = None
54 self.currentlyPlayingServiceOrGroup = None
55 self.currentlyPlayingService = None
57 def dispatchRecordEvent(self, rec_service, event):
58 # print "record_event", rec_service, event
59 for x in self.record_event:
62 def playService(self, ref, checkParentalControl=True, forceRestart=False, adjust=True):
63 oldref = self.currentlyPlayingServiceOrGroup
64 if ref and oldref and ref == oldref and not forceRestart:
65 print "ignore request to play already running service(1)"
67 print "playing", ref and ref.toString()
71 from Components.ServiceEventTracker import InfoBarCount
72 InfoBarInstance = InfoBarCount == 1 and InfoBar.instance
73 if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl=False, forceRestart=forceRestart, adjust=adjust)):
74 if ref.flags & eServiceReference.isGroup:
75 oldref = self.currentlyPlayingServiceReference or eServiceReference()
76 playref = getBestPlayableServiceReference(ref, oldref)
77 print "playref", playref
78 if playref and oldref and playref == oldref and not forceRestart:
79 print "ignore request to play already running service(2)"
81 if not playref or (checkParentalControl and not parentalControl.isServicePlayable(playref, boundFunction(self.playService, checkParentalControl = False))):
87 self.pnav.stopService()
88 self.currentlyPlayingServiceReference = playref
89 self.currentlyPlayingServiceOrGroup = ref
90 if InfoBarInstance and InfoBarInstance.servicelist.servicelist.setCurrent(ref, adjust):
91 self.currentlyPlayingServiceOrGroup = InfoBarInstance.servicelist.servicelist.getCurrent()
92 if self.pnav.playService(playref):
93 print "Failed to start", playref
94 self.currentlyPlayingServiceReference = None
95 self.currentlyPlayingServiceOrGroup = None
97 elif oldref and InfoBarInstance and InfoBarInstance.servicelist.servicelist.setCurrent(oldref, adjust):
98 self.currentlyPlayingServiceOrGroup = InfoBarInstance.servicelist.servicelist.getCurrent()
101 def getCurrentlyPlayingServiceReference(self):
102 return self.currentlyPlayingServiceReference
104 def getCurrentlyPlayingServiceOrGroup(self):
105 return self.currentlyPlayingServiceOrGroup
107 def recordService(self, ref, simulate=False):
109 if not simulate: print "recording service: %s" % (str(ref))
110 if isinstance(ref, ServiceReference.ServiceReference):
113 if ref.flags & eServiceReference.isGroup:
114 ref = getBestPlayableServiceReference(ref, eServiceReference(), simulate)
115 service = ref and self.pnav and self.pnav.recordService(ref, simulate)
117 print "record returned non-zero"
120 def stopRecordService(self, service):
121 ret = self.pnav and self.pnav.stopRecordService(service)
124 def getRecordings(self, simulate=False):
125 return self.pnav and self.pnav.getRecordings(simulate)
127 def getCurrentService(self):
128 if not self.currentlyPlayingService:
129 self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
130 return self.currentlyPlayingService
132 def stopService(self):
134 self.pnav.stopService()
135 self.currentlyPlayingServiceReference = None
136 self.currentlyPlayingServiceOrGroup = None
139 return self.pnav and self.pnav.pause(p)
142 self.RecordTimer.shutdown()
143 self.ServiceHandler = None
146 def stopUserServices(self):