add ability to remove list and config from a wizard
[enigma2.git] / lib / python / Screens / ChannelSelection.py
index 0534a78..b98df0f 100644 (file)
@@ -1,11 +1,12 @@
 from Screen import Screen
 from Components.Button import Button
 from Components.ServiceList import ServiceList
 from Screen import Screen
 from Components.Button import Button
 from Components.ServiceList import ServiceList
-from Components.ActionMap import ActionMap
+from Components.ActionMap import NumberActionMap
 from EpgSelection import EPGSelection
 from enigma import eServiceReference, eEPGCache, eEPGCachePtr, eServiceCenter, eServiceCenterPtr, iMutableServiceListPtr, iStaticServiceInformationPtr, eTimer
 from Components.config import config, configElement, ConfigSubsection, configText
 from Screens.FixedMenu import FixedMenu
 from EpgSelection import EPGSelection
 from enigma import eServiceReference, eEPGCache, eEPGCachePtr, eServiceCenter, eServiceCenterPtr, iMutableServiceListPtr, iStaticServiceInformationPtr, eTimer
 from Components.config import config, configElement, ConfigSubsection, configText
 from Screens.FixedMenu import FixedMenu
+from Tools.NumericalTextInput import NumericalTextInput
 
 import xml.dom.minidom
 
 
 import xml.dom.minidom
 
@@ -28,29 +29,30 @@ class ChannelContextMenu(FixedMenu):
 
                menu = [ ]
 
 
                menu = [ ]
 
-               inBouquetRootList = csel.servicelist.getRoot().toString().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
+               inBouquetRootList = csel.servicelist.getRoot().getPath().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
                inBouquet = csel.getMutableList() is not None
 
                if not csel.bouquet_mark_edit and not csel.movemode and not inBouquetRootList:
                inBouquet = csel.getMutableList() is not None
 
                if not csel.bouquet_mark_edit and not csel.movemode and not inBouquetRootList:
-                       menu.append(("add service to bouquet", self.addServiceToBouquetSelected))
+                       if (csel.getCurrentSelection().type & eServiceReference.flagDirectory) != eServiceReference.flagDirectory:
+                               menu.append((_("add service to bouquet"), self.addServiceToBouquetSelected))
                        if inBouquet:
                        if inBouquet:
-                               menu.append(("remove service", self.removeCurrentService))
+                               menu.append((_("remove service"), self.removeCurrentService))
 
                if inBouquet: # current list is editable?
                        if not csel.bouquet_mark_edit:
                                if not csel.movemode:
 
                if inBouquet: # current list is editable?
                        if not csel.bouquet_mark_edit:
                                if not csel.movemode:
-                                       menu.append(("enable move mode", self.toggleMoveMode))
-                                       if not inBouquetRootList: 
-                                               menu.append(("enable bouquet edit", self.bouquetMarkStart))
+                                       menu.append((_("enable move mode"), self.toggleMoveMode))
+                                       if not inBouquetRootList:
+                                               menu.append((_("enable bouquet edit"), self.bouquetMarkStart))
                                else:
                                else:
-                                       menu.append(("disable move mode", self.toggleMoveMode))
-                       elif not inBouquetRootList: 
-                               menu.append(("end bouquet edit", self.bouquetMarkEnd))
-                               menu.append(("abort bouquet edit", self.bouquetMarkAbort))
+                                       menu.append((_("disable move mode"), self.toggleMoveMode))
+                       elif not inBouquetRootList:
+                               menu.append((_("end bouquet edit"), self.bouquetMarkEnd))
+                               menu.append((_("abort bouquet edit"), self.bouquetMarkAbort))
 
 
-               menu.append(("back", self.close))
+               menu.append((_("back"), self.close))
 
 
-               FixedMenu.__init__(self, session, "Channel Selection", menu)
+               FixedMenu.__init__(self, session, _("Channel Selection"), menu)
                self.skinName = "Menu"
 
        def addServiceToBouquetSelected(self):
                self.skinName = "Menu"
 
        def addServiceToBouquetSelected(self):
@@ -209,29 +211,29 @@ class ChannelSelectionBase(Screen):
        def __init__(self, session):
                Screen.__init__(self, session)
 
        def __init__(self, session):
                Screen.__init__(self, session)
 
-               self.bouquet_root = eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet')
-               #self.bouquet_root = eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet')
+               # 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["key_red"] = Button("All")
-               #self["key_green"] = Button("Provider")
-               #self["key_yellow"] = Button("Satellite")
-               self["key_green"] = Button("")
-               self["key_yellow"] = Button("")
-               self["key_blue"] = Button("Favourites")
+               self.service_types = self.service_types_tv
+
+               #self.bouquet_root = eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) FROM BOUQUET "bouquets.tv" ORDER BY bouquet')
+               self.bouquet_root = eServiceReference('%s FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet'%(self.service_types))
+
+               self["key_red"] = Button(_("All"))
+               self["key_green"] = Button(_("Satellites"))
+               self["key_yellow"] = Button(_("Provider"))
+               self["key_blue"] = Button(_("Favourites"))
 
                self["list"] = ServiceList()
                self.servicelist = self["list"]
 
                #self["okbutton"] = Button("ok", [self.channelSelected])
 
                self["list"] = ServiceList()
                self.servicelist = self["list"]
 
                #self["okbutton"] = Button("ok", [self.channelSelected])
-               
-               self.lastService = None
 
 
-               self.lastServiceTimer = eTimer()
-               self.lastServiceTimer.timeout.get().append(self.lastService)
-               self.lastServiceTimer.start(100)
+               self.numericalTextInput = NumericalTextInput()
 
        def getBouquetNumOffset(self, bouquet):
 
        def getBouquetNumOffset(self, bouquet):
-               if self.bouquet_root.toString().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
+               if self.bouquet_root.getPath().find('FROM BOUQUET "bouquets.') == -1: #FIXME HACK
                        return 0
                offsetCount = 0
                serviceHandler = eServiceCenter.getInstance()
                        return 0
                offsetCount = 0
                serviceHandler = eServiceCenter.getInstance()
@@ -255,8 +257,8 @@ class ChannelSelectionBase(Screen):
                return offsetCount
 
        def setRootBase(self, root):
                return offsetCount
 
        def setRootBase(self, root):
-               inBouquetRootList = root.toString().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
-               if not inBouquetRootList and ((root.flags & eServiceReference.flagDirectory) == eServiceReference.flagDirectory):
+               inBouquetRootList = root.getPath().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
+               if not inBouquetRootList and (root.getPath().find('FROM BOUQUET') != -1):
                        self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
                        self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
                else:
                        self.servicelist.setMode(ServiceList.MODE_FAVOURITES)
                        self.servicelist.setNumberOffset(self.getBouquetNumOffset(root))
                else:
@@ -269,9 +271,27 @@ class ChannelSelectionBase(Screen):
        def moveDown(self):
                self.servicelist.moveDown()
 
        def moveDown(self):
                self.servicelist.moveDown()
 
+       def showAllServices(self):
+               ref = eServiceReference('%s ORDER BY name'%(self.service_types))
+               self.setRoot(ref)
+
+       def showSatellites(self):
+               ref = eServiceReference('%s FROM SATELLITES ORDER BY satellitePosition'%(self.service_types))
+               self.setRoot(ref)
+
+       def showProviders(self):
+               ref = eServiceReference('%s FROM PROVIDERS ORDER BY name'%(self.service_types))
+               self.setRoot(ref)
+
        def showFavourites(self):
                self.setRoot(self.bouquet_root)
 
        def showFavourites(self):
                self.setRoot(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:
        def enterBouquet(self, action):
                if action[:7] == "bouquet":
                        if action.find("FROM BOUQUET") != -1:
@@ -303,15 +323,12 @@ class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit):
                config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
                config.tv.lastroot = configElement("config.tv.lastroot", configText, "", 0);
 
                config.tv.lastservice = configElement("config.tv.lastservice", configText, "", 0);
                config.tv.lastroot = configElement("config.tv.lastroot", configText, "", 0);
 
-               if config.tv.lastroot.value == "":
-                       self.servicelist.setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(type == 1)"""))
-
-               class ChannelActionMap(ActionMap):
+               class ChannelActionMap(NumberActionMap):
                        def action(self, contexts, action):
                                if not self.csel.enterBouquet(action):
                                        if action == "cancel":
                                                self.csel.handleEditCancel()
                        def action(self, contexts, action):
                                if not self.csel.enterBouquet(action):
                                        if action == "cancel":
                                                self.csel.handleEditCancel()
-                                       ActionMap.action(self, contexts, action)
+                                       NumberActionMap.action(self, contexts, action)
                self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
                        {
                                "cancel": self.cancel,
                self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
                        {
                                "cancel": self.cancel,
@@ -319,12 +336,50 @@ class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit):
                                "mark": self.doMark,
                                "contextMenu": self.doContext,
                                "showFavourites": self.showFavourites,
                                "mark": self.doMark,
                                "contextMenu": self.doContext,
                                "showFavourites": self.showFavourites,
-                               "showEPGList": self.showEPGList
+                               "showAllServices": self.showAllServices,
+                               "showProviders": self.showProviders,
+                               "showSatellites": self.showSatellites,
+                               "showEPGList": self.showEPGList,
+                               "1": self.keyNumberGlobal,
+                               "2": self.keyNumberGlobal,
+                               "3": self.keyNumberGlobal,
+                               "4": self.keyNumberGlobal,
+                               "5": self.keyNumberGlobal,
+                               "6": self.keyNumberGlobal,
+                               "7": self.keyNumberGlobal,
+                               "8": self.keyNumberGlobal,
+                               "9": self.keyNumberGlobal,
+                               "0": self.keyNumberGlobal
                        })
                self["actions"].csel = self
                        })
                self["actions"].csel = self
+               self.onShown.append(self.onShow)
+
+#              self.onLayoutFinish.append(self.onCreate)
+               self.lastChannelRootTimer = eTimer()
+               self.lastChannelRootTimer.timeout.get().append(self.onCreate)
+               self.lastChannelRootTimer.start(100,True)
+
+       def onCreate(self):
+               lastroot=eServiceReference(config.tv.lastroot.value)
+               if lastroot.valid():
+                       self.setRoot(lastroot)
+               else:
+                       self.showFavourites()
+                       self.saveRoot(self.getRoot())
+               lastservice=eServiceReference(config.tv.lastservice.value)
+               if lastservice.valid():
+                       self.session.nav.playService(lastservice)
+                       self.servicelist.setCurrent(lastservice)
+
+       def onShow(self):
+               ref = self.session.nav.getCurrentlyPlayingServiceReference()
+               if ref is not None and ref.valid() and ref.getPath() == "":
+                       self.servicelist.setPlayableIgnoreService(ref)
+               else:
+                       self.servicelist.setPlayableIgnoreService(eServiceReference())
 
        def showEPGList(self):
 
        def showEPGList(self):
-               ref=self.servicelist.getCurrent()
+               ref=self.getCurrentSelection()
                ptr=eEPGCache.getInstance()
                if ptr.startTimeQuery(ref) != -1:
                        self.session.open(EPGSelection, ref)
                ptr=eEPGCache.getInstance()
                if ptr.startTimeQuery(ref) != -1:
                        self.session.open(EPGSelection, ref)
@@ -332,7 +387,7 @@ class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit):
                        print 'no epg for service', ref.toString()
 
        def channelSelected(self):
                        print 'no epg for service', ref.toString()
 
        def channelSelected(self):
-               ref = self.servicelist.getCurrent()
+               ref = self.getCurrentSelection()
                if self.movemode:
                        self.toggleMoveMarked()
                elif (ref.flags & 7) == 7:
                if self.movemode:
                        self.toggleMoveMarked()
                elif (ref.flags & 7) == 7:
@@ -349,7 +404,8 @@ class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit):
 
        #called from infoBar and channelSelected
        def zap(self):
 
        #called from infoBar and channelSelected
        def zap(self):
-               self.session.nav.playService(self.servicelist.getCurrent())
+               self.session.nav.playService(self.getCurrentSelection())
+               self.saveRoot(self.getRoot())
                self.saveChannel()
 
        def saveRoot(self, root):
                self.saveChannel()
 
        def saveRoot(self, root):
@@ -366,11 +422,14 @@ class ChannelSelection(ChannelSelectionBase, ChannelSelectionEdit):
                config.tv.lastservice.value = refstr
                config.tv.lastservice.save()
 
                config.tv.lastservice.value = refstr
                config.tv.lastservice.save()
 
-       def lastService(self):
-               self.lastServiceTimer.stop()
-               #zap to last running tv service
-               self.setRoot(eServiceReference(config.tv.lastroot.value))
-               self.session.nav.playService(eServiceReference(config.tv.lastservice.value))
+       def cancel(self):
+               self.close(None)
+               lastroot=eServiceReference(config.tv.lastroot.value)
+               lastservice=eServiceReference(config.tv.lastservice.value)
+               if lastroot.valid() and self.getRoot() != lastroot:
+                       self.setRoot(lastroot)
+               if lastservice.valid() and self.getCurrentSelection() != lastservice:
+                       self.servicelist.setCurrent(lastservice)
 
 class SimpleChannelSelection(ChannelSelectionBase):
        def __init__(self, session, title):
 
 class SimpleChannelSelection(ChannelSelectionBase):
        def __init__(self, session, title):
@@ -378,24 +437,38 @@ class SimpleChannelSelection(ChannelSelectionBase):
                self.title = title
                self.onShown.append(self.onExecCallback)
 
                self.title = title
                self.onShown.append(self.onExecCallback)
 
-               class ChannelActionMap(ActionMap):
+               class ChannelActionMap(NumberActionMap):
                        def action(self, contexts, action):
                                if not self.csel.enterBouquet(action):
                        def action(self, contexts, action):
                                if not self.csel.enterBouquet(action):
-                                       ActionMap.action(self, contexts, action)
+                                       NumberActionMap.action(self, contexts, action)
                self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
                        {
                                "cancel": self.cancel,
                                "ok": self.channelSelected,
                                "showFavourites": self.showFavourites,
                self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions", "ContextMenuActions"],
                        {
                                "cancel": self.cancel,
                                "ok": self.channelSelected,
                                "showFavourites": self.showFavourites,
+                               "showAllServices": self.showAllServices,
+                               "showProviders": self.showProviders,
+                               "showSatellites": self.showSatellites,
+                               "1": self.keyNumberGlobal,
+                               "2": self.keyNumberGlobal,
+                               "3": self.keyNumberGlobal,
+                               "4": self.keyNumberGlobal,
+                               "5": self.keyNumberGlobal,
+                               "6": self.keyNumberGlobal,
+                               "7": self.keyNumberGlobal,
+                               "8": self.keyNumberGlobal,
+                               "9": self.keyNumberGlobal,
+                               "0": self.keyNumberGlobal
                        })
                self["actions"].csel = self
 
        def onExecCallback(self):
                print "onExecCallback"
                        })
                self["actions"].csel = self
 
        def onExecCallback(self):
                print "onExecCallback"
+               self.showFavourites()
                self.session.currentDialog.instance.setTitle(self.title)
 
        def channelSelected(self): # just return selected service
                self.session.currentDialog.instance.setTitle(self.title)
 
        def channelSelected(self): # just return selected service
-               ref = self.servicelist.getCurrent()
+               ref = self.getCurrentSelection()
                self.close(ref)
 
        def setRoot(self, root):
                self.close(ref)
 
        def setRoot(self, root):