zap to last channel with 0
[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.currentlyPlayingService = None
23                 self.currentlyPlayingServiceReference = None
24                 self.lastServiceRef = None
25                 
26                 self.RecordTimer = RecordTimer.RecordTimer()
27
28         def callEvent(self, i):
29                 for x in self.event:
30                         x(i)
31         
32         def playService(self, ref):
33                 self.lastServiceRef = self.currentlyPlayingServiceReference
34                 self.currentlyPlayingServiceReference = None
35                 if ref is None:
36                         self.stopService()
37                         return 0
38                 
39                 if not self.pnav.playService(ref):
40                         self.currentlyPlayingServiceReference = ref
41                         return 0
42                 return 1
43         
44         def zapLast(self):
45                 return self.playService(self.lastServiceRef)
46         
47         def getCurrentlyPlayingServiceReference(self):
48                 return self.currentlyPlayingServiceReference
49         
50         def recordService(self, ref):
51                 print "recording service: %s" % (str(ref))
52                 if isinstance(ref, ServiceReference.ServiceReference):
53                         ref = ref.ref
54                 service = self.pnav.recordService(ref)
55                 
56                 if service is None:
57                         print "record returned non-zero"
58                         return None
59                 else:
60                         return service
61         
62         def enqueueService(self, ref):
63                 return self.pnav.enqueueService(ref)
64         
65         def getCurrentService(self):
66                 service = self.pnav.getCurrentService()
67                 
68                 if service is None:
69                         return None
70                 
71                 return service
72         
73         def stopService(self):
74                 self.pnav.stopService()
75         
76         def getPlaylist(self):
77                 playlist = ePlaylistPtr()
78                 if self.pnav.getPlaylist(playlist):
79                         return None
80                 return playlist
81         
82         def pause(self, p):
83                 return self.pnav.pause(p)
84         
85         def recordWithTimer(self, ref, begin, end, name, description, eit):
86                 if isinstance(ref, eServiceReference):
87                         ref = ServiceReference.ServiceReference(ref)
88                 entry = RecordTimer.RecordTimerEntry(ref, begin, end, name, description, eit)
89                 self.RecordTimer.record(entry)
90                 return entry
91         
92         def shutdown(self):
93                 self.RecordTimer.shutdown()
94
95         def stopUserServices(self):
96                 self.stopService()