1 from Screen import Screen
2 from Components.Button import Button
3 from Components.ServiceList import ServiceList
4 from Components.ActionMap import NumberActionMap, ActionMap
5 from Components.MenuList import MenuList
6 from EpgSelection import EPGSelection
7 from enigma import eServiceReference, eEPGCache, eEPGCachePtr, eServiceCenter, eServiceCenterPtr, iMutableServiceListPtr, iStaticServiceInformationPtr, eTimer, eDVBDB
8 from Components.config import config, configElement, ConfigSubsection, configText, currentConfigSelectionElement
9 from Screens.FixedMenu import FixedMenu
10 from Tools.NumericalTextInput import NumericalTextInput
11 from Components.NimManager import nimmanager
12 from Components.ServiceName import ServiceName
13 from Components.Clock import Clock
14 from Components.EventInfo import EventInfo
15 from ServiceReference import ServiceReference
19 import xml.dom.minidom
21 class BouquetSelector(Screen):
22 def __init__(self, session, bouquets, selectedFunc):
23 Screen.__init__(self, session)
25 self.selectedFunc=selectedFunc
27 self["actions"] = ActionMap(["OkCancelActions"],
29 "ok": self.okbuttonClick,
30 "cancel": self.cancelClick
34 entrys.append((x[0], x[1]))
35 self["menu"] = MenuList(entrys)
37 def okbuttonClick(self):
38 self.selectedFunc(self["menu"].getCurrent()[1])
40 def cancelClick(self):
43 class ChannelContextMenu(FixedMenu):
44 def __init__(self, session, csel):
49 inBouquetRootList = csel.getRoot().getPath().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
50 inBouquet = csel.getMutableList() is not None
51 haveBouquets = csel.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1
53 if not csel.bouquet_mark_edit and not csel.movemode:
54 if not inBouquetRootList:
55 if (csel.getCurrentSelection().flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory:
57 menu.append((_("add service to bouquet"), self.addServiceToBouquetSelected))
59 menu.append((_("add service to favourites"), self.addServiceToBouquetSelected))
61 if not inBouquet and csel.getCurrentSelection().getPath().find("PROVIDERS") == -1:
62 menu.append((_("copy to favourites"), csel.copyCurrentToBouquetList))
64 menu.append((_("remove service"), self.removeCurrentService))
66 menu.append((_("remove bouquet"), csel.removeBouquet))
68 if inBouquet: # current list is editable?
69 if not csel.bouquet_mark_edit:
71 menu.append((_("enable move mode"), self.toggleMoveMode))
72 if not inBouquetRootList:
74 menu.append((_("enable bouquet edit"), self.bouquetMarkStart))
76 menu.append((_("enable favourite edit"), self.bouquetMarkStart))
78 menu.append((_("disable move mode"), self.toggleMoveMode))
79 elif not inBouquetRootList:
81 menu.append((_("end bouquet edit"), self.bouquetMarkEnd))
82 menu.append((_("abort bouquet edit"), self.bouquetMarkAbort))
84 menu.append((_("end favourites edit"), self.bouquetMarkEnd))
85 menu.append((_("abort favourites edit"), self.bouquetMarkAbort))
87 menu.append((_("back"), self.close))
89 FixedMenu.__init__(self, session, _("Channel Selection"), menu)
90 self.skinName = "Menu"
92 def addServiceToBouquetSelected(self):
93 bouquets = self.csel.getBouquetList()
98 if cnt > 1: # show bouquet list
99 self.session.open(BouquetSelector, bouquets, self.addCurrentServiceToBouquet)
100 elif cnt == 1: # add to only one existing bouquet
101 self.addCurrentServiceToBouquet(bouquets[0][1])
102 else: #no bouquets in root.. so assume only one favourite list is used
103 self.addCurrentServiceToBouquet(self.csel.bouquet_root)
105 def copyCurrentToBouquetList(self):
106 self.csel.copyCurrentToBouquetList()
109 def removeBouquet(self):
110 self.csel.removeBouquet()
113 def addCurrentServiceToBouquet(self, dest):
114 self.csel.addCurrentServiceToBouquet(dest)
117 def removeCurrentService(self):
118 self.csel.removeCurrentService()
121 def toggleMoveMode(self):
122 self.csel.toggleMoveMode()
125 def bouquetMarkStart(self):
126 self.csel.startMarkedEdit()
129 def bouquetMarkEnd(self):
130 self.csel.endMarkedEdit(abort=False)
133 def bouquetMarkAbort(self):
134 self.csel.endMarkedEdit(abort=True)
137 class ChannelSelectionEPG:
139 self["ChannelSelectEPGActions"] = ActionMap(["ChannelSelectEPGActions"],
141 "showEPGList": self.showEPGList,
144 def showEPGList(self):
145 ref=self.getCurrentSelection()
146 ptr=eEPGCache.getInstance()
147 if ptr.startTimeQuery(ref) != -1:
148 self.session.open(EPGSelection, ref)
150 print 'no epg for service', ref.toString()
152 class ChannelSelectionEdit:
154 self.entry_marked = False
155 self.movemode = False
156 self.bouquet_mark_edit = False
157 self.mutableList = None
159 self.saved_title = None
160 self.saved_root = None
162 class ChannelSelectionEditActionMap(ActionMap):
163 def __init__(self, csel, contexts = [ ], actions = { }, prio=0):
164 ActionMap.__init__(self, contexts, actions, prio)
166 def action(self, contexts, action):
167 if action == "cancel":
168 self.csel.handleEditCancel()
170 pass # avoid typo warning...
172 ActionMap.action(self, contexts, action)
173 self["ChannelSelectEditActions"] = ChannelSelectionEditActionMap(self, ["ChannelSelectEditActions", "OkCancelActions"],
175 "contextMenu": self.doContext,
178 def getMutableList(self, root=eServiceReference()):
179 if not self.mutableList is None:
180 return self.mutableList
181 serviceHandler = eServiceCenter.getInstance()
184 list = serviceHandler.list(root)
186 return list.startEdit()
189 def buildBouquetID(self, str):
193 if (c >= 'a' and c <= 'z') or (c >= '0' and c <= '9'):
199 def copyCurrentToBouquetList(self):
200 provider = ServiceReference(self.getCurrentSelection())
201 serviceHandler = eServiceCenter.getInstance()
202 mutableBouquetList = serviceHandler.list(self.bouquet_root).startEdit()
203 if mutableBouquetList:
204 providerName = provider.getServiceName()
205 if self.mode == MODE_TV:
206 str = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET \"userbouquet.%s.tv\" ORDER BY bouquet'%(self.buildBouquetID(providerName))
208 str = '1:7:2:0:0:0:0:0:0:0:(type == 2) FROM BOUQUET \"userbouquet.%s.radio\" ORDER BY bouquet'%(self.buildBouquetID(providerName))
209 new_bouquet_ref = eServiceReference(str)
210 if not mutableBouquetList.addService(new_bouquet_ref):
211 mutableBouquetList.flushChanges()
212 eDVBDB.getInstance().reloadBouquets()
213 mutableBouquet = serviceHandler.list(new_bouquet_ref).startEdit()
215 mutableBouquet.setListName(providerName)
217 services = serviceHandler.list(provider.ref)
218 if not services is None:
219 if not services.getContent(list, True):
221 if mutableBouquet.addService(service):
222 print "add", service.toString(), "to new bouquet failed"
223 mutableBouquet.flushChanges()
225 print "getContent failed"
227 print "list provider", providerName, "failed"
229 print "get mutable list for new created bouquet failed"
231 print "add", str, "to bouquets failed"
233 print "bouquetlist is not editable"
235 def removeBouquet(self):
236 refstr = self.getCurrentSelection().toString()
237 pos = refstr.find('FROM BOUQUET "')
239 refstr = refstr[pos+14:]
241 pos = refstr.find('"')
243 filename = '/etc/enigma2/' + refstr[:pos] # FIXMEEE !!! HARDCODED /etc/enigma2
244 self.removeCurrentService()
246 eDVBDB.getInstance().reloadBouquets()
248 # multiple marked entry stuff ( edit mode, later multiepg selection )
249 def startMarkedEdit(self):
250 self.mutableList = self.getMutableList()
251 # add all services from the current list to internal marked set in listboxservicecontent
252 self.bouquetRoot = self.getRoot()
253 self.clearMarks() # this clears the internal marked set in the listboxservicecontent
254 self.saved_title = self.instance.getTitle()
255 new_title = self.saved_title
256 if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1:
257 new_title += ' ' + _("[bouquet edit]")
259 new_title += ' ' + _("[favourite edit]")
260 self.instance.setTitle(new_title)
261 self.bouquet_mark_edit = True
262 self.__marked = self.servicelist.getRootServices()
263 for x in self.__marked:
264 self.servicelist.addMarked(eServiceReference(x))
265 self.saved_root = self.getRoot()
266 self.showAllServices()
268 def endMarkedEdit(self, abort):
269 if not abort and self.mutableList is not None:
270 new_marked = set(self.servicelist.getMarked())
271 old_marked = set(self.__marked)
272 removed = old_marked - new_marked
273 added = new_marked - old_marked
277 self.mutableList.removeService(eServiceReference(x))
280 self.mutableList.addService(eServiceReference(x))
282 self.mutableList.flushChanges()
285 self.bouquet_mark_edit = False
286 self.bouquetRoot = None
287 self.mutableList = None
288 self.instance.setTitle(self.saved_title)
289 self.saved_title = None
290 self.setRoot(self.saved_root)
292 def clearMarks(self):
293 self.servicelist.clearMarks()
296 ref = self.servicelist.getCurrent()
297 if self.servicelist.isMarked(ref):
298 self.servicelist.removeMarked(ref)
300 self.servicelist.addMarked(ref)
302 def removeCurrentService(self):
303 ref = self.servicelist.getCurrent()
304 mutableList = self.getMutableList()
305 if ref.valid() and mutableList is not None:
306 if not mutableList.removeService(ref):
307 currentIndex = self.servicelist.getCurrentIndex()
308 self.servicelist.moveDown()
309 if self.servicelist.getCurrentIndex() == currentIndex:
311 mutableList.flushChanges() #FIXME dont flush on each single removed service
312 self.setRoot(self.getRoot())
313 self.servicelist.moveToIndex(currentIndex)
315 def addCurrentServiceToBouquet(self, dest):
316 mutableList = self.getMutableList(dest)
317 if not mutableList is None:
318 if not mutableList.addService(self.servicelist.getCurrent()):
319 mutableList.flushChanges()
322 def toggleMoveMode(self):
324 if self.entry_marked:
325 self.toggleMoveMarked() # unmark current entry
326 self.movemode = False
327 self.pathChangedDisabled = False # re-enable path change
328 self.mutableList.flushChanges() # FIXME add check if changes was made
329 self.mutableList = None
330 self.instance.setTitle(self.saved_title)
331 self.saved_title = None
333 self.mutableList = self.getMutableList()
335 self.pathChangedDisabled = True # no path change allowed in movemode
336 self.saved_title = self.instance.getTitle()
337 new_title = self.saved_title
338 new_title += ' ' + _("[move mode]");
339 self.instance.setTitle(new_title);
341 def handleEditCancel(self):
342 if self.movemode: #movemode active?
343 self.channelSelected() # unmark
344 self.toggleMoveMode() # disable move mode
345 elif self.bouquet_mark_edit:
346 self.endMarkedEdit(True) # abort edit mode
348 def toggleMoveMarked(self):
349 if self.entry_marked:
350 self.servicelist.setCurrentMarked(False)
351 self.entry_marked = False
353 self.servicelist.setCurrentMarked(True)
354 self.entry_marked = True
357 self.session.open(ChannelContextMenu, self)
362 class ChannelSelectionBase(Screen):
363 def __init__(self, session):
364 Screen.__init__(self, session)
366 # this makes it much simple to implement a selectable radio or tv mode :)
367 self.service_types_tv = '1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17)'
368 self.service_types_radio = '1:7:2:0:0:0:0:0:0:0:(type == 2)'
370 self["key_red"] = Button(_("All"))
371 self["key_green"] = Button(_("Satellites"))
372 self["key_yellow"] = Button(_("Provider"))
373 self["key_blue"] = Button(_("Favourites"))
375 self["list"] = ServiceList()
376 self.servicelist = self["list"]
378 self.numericalTextInput = NumericalTextInput()
380 self.servicePathTV = [ ]
381 self.servicePathRadio = [ ]
383 self.pathChangedDisabled = False
385 self["ChannelSelectBaseActions"] = NumberActionMap(["ChannelSelectBaseActions", "NumberActions"],
387 "showFavourites": self.showFavourites,
388 "showAllServices": self.showAllServices,
389 "showProviders": self.showProviders,
390 "showSatellites": self.showSatellites,
391 "nextBouquet": self.nextBouquet,
392 "prevBouquet": self.prevBouquet,
393 "1": self.keyNumberGlobal,
394 "2": self.keyNumberGlobal,
395 "3": self.keyNumberGlobal,
396 "4": self.keyNumberGlobal,
397 "5": self.keyNumberGlobal,
398 "6": self.keyNumberGlobal,
399 "7": self.keyNumberGlobal,
400 "8": self.keyNumberGlobal,
401 "9": self.keyNumberGlobal,
402 "0": self.keyNumberGlobal
405 def appendDVBTypes(self, ref):
407 pos = path.find(' FROM BOUQUET')
409 return eServiceReference(self.service_types + path[pos:])
412 def getBouquetNumOffset(self, bouquet):
413 bouquet = self.appendDVBTypes(bouquet)
414 if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
417 serviceHandler = eServiceCenter.getInstance()
418 bouquetlist = serviceHandler.list(self.bouquet_root)
419 if not bouquetlist is None:
421 bouquetIterator = self.appendDVBTypes(bouquetlist.getNext())
422 if not bouquetIterator.valid() or bouquetIterator == bouquet: #end of list or bouquet found
424 if ((bouquetIterator.flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory):
426 servicelist = serviceHandler.list(bouquetIterator)
427 if not servicelist is None:
429 serviceIterator = servicelist.getNext()
430 if not serviceIterator.valid(): #check if end of list
432 if serviceIterator.flags: #playable services have no flags
437 def recallBouquetMode(self):
438 if self.mode == MODE_TV:
439 self.service_types = self.service_types_tv
440 if currentConfigSelectionElement(config.usage.multibouquet) == "yes":
441 self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet'
443 self.bouquet_rootstr = '%s FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet'%(self.service_types)
445 self.service_types = self.service_types_radio
446 if currentConfigSelectionElement(config.usage.multibouquet) == "yes":
447 self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.radio" ORDER BY bouquet'
449 self.bouquet_rootstr = '%s FROM BOUQUET "userbouquet.favourites.radio" ORDER BY bouquet'%(self.service_types)
450 self.bouquet_root = eServiceReference(self.bouquet_rootstr)
453 title = self.instance.getTitle()
454 pos = title.find(" (")
458 self.instance.setTitle(title)
460 self.recallBouquetMode()
462 def setRadioMode(self):
463 title = self.instance.getTitle()
464 pos = title.find(" (")
468 self.instance.setTitle(title)
469 self.mode = MODE_RADIO
470 self.recallBouquetMode()
472 def setRoot(self, root, justSet=False):
473 path = root.getPath()
474 inBouquetRootList = path.find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
475 pos = path.find(' FROM BOUQUET')
476 isBouquet = pos != -1
477 if not inBouquetRootList and isBouquet:
478 self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
479 self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
480 refstr = self.service_types + path[pos:]
481 root = eServiceReference(refstr)
483 self.servicelist.setMode(ServiceList.MODE_NORMAL)
484 self.servicelist.setRoot(root, justSet)
487 self.servicelist.moveUp()
490 self.servicelist.moveDown()
493 if self.mode == MODE_RADIO:
494 self.servicePathRadio = [ ]
496 self.servicePathTV = [ ]
498 def enterPath(self, ref, justSet=False):
499 if self.mode == MODE_RADIO:
500 self.servicePathRadio.append(ref)
502 self.servicePathTV.append(ref)
503 self.setRoot(ref, justSet)
505 def pathUp(self, justSet=False):
506 if self.mode == MODE_TV:
507 prev = self.servicePathTV.pop()
508 length = len(self.servicePathTV)
510 current = self.servicePathTV[length-1]
512 prev = self.servicePathRadio.pop()
513 length = len(self.servicePathRadio)
515 current = self.servicePathRadio[length-1]
516 self.setRoot(current, justSet)
518 self.setCurrentSelection(prev)
521 def isBasePathEqual(self, ref):
522 if self.mode == MODE_RADIO and len(self.servicePathRadio) > 1 and self.servicePathRadio[0] == ref:
524 elif self.mode == MODE_TV and len(self.servicePathTV) > 1 and self.servicePathTV[0] == ref:
528 def isPrevPathEqual(self, ref):
529 path = self.servicePathRadio
530 if self.mode == MODE_TV:
531 path = self.servicePathTV
533 if length > 1 and path[length-2] == ref:
537 def preEnterPath(self, refstr):
540 def showAllServices(self):
541 if not self.pathChangedDisabled:
542 refstr = '%s ORDER BY name'%(self.service_types)
543 if not self.preEnterPath(refstr):
544 ref = eServiceReference(refstr)
545 currentRoot = self.getRoot()
546 if currentRoot is None or currentRoot != ref:
550 def showSatellites(self):
551 if not self.pathChangedDisabled:
552 refstr = '%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types)
553 if not self.preEnterPath(refstr):
554 ref = eServiceReference(refstr)
558 if self.isBasePathEqual(ref):
559 if self.isPrevPathEqual(ref):
561 prev = self.pathUp(justSet)
563 currentRoot = self.getRoot()
564 if currentRoot is None or currentRoot != ref:
567 self.enterPath(ref, True)
569 serviceHandler = eServiceCenter.getInstance()
570 servicelist = serviceHandler.list(ref)
571 if not servicelist is None:
573 service = servicelist.getNext()
574 if not service.valid(): #check if end of list
576 orbpos = service.getData(4) >> 16
577 if service.getPath().find("FROM PROVIDER") != -1:
578 service_name = _("Providers")
580 service_name = _("Services")
582 service_name += str(' - %s'%(nimmanager.getSatDescription(orbpos)))
583 service.setName(service_name) # why we need this cast?
585 if orbpos > 1800: # west
586 service.setName("%s (%3.1f" + _("W") + ")" %(str, (0 - (orbpos - 3600)) / 10.0))
588 service.setName("%s (%3.1f" + _("E") + ")" % (str, orbpos / 10.0))
589 self.servicelist.addService(service)
590 self.servicelist.finishFill()
592 self.setCurrentSelection(prev)
594 def showProviders(self):
595 if not self.pathChangedDisabled:
596 refstr = '%s FROM PROVIDERS ORDER BY name'%(self.service_types)
597 if not self.preEnterPath(refstr):
598 ref = eServiceReference(refstr)
599 if self.isBasePathEqual(ref):
602 currentRoot = self.getRoot()
603 if currentRoot is None or currentRoot != ref:
607 def changeBouquet(self, direction):
608 if not self.pathChangedDisabled:
609 if self.isBasePathEqual(self.bouquet_root):
615 ref = self.getCurrentSelection()
618 def nextBouquet(self):
619 self.changeBouquet(+1)
621 def prevBouquet(self):
622 self.changeBouquet(-1)
624 def showFavourites(self):
625 if not self.pathChangedDisabled:
626 if not self.preEnterPath(self.bouquet_rootstr):
627 if self.isBasePathEqual(self.bouquet_root):
630 currentRoot = self.getRoot()
631 if currentRoot is None or currentRoot != self.bouquet_root:
633 self.enterPath(self.bouquet_root)
635 def keyNumberGlobal(self, number):
636 char = self.numericalTextInput.getKey(number)
637 self.servicelist.moveToChar(char)
640 return self.servicelist.getRoot()
642 def getCurrentSelection(self):
643 return self.servicelist.getCurrent()
645 def setCurrentSelection(self, service):
646 servicepath = service.getPath()
647 pos = servicepath.find(" FROM BOUQUET")
649 if self.mode == MODE_TV:
650 servicepath = '(type == 1)' + servicepath[pos:]
652 servicepath = '(type == 2)' + servicepath[pos:]
653 service.setPath(servicepath)
654 self.servicelist.setCurrent(service)
656 def getBouquetList(self):
659 serviceHandler = eServiceCenter.getInstance()
660 list = serviceHandler.list(self.bouquet_root)
666 if ((s.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
667 info = serviceHandler.info(s)
669 bouquets.append((info.getName(s), s))
672 if len(bouquets) == 0 and serviceCount > 0:
673 info = serviceHandler.info(self.bouquet_root)
675 bouquets.append((info.getName(self.bouquet_root), self.bouquet_root))
679 class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
680 def __init__(self, session):
681 ChannelSelectionBase.__init__(self,session)
682 ChannelSelectionEdit.__init__(self)
683 ChannelSelectionEPG.__init__(self)
685 #config for lastservice
686 config.tv = ConfigSubsection();
687 config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
688 config.tv.lastroot = configElement("config.tv.lastroot", configText, "", 0);
689 config.tv.prevservice = configElement("config.tv.prevservice", configText, "", 0);
690 config.tv.prevroot = configElement("config.tv.prevroot", configText, "", 0);
692 self["actions"] = ActionMap(["OkCancelActions"],
694 "cancel": self.cancel,
695 "ok": self.channelSelected,
697 self.onShown.append(self.onShow)
699 self.lastChannelRootTimer = eTimer()
700 self.lastChannelRootTimer.timeout.get().append(self.onCreate)
701 self.lastChannelRootTimer.start(100,True)
705 self.servicePathTV = [ ]
707 lastservice=eServiceReference(config.tv.lastservice.value)
708 if lastservice.valid():
709 self.setCurrentSelection(lastservice)
710 self.session.nav.playService(lastservice)
713 self.recallBouquetMode()
714 ref = self.session.nav.getCurrentlyPlayingServiceReference()
715 if ref is not None and ref.valid() and ref.getPath() == "":
716 self.servicelist.setPlayableIgnoreService(ref)
718 self.servicelist.setPlayableIgnoreService(eServiceReference())
720 def channelSelected(self):
721 ref = self.getCurrentSelection()
723 self.toggleMoveMarked()
724 elif (ref.flags & 7) == 7:
726 elif self.bouquet_mark_edit:
732 #called from infoBar and channelSelected
734 ref = self.session.nav.getCurrentlyPlayingServiceReference()
735 if ref is None or ref != self.getCurrentSelection():
736 self.session.nav.playService(self.getCurrentSelection())
742 for i in self.servicePathTV:
745 if config.tv.prevroot.value != config.tv.lastroot.value:
746 config.tv.prevroot.value = config.tv.lastroot.value
747 config.tv.prevroot.save()
748 if len(path) and path != config.tv.lastroot.value:
749 config.tv.lastroot.value = path
750 config.tv.lastroot.save()
752 def restoreRoot(self):
753 self.servicePathTV = [ ]
755 tmp = re.findall(config.tv.lastroot.value)
758 self.servicePathTV.append(eServiceReference(i[:len(i)-1]))
761 path = self.servicePathTV.pop()
764 self.showFavourites()
767 def preEnterPath(self, refstr):
768 if len(self.servicePathTV) and self.servicePathTV[0] != eServiceReference(refstr):
769 pathstr = config.tv.lastroot.value
770 if pathstr is not None and pathstr.find(refstr) == 0:
772 lastservice=eServiceReference(config.tv.lastservice.value)
773 if lastservice is not None:
774 self.setCurrentSelection(lastservice)
778 def saveChannel(self):
779 ref = self.session.nav.getCurrentlyPlayingServiceReference()
781 refstr = ref.toString()
784 if refstr != config.tv.lastservice.value:
785 config.tv.prevservice.value = config.tv.lastservice.value
786 config.tv.prevservice.save()
787 config.tv.lastservice.value = refstr
788 config.tv.lastservice.save()
790 def recallPrevService(self):
791 if len(config.tv.prevservice.value) and len(config.tv.prevroot.value):
792 if config.tv.lastroot.value != config.tv.prevroot.value:
793 tmp = config.tv.lastroot.value
794 config.tv.lastroot.value = config.tv.prevroot.value
795 config.tv.lastroot.save()
796 config.tv.prevroot.value = tmp
797 config.tv.prevroot.save()
799 if config.tv.lastservice.value != config.tv.prevservice.value:
800 tmp = config.tv.lastservice.value
801 config.tv.lastservice.value = config.tv.prevservice.value
802 config.tv.lastservice.save()
803 config.tv.prevservice.value = tmp
804 config.tv.prevservice.save()
805 lastservice=eServiceReference(config.tv.lastservice.value)
806 self.session.nav.playService(lastservice)
807 self.setCurrentSelection(lastservice)
812 lastservice=eServiceReference(config.tv.lastservice.value)
813 if lastservice.valid() and self.getCurrentSelection() != lastservice:
814 self.setCurrentSelection(lastservice)
816 from Screens.InfoBarGenerics import InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord
818 class RadioInfoBar(Screen, InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord):
819 def __init__(self, session):
820 Screen.__init__(self, session)
821 InfoBarEvent.__init__(self)
822 InfoBarServiceName.__init__(self)
823 InfoBarInstantRecord.__init__(self)
824 self["Clock"] = Clock()
826 class ChannelSelectionRadio(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
827 def __init__(self, session):
828 ChannelSelectionBase.__init__(self, session)
829 ChannelSelectionEdit.__init__(self)
830 ChannelSelectionEPG.__init__(self)
832 config.radio = ConfigSubsection();
833 config.radio.lastservice = configElement("config.radio.lastservice", configText, "", 0);
834 config.radio.lastroot = configElement("config.radio.lastroot", configText, "", 0);
835 self.onLayoutFinish.append(self.onCreate)
837 self.info = session.instantiateDialog(RadioInfoBar)
839 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
841 "keyTV": self.closeRadio,
842 "keyRadio": self.closeRadio,
843 "cancel": self.closeRadio,
844 "ok": self.channelSelected,
849 for i in self.servicePathRadio:
852 if len(path) and path != config.radio.lastroot.value:
853 config.radio.lastroot.value = path
854 config.radio.lastroot.save()
856 def restoreRoot(self):
857 self.servicePathRadio = [ ]
859 tmp = re.findall(config.radio.lastroot.value)
862 self.servicePathRadio.append(eServiceReference(i[:len(i)-1]))
865 path = self.servicePathRadio.pop()
868 self.showFavourites()
871 def preEnterPath(self, refstr):
872 if len(self.servicePathRadio) and self.servicePathRadio[0] != eServiceReference(refstr):
873 pathstr = config.radio.lastroot.value
874 if pathstr is not None and pathstr.find(refstr) == 0:
876 lastservice=eServiceReference(config.radio.lastservice.value)
877 if lastservice is not None:
878 self.setCurrentSelection(lastservice)
885 lastservice=eServiceReference(config.radio.lastservice.value)
886 if lastservice.valid():
887 self.servicelist.setCurrent(lastservice)
888 self.session.nav.playService(lastservice)
889 self.servicelist.setPlayableIgnoreService(lastservice)
890 self.info.instance.show()
892 def channelSelected(self): # just return selected service
893 ref = self.getCurrentSelection()
895 self.toggleMoveMarked()
896 elif (ref.flags & 7) == 7:
898 elif self.bouquet_mark_edit:
901 playingref = self.session.nav.getCurrentlyPlayingServiceReference()
902 if playingref is None or playingref != ref:
903 self.session.nav.playService(ref)
904 self.servicelist.setPlayableIgnoreService(ref)
905 config.radio.lastservice.value = ref.toString()
906 config.radio.lastservice.save()
909 def closeRadio(self):
910 self.info.instance.hide()
911 #set previous tv service
912 lastservice=eServiceReference(config.tv.lastservice.value)
913 self.session.nav.playService(lastservice)
916 class SimpleChannelSelection(ChannelSelectionBase):
917 def __init__(self, session, title):
918 ChannelSelectionBase.__init__(self, session)
920 self.onShown.append(self.onExecCallback)
922 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
924 "cancel": self.cancel,
925 "ok": self.channelSelected,
926 "keyRadio": self.setModeRadio,
927 "keyTV": self.setModeTv,
930 def onExecCallback(self):
931 self.session.currentDialog.instance.setTitle(self.title)
934 def channelSelected(self): # just return selected service
935 ref = self.getCurrentSelection()
936 if (ref.flags & 7) == 7:
939 ref = self.getCurrentSelection()
944 self.showFavourites()
946 def setModeRadio(self):
948 self.showFavourites()