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, eServiceCenter, eServiceCenterPtr, iMutableServiceListPtr, iStaticServiceInformationPtr, eTimer, eDVBDB
8 from Components.config import config, ConfigSubsection, ConfigText
9 from Screens.FixedMenu import FixedMenu
10 from Tools.NumericalTextInput import NumericalTextInput
11 from Components.NimManager import nimmanager
12 from Components.Sources.Clock import Clock
13 from Components.Input import Input
14 from Components.ParentalControl import parentalControl
15 from Screens.InputBox import InputBox, PinInput
16 from Screens.MessageBox import MessageBox
17 from ServiceReference import ServiceReference
18 from Tools.BoundFunction import boundFunction
22 FLAG_SERVICE_NEW_FOUND = 64 #define in lib/dvb/idvb.h as dxNewFound = 64
24 import xml.dom.minidom
26 class BouquetSelector(Screen):
27 def __init__(self, session, bouquets, selectedFunc, enableWrapAround=False):
28 Screen.__init__(self, session)
30 self.selectedFunc=selectedFunc
32 self["actions"] = ActionMap(["OkCancelActions"],
34 "ok": self.okbuttonClick,
35 "cancel": self.cancelClick
39 entrys.append((x[0], x[1]))
40 self["menu"] = MenuList(entrys, enableWrapAround)
43 cur = self["menu"].getCurrent()
46 def okbuttonClick(self):
47 self.selectedFunc(self.getCurrent())
55 def cancelClick(self):
58 class ChannelContextMenu(Screen):
59 def __init__(self, session, csel):
60 Screen.__init__(self, session)
64 self["actions"] = ActionMap(["OkCancelActions"],
66 "ok": self.okbuttonClick,
67 "cancel": self.cancelClick
71 current_root = csel.getRoot()
72 current_sel_path = csel.getCurrentSelection().getPath()
73 current_sel_flags = csel.getCurrentSelection().flags
74 inBouquetRootList = current_root and current_root.getPath().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
75 inBouquet = csel.getMutableList() is not None
76 haveBouquets = csel.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1
78 if not csel.bouquet_mark_edit and not csel.movemode:
79 if not inBouquetRootList:
80 if (csel.getCurrentSelection().flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory:
81 if config.ParentalControl.configured.value:
82 if parentalControl.getProtectionLevel(csel.getCurrentSelection()) == -1:
83 menu.append((_("add to parental protection"), boundFunction(self.addParentalProtection, csel.getCurrentSelection())))
85 menu.append((_("remove from parental protection"), boundFunction(self.removeParentalProtection, csel.getCurrentSelection())))
87 menu.append((_("add service to bouquet"), self.addServiceToBouquetSelected))
89 menu.append((_("add service to favourites"), self.addServiceToBouquetSelected))
92 if not inBouquet and current_sel_path.find("PROVIDERS") == -1:
93 menu.append((_("copy to favourites"), self.copyCurrentToBouquetList))
94 if current_sel_path.find("flags == %d" %(FLAG_SERVICE_NEW_FOUND)) != -1:
95 menu.append((_("remove all new found flags"), self.removeAllNewFoundFlags))
97 menu.append((_("remove entry"), self.removeCurrentService))
98 if current_root is not None and current_root.getPath().find("flags == %d" %(FLAG_SERVICE_NEW_FOUND)) != -1:
99 menu.append((_("remove new found flag"), self.removeNewFoundFlag))
101 menu.append((_("add bouquet"), self.showBouquetInputBox))
102 menu.append((_("remove entry"), self.removeBouquet))
104 if inBouquet: # current list is editable?
105 if not csel.bouquet_mark_edit:
106 if not csel.movemode:
107 menu.append((_("add marker"), self.showMarkerInputBox))
108 menu.append((_("enable move mode"), self.toggleMoveMode))
109 if not inBouquetRootList:
111 menu.append((_("enable bouquet edit"), self.bouquetMarkStart))
113 menu.append((_("enable favourite edit"), self.bouquetMarkStart))
115 menu.append((_("disable move mode"), self.toggleMoveMode))
116 elif not inBouquetRootList:
118 menu.append((_("end bouquet edit"), self.bouquetMarkEnd))
119 menu.append((_("abort bouquet edit"), self.bouquetMarkAbort))
121 menu.append((_("end favourites edit"), self.bouquetMarkEnd))
122 menu.append((_("abort favourites edit"), self.bouquetMarkAbort))
124 menu.append((_("back"), self.cancelClick))
125 self["menu"] = MenuList(menu)
127 def okbuttonClick(self):
128 self["menu"].getCurrent()[1]()
130 def cancelClick(self):
133 def showBouquetInputBox(self):
134 self.session.openWithCallback(self.bouquetInputCallback, InputBox, title=_("Please enter a name for the new bouquet"), text="bouquetname", maxSize=False, type=Input.TEXT)
136 def bouquetInputCallback(self, bouquet):
137 if bouquet is not None:
138 self.csel.addBouquet(bouquet, None)
141 def addParentalProtection(self, service):
142 parentalControl.protectService(service.toCompareString())
145 def removeParentalProtection(self, service):
146 self.session.openWithCallback(boundFunction(self.pinEntered, service.toCompareString()), PinInput, pinList = [config.ParentalControl.servicepin[0].value], title = _("Enter the service pin"), windowTitle = _("Change pin code"))
148 def pinEntered(self, service, result):
150 parentalControl.unProtectService(service)
153 self.session.openWithCallback(self.close, MessageBox, _("The pin code you entered is wrong."), MessageBox.TYPE_ERROR)
156 def addServiceToBouquetSelected(self):
157 bouquets = self.csel.getBouquetList()
162 if cnt > 1: # show bouquet list
163 self.bsel = self.session.openWithCallback(self.bouquetSelClosed, BouquetSelector, bouquets, self.addCurrentServiceToBouquet)
164 elif cnt == 1: # add to only one existing bouquet
165 self.addCurrentServiceToBouquet(bouquets[0][1])
166 else: #no bouquets in root.. so assume only one favourite list is used
167 self.addCurrentServiceToBouquet(self.csel.bouquet_root)
169 def bouquetSelClosed(self, recursive):
174 def copyCurrentToBouquetList(self):
175 self.csel.copyCurrentToBouquetList()
178 def removeBouquet(self):
179 self.csel.removeBouquet()
182 def showMarkerInputBox(self):
183 self.session.openWithCallback(self.markerInputCallback, InputBox, title=_("Please enter a name for the new marker"), text="markername", maxSize=False, type=Input.TEXT)
185 def markerInputCallback(self, marker):
186 if marker is not None:
187 self.csel.addMarker(marker)
190 def addCurrentServiceToBouquet(self, dest):
191 self.csel.addCurrentServiceToBouquet(dest)
192 if self.bsel is not None:
193 self.bsel.close(True)
195 self.close(True) # close bouquet selection
197 def removeCurrentService(self):
198 self.csel.removeCurrentService()
201 def toggleMoveMode(self):
202 self.csel.toggleMoveMode()
205 def bouquetMarkStart(self):
206 self.csel.startMarkedEdit()
209 def bouquetMarkEnd(self):
210 self.csel.endMarkedEdit(abort=False)
213 def bouquetMarkAbort(self):
214 self.csel.endMarkedEdit(abort=True)
217 def removeNewFoundFlag(self):
218 eDVBDB.getInstance().removeFlag(self.csel.getCurrentSelection(), FLAG_SERVICE_NEW_FOUND)
221 def removeAllNewFoundFlags(self):
222 curpath = self.csel.getCurrentSelection().getPath()
223 idx = curpath.find("satellitePosition == ")
225 tmp = curpath[idx+21:]
228 satpos = int(tmp[:idx])
229 eDVBDB.getInstance().removeFlags(FLAG_SERVICE_NEW_FOUND, -1, -1, -1, satpos)
232 class ChannelSelectionEPG:
234 self["ChannelSelectEPGActions"] = ActionMap(["ChannelSelectEPGActions"],
236 "showEPGList": self.showEPGList,
239 def showEPGList(self):
240 ref=self.getCurrentSelection()
241 ptr=eEPGCache.getInstance()
242 if ptr.startTimeQuery(ref) != -1:
243 self.session.open(EPGSelection, ref)
245 print 'no epg for service', ref.toString()
247 class ChannelSelectionEdit:
249 self.entry_marked = False
250 self.movemode = False
251 self.bouquet_mark_edit = False
252 self.mutableList = None
254 self.saved_title = None
255 self.saved_root = None
257 class ChannelSelectionEditActionMap(ActionMap):
258 def __init__(self, csel, contexts = [ ], actions = { }, prio=0):
259 ActionMap.__init__(self, contexts, actions, prio)
262 def action(self, contexts, action):
263 if action == "cancel":
264 self.csel.handleEditCancel()
265 return 0 # fall-trough
267 return 0 # fall-trough
269 return ActionMap.action(self, contexts, action)
271 self["ChannelSelectEditActions"] = ChannelSelectionEditActionMap(self, ["ChannelSelectEditActions", "OkCancelActions"],
273 "contextMenu": self.doContext,
276 def getMutableList(self, root=eServiceReference()):
277 if not self.mutableList is None:
278 return self.mutableList
279 serviceHandler = eServiceCenter.getInstance()
282 list = root and serviceHandler.list(root)
284 return list.startEdit()
287 def buildBouquetID(self, str):
291 if (c >= 'a' and c <= 'z') or (c >= '0' and c <= '9'):
297 def addMarker(self, name):
298 current = self.servicelist.getCurrent()
299 mutableList = self.getMutableList()
302 str = '1:64:%d:0:0:0:0:0:0:0::%s'%(cnt, name)
303 ref = eServiceReference(str)
304 if current and current.valid():
305 if not mutableList.addService(ref, current):
306 self.servicelist.addService(ref, True)
307 mutableList.flushChanges()
309 elif not mutableList.addService(ref):
310 self.servicelist.addService(ref, True)
311 mutableList.flushChanges()
315 def addBouquet(self, bName, services):
316 serviceHandler = eServiceCenter.getInstance()
317 mutableBouquetList = serviceHandler.list(self.bouquet_root).startEdit()
318 if mutableBouquetList:
319 if self.mode == MODE_TV:
321 str = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET \"userbouquet.%s.tv\" ORDER BY bouquet'%(self.buildBouquetID(bName))
324 str = '1:7:2:0:0:0:0:0:0:0:(type == 2) FROM BOUQUET \"userbouquet.%s.radio\" ORDER BY bouquet'%(self.buildBouquetID(bName))
325 new_bouquet_ref = eServiceReference(str)
326 if not mutableBouquetList.addService(new_bouquet_ref):
327 self.bouquetNumOffsetCache = { }
328 mutableBouquetList.flushChanges()
329 eDVBDB.getInstance().reloadBouquets()
330 mutableBouquet = serviceHandler.list(new_bouquet_ref).startEdit()
332 mutableBouquet.setListName(bName)
333 if services is not None:
334 for service in services:
335 if mutableBouquet.addService(service):
336 print "add", service.toString(), "to new bouquet failed"
338 current = self.servicelist.getCurrent()
339 if current and current.toString() == self.bouquet_rootstr:
340 self.servicelist.addService(service, True)
341 mutableBouquet.flushChanges()
343 print "get mutable list for new created bouquet failed"
345 print "add", str, "to bouquets failed"
347 print "bouquetlist is not editable"
349 def copyCurrentToBouquetList(self):
350 provider = ServiceReference(self.getCurrentSelection())
351 providerName = provider.getServiceName()
352 serviceHandler = eServiceCenter.getInstance()
353 services = serviceHandler.list(provider.ref)
354 self.addBouquet(providerName, services and services.getContent('R', True))
356 def removeBouquet(self):
357 refstr = self.getCurrentSelection().toString()
358 self.bouquetNumOffsetCache = { }
359 pos = refstr.find('FROM BOUQUET "')
361 refstr = refstr[pos+14:]
362 pos = refstr.find('"')
364 filename = '/etc/enigma2/' + refstr[:pos] # FIXMEEE !!! HARDCODED /etc/enigma2
365 self.removeCurrentService()
369 print "error during remove of", filename
371 # multiple marked entry stuff ( edit mode, later multiepg selection )
372 def startMarkedEdit(self):
373 self.mutableList = self.getMutableList()
374 # add all services from the current list to internal marked set in listboxservicecontent
375 self.clearMarks() # this clears the internal marked set in the listboxservicecontent
376 self.saved_title = self.instance.getTitle()
377 pos = self.saved_title.find(')')
378 new_title = self.saved_title[:pos+1]
379 if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1:
380 new_title += ' ' + _("[bouquet edit]")
382 new_title += ' ' + _("[favourite edit]")
383 self.setTitle(new_title)
384 self.bouquet_mark_edit = True
385 self.__marked = self.servicelist.getRootServices()
386 for x in self.__marked:
387 self.servicelist.addMarked(eServiceReference(x))
388 self.savedPath = self.servicePath[:]
389 self.showAllServices()
391 def endMarkedEdit(self, abort):
392 if not abort and self.mutableList is not None:
393 self.bouquetNumOffsetCache = { }
394 new_marked = set(self.servicelist.getMarked())
395 old_marked = set(self.__marked)
396 removed = old_marked - new_marked
397 added = new_marked - old_marked
401 self.mutableList.removeService(eServiceReference(x))
404 self.mutableList.addService(eServiceReference(x))
406 self.mutableList.flushChanges()
409 self.bouquet_mark_edit = False
410 self.mutableList = None
411 self.setTitle(self.saved_title)
412 self.saved_title = None
413 # self.servicePath is just a reference to servicePathTv or Radio...
414 # so we never ever do use the asignment operator in self.servicePath
415 del self.servicePath[:] # remove all elements
416 self.servicePath += self.savedPath # add saved elements
418 self.setRoot(self.servicePath[len(self.servicePath)-1])
420 def clearMarks(self):
421 self.servicelist.clearMarks()
424 ref = self.servicelist.getCurrent()
425 if self.servicelist.isMarked(ref):
426 self.servicelist.removeMarked(ref)
428 self.servicelist.addMarked(ref)
430 def removeCurrentService(self):
431 ref = self.servicelist.getCurrent()
432 mutableList = self.getMutableList()
433 if ref.valid() and mutableList is not None:
434 if not mutableList.removeService(ref):
435 self.bouquetNumOffsetCache = { }
436 mutableList.flushChanges() #FIXME dont flush on each single removed service
437 self.servicelist.removeCurrent()
439 def addCurrentServiceToBouquet(self, dest):
440 mutableList = self.getMutableList(dest)
441 if not mutableList is None:
442 if not mutableList.addService(self.servicelist.getCurrent()):
443 self.bouquetNumOffsetCache = { }
444 mutableList.flushChanges()
446 def toggleMoveMode(self):
448 if self.entry_marked:
449 self.toggleMoveMarked() # unmark current entry
450 self.movemode = False
451 self.pathChangedDisabled = False # re-enable path change
452 self.mutableList.flushChanges() # FIXME add check if changes was made
453 self.mutableList = None
454 self.setTitle(self.saved_title)
455 self.saved_title = None
456 if self.getRoot() == self.bouquet_root:
457 self.bouquetNumOffsetCache = { }
459 self.mutableList = self.getMutableList()
461 self.pathChangedDisabled = True # no path change allowed in movemode
462 self.saved_title = self.instance.getTitle()
463 new_title = self.saved_title
464 pos = self.saved_title.find(')')
465 new_title = self.saved_title[:pos+1] + ' ' + _("[move mode]") + self.saved_title[pos+1:]
466 self.setTitle(new_title);
468 def handleEditCancel(self):
469 if self.movemode: #movemode active?
470 self.channelSelected() # unmark
471 self.toggleMoveMode() # disable move mode
472 elif self.bouquet_mark_edit:
473 self.endMarkedEdit(True) # abort edit mode
475 def toggleMoveMarked(self):
476 if self.entry_marked:
477 self.servicelist.setCurrentMarked(False)
478 self.entry_marked = False
480 self.servicelist.setCurrentMarked(True)
481 self.entry_marked = True
484 self.session.open(ChannelContextMenu, self)
489 # this makes it much simple to implement a selectable radio or tv mode :)
490 service_types_tv = '1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17) || (type == 195) || (type == 25)'
491 service_types_radio = '1:7:2:0:0:0:0:0:0:0:(type == 2)'
493 class ChannelSelectionBase(Screen):
494 def __init__(self, session):
495 Screen.__init__(self, session)
497 self["key_red"] = Button(_("All"))
498 self["key_green"] = Button(_("Satellites"))
499 self["key_yellow"] = Button(_("Provider"))
500 self["key_blue"] = Button(_("Favourites"))
502 self["list"] = ServiceList()
503 self.servicelist = self["list"]
505 self.numericalTextInput = NumericalTextInput()
506 self.numericalTextInput.setUseableChars(u'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ')
508 self.servicePathTV = [ ]
509 self.servicePathRadio = [ ]
510 self.servicePath = [ ]
514 self.pathChangedDisabled = False
516 self.bouquetNumOffsetCache = { }
518 self["ChannelSelectBaseActions"] = NumberActionMap(["ChannelSelectBaseActions", "NumberActions"],
520 "showFavourites": self.showFavourites,
521 "showAllServices": self.showAllServices,
522 "showProviders": self.showProviders,
523 "showSatellites": self.showSatellites,
524 "nextBouquet": self.nextBouquet,
525 "prevBouquet": self.prevBouquet,
526 "nextMarker": self.nextMarker,
527 "prevMarker": self.prevMarker,
528 "1": self.keyNumberGlobal,
529 "2": self.keyNumberGlobal,
530 "3": self.keyNumberGlobal,
531 "4": self.keyNumberGlobal,
532 "5": self.keyNumberGlobal,
533 "6": self.keyNumberGlobal,
534 "7": self.keyNumberGlobal,
535 "8": self.keyNumberGlobal,
536 "9": self.keyNumberGlobal,
539 self.recallBouquetMode()
541 def appendDVBTypes(self, ref):
543 pos = path.find(' FROM BOUQUET')
545 return eServiceReference(self.service_types + path[pos:])
548 def getBouquetNumOffset(self, bouquet):
549 if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
551 bouquet = self.appendDVBTypes(bouquet)
553 return self.bouquetNumOffsetCache[bouquet.toString()]
556 serviceHandler = eServiceCenter.getInstance()
557 bouquetlist = serviceHandler.list(self.bouquet_root)
558 if not bouquetlist is None:
560 bouquetIterator = self.appendDVBTypes(bouquetlist.getNext())
561 if not bouquetIterator.valid(): #end of list
563 self.bouquetNumOffsetCache[bouquetIterator.toString()]=offsetCount
564 if ((bouquetIterator.flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory):
566 servicelist = serviceHandler.list(bouquetIterator)
567 if not servicelist is None:
569 serviceIterator = servicelist.getNext()
570 if not serviceIterator.valid(): #check if end of list
572 if serviceIterator.flags: #playable services have no flags
575 return self.bouquetNumOffsetCache.get(bouquet.toString(), offsetCount)
577 def recallBouquetMode(self):
578 if self.mode == MODE_TV:
579 self.service_types = service_types_tv
580 if config.usage.multibouquet.value:
581 self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet'
583 self.bouquet_rootstr = '%s FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet'%(self.service_types)
585 self.service_types = service_types_radio
586 if config.usage.multibouquet.value:
587 self.bouquet_rootstr = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.radio" ORDER BY bouquet'
589 self.bouquet_rootstr = '%s FROM BOUQUET "userbouquet.favourites.radio" ORDER BY bouquet'%(self.service_types)
590 self.bouquet_root = eServiceReference(self.bouquet_rootstr)
594 self.servicePath = self.servicePathTV
595 self.recallBouquetMode()
596 title = self.instance.getTitle()
597 pos = title.find(" (")
603 def setRadioMode(self):
604 self.mode = MODE_RADIO
605 self.servicePath = self.servicePathRadio
606 self.recallBouquetMode()
607 title = self.instance.getTitle()
608 pos = title.find(" (")
614 def setRoot(self, root, justSet=False):
615 path = root.getPath()
616 inBouquetRootList = path.find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
617 pos = path.find(' FROM BOUQUET')
618 isBouquet = pos != -1
619 if not inBouquetRootList and isBouquet:
620 self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
621 self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
622 refstr = self.service_types + path[pos:]
623 root = eServiceReference(refstr)
625 self.servicelist.setMode(ServiceList.MODE_NORMAL)
626 self.servicelist.setRoot(root, justSet)
627 self.buildTitleString()
629 def removeModeStr(self, str):
630 if self.mode == MODE_TV:
631 pos = str.find(' (TV)')
633 pos = str.find(' (Radio)')
638 def getServiceName(self, ref):
639 str = self.removeModeStr(ServiceReference(ref).getServiceName())
641 pathstr = ref.getPath()
642 if pathstr.find('FROM PROVIDERS') != -1:
644 if pathstr.find('FROM SATELLITES') != -1:
645 return _("Satellites")
646 if pathstr.find(') ORDER BY name') != -1:
650 def buildTitleString(self):
651 titleStr = self.instance.getTitle()
652 pos = titleStr.find(']')
654 pos = titleStr.find(')')
656 titleStr = titleStr[:pos+1]
657 Len = len(self.servicePath)
659 base_ref = self.servicePath[0]
661 end_ref = self.servicePath[Len-1]
664 nameStr = self.getServiceName(base_ref)
665 titleStr += ' ' + nameStr
666 if end_ref is not None:
671 nameStr = self.getServiceName(end_ref)
673 self.setTitle(titleStr)
676 self.servicelist.moveUp()
679 self.servicelist.moveDown()
682 del self.servicePath[:]
684 def enterPath(self, ref, justSet=False):
685 self.servicePath.append(ref)
686 self.setRoot(ref, justSet)
688 def pathUp(self, justSet=False):
689 prev = self.servicePath.pop()
690 length = len(self.servicePath)
692 current = self.servicePath[length-1]
693 self.setRoot(current, justSet)
695 self.setCurrentSelection(prev)
698 def isBasePathEqual(self, ref):
699 if len(self.servicePath) > 1 and self.servicePath[0] == ref:
703 def isPrevPathEqual(self, ref):
704 length = len(self.servicePath)
705 if length > 1 and self.servicePath[length-2] == ref:
709 def preEnterPath(self, refstr):
712 def showAllServices(self):
713 if not self.pathChangedDisabled:
714 refstr = '%s ORDER BY name'%(self.service_types)
715 if not self.preEnterPath(refstr):
716 ref = eServiceReference(refstr)
717 currentRoot = self.getRoot()
718 if currentRoot is None or currentRoot != ref:
722 def showSatellites(self):
723 if not self.pathChangedDisabled:
724 refstr = '%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types)
725 if not self.preEnterPath(refstr):
726 ref = eServiceReference(refstr)
730 if self.isBasePathEqual(ref):
731 if self.isPrevPathEqual(ref):
733 prev = self.pathUp(justSet)
735 currentRoot = self.getRoot()
736 if currentRoot is None or currentRoot != ref:
739 self.enterPath(ref, True)
741 serviceHandler = eServiceCenter.getInstance()
742 servicelist = serviceHandler.list(ref)
743 if not servicelist is None:
745 service = servicelist.getNext()
746 if not service.valid(): #check if end of list
748 orbpos = service.getUnsignedData(4) >> 16
749 if service.getPath().find("FROM PROVIDER") != -1:
750 service_name = _("Providers")
751 elif service.getPath().find("flags == %d" %(FLAG_SERVICE_NEW_FOUND)) != -1:
752 service_name = _("New")
754 service_name = _("Services")
756 service_name += str(' - %s'%(nimmanager.getSatDescription(orbpos)))
757 service.setName(service_name) # why we need this cast?
759 if orbpos == 0xFFFF: #Cable
760 n = ("%s (%s)") % (service_name, _("Cable"))
761 elif orbpos == 0xEEEE: #Terrestrial
762 n = ("%s (%s)") % (service_name, _("Terrestrial"))
764 if orbpos > 1800: # west
765 orbpos = 3600 - orbpos
769 n = ("%s (%d.%d" + h + ")") % (service_name, orbpos / 10, orbpos % 10)
771 self.servicelist.addService(service)
772 self.servicelist.finishFill()
774 self.setCurrentSelection(prev)
776 def showProviders(self):
777 if not self.pathChangedDisabled:
778 refstr = '%s FROM PROVIDERS ORDER BY name'%(self.service_types)
779 if not self.preEnterPath(refstr):
780 ref = eServiceReference(refstr)
781 if self.isBasePathEqual(ref):
784 currentRoot = self.getRoot()
785 if currentRoot is None or currentRoot != ref:
789 def changeBouquet(self, direction):
790 if not self.pathChangedDisabled:
791 if self.isBasePathEqual(self.bouquet_root):
797 ref = self.getCurrentSelection()
801 return self.isBasePathEqual(self.bouquet_root)
804 return self.servicelist.atBegin()
807 return self.servicelist.atEnd()
809 def nextBouquet(self):
810 self.changeBouquet(+1)
812 def prevBouquet(self):
813 self.changeBouquet(-1)
815 def showFavourites(self):
816 if not self.pathChangedDisabled:
817 if not self.preEnterPath(self.bouquet_rootstr):
818 if self.isBasePathEqual(self.bouquet_root):
821 currentRoot = self.getRoot()
822 if currentRoot is None or currentRoot != self.bouquet_root:
824 self.enterPath(self.bouquet_root)
826 def keyNumberGlobal(self, number):
827 unichar = self.numericalTextInput.getKey(number)
828 charstr = unichar.encode("utf-8")
829 if len(charstr) == 1:
830 self.servicelist.moveToChar(charstr[0])
833 return self.servicelist.getRoot()
835 def getCurrentSelection(self):
836 return self.servicelist.getCurrent()
838 def setCurrentSelection(self, service):
839 servicepath = service.getPath()
840 pos = servicepath.find(" FROM BOUQUET")
842 if self.mode == MODE_TV:
843 servicepath = '(type == 1)' + servicepath[pos:]
845 servicepath = '(type == 2)' + servicepath[pos:]
846 service.setPath(servicepath)
847 self.servicelist.setCurrent(service)
849 def getBouquetList(self):
852 serviceHandler = eServiceCenter.getInstance()
853 list = serviceHandler.list(self.bouquet_root)
859 if ((s.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
860 info = serviceHandler.info(s)
862 bouquets.append((info.getName(s), s))
865 if len(bouquets) == 0 and serviceCount > 0:
866 info = serviceHandler.info(self.bouquet_root)
868 bouquets.append((info.getName(self.bouquet_root), self.bouquet_root))
872 def keyNumber0(self, num):
873 if len(self.servicePath) > 1:
876 self.keyNumberGlobal(num)
879 if len(self.servicePath) > 1:
880 if self.isBasePathEqual(self.bouquet_root):
881 self.showFavourites()
883 ref = eServiceReference('%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types))
884 if self.isBasePathEqual(ref):
885 self.showSatellites()
887 ref = eServiceReference('%s FROM PROVIDERS ORDER BY name'%(self.service_types))
888 if self.isBasePathEqual(ref):
891 self.showAllServices()
893 def nextMarker(self):
894 self.servicelist.moveToNextMarker()
896 def prevMarker(self):
897 self.servicelist.moveToPrevMarker()
901 #config for lastservice
902 config.tv = ConfigSubsection()
903 config.tv.lastservice = ConfigText()
904 config.tv.lastroot = ConfigText()
905 config.radio = ConfigSubsection()
906 config.radio.lastservice = ConfigText()
907 config.radio.lastroot = ConfigText()
908 config.servicelist = ConfigSubsection()
909 config.servicelist.lastmode = ConfigText(default = "tv")
911 class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
912 def __init__(self, session):
913 ChannelSelectionBase.__init__(self,session)
914 ChannelSelectionEdit.__init__(self)
915 ChannelSelectionEPG.__init__(self)
917 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
919 "cancel": self.cancel,
920 "ok": self.channelSelected,
921 "keyRadio": self.setModeRadio,
922 "keyTV": self.setModeTv,
925 self.onShown.append(self.__onShown)
927 self.lastChannelRootTimer = eTimer()
928 self.lastChannelRootTimer.timeout.get().append(self.__onCreate)
929 self.lastChannelRootTimer.start(100,True)
931 self.history_tv = [ ]
932 self.history_radio = [ ]
933 self.history = self.history_tv
936 self.lastservice = config.tv.lastservice
937 self.lastroot = config.tv.lastroot
938 self.revertMode = None
942 lastservice=eServiceReference(self.lastservice.value)
943 if lastservice.valid():
944 self.setCurrentSelection(lastservice)
947 if self.revertMode is None and config.servicelist.lastmode.value == "radio":
948 self.revertMode = MODE_RADIO
949 self.history = self.history_tv
950 self.lastservice = config.tv.lastservice
951 self.lastroot = config.tv.lastroot
952 config.servicelist.lastmode.value = "tv"
956 def setModeRadio(self):
957 if self.revertMode is None and config.servicelist.lastmode.value == "tv":
958 self.revertMode = MODE_TV
959 if config.usage.e1like_radio_mode.value == "yes":
960 self.history = self.history_radio
961 self.lastservice = config.radio.lastservice
962 self.lastroot = config.radio.lastroot
963 config.servicelist.lastmode.value = "radio"
967 def __onCreate(self):
968 if config.usage.e1like_radio_mode.value == "yes":
969 if config.servicelist.lastmode.value == "tv":
975 lastservice=eServiceReference(self.lastservice.value)
976 if lastservice.valid():
980 self.recallBouquetMode()
981 ref = self.session.nav.getCurrentlyPlayingServiceReference()
982 if ref is not None and ref.valid() and ref.getPath() == "":
983 self.servicelist.setPlayableIgnoreService(ref)
985 self.servicelist.setPlayableIgnoreService(eServiceReference())
987 def channelSelected(self):
988 ref = self.getCurrentSelection()
990 self.toggleMoveMarked()
991 elif (ref.flags & 7) == 7:
993 elif self.bouquet_mark_edit:
995 elif not (ref.flags & 64): # no marker
999 #called from infoBar and channelSelected
1001 self.revertMode=None
1002 ref = self.session.nav.getCurrentlyPlayingServiceReference()
1003 nref = self.getCurrentSelection()
1004 if ref is None or ref != nref:
1005 self.session.nav.playService(nref)
1008 config.servicelist.lastmode.save()
1009 self.addToHistory(nref)
1011 def addToHistory(self, ref):
1012 if self.servicePath is not None:
1013 tmp=self.servicePath[:]
1016 del self.history[self.history_pos+1:]
1019 self.history.append(tmp)
1020 hlen = len(self.history)
1021 if hlen > HISTORYSIZE:
1024 self.history_pos = hlen-1
1026 def historyBack(self):
1027 hlen = len(self.history)
1028 if hlen > 1 and self.history_pos > 0:
1029 self.history_pos -= 1
1030 self.setHistoryPath()
1032 def historyNext(self):
1033 hlen = len(self.history)
1034 if hlen > 1 and self.history_pos < (hlen-1):
1035 self.history_pos += 1
1036 self.setHistoryPath()
1038 def setHistoryPath(self):
1039 path = self.history[self.history_pos][:]
1041 del self.servicePath[:]
1042 self.servicePath += path
1046 if self.getRoot() != root:
1048 self.session.nav.playService(ref)
1049 self.setCurrentSelection(ref)
1054 for i in self.servicePath:
1055 path += i.toString()
1057 if len(path) and path != self.lastroot.value:
1058 self.lastroot.value = path
1059 self.lastroot.save()
1061 def restoreRoot(self):
1063 re = compile('.+?;')
1064 tmp = re.findall(self.lastroot.value)
1067 self.servicePath.append(eServiceReference(i[:len(i)-1]))
1070 path = self.servicePath.pop()
1071 self.enterPath(path)
1073 self.showFavourites()
1076 def preEnterPath(self, refstr):
1077 if len(self.servicePath) and self.servicePath[0] != eServiceReference(refstr):
1078 pathstr = self.lastroot.value
1079 if pathstr is not None and pathstr.find(refstr) == 0:
1081 lastservice=eServiceReference(self.lastservice.value)
1082 if lastservice.valid():
1083 self.setCurrentSelection(lastservice)
1087 def saveChannel(self):
1088 ref = self.session.nav.getCurrentlyPlayingServiceReference()
1090 refstr = ref.toString()
1093 if refstr != self.lastservice.value:
1094 self.lastservice.value = refstr
1095 self.lastservice.save()
1097 def setCurrentServicePath(self, path):
1098 hlen = len(self.history)
1100 self.history[self.history_pos] = path
1102 self.history.append(path)
1103 self.setHistoryPath()
1105 def getCurrentServicePath(self):
1106 hlen = len(self.history)
1108 return self.history[self.history_pos]
1111 def recallPrevService(self):
1112 hlen = len(self.history)
1114 if self.history_pos == hlen-1:
1115 tmp = self.history[self.history_pos]
1116 self.history[self.history_pos] = self.history[self.history_pos-1]
1117 self.history[self.history_pos-1] = tmp
1119 tmp = self.history[self.history_pos+1]
1120 self.history[self.history_pos+1] = self.history[self.history_pos]
1121 self.history[self.history_pos] = tmp
1122 self.setHistoryPath()
1125 if self.revertMode is None:
1127 lastservice=eServiceReference(self.lastservice.value)
1128 if lastservice.valid() and self.getCurrentSelection() != lastservice:
1129 self.setCurrentSelection(lastservice)
1130 elif self.revertMode == MODE_TV:
1132 elif self.revertMode == MODE_RADIO:
1134 self.revertMode = None
1137 from Screens.InfoBarGenerics import InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord
1139 class RadioInfoBar(Screen, InfoBarEvent, InfoBarServiceName, InfoBarInstantRecord):
1140 def __init__(self, session):
1141 Screen.__init__(self, session)
1142 InfoBarEvent.__init__(self)
1143 InfoBarServiceName.__init__(self)
1144 InfoBarInstantRecord.__init__(self)
1145 self["CurrentTime"] = Clock()
1147 class ChannelSelectionRadio(ChannelSelectionBase, ChannelSelectionEdit, ChannelSelectionEPG):
1149 ALLOW_SUSPEND = True
1151 def __init__(self, session):
1152 ChannelSelectionBase.__init__(self, session)
1153 ChannelSelectionEdit.__init__(self)
1154 ChannelSelectionEPG.__init__(self)
1156 config.radio = ConfigSubsection();
1157 config.radio.lastservice = ConfigText()
1158 config.radio.lastroot = ConfigText()
1159 self.onLayoutFinish.append(self.onCreate)
1161 self.info = session.instantiateDialog(RadioInfoBar)
1163 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
1165 "keyTV": self.closeRadio,
1166 "keyRadio": self.closeRadio,
1167 "cancel": self.closeRadio,
1168 "ok": self.channelSelected,
1173 for i in self.servicePathRadio:
1174 path += i.toString()
1176 if len(path) and path != config.radio.lastroot.value:
1177 config.radio.lastroot.value = path
1178 config.radio.lastroot.save()
1180 def restoreRoot(self):
1182 re = compile('.+?;')
1183 tmp = re.findall(config.radio.lastroot.value)
1186 self.servicePathRadio.append(eServiceReference(i[:len(i)-1]))
1189 path = self.servicePathRadio.pop()
1190 self.enterPath(path)
1192 self.showFavourites()
1195 def preEnterPath(self, refstr):
1196 if len(self.servicePathRadio) and self.servicePathRadio[0] != eServiceReference(refstr):
1197 pathstr = config.radio.lastroot.value
1198 if pathstr is not None and pathstr.find(refstr) == 0:
1200 lastservice=eServiceReference(config.radio.lastservice.value)
1201 if lastservice.valid():
1202 self.setCurrentSelection(lastservice)
1209 lastservice=eServiceReference(config.radio.lastservice.value)
1210 if lastservice.valid():
1211 self.servicelist.setCurrent(lastservice)
1212 self.session.nav.playService(lastservice)
1213 self.servicelist.setPlayableIgnoreService(lastservice)
1216 def channelSelected(self): # just return selected service
1217 ref = self.getCurrentSelection()
1219 self.toggleMoveMarked()
1220 elif (ref.flags & 7) == 7:
1222 elif self.bouquet_mark_edit:
1224 elif not (ref.flags & 64): # no marker
1225 playingref = self.session.nav.getCurrentlyPlayingServiceReference()
1226 if playingref is None or playingref != ref:
1227 self.session.nav.playService(ref)
1228 self.servicelist.setPlayableIgnoreService(ref)
1229 config.radio.lastservice.value = ref.toString()
1230 config.radio.lastservice.save()
1233 def closeRadio(self):
1235 #set previous tv service
1236 lastservice=eServiceReference(config.tv.lastservice.value)
1237 self.session.nav.playService(lastservice)
1240 class SimpleChannelSelection(ChannelSelectionBase):
1241 def __init__(self, session, title):
1242 ChannelSelectionBase.__init__(self, session)
1244 self.onShown.append(self.__onExecCallback)
1246 self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
1248 "cancel": self.close,
1249 "ok": self.channelSelected,
1250 "keyRadio": self.setModeRadio,
1251 "keyTV": self.setModeTv,
1254 def __onExecCallback(self):
1255 self.setTitle(self.title)
1258 def channelSelected(self): # just return selected service
1259 ref = self.getCurrentSelection()
1260 if (ref.flags & 7) == 7:
1262 elif not (ref.flags & 64):
1263 ref = self.getCurrentSelection()
1266 def setModeTv(self):
1268 self.showFavourites()
1270 def setModeRadio(self):
1272 self.showFavourites()