from Components.Button import Button
from Components.ServiceList import ServiceList
from Components.ActionMap import NumberActionMap, ActionMap
+from Components.MenuList import MenuList
from EpgSelection import EPGSelection
-from enigma import eServiceReference, eEPGCache, eEPGCachePtr, eServiceCenter, eServiceCenterPtr, iMutableServiceListPtr, iStaticServiceInformationPtr, eTimer
+from enigma import eServiceReference, eEPGCache, eEPGCachePtr, eServiceCenter, eServiceCenterPtr, iMutableServiceListPtr, iStaticServiceInformationPtr, eTimer, eDVBDB
from Components.config import config, configElement, ConfigSubsection, configText, currentConfigSelectionElement
from Screens.FixedMenu import FixedMenu
from Tools.NumericalTextInput import NumericalTextInput
from Components.ServiceName import ServiceName
from Components.Clock import Clock
from Components.EventInfo import EventInfo
+from ServiceReference import ServiceReference
from re import *
+from os import remove
import xml.dom.minidom
-class BouquetSelector(FixedMenu):
+class BouquetSelector(Screen):
def __init__(self, session, bouquets, selectedFunc):
+ Screen.__init__(self, session)
+
self.selectedFunc=selectedFunc
+
+ self["actions"] = ActionMap(["OkCancelActions"],
+ {
+ "ok": self.okbuttonClick,
+ "cancel": self.cancelClick
+ })
entrys = [ ]
for x in bouquets:
- entrys.append((x[0], self.bouquetSelected, x[1]))
- FixedMenu.__init__(self, session, "Bouquetlist", entrys)
- self.skinName = "Menu"
+ entrys.append((x[0], x[1]))
+ self["menu"] = MenuList(entrys)
+
+ def okbuttonClick(self):
+ self.selectedFunc(self["menu"].getCurrent()[1])
- def bouquetSelected(self):
- self.selectedFunc(self["menu"].getCurrent()[2])
+ def cancelClick(self):
+ self.close(False)
class ChannelContextMenu(FixedMenu):
def __init__(self, session, csel):
inBouquet = csel.getMutableList() is not None
haveBouquets = csel.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') != -1
- if not csel.bouquet_mark_edit and not csel.movemode and not inBouquetRootList:
- if (csel.getCurrentSelection().flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory:
- if haveBouquets:
- menu.append((_("add service to bouquet"), self.addServiceToBouquetSelected))
- else:
- menu.append((_("add service to favourites"), self.addServiceToBouquetSelected))
- if inBouquet:
- menu.append((_("remove service"), self.removeCurrentService))
+ if not csel.bouquet_mark_edit and not csel.movemode:
+ if not inBouquetRootList:
+ if (csel.getCurrentSelection().flags & eServiceReference.flagDirectory) != eServiceReference.flagDirectory:
+ if haveBouquets:
+ menu.append((_("add service to bouquet"), self.addServiceToBouquetSelected))
+ else:
+ menu.append((_("add service to favourites"), self.addServiceToBouquetSelected))
+ elif haveBouquets:
+ if not inBouquet and csel.getCurrentSelection().getPath().find("PROVIDERS") == -1:
+ menu.append((_("copy to favourites"), csel.copyCurrentToBouquetList))
+ if inBouquet:
+ menu.append((_("remove service"), self.removeCurrentService))
+ elif haveBouquets:
+ menu.append((_("remove bouquet"), csel.removeBouquet))
if inBouquet: # current list is editable?
if not csel.bouquet_mark_edit:
else: #no bouquets in root.. so assume only one favourite list is used
self.addCurrentServiceToBouquet(self.csel.bouquet_root)
+ def copyCurrentToBouquetList(self):
+ self.csel.copyCurrentToBouquetList()
+ self.close()
+
+ def removeBouquet(self):
+ self.csel.removeBouquet()
+ self.close()
+
def addCurrentServiceToBouquet(self, dest):
self.csel.addCurrentServiceToBouquet(dest)
self.close()
def action(self, contexts, action):
if action == "cancel":
self.csel.handleEditCancel()
- ActionMap.action(self, contexts, action)
- self["ChannelSelectEditActions"] = ChannelSelectionEditActionMap(self, ["ChannelSelectEditActions"],
+ elif action == "ok":
+ pass # avoid typo warning...
+ else:
+ ActionMap.action(self, contexts, action)
+ self["ChannelSelectEditActions"] = ChannelSelectionEditActionMap(self, ["ChannelSelectEditActions", "OkCancelActions"],
{
"contextMenu": self.doContext,
})
return list.startEdit()
return None
+ def buildBouquetID(self, str):
+ tmp = str.lower()
+ name = ''
+ for c in tmp:
+ if (c >= 'a' and c <= 'z') or (c >= '0' and c <= '9'):
+ name += c
+ else:
+ name += '_'
+ return name
+
+ def copyCurrentToBouquetList(self):
+ provider = ServiceReference(self.getCurrentSelection())
+ serviceHandler = eServiceCenter.getInstance()
+ mutableBouquetList = serviceHandler.list(self.bouquet_root).startEdit()
+ if mutableBouquetList:
+ providerName = provider.getServiceName()
+ if self.mode == MODE_TV:
+ str = '1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET \"userbouquet.%s.tv\" ORDER BY bouquet'%(self.buildBouquetID(providerName))
+ else:
+ str = '1:7:2:0:0:0:0:0:0:0:(type == 2) FROM BOUQUET \"userbouquet.%s.radio\" ORDER BY bouquet'%(self.buildBouquetID(providerName))
+ new_bouquet_ref = eServiceReference(str)
+ if not mutableBouquetList.addService(new_bouquet_ref):
+ mutableBouquetList.flushChanges()
+ eDVBDB.getInstance().reloadBouquets()
+ mutableBouquet = serviceHandler.list(new_bouquet_ref).startEdit()
+ if mutableBouquet:
+ mutableBouquet.setListName(providerName)
+ list = [ ]
+ services = serviceHandler.list(provider.ref)
+ if not services is None:
+ if not services.getContent(list, True):
+ for service in list:
+ if mutableBouquet.addService(service):
+ print "add", service.toString(), "to new bouquet failed"
+ mutableBouquet.flushChanges()
+ else:
+ print "getContent failed"
+ else:
+ print "list provider", providerName, "failed"
+ else:
+ print "get mutable list for new created bouquet failed"
+ else:
+ print "add", str, "to bouquets failed"
+ else:
+ print "bouquetlist is not editable"
+
+ def removeBouquet(self):
+ refstr = self.getCurrentSelection().toString()
+ pos = refstr.find('FROM BOUQUET "')
+ if pos != -1:
+ refstr = refstr[pos+14:]
+ print refstr
+ pos = refstr.find('"')
+ if pos != -1:
+ filename = '/etc/enigma2/' + refstr[:pos] # FIXMEEE !!! HARDCODED /etc/enigma2
+ self.removeCurrentService()
+ remove(filename)
+ eDVBDB.getInstance().reloadBouquets()
+
# multiple marked entry stuff ( edit mode, later multiepg selection )
def startMarkedEdit(self):
self.mutableList = self.getMutableList()
if self.entry_marked:
self.toggleMoveMarked() # unmark current entry
self.movemode = False
+ self.pathChangedDisabled = False # re-enable path change
self.mutableList.flushChanges() # FIXME add check if changes was made
self.mutableList = None
self.instance.setTitle(self.saved_title)
else:
self.mutableList = self.getMutableList()
self.movemode = True
+ self.pathChangedDisabled = True # no path change allowed in movemode
self.saved_title = self.instance.getTitle()
new_title = self.saved_title
new_title += ' ' + _("[move mode]");
# this makes it much simple to implement a selectable radio or tv mode :)
self.service_types_tv = '1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17)'
- self.service_types_radio = '1:7:1:0:0:0:0:0:0:0:(type == 2)'
+ self.service_types_radio = '1:7:2:0:0:0:0:0:0:0:(type == 2)'
self["key_red"] = Button(_("All"))
self["key_green"] = Button(_("Satellites"))
self.servicePathTV = [ ]
self.servicePathRadio = [ ]
- class ChannelBaseActionMap(NumberActionMap):
- def __init__(self, csel, contexts = [ ], actions = { }, prio=0):
- NumberActionMap.__init__(self, contexts, actions, prio)
- self.csel = csel
- def action(self, contexts, action):
- if not self.csel.enterBouquet(action):
- NumberActionMap.action(self, contexts, action)
- self["ChannelSelectBaseActions"] = ChannelBaseActionMap(self, ["ChannelSelectBaseActions"],
+ self.pathChangedDisabled = False
+
+ self["ChannelSelectBaseActions"] = NumberActionMap(["ChannelSelectBaseActions", "NumberActions"],
{
"showFavourites": self.showFavourites,
"showAllServices": self.showAllServices,
"showProviders": self.showProviders,
"showSatellites": self.showSatellites,
+ "nextBouquet": self.nextBouquet,
+ "prevBouquet": self.prevBouquet,
"1": self.keyNumberGlobal,
"2": self.keyNumberGlobal,
"3": self.keyNumberGlobal,
self.mode = MODE_RADIO
self.recallBouquetMode()
- def setRootBase(self, root, justSet=False):
+ def setRoot(self, root, justSet=False):
path = root.getPath()
inBouquetRootList = path.find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
pos = path.find(' FROM BOUQUET')
return False
def showAllServices(self):
- refstr = '%s ORDER BY name'%(self.service_types)
- if not self.preEnterPath(refstr):
- ref = eServiceReference(refstr)
- currentRoot = self.getRoot()
- if currentRoot is None or currentRoot != ref:
- self.clearPath()
- self.enterPath(ref)
-
- def showSatellites(self):
- refstr = '%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types)
- if not self.preEnterPath(refstr):
- ref = eServiceReference(refstr)
- justSet=False
- prev = None
-
- if self.isBasePathEqual(ref):
- if self.isPrevPathEqual(ref):
- justSet=True
- prev = self.pathUp(justSet)
- else:
+ if not self.pathChangedDisabled:
+ refstr = '%s ORDER BY name'%(self.service_types)
+ if not self.preEnterPath(refstr):
+ ref = eServiceReference(refstr)
currentRoot = self.getRoot()
if currentRoot is None or currentRoot != ref:
- justSet=True
self.clearPath()
- self.enterPath(ref, True)
- if justSet:
- serviceHandler = eServiceCenter.getInstance()
- servicelist = serviceHandler.list(ref)
- if not servicelist is None:
- while True:
- service = servicelist.getNext()
- if not service.valid(): #check if end of list
- break
- orbpos = service.getData(4) >> 16
- if service.getPath().find("FROM PROVIDER") != -1:
- service_name = _("Providers")
- else:
- service_name = _("Services")
- try:
- service_name += str(' - %s'%(nimmanager.getSatDescription(orbpos)))
- service.setName(service_name) # why we need this cast?
- except:
- if orbpos > 1800: # west
- service.setName("%s (%3.1f" + _("W") + ")" %(str, (0 - (orbpos - 3600)) / 10.0))
+ self.enterPath(ref)
+
+ def showSatellites(self):
+ if not self.pathChangedDisabled:
+ refstr = '%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types)
+ if not self.preEnterPath(refstr):
+ ref = eServiceReference(refstr)
+ justSet=False
+ prev = None
+
+ if self.isBasePathEqual(ref):
+ if self.isPrevPathEqual(ref):
+ justSet=True
+ prev = self.pathUp(justSet)
+ else:
+ currentRoot = self.getRoot()
+ if currentRoot is None or currentRoot != ref:
+ justSet=True
+ self.clearPath()
+ self.enterPath(ref, True)
+ if justSet:
+ serviceHandler = eServiceCenter.getInstance()
+ servicelist = serviceHandler.list(ref)
+ if not servicelist is None:
+ while True:
+ service = servicelist.getNext()
+ if not service.valid(): #check if end of list
+ break
+ orbpos = service.getData(4) >> 16
+ if service.getPath().find("FROM PROVIDER") != -1:
+ service_name = _("Providers")
else:
- service.setName("%s (%3.1f" + _("E") + ")" % (str, orbpos / 10.0))
- # print service.toString()
- self.servicelist.addService(service)
- self.servicelist.finishFill()
- if prev is not None:
- # print "-->", prev.toString()
- self.setCurrentSelection(prev)
+ service_name = _("Services")
+ try:
+ service_name += str(' - %s'%(nimmanager.getSatDescription(orbpos)))
+ service.setName(service_name) # why we need this cast?
+ except:
+ if orbpos > 1800: # west
+ service.setName("%s (%3.1f" + _("W") + ")" %(str, (0 - (orbpos - 3600)) / 10.0))
+ else:
+ service.setName("%s (%3.1f" + _("E") + ")" % (str, orbpos / 10.0))
+ self.servicelist.addService(service)
+ self.servicelist.finishFill()
+ if prev is not None:
+ self.setCurrentSelection(prev)
def showProviders(self):
- refstr = '%s FROM PROVIDERS ORDER BY name'%(self.service_types)
- if not self.preEnterPath(refstr):
- ref = eServiceReference(refstr)
- if self.isBasePathEqual(ref):
- self.pathUp()
- else:
- currentRoot = self.getRoot()
- if currentRoot is None or currentRoot != ref:
- self.clearPath()
- self.enterPath(ref)
+ if not self.pathChangedDisabled:
+ refstr = '%s FROM PROVIDERS ORDER BY name'%(self.service_types)
+ if not self.preEnterPath(refstr):
+ ref = eServiceReference(refstr)
+ if self.isBasePathEqual(ref):
+ self.pathUp()
+ else:
+ currentRoot = self.getRoot()
+ if currentRoot is None or currentRoot != ref:
+ self.clearPath()
+ self.enterPath(ref)
- def showFavourites(self):
- if not self.preEnterPath(self.bouquet_rootstr):
+ def changeBouquet(self, direction):
+ if not self.pathChangedDisabled:
if self.isBasePathEqual(self.bouquet_root):
self.pathUp()
- else:
- currentRoot = self.getRoot()
- if currentRoot is None or currentRoot != self.bouquet_root:
- self.clearPath()
- self.enterPath(self.bouquet_root)
+ if direction < 0:
+ self.moveUp()
+ else:
+ self.moveDown()
+ ref = self.getCurrentSelection()
+ self.enterPath(ref)
+
+ def nextBouquet(self):
+ self.changeBouquet(+1)
+
+ def prevBouquet(self):
+ self.changeBouquet(-1)
+
+ def showFavourites(self):
+ if not self.pathChangedDisabled:
+ if not self.preEnterPath(self.bouquet_rootstr):
+ if self.isBasePathEqual(self.bouquet_root):
+ self.pathUp()
+ else:
+ currentRoot = self.getRoot()
+ if currentRoot is None or currentRoot != self.bouquet_root:
+ self.clearPath()
+ self.enterPath(self.bouquet_root)
def keyNumberGlobal(self, number):
char = self.numericalTextInput.getKey(number)
- print "You pressed number " + str(number)
- print "You would go to character " + str(char)
self.servicelist.moveToChar(char)
- def enterBouquet(self, action):
- if action[:7] == "bouquet":
- if action.find("FROM BOUQUET") != -1:
- self.setRoot(eServiceReference("1:7:1:0:0:0:0:0:0:0:" + action[8:]))
- else:
- self.setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
- return True
- return False
-
def getRoot(self):
return self.servicelist.getRoot()
servicepath = service.getPath()
pos = servicepath.find(" FROM BOUQUET")
if pos != -1:
- servicepath = '(type == 1)' + servicepath[pos:]
+ if self.mode == MODE_TV:
+ servicepath = '(type == 1)' + servicepath[pos:]
+ else:
+ servicepath = '(type == 2)' + servicepath[pos:]
service.setPath(servicepath)
self.servicelist.setCurrent(service)
- def cancel(self):
- self.close(None)
-
def getBouquetList(self):
serviceCount=0
bouquets = [ ]
"cancel": self.cancel,
"ok": self.channelSelected,
})
- self.onShown.append(self.onShow)
+ self.onShown.append(self.__onShown)
self.lastChannelRootTimer = eTimer()
- self.lastChannelRootTimer.timeout.get().append(self.onCreate)
+ self.lastChannelRootTimer.timeout.get().append(self.__onCreate)
self.lastChannelRootTimer.start(100,True)
- def onCreate(self):
+ def __onCreate(self):
self.setTvMode()
self.servicePathTV = [ ]
self.restoreRoot()
self.setCurrentSelection(lastservice)
self.session.nav.playService(lastservice)
- def onShow(self):
+ def __onShown(self):
self.recallBouquetMode()
ref = self.session.nav.getCurrentlyPlayingServiceReference()
if ref is not None and ref.valid() and ref.getPath() == "":
self.zap()
self.close(ref)
- def setRoot(self, root, justSet=False):
- if not self.movemode:
- self.setRootBase(root, justSet)
-
#called from infoBar and channelSelected
def zap(self):
ref = self.session.nav.getCurrentlyPlayingServiceReference()
self.servicelist.setCurrent(lastservice)
self.session.nav.playService(lastservice)
self.servicelist.setPlayableIgnoreService(lastservice)
- self.info.instance.show()
+ self.info.show()
def channelSelected(self): # just return selected service
ref = self.getCurrentSelection()
config.radio.lastservice.save()
self.saveRoot()
- def setRoot(self, root, justSet=False):
- self.setRootBase(root, justSet)
-
def closeRadio(self):
- self.info.instance.hide()
+ self.info.hide()
#set previous tv service
lastservice=eServiceReference(config.tv.lastservice.value)
self.session.nav.playService(lastservice)
def __init__(self, session, title):
ChannelSelectionBase.__init__(self, session)
self.title = title
- self.onShown.append(self.onExecCallback)
+ self.onShown.append(self.__onExecCallback)
self["actions"] = ActionMap(["OkCancelActions", "TvRadioActions"],
{
"keyTV": self.setModeTv,
})
- def onExecCallback(self):
+ def __onExecCallback(self):
self.session.currentDialog.instance.setTitle(self.title)
self.setModeTv()
ref = self.getCurrentSelection()
self.close(ref)
- def setRoot(self, root, justSet=False):
- self.setRootBase(root, justSet)
-
def setModeTv(self):
self.setTvMode()
self.showFavourites()