give more resources free on nav.shutdown and nav.stopService
[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.toString()
34                 self.currentlyPlayingServiceReference = None
35                 self.currentlyPlayingService = None
36                 if ref is None:
37                         self.stopService()
38                         return 0
39                 
40                 if 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.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.getCurrentService()
64                         return self.currentlyPlayingService
65                 return None
66
67         def stopService(self):
68                 self.pnav.stopService()
69                 self.currentlyPlayingService = None
70                 self.currentlyPlayingServiceReference = None
71
72         def pause(self, p):
73                 return self.pnav.pause(p)
74
75         def recordWithTimer(self, ref, begin, end, name, description, eit):
76                 if isinstance(ref, eServiceReference):
77                         ref = ServiceReference.ServiceReference(ref)
78                 entry = RecordTimer.RecordTimerEntry(ref, begin, end, name, description, eit)
79                 self.RecordTimer.record(entry)
80                 return entry
81         
82         def shutdown(self):
83                 self.RecordTimer.shutdown()
84                 del self.ServiceHandler
85                 del self.pnav
86
87         def stopUserServices(self):
88                 self.stopService()