recording service events now working
[openblackhole/openblackhole-enigma2.git] / Navigation.py
1 from enigma import *
2 from Components.ParentalControl import parentalControl
3 from Tools.BoundFunction import boundFunction
4 import RecordTimer
5 import SleepTimer
6
7 import NavigationInstance
8 import ServiceReference
9
10 from time import time
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.state = 0
32                 self.RecordTimer = RecordTimer.RecordTimer()
33                 self.SleepTimer = SleepTimer.SleepTimer()
34
35         def dispatchEvent(self, i):
36                 self.state = i != 1
37                 for x in self.event:
38                         x(i)
39
40         def dispatchRecordEvent(self, rec_service, event):
41 #               print "record_event", rec_service, event
42                 for x in self.record_event:
43                         x(rec_service, event)
44
45         def playService(self, ref, checkParentalControl = True):
46                 print "playing", ref and ref.toString()
47                 self.currentlyPlayingServiceReference = None
48                 self.currentlyPlayingService = None
49                 if ref is None:
50                         self.stopService()
51                         return 0
52                 
53                 if not checkParentalControl or parentalControl.isServicePlayable(ref.toCompareString(), boundFunction(self.playService, checkParentalControl = False)):
54                         if self.pnav and not self.pnav.playService(ref):
55                                 self.currentlyPlayingServiceReference = ref
56                                 return 0
57                 else:
58                         self.stopService()
59                 return 1
60         
61         def getCurrentlyPlayingServiceReference(self):
62                 return self.currentlyPlayingServiceReference
63         
64         def recordService(self, ref):
65                 print "recording service: %s" % (str(ref))
66                 if isinstance(ref, ServiceReference.ServiceReference):
67                         ref = ref.ref
68                 service = self.pnav and self.pnav.recordService(ref)
69                 
70                 if service is None:
71                         print "record returned non-zero"
72                         return None
73                 else:
74                         return service
75
76         def stopRecordService(self, service):
77                 ret = self.pnav and self.pnav.stopRecordService(service)
78                 return ret
79
80         def getRecordings(self):
81                 return self.pnav and self.pnav.getRecordings()
82
83         def getCurrentService(self):
84                 if self.state:
85                         if not self.currentlyPlayingService:
86                                 self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
87                         return self.currentlyPlayingService
88                 return None
89
90         def stopService(self):
91                 print "stopService"
92                 if self.pnav:
93                         self.pnav.stopService()
94                 self.currentlyPlayingService = None
95                 self.currentlyPlayingServiceReference = None
96
97         def pause(self, p):
98                 return self.pnav and self.pnav.pause(p)
99
100         def recordWithTimer(self, ref, begin, end, name, description, eit):
101                 if isinstance(ref, eServiceReference):
102                         ref = ServiceReference.ServiceReference(ref)
103                 entry = RecordTimer.RecordTimerEntry(ref, begin, end, name, description, eit)
104                 self.RecordTimer.record(entry)
105                 return entry
106         
107         def shutdown(self):
108                 self.RecordTimer.shutdown()
109                 self.ServiceHandler = None
110                 self.pnav = None
111
112         def stopUserServices(self):
113                 self.stopService()