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)'
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 if self.servicePath is not None:
901 tmp=self.servicePath[:]
904 del self.history[self.history_pos+1:]
907 self.history.append(tmp)
908 hlen = len(self.history)
909 if hlen > HISTORYSIZE:
912 self.history_pos = hlen-1
914 def historyBack(self):
915 hlen = len(self.history)
916 if hlen > 1 and self.history_pos > 0:
917 self.history_pos -= 1
918 self.setHistoryPath()
920 def historyNext(self):
921 hlen = len(self.history)
922 if hlen > 1 and self.history_pos < (hlen-1):
923 self.history_pos += 1
924 self.setHistoryPath()
926 def setHistoryPath(self):
927 path = self.history[self.history_pos][:]
929 del self.servicePath[:]
930 self.servicePath += path
934 if self.getRoot() != root:
936 self.session.nav.playService(ref)
937 self.setCurrentSelection(ref)
942 for i in self.servicePathTV:
945 if len(path) and path != config.tv.lastroot.value:
946 config.tv.lastroot.value = path
947 config.tv.lastroot.save()
949 def restoreRoot(self):
952 tmp = re.findall(config.tv.lastroot.value)
955 self.servicePathTV.append(eServiceReference(i[:len(i)-1]))
958 path = self.servicePathTV.pop()
961 self.showFavourites()
964 def preEnterPath(self, refstr):
965 if len(self.servicePathTV) and self.servicePathTV[0] != eServiceReference(refstr):
966 pathstr = config.tv.lastroot.value
967 if pathstr is not None and pathstr.find(refstr) == 0:
969 lastservice=eServiceReference(config.tv.lastservice.value)
970 if lastservice.valid():
971 self.setCurrentSelection(lastservice)
975 def saveChannel(self):
976 ref = self.session.nav.getCurrentlyPlayingServiceReference()
978 refstr = ref.toString()
981 if refstr != config.tv.lastservice.value:
982 config.tv.lastservice.value = refstr
983 config.tv.lastservice.save()
985 def recallPrevService(self):
986 hlen = len(self.history)
988 if self.history_pos == hlen-1:
989 tmp = self.history[self.history_pos]
990 self.history[self.history_pos] = self.history[self.history_pos-1]
991 self.history[self.history_pos-1] = tmp
993 tmp = self.history[self.history_pos+1]
994 self.history[self.history_pos+1] = self.history[self.history_pos]
995 self.history[self.history_pos] = tmp
996 self.setHistoryPath()
1001 lastservice=eServiceReference(config.tv.lastservice.value)
1002 if lastservice.valid() and self.getCurrentSelection() != lastservice:
1003 self.setCurrentSelection(lastservice)
1005 from Screens.InfoBarGenerics import InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord
1007 class RadioInfoBar(Screen, InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord):
1008 def __init__(self, session):
1009 Screen.__init__(self, session)
1010 InfoBarEvent.__init__(self)
1011 InfoBarServiceName.__init__(self)
1012 InfoBarInstantRecord.__init__(self)
1013 self["Clock"] = Clock()
1015 class ChannelSelectionRadio(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
1016 def __init__(self, session):
1017 ChannelSelectionBase.__init__(self, session)
1018 ChannelSelectionEdit.__init__(self)
1019 ChannelSelectionEPG.__init__(self)
1021 config.radio = ConfigSubsection();
1022 config.radio.lastservice = configElement("config.radio.lastservice", configText, "", 0);
1023 config.radio.lastroot = configElement("config.radio.lastroot", configText, "", 0);
1024 self.onLayoutFinish.append(self.onCreate)
1026 self.info = session.instantiateDialog(RadioInfoBar)
1028 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
1030 "keyTV": self.closeRadio,
1031 "keyRadio": self.closeRadio,
1032 "cancel": self.closeRadio,
1033 "ok": self.channelSelected,
1038 for i in self.servicePathRadio:
1039 path += i.toString()
1041 if len(path) and path != config.radio.lastroot.value:
1042 config.radio.lastroot.value = path
1043 config.radio.lastroot.save()
1045 def restoreRoot(self):
1047 re = compile('.+?;')
1048 tmp = re.findall(config.radio.lastroot.value)
1051 self.servicePathRadio.append(eServiceReference(i[:len(i)-1]))
1054 path = self.servicePathRadio.pop()
1055 self.enterPath(path)
1057 self.showFavourites()
1060 def preEnterPath(self, refstr):
1061 if len(self.servicePathRadio) and self.servicePathRadio[0] != eServiceReference(refstr):
1062 pathstr = config.radio.lastroot.value
1063 if pathstr is not None and pathstr.find(refstr) == 0:
1065 lastservice=eServiceReference(config.radio.lastservice.value)
1066 if lastservice.valid():
1067 self.setCurrentSelection(lastservice)
1074 lastservice=eServiceReference(config.radio.lastservice.value)
1075 if lastservice.valid():
1076 self.servicelist.setCurrent(lastservice)
1077 self.session.nav.playService(lastservice)
1078 self.servicelist.setPlayableIgnoreService(lastservice)
1081 def channelSelected(self): # just return selected service
1082 ref = self.getCurrentSelection()
1084 self.toggleMoveMarked()
1085 elif (ref.flags & 7) == 7:
1087 elif self.bouquet_mark_edit:
1090 playingref = self.session.nav.getCurrentlyPlayingServiceReference()
1091 if playingref is None or playingref != ref:
1092 self.session.nav.playService(ref)
1093 self.servicelist.setPlayableIgnoreService(ref)
1094 config.radio.lastservice.value = ref.toString()
1095 config.radio.lastservice.save()
1098 def closeRadio(self):
1100 #set previous tv service
1101 lastservice=eServiceReference(config.tv.lastservice.value)
1102 self.session.nav.playService(lastservice)
1105 class SimpleChannelSelection(ChannelSelectionBase):
1106 def __init__(self, session, title):
1107 ChannelSelectionBase.__init__(self, session)
1109 self.onShown.append(self.__onExecCallback)
1111 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
1113 "cancel": self.close,
1114 "ok": self.channelSelected,
1115 "keyRadio": self.setModeRadio,
1116 "keyTV": self.setModeTv,
1119 def __onExecCallback(self):
1120 self.setTitle(self.title)
1123 def channelSelected(self): # just return selected service
1124 ref = self.getCurrentSelection()
1125 if (ref.flags & 7) == 7:
1128 ref = self.getCurrentSelection()
1131 def setModeTv(self):
1133 self.showFavourites()
1135 def setModeRadio(self):
1137 self.showFavourites()