finally fix satfinder with new config
[enigma2.git] / lib / python / Plugins / SystemPlugins / Satfinder / plugin.py
index 861db62..06a0f3f 100644 (file)
@@ -10,7 +10,7 @@ from Components.TunerInfo import TunerInfo
 from Components.ActionMap import ActionMap
 from Components.NimManager import nimmanager
 from Components.MenuList import MenuList
 from Components.ActionMap import ActionMap
 from Components.NimManager import nimmanager
 from Components.MenuList import MenuList
-from Components.config import config, ConfigSubsection, configElement_nonSave, configNothing, getConfigListEntry, configSelection, currentConfigSelectionElement, configSatlist
+from Components.config import ConfigSelection, ConfigSatlist, getConfigListEntry
 
 class Tuner:
        def __init__(self, frontend):
 
 class Tuner:
        def __init__(self, frontend):
@@ -77,14 +77,22 @@ class Satfinder(ScanSetup):
        def __init__(self, session, feid):
                self.initcomplete = False
                self.feid = feid
        def __init__(self, session, feid):
                self.initcomplete = False
                self.feid = feid
-
+               self.oldref = None
+               
                if not self.openFrontend():
                if not self.openFrontend():
-                       self.frontend = None
+                       self.oldref = session.nav.getCurrentlyPlayingServiceReference()
+                       session.nav.stopService() # try to disable foreground service
+                       if not self.openFrontend():
+                               if session.pipshown: # try to disable pip
+                                       session.pipshown = False
+                                       del session.pip
+                                       if not self.openFrontend():
+                                               self.frontend = None # in normal case this should not happen
+                                               self.getFrontend = None
 
                ScanSetup.__init__(self, session)
 
                ScanSetup.__init__(self, session)
-               self.session.nav.stopService()
                self.tuner = Tuner(self.frontend)
                self.tuner = Tuner(self.frontend)
-               
+
                self["snr"] = Label()
                self["agc"] = Label()
                self["ber"] = Label()
                self["snr"] = Label()
                self["agc"] = Label()
                self["ber"] = Label()
@@ -104,6 +112,7 @@ class Satfinder(ScanSetup):
                self.statusTimer.start(50, False)
 
                self.initcomplete = True
                self.statusTimer.start(50, False)
 
                self.initcomplete = True
+               self.session = session
                
        def updateStatus(self):
                self["snr_percentage"].update()
                
        def updateStatus(self):
                self["snr_percentage"].update()
@@ -119,18 +128,18 @@ class Satfinder(ScanSetup):
                self.satEntry = None
 
                self.list = []
                self.satEntry = None
 
                self.list = []
-               self.typeOfTuningEntry = getConfigListEntry(_('Tune'), config.tuning.type)
+               self.typeOfTuningEntry = getConfigListEntry(_('Tune'), self.tuning_type)
                self.list.append(self.typeOfTuningEntry)
                self.list.append(self.typeOfTuningEntry)
-               self.satEntry = getConfigListEntry(_('Satellite'), config.tuning.sat)
+               self.satEntry = getConfigListEntry(_('Satellite'), self.tuning_sat)
                self.list.append(self.satEntry)
                self.list.append(self.satEntry)
-               if currentConfigSelectionElement(config.tuning.type) == "manual_transponder":
-                       self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
-                       self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
-                       self.list.append(getConfigListEntry(_('Symbol Rate'), config.scan.sat.symbolrate))
-                       self.list.append(getConfigListEntry(_("Polarity"), config.scan.sat.polarization))
-                       self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec))
-               elif config.tuning.transponder and self.currentConfigSelectionElement(config.tuning.type) == "predefined_transponder":
-                       self.list.append(getConfigListEntry(_("Transponder"), config.tuning.transponder))
+               if self.tuning_type.value == "manual_transponder":
+                       self.list.append(getConfigListEntry(_('Frequency'), self.scan_sat.frequency))
+                       self.list.append(getConfigListEntry(_('Inversion'), self.scan_sat.inversion))
+                       self.list.append(getConfigListEntry(_('Symbol Rate'), self.scan_sat.symbolrate))
+                       self.list.append(getConfigListEntry(_("Polarity"), self.scan_sat.polarization))
+                       self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec))
+               elif self.tuning_transponder and self.tuning_type.value == "predefined_transponder":
+                       self.list.append(getConfigListEntry(_("Transponder"), self.tuning_transponder))
                self["config"].list = self.list
                self["config"].l.setList(self.list)
 
                self["config"].list = self.list
                self["config"].l.setList(self.list)
 
@@ -141,46 +150,43 @@ class Satfinder(ScanSetup):
                        self.updateSats()
                        self.createSetup()
 
                        self.updateSats()
                        self.createSetup()
 
+       def sat_changed(self, config_element):
+               self.newConfig()
+               self.retune(config_element)
+
        def retune(self, configElement):
                returnvalue = (0, 0, 0, 0, 0, 0, 0)
        def retune(self, configElement):
                returnvalue = (0, 0, 0, 0, 0, 0, 0)
-               val = config.tuning.sat.value
-               if val > 0 and len(config.tuning.sat.vals) > val:
-                       satpos = config.tuning.sat.vals[config.tuning.sat.value][1]
-               elif len(config.tuning.sat.vals) > 0:
-                       satpos = config.tuning.sat.vals[0][1]
-               else:
-                       satpos = None
-               if satpos:
-                       if currentConfigSelectionElement(config.tuning.type) == "manual_transponder":
-                               returnvalue = (config.scan.sat.frequency.value[0], config.scan.sat.symbolrate.value[0], config.scan.sat.polarization.value, config.scan.sat.fec.value, config.scan.sat.inversion.value, satpos)
-                       elif currentConfigSelectionElement(config.tuning.type) == "predefined_transponder":
-                               transponder = nimmanager.getTransponders(config.tuning.sat.vals[config.tuning.sat.value][1])[config.tuning.transponder.value]
-                               returnvalue = (int(transponder[1] / 1000), int(transponder[2] / 1000), transponder[3], transponder[4], 2, config.tuning.sat.vals[config.tuning.sat.value][1], satpos)
+               satpos = self.tuning_sat.orbital_position
+               
+               if satpos is not None:
+                       if self.tuning_type.value == "manual_transponder":
+                               returnvalue = (self.scan_sat.frequency.value, self.scan_sat.symbolrate.value, self.scan_sat.polarization.index, self.scan_sat.fec.index, self.scan_sat.inversion.index, satpos)
+                       elif self.tuning_type.value == "predefined_transponder":
+                               transponder = nimmanager.getTransponders(satpos)[self.tuning_transponder.index]
+                               returnvalue = (int(transponder[1] / 1000), int(transponder[2] / 1000), transponder[3], transponder[4], 2, satpos)
                        self.tune(returnvalue)
 
        def createConfig(self, foo):
                        self.tune(returnvalue)
 
        def createConfig(self, foo):
-               config.tuning = ConfigSubsection()
 
 
-               config.tuning.transponder = None
-               config.tuning.type = configElement_nonSave("config.tuning.type", configSelection, 0, (("manual_transponder", _("Manual transponder")), ("predefined_transponder", _("Predefined satellite"))))
-               config.tuning.sat = configElement_nonSave("config.tuning.sat", configSatlist, 192, nimmanager.getSatListForNim(self.feid))
+               self.tuning_transponder = None
+               self.tuning_type = ConfigSelection(choices = [("manual_transponder", _("Manual transponder")), ("predefined_transponder", _("Predefined satellite"))])
+               self.tuning_sat = ConfigSatlist(default = 192, list = nimmanager.getSatListForNim(self.feid))
                ScanSetup.createConfig(self, None)
                
                self.updateSats()
 
                ScanSetup.createConfig(self, None)
                
                self.updateSats()
 
-               config.tuning.type.addNotifier(self.retune)
-               config.tuning.sat.addNotifier(self.retune)
-               config.scan.sat.frequency.addNotifier(self.retune)
-               config.scan.sat.inversion.addNotifier(self.retune)
-               config.scan.sat.symbolrate.addNotifier(self.retune)
-               config.scan.sat.polarization.addNotifier(self.retune)
-               config.scan.sat.fec.addNotifier(self.retune)
+               self.tuning_type.addNotifier(self.retune)
+               self.tuning_sat.addNotifier(self.sat_changed)
+               self.scan_sat.frequency.addNotifier(self.retune)
+               self.scan_sat.inversion.addNotifier(self.retune)
+               self.scan_sat.symbolrate.addNotifier(self.retune)
+               self.scan_sat.polarization.addNotifier(self.retune)
+               self.scan_sat.fec.addNotifier(self.retune)
 
        def updateSats(self):
 
        def updateSats(self):
-               satnum = config.tuning.sat.value
-               satlist = config.tuning.sat.vals
-               if len(satlist):
-                       transponderlist = nimmanager.getTransponders(satlist[satnum][1])
+               orb_pos = self.tuning_sat.orbital_position
+               if orb_pos is not None:
+                       transponderlist = nimmanager.getTransponders(orb_pos)
                        list = []
                        for x in transponderlist:
                                if x[3] == 0:
                        list = []
                        for x in transponderlist:
                                if x[3] == 0:
@@ -208,13 +214,18 @@ class Satfinder(ScanSetup):
                                elif x[4] == 6:
                                        fec = "FEC_None"
                                list.append(str(x[1]) + "," + str(x[2]) + "," + pol + "," + fec)
                                elif x[4] == 6:
                                        fec = "FEC_None"
                                list.append(str(x[1]) + "," + str(x[2]) + "," + pol + "," + fec)
-                       config.tuning.transponder = configElement_nonSave("config.tuning.transponder", configSelection, 0, list)
-                       config.tuning.transponder.addNotifier(self.retune)
+                       self.tuning_transponder = ConfigSelection(choices = list)
+                       self.tuning_transponder.addNotifier(self.retune)
        
        def keyGo(self):
        
        def keyGo(self):
-               self.retune(config.tuning.type)
+               self.retune(self.tuning_type)
 
        def keyCancel(self):
 
        def keyCancel(self):
+               if self.oldref:
+                       if self.frontend:
+                               self.frontend = None
+                               del self.raw_channel
+                       self.session.nav.playService(self.oldref)
                self.close(None)
                
        def tune(self, transponder):
                self.close(None)
                
        def tune(self, transponder):
@@ -263,5 +274,6 @@ def SatfinderMain(session, **kwargs):
                        else:
                                session.open(MessageBox, _("No tuner is configured for use with a diseqc positioner!"), MessageBox.TYPE_ERROR)
 
                        else:
                                session.open(MessageBox, _("No tuner is configured for use with a diseqc positioner!"), MessageBox.TYPE_ERROR)
 
+
 def Plugins(**kwargs):
        return PluginDescriptor(name="Satfinder", description="Helps setting up your dish", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=SatfinderMain)
 def Plugins(**kwargs):
        return PluginDescriptor(name="Satfinder", description="Helps setting up your dish", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=SatfinderMain)