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