more changes for service groups (replacement for zapping alternatives
[vuplus_dvbapp] / 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                 oldref = self.currentlyPlayingServiceReference
47                 print "playing", ref and ref.toString()
48                 self.currentlyPlayingServiceReference = None
49                 self.currentlyPlayingService = None
50                 if ref is None:
51                         self.stopService()
52                         return 0
53                 if not checkParentalControl or parentalControl.isServicePlayable(ref.toCompareString(), boundFunction(self.playService, checkParentalControl = False)):
54                         if ref.flags & eServiceReference.isGroup:
55                                 if not oldref:
56                                         oldref = eServiceReference()
57                                 playref = getBestPlayableServiceReference(ref, oldref)
58                                 if not playref or (checkParentalControl and not parentalControl.isServicePlayable(playref.toCompareString(), boundFunction(self.playService, checkParentalControl = False))):
59                                         self.stopService()
60                                         return 0
61                         else:
62                                 playref = ref
63                         if self.pnav and not self.pnav.playService(playref):
64                                 self.currentlyPlayingServiceReference = ref
65                                 return 0
66                 else:
67                         self.stopService()
68                 return 1
69         
70         def getCurrentlyPlayingServiceReference(self):
71                 return self.currentlyPlayingServiceReference
72         
73         def recordService(self, ref):
74                 service = None
75                 print "recording service: %s" % (str(ref))
76                 if isinstance(ref, ServiceReference.ServiceReference):
77                         ref = ref.ref
78                 if ref:
79                         if ref.flags & eServiceReference.isGroup:
80                                 ref = getBestPlayableServiceReference(ref, eServiceReference())
81                         service = ref and self.pnav and self.pnav.recordService(ref)
82                         if service is None:
83                                 print "record returned non-zero"
84                 return service
85
86         def stopRecordService(self, service):
87                 ret = self.pnav and self.pnav.stopRecordService(service)
88                 return ret
89
90         def getRecordings(self):
91                 return self.pnav and self.pnav.getRecordings()
92
93         def getCurrentService(self):
94                 if self.state:
95                         if not self.currentlyPlayingService:
96                                 self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
97                         return self.currentlyPlayingService
98                 return None
99
100         def stopService(self):
101                 print "stopService"
102                 if self.pnav:
103                         self.pnav.stopService()
104                 self.currentlyPlayingService = None
105                 self.currentlyPlayingServiceReference = None
106
107         def pause(self, p):
108                 return self.pnav and self.pnav.pause(p)
109
110         def recordWithTimer(self, ref, begin, end, name, description, eit):
111                 if isinstance(ref, eServiceReference):
112                         ref = ServiceReference.ServiceReference(ref)
113                 entry = RecordTimer.RecordTimerEntry(ref, begin, end, name, description, eit)
114                 self.RecordTimer.record(entry)
115                 return entry
116         
117         def shutdown(self):
118                 self.RecordTimer.shutdown()
119                 self.ServiceHandler = None
120                 self.pnav = None
121
122         def stopUserServices(self):
123                 self.stopService()