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 FLAG_SERVICE_NEW_FOUND = 64 #define in lib/dvb/idvb.h as dxNewFound = 64
23 import xml.dom.minidom
25 class BouquetSelector(Screen):
26 def __init__(self, session, bouquets, selectedFunc, enableWrapAround=False):
27 Screen.__init__(self, session)
29 self.selectedFunc=selectedFunc
31 self["actions"] = ActionMap(["OkCancelActions"],
33 "ok": self.okbuttonClick,
34 "cancel": self.cancelClick
38 entrys.append((x[0], x[1]))
39 self["menu"] = MenuList(entrys, enableWrapAround)
42 cur = self["menu"].getCurrent()
45 def okbuttonClick(self):
46 self.selectedFunc(self.getCurrent())
54 def cancelClick(self):
57 class ChannelContextMenu(Screen):
58 def __init__(self, session, csel):
59 Screen.__init__(self, session)
63 self["actions"] = ActionMap(["OkCancelActions"],
65 "ok": self.okbuttonClick,
66 "cancel": self.cancelClick
70 current_root = csel.getRoot()
71 current_sel_path = csel.getCurrentSelection().getPath()
72 current_sel_flags = csel.getCurrentSelection().flags
73 inBouquetRootList = current_root and current_root.getPath().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
74 inBouquet = csel.getMutableList() is not None
75 haveBouquets = csel.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1
77 if not csel.bouquet_mark_edit and not csel.movemode:
78 if not inBouquetRootList:
79 if (csel.getCurrentSelection().flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory:
81 menu.append((_("add service to bouquet"), self.addServiceToBouquetSelected))
83 menu.append((_("add service to favourites"), self.addServiceToBouquetSelected))
86 if not inBouquet and current_sel_path.find("PROVIDERS") == -1:
87 menu.append((_("copy to favourites"), self.copyCurrentToBouquetList))
88 if current_sel_path.find("flags == %d" %(FLAG_SERVICE_NEW_FOUND)) != -1:
89 menu.append((_("remove all new found flags"), self.removeAllNewFoundFlags))
91 menu.append((_("remove service"), self.removeCurrentService))
92 if current_root.getPath().find("flags == %d" %(FLAG_SERVICE_NEW_FOUND)) != -1:
93 menu.append((_("remove new found flag"), self.removeNewFoundFlag))
95 menu.append((_("remove bouquet"), self.removeBouquet))
97 if inBouquet: # current list is editable?
98 if not csel.bouquet_mark_edit:
100 menu.append((_("enable move mode"), self.toggleMoveMode))
101 menu.append((_("add bouquet..."), self.showBouquetInputBox))
102 if not inBouquetRootList:
104 menu.append((_("enable bouquet edit"), self.bouquetMarkStart))
106 menu.append((_("enable favourite edit"), self.bouquetMarkStart))
108 menu.append((_("disable move mode"), self.toggleMoveMode))
109 elif not inBouquetRootList:
111 menu.append((_("end bouquet edit"), self.bouquetMarkEnd))
112 menu.append((_("abort bouquet edit"), self.bouquetMarkAbort))
114 menu.append((_("end favourites edit"), self.bouquetMarkEnd))
115 menu.append((_("abort favourites edit"), self.bouquetMarkAbort))
117 menu.append((_("back"), self.cancelClick))
118 self["menu"] = MenuList(menu)
120 def okbuttonClick(self):
121 self["menu"].getCurrent()[1]()
123 def cancelClick(self):
126 def showBouquetInputBox(self):
127 self.session.openWithCallback(self.bouquetInputCallback, InputBox, title=_("Please enter a name for the new bouquet"), text="bouquetname", maxSize=False, type=Input.TEXT)
129 def bouquetInputCallback(self, bouquet):
130 if bouquet is not None:
131 self.csel.addBouquet(bouquet, True)
133 def addServiceToBouquetSelected(self):
134 bouquets = self.csel.getBouquetList()
139 if cnt > 1: # show bouquet list
140 self.bsel = self.session.openWithCallback(self.bouquetSelClosed, BouquetSelector, bouquets, self.addCurrentServiceToBouquet)
141 elif cnt == 1: # add to only one existing bouquet
142 self.addCurrentServiceToBouquet(bouquets[0][1])
143 else: #no bouquets in root.. so assume only one favourite list is used
144 self.addCurrentServiceToBouquet(self.csel.bouquet_root)
146 def bouquetSelClosed(self, recursive):
151 def copyCurrentToBouquetList(self):
152 self.csel.copyCurrentToBouquetList()
155 def removeBouquet(self):
156 self.csel.removeBouquet()
159 def addCurrentServiceToBouquet(self, dest):
160 self.csel.addCurrentServiceToBouquet(dest)
161 if self.bsel is not None:
162 self.bsel.close(True)
164 self.close(True) # close bouquet selection
166 def removeCurrentService(self):
167 self.csel.removeCurrentService()
170 def toggleMoveMode(self):
171 self.csel.toggleMoveMode()
174 def bouquetMarkStart(self):
175 self.csel.startMarkedEdit()
178 def bouquetMarkEnd(self):
179 self.csel.endMarkedEdit(abort=False)
182 def bouquetMarkAbort(self):
183 self.csel.endMarkedEdit(abort=True)
186 def removeNewFoundFlag(self):
187 eDVBDB.getInstance().removeFlag(self.csel.getCurrentSelection(), FLAG_SERVICE_NEW_FOUND)
190 def removeAllNewFoundFlags(self):
191 curpath = self.csel.getCurrentSelection().getPath()
192 idx = curpath.find("satellitePosition == ")
194 tmp = curpath[idx+21:]
197 satpos = int(tmp[:idx])
198 eDVBDB.getInstance().removeFlags(FLAG_SERVICE_NEW_FOUND, -1, -1, -1, satpos)
201 class ChannelSelectionEPG:
203 self["ChannelSelectEPGActions"] = ActionMap(["ChannelSelectEPGActions"],
205 "showEPGList": self.showEPGList,
208 def showEPGList(self):
209 ref=self.getCurrentSelection()
210 ptr=eEPGCache.getInstance()
211 if ptr.startTimeQuery(ref) != -1:
212 self.session.open(EPGSelection, ref)
214 print 'no epg for service', ref.toString()
216 class ChannelSelectionEdit:
218 self.entry_marked = False
219 self.movemode = False
220 self.bouquet_mark_edit = False
221 self.mutableList = None
223 self.saved_title = None
224 self.saved_root = None
226 class ChannelSelectionEditActionMap(ActionMap):
227 def __init__(self, csel, contexts = [ ], actions = { }, prio=0):
228 ActionMap.__init__(self, contexts, actions, prio)
231 def action(self, contexts, action):
232 if action == "cancel":
233 self.csel.handleEditCancel()
234 return 0 # fall-trough
236 return 0 # fall-trough
238 return ActionMap.action(self, contexts, action)
240 self["ChannelSelectEditActions"] = ChannelSelectionEditActionMap(self, ["ChannelSelectEditActions", "OkCancelActions"],
242 "contextMenu": self.doContext,
245 def getMutableList(self, root=eServiceReference()):
246 if not self.mutableList is None:
247 return self.mutableList
248 serviceHandler = eServiceCenter.getInstance()
251 list = root and serviceHandler.list(root)
253 return list.startEdit()
256 def buildBouquetID(self, str):
260 if (c >= 'a' and c <= 'z') or (c >= '0' and c <= '9'):
266 def addBouquet(self, bName, services, refresh=False):
267 serviceHandler = eServiceCenter.getInstance()
268 mutableBouquetList = serviceHandler.list(self.bouquet_root).startEdit()
269 if mutableBouquetList:
270 if self.mode == MODE_TV:
272 str = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET \"userbouquet.%s.tv\" ORDER BY bouquet'%(self.buildBouquetID(bName))
275 str = '1:7:2:0:0:0:0:0:0:0:(type == 2) FROM BOUQUET \"userbouquet.%s.radio\" ORDER BY bouquet'%(self.buildBouquetID(bName))
276 new_bouquet_ref = eServiceReference(str)
277 if not mutableBouquetList.addService(new_bouquet_ref):
278 self.bouquetNumOffsetCache = { }
279 mutableBouquetList.flushChanges()
280 eDVBDB.getInstance().reloadBouquets()
281 mutableBouquet = serviceHandler.list(new_bouquet_ref).startEdit()
283 mutableBouquet.setListName(bName)
284 if services is not None:
285 for service in services:
286 if mutableBouquet.addService(service):
287 print "add", service.toString(), "to new bouquet failed"
288 mutableBouquet.flushChanges()
290 self.setRoot(self.getRoot())
292 print "get mutable list for new created bouquet failed"
294 print "add", str, "to bouquets failed"
296 print "bouquetlist is not editable"
298 def copyCurrentToBouquetList(self):
299 provider = ServiceReference(self.getCurrentSelection())
300 providerName = provider.getServiceName()
301 serviceHandler = eServiceCenter.getInstance()
302 services = serviceHandler.list(provider.ref)
303 self.addBouquet(providerName, services and services.getContent('R', True))
305 def removeBouquet(self):
306 refstr = self.getCurrentSelection().toString()
307 self.bouquetNumOffsetCache = { }
308 pos = refstr.find('FROM BOUQUET "')
310 refstr = refstr[pos+14:]
311 pos = refstr.find('"')
313 filename = '/etc/enigma2/' + refstr[:pos] # FIXMEEE !!! HARDCODED /etc/enigma2
314 self.removeCurrentService()
318 print "error during remove of", filename
319 eDVBDB.getInstance().reloadBouquets()
321 # multiple marked entry stuff ( edit mode, later multiepg selection )
322 def startMarkedEdit(self):
323 self.mutableList = self.getMutableList()
324 # add all services from the current list to internal marked set in listboxservicecontent
325 self.clearMarks() # this clears the internal marked set in the listboxservicecontent
326 self.saved_title = self.instance.getTitle()
327 pos = self.saved_title.find(')')
328 new_title = self.saved_title[:pos+1]
329 if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1:
330 new_title += ' ' + _("[bouquet edit]")
332 new_title += ' ' + _("[favourite edit]")
333 self.setTitle(new_title)
334 self.bouquet_mark_edit = True
335 self.__marked = self.servicelist.getRootServices()
336 for x in self.__marked:
337 self.servicelist.addMarked(eServiceReference(x))
338 self.savedPath = self.servicePath[:]
339 self.showAllServices()
341 def endMarkedEdit(self, abort):
342 if not abort and self.mutableList is not None:
343 self.bouquetNumOffsetCache = { }
344 new_marked = set(self.servicelist.getMarked())
345 old_marked = set(self.__marked)
346 removed = old_marked - new_marked
347 added = new_marked - old_marked
351 self.mutableList.removeService(eServiceReference(x))
354 self.mutableList.addService(eServiceReference(x))
356 self.mutableList.flushChanges()
359 self.bouquet_mark_edit = False
360 self.mutableList = None
361 self.setTitle(self.saved_title)
362 self.saved_title = None
363 # self.servicePath is just a reference to servicePathTv or Radio...
364 # so we never ever do use the asignment operator in self.servicePath
365 del self.servicePath[:] # remove all elements
366 self.servicePath += self.savedPath # add saved elements
368 self.setRoot(self.servicePath[len(self.servicePath)-1])
370 def clearMarks(self):
371 self.servicelist.clearMarks()
374 ref = self.servicelist.getCurrent()
375 if self.servicelist.isMarked(ref):
376 self.servicelist.removeMarked(ref)
378 self.servicelist.addMarked(ref)
380 def removeCurrentService(self):
381 ref = self.servicelist.getCurrent()
382 mutableList = self.getMutableList()
383 if ref.valid() and mutableList is not None:
384 if not mutableList.removeService(ref):
385 self.bouquetNumOffsetCache = { }
386 mutableList.flushChanges() #FIXME dont flush on each single removed service
387 self.setRoot(self.getRoot())
389 def addCurrentServiceToBouquet(self, dest):
390 mutableList = self.getMutableList(dest)
391 if not mutableList is None:
392 if not mutableList.addService(self.servicelist.getCurrent()):
393 self.bouquetNumOffsetCache = { }
394 mutableList.flushChanges()
396 def toggleMoveMode(self):
398 if self.entry_marked:
399 self.toggleMoveMarked() # unmark current entry
400 self.movemode = False
401 self.pathChangedDisabled = False # re-enable path change
402 self.mutableList.flushChanges() # FIXME add check if changes was made
403 self.mutableList = None
404 self.setTitle(self.saved_title)
405 self.saved_title = None
406 if self.getRoot() == self.bouquet_root:
407 self.bouquetNumOffsetCache = { }
409 self.mutableList = self.getMutableList()
411 self.pathChangedDisabled = True # no path change allowed in movemode
412 self.saved_title = self.instance.getTitle()
413 new_title = self.saved_title
414 pos = self.saved_title.find(')')
415 new_title = self.saved_title[:pos+1] + ' ' + _("[move mode]") + self.saved_title[pos+1:]
416 self.setTitle(new_title);
418 def handleEditCancel(self):
419 if self.movemode: #movemode active?
420 self.channelSelected() # unmark
421 self.toggleMoveMode() # disable move mode
422 elif self.bouquet_mark_edit:
423 self.endMarkedEdit(True) # abort edit mode
425 def toggleMoveMarked(self):
426 if self.entry_marked:
427 self.servicelist.setCurrentMarked(False)
428 self.entry_marked = False
430 self.servicelist.setCurrentMarked(True)
431 self.entry_marked = True
434 self.session.open(ChannelContextMenu, self)
439 class ChannelSelectionBase(Screen):
440 def __init__(self, session):
441 Screen.__init__(self, session)
443 # this makes it much simple to implement a selectable radio or tv mode :)
444 self.service_types_tv = '1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17) || (type == 195) || (type == 25)'
445 self.service_types_radio = '1:7:2:0:0:0:0:0:0:0:(type == 2)'
447 self["key_red"] = Button(_("All"))
448 self["key_green"] = Button(_("Satellites"))
449 self["key_yellow"] = Button(_("Provider"))
450 self["key_blue"] = Button(_("Favourites"))
452 self["list"] = ServiceList()
453 self.servicelist = self["list"]
455 self.numericalTextInput = NumericalTextInput()
457 self.servicePathTV = [ ]
458 self.servicePathRadio = [ ]
459 self.servicePath = [ ]
463 self.pathChangedDisabled = False
465 self.bouquetNumOffsetCache = { }
467 self["ChannelSelectBaseActions"] = NumberActionMap(["ChannelSelectBaseActions", "NumberActions"],
469 "showFavourites": self.showFavourites,
470 "showAllServices": self.showAllServices,
471 "showProviders": self.showProviders,
472 "showSatellites": self.showSatellites,
473 "nextBouquet": self.nextBouquet,
474 "prevBouquet": self.prevBouquet,
475 "1": self.keyNumberGlobal,
476 "2": self.keyNumberGlobal,
477 "3": self.keyNumberGlobal,
478 "4": self.keyNumberGlobal,
479 "5": self.keyNumberGlobal,
480 "6": self.keyNumberGlobal,
481 "7": self.keyNumberGlobal,
482 "8": self.keyNumberGlobal,
483 "9": self.keyNumberGlobal,
487 def appendDVBTypes(self, ref):
489 pos = path.find(' FROM BOUQUET')
491 return eServiceReference(self.service_types + path[pos:])
494 def getBouquetNumOffset(self, bouquet):
495 if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
497 bouquet = self.appendDVBTypes(bouquet)
499 return self.bouquetNumOffsetCache[bouquet.toString()]
502 serviceHandler = eServiceCenter.getInstance()
503 bouquetlist = serviceHandler.list(self.bouquet_root)
504 if not bouquetlist is None:
506 bouquetIterator = self.appendDVBTypes(bouquetlist.getNext())
507 if not bouquetIterator.valid(): #end of list
509 self.bouquetNumOffsetCache[bouquetIterator.toString()]=offsetCount
510 if ((bouquetIterator.flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory):
512 servicelist = serviceHandler.list(bouquetIterator)
513 if not servicelist is None:
515 serviceIterator = servicelist.getNext()
516 if not serviceIterator.valid(): #check if end of list
518 if serviceIterator.flags: #playable services have no flags
521 return self.bouquetNumOffsetCache.get(bouquet.toString(), offsetCount)
523 def recallBouquetMode(self):
524 if self.mode == MODE_TV:
525 self.service_types = self.service_types_tv
526 if currentConfigSelectionElement(config.usage.multibouquet) == "yes":
527 self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet'
529 self.bouquet_rootstr = '%s FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet'%(self.service_types)
531 self.service_types = self.service_types_radio
532 if currentConfigSelectionElement(config.usage.multibouquet) == "yes":
533 self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.radio" ORDER BY bouquet'
535 self.bouquet_rootstr = '%s FROM BOUQUET "userbouquet.favourites.radio" ORDER BY bouquet'%(self.service_types)
536 self.bouquet_root = eServiceReference(self.bouquet_rootstr)
540 self.servicePath = self.servicePathTV
541 self.recallBouquetMode()
542 title = self.instance.getTitle()
543 pos = title.find(" (")
549 def setRadioMode(self):
550 self.mode = MODE_RADIO
551 self.servicePath = self.servicePathRadio
552 self.recallBouquetMode()
553 title = self.instance.getTitle()
554 pos = title.find(" (")
560 def setRoot(self, root, justSet=False):
561 path = root.getPath()
562 inBouquetRootList = path.find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
563 pos = path.find(' FROM BOUQUET')
564 isBouquet = pos != -1
565 if not inBouquetRootList and isBouquet:
566 self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
567 self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
568 refstr = self.service_types + path[pos:]
569 root = eServiceReference(refstr)
571 self.servicelist.setMode(ServiceList.MODE_NORMAL)
572 self.servicelist.setRoot(root, justSet)
573 self.buildTitleString()
575 def removeModeStr(self, str):
576 if self.mode == MODE_TV:
577 pos = str.find(' (TV)')
579 pos = str.find(' (Radio)')
584 def getServiceName(self, ref):
585 str = self.removeModeStr(ServiceReference(ref).getServiceName())
587 pathstr = ref.getPath()
588 if pathstr.find('FROM PROVIDERS') != -1:
590 if pathstr.find('FROM SATELLITES') != -1:
591 return _("Satellites")
592 if pathstr.find(') ORDER BY name') != -1:
596 def buildTitleString(self):
597 titleStr = self.instance.getTitle()
598 pos = titleStr.find(']')
600 pos = titleStr.find(')')
602 titleStr = titleStr[:pos+1]
603 Len = len(self.servicePath)
605 base_ref = self.servicePath[0]
607 end_ref = self.servicePath[Len-1]
610 nameStr = self.getServiceName(base_ref)
611 titleStr += ' ' + nameStr
612 if end_ref is not None:
617 nameStr = self.getServiceName(end_ref)
619 self.setTitle(titleStr)
622 self.servicelist.moveUp()
625 self.servicelist.moveDown()
628 del self.servicePath[:]
630 def enterPath(self, ref, justSet=False):
631 self.servicePath.append(ref)
632 self.setRoot(ref, justSet)
634 def pathUp(self, justSet=False):
635 prev = self.servicePath.pop()
636 length = len(self.servicePath)
638 current = self.servicePath[length-1]
639 self.setRoot(current, justSet)
641 self.setCurrentSelection(prev)
644 def isBasePathEqual(self, ref):
645 if len(self.servicePath) > 1 and self.servicePath[0] == ref:
649 def isPrevPathEqual(self, ref):
650 length = len(self.servicePath)
651 if length > 1 and self.servicePath[length-2] == ref:
655 def preEnterPath(self, refstr):
658 def showAllServices(self):
659 if not self.pathChangedDisabled:
660 refstr = '%s ORDER BY name'%(self.service_types)
661 if not self.preEnterPath(refstr):
662 ref = eServiceReference(refstr)
663 currentRoot = self.getRoot()
664 if currentRoot is None or currentRoot != ref:
668 def showSatellites(self):
669 if not self.pathChangedDisabled:
670 refstr = '%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types)
671 if not self.preEnterPath(refstr):
672 ref = eServiceReference(refstr)
676 if self.isBasePathEqual(ref):
677 if self.isPrevPathEqual(ref):
679 prev = self.pathUp(justSet)
681 currentRoot = self.getRoot()
682 if currentRoot is None or currentRoot != ref:
685 self.enterPath(ref, True)
687 serviceHandler = eServiceCenter.getInstance()
688 servicelist = serviceHandler.list(ref)
689 if not servicelist is None:
691 service = servicelist.getNext()
692 if not service.valid(): #check if end of list
694 orbpos = service.getUnsignedData(4) >> 16
695 if service.getPath().find("FROM PROVIDER") != -1:
696 service_name = _("Providers")
697 elif service.getPath().find("flags == %d" %(FLAG_SERVICE_NEW_FOUND)) != -1:
698 service_name = _("New")
700 service_name = _("Services")
702 service_name += str(' - %s'%(nimmanager.getSatDescription(orbpos)))
703 service.setName(service_name) # why we need this cast?
705 if orbpos == 0xFFFF: #Cable
706 n = ("%s (%s)") % (service_name, _("Cable"))
707 elif orbpos == 0xEEEE: #Terrestrial
708 n = ("%s (%s)") % (service_name, _("Terrestrial"))
710 if orbpos > 1800: # west
711 orbpos = 3600 - orbpos
715 n = ("%s (%d.%d" + h + ")") % (service_name, orbpos / 10, orbpos % 10)
717 self.servicelist.addService(service)
718 self.servicelist.finishFill()
720 self.setCurrentSelection(prev)
722 def showProviders(self):
723 if not self.pathChangedDisabled:
724 refstr = '%s FROM PROVIDERS ORDER BY name'%(self.service_types)
725 if not self.preEnterPath(refstr):
726 ref = eServiceReference(refstr)
727 if self.isBasePathEqual(ref):
730 currentRoot = self.getRoot()
731 if currentRoot is None or currentRoot != ref:
735 def changeBouquet(self, direction):
736 if not self.pathChangedDisabled:
737 if self.isBasePathEqual(self.bouquet_root):
743 ref = self.getCurrentSelection()
747 return self.isBasePathEqual(self.bouquet_root)
750 return self.servicelist.atBegin()
753 return self.servicelist.atEnd()
755 def nextBouquet(self):
756 self.changeBouquet(+1)
758 def prevBouquet(self):
759 self.changeBouquet(-1)
761 def showFavourites(self):
762 if not self.pathChangedDisabled:
763 if not self.preEnterPath(self.bouquet_rootstr):
764 if self.isBasePathEqual(self.bouquet_root):
767 currentRoot = self.getRoot()
768 if currentRoot is None or currentRoot != self.bouquet_root:
770 self.enterPath(self.bouquet_root)
772 def keyNumberGlobal(self, number):
773 char = self.numericalTextInput.getKey(number)
774 self.servicelist.moveToChar(char)
777 return self.servicelist.getRoot()
779 def getCurrentSelection(self):
780 return self.servicelist.getCurrent()
782 def setCurrentSelection(self, service):
783 servicepath = service.getPath()
784 pos = servicepath.find(" FROM BOUQUET")
786 if self.mode == MODE_TV:
787 servicepath = '(type == 1)' + servicepath[pos:]
789 servicepath = '(type == 2)' + servicepath[pos:]
790 service.setPath(servicepath)
791 self.servicelist.setCurrent(service)
793 def getBouquetList(self):
796 serviceHandler = eServiceCenter.getInstance()
797 list = serviceHandler.list(self.bouquet_root)
803 if ((s.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
804 info = serviceHandler.info(s)
806 bouquets.append((info.getName(s), s))
809 if len(bouquets) == 0 and serviceCount > 0:
810 info = serviceHandler.info(self.bouquet_root)
812 bouquets.append((info.getName(self.bouquet_root), self.bouquet_root))
816 def keyNumber0(self, num):
817 if len(self.servicePath) > 1:
820 self.keyNumberGlobal(num)
823 if len(self.servicePath) > 1:
824 if self.isBasePathEqual(self.bouquet_root):
825 self.showFavourites()
827 ref = eServiceReference('%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types))
828 if self.isBasePathEqual(ref):
829 self.showSatellites()
831 ref = eServiceReference('%s FROM PROVIDERS ORDER BY name'%(self.service_types))
832 if self.isBasePathEqual(ref):
835 self.showAllServices()
839 class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
840 def __init__(self, session):
841 ChannelSelectionBase.__init__(self,session)
842 ChannelSelectionEdit.__init__(self)
843 ChannelSelectionEPG.__init__(self)
845 #config for lastservice
846 config.tv = ConfigSubsection();
847 config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
848 config.tv.lastroot = configElement("config.tv.lastroot", configText, "", 0);
850 self["actions"] = ActionMap(["OkCancelActions"],
852 "cancel": self.cancel,
853 "ok": self.channelSelected,
855 self.onShown.append(self.__onShown)
857 self.lastChannelRootTimer = eTimer()
858 self.lastChannelRootTimer.timeout.get().append(self.__onCreate)
859 self.lastChannelRootTimer.start(100,True)
864 def __onCreate(self):
867 lastservice=eServiceReference(config.tv.lastservice.value)
868 if lastservice.valid():
869 self.setCurrentSelection(lastservice)
873 self.recallBouquetMode()
874 ref = self.session.nav.getCurrentlyPlayingServiceReference()
875 if ref is not None and ref.valid() and ref.getPath() == "":
876 self.servicelist.setPlayableIgnoreService(ref)
878 self.servicelist.setPlayableIgnoreService(eServiceReference())
880 def channelSelected(self):
881 ref = self.getCurrentSelection()
883 self.toggleMoveMarked()
884 elif (ref.flags & 7) == 7:
886 elif self.bouquet_mark_edit:
892 #called from infoBar and channelSelected
894 ref = self.session.nav.getCurrentlyPlayingServiceReference()
895 nref = self.getCurrentSelection()
896 if ref is None or ref != nref:
897 self.session.nav.playService(nref)
900 self.addToHistory(nref)
902 def addToHistory(self, ref):
903 if self.servicePath is not None:
904 tmp=self.servicePath[:]
907 del self.history[self.history_pos+1:]
910 self.history.append(tmp)
911 hlen = len(self.history)
912 if hlen > HISTORYSIZE:
915 self.history_pos = hlen-1
917 def historyBack(self):
918 hlen = len(self.history)
919 if hlen > 1 and self.history_pos > 0:
920 self.history_pos -= 1
921 self.setHistoryPath()
923 def historyNext(self):
924 hlen = len(self.history)
925 if hlen > 1 and self.history_pos < (hlen-1):
926 self.history_pos += 1
927 self.setHistoryPath()
929 def setHistoryPath(self):
930 path = self.history[self.history_pos][:]
932 del self.servicePath[:]
933 self.servicePath += path
937 if self.getRoot() != root:
939 self.session.nav.playService(ref)
940 self.setCurrentSelection(ref)
945 for i in self.servicePathTV:
948 if len(path) and path != config.tv.lastroot.value:
949 config.tv.lastroot.value = path
950 config.tv.lastroot.save()
952 def restoreRoot(self):
955 tmp = re.findall(config.tv.lastroot.value)
958 self.servicePathTV.append(eServiceReference(i[:len(i)-1]))
961 path = self.servicePathTV.pop()
964 self.showFavourites()
967 def preEnterPath(self, refstr):
968 if len(self.servicePathTV) and self.servicePathTV[0] != eServiceReference(refstr):
969 pathstr = config.tv.lastroot.value
970 if pathstr is not None and pathstr.find(refstr) == 0:
972 lastservice=eServiceReference(config.tv.lastservice.value)
973 if lastservice.valid():
974 self.setCurrentSelection(lastservice)
978 def saveChannel(self):
979 ref = self.session.nav.getCurrentlyPlayingServiceReference()
981 refstr = ref.toString()
984 if refstr != config.tv.lastservice.value:
985 config.tv.lastservice.value = refstr
986 config.tv.lastservice.save()
988 def recallPrevService(self):
989 hlen = len(self.history)
991 if self.history_pos == hlen-1:
992 tmp = self.history[self.history_pos]
993 self.history[self.history_pos] = self.history[self.history_pos-1]
994 self.history[self.history_pos-1] = tmp
996 tmp = self.history[self.history_pos+1]
997 self.history[self.history_pos+1] = self.history[self.history_pos]
998 self.history[self.history_pos] = tmp
999 self.setHistoryPath()
1004 lastservice=eServiceReference(config.tv.lastservice.value)
1005 if lastservice.valid() and self.getCurrentSelection() != lastservice:
1006 self.setCurrentSelection(lastservice)
1008 from Screens.InfoBarGenerics import InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord
1010 class RadioInfoBar(Screen, InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord):
1011 def __init__(self, session):
1012 Screen.__init__(self, session)
1013 InfoBarEvent.__init__(self)
1014 InfoBarServiceName.__init__(self)
1015 InfoBarInstantRecord.__init__(self)
1016 self["Clock"] = Clock()
1018 class ChannelSelectionRadio(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
1019 def __init__(self, session):
1020 ChannelSelectionBase.__init__(self, session)
1021 ChannelSelectionEdit.__init__(self)
1022 ChannelSelectionEPG.__init__(self)
1024 config.radio = ConfigSubsection();
1025 config.radio.lastservice = configElement("config.radio.lastservice", configText, "", 0);
1026 config.radio.lastroot = configElement("config.radio.lastroot", configText, "", 0);
1027 self.onLayoutFinish.append(self.onCreate)
1029 self.info = session.instantiateDialog(RadioInfoBar)
1031 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
1033 "keyTV": self.closeRadio,
1034 "keyRadio": self.closeRadio,
1035 "cancel": self.closeRadio,
1036 "ok": self.channelSelected,
1041 for i in self.servicePathRadio:
1042 path += i.toString()
1044 if len(path) and path != config.radio.lastroot.value:
1045 config.radio.lastroot.value = path
1046 config.radio.lastroot.save()
1048 def restoreRoot(self):
1050 re = compile('.+?;')
1051 tmp = re.findall(config.radio.lastroot.value)
1054 self.servicePathRadio.append(eServiceReference(i[:len(i)-1]))
1057 path = self.servicePathRadio.pop()
1058 self.enterPath(path)
1060 self.showFavourites()
1063 def preEnterPath(self, refstr):
1064 if len(self.servicePathRadio) and self.servicePathRadio[0] != eServiceReference(refstr):
1065 pathstr = config.radio.lastroot.value
1066 if pathstr is not None and pathstr.find(refstr) == 0:
1068 lastservice=eServiceReference(config.radio.lastservice.value)
1069 if lastservice.valid():
1070 self.setCurrentSelection(lastservice)
1077 lastservice=eServiceReference(config.radio.lastservice.value)
1078 if lastservice.valid():
1079 self.servicelist.setCurrent(lastservice)
1080 self.session.nav.playService(lastservice)
1081 self.servicelist.setPlayableIgnoreService(lastservice)
1084 def channelSelected(self): # just return selected service
1085 ref = self.getCurrentSelection()
1087 self.toggleMoveMarked()
1088 elif (ref.flags & 7) == 7:
1090 elif self.bouquet_mark_edit:
1093 playingref = self.session.nav.getCurrentlyPlayingServiceReference()
1094 if playingref is None or playingref != ref:
1095 self.session.nav.playService(ref)
1096 self.servicelist.setPlayableIgnoreService(ref)
1097 config.radio.lastservice.value = ref.toString()
1098 config.radio.lastservice.save()
1101 def closeRadio(self):
1103 #set previous tv service
1104 lastservice=eServiceReference(config.tv.lastservice.value)
1105 self.session.nav.playService(lastservice)
1108 class SimpleChannelSelection(ChannelSelectionBase):
1109 def __init__(self, session, title):
1110 ChannelSelectionBase.__init__(self, session)
1112 self.onShown.append(self.__onExecCallback)
1114 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
1116 "cancel": self.close,
1117 "ok": self.channelSelected,
1118 "keyRadio": self.setModeRadio,
1119 "keyTV": self.setModeTv,
1122 def __onExecCallback(self):
1123 self.setTitle(self.title)
1126 def channelSelected(self): # just return selected service
1127 ref = self.getCurrentSelection()
1128 if (ref.flags & 7) == 7:
1131 ref = self.getCurrentSelection()
1134 def setModeTv(self):
1136 self.showFavourites()
1138 def setModeRadio(self):
1140 self.showFavourites()