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 Components.Input import Input
16 from Screens.InputBox import InputBox
17 from ServiceReference import ServiceReference
21 import xml.dom.minidom
23 class BouquetSelector(Screen):
24 def __init__(self, session, bouquets, selectedFunc):
25 Screen.__init__(self, session)
27 self.selectedFunc=selectedFunc
29 self["actions"] = ActionMap(["OkCancelActions"],
31 "ok": self.okbuttonClick,
32 "cancel": self.cancelClick
36 entrys.append((x[0], x[1]))
37 self["menu"] = MenuList(entrys)
39 def okbuttonClick(self):
40 self.selectedFunc(self["menu"].getCurrent()[1])
42 def cancelClick(self):
45 class ChannelContextMenu(Screen):
46 def __init__(self, session, csel):
47 Screen.__init__(self, session)
50 self["actions"] = ActionMap(["OkCancelActions"],
52 "ok": self.okbuttonClick,
53 "cancel": self.cancelClick
57 current_root = csel.getRoot()
58 inBouquetRootList = current_root and current_root.getPath().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
59 inBouquet = csel.getMutableList() is not None
60 haveBouquets = csel.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1
62 if not csel.bouquet_mark_edit and not csel.movemode:
63 if not inBouquetRootList:
64 if (csel.getCurrentSelection().flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory:
66 menu.append((_("add service to bouquet"), self.addServiceToBouquetSelected))
68 menu.append((_("add service to favourites"), self.addServiceToBouquetSelected))
70 if not inBouquet and csel.getCurrentSelection().getPath().find("PROVIDERS") == -1:
71 menu.append((_("copy to favourites"), self.copyCurrentToBouquetList))
73 menu.append((_("remove service"), self.removeCurrentService))
75 menu.append((_("remove bouquet"), self.removeBouquet))
77 if inBouquet: # current list is editable?
78 if not csel.bouquet_mark_edit:
80 menu.append((_("enable move mode"), self.toggleMoveMode))
81 menu.append((_("add bouquet..."), self.showBouquetInputBox))
82 if not inBouquetRootList:
84 menu.append((_("enable bouquet edit"), self.bouquetMarkStart))
86 menu.append((_("enable favourite edit"), self.bouquetMarkStart))
88 menu.append((_("disable move mode"), self.toggleMoveMode))
89 elif not inBouquetRootList:
91 menu.append((_("end bouquet edit"), self.bouquetMarkEnd))
92 menu.append((_("abort bouquet edit"), self.bouquetMarkAbort))
94 menu.append((_("end favourites edit"), self.bouquetMarkEnd))
95 menu.append((_("abort favourites edit"), self.bouquetMarkAbort))
97 menu.append((_("back"), self.cancelClick))
98 self["menu"] = MenuList(menu)
100 def okbuttonClick(self):
101 self["menu"].getCurrent()[1]()
103 def cancelClick(self):
106 def showBouquetInputBox(self):
107 self.session.openWithCallback(self.bouquetInputCallback, InputBox, title=_("Please enter a name for the new bouquet"), text="bouquetname", maxSize=False, type=Input.TEXT)
109 def bouquetInputCallback(self, bouquet):
110 if bouquet is not None:
111 self.csel.addBouquet(bouquet)
113 def addServiceToBouquetSelected(self):
114 bouquets = self.csel.getBouquetList()
119 if cnt > 1: # show bouquet list
120 self.session.openWithCallback(self.bouquetSelClosed, BouquetSelector, bouquets, self.addCurrentServiceToBouquet)
121 elif cnt == 1: # add to only one existing bouquet
122 self.addCurrentServiceToBouquet(bouquets[0][1])
123 else: #no bouquets in root.. so assume only one favourite list is used
124 self.addCurrentServiceToBouquet(self.csel.bouquet_root)
126 def bouquetSelClosed(self, recursive):
130 def copyCurrentToBouquetList(self):
131 self.csel.copyCurrentToBouquetList()
134 def removeBouquet(self):
135 self.csel.removeBouquet()
138 def addCurrentServiceToBouquet(self, dest):
139 self.csel.addCurrentServiceToBouquet(dest)
140 self.close(True) # close bouquet selection
142 def removeCurrentService(self):
143 self.csel.removeCurrentService()
146 def toggleMoveMode(self):
147 self.csel.toggleMoveMode()
150 def bouquetMarkStart(self):
151 self.csel.startMarkedEdit()
154 def bouquetMarkEnd(self):
155 self.csel.endMarkedEdit(abort=False)
158 def bouquetMarkAbort(self):
159 self.csel.endMarkedEdit(abort=True)
162 class ChannelSelectionEPG:
164 self["ChannelSelectEPGActions"] = ActionMap(["ChannelSelectEPGActions"],
166 "showEPGList": self.showEPGList,
169 def showEPGList(self):
170 ref=self.getCurrentSelection()
171 ptr=eEPGCache.getInstance()
172 if ptr.startTimeQuery(ref) != -1:
173 self.session.open(EPGSelection, ref)
175 print 'no epg for service', ref.toString()
177 class ChannelSelectionEdit:
179 self.entry_marked = False
180 self.movemode = False
181 self.bouquet_mark_edit = False
182 self.mutableList = None
184 self.saved_title = None
185 self.saved_root = None
187 class ChannelSelectionEditActionMap(ActionMap):
188 def __init__(self, csel, contexts = [ ], actions = { }, prio=0):
189 ActionMap.__init__(self, contexts, actions, prio)
192 def action(self, contexts, action):
193 if action == "cancel":
194 self.csel.handleEditCancel()
195 return 0 # fall-trough
197 return 0 # fall-trough
199 return ActionMap.action(self, contexts, action)
201 self["ChannelSelectEditActions"] = ChannelSelectionEditActionMap(self, ["ChannelSelectEditActions", "OkCancelActions"],
203 "contextMenu": self.doContext,
206 def getMutableList(self, root=eServiceReference()):
207 if not self.mutableList is None:
208 return self.mutableList
209 serviceHandler = eServiceCenter.getInstance()
212 list = serviceHandler.list(root)
214 return list.startEdit()
217 def buildBouquetID(self, str):
221 if (c >= 'a' and c <= 'z') or (c >= '0' and c <= '9'):
227 def addBouquet(self, providerName):
228 serviceHandler = eServiceCenter.getInstance()
229 mutableBouquetList = serviceHandler.list(self.bouquet_root).startEdit()
230 if mutableBouquetList:
231 if self.mode == MODE_TV:
232 providerName += " (TV)"
233 str = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET \"userbouquet.%s.tv\" ORDER BY bouquet'%(self.buildBouquetID(providerName))
235 providerName += " (Radio)"
236 str = '1:7:2:0:0:0:0:0:0:0:(type == 2) FROM BOUQUET \"userbouquet.%s.radio\" ORDER BY bouquet'%(self.buildBouquetID(providerName))
237 new_bouquet_ref = eServiceReference(str)
238 if not mutableBouquetList.addService(new_bouquet_ref):
239 self.bouquetNumOffsetCache = { }
240 mutableBouquetList.flushChanges()
241 eDVBDB.getInstance().reloadBouquets()
242 mutableBouquet = serviceHandler.list(new_bouquet_ref).startEdit()
244 mutableBouquet.setListName(providerName)
245 mutableBouquet.flushChanges()
246 self.setRoot(self.getRoot())
248 print "get mutable list for new created bouquet failed"
250 print "add", str, "to bouquets failed"
252 print "bouquetlist is not editable"
254 def copyCurrentToBouquetList(self):
255 provider = ServiceReference(self.getCurrentSelection())
256 serviceHandler = eServiceCenter.getInstance()
257 mutableBouquetList = serviceHandler.list(self.bouquet_root).startEdit()
258 if mutableBouquetList:
259 providerName = provider.getServiceName()
260 if self.mode == MODE_TV:
261 str = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET \"userbouquet.%s.tv\" ORDER BY bouquet'%(self.buildBouquetID(providerName))
263 str = '1:7:2:0:0:0:0:0:0:0:(type == 2) FROM BOUQUET \"userbouquet.%s.radio\" ORDER BY bouquet'%(self.buildBouquetID(providerName))
264 new_bouquet_ref = eServiceReference(str)
265 if not mutableBouquetList.addService(new_bouquet_ref):
266 self.bouquetNumOffsetCache = { }
267 mutableBouquetList.flushChanges()
268 eDVBDB.getInstance().reloadBouquets()
269 mutableBouquet = serviceHandler.list(new_bouquet_ref).startEdit()
271 mutableBouquet.setListName(providerName)
273 services = serviceHandler.list(provider.ref)
274 if not services is None:
275 if not services.getContent(list, True):
277 if mutableBouquet.addService(service):
278 print "add", service.toString(), "to new bouquet failed"
279 mutableBouquet.flushChanges()
281 print "getContent failed"
283 print "list provider", providerName, "failed"
285 print "get mutable list for new created bouquet failed"
287 print "add", str, "to bouquets failed"
289 print "bouquetlist is not editable"
291 def removeBouquet(self):
292 refstr = self.getCurrentSelection().toString()
293 self.bouquetNumOffsetCache = { }
294 pos = refstr.find('FROM BOUQUET "')
296 refstr = refstr[pos+14:]
297 pos = refstr.find('"')
299 filename = '/etc/enigma2/' + refstr[:pos] # FIXMEEE !!! HARDCODED /etc/enigma2
300 self.removeCurrentService()
304 print "error during remove of", filename
305 eDVBDB.getInstance().reloadBouquets()
307 # multiple marked entry stuff ( edit mode, later multiepg selection )
308 def startMarkedEdit(self):
309 self.mutableList = self.getMutableList()
310 # add all services from the current list to internal marked set in listboxservicecontent
311 self.clearMarks() # this clears the internal marked set in the listboxservicecontent
312 self.saved_title = self.instance.getTitle()
313 pos = self.saved_title.find(')')
314 new_title = self.saved_title[:pos+1]
315 if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1:
316 new_title += ' ' + _("[bouquet edit]")
318 new_title += ' ' + _("[favourite edit]")
319 self.setTitle(new_title)
320 self.bouquet_mark_edit = True
321 self.__marked = self.servicelist.getRootServices()
322 for x in self.__marked:
323 self.servicelist.addMarked(eServiceReference(x))
324 self.savedPath = self.servicePath[:]
325 self.showAllServices()
327 def endMarkedEdit(self, abort):
328 if not abort and self.mutableList is not None:
329 self.bouquetNumOffsetCache = { }
330 new_marked = set(self.servicelist.getMarked())
331 old_marked = set(self.__marked)
332 removed = old_marked - new_marked
333 added = new_marked - old_marked
337 self.mutableList.removeService(eServiceReference(x))
340 self.mutableList.addService(eServiceReference(x))
342 self.mutableList.flushChanges()
345 self.bouquet_mark_edit = False
346 self.mutableList = None
347 self.setTitle(self.saved_title)
348 self.saved_title = None
349 # self.servicePath is just a reference to servicePathTv or Radio...
350 # so we never ever do use the asignment operator in self.servicePath
351 del self.servicePath[:] # remove all elements
352 self.servicePath += self.savedPath # add saved elements
354 self.setRoot(self.servicePath[len(self.servicePath)-1])
356 def clearMarks(self):
357 self.servicelist.clearMarks()
360 ref = self.servicelist.getCurrent()
361 if self.servicelist.isMarked(ref):
362 self.servicelist.removeMarked(ref)
364 self.servicelist.addMarked(ref)
366 def removeCurrentService(self):
367 ref = self.servicelist.getCurrent()
368 mutableList = self.getMutableList()
369 if ref.valid() and mutableList is not None:
370 if not mutableList.removeService(ref):
371 self.bouquetNumOffsetCache = { }
372 mutableList.flushChanges() #FIXME dont flush on each single removed service
373 self.setRoot(self.getRoot())
375 def addCurrentServiceToBouquet(self, dest):
376 mutableList = self.getMutableList(dest)
377 if not mutableList is None:
378 if not mutableList.addService(self.servicelist.getCurrent()):
379 self.bouquetNumOffsetCache = { }
380 mutableList.flushChanges()
382 def toggleMoveMode(self):
384 if self.entry_marked:
385 self.toggleMoveMarked() # unmark current entry
386 self.movemode = False
387 self.pathChangedDisabled = False # re-enable path change
388 self.mutableList.flushChanges() # FIXME add check if changes was made
389 self.mutableList = None
390 self.setTitle(self.saved_title)
391 self.saved_title = None
392 if self.getRoot() == self.bouquet_root:
393 self.bouquetNumOffsetCache = { }
395 self.mutableList = self.getMutableList()
397 self.pathChangedDisabled = True # no path change allowed in movemode
398 self.saved_title = self.instance.getTitle()
399 new_title = self.saved_title
400 pos = self.saved_title.find(')')
401 new_title = self.saved_title[:pos+1] + ' ' + _("[move mode]") + self.saved_title[pos+1:]
402 self.setTitle(new_title);
404 def handleEditCancel(self):
405 if self.movemode: #movemode active?
406 self.channelSelected() # unmark
407 self.toggleMoveMode() # disable move mode
408 elif self.bouquet_mark_edit:
409 self.endMarkedEdit(True) # abort edit mode
411 def toggleMoveMarked(self):
412 if self.entry_marked:
413 self.servicelist.setCurrentMarked(False)
414 self.entry_marked = False
416 self.servicelist.setCurrentMarked(True)
417 self.entry_marked = True
420 self.session.open(ChannelContextMenu, self)
425 class ChannelSelectionBase(Screen):
426 def __init__(self, session):
427 Screen.__init__(self, session)
429 # this makes it much simple to implement a selectable radio or tv mode :)
430 self.service_types_tv = '1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17)'
431 self.service_types_radio = '1:7:2:0:0:0:0:0:0:0:(type == 2)'
433 self["key_red"] = Button(_("All"))
434 self["key_green"] = Button(_("Satellites"))
435 self["key_yellow"] = Button(_("Provider"))
436 self["key_blue"] = Button(_("Favourites"))
438 self["list"] = ServiceList()
439 self.servicelist = self["list"]
441 self.numericalTextInput = NumericalTextInput()
443 self.servicePathTV = [ ]
444 self.servicePathRadio = [ ]
445 self.servicePath = [ ]
449 self.pathChangedDisabled = False
451 self.bouquetNumOffsetCache = { }
453 self["ChannelSelectBaseActions"] = NumberActionMap(["ChannelSelectBaseActions", "NumberActions"],
455 "showFavourites": self.showFavourites,
456 "showAllServices": self.showAllServices,
457 "showProviders": self.showProviders,
458 "showSatellites": self.showSatellites,
459 "nextBouquet": self.nextBouquet,
460 "prevBouquet": self.prevBouquet,
461 "1": self.keyNumberGlobal,
462 "2": self.keyNumberGlobal,
463 "3": self.keyNumberGlobal,
464 "4": self.keyNumberGlobal,
465 "5": self.keyNumberGlobal,
466 "6": self.keyNumberGlobal,
467 "7": self.keyNumberGlobal,
468 "8": self.keyNumberGlobal,
469 "9": self.keyNumberGlobal,
473 def appendDVBTypes(self, ref):
475 pos = path.find(' FROM BOUQUET')
477 return eServiceReference(self.service_types + path[pos:])
480 def getBouquetNumOffset(self, bouquet):
481 if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
483 bouquet = self.appendDVBTypes(bouquet)
485 return self.bouquetNumOffsetCache[bouquet.toString()]
488 serviceHandler = eServiceCenter.getInstance()
489 bouquetlist = serviceHandler.list(self.bouquet_root)
490 if not bouquetlist is None:
492 bouquetIterator = self.appendDVBTypes(bouquetlist.getNext())
493 if not bouquetIterator.valid(): #end of list
495 self.bouquetNumOffsetCache[bouquetIterator.toString()]=offsetCount
496 if ((bouquetIterator.flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory):
498 servicelist = serviceHandler.list(bouquetIterator)
499 if not servicelist is None:
501 serviceIterator = servicelist.getNext()
502 if not serviceIterator.valid(): #check if end of list
504 if serviceIterator.flags: #playable services have no flags
507 return self.bouquetNumOffsetCache.get(bouquet.toString(), offsetCount)
509 def recallBouquetMode(self):
510 if self.mode == MODE_TV:
511 self.service_types = self.service_types_tv
512 if currentConfigSelectionElement(config.usage.multibouquet) == "yes":
513 self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet'
515 self.bouquet_rootstr = '%s FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet'%(self.service_types)
517 self.service_types = self.service_types_radio
518 if currentConfigSelectionElement(config.usage.multibouquet) == "yes":
519 self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.radio" ORDER BY bouquet'
521 self.bouquet_rootstr = '%s FROM BOUQUET "userbouquet.favourites.radio" ORDER BY bouquet'%(self.service_types)
522 self.bouquet_root = eServiceReference(self.bouquet_rootstr)
526 self.servicePath = self.servicePathTV
527 self.recallBouquetMode()
528 title = self.instance.getTitle()
529 pos = title.find(" (")
535 def setRadioMode(self):
536 self.mode = MODE_RADIO
537 self.servicePath = self.servicePathRadio
538 self.recallBouquetMode()
539 title = self.instance.getTitle()
540 pos = title.find(" (")
546 def setRoot(self, root, justSet=False):
547 path = root.getPath()
548 inBouquetRootList = path.find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
549 pos = path.find(' FROM BOUQUET')
550 isBouquet = pos != -1
551 if not inBouquetRootList and isBouquet:
552 self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
553 self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
554 refstr = self.service_types + path[pos:]
555 root = eServiceReference(refstr)
557 self.servicelist.setMode(ServiceList.MODE_NORMAL)
558 self.servicelist.setRoot(root, justSet)
559 self.buildTitleString()
561 def removeModeStr(self, str):
562 if self.mode == MODE_TV:
563 pos = str.find(' (TV)')
565 pos = str.find(' (Radio)')
570 def getServiceName(self, ref):
571 str = self.removeModeStr(ServiceReference(ref).getServiceName())
573 pathstr = ref.getPath()
574 if pathstr.find('FROM PROVIDERS') != -1:
576 if pathstr.find('FROM SATELLITES') != -1:
577 return _("Satellites")
578 if pathstr.find(') ORDER BY name') != -1:
582 def buildTitleString(self):
583 titleStr = self.instance.getTitle()
584 pos = titleStr.find(']')
586 pos = titleStr.find(')')
588 titleStr = titleStr[:pos+1]
589 Len = len(self.servicePath)
591 base_ref = self.servicePath[0]
593 end_ref = self.servicePath[Len-1]
596 nameStr = self.getServiceName(base_ref)
597 titleStr += ' ' + nameStr
598 if end_ref is not None:
603 nameStr = self.getServiceName(end_ref)
605 self.setTitle(titleStr)
608 self.servicelist.moveUp()
611 self.servicelist.moveDown()
614 del self.servicePath[:]
616 def enterPath(self, ref, justSet=False):
617 self.servicePath.append(ref)
618 self.setRoot(ref, justSet)
620 def pathUp(self, justSet=False):
621 prev = self.servicePath.pop()
622 length = len(self.servicePath)
624 current = self.servicePath[length-1]
625 self.setRoot(current, justSet)
627 self.setCurrentSelection(prev)
630 def isBasePathEqual(self, ref):
631 if len(self.servicePath) > 1 and self.servicePath[0] == ref:
635 def isPrevPathEqual(self, ref):
636 length = len(self.servicePath)
637 if length > 1 and self.servicePath[length-2] == ref:
641 def preEnterPath(self, refstr):
644 def showAllServices(self):
645 if not self.pathChangedDisabled:
646 refstr = '%s ORDER BY name'%(self.service_types)
647 if not self.preEnterPath(refstr):
648 ref = eServiceReference(refstr)
649 currentRoot = self.getRoot()
650 if currentRoot is None or currentRoot != ref:
654 def showSatellites(self):
655 if not self.pathChangedDisabled:
656 refstr = '%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types)
657 if not self.preEnterPath(refstr):
658 ref = eServiceReference(refstr)
662 if self.isBasePathEqual(ref):
663 if self.isPrevPathEqual(ref):
665 prev = self.pathUp(justSet)
667 currentRoot = self.getRoot()
668 if currentRoot is None or currentRoot != ref:
671 self.enterPath(ref, True)
673 serviceHandler = eServiceCenter.getInstance()
674 servicelist = serviceHandler.list(ref)
675 if not servicelist is None:
677 service = servicelist.getNext()
678 if not service.valid(): #check if end of list
680 orbpos = service.getData(4) >> 16
681 if service.getPath().find("FROM PROVIDER") != -1:
682 service_name = _("Providers")
684 service_name = _("Services")
686 service_name += str(' - %s'%(nimmanager.getSatDescription(orbpos)))
687 service.setName(service_name) # why we need this cast?
689 if orbpos > 1800: # west
690 orbpos = 3600 - orbpos
694 n = ("%s (%d.%d" + h + ")") % (service_name, orbpos / 10, orbpos % 10)
696 self.servicelist.addService(service)
697 self.servicelist.finishFill()
699 self.setCurrentSelection(prev)
701 def showProviders(self):
702 if not self.pathChangedDisabled:
703 refstr = '%s FROM PROVIDERS ORDER BY name'%(self.service_types)
704 if not self.preEnterPath(refstr):
705 ref = eServiceReference(refstr)
706 if self.isBasePathEqual(ref):
709 currentRoot = self.getRoot()
710 if currentRoot is None or currentRoot != ref:
714 def changeBouquet(self, direction):
715 if not self.pathChangedDisabled:
716 if self.isBasePathEqual(self.bouquet_root):
722 ref = self.getCurrentSelection()
726 return self.isBasePathEqual(self.bouquet_root)
729 return self.servicelist.atBegin()
732 return self.servicelist.atEnd()
734 def nextBouquet(self):
735 self.changeBouquet(+1)
737 def prevBouquet(self):
738 self.changeBouquet(-1)
740 def showFavourites(self):
741 if not self.pathChangedDisabled:
742 if not self.preEnterPath(self.bouquet_rootstr):
743 if self.isBasePathEqual(self.bouquet_root):
746 currentRoot = self.getRoot()
747 if currentRoot is None or currentRoot != self.bouquet_root:
749 self.enterPath(self.bouquet_root)
751 def keyNumberGlobal(self, number):
752 char = self.numericalTextInput.getKey(number)
753 self.servicelist.moveToChar(char)
756 return self.servicelist.getRoot()
758 def getCurrentSelection(self):
759 return self.servicelist.getCurrent()
761 def setCurrentSelection(self, service):
762 servicepath = service.getPath()
763 pos = servicepath.find(" FROM BOUQUET")
765 if self.mode == MODE_TV:
766 servicepath = '(type == 1)' + servicepath[pos:]
768 servicepath = '(type == 2)' + servicepath[pos:]
769 service.setPath(servicepath)
770 self.servicelist.setCurrent(service)
772 def getBouquetList(self):
775 serviceHandler = eServiceCenter.getInstance()
776 list = serviceHandler.list(self.bouquet_root)
782 if ((s.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
783 info = serviceHandler.info(s)
785 bouquets.append((info.getName(s), s))
788 if len(bouquets) == 0 and serviceCount > 0:
789 info = serviceHandler.info(self.bouquet_root)
791 bouquets.append((info.getName(self.bouquet_root), self.bouquet_root))
795 def keyNumber0(self, num):
796 if len(self.servicePath) > 1:
799 self.keyNumberGlobal(num)
802 if len(self.servicePath) > 1:
803 if self.isBasePathEqual(self.bouquet_root):
804 self.showFavourites()
806 ref = eServiceReference('%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types))
807 if self.isBasePathEqual(ref):
808 self.showSatellites()
810 ref = eServiceReference('%s FROM PROVIDERS ORDER BY name'%(self.service_types))
811 if self.isBasePathEqual(ref):
814 self.showAllServices()
818 class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
819 def __init__(self, session):
820 ChannelSelectionBase.__init__(self,session)
821 ChannelSelectionEdit.__init__(self)
822 ChannelSelectionEPG.__init__(self)
824 #config for lastservice
825 config.tv = ConfigSubsection();
826 config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
827 config.tv.lastroot = configElement("config.tv.lastroot", configText, "", 0);
829 self["actions"] = ActionMap(["OkCancelActions"],
831 "cancel": self.cancel,
832 "ok": self.channelSelected,
834 self.onShown.append(self.__onShown)
836 self.lastChannelRootTimer = eTimer()
837 self.lastChannelRootTimer.timeout.get().append(self.__onCreate)
838 self.lastChannelRootTimer.start(100,True)
843 def __onCreate(self):
846 lastservice=eServiceReference(config.tv.lastservice.value)
847 if lastservice.valid():
848 self.setCurrentSelection(lastservice)
852 self.recallBouquetMode()
853 ref = self.session.nav.getCurrentlyPlayingServiceReference()
854 if ref is not None and ref.valid() and ref.getPath() == "":
855 self.servicelist.setPlayableIgnoreService(ref)
857 self.servicelist.setPlayableIgnoreService(eServiceReference())
859 def channelSelected(self):
860 ref = self.getCurrentSelection()
862 self.toggleMoveMarked()
863 elif (ref.flags & 7) == 7:
865 elif self.bouquet_mark_edit:
871 #called from infoBar and channelSelected
873 ref = self.session.nav.getCurrentlyPlayingServiceReference()
874 nref = self.getCurrentSelection()
875 if ref is None or ref != nref:
876 self.session.nav.playService(nref)
879 if self.servicePath is not None:
880 tmp=self.servicePath[:]
883 del self.history[self.history_pos+1:]
886 self.history.append(tmp)
887 hlen = len(self.history)
888 if hlen > HISTORYSIZE:
891 self.history_pos = hlen-1
893 def historyBack(self):
894 hlen = len(self.history)
895 if hlen > 1 and self.history_pos > 0:
896 self.history_pos -= 1
897 self.setHistoryPath()
899 def historyNext(self):
900 hlen = len(self.history)
901 if hlen > 1 and self.history_pos < (hlen-1):
902 self.history_pos += 1
903 self.setHistoryPath()
905 def setHistoryPath(self):
906 path = self.history[self.history_pos][:]
908 del self.servicePath[:]
909 self.servicePath += path
913 if self.getRoot() != root:
915 self.session.nav.playService(ref)
916 self.setCurrentSelection(ref)
921 for i in self.servicePathTV:
924 if len(path) and path != config.tv.lastroot.value:
925 config.tv.lastroot.value = path
926 config.tv.lastroot.save()
928 def restoreRoot(self):
931 tmp = re.findall(config.tv.lastroot.value)
934 self.servicePathTV.append(eServiceReference(i[:len(i)-1]))
937 path = self.servicePathTV.pop()
940 self.showFavourites()
943 def preEnterPath(self, refstr):
944 if len(self.servicePathTV) and self.servicePathTV[0] != eServiceReference(refstr):
945 pathstr = config.tv.lastroot.value
946 if pathstr is not None and pathstr.find(refstr) == 0:
948 lastservice=eServiceReference(config.tv.lastservice.value)
949 if lastservice.valid():
950 self.setCurrentSelection(lastservice)
954 def saveChannel(self):
955 ref = self.session.nav.getCurrentlyPlayingServiceReference()
957 refstr = ref.toString()
960 if refstr != config.tv.lastservice.value:
961 config.tv.lastservice.value = refstr
962 config.tv.lastservice.save()
964 def recallPrevService(self):
965 hlen = len(self.history)
967 if self.history_pos == hlen-1:
968 tmp = self.history[self.history_pos]
969 self.history[self.history_pos] = self.history[self.history_pos-1]
970 self.history[self.history_pos-1] = tmp
972 tmp = self.history[self.history_pos+1]
973 self.history[self.history_pos+1] = self.history[self.history_pos]
974 self.history[self.history_pos] = tmp
975 self.setHistoryPath()
980 lastservice=eServiceReference(config.tv.lastservice.value)
981 if lastservice.valid() and self.getCurrentSelection() != lastservice:
982 self.setCurrentSelection(lastservice)
984 from Screens.InfoBarGenerics import InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord
986 class RadioInfoBar(Screen, InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord):
987 def __init__(self, session):
988 Screen.__init__(self, session)
989 InfoBarEvent.__init__(self)
990 InfoBarServiceName.__init__(self)
991 InfoBarInstantRecord.__init__(self)
992 self["Clock"] = Clock()
994 class ChannelSelectionRadio(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
995 def __init__(self, session):
996 ChannelSelectionBase.__init__(self, session)
997 ChannelSelectionEdit.__init__(self)
998 ChannelSelectionEPG.__init__(self)
1000 config.radio = ConfigSubsection();
1001 config.radio.lastservice = configElement("config.radio.lastservice", configText, "", 0);
1002 config.radio.lastroot = configElement("config.radio.lastroot", configText, "", 0);
1003 self.onLayoutFinish.append(self.onCreate)
1005 self.info = session.instantiateDialog(RadioInfoBar)
1007 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
1009 "keyTV": self.closeRadio,
1010 "keyRadio": self.closeRadio,
1011 "cancel": self.closeRadio,
1012 "ok": self.channelSelected,
1017 for i in self.servicePathRadio:
1018 path += i.toString()
1020 if len(path) and path != config.radio.lastroot.value:
1021 config.radio.lastroot.value = path
1022 config.radio.lastroot.save()
1024 def restoreRoot(self):
1026 re = compile('.+?;')
1027 tmp = re.findall(config.radio.lastroot.value)
1030 self.servicePathRadio.append(eServiceReference(i[:len(i)-1]))
1033 path = self.servicePathRadio.pop()
1034 self.enterPath(path)
1036 self.showFavourites()
1039 def preEnterPath(self, refstr):
1040 if len(self.servicePathRadio) and self.servicePathRadio[0] != eServiceReference(refstr):
1041 pathstr = config.radio.lastroot.value
1042 if pathstr is not None and pathstr.find(refstr) == 0:
1044 lastservice=eServiceReference(config.radio.lastservice.value)
1045 if lastservice.valid():
1046 self.setCurrentSelection(lastservice)
1053 lastservice=eServiceReference(config.radio.lastservice.value)
1054 if lastservice.valid():
1055 self.servicelist.setCurrent(lastservice)
1056 self.session.nav.playService(lastservice)
1057 self.servicelist.setPlayableIgnoreService(lastservice)
1060 def channelSelected(self): # just return selected service
1061 ref = self.getCurrentSelection()
1063 self.toggleMoveMarked()
1064 elif (ref.flags & 7) == 7:
1066 elif self.bouquet_mark_edit:
1069 playingref = self.session.nav.getCurrentlyPlayingServiceReference()
1070 if playingref is None or playingref != ref:
1071 self.session.nav.playService(ref)
1072 self.servicelist.setPlayableIgnoreService(ref)
1073 config.radio.lastservice.value = ref.toString()
1074 config.radio.lastservice.save()
1077 def closeRadio(self):
1079 #set previous tv service
1080 lastservice=eServiceReference(config.tv.lastservice.value)
1081 self.session.nav.playService(lastservice)
1084 class SimpleChannelSelection(ChannelSelectionBase):
1085 def __init__(self, session, title):
1086 ChannelSelectionBase.__init__(self, session)
1088 self.onShown.append(self.__onExecCallback)
1090 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
1092 "cancel": self.close,
1093 "ok": self.channelSelected,
1094 "keyRadio": self.setModeRadio,
1095 "keyTV": self.setModeTv,
1098 def __onExecCallback(self):
1099 self.setTitle(self.title)
1102 def channelSelected(self): # just return selected service
1103 ref = self.getCurrentSelection()
1104 if (ref.flags & 7) == 7:
1107 ref = self.getCurrentSelection()
1110 def setModeTv(self):
1112 self.showFavourites()
1114 def setModeRadio(self):
1116 self.showFavourites()