configure.ac - remove FrontprocessorUpgrade and NFIFlash missed in a6cb9fcb40d84b6a32...
[openblackhole/openblackhole-enigma2.git] / Navigation.py
1 from enigma import eServiceCenter, eServiceReference, eTimer, pNavigation, getBestPlayableServiceReference, iPlayableService, eActionMap, setPreferredTuner, eStreamServer
2 from Components.ParentalControl import parentalControl
3 from Components.SystemInfo import SystemInfo
4 from Components.config import config, configfile
5 from Tools.BoundFunction import boundFunction
6 from Tools.StbHardware import setFPWakeuptime, getFPWakeuptime, getFPWasTimerWakeup
7 from Tools import Notifications
8 from time import time, localtime
9 import RecordTimer
10 import Screens.Standby
11 import NavigationInstance
12 import ServiceReference
13 from Screens.InfoBar import InfoBar
14 from sys import maxint
15
16 # TODO: remove pNavgation, eNavigation and rewrite this stuff in python.
17 class Navigation:
18         def __init__(self):
19                 if NavigationInstance.instance is not None:
20                         raise NavigationInstance.instance
21
22                 NavigationInstance.instance = self
23                 self.ServiceHandler = eServiceCenter.getInstance()
24
25                 import Navigation as Nav
26                 Nav.navcore = self
27
28                 self.pnav = pNavigation()
29                 self.pnav.m_event.get().append(self.dispatchEvent)
30                 self.pnav.m_record_event.get().append(self.dispatchRecordEvent)
31                 self.event = [ ]
32                 self.record_event = [ ]
33                 self.currentlyPlayingServiceReference = None
34                 self.currentlyPlayingServiceOrGroup = None
35                 self.currentlyPlayingService = None
36                 self.RecordTimer = RecordTimer.RecordTimer()
37                 self.__wasTimerWakeup = getFPWasTimerWakeup()
38                 startup_to_standby = config.usage.startup_to_standby.value
39                 wakeup_time_type = config.misc.prev_wakeup_time_type.value
40                 if self.__wasTimerWakeup:
41                         RecordTimer.RecordTimerEntry.setWasInDeepStandby()
42                 if config.misc.RestartUI.value:
43                         config.misc.RestartUI.value = False
44                         config.misc.RestartUI.save()
45                         configfile.save()
46                 elif startup_to_standby == "yes" or self.__wasTimerWakeup and config.misc.prev_wakeup_time.value and ((wakeup_time_type == 0 or wakeup_time_type == 1) or ( wakeup_time_type == 3 and startup_to_standby == "except")):
47                         if not Screens.Standby.inTryQuitMainloop:
48                                 Notifications.AddNotification(Screens.Standby.Standby)
49                 if config.misc.prev_wakeup_time.value:
50                         config.misc.prev_wakeup_time.value = 0
51                         config.misc.prev_wakeup_time.save()
52                         configfile.save()
53
54         def wasTimerWakeup(self):
55                 return self.__wasTimerWakeup
56
57         def dispatchEvent(self, i):
58                 for x in self.event:
59                         x(i)
60                 if i == iPlayableService.evEnd:
61                         self.currentlyPlayingServiceReference = None
62                         self.currentlyPlayingServiceOrGroup = None
63                         self.currentlyPlayingService = None
64
65         def dispatchRecordEvent(self, rec_service, event):
66 #               print "record_event", rec_service, event
67                 for x in self.record_event:
68                         x(rec_service, event)
69
70         def playService(self, ref, checkParentalControl=True, forceRestart=False, adjust=True):
71                 oldref = self.currentlyPlayingServiceOrGroup
72                 if ref and oldref and ref == oldref and not forceRestart:
73                         print "ignore request to play already running service(1)"
74                         return 1
75                 print "playing", ref and ref.toString()
76                 if ref is None:
77                         self.stopService()
78                         return 0
79                 from Components.ServiceEventTracker import InfoBarCount
80                 InfoBarInstance = InfoBarCount == 1 and InfoBar.instance
81                 if not checkParentalControl or parentalControl.isServicePlayable(ref, boundFunction(self.playService, checkParentalControl=False, forceRestart=forceRestart, adjust=adjust)):
82                         if ref.flags & eServiceReference.isGroup:
83                                 oldref = self.currentlyPlayingServiceReference or eServiceReference()
84                                 playref = getBestPlayableServiceReference(ref, oldref)
85                                 print "playref", playref
86                                 if playref and oldref and playref == oldref and not forceRestart:
87                                         print "ignore request to play already running service(2)"
88                                         return 1
89                                 if not playref:
90                                         alternativeref = getBestPlayableServiceReference(ref, eServiceReference(), True)
91                                         self.stopService()
92                                         if alternativeref and self.pnav and self.pnav.playService(alternativeref):
93                                                 print "Failed to start", alternativeref
94                                         return 0
95                                 elif checkParentalControl and not parentalControl.isServicePlayable(playref, boundFunction(self.playService, checkParentalControl = False)):
96                                         if self.currentlyPlayingServiceOrGroup and InfoBarInstance and InfoBarInstance.servicelist.servicelist.setCurrent(self.currentlyPlayingServiceOrGroup, adjust):
97                                                 self.currentlyPlayingServiceOrGroup = InfoBarInstance.servicelist.servicelist.getCurrent()
98                                         return 1
99                         else:
100                                 playref = ref
101                         if self.pnav:
102                                 self.pnav.stopService()
103                                 self.currentlyPlayingServiceReference = playref
104                                 self.currentlyPlayingServiceOrGroup = ref
105                                 if InfoBarInstance and InfoBarInstance.servicelist.servicelist.setCurrent(ref, adjust):
106                                         self.currentlyPlayingServiceOrGroup = InfoBarInstance.servicelist.servicelist.getCurrent()
107                                 setPriorityFrontend = False
108                                 if SystemInfo["DVB-T_priority_tuner_available"] or SystemInfo["DVB-C_priority_tuner_available"] or SystemInfo["DVB-S_priority_tuner_available"]:
109                                         str_service = playref.toString()
110                                         if '%3a//' not in str_service and not str_service.rsplit(":", 1)[1].startswith("/"):
111                                                 type_service = playref.getUnsignedData(4) >> 16
112                                                 if type_service == 0xEEEE:
113                                                         if config.usage.frontend_priority_dvbt.value != "-2":
114                                                                 if config.usage.frontend_priority_dvbt.value != config.usage.frontend_priority.value:
115                                                                         setPreferredTuner(int(config.usage.frontend_priority_dvbt.value))
116                                                                         setPriorityFrontend = True
117                                                 elif type_service == 0xFFFF:
118                                                         if config.usage.frontend_priority_dvbc.value != "-2":
119                                                                 if config.usage.frontend_priority_dvbc.value != config.usage.frontend_priority.value:
120                                                                         setPreferredTuner(int(config.usage.frontend_priority_dvbc.value))
121                                                                         setPriorityFrontend = True
122                                                 else:
123                                                         if config.usage.frontend_priority_dvbs.value != "-2":
124                                                                 if config.usage.frontend_priority_dvbs.value != config.usage.frontend_priority.value:
125                                                                         setPreferredTuner(int(config.usage.frontend_priority_dvbs.value))
126                                                                         setPriorityFrontend = True
127                                 if self.pnav.playService(playref):
128                                         print "Failed to start", playref
129                                         self.currentlyPlayingServiceReference = None
130                                         self.currentlyPlayingServiceOrGroup = None
131                                 if setPriorityFrontend:
132                                         setPreferredTuner(int(config.usage.frontend_priority.value))
133                                 return 0
134                 elif oldref and InfoBarInstance and InfoBarInstance.servicelist.servicelist.setCurrent(oldref, adjust):
135                         self.currentlyPlayingServiceOrGroup = InfoBarInstance.servicelist.servicelist.getCurrent()
136                 return 1
137
138         def getCurrentlyPlayingServiceReference(self):
139                 return self.currentlyPlayingServiceReference
140
141         def getCurrentlyPlayingServiceOrGroup(self):
142                 return self.currentlyPlayingServiceOrGroup
143
144         def recordService(self, ref, simulate=False):
145                 service = None
146                 if not simulate: print "recording service: %s" % (str(ref))
147                 if isinstance(ref, ServiceReference.ServiceReference):
148                         ref = ref.ref
149                 if ref:
150                         if ref.flags & eServiceReference.isGroup:
151                                 ref = getBestPlayableServiceReference(ref, eServiceReference(), simulate)
152                         service = ref and self.pnav and self.pnav.recordService(ref, simulate)
153                         if service is None:
154                                 print "record returned non-zero"
155                 return service
156
157         def stopRecordService(self, service):
158                 ret = self.pnav and self.pnav.stopRecordService(service)
159                 return ret
160
161         def getRecordings(self, simulate=False):
162                 return self.pnav and self.pnav.getRecordings(simulate)
163
164         def getCurrentService(self):
165                 if not self.currentlyPlayingService:
166                         self.currentlyPlayingService = self.pnav and self.pnav.getCurrentService()
167                 return self.currentlyPlayingService
168
169         def stopService(self):
170                 if self.pnav:
171                         self.pnav.stopService()
172                 self.currentlyPlayingServiceReference = None
173                 self.currentlyPlayingServiceOrGroup = None
174
175         def pause(self, p):
176                 return self.pnav and self.pnav.pause(p)
177
178         def shutdown(self):
179                 self.RecordTimer.shutdown()
180                 self.ServiceHandler = None
181                 self.pnav = None
182
183         def stopUserServices(self):
184                 self.stopService()
185
186         def getClientsStreaming(self):
187                 return eStreamServer.getInstance() and eStreamServer.getInstance().getConnectedClients()