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()
302 eDVBDB.getInstance().reloadBouquets()
304 # multiple marked entry stuff ( edit mode, later multiepg selection )
305 def startMarkedEdit(self):
306 self.mutableList = self.getMutableList()
307 # add all services from the current list to internal marked set in listboxservicecontent
308 self.clearMarks() # this clears the internal marked set in the listboxservicecontent
309 self.saved_title = self.instance.getTitle()
310 pos = self.saved_title.find(')')
311 new_title = self.saved_title[:pos+1]
312 if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1:
313 new_title += ' ' + _("[bouquet edit]")
315 new_title += ' ' + _("[favourite edit]")
316 self.setTitle(new_title)
317 self.bouquet_mark_edit = True
318 self.__marked = self.servicelist.getRootServices()
319 for x in self.__marked:
320 self.servicelist.addMarked(eServiceReference(x))
321 self.savedPath = self.servicePath[:]
322 self.showAllServices()
324 def endMarkedEdit(self, abort):
325 if not abort and self.mutableList is not None:
326 self.bouquetNumOffsetCache = { }
327 new_marked = set(self.servicelist.getMarked())
328 old_marked = set(self.__marked)
329 removed = old_marked - new_marked
330 added = new_marked - old_marked
334 self.mutableList.removeService(eServiceReference(x))
337 self.mutableList.addService(eServiceReference(x))
339 self.mutableList.flushChanges()
342 self.bouquet_mark_edit = False
343 self.mutableList = None
344 self.setTitle(self.saved_title)
345 self.saved_title = None
346 # self.servicePath is just a reference to servicePathTv or Radio...
347 # so we never ever do use the asignment operator in self.servicePath
348 del self.servicePath[:] # remove all elements
349 self.servicePath += self.savedPath # add saved elements
351 self.setRoot(self.servicePath[len(self.servicePath)-1])
353 def clearMarks(self):
354 self.servicelist.clearMarks()
357 ref = self.servicelist.getCurrent()
358 if self.servicelist.isMarked(ref):
359 self.servicelist.removeMarked(ref)
361 self.servicelist.addMarked(ref)
363 def removeCurrentService(self):
364 ref = self.servicelist.getCurrent()
365 mutableList = self.getMutableList()
366 if ref.valid() and mutableList is not None:
367 if not mutableList.removeService(ref):
368 self.bouquetNumOffsetCache = { }
369 mutableList.flushChanges() #FIXME dont flush on each single removed service
370 self.setRoot(self.getRoot())
372 def addCurrentServiceToBouquet(self, dest):
373 mutableList = self.getMutableList(dest)
374 if not mutableList is None:
375 if not mutableList.addService(self.servicelist.getCurrent()):
376 self.bouquetNumOffsetCache = { }
377 mutableList.flushChanges()
379 def toggleMoveMode(self):
381 if self.entry_marked:
382 self.toggleMoveMarked() # unmark current entry
383 self.movemode = False
384 self.pathChangedDisabled = False # re-enable path change
385 self.mutableList.flushChanges() # FIXME add check if changes was made
386 self.mutableList = None
387 self.setTitle(self.saved_title)
388 self.saved_title = None
389 if self.getRoot() == self.bouquet_root:
390 self.bouquetNumOffsetCache = { }
392 self.mutableList = self.getMutableList()
394 self.pathChangedDisabled = True # no path change allowed in movemode
395 self.saved_title = self.instance.getTitle()
396 new_title = self.saved_title
397 pos = self.saved_title.find(')')
398 new_title = self.saved_title[:pos+1] + ' ' + _("[move mode]") + self.saved_title[pos+1:]
399 self.setTitle(new_title);
401 def handleEditCancel(self):
402 if self.movemode: #movemode active?
403 self.channelSelected() # unmark
404 self.toggleMoveMode() # disable move mode
405 elif self.bouquet_mark_edit:
406 self.endMarkedEdit(True) # abort edit mode
408 def toggleMoveMarked(self):
409 if self.entry_marked:
410 self.servicelist.setCurrentMarked(False)
411 self.entry_marked = False
413 self.servicelist.setCurrentMarked(True)
414 self.entry_marked = True
417 self.session.open(ChannelContextMenu, self)
422 class ChannelSelectionBase(Screen):
423 def __init__(self, session):
424 Screen.__init__(self, session)
426 # this makes it much simple to implement a selectable radio or tv mode :)
427 self.service_types_tv = '1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17)'
428 self.service_types_radio = '1:7:2:0:0:0:0:0:0:0:(type == 2)'
430 self["key_red"] = Button(_("All"))
431 self["key_green"] = Button(_("Satellites"))
432 self["key_yellow"] = Button(_("Provider"))
433 self["key_blue"] = Button(_("Favourites"))
435 self["list"] = ServiceList()
436 self.servicelist = self["list"]
438 self.numericalTextInput = NumericalTextInput()
440 self.servicePathTV = [ ]
441 self.servicePathRadio = [ ]
442 self.servicePath = [ ]
446 self.pathChangedDisabled = False
448 self.bouquetNumOffsetCache = { }
450 self["ChannelSelectBaseActions"] = NumberActionMap(["ChannelSelectBaseActions", "NumberActions"],
452 "showFavourites": self.showFavourites,
453 "showAllServices": self.showAllServices,
454 "showProviders": self.showProviders,
455 "showSatellites": self.showSatellites,
456 "nextBouquet": self.nextBouquet,
457 "prevBouquet": self.prevBouquet,
458 "1": self.keyNumberGlobal,
459 "2": self.keyNumberGlobal,
460 "3": self.keyNumberGlobal,
461 "4": self.keyNumberGlobal,
462 "5": self.keyNumberGlobal,
463 "6": self.keyNumberGlobal,
464 "7": self.keyNumberGlobal,
465 "8": self.keyNumberGlobal,
466 "9": self.keyNumberGlobal,
470 def appendDVBTypes(self, ref):
472 pos = path.find(' FROM BOUQUET')
474 return eServiceReference(self.service_types + path[pos:])
477 def getBouquetNumOffset(self, bouquet):
478 if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
480 bouquet = self.appendDVBTypes(bouquet)
482 return self.bouquetNumOffsetCache[bouquet.toString()]
485 serviceHandler = eServiceCenter.getInstance()
486 bouquetlist = serviceHandler.list(self.bouquet_root)
487 if not bouquetlist is None:
489 bouquetIterator = self.appendDVBTypes(bouquetlist.getNext())
490 if not bouquetIterator.valid(): #end of list
492 self.bouquetNumOffsetCache[bouquetIterator.toString()]=offsetCount
493 if ((bouquetIterator.flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory):
495 servicelist = serviceHandler.list(bouquetIterator)
496 if not servicelist is None:
498 serviceIterator = servicelist.getNext()
499 if not serviceIterator.valid(): #check if end of list
501 if serviceIterator.flags: #playable services have no flags
504 return self.bouquetNumOffsetCache.get(bouquet.toString(), offsetCount)
506 def recallBouquetMode(self):
507 if self.mode == MODE_TV:
508 self.service_types = self.service_types_tv
509 if currentConfigSelectionElement(config.usage.multibouquet) == "yes":
510 self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet'
512 self.bouquet_rootstr = '%s FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet'%(self.service_types)
514 self.service_types = self.service_types_radio
515 if currentConfigSelectionElement(config.usage.multibouquet) == "yes":
516 self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.radio" ORDER BY bouquet'
518 self.bouquet_rootstr = '%s FROM BOUQUET "userbouquet.favourites.radio" ORDER BY bouquet'%(self.service_types)
519 self.bouquet_root = eServiceReference(self.bouquet_rootstr)
523 self.servicePath = self.servicePathTV
524 self.recallBouquetMode()
525 title = self.instance.getTitle()
526 pos = title.find(" (")
532 def setRadioMode(self):
533 self.mode = MODE_RADIO
534 self.servicePath = self.servicePathRadio
535 self.recallBouquetMode()
536 title = self.instance.getTitle()
537 pos = title.find(" (")
543 def setRoot(self, root, justSet=False):
544 path = root.getPath()
545 inBouquetRootList = path.find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
546 pos = path.find(' FROM BOUQUET')
547 isBouquet = pos != -1
548 if not inBouquetRootList and isBouquet:
549 self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
550 self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
551 refstr = self.service_types + path[pos:]
552 root = eServiceReference(refstr)
554 self.servicelist.setMode(ServiceList.MODE_NORMAL)
555 self.servicelist.setRoot(root, justSet)
556 self.buildTitleString()
558 def removeModeStr(self, str):
559 if self.mode == MODE_TV:
560 pos = str.find(' (TV)')
562 pos = str.find(' (Radio)')
567 def getServiceName(self, ref):
568 str = self.removeModeStr(ServiceReference(ref).getServiceName())
570 pathstr = ref.getPath()
571 if pathstr.find('FROM PROVIDERS') != -1:
573 if pathstr.find('FROM SATELLITES') != -1:
574 return _("Satellites")
575 if pathstr.find(') ORDER BY name') != -1:
579 def buildTitleString(self):
580 titleStr = self.instance.getTitle()
581 pos = titleStr.find(']')
583 pos = titleStr.find(')')
585 titleStr = titleStr[:pos+1]
586 Len = len(self.servicePath)
588 base_ref = self.servicePath[0]
590 end_ref = self.servicePath[Len-1]
593 nameStr = self.getServiceName(base_ref)
594 titleStr += ' ' + nameStr
595 if end_ref is not None:
600 nameStr = self.getServiceName(end_ref)
602 self.setTitle(titleStr)
605 self.servicelist.moveUp()
608 self.servicelist.moveDown()
611 del self.servicePath[:]
613 def enterPath(self, ref, justSet=False):
614 self.servicePath.append(ref)
615 self.setRoot(ref, justSet)
617 def pathUp(self, justSet=False):
618 prev = self.servicePath.pop()
619 length = len(self.servicePath)
621 current = self.servicePath[length-1]
622 self.setRoot(current, justSet)
624 self.setCurrentSelection(prev)
627 def isBasePathEqual(self, ref):
628 if len(self.servicePath) > 1 and self.servicePath[0] == ref:
632 def isPrevPathEqual(self, ref):
633 length = len(self.servicePath)
634 if length > 1 and self.servicePath[length-2] == ref:
638 def preEnterPath(self, refstr):
641 def showAllServices(self):
642 if not self.pathChangedDisabled:
643 refstr = '%s ORDER BY name'%(self.service_types)
644 if not self.preEnterPath(refstr):
645 ref = eServiceReference(refstr)
646 currentRoot = self.getRoot()
647 if currentRoot is None or currentRoot != ref:
651 def showSatellites(self):
652 if not self.pathChangedDisabled:
653 refstr = '%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types)
654 if not self.preEnterPath(refstr):
655 ref = eServiceReference(refstr)
659 if self.isBasePathEqual(ref):
660 if self.isPrevPathEqual(ref):
662 prev = self.pathUp(justSet)
664 currentRoot = self.getRoot()
665 if currentRoot is None or currentRoot != ref:
668 self.enterPath(ref, True)
670 serviceHandler = eServiceCenter.getInstance()
671 servicelist = serviceHandler.list(ref)
672 if not servicelist is None:
674 service = servicelist.getNext()
675 if not service.valid(): #check if end of list
677 orbpos = service.getData(4) >> 16
678 if service.getPath().find("FROM PROVIDER") != -1:
679 service_name = _("Providers")
681 service_name = _("Services")
683 service_name += str(' - %s'%(nimmanager.getSatDescription(orbpos)))
684 service.setName(service_name) # why we need this cast?
686 if orbpos > 1800: # west
687 orbpos = 3600 - orbpos
691 n = ("%s (%d.%d" + h + ")") % (service_name, orbpos / 10, orbpos % 10)
693 self.servicelist.addService(service)
694 self.servicelist.finishFill()
696 self.setCurrentSelection(prev)
698 def showProviders(self):
699 if not self.pathChangedDisabled:
700 refstr = '%s FROM PROVIDERS ORDER BY name'%(self.service_types)
701 if not self.preEnterPath(refstr):
702 ref = eServiceReference(refstr)
703 if self.isBasePathEqual(ref):
706 currentRoot = self.getRoot()
707 if currentRoot is None or currentRoot != ref:
711 def changeBouquet(self, direction):
712 if not self.pathChangedDisabled:
713 if self.isBasePathEqual(self.bouquet_root):
719 ref = self.getCurrentSelection()
723 return self.isBasePathEqual(self.bouquet_root)
726 return self.servicelist.atBegin()
729 return self.servicelist.atEnd()
731 def nextBouquet(self):
732 self.changeBouquet(+1)
734 def prevBouquet(self):
735 self.changeBouquet(-1)
737 def showFavourites(self):
738 if not self.pathChangedDisabled:
739 if not self.preEnterPath(self.bouquet_rootstr):
740 if self.isBasePathEqual(self.bouquet_root):
743 currentRoot = self.getRoot()
744 if currentRoot is None or currentRoot != self.bouquet_root:
746 self.enterPath(self.bouquet_root)
748 def keyNumberGlobal(self, number):
749 char = self.numericalTextInput.getKey(number)
750 self.servicelist.moveToChar(char)
753 return self.servicelist.getRoot()
755 def getCurrentSelection(self):
756 return self.servicelist.getCurrent()
758 def setCurrentSelection(self, service):
759 servicepath = service.getPath()
760 pos = servicepath.find(" FROM BOUQUET")
762 if self.mode == MODE_TV:
763 servicepath = '(type == 1)' + servicepath[pos:]
765 servicepath = '(type == 2)' + servicepath[pos:]
766 service.setPath(servicepath)
767 self.servicelist.setCurrent(service)
769 def getBouquetList(self):
772 serviceHandler = eServiceCenter.getInstance()
773 list = serviceHandler.list(self.bouquet_root)
779 if ((s.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
780 info = serviceHandler.info(s)
782 bouquets.append((info.getName(s), s))
785 if len(bouquets) == 0 and serviceCount > 0:
786 info = serviceHandler.info(self.bouquet_root)
788 bouquets.append((info.getName(self.bouquet_root), self.bouquet_root))
792 def keyNumber0(self, num):
793 if len(self.servicePath) > 1:
796 self.keyNumberGlobal(num)
799 if len(self.servicePath) > 1:
800 if self.isBasePathEqual(self.bouquet_root):
801 self.showFavourites()
803 ref = eServiceReference('%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types))
804 if self.isBasePathEqual(ref):
805 self.showSatellites()
807 ref = eServiceReference('%s FROM PROVIDERS ORDER BY name'%(self.service_types))
808 if self.isBasePathEqual(ref):
811 self.showAllServices()
815 class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
816 def __init__(self, session):
817 ChannelSelectionBase.__init__(self,session)
818 ChannelSelectionEdit.__init__(self)
819 ChannelSelectionEPG.__init__(self)
821 #config for lastservice
822 config.tv = ConfigSubsection();
823 config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
824 config.tv.lastroot = configElement("config.tv.lastroot", configText, "", 0);
826 self["actions"] = ActionMap(["OkCancelActions"],
828 "cancel": self.cancel,
829 "ok": self.channelSelected,
831 self.onShown.append(self.__onShown)
833 self.lastChannelRootTimer = eTimer()
834 self.lastChannelRootTimer.timeout.get().append(self.__onCreate)
835 self.lastChannelRootTimer.start(100,True)
840 def __onCreate(self):
843 lastservice=eServiceReference(config.tv.lastservice.value)
844 if lastservice.valid():
845 self.setCurrentSelection(lastservice)
849 self.recallBouquetMode()
850 ref = self.session.nav.getCurrentlyPlayingServiceReference()
851 if ref is not None and ref.valid() and ref.getPath() == "":
852 self.servicelist.setPlayableIgnoreService(ref)
854 self.servicelist.setPlayableIgnoreService(eServiceReference())
856 def channelSelected(self):
857 ref = self.getCurrentSelection()
859 self.toggleMoveMarked()
860 elif (ref.flags & 7) == 7:
862 elif self.bouquet_mark_edit:
868 #called from infoBar and channelSelected
870 ref = self.session.nav.getCurrentlyPlayingServiceReference()
871 nref = self.getCurrentSelection()
872 if ref is None or ref != nref:
873 self.session.nav.playService(nref)
876 if self.servicePath is not None:
877 tmp=self.servicePath[:]
880 del self.history[self.history_pos+1:]
883 self.history.append(tmp)
884 hlen = len(self.history)
885 if hlen > HISTORYSIZE:
888 self.history_pos = hlen-1
890 def historyBack(self):
891 hlen = len(self.history)
892 if hlen > 1 and self.history_pos > 0:
893 self.history_pos -= 1
894 self.setHistoryPath()
896 def historyNext(self):
897 hlen = len(self.history)
898 if hlen > 1 and self.history_pos < (hlen-1):
899 self.history_pos += 1
900 self.setHistoryPath()
902 def setHistoryPath(self):
903 path = self.history[self.history_pos][:]
905 del self.servicePath[:]
906 self.servicePath += path
910 if self.getRoot() != root:
912 self.session.nav.playService(ref)
913 self.setCurrentSelection(ref)
918 for i in self.servicePathTV:
921 if len(path) and path != config.tv.lastroot.value:
922 config.tv.lastroot.value = path
923 config.tv.lastroot.save()
925 def restoreRoot(self):
928 tmp = re.findall(config.tv.lastroot.value)
931 self.servicePathTV.append(eServiceReference(i[:len(i)-1]))
934 path = self.servicePathTV.pop()
937 self.showFavourites()
940 def preEnterPath(self, refstr):
941 if len(self.servicePathTV) and self.servicePathTV[0] != eServiceReference(refstr):
942 pathstr = config.tv.lastroot.value
943 if pathstr is not None and pathstr.find(refstr) == 0:
945 lastservice=eServiceReference(config.tv.lastservice.value)
946 if lastservice.valid():
947 self.setCurrentSelection(lastservice)
951 def saveChannel(self):
952 ref = self.session.nav.getCurrentlyPlayingServiceReference()
954 refstr = ref.toString()
957 if refstr != config.tv.lastservice.value:
958 config.tv.lastservice.value = refstr
959 config.tv.lastservice.save()
961 def recallPrevService(self):
962 hlen = len(self.history)
964 if self.history_pos == hlen-1:
965 tmp = self.history[self.history_pos]
966 self.history[self.history_pos] = self.history[self.history_pos-1]
967 self.history[self.history_pos-1] = tmp
969 tmp = self.history[self.history_pos+1]
970 self.history[self.history_pos+1] = self.history[self.history_pos]
971 self.history[self.history_pos] = tmp
972 self.setHistoryPath()
977 lastservice=eServiceReference(config.tv.lastservice.value)
978 if lastservice.valid() and self.getCurrentSelection() != lastservice:
979 self.setCurrentSelection(lastservice)
981 from Screens.InfoBarGenerics import InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord
983 class RadioInfoBar(Screen, InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord):
984 def __init__(self, session):
985 Screen.__init__(self, session)
986 InfoBarEvent.__init__(self)
987 InfoBarServiceName.__init__(self)
988 InfoBarInstantRecord.__init__(self)
989 self["Clock"] = Clock()
991 class ChannelSelectionRadio(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
992 def __init__(self, session):
993 ChannelSelectionBase.__init__(self, session)
994 ChannelSelectionEdit.__init__(self)
995 ChannelSelectionEPG.__init__(self)
997 config.radio = ConfigSubsection();
998 config.radio.lastservice = configElement("config.radio.lastservice", configText, "", 0);
999 config.radio.lastroot = configElement("config.radio.lastroot", configText, "", 0);
1000 self.onLayoutFinish.append(self.onCreate)
1002 self.info = session.instantiateDialog(RadioInfoBar)
1004 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
1006 "keyTV": self.closeRadio,
1007 "keyRadio": self.closeRadio,
1008 "cancel": self.closeRadio,
1009 "ok": self.channelSelected,
1014 for i in self.servicePathRadio:
1015 path += i.toString()
1017 if len(path) and path != config.radio.lastroot.value:
1018 config.radio.lastroot.value = path
1019 config.radio.lastroot.save()
1021 def restoreRoot(self):
1023 re = compile('.+?;')
1024 tmp = re.findall(config.radio.lastroot.value)
1027 self.servicePathRadio.append(eServiceReference(i[:len(i)-1]))
1030 path = self.servicePathRadio.pop()
1031 self.enterPath(path)
1033 self.showFavourites()
1036 def preEnterPath(self, refstr):
1037 if len(self.servicePathRadio) and self.servicePathRadio[0] != eServiceReference(refstr):
1038 pathstr = config.radio.lastroot.value
1039 if pathstr is not None and pathstr.find(refstr) == 0:
1041 lastservice=eServiceReference(config.radio.lastservice.value)
1042 if lastservice.valid():
1043 self.setCurrentSelection(lastservice)
1050 lastservice=eServiceReference(config.radio.lastservice.value)
1051 if lastservice.valid():
1052 self.servicelist.setCurrent(lastservice)
1053 self.session.nav.playService(lastservice)
1054 self.servicelist.setPlayableIgnoreService(lastservice)
1057 def channelSelected(self): # just return selected service
1058 ref = self.getCurrentSelection()
1060 self.toggleMoveMarked()
1061 elif (ref.flags & 7) == 7:
1063 elif self.bouquet_mark_edit:
1066 playingref = self.session.nav.getCurrentlyPlayingServiceReference()
1067 if playingref is None or playingref != ref:
1068 self.session.nav.playService(ref)
1069 self.servicelist.setPlayableIgnoreService(ref)
1070 config.radio.lastservice.value = ref.toString()
1071 config.radio.lastservice.save()
1074 def closeRadio(self):
1076 #set previous tv service
1077 lastservice=eServiceReference(config.tv.lastservice.value)
1078 self.session.nav.playService(lastservice)
1081 class SimpleChannelSelection(ChannelSelectionBase):
1082 def __init__(self, session, title):
1083 ChannelSelectionBase.__init__(self, session)
1085 self.onShown.append(self.__onExecCallback)
1087 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
1089 "cancel": self.close,
1090 "ok": self.channelSelected,
1091 "keyRadio": self.setModeRadio,
1092 "keyTV": self.setModeTv,
1095 def __onExecCallback(self):
1096 self.setTitle(self.title)
1099 def channelSelected(self): # just return selected service
1100 ref = self.getCurrentSelection()
1101 if (ref.flags & 7) == 7:
1104 ref = self.getCurrentSelection()
1107 def setModeTv(self):
1109 self.showFavourites()
1111 def setModeRadio(self):
1113 self.showFavourites()