Add parameter to playService not to adjust on servicelist
[openblackhole/openblackhole-enigma2.git] / Navigation.py
1 from enigma import eServiceCenter, eServiceReference, eTimer, pNavigation, getBestPlayableServiceReference, iPlayableService, eActionMap
2 from Components.ParentalControl import parentalControl
3 from Components.config import config
4 from Tools.BoundFunction import boundFunction
5 from Tools.StbHardware import setFPWakeuptime, getFPWakeuptime, getFPWasTimerWakeup
6 from Tools import Notifications
7 from time import time, localtime
8 import RecordTimer
9 import Screens.Standby
10 import NavigationInstance
11 import ServiceReference
12 from Screens.InfoBar import InfoBar
13 from sys import maxint
14
15 # TODO: remove pNavgation, eNavigation and rewrite this stuff in python.
16 class Navigation:
17         def __init__(self):
18                 if NavigationInstance.instance is not None:
19                         raise NavigationInstance.instance
20
21                 NavigationInstance.instance = self
22                 self.ServiceHandler = eServiceCenter.getInstance()
23
24                 import Navigation as Nav
25                 Nav.navcore = self
26
27                 self.pnav = pNavigation()
28                 self.pnav.m_event.get().append(self.dispatchEvent)
29                 self.pnav.m_record_event.get().append(self.dispatchRecordEvent)
30                 self.event = [ ]
31                 self.record_event = [ ]
32                 self.currentlyPlayingServiceReference = None
33                 self.currentlyPlayingServiceOrGroup = None
34                 self.currentlyPlayingService = None
35                 self.RecordTimer = RecordTimer.RecordTimer()
36                 self.__wasTimerWakeup = getFPWasTimerWakeup()
37                 if self.__wasTimerWakeup:
38                         RecordTimer.RecordTimerEntry.setWasInDeepStandby()
39
40         def wasTimerWakeup(self):
41                 return self.__wasTimerWakeup
42
43         def dispatchEvent(self, i):
44                 for x in self.event:
45                         x(i)
46                 if i == iPlayableService.evEnd:
47                         self.currentlyPlayingServiceReference = None
48                         self.currentlyPlayingServiceOrGroup = None
49                         self.currentlyPlayingService = None
50
51         def dispatchRecordEvent(self, rec_service, event):
52 #               print "record_event", rec_service, event
53                 for x in self.record_event:
54                         x(rec_service, event)
55
56         def playService(self, ref, checkParentalControl=True, forceRestart=False, adjust=True):
57                 oldref = self.currentlyPlayingServiceOrGroup
58                 if ref and oldref and ref == oldref and not forceRestart:
59                         print "ignore request to play already running service(1)"
60                         return 0
61                 print "playing", ref and ref.toString()
62                 if ref is None:
63                         self.stopService()
64                         return 0
65                 from Components.ServiceEventTracker import InfoBarCount
66                 InfoBarInstance = InfoBarCount == 1 and InfoBar.instance
67                 if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl=False, forceRestart=forceRestart, adjust=adjust)):
68                         if ref.flags & eServiceReference.isGroup:
69                                 oldref = self.currentlyPlayingServiceReference or eServiceReference()
70                                 playref = getBestPlayableServiceReference(ref, oldref)
71                                 print "playref", playref
72                                 if playref and oldref and playref == oldref and not forceRestart:
73                                         print "ignore request to play already running service(2)"
74                                         return 0
75                                 if not playref or (checkParentalControl and not parentalControl.isServicePlayable(playref, boundFunction(self.playService, checkParentalControl = False))):
76                                         self.stopService()
77                                         return 0
78                         else:
79                                 playref = ref
80                         if self.pnav:
81                                 self.pnav.stopService()
82                                 self.currentlyPlayingServiceReference = playref
83                                 self.currentlyPlayingServiceOrGroup = ref
84                                 if InfoBarInstance and InfoBarInstance.servicelist.servicelist.setCurrent(ref, adjust):
85                                         self.currentlyPlayingServiceOrGroup = InfoBarInstance.servicelist.servicelist.getCurrent()
86                                 if self.pnav.playService(playref):
87                                         print "Failed to start", playref
88                                         self.currentlyPlayingServiceReference = None
89                                         self.currentlyPlayingServiceOrGroup = None
90                                 return 0
91                 elif oldref and InfoBarInstance and InfoBarInstance.servicelist.servicelist.setCurrent(oldref, adjust):
92                         self.currentlyPlayingServiceOrGroup = InfoBarInstance.servicelist.servicelist.getCurrent()
93                 return 1
94
95         def getCurrentlyPlayingServiceReference(self):
96                 return self.currentlyPlayingServiceReference
97
98         def getCurrentlyPlayingServiceOrGroup(self):
99                 return self.currentlyPlayingServiceOrGroup
100
101         def recordService(self, ref, simulate=False):
102                 service = None
103                 if not simulate: print "recording service: %s" % (str(ref))
104                 if isinstance(ref, ServiceReference.ServiceReference):
105                         ref = ref.ref
106                 if ref:
107                         if ref.flags & eServiceReference.isGroup:
108                                 ref = getBestPlayableServiceReference(ref, eServiceReference(), simulate)
109                         service = ref and self.pnav and self.pnav.recordService(ref, simulate)
110                         if service is None:
111                                 print "record returned non-zero"
112                 return service
113
114         def stopRecordService(self, service):
115                 ret = self.pnav and self.pnav.stopRecordService(service)
116                 return ret
117
118         def getRecordings(self, simulate=False):
119                 return self.pnav and self.pnav.getRecordings(simulate)
120
121         def getCurrentService(self):
122                 if not self.currentlyPlayingService:
123                         self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
124                 return self.currentlyPlayingService
125
126         def stopService(self):
127                 if self.pnav:
128                         self.pnav.stopService()
129                 self.currentlyPlayingServiceReference = None
130                 self.currentlyPlayingServiceOrGroup = None
131
132         def pause(self, p):
133                 return self.pnav and self.pnav.pause(p)
134
135         def shutdown(self):
136                 self.RecordTimer.shutdown()
137                 self.ServiceHandler = None
138                 self.pnav = None
139
140         def stopUserServices(self):
141                 self.stopService()