link e2 against shared libxmlccwrap
[enigma2.git] / Navigation.py
1 from enigma import eServiceCenter, eServiceReference, pNavigation, getBestPlayableServiceReference
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 # TODO: remove pNavgation, eNavigation and rewrite this stuff in python.
11 class Navigation:
12         def __init__(self):
13                 if NavigationInstance.instance is not None:
14                         raise NavigationInstance.instance
15                 
16                 NavigationInstance.instance = self
17                 self.ServiceHandler = eServiceCenter.getInstance()
18                 
19                 import Navigation as Nav
20                 Nav.navcore = self
21                 
22                 self.pnav = pNavigation()
23                 self.pnav.m_event.get().append(self.dispatchEvent)
24                 self.pnav.m_record_event.get().append(self.dispatchRecordEvent)
25                 self.event = [ ]
26                 self.record_event = [ ]
27                 self.currentlyPlayingServiceReference = None
28                 self.currentlyPlayingService = None
29                 self.RecordTimer = RecordTimer.RecordTimer()
30                 self.SleepTimer = SleepTimer.SleepTimer()
31
32         def dispatchEvent(self, i):
33                 for x in self.event:
34                         x(i)
35
36         def dispatchRecordEvent(self, rec_service, event):
37 #               print "record_event", rec_service, event
38                 for x in self.record_event:
39                         x(rec_service, event)
40
41         def playService(self, ref, checkParentalControl = True):
42                 oldref = self.currentlyPlayingServiceReference
43                 if ref and oldref and ref == oldref:
44                         print "ignore request to play already running service"
45                         return 0
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                 if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl = False)):
53                         if ref.flags & eServiceReference.isGroup:
54                                 if not oldref:
55                                         oldref = eServiceReference()
56                                 playref = getBestPlayableServiceReference(ref, oldref)
57                                 if not playref or (checkParentalControl and not parentalControl.isServicePlayable(playref, boundFunction(self.playService, checkParentalControl = False))):
58                                         self.stopService()
59                                         return 0
60                         else:
61                                 playref = ref
62                         if self.pnav and not self.pnav.playService(playref):
63                                 self.currentlyPlayingServiceReference = playref
64                                 return 0
65                 else:
66                         self.stopService()
67                 return 1
68         
69         def getCurrentlyPlayingServiceReference(self):
70                 return self.currentlyPlayingServiceReference
71         
72         def recordService(self, ref):
73                 service = None
74                 print "recording service: %s" % (str(ref))
75                 if isinstance(ref, ServiceReference.ServiceReference):
76                         ref = ref.ref
77                 if ref:
78                         if ref.flags & eServiceReference.isGroup:
79                                 ref = getBestPlayableServiceReference(ref, eServiceReference())
80                         service = ref and self.pnav and self.pnav.recordService(ref)
81                         if service is None:
82                                 print "record returned non-zero"
83                 return service
84
85         def stopRecordService(self, service):
86                 ret = self.pnav and self.pnav.stopRecordService(service)
87                 return ret
88
89         def getRecordings(self):
90                 return self.pnav and self.pnav.getRecordings()
91
92         def getCurrentService(self):
93                 if not self.currentlyPlayingService:
94                         self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
95                 return self.currentlyPlayingService
96
97         def stopService(self):
98                 print "stopService"
99                 if self.pnav:
100                         self.pnav.stopService()
101                 self.currentlyPlayingService = None
102                 self.currentlyPlayingServiceReference = None
103
104         def pause(self, p):
105                 return self.pnav and self.pnav.pause(p)
106
107         def recordWithTimer(self, ref, begin, end, name, description, eit):
108                 if isinstance(ref, eServiceReference):
109                         ref = ServiceReference.ServiceReference(ref)
110                 entry = RecordTimer.RecordTimerEntry(ref, begin, end, name, description, eit)
111                 self.RecordTimer.record(entry)
112                 return entry
113         
114         def shutdown(self):
115                 self.RecordTimer.shutdown()
116                 self.ServiceHandler = None
117                 self.pnav = None
118
119         def stopUserServices(self):
120                 self.stopService()