f8c8417384ad16c93cd1f85ca06eee93a442da0d
[enigma2.git] / Navigation.py
1 from enigma import *
2 from Components.ParentalControl import parentalControl
3 from Tools.BoundFunction import boundFunction
4 import RecordTimer
5
6 import NavigationInstance
7 import ServiceReference
8
9 from time import time
10
11 # TODO: remove pNavgation, eNavigation and rewrite this stuff in python.
12 class Navigation:
13         def __init__(self):
14                 if NavigationInstance.instance is not None:
15                         raise NavigationInstance.instance
16                 
17                 NavigationInstance.instance = self
18                 self.ServiceHandler = eServiceCenter.getInstance()
19                 
20                 import Navigation as Nav
21                 Nav.navcore = self
22                 
23                 self.pnav = pNavigation()
24                 self.pnav.m_event.get().append(self.callEvent)
25                 self.event = [ ]
26                 self.currentlyPlayingServiceReference = None
27                 self.currentlyPlayingService = None
28                 self.state = 0
29                 self.RecordTimer = RecordTimer.RecordTimer()
30                 
31         def callEvent(self, i):
32                 self.state = i != 1
33                 for x in self.event:
34                         x(i)
35
36         def playService(self, ref, checkParentalControl = True):
37                 print "playing", ref and ref.toString()
38                 self.currentlyPlayingServiceReference = None
39                 self.currentlyPlayingService = None
40                 if ref is None:
41                         self.stopService()
42                         return 0
43                 
44                 if not checkParentalControl or parentalControl.isServicePlayable(ref.toCompareString(), boundFunction(self.playService, checkParentalControl = False)):
45                         if self.pnav and not self.pnav.playService(ref):
46                                 self.currentlyPlayingServiceReference = ref
47                                 return 0
48                 else:
49                         self.stopService()
50                 return 1
51         
52         def getCurrentlyPlayingServiceReference(self):
53                 return self.currentlyPlayingServiceReference
54         
55         def recordService(self, ref):
56                 print "recording service: %s" % (str(ref))
57                 if isinstance(ref, ServiceReference.ServiceReference):
58                         ref = ref.ref
59                 service = self.pnav and self.pnav.recordService(ref)
60                 
61                 if service is None:
62                         print "record returned non-zero"
63                         return None
64                 else:
65                         return service
66
67         def getCurrentService(self):
68                 if self.state:
69                         if not self.currentlyPlayingService:
70                                 self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
71                         return self.currentlyPlayingService
72                 return None
73
74         def stopService(self):
75                 print "stopService"
76                 if self.pnav:
77                         self.pnav.stopService()
78                 self.currentlyPlayingService = None
79                 self.currentlyPlayingServiceReference = None
80
81         def pause(self, p):
82                 return self.pnav and self.pnav.pause(p)
83
84         def recordWithTimer(self, ref, begin, end, name, description, eit):
85                 if isinstance(ref, eServiceReference):
86                         ref = ServiceReference.ServiceReference(ref)
87                 entry = RecordTimer.RecordTimerEntry(ref, begin, end, name, description, eit)
88                 self.RecordTimer.record(entry)
89                 return entry
90         
91         def shutdown(self):
92                 self.RecordTimer.shutdown()
93                 self.ServiceHandler = None
94                 self.pnav = None
95
96         def stopUserServices(self):
97                 self.stopService()