from Components.ServiceList import ServiceList
from Components.ActionMap import ActionMap
from EpgSelection import EPGSelection
-from enigma import eServiceReference, eEPGCache, eEPGCachePtr
+from enigma import eServiceReference, eEPGCache, eEPGCachePtr, eServiceCenter, eServiceCenterPtr, iMutableServiceListPtr, eTimer
+from Components.config import config, configElement, ConfigSubsection, configText
from Screens.FixedMenu import FixedMenu
def __init__(self, session, csel):
self.csel = csel
- menu = [("back", self.close)]
+ menu = [ ]
- if csel.movemode:
- menu.append(("disable move mode", self.moveMode))
- else:
- menu.append(("enable move mode", self.moveMode))
+ if csel.mutableList is not None:
+ if not csel.bouquet_mark_edit:
+ if csel.movemode:
+ menu.append(("disable move mode", self.toggleMoveMode))
+ else:
+ menu.append(("enable move mode", self.toggleMoveMode))
- if csel.bouquet_mark_edit:
- menu.append(("end bouquet edit", self.bouquetMarkEnd))
- menu.append(("abort bouquet edit", self.bouquetMarkAbort))
+ if not csel.movemode:
+ if csel.bouquet_mark_edit:
+ menu.append(("end bouquet edit", self.bouquetMarkEnd))
+ menu.append(("abort bouquet edit", self.bouquetMarkAbort))
+ else:
+ menu.append(("edit bouquet...", self.bouquetMarkStart))
+
+ if not csel.bouquet_mark_edit and not csel.movemode:
+ menu.append(("remove service", self.removeCurrentService))
+ menu.append(("back", self.close))
else:
- menu.append(("edit bouquet...", self.bouquetMarkStart))
-
+ menu.append(("back", self.close))
+
FixedMenu.__init__(self, session, "Channel Selection", menu)
self.skinName = "Menu"
- def moveMode(self):
- self.csel.setMoveMode(self.csel.movemode)
+ def removeCurrentService(self):
self.close()
-
+ self.csel.removeCurrentService()
+
+ def toggleMoveMode(self):
+ self.csel.toggleMoveMode()
+ self.close()
+
def bouquetMarkStart(self):
- self.csel.startMarkedEdit()
self.close()
-
+ self.csel.startMarkedEdit()
+
def bouquetMarkEnd(self):
self.csel.endMarkedEdit(abort=False)
self.close()
self.close()
class ChannelSelection(Screen):
+ def lastService(self):
+ self.lastServiceTimer.stop()
+ #zap to last running tv service
+ self.session.nav.playService(eServiceReference(config.tv.lastservice.value))
+
def __init__(self, session):
Screen.__init__(self, session)
+
+ #config for lastservice
+ config.tv = ConfigSubsection();
+ config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
+
self.entry_marked = False
self.movemode = False
self["key_blue"] = Button("Favourites")
self["list"] = ServiceList()
- self["list"].setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(type == 1)"""))
+ self.setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(type == 1)"""))
#self["okbutton"] = Button("ok", [self.channelSelected])
-
+
+ self.lastServiceTimer = eTimer()
+ self.lastServiceTimer.timeout.get().append(self.lastService)
+ self.lastServiceTimer.start(100)
+
class ChannelActionMap(ActionMap):
def action(self, contexts, action):
if action[:7] == "bouquet":
- l = self.csel["list"]
- l.setMode(l.MODE_NORMAL)
- l.setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
+ l = self.csel
+ list = l["list"]
+ list.setMode(list.MODE_NORMAL)
+ l.setRoot(eServiceReference("1:7:1:0:0:0:0:0:0:0:" + action[8:]))
else:
+ if action == "cancel":
+ l = self.csel
+ if l.movemode: #movemode active?
+ l.channelSelected() # unmark
+ l.toggleMoveMode() # disable move mode
+ elif l.bouquet_mark_edit:
+ l.endMarkedEdit(True) # abort edit mode
ActionMap.action(self, contexts, action)
self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
"mark": self.doMark,
"contextMenu": self.doContext,
"showFavourites": self.showFavourites,
- "showEPGList": self.showEPGList
+ "showEPGList": self.showEPGList
})
self["actions"].csel = self
else:
print 'no epg for service', ref.toString()
- # marked edit mode
+# multiple marked entry stuff ( edit mode, later multiepg selection )
def startMarkedEdit(self):
- self.bouquet_mark_edit = True
- self.clearMarks()
-
- # TODO
- marked = self.__marked
-
l = self["list"]
- for x in marked:
- l.addMarked(x)
-
+ # add all services from the current list to internal marked set in listboxservicecontent
+ if self.mutableList is not None:
+ self.bouquetRoot = l.getRoot()
+ self.clearMarks() # this clears the internal marked set in the listboxservicecontent
+ self.bouquet_mark_edit = True
+ self.__marked = l.getRootServices()
+ for x in self.__marked:
+ l.addMarked(eServiceReference(x))
+
+ def removeCurrentService(self):
+ l = self["list"]
+ ref=l.getCurrent()
+ if ref.valid() and self.mutableList is not None:
+ self.mutableList.removeService(ref)
+ self.mutableList.flushChanges() #FIXME dont flush on each single removed service
+ self.setRoot(l.getRoot())
+
def endMarkedEdit(self, abort):
- self.bouquet_mark_edit = True
- new_marked = self["list"].getMarked()
- self.__marked = new_marked
+ l = self["list"]
+ if not abort and self.mutableList is not None:
+ new_marked = set(l.getMarked())
+ old_marked = set(self.__marked)
+ removed = old_marked - new_marked
+ added = new_marked - old_marked
+ changed = False
+ for x in removed:
+ changed = True
+ self.mutableList.removeService(eServiceReference(x))
+ for x in added:
+ changed = True
+ self.mutableList.addService(eServiceReference(x))
+ if changed:
+ self.mutableList.flushChanges()
+ #self.setRoot(self.bouquetRoot)
+ self.showFavourites()
+ self.__marked = []
self.clearMarks()
self.bouquet_mark_edit = False
+ self.bouquetRoot = None
+
+ def setRoot(self, root):
+ if not self.movemode:
+ if not self.bouquet_mark_edit:
+ serviceHandler = eServiceCenter.getInstance()
+ list = serviceHandler.list(root)
+ if list is not None:
+ self.mutableList = list.startEdit()
+ else:
+ self.mutableList = None
+ self["list"].setRoot(root)
def clearMarks(self):
self["list"].clearMarks()
-
+
def doMark(self):
if not self.bouquet_mark_edit:
return
-
ref = self["list"].getCurrent()
if self["list"].isMarked(ref):
self["list"].removeMarked(ref)
else:
self["list"].addMarked(ref)
-
- # ...
+
def channelSelected(self):
ref = self["list"].getCurrent()
if self.movemode:
self["list"].setCurrentMarked(True)
self.entry_marked = True
elif (ref.flags & 7) == 7:
- l = self["list"]
- l.setMode(l.MODE_NORMAL)
- l.setRoot(ref)
+ self.setRoot(ref)
+ elif self.bouquet_mark_edit:
+ self.doMark()
else:
self.session.nav.playService(ref)
+ self.saveChannel()
self.close()
#called from infoBar
def zap(self):
self.session.nav.playService(self["list"].getCurrent())
+ self.saveChannel()
def moveUp(self):
self["list"].moveUp()
def doContext(self):
self.session.open(ChannelContextMenu, self)
- def setMoveMode(self, mode):
- if mode:
+ def toggleMoveMode(self):
+ if self.movemode:
+ if self.entry_marked:
+ self.channelSelected() # unmark current entry
self.movemode = False
+ self.mutableList.flushChanges() # FIXME add check if changes was made
else:
self.movemode = True
def showFavourites(self):
- l = self["list" ]
- l.setRoot(eServiceReference('1:0:1:0:0:0:0:0:0:0:(provider == "fav")'))
- l.setMode(l.MODE_FAVOURITES)
+ self.setRoot(eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet'))
+ list = self["list"]
+ list.setMode(list.MODE_FAVOURITES)
+
+ def saveChannel(self):
+ ref = self.session.nav.getCurrentlyPlayingServiceReference()
+ if ref is not None:
+ refstr = ref.toString()
+ else:
+ refstr = ""
+ config.tv.lastservice.value = refstr
+ config.tv.lastservice.save()