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