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