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