add support for dm8000 rtc,
[openblackhole/openblackhole-enigma2.git] / Navigation.py
1 from enigma import eServiceCenter, eServiceReference, pNavigation, getBestPlayableServiceReference, iPlayableService
2 from Components.ParentalControl import parentalControl
3 from Tools.BoundFunction import boundFunction
4 from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime, getFPWasTimerWakeup, clearFPWasTimerWakeup
5 from time import time
6 import RecordTimer
7 import SleepTimer
8 import Screens.Standby
9 import NavigationInstance
10 import ServiceReference
11
12 # TODO: remove pNavgation, eNavigation and rewrite this stuff in python.
13 class Navigation:
14         def __init__(self):
15                 if NavigationInstance.instance is not None:
16                         raise NavigationInstance.instance
17                 
18                 NavigationInstance.instance = self
19                 self.ServiceHandler = eServiceCenter.getInstance()
20                 
21                 import Navigation as Nav
22                 Nav.navcore = self
23                 
24                 self.pnav = pNavigation()
25                 self.pnav.m_event.get().append(self.dispatchEvent)
26                 self.pnav.m_record_event.get().append(self.dispatchRecordEvent)
27                 self.event = [ ]
28                 self.record_event = [ ]
29                 self.currentlyPlayingServiceReference = None
30                 self.currentlyPlayingService = None
31                 self.RecordTimer = RecordTimer.RecordTimer()
32                 if getFPWasTimerWakeup():
33                         clearFPWasTimerWakeup()
34                         if getFPWasTimerWakeup(): # sanity check to detect if the FP driver is working correct!
35                                 print "buggy fp driver detected!!! please update drivers.... ignore timer wakeup!"
36                                 setFPWakeuptime(0)
37                         elif len(self.getRecordings()) or abs(self.RecordTimer.getNextRecordingTime() - time()) <= 360:
38                                 setFPWakeuptime(0x89ABCDEF)
39                                 if getFPWakeuptime() != 0x89ABCDEF: # sanity check to detect if the FP Atmel Firmware is working correct!
40                                         print "buggy atmel firmware detected!! atmel update needed... ignore fp timer wakeup!"
41                                         setFPWakeuptime(0)
42                                 elif not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
43                                         RecordTimer.RecordTimerEntry.TryQuitMainloop(0) # start shutdown handling
44                 setFPWakeuptime(1)
45                 self.SleepTimer = SleepTimer.SleepTimer()
46
47         def dispatchEvent(self, i):
48                 for x in self.event:
49                         x(i)
50                 if i == iPlayableService.evEnd:
51                         self.currentlyPlayingServiceReference = None
52                         self.currentlyPlayingService = None
53
54         def dispatchRecordEvent(self, rec_service, event):
55 #               print "record_event", rec_service, event
56                 for x in self.record_event:
57                         x(rec_service, event)
58
59         def playService(self, ref, checkParentalControl = True):
60                 oldref = self.currentlyPlayingServiceReference
61                 if ref and oldref and ref == oldref:
62                         print "ignore request to play already running service"
63                         return 0
64                 print "playing", ref and ref.toString()
65                 if ref is None:
66                         self.stopService()
67                         return 0
68                 if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl = False)):
69                         if ref.flags & eServiceReference.isGroup:
70                                 if not oldref:
71                                         oldref = eServiceReference()
72                                 playref = getBestPlayableServiceReference(ref, oldref)
73                                 if not playref or (checkParentalControl and not parentalControl.isServicePlayable(playref, boundFunction(self.playService, checkParentalControl = False))):
74                                         self.stopService()
75                                         return 0
76                         else:
77                                 playref = ref
78                         if self.pnav and not self.pnav.playService(playref):
79                                 self.currentlyPlayingServiceReference = playref
80                                 return 0
81                 else:
82                         self.stopService()
83                 return 1
84         
85         def getCurrentlyPlayingServiceReference(self):
86                 return self.currentlyPlayingServiceReference
87         
88         def recordService(self, ref):
89                 service = None
90                 print "recording service: %s" % (str(ref))
91                 if isinstance(ref, ServiceReference.ServiceReference):
92                         ref = ref.ref
93                 if ref:
94                         if ref.flags & eServiceReference.isGroup:
95                                 ref = getBestPlayableServiceReference(ref, eServiceReference())
96                         service = ref and self.pnav and self.pnav.recordService(ref)
97                         if service is None:
98                                 print "record returned non-zero"
99                 return service
100
101         def stopRecordService(self, service):
102                 ret = self.pnav and self.pnav.stopRecordService(service)
103                 return ret
104
105         def getRecordings(self):
106                 return self.pnav and self.pnav.getRecordings()
107
108         def getCurrentService(self):
109                 if not self.currentlyPlayingService:
110                         self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
111                 return self.currentlyPlayingService
112
113         def stopService(self):
114                 print "stopService"
115                 if self.pnav:
116                         self.pnav.stopService()
117
118         def pause(self, p):
119                 return self.pnav and self.pnav.pause(p)
120
121         def shutdown(self):
122                 self.RecordTimer.shutdown()
123                 self.ServiceHandler = None
124                 self.pnav = None
125
126         def stopUserServices(self):
127                 self.stopService()