+ lookup = {
+ self.SEEK_STATE_PLAY: self.SEEK_STATE_BACK_16X,
+ self.SEEK_STATE_PAUSE: self.SEEK_STATE_PAUSE,
+ self.SEEK_STATE_FF_2X: self.SEEK_STATE_PLAY,
+ self.SEEK_STATE_FF_4X: self.SEEK_STATE_FF_2X,
+ self.SEEK_STATE_FF_8X: self.SEEK_STATE_FF_4X,
+ self.SEEK_STATE_FF_32X: self.SEEK_STATE_FF_8X,
+ self.SEEK_STATE_FF_64X: self.SEEK_STATE_FF_32X,
+ self.SEEK_STATE_FF_128X: self.SEEK_STATE_FF_64X,
+ self.SEEK_STATE_BACK_16X: self.SEEK_STATE_BACK_32X,
+ self.SEEK_STATE_BACK_32X: self.SEEK_STATE_BACK_64X,
+ self.SEEK_STATE_BACK_64X: self.SEEK_STATE_BACK_128X,
+ self.SEEK_STATE_BACK_128X: self.SEEK_STATE_BACK_128X,
+ self.SEEK_STATE_SM_HALF: self.SEEK_STATE_SM_QUARTER,
+ self.SEEK_STATE_SM_QUARTER: self.SEEK_STATE_SM_EIGHTH,
+ self.SEEK_STATE_SM_EIGHTH: self.SEEK_STATE_PAUSE
+ }
+ self.setSeekState(lookup[self.seekstate])
+
+ if self.seekstate == self.SEEK_STATE_PAUSE:
+ seekable = self.getSeek()
+ if seekable is not None:
+ seekable.seekRelative(-1, 3)
+
+ def fwdTimerFire(self):
+ print "Display seek fwd"
+ self.fwdKeyTimer.stop()
+ self.fwdtimer = False
+ self.session.openWithCallback(self.fwdSeekTo, MinuteInput)
+
+ def fwdSeekTo(self, minutes):
+ print "Seek", minutes, "minutes forward"
+ if minutes != 0:
+ seekable = self.getSeek()
+ if seekable is not None:
+ seekable.seekRelative(1, minutes * 60 * 90000)
+
+ def rwdTimerFire(self):
+ print "rwdTimerFire"
+ self.rwdKeyTimer.stop()
+ self.rwdtimer = False
+ self.session.openWithCallback(self.rwdSeekTo, MinuteInput)
+
+ def rwdSeekTo(self, minutes):
+ print "rwdSeekTo"
+ self.fwdSeekTo(0 - minutes)
+
+ def checkSkipShowHideLock(self):
+ wantlock = self.seekstate != self.SEEK_STATE_PLAY
+
+ if config.usage.show_infobar_on_zap.value:
+ if self.lockedBecauseOfSkipping and not wantlock:
+ self.unlockShow()
+ self.lockedBecauseOfSkipping = False
+
+ if wantlock and not self.lockedBecauseOfSkipping:
+ self.lockShow()
+ self.lockedBecauseOfSkipping = True
+
+ def __evEOF(self):
+ if self.seekstate != self.SEEK_STATE_PLAY:
+ self.setSeekState(self.SEEK_STATE_PAUSE)
+ # HACK
+ #self.getSeek().seekRelative(1, -90000)
+ self.setSeekState(self.SEEK_STATE_PLAY)
+ else:
+ self.setSeekState(self.SEEK_STATE_PAUSE)
+
+ def __evSOF(self):
+ self.setSeekState(self.SEEK_STATE_PLAY)
+ self.doSeek(0)
+
+ def seekRelative(self, diff):
+ seekable = self.getSeek()
+ if seekable is not None:
+ seekable.seekRelative(1, diff)
+
+ def seekAbsolute(self, abs):
+ seekable = self.getSeek()
+ if seekable is not None:
+ seekable.seekTo(abs)
+
+from Screens.PVRState import PVRState, TimeshiftState
+
+class InfoBarPVRState:
+ def __init__(self, screen=PVRState, show_always=False):
+ self.show_always = show_always
+ self.onPlayStateChanged.append(self.__playStateChanged)
+ self.pvrStateDialog = self.session.instantiateDialog(screen)
+ self.onShow.append(self.__mayShow)
+ self.onHide.append(self.pvrStateDialog.hide)
+
+ def __mayShow(self):
+ if self.execing and (self.show_always or self.seekstate != self.SEEK_STATE_PLAY):
+ self.pvrStateDialog.show()
+
+ def __playStateChanged(self, state):
+ playstateString = state[3]
+ self.pvrStateDialog["state"].setText(playstateString)
+ self.__mayShow()
+
+class InfoBarTimeshiftState(InfoBarPVRState):
+ def __init__(self):
+ InfoBarPVRState.__init__(self, screen=TimeshiftState, show_always=True)
+
+class InfoBarShowMovies:
+
+ # i don't really like this class.
+ # it calls a not further specified "movie list" on up/down/movieList,
+ # so this is not more than an action map
+ def __init__(self):
+ self["MovieListActions"] = HelpableActionMap(self, "InfobarMovieListActions",
+ {
+ "movieList": (self.showMovies, "movie list"),
+ "up": (self.showMovies, "movie list"),
+ "down": (self.showMovies, "movie list")
+ })
+
+# InfoBarTimeshift requires InfoBarSeek, instantiated BEFORE!
+
+# Hrmf.
+#
+# Timeshift works the following way:
+# demux0 demux1 "TimeshiftActions" "TimeshiftActivateActions" "SeekActions"
+# - normal playback TUNER unused PLAY enable disable disable
+# - user presses "yellow" button. TUNER record PAUSE enable disable enable
+# - user presess pause again FILE record PLAY enable disable enable
+# - user fast forwards FILE record FF enable disable enable
+# - end of timeshift buffer reached TUNER record PLAY enable enable disable
+# - user backwards FILE record BACK # !! enable disable enable
+#
+
+# in other words:
+# - when a service is playing, pressing the "timeshiftStart" button ("yellow") enables recording ("enables timeshift"),
+# freezes the picture (to indicate timeshift), sets timeshiftMode ("activates timeshift")
+# now, the service becomes seekable, so "SeekActions" are enabled, "TimeshiftEnableActions" are disabled.
+# - the user can now PVR around
+# - if it hits the end, the service goes into live mode ("deactivates timeshift", it's of course still "enabled")
+# the service looses it's "seekable" state. It can still be paused, but just to activate timeshift right
+# after!
+# the seek actions will be disabled, but the timeshiftActivateActions will be enabled
+# - if the user rewinds, or press pause, timeshift will be activated again
+
+# note that a timeshift can be enabled ("recording") and
+# activated (currently time-shifting).
+
+class InfoBarTimeshift:
+ def __init__(self):
+ self["TimeshiftActions"] = HelpableActionMap(self, "InfobarTimeshiftActions",
+ {
+ "timeshiftStart": (self.startTimeshift, _("start timeshift")), # the "yellow key"
+ "timeshiftStop": (self.stopTimeshift, _("stop timeshift")) # currently undefined :), probably 'TV'
+ }, prio=1)
+ self["TimeshiftActivateActions"] = ActionMap(["InfobarTimeshiftActivateActions"],
+ {
+ "timeshiftActivateEnd": self.activateTimeshiftEnd, # something like "pause key"
+ "timeshiftActivateEndAndPause": self.activateTimeshiftEndAndPause # something like "backward key"
+ }, prio=-1) # priority over record
+
+ self.timeshift_enabled = 0
+ self.timeshift_state = 0
+ self.ts_pause_timer = eTimer()
+ self.ts_pause_timer.timeout.get().append(self.pauseService)
+
+ self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
+ {
+ iPlayableService.evStart: self.__serviceStarted,
+ iPlayableService.evSeekableStatusChanged: self.__seekableStatusChanged
+ })
+
+ def getTimeshift(self):
+ service = self.session.nav.getCurrentService()
+ return service and service.timeshift()
+
+ def startTimeshift(self):
+ print "enable timeshift"
+ ts = self.getTimeshift()
+ if ts is None:
+ self.session.open(MessageBox, _("Timeshift not possible!"), MessageBox.TYPE_ERROR)
+ print "no ts interface"
+ return 0;
+
+ if self.timeshift_enabled:
+ print "hu, timeshift already enabled?"
+ else:
+ if not ts.startTimeshift():
+ self.timeshift_enabled = 1
+
+ # we remove the "relative time" for now.
+ #self.pvrStateDialog["timeshift"].setRelative(time.time())
+
+ # PAUSE.
+ self.setSeekState(self.SEEK_STATE_PAUSE)
+
+ # enable the "TimeshiftEnableActions", which will override
+ # the startTimeshift actions
+ self.__seekableStatusChanged()
+ else:
+ print "timeshift failed"
+
+ def stopTimeshift(self):
+ if not self.timeshift_enabled:
+ return 0
+ print "disable timeshift"
+ ts = self.getTimeshift()
+ if ts is None:
+ return 0
+ self.session.openWithCallback(self.stopTimeshiftConfirmed, MessageBox, _("Stop Timeshift?"), MessageBox.TYPE_YESNO)
+
+ def stopTimeshiftConfirmed(self, confirmed):
+ if not confirmed:
+ return
+
+ ts = self.getTimeshift()
+ if ts is None:
+ return
+
+ ts.stopTimeshift()
+ self.timeshift_enabled = 0
+
+ # disable actions
+ self.__seekableStatusChanged()
+
+ # activates timeshift, and seeks to (almost) the end
+ def activateTimeshiftEnd(self):
+ ts = self.getTimeshift()
+
+ if ts is None:
+ return
+
+ if ts.isTimeshiftActive():
+ print "!! activate timeshift called - but shouldn't this be a normal pause?"
+ self.pauseService()
+ else:
+ self.setSeekState(self.SEEK_STATE_PLAY)
+ ts.activateTimeshift()
+ self.seekRelative(0)
+
+ # same as activateTimeshiftEnd, but pauses afterwards.
+ def activateTimeshiftEndAndPause(self):
+ state = self.seekstate
+ self.activateTimeshiftEnd()
+
+ # well, this is "andPause", but it could be pressed from pause,
+ # when pausing on the (fake-)"live" picture, so an un-pause
+ # is perfectly ok.
+
+ print "now, pauseService"
+ if state == self.SEEK_STATE_PLAY:
+ print "is PLAYING, start pause timer"
+ self.ts_pause_timer.start(200, 1)
+ else:
+ print "unpause"
+ self.unPauseService()
+
+ def __seekableStatusChanged(self):
+ enabled = False
+
+ print "self.isSeekable", self.isSeekable()
+ print "self.timeshift_enabled", self.timeshift_enabled
+
+ # when this service is not seekable, but timeshift
+ # is enabled, this means we can activate
+ # the timeshift
+ if not self.isSeekable() and self.timeshift_enabled:
+ enabled = True
+
+ print "timeshift activate:", enabled
+ self["TimeshiftActivateActions"].setEnabled(enabled)
+
+ def __serviceStarted(self):
+ self.timeshift_enabled = False
+ self.__seekableStatusChanged()
+
+from Screens.PiPSetup import PiPSetup
+
+class InfoBarExtensions:
+ EXTENSION_SINGLE = 0
+ EXTENSION_LIST = 1
+
+ def __init__(self):
+ self.list = []
+
+ self["InstantExtensionsActions"] = HelpableActionMap(self, "InfobarExtensions",
+ {
+ "extensions": (self.showExtensionSelection, _("view extensions...")),
+ })
+
+ def addExtension(self, extension, key = None, type = EXTENSION_SINGLE):
+ self.list.append((type, extension, key))
+
+ def updateExtension(self, extension, key = None):
+ self.extensionsList.append(extension)
+ if key is not None:
+ if self.extensionKeys.has_key(key):
+ key = None
+
+ if key is None:
+ for x in self.availableKeys:
+ if not self.extensionKeys.has_key(x):
+ key = x
+ break
+
+ if key is not None:
+ self.extensionKeys[key] = len(self.extensionsList) - 1
+
+ def updateExtensions(self):
+ self.extensionsList = []
+ self.availableKeys = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "red", "green", "yellow", "blue" ]
+ self.extensionKeys = {}
+ for x in self.list:
+ if x[0] == self.EXTENSION_SINGLE:
+ self.updateExtension(x[1], x[2])
+ else:
+ for y in x[1]():
+ self.updateExtension(y[0], y[1])
+
+
+ def showExtensionSelection(self):
+ self.updateExtensions()
+ extensionsList = self.extensionsList[:]
+ keys = []
+ list = []
+ for x in self.availableKeys:
+ if self.extensionKeys.has_key(x):
+ entry = self.extensionKeys[x]
+ extension = self.extensionsList[entry]
+ if extension[2]():
+ name = str(extension[0]())
+ list.append((extension[0](), extension))
+ keys.append(x)
+ extensionsList.remove(extension)
+ else:
+ extensionsList.remove(extension)
+ for x in extensionsList:
+ list.append((x[0](), x))
+ keys += [""] * len(extensionsList)
+ self.session.openWithCallback(self.extensionCallback, ChoiceBox, title=_("Please choose an extension..."), list = list, keys = keys)
+
+ def extensionCallback(self, answer):
+ if answer is not None:
+ answer[1][1]()
+
+from Tools.BoundFunction import boundFunction
+
+# depends on InfoBarExtensions
+from Components.PluginComponent import plugins
+
+class InfoBarPlugins:
+ def __init__(self):
+ self.addExtension(extension = self.getPluginList, type = InfoBarExtensions.EXTENSION_LIST)
+
+ def getPluginName(self, name):
+ return name
+
+ def getPluginList(self):
+ list = []
+ for p in plugins.getPlugins(where = PluginDescriptor.WHERE_EXTENSIONSMENU):
+ list.append(((boundFunction(self.getPluginName, p.name), boundFunction(self.runPlugin, p), lambda: True), None))
+ return list
+
+ def runPlugin(self, plugin):
+ plugin(session = self.session)
+
+# depends on InfoBarExtensions
+class InfoBarSleepTimer:
+ def __init__(self):
+ self.addExtension((self.getSleepTimerName, self.showSleepTimerSetup, self.available), "1")
+
+ def available(self):
+ return True
+
+ def getSleepTimerName(self):
+ return _("Sleep Timer")
+
+ def showSleepTimerSetup(self):
+ self.session.open(SleepTimerEdit)
+
+# depends on InfoBarExtensions
+class InfoBarPiP:
+ def __init__(self):
+ self.session.pipshown = False
+
+ self.addExtension((self.getShowHideName, self.showPiP, self.available), "blue")
+ self.addExtension((self.getMoveName, self.movePiP, self.pipShown), "green")
+ self.addExtension((self.getSwapName, self.swapPiP, self.pipShown), "yellow")
+
+ def available(self):
+ return True
+
+ def pipShown(self):
+ return self.session.pipshown
+
+ def getShowHideName(self):
+ if self.session.pipshown:
+ return _("Disable Picture in Picture")
+ else:
+ return _("Activate Picture in Picture")
+
+ def getSwapName(self):
+ return _("Swap Services")
+
+ def getMoveName(self):
+ return _("Move Picture in Picture")
+
+ def showPiP(self):
+ if self.session.pipshown:
+ del self.session.pip
+ self.session.pipshown = False
+ else:
+ self.session.pip = self.session.instantiateDialog(PictureInPicture)
+ newservice = self.session.nav.getCurrentlyPlayingServiceReference()
+ if self.session.pip.playService(newservice):
+ self.session.pipshown = True
+ self.session.pip.servicePath = self.servicelist.getCurrentServicePath()
+ else:
+ self.session.pipshown = False
+ del self.session.pip
+ self.session.nav.playService(newservice)
+
+ def swapPiP(self):
+ swapservice = self.session.nav.getCurrentlyPlayingServiceReference()
+ if self.session.pip.servicePath:
+ servicepath = self.servicelist.getCurrentServicePath()
+ ref=servicepath[len(servicepath)-1]
+ pipref=self.session.pip.getCurrentService()
+ self.session.pip.playService(swapservice)
+ self.servicelist.setCurrentServicePath(self.session.pip.servicePath)
+ if pipref.toString() != ref.toString(): # is a subservice ?
+ self.session.nav.stopService() # stop portal
+ self.session.nav.playService(pipref) # start subservice
+ self.session.pip.servicePath=servicepath
+
+ def movePiP(self):
+ self.session.open(PiPSetup, pip = self.session.pip)
+
+from RecordTimer import parseEvent