add missing import
[enigma2.git] / lib / python / Components / ServiceScan.py
index 768369617e8b24d1b0e56fbced7e66b622357dff..5a7b3dea5691628e4933526dd40397dc07ef0bf3 100644 (file)
@@ -1,4 +1,5 @@
-from enigma import eComponentScan, eDVBFrontendParametersSatellite, eDVBFrontendParametersCable, eDVBFrontendParametersTerrestrial
+from enigma import eComponentScan, iDVBFrontend
+from Components.NimManager import nimmanager as nimmgr
 
 class ServiceScan:
        
@@ -17,6 +18,7 @@ class ServiceScan:
        def scanStatusChanged(self):
                if self.state == self.Running:
                        self.progressbar.setValue(self.scan.getProgress())
+                       self.lcd_summary.updateProgress(self.scan.getProgress())
                        if self.scan.isDone():
                                errcode = self.scan.getError()
                                
@@ -25,69 +27,140 @@ class ServiceScan:
                                else:
                                        self.state = self.Error
                                        self.errorcode = errcode
+                               self.network.setText("")
+                               self.transponder.setText("")
                        else:
-                               self.text.setText("scan in progress - %d %% done!\n%d services found!" % (self.scan.getProgress(), self.scan.getNumServices()))
+                               self.text.setText(_("scan in progress - %d%% done!") % self.scan.getProgress() + ' ' + _("%d services found!") % (self.foundServices + self.scan.getNumServices()))
+                               transponder = self.scan.getCurrentTransponder()
+                               network = ""
+                               tp_text = ""
+                               if transponder:
+                                       tp_type = transponder.getSystem()
+                                       if not tp_type[0]:
+                                               tp_type = tp_type[1]
+                                               if tp_type == iDVBFrontend.feSatellite:
+                                                       network = _("Satellite")
+                                                       tp = transponder.getDVBS()
+                                                       if not tp[0]:
+                                                               tp = tp[1]
+                                                               orb_pos = tp.orbital_position
+                                                               try:
+                                                                       sat_name = str(nimmgr.getSatDescription(orb_pos))
+                                                               except KeyError:
+                                                                       sat_name = ""
+                                                               if orb_pos > 1800: # west
+                                                                       orb_pos = 3600 - orb_pos
+                                                                       h = _("W")
+                                                               else:
+                                                                       h = _("E")
+                                                               if sat_name.find("%d.%d" % (orb_pos/10, orb_pos%10)) != -1:
+                                                                       network = sat_name
+                                                               else:
+                                                                       network = ("%s %d.%d %s") % (sat_name, orb_pos / 10, orb_pos % 10, h)
+                                                               tp_text = ("%s %s %d%c / %d / %s") %( { 0 : "DVB-S", 1 : "DVB-S2" }[tp.system],
+                                                                       { 0 : "Auto", 1 : "QPSK", 2 : "M8PSK", 3 : "QAM16" }[tp.modulation],
+                                                                       tp.frequency/1000,
+                                                                       { 0 : 'H', 1 : 'V', 2 : 'L', 3 : 'R' }[tp.polarisation],
+                                                                       tp.symbol_rate/1000,
+                                                                       { 0 : "AUTO", 1 : "1/2", 2 : "2/3", 3 : "3/4", 4 : "5/6",
+                                                                        5 : "7/8", 6 : "8/9", 7 : "3/5", 8 : "4/5", 9 : "9/10",
+                                                                        15 : "NONE" }[tp.fec] )
+                                               elif tp_type == iDVBFrontend.feCable:
+                                                       network = _("Cable")
+                                                       tp = transponder.getDVBC()
+                                                       if not tp[0]:
+                                                               tp = tp[1]
+                                                               tp_text = ("DVB-C %s %d / %d / %s") %( { 0 : "AUTO", 1 : "QAM16", 2 : "QAM32", 3 : "QAM64", 4 : "QAM128", 5 : "QAM256" }[tp.modulation],
+                                                                       tp.frequency,
+                                                                       tp.symbol_rate/1000,
+                                                                       { 0 : "AUTO", 1 : "1/2", 2 : "2/3", 3 : "3/4", 4 : "5/6", 5 : "7/8", 6 : "8/9", 15 : "NONE" }[tp.fec_inner] )
+                                               elif tp_type == iDVBFrontend.feTerrestrial:
+                                                       network = _("Terrestrial")
+                                                       tp = transponder.getDVBT()
+                                                       if not tp[0]:
+                                                               tp = tp[1]
+                                                               tp_text = ("DVB-T %s %d %s") %( { 0 : "QPSK", 1 : "QAM16", 2 : "QAM64", 3 : "AUTO"}[tp.modulation],
+                                                                       tp.frequency,
+                                                                       { 0 : "Bw 8MHz", 1 : "Bw 7MHz", 2 : "Bw 6MHz", 3 : "Bw Auto" }[tp.bandwidth])
+                                               else:
+                                                       print "unknown transponder type in scanStatusChanged"
+                               self.network.setText(network)
+                               self.transponder.setText(tp_text)
                
                if self.state == self.Done:
-                       self.text.setText("scan done!")
+                       if self.scan.getNumServices() == 0:
+                               self.text.setText(_("scan done!") + ' ' + _("%d services found!") % 0 )
+                       else:
+                               self.text.setText(_("scan done!") + ' ' + _("%d services found!") % (self.foundServices + self.scan.getNumServices()))
                
                if self.state == self.Error:
-                       self.text.setText("ERROR - failed to scan (%s)!" % (self.Errors[self.errorcode]) )
+                       self.text.setText(_("ERROR - failed to scan (%s)!") % (self.Errors[self.errorcode]) )
+                       
+               if self.state == self.Done or self.state == self.Error:
+                       if self.run != len(self.scanList) - 1:
+                               self.foundServices += self.scan.getNumServices()
+                               self.execEnd()
+                               self.run += 1
+                               self.execBegin()
        
-       def __init__(self, progressbar, text, transponders, feid, flags):
+       def __init__(self, progressbar, text, servicelist, passNumber, scanList, network, transponder, frontendInfo, lcd_summary):
+               self.foundServices = 0
                self.progressbar = progressbar
                self.text = text
+               self.servicelist = servicelist
+               self.passNumber = passNumber
+               self.scanList = scanList
+               self.frontendInfo = frontendInfo
+               self.transponder = transponder
+               self.network = network
+               self.run = 0
+               self.lcd_summary = lcd_summary
+
+       def doRun(self):
                self.scan = eComponentScan()
+               self.frontendInfo.frontend_source = lambda : self.scan.getFrontend()
+               self.feid = self.scanList[self.run]["feid"]
+               self.flags = self.scanList[self.run]["flags"]
                self.state = self.Idle
-               self.feid = feid
-               self.flags = flags
                self.scanStatusChanged()
                
-#              if 1:
-#                      parm = eDVBFrontendParametersSatellite()
-#
-#                      parm.frequency = 11817000
-#                      parm.symbol_rate = 27500000
-#                      parm.polarisation = 1 # eDVBFrontendParametersSatellite.Polarisation.Vertical
-#                      parm.fec = 3 # eDVBFrontendParametersSatellite.FEC.f3_4;
-#                      parm.inversion = 1 #eDVBFrontendParametersSatellite.Inversion.Off;
-#                      parm.orbital_position = 192
-#                      self.scan.addInitial(parm)
-#              else:
-#                              # until we have a terrestrial.xml:
-#                      for x in [490000000, 530000000, 546000000, 570000000, 626000000]:
-#                              parm = eDVBFrontendParametersTerrestrial()
-#                              parm.frequency = x
-#                              parm.inversion = 2  # eDVBFrontendParametersTerrestrial.Inversion.Unknown;
-#                              parm.bandwidth = 0  #eDVBFrontendParametersTerrestrial.Bandwidth.Bw8MHz;
-#                              parm.code_rate_HP = parm.code_rate_LP = 6 #eDVBFrontendParametersTerrestrial.FEC.fAuto;
-#                              parm.modulation = 1 #eDVBFrontendParametersTerrestrial.Modulation.QAM16;
-#                              parm.transmission_mode = 1 # eDVBFrontendParametersTerrestrial.TransmissionMode.TM8k;
-#                              parm.guard_interval = 0 # eDVBFrontendParametersTerrestrial.GuardInterval.GI_1_32;
-#                              parm.hierarchy = 0 #eDVBFrontendParametersTerrestrial.Hierarchy.HNone;
-#                              self.scan.addInitial(parm)
-               
-               for x in transponders:
+               for x in self.scanList[self.run]["transponders"]:
                        self.scan.addInitial(x)
-               
-               #self.scan.addInitial(parm)
+
+       def updatePass(self):
+               size = len(self.scanList)
+               if size > 1:
+                       self.passNumber.setText(_("pass") + " " + str(self.run + 1) + "/" + str(size) + " (" + _("Tuner") + " " + str(self.scanList[self.run]["feid"]) + ")")
                
        def execBegin(self):
+               self.doRun()
+               self.updatePass()
                self.scan.statusChanged.get().append(self.scanStatusChanged)
+               self.scan.newService.get().append(self.newService)
+               self.servicelist.clear()
                self.state = self.Running
                err = self.scan.start(self.feid, self.flags)
+               self.frontendInfo.updateFrontendData()
                if err:
                        self.state = self.Error
                        self.errorcode = 0
-
                self.scanStatusChanged()
        
        def execEnd(self):
                self.scan.statusChanged.get().remove(self.scanStatusChanged)
+               self.scan.newService.get().remove(self.newService)
                if not self.isDone():
                        print "*** warning *** scan was not finished!"
+               
+               del self.scan
 
        def isDone(self):
-               print "state is %d " % (self.state)
                return self.state == self.Done or self.state == self.Error
-       
+
+       def newService(self):
+               newServiceName = self.scan.getLastServiceName()
+               self.servicelist.addItem(newServiceName)
+               self.lcd_summary.updateService(self.scan.getLastServiceName())
+
+       def destroy(self):
+               pass