+ if not self.pathChangedDisabled:
+ if not self.preEnterPath(self.bouquet_rootstr):
+ if self.isBasePathEqual(self.bouquet_root):
+ self.pathUp()
+ else:
+ currentRoot = self.getRoot()
+ if currentRoot is None or currentRoot != self.bouquet_root:
+ self.clearPath()
+ self.enterPath(self.bouquet_root)
+
+ def keyNumberGlobal(self, number):
+ char = self.numericalTextInput.getKey(number)
+ self.servicelist.moveToChar(char)
+
+ def getRoot(self):
+ return self.servicelist.getRoot()
+
+ def getCurrentSelection(self):
+ return self.servicelist.getCurrent()
+
+ def setCurrentSelection(self, service):
+ servicepath = service.getPath()
+ pos = servicepath.find(" FROM BOUQUET")
+ if pos != -1:
+ if self.mode == MODE_TV:
+ servicepath = '(type == 1)' + servicepath[pos:]
+ else:
+ servicepath = '(type == 2)' + servicepath[pos:]
+ service.setPath(servicepath)
+ self.servicelist.setCurrent(service)
+
+ def getBouquetList(self):
+ serviceCount=0
+ bouquets = [ ]
+ serviceHandler = eServiceCenter.getInstance()
+ list = serviceHandler.list(self.bouquet_root)
+ if not list is None:
+ while True:
+ s = list.getNext()
+ if not s.valid():
+ break
+ if ((s.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
+ info = serviceHandler.info(s)
+ if not info is None:
+ bouquets.append((info.getName(s), s))
+ else:
+ serviceCount += 1
+ if len(bouquets) == 0 and serviceCount > 0:
+ info = serviceHandler.info(self.bouquet_root)
+ if not info is None:
+ bouquets.append((info.getName(self.bouquet_root), self.bouquet_root))
+ return bouquets
+ return None
+
+HISTORYSIZE = 20
+
+class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
+ def __init__(self, session):
+ ChannelSelectionBase.__init__(self,session)
+ ChannelSelectionEdit.__init__(self)
+ ChannelSelectionEPG.__init__(self)
+
+ #config for lastservice
+ config.tv = ConfigSubsection();
+ config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
+ config.tv.lastroot = configElement("config.tv.lastroot", configText, "", 0);
+ config.tv.prevservice = configElement("config.tv.prevservice", configText, "", 0);
+ config.tv.prevroot = configElement("config.tv.prevroot", configText, "", 0);
+
+ self["actions"] = ActionMap(["OkCancelActions"],
+ {
+ "cancel": self.cancel,
+ "ok": self.channelSelected,
+ })
+ self.onShown.append(self.__onShown)
+
+ self.lastChannelRootTimer = eTimer()
+ self.lastChannelRootTimer.timeout.get().append(self.__onCreate)
+ self.lastChannelRootTimer.start(100,True)
+
+ self.history = [ ]
+ self.history_pos = 0
+
+ def __onCreate(self):
+ self.setTvMode()
+ self.restoreRoot()
+ lastservice=eServiceReference(config.tv.lastservice.value)
+ if lastservice.valid():
+ self.setCurrentSelection(lastservice)
+ self.zap()
+
+ def __onShown(self):
+ self.recallBouquetMode()
+ ref = self.session.nav.getCurrentlyPlayingServiceReference()
+ if ref is not None and ref.valid() and ref.getPath() == "":
+ self.servicelist.setPlayableIgnoreService(ref)
+ else:
+ self.servicelist.setPlayableIgnoreService(eServiceReference())
+
+ def channelSelected(self):
+ ref = self.getCurrentSelection()
+ if self.movemode:
+ self.toggleMoveMarked()
+ elif (ref.flags & 7) == 7:
+ self.enterPath(ref)
+ elif self.bouquet_mark_edit:
+ self.doMark()
+ else:
+ self.zap()
+ self.close(ref)
+
+ #called from infoBar and channelSelected
+ def zap(self):
+ ref = self.session.nav.getCurrentlyPlayingServiceReference()
+ nref = self.getCurrentSelection()
+ if ref is None or ref != nref:
+ self.session.nav.playService(nref)
+ self.saveRoot()
+ self.saveChannel()
+ tmp=self.servicePath[:]
+ tmp.append(nref)
+ try:
+ del self.history[self.history_pos+1:]
+ except:
+ pass
+ self.history.append(tmp)
+ hlen = len(self.history)
+ if hlen > HISTORYSIZE:
+ del self.history[0]
+ hlen -= 1
+ self.history_pos = hlen-1
+
+ def historyBack(self):
+ hlen = len(self.history)
+ if hlen > 1 and self.history_pos > 0:
+ self.history_pos -= 1
+ self.setHistoryPath()
+
+ def historyNext(self):
+ hlen = len(self.history)
+ if hlen > 1 and self.history_pos < (hlen-1):
+ self.history_pos += 1
+ self.setHistoryPath()
+
+ def setHistoryPath(self):
+ path = self.history[self.history_pos][:]
+ ref = path.pop()
+ self.servicePath = path
+ self.saveRoot()
+ plen = len(path)
+ root = path[plen-1]
+ if self.getRoot() != root:
+ self.setRoot(root)
+ self.session.nav.playService(ref)
+ self.setCurrentSelection(ref)
+ self.saveChannel()
+
+ def saveRoot(self):
+ path = ''
+ for i in self.servicePathTV:
+ path += i.toString()
+ path += ';'
+ if config.tv.prevroot.value != config.tv.lastroot.value:
+ config.tv.prevroot.value = config.tv.lastroot.value
+ config.tv.prevroot.save()
+ if len(path) and path != config.tv.lastroot.value:
+ config.tv.lastroot.value = path
+ config.tv.lastroot.save()
+
+ def restoreRoot(self):
+ self.clearPath()
+ re = compile('.+?;')
+ tmp = re.findall(config.tv.lastroot.value)
+ cnt = 0
+ for i in tmp:
+ self.servicePathTV.append(eServiceReference(i[:len(i)-1]))
+ cnt += 1
+ if cnt:
+ path = self.servicePathTV.pop()
+ self.enterPath(path)
+ else:
+ self.showFavourites()
+ self.saveRoot()
+
+ def preEnterPath(self, refstr):
+ if len(self.servicePathTV) and self.servicePathTV[0] != eServiceReference(refstr):
+ pathstr = config.tv.lastroot.value
+ if pathstr is not None and pathstr.find(refstr) == 0:
+ self.restoreRoot()
+ lastservice=eServiceReference(config.tv.lastservice.value)
+ if lastservice.valid():
+ self.setCurrentSelection(lastservice)
+ return True
+ return False
+
+ def saveChannel(self):
+ ref = self.session.nav.getCurrentlyPlayingServiceReference()
+ if ref is not None:
+ refstr = ref.toString()
+ else:
+ refstr = ""
+ if refstr != config.tv.lastservice.value:
+ config.tv.prevservice.value = config.tv.lastservice.value
+ config.tv.prevservice.save()
+ config.tv.lastservice.value = refstr
+ config.tv.lastservice.save()
+
+ def recallPrevService(self):
+ if len(config.tv.prevservice.value) and len(config.tv.prevroot.value):
+ if config.tv.lastroot.value != config.tv.prevroot.value:
+ tmp = config.tv.lastroot.value
+ config.tv.lastroot.value = config.tv.prevroot.value
+ config.tv.lastroot.save()
+ config.tv.prevroot.value = tmp
+ config.tv.prevroot.save()
+ self.restoreRoot()
+ if config.tv.lastservice.value != config.tv.prevservice.value:
+ tmp = config.tv.lastservice.value
+ config.tv.lastservice.value = config.tv.prevservice.value
+ config.tv.lastservice.save()
+ config.tv.prevservice.value = tmp
+ config.tv.prevservice.save()
+ lastservice=eServiceReference(config.tv.lastservice.value)
+ self.session.nav.playService(lastservice)
+ self.setCurrentSelection(lastservice)
+
+ def cancel(self):
+ self.close(None)
+ self.restoreRoot()
+ lastservice=eServiceReference(config.tv.lastservice.value)
+ if lastservice.valid() and self.getCurrentSelection() != lastservice:
+ self.setCurrentSelection(lastservice)
+
+from Screens.InfoBarGenerics import InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord
+
+class RadioInfoBar(Screen, InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord):
+ def __init__(self, session):
+ Screen.__init__(self, session)
+ InfoBarEvent.__init__(self)
+ InfoBarServiceName.__init__(self)
+ InfoBarInstantRecord.__init__(self)
+ self["Clock"] = Clock()
+
+class ChannelSelectionRadio(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
+ def __init__(self, session):
+ ChannelSelectionBase.__init__(self, session)
+ ChannelSelectionEdit.__init__(self)
+ ChannelSelectionEPG.__init__(self)
+
+ config.radio = ConfigSubsection();
+ config.radio.lastservice = configElement("config.radio.lastservice", configText, "", 0);
+ config.radio.lastroot = configElement("config.radio.lastroot", configText, "", 0);
+ self.onLayoutFinish.append(self.onCreate)
+
+ self.info = session.instantiateDialog(RadioInfoBar)
+
+ self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
+ {
+ "keyTV": self.closeRadio,
+ "keyRadio": self.closeRadio,
+ "cancel": self.closeRadio,
+ "ok": self.channelSelected,
+ })
+
+ def saveRoot(self):
+ path = ''
+ for i in self.servicePathRadio:
+ path += i.toString()
+ path += ';'
+ if len(path) and path != config.radio.lastroot.value:
+ config.radio.lastroot.value = path
+ config.radio.lastroot.save()
+
+ def restoreRoot(self):
+ self.clearPath()
+ re = compile('.+?;')
+ tmp = re.findall(config.radio.lastroot.value)
+ cnt = 0
+ for i in tmp:
+ self.servicePathRadio.append(eServiceReference(i[:len(i)-1]))
+ cnt += 1
+ if cnt:
+ path = self.servicePathRadio.pop()
+ self.enterPath(path)
+ else:
+ self.showFavourites()
+ self.saveRoot()
+
+ def preEnterPath(self, refstr):
+ if len(self.servicePathRadio) and self.servicePathRadio[0] != eServiceReference(refstr):
+ pathstr = config.radio.lastroot.value
+ if pathstr is not None and pathstr.find(refstr) == 0:
+ self.restoreRoot()
+ lastservice=eServiceReference(config.radio.lastservice.value)
+ if lastservice.valid():
+ self.setCurrentSelection(lastservice)
+ return True
+ return False
+
+ def onCreate(self):
+ self.setRadioMode()
+ self.restoreRoot()
+ lastservice=eServiceReference(config.radio.lastservice.value)
+ if lastservice.valid():
+ self.servicelist.setCurrent(lastservice)
+ self.session.nav.playService(lastservice)
+ self.servicelist.setPlayableIgnoreService(lastservice)
+ self.info.show()
+
+ def channelSelected(self): # just return selected service
+ ref = self.getCurrentSelection()
+ if self.movemode:
+ self.toggleMoveMarked()
+ elif (ref.flags & 7) == 7:
+ self.enterPath(ref)
+ elif self.bouquet_mark_edit:
+ self.doMark()
+ else:
+ playingref = self.session.nav.getCurrentlyPlayingServiceReference()
+ if playingref is None or playingref != ref:
+ self.session.nav.playService(ref)
+ self.servicelist.setPlayableIgnoreService(ref)
+ config.radio.lastservice.value = ref.toString()
+ config.radio.lastservice.save()
+ self.saveRoot()
+
+ def closeRadio(self):
+ self.info.hide()
+ #set previous tv service
+ lastservice=eServiceReference(config.tv.lastservice.value)
+ self.session.nav.playService(lastservice)
+ self.close(None)
+
+class SimpleChannelSelection(ChannelSelectionBase):
+ def __init__(self, session, title):
+ ChannelSelectionBase.__init__(self, session)
+ self.title = title
+ self.onShown.append(self.__onExecCallback)
+
+ self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
+ {
+ "cancel": self.close,
+ "ok": self.channelSelected,
+ "keyRadio": self.setModeRadio,
+ "keyTV": self.setModeTv,
+ })
+
+ def __onExecCallback(self):
+ self.session.currentDialog.instance.setTitle(self.title)
+ self.setModeTv()
+
+ def channelSelected(self): # just return selected service
+ ref = self.getCurrentSelection()
+ if (ref.flags & 7) == 7:
+ self.enterPath(ref)
+ else:
+ ref = self.getCurrentSelection()
+ self.close(ref)
+
+ def setModeTv(self):
+ self.setTvMode()
+ self.showFavourites()
+
+ def setModeRadio(self):
+ self.setRadioMode()
+ self.showFavourites()