remove no more needed function
[enigma2.git] / lib / python / Screens / ScanSetup.py
1 from Screen import Screen
2 from Screens.DefaultWizard import DefaultWizard
3 from ServiceScan import ServiceScan
4 from Components.config import config, ConfigSubsection, ConfigSelection, \
5         ConfigYesNo, ConfigInteger, getConfigListEntry, ConfigSlider, ConfigEnableDisable
6 from Components.ActionMap import NumberActionMap, ActionMap
7 from Components.ConfigList import ConfigListScreen
8 from Components.NimManager import nimmanager, getConfigSatlist
9 from Components.Label import Label
10 from Tools.Directories import resolveFilename, SCOPE_DEFAULTPARTITIONMOUNTDIR, SCOPE_DEFAULTDIR, SCOPE_DEFAULTPARTITION
11 from Screens.MessageBox import MessageBox
12 from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, \
13         eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial, \
14         eDVBFrontendParametersCable, eConsoleAppContainer, eDVBResourceManager
15
16 def buildTerTransponder(frequency, 
17                 inversion=2, bandwidth = 3, fechigh = 6, feclow = 6,
18                 modulation = 2, transmission = 2, guard = 4,
19                 hierarchy = 4):
20
21 #       print "freq", frequency, "inv", inversion, "bw", bandwidth, "fech", fechigh, "fecl", feclow, "mod", modulation, "tm", transmission, "guard", guard, "hierarchy", hierarchy
22
23         # WARNING: normally, enums are working directly.
24         # Don't copy this (very bad)!! Instead either fix swig (good) or
25         # move this into a central place.
26         Bw8MHz = 0
27         Bw7MHz = 1
28         Bw6MHz = 2
29         #Bw5MHz = 3 #not implemented for e1 compatibilty
30         BwAuto = 3
31         
32         f1_2 = 0
33         f2_3 = 1
34         f3_4 = 2
35         f5_6 = 3
36         f7_8 = 4
37         fAuto = 5
38         
39         TM2k = 0
40         TM8k = 1
41         #TM4k = 2  #not implemented for e1 compatibilty
42         TMAuto = 2
43         
44         GI_1_32 = 0
45         GI_1_16 = 1
46         GI_1_8 = 2
47         GI_1_4 = 3
48         GI_Auto = 4
49         
50         HNone = 0
51         H1 = 1
52         H2 = 2
53         H4 = 3
54         HAuto = 4
55
56         QPSK = 0
57         QAM16 = 1
58         QAM64 = 2
59         Auto = 3
60         
61         Off = 0
62         On = 1
63         Unknown = 2
64
65         parm = eDVBFrontendParametersTerrestrial()
66
67         parm.frequency = frequency
68
69         parm.inversion = [Off, On, Unknown][inversion]
70         parm.bandwidth = [Bw8MHz, Bw7MHz, Bw6MHz, BwAuto][bandwidth] # Bw5MHz unsupported
71         parm.code_rate_HP = [f1_2, f2_3, f3_4, f5_6, f7_8, fAuto][fechigh]
72         parm.code_rate_LP = [f1_2, f2_3, f3_4, f5_6, f7_8, fAuto][feclow]
73         parm.modulation = [QPSK, QAM16, QAM64, Auto][modulation]
74         parm.transmission_mode = [TM2k, TM8k, TMAuto][transmission] # TM4k unsupported
75         parm.guard_interval = [GI_1_32, GI_1_16, GI_1_8, GI_1_4, GI_Auto][guard]
76         parm.hierarchy = [HNone, H1, H2, H4, HAuto][hierarchy]
77         
78         return parm
79
80 def getInitialTransponderList(tlist, pos):
81         list = nimmanager.getTransponders(pos)
82         for x in list:
83                 if x[0] == 0:           #SAT
84                         parm = eDVBFrontendParametersSatellite()
85                         parm.frequency = x[1]
86                         parm.symbol_rate = x[2]
87                         parm.polarisation = x[3]
88                         parm.fec = x[4]
89                         parm.inversion = x[7]
90                         parm.orbital_position = pos
91                         parm.system = x[5]
92                         parm.modulation = x[6]
93                         parm.rolloff = x[8]
94                         parm.pilot = x[9]
95                         tlist.append(parm)
96
97 def getInitialCableTransponderList(tlist, nim):
98         list = nimmanager.getTranspondersCable(nim)
99         for x in list:
100                 if x[0] == 1: #CABLE
101                         parm = eDVBFrontendParametersCable()
102                         parm.frequency = x[1]
103                         parm.symbol_rate = x[2]
104                         parm.modulation = x[3]
105                         parm.fec_inner = x[4]
106                         parm.inversion = 2 # AUTO
107                         #print "frequency:", x[1]
108                         #print "symbol_rate:", x[2]
109                         #print "modulation:", x[3]
110                         #print "fec_inner:", x[4]
111                         #print "inversion:", 2
112                         tlist.append(parm)
113
114 def getInitialTerrestrialTransponderList(tlist, region):
115         list = nimmanager.getTranspondersTerrestrial(region)
116
117         #self.transponders[self.parsedTer].append((2,freq,bw,const,crh,crl,guard,transm,hierarchy,inv))
118
119         #def buildTerTransponder(frequency, inversion = 2, bandwidth = 3, fechigh = 6, feclow = 6,
120                                 #modulation = 2, transmission = 2, guard = 4, hierarchy = 4):
121
122         for x in list:
123                 if x[0] == 2: #TERRESTRIAL
124                         parm = buildTerTransponder(x[1], x[9], x[2], x[4], x[5], x[3], x[7], x[6], x[8])
125                         tlist.append(parm)
126
127 cable_bands = {
128         "DVBC_BAND_EU_VHF_I" : 1 << 0,
129         "DVBC_BAND_EU_MID" : 1 << 1,
130         "DVBC_BAND_EU_VHF_III" : 1 << 2,
131         "DVBC_BAND_EU_SUPER" : 1 << 3,
132         "DVBC_BAND_EU_HYPER" : 1 << 4,
133         "DVBC_BAND_EU_UHF_IV" : 1 << 5,
134         "DVBC_BAND_EU_UHF_V" : 1 << 6,
135         "DVBC_BAND_US_LO" : 1 << 7,
136         "DVBC_BAND_US_MID" : 1 << 8,
137         "DVBC_BAND_US_HI" : 1 << 9,
138         "DVBC_BAND_US_SUPER" : 1 << 10,
139         "DVBC_BAND_US_HYPER" : 1 << 11,
140 }
141
142 class CableTransponderSearchSupport:
143 #       def setCableTransponderSearchResult(self, tlist):
144 #               pass
145
146 #       def cableTransponderSearchFinished(self):
147 #               pass
148
149         def tryGetRawFrontend(self, feid):
150                 res_mgr = eDVBResourceManager.getInstance()
151                 if res_mgr:
152                         raw_channel = res_mgr.allocateRawChannel(self.feid)
153                         if raw_channel:
154                                 frontend = raw_channel.getFrontend()
155                                 if frontend:
156                                         del frontend
157                                         del raw_channel
158                                         return True
159                 return False
160
161         def cableTransponderSearchSessionClosed(self, *val):
162                 print "cableTransponderSearchSessionClosed, val", val
163                 self.cable_search_container.appClosed.get().remove(self.cableTransponderSearchClosed)
164                 self.cable_search_container.dataAvail.get().remove(self.getCableTransponderData)
165                 self.cable_search_container = None
166                 self.cable_search_session = None
167                 if val and len(val) and val[0]:
168                         self.setCableTransponderSearchResult(self.__tlist)
169                 self.__tlist = None
170                 self.cableTransponderSearchFinished()
171
172         def cableTransponderSearchClosed(self, retval):
173                 print "cableTransponderSearch finished", retval
174                 self.cable_search_session.close(True)
175
176         def getCableTransponderData(self, str):
177                 data = str.split()
178                 if len(data):
179                         if data[0] == 'OK':
180                                 print str
181                                 qam = { "QAM16" : 1, "QAM32" : 2, "QAM64" : 3, "QAM128" : 4, "QAM256" : 5 }
182                                 inv = { "INVERSION_OFF" : 0, "INVERSION_ON" : 1 }
183                                 fec = { "FEC_AUTO" : 0, "FEC_1_2" : 1, "FEC_2_3" : 2, "FEC_3_4" : 3, "FEC_5_6": 4, "FEC_7_8" : 5, "FEC_8_9" : 6, "FEC_NONE" : 15 }
184                                 parm = eDVBFrontendParametersCable()
185                                 parm.frequency = int(data[1])
186                                 parm.symbol_rate = int(data[2])
187                                 parm.fec_inner = fec[data[3]]
188                                 parm.modulation = qam[data[4]]
189                                 parm.inversion = inv[data[5]]
190                                 self.__tlist.append(parm)
191                 tmpstr = _("Try to find used Transponders in cable network.. please wait...")
192                 tmpstr += "\n\n"
193                 tmpstr += data[1]
194                 tmpstr += " kHz "
195                 tmpstr += data[0]
196                 self.cable_search_session["text"].setText(tmpstr)
197
198         def startCableTransponderSearch(self, nim_idx):
199                 if not self.tryGetRawFrontend(nim_idx):
200                         self.session.nav.stopService()
201                         if not self.tryGetRawFrontend(nim_idx):
202                                 if self.session.pipshown: # try to disable pip
203                                         self.session.pipshown = False
204                                         del self.session.pip
205                                 if not self.tryGetRawFrontend(nim_idx):
206                                         self.cableTransponderSearchFinished()
207                                         return
208                 self.__tlist = [ ]
209                 self.cable_search_container = eConsoleAppContainer()
210                 self.cable_search_container.appClosed.get().append(self.cableTransponderSearchClosed)
211                 self.cable_search_container.dataAvail.get().append(self.getCableTransponderData)
212                 cableConfig = config.Nims[nim_idx].cable
213                 cmd = "tda1002x --init --scan --verbose --wakeup --inv 2 --bus "
214                 #FIXMEEEEEE hardcoded i2c devices for dm7025 and dm8000
215                 if nim_idx < 2:
216                         cmd += str(nim_idx)
217                 else:
218                         if nim_idx == 2:
219                                 cmd += "2" # first nim socket on DM8000 use /dev/i2c/2
220                         else:
221                                 cmd += "4" # second nim socket on DM8000 use /dev/i2c/4
222                 if cableConfig.scan_type.value == "bands":
223                         cmd += " --scan-bands "
224                         bands = 0
225                         if cableConfig.scan_band_EU_VHF_I.value:
226                                 bands |= cable_bands["DVBC_BAND_EU_VHF_I"]
227                         if cableConfig.scan_band_EU_MID.value:
228                                 bands |= cable_bands["DVBC_BAND_EU_MID"]
229                         if cableConfig.scan_band_EU_VHF_III.value:
230                                 bands |= cable_bands["DVBC_BAND_EU_VHF_III"]
231                         if cableConfig.scan_band_EU_UHF_IV.value:
232                                 bands |= cable_bands["DVBC_BAND_EU_UHF_IV"]
233                         if cableConfig.scan_band_EU_UHF_V.value:
234                                 bands |= cable_bands["DVBC_BAND_EU_UHF_V"]
235                         if cableConfig.scan_band_EU_SUPER.value:
236                                 bands |= cable_bands["DVBC_BAND_EU_SUPER"]
237                         if cableConfig.scan_band_EU_HYPER.value:
238                                 bands |= cable_bands["DVBC_BAND_EU_HYPER"]
239                         if cableConfig.scan_band_US_LOW.value:
240                                 bands |= cable_bands["DVBC_BAND_US_LO"]
241                         if cableConfig.scan_band_US_MID.value:
242                                 bands |= cable_bands["DVBC_BAND_US_MID"]
243                         if cableConfig.scan_band_US_HIGH.value:
244                                 bands |= cable_bands["DVBC_BAND_US_HI"]
245                         if cableConfig.scan_band_US_SUPER.value:
246                                 bands |= cable_bands["DVBC_BAND_US_SUPER"]
247                         if cableConfig.scan_band_US_HYPER.value:
248                                 bands |= cable_bands["DVBC_BAND_US_HYPER"]
249                         cmd += str(bands)
250                 else:
251                         cmd += " --scan-stepsize "
252                         cmd += str(cableConfig.scan_frequency_steps.value)
253                 if cableConfig.scan_mod_qam16.value:
254                         cmd += " --mod 16"
255                 if cableConfig.scan_mod_qam32.value:
256                         cmd += " --mod 32"
257                 if cableConfig.scan_mod_qam64.value:
258                         cmd += " --mod 64"
259                 if cableConfig.scan_mod_qam128.value:
260                         cmd += " --mod 128"
261                 if cableConfig.scan_mod_qam256.value:
262                         cmd += " --mod 256"
263                 if cableConfig.scan_sr_6900.value:
264                         cmd += " --sr 6900000"
265                 if cableConfig.scan_sr_6875.value:
266                         cmd += " --sr 6875000"
267                 if cableConfig.scan_sr_ext1.value > 450:
268                         cmd += " --sr "
269                         cmd += str(cableConfig.scan_sr_ext1.value)
270                         cmd += "000"
271                 if cableConfig.scan_sr_ext2.value > 450:
272                         cmd += " --sr "
273                         cmd += str(cableConfig.scan_sr_ext2.value)
274                         cmd += "000"
275                 print "TDA1002x CMD is", cmd
276
277                 self.cable_search_container.execute(cmd)
278                 tmpstr = _("Try to find used transponders in cable network.. please wait...")
279                 tmpstr += "\n\n..."
280                 self.cable_search_session = self.session.openWithCallback(self.cableTransponderSearchSessionClosed, MessageBox, tmpstr, MessageBox.TYPE_INFO)
281
282 class DefaultSatLists(DefaultWizard):
283         def __init__(self, session, silent = True, showSteps = False):
284                 self.xmlfile = "defaultsatlists.xml"
285                 DefaultWizard.__init__(self, session, silent, showSteps, neededTag = "services")
286                 print "configuredSats:", nimmanager.getConfiguredSats()
287
288         def setDirectory(self):
289                 self.directory = []
290                 self.directory.append(resolveFilename(SCOPE_DEFAULTDIR))
291                 import os
292                 os.system("mount %s %s" % (resolveFilename(SCOPE_DEFAULTPARTITION), resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR)))
293                 self.directory.append(resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR))
294                                 
295         def statusCallback(self, status, progress):
296                 print "statusCallback:", status, progress
297                 from Components.DreamInfoHandler import DreamInfoHandler
298                 if status == DreamInfoHandler.STATUS_DONE:
299                         self["text"].setText(_("The installation of the default services lists is finished.") + "\n\n" + _("Please press OK to continue."))
300                         self.markDone()
301                         self.disableKeys = False        
302
303 class ScanSetup(ConfigListScreen, Screen, CableTransponderSearchSupport):
304         def __init__(self, session):
305                 Screen.__init__(self, session)
306
307                 self.finished_cb = None
308                 self.updateSatList()
309                 self.service = session.nav.getCurrentService()
310                 self.feinfo = None
311                 frontendData = None
312                 if self.service is not None:
313                         self.feinfo = self.service.frontendInfo()
314                         frontendData = self.feinfo and self.feinfo.getAll(True)
315                 
316                 self.createConfig(frontendData)
317
318                 del self.feinfo
319                 del self.service
320
321                 self["actions"] = NumberActionMap(["SetupActions"],
322                 {
323                         "ok": self.keyGo,
324                         "cancel": self.keyCancel,
325                 }, -2)
326
327                 self.statusTimer = eTimer()
328                 self.statusTimer.callback.append(self.updateStatus)
329                 #self.statusTimer.start(5000, True)
330
331                 self.list = []
332                 ConfigListScreen.__init__(self, self.list)
333                 self.createSetup()
334
335                 self["introduction"] = Label(_("Press OK to start the scan"))
336
337         def runAsync(self, finished_cb):
338                 self.finished_cb = finished_cb
339                 self.keyGo()
340
341         def updateSatList(self):
342                 self.satList = []
343                 for slot in nimmanager.nim_slots:
344                         if slot.isCompatible("DVB-S"):
345                                 self.satList.append(nimmanager.getSatListForNim(slot.slot))
346                         else:
347                                 self.satList.append(None)
348
349         def createSetup(self):
350                 self.list = []
351                 self.multiscanlist = []
352                 index_to_scan = int(self.scan_nims.value)
353                 print "ID: ", index_to_scan
354
355                 self.tunerEntry = getConfigListEntry(_("Tuner"), self.scan_nims)
356                 self.list.append(self.tunerEntry)
357                 
358                 if self.scan_nims == [ ]:
359                         return
360                 
361                 self.typeOfScanEntry = None
362                 self.systemEntry = None
363                 self.modulationEntry = None
364                 nim = nimmanager.nim_slots[index_to_scan]
365                 if nim.isCompatible("DVB-S"):
366                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_type)
367                         self.list.append(self.typeOfScanEntry)
368                 elif nim.isCompatible("DVB-C"):
369                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typecable)
370                         self.list.append(self.typeOfScanEntry)
371                 elif nim.isCompatible("DVB-T"):
372                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typeterrestrial)
373                         self.list.append(self.typeOfScanEntry)
374
375                 if nim.isCompatible("DVB-S"):
376                         if self.scan_type.value == "single_transponder":
377                                 self.updateSatList()
378                                 if nim.isCompatible("DVB-S2"):
379                                         self.systemEntry = getConfigListEntry(_('System'), self.scan_sat.system)
380                                         self.list.append(self.systemEntry)
381                                 else:
382                                         # downgrade to dvb-s, in case a -s2 config was active
383                                         self.scan_sat.system.value = "dvb-s"
384                                 self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[index_to_scan]))
385                                 self.list.append(getConfigListEntry(_('Frequency'), self.scan_sat.frequency))
386                                 self.list.append(getConfigListEntry(_('Inversion'), self.scan_sat.inversion))
387                                 self.list.append(getConfigListEntry(_('Symbol Rate'), self.scan_sat.symbolrate))
388                                 self.list.append(getConfigListEntry(_("Polarity"), self.scan_sat.polarization))
389                                 if self.scan_sat.system.value == "dvb-s":
390                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec))
391                                 elif self.scan_sat.system.value == "dvb-s2":
392                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2))
393                                         self.modulationEntry = getConfigListEntry(_('Modulation'), self.scan_sat.modulation)
394                                         self.list.append(self.modulationEntry)
395                                         self.list.append(getConfigListEntry(_('Rolloff'), self.scan_sat.rolloff))
396                                         if self.scan_sat.modulation.value == "8psk":
397                                                 self.list.append(getConfigListEntry(_('Pilot'), self.scan_sat.pilot))
398                                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_networkScan))
399                         elif self.scan_type.value == "single_satellite":
400                                 self.updateSatList()
401                                 print self.scan_satselection[index_to_scan]
402                                 self.list.append(getConfigListEntry(_("Satellite"), self.scan_satselection[index_to_scan]))
403                                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
404                         elif self.scan_type.value == "multisat":
405                                 # if (norotor)
406                                 tlist = []
407                                 SatList = nimmanager.getSatListForNim(index_to_scan)
408                                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
409                                 for x in SatList:
410                                         if self.Satexists(tlist, x[0]) == 0:
411                                                 tlist.append(x[0])
412                                                 sat = ConfigEnableDisable(default = True)
413                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[0]), sat)
414                                                 self.list.append(configEntry)
415                                                 self.multiscanlist.append((x[0], sat))
416                                 # if (rotor):
417                            # for sat in nimmanager.satList:
418                                 #       self.list.append(getConfigListEntry(sat[1], self.scan_scansat[sat[0]]))
419                 elif nim.isCompatible("DVB-C"):
420                         if self.scan_typecable.value == "single_transponder":
421                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_cab.frequency))
422                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_cab.inversion))
423                                 self.list.append(getConfigListEntry(_("Symbol Rate"), self.scan_cab.symbolrate))
424                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_cab.modulation))
425                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_cab.fec))
426                                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_networkScan))
427                         elif self.scan_typecable.value == "complete":
428                                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
429                 elif nim.isCompatible("DVB-T"):
430                         if self.scan_typeterrestrial.value == "single_transponder":
431                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_ter.frequency))
432                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_ter.inversion))
433                                 self.list.append(getConfigListEntry(_("Bandwidth"), self.scan_ter.bandwidth))
434                                 self.list.append(getConfigListEntry(_("Code rate high"), self.scan_ter.fechigh))
435                                 self.list.append(getConfigListEntry(_("Code rate low"), self.scan_ter.feclow))
436                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_ter.modulation))
437                                 self.list.append(getConfigListEntry(_("Transmission mode"), self.scan_ter.transmission))
438                                 self.list.append(getConfigListEntry(_("Guard interval mode"), self.scan_ter.guard))
439                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), self.scan_ter.hierarchy))
440                                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_networkScan))
441                         elif self.scan_typeterrestrial.value == "complete":
442                                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
443
444 #               if (nim.isCompatible("DVB-S") and self.scan_type.type == "single_transponder") or \
445 #                       (nim.isCompatbile("DVB-C") and self.scan_typecable.type == "single_transponder") or \
446 #                       (nim.isCompatible("DVB-T") and self.scan_typeterrestrial.type == "single_transponder"):
447 #                               self.configElementSNR = getConfigListEntry(_("SNR"), self.scan_snr)
448 #                               self.list.append(self.configElementSNR)
449 #                               self.configElementACG = getConfigListEntry(_("AGC"), self.scan_agc)
450 #                               self.list.append(self.configElementACG)
451 #                               self.configElementBER = getConfigListEntry(_("BER"), self.scan_ber)
452 #                               self.list.append(self.configElementBER)
453 #                               self.statusTimer.start(500, False)
454 #               else:
455 #                       self.statusTimer.stop()
456
457                 self["config"].list = self.list
458                 self["config"].l.setList(self.list)
459
460         def Satexists(self, tlist, pos):
461                 for x in tlist:
462                         if x == pos:
463                                 return 1
464                 return 0
465
466         def newConfig(self):
467                 cur = self["config"].getCurrent()
468                 print "cur is", cur
469                 if cur == self.typeOfScanEntry or \
470                         cur == self.tunerEntry or \
471                         cur == self.systemEntry or \
472                         (self.modulationEntry and self.systemEntry[1].value == "dvb-s2" and cur == self.modulationEntry):
473                         self.createSetup()
474
475         def createConfig(self, frontendData):
476                                                            #("Type", frontendData["system"], TYPE_TEXT),
477                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
478                                            #("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
479                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
480                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
481                                            #("Polarization", frontendData["polarization"], TYPE_TEXT),
482                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
483                                            #("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
484                                                 #)
485                 #elif frontendData["tuner_type"] == "DVB-C":
486                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
487                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
488                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
489                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
490                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
491                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
492                         #                  ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
493                                                 #)
494                 #elif frontendData["tuner_type"] == "DVB-T":
495                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
496                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
497                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
498                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
499                                            #("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
500                                            #("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
501                                            #("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
502                                            #("Constellation", frontendData["constellation"], TYPE_TEXT),
503                                            #("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
504                                            #("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
505                                            #("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT),
506                         defaultSat = { "orbpos": 192, "system": "dvb-s", "frequency": 11836, "inversion": "auto", "symbolrate": 27500, "polarization": "horizontal", "fec": "auto", "fec_s2": "9_10", "modulation": "qpsk" }
507                         defaultCab = {"frequency": 466, "inversion": "auto", "modulation": "64qam", "fec": "auto", "symbolrate": 6900}
508                         if frontendData is not None:
509                                 ttype = frontendData.get("tuner_type", "UNKNOWN")
510                                 if ttype == "DVB-S":
511                                         defaultSat["system"] = {"DVB-S": "dvb-s", "DVB-S2": "dvb-s2"}[frontendData.get("system", "DVB-S")]
512                                         defaultSat["frequency"] = int(frontendData.get("frequency", 0) / 1000)
513                                         defaultSat["inversion"] = {"INVERSION_OFF": "off", "INVERSION_ON": "on", "INVERSION_AUTO": "auto"}[frontendData.get("inversion", "INVERSION_AUTO")]
514                                         defaultSat["symbolrate"] = int(frontendData.get("symbol_rate", 0) / 1000)
515                                         defaultSat["polarization"] = {"HORIZONTAL": "horizontal", "VERTICAL": "vertical", "CIRCULAR_LEFT": "circular_left", "CIRCULAR_RIGHT": "circular_right", "UNKNOWN": None}[frontendData.get("polarization", "HORIZONTAL")]
516
517                                         if frontendData.get("system", "DVB-S") == "DVB-S2":
518                                                 defaultSat["fec_s2"] = {"FEC_1_2": "1_2", "FEC_2_3": "2_3", "FEC_3_4": "3_4", "FEC_4_5": "4_5", "FEC_5_6": "5_6", "FEC_7_8": "7_8", "FEC_8_9": "8_9", "FEC_9_10": "9_10"} \
519                                                                                         [frontendData.get("fec_inner", "FEC_AUTO")]
520                                                 defaultSat["rolloff"] = {"ROLLOFF_0_35" : "0_35", "ROLLOFF_0_25" : "0_25", "ROLLOFF_0_20" : "0_20"}[frontendData.get("rolloff", "ROLLOFF_0_35")]
521                                                 defaultSat["pilot"] = {"PILOT_ON" : "on", "PILOT_OFF" : "off", "PILOT_AUTO" : "auto"}[frontendData.get("pilot", "PILOT_AUTO")]
522                                         else:
523                                                 defaultSat["fec"] = {"FEC_AUTO": "auto", "FEC_1_2": "1_2", "FEC_2_3": "2_3", "FEC_3_4": "3_4", "FEC_5_6": "5_6", "FEC_7_8": "7_8", "FEC_NONE": "none"} \
524                                                         [frontendData.get("fec_inner", "FEC_AUTO")]
525
526                                         defaultSat["modulation"] = {"QPSK": "qpsk", "8PSK": "8psk"}[frontendData.get("modulation", "QPSK")]
527                                         defaultSat["orbpos"] = frontendData.get("orbital_position", 0)
528                                 elif ttype == "DVB-C":
529                                         defaultCab["frequency"] = int(frontendData.get("frequency", 0) / 1000)
530                                         defaultCab["symbolrate"] = int(frontendData.get("symbol_rate", 0) / 1000)
531                                         defaultCab["inversion"] = {"INVERSION_OFF": "off", "INVERSION_ON": "on", "INVERSION_AUTO": "auto"}[frontendData.get("inversion", "INVERSION_AUTO")]
532                                         defaultCab["fec"] = {"FEC_AUTO": "auto", "FEC_1_2": "1_2", "FEC_2_3": "2_3", "FEC_3_4": "3_4", "FEC_5_6": "5_6", "FEC_7_8": "7_8", "FEC_8_9": "8_9", "FEC_NONE": "none"}[frontendData.get("fec_inner", "FEC_AUTO")]
533                                         defaultCab["modulation"] = {"QAM_AUTO": "auto", "QAM_16": "16qam", "QAM_32": "32qam", "QAM_64": "64qam", "QAM_128": "128qam", "QAM_256": "256qam"}[frontendData.get("modulation", "QAM_16")]
534
535                         self.scan_sat = ConfigSubsection()
536                         self.scan_cab = ConfigSubsection()
537                         self.scan_ter = ConfigSubsection()
538
539                         self.scan_type = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat"))])
540                         self.scan_typecable = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
541                         self.scan_typeterrestrial = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
542                         self.scan_clearallservices = ConfigSelection(default = "no", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
543                         self.scan_networkScan = ConfigYesNo(default = False)
544
545                         nim_list = []
546                         # collect all nims which are *not* set to "nothing"
547                         for n in nimmanager.nim_slots:
548                                 if n.config_mode != "nothing":
549                                         nim_list.append((str(n.slot), n.friendly_full_description))
550
551                         self.scan_nims = ConfigSelection(choices = nim_list)
552
553                         # status
554                         self.scan_snr = ConfigSlider()
555                         self.scan_snr.enabled = False
556                         self.scan_agc = ConfigSlider()
557                         self.scan_agc.enabled = False
558                         self.scan_ber = ConfigSlider()
559                         self.scan_ber.enabled = False
560
561                         # sat
562                         self.scan_sat.system = ConfigSelection(default = defaultSat["system"], choices = [("dvb-s", _("DVB-S")), ("dvb-s2", _("DVB-S2"))])
563                         self.scan_sat.frequency = ConfigInteger(default = defaultSat["frequency"], limits = (1, 99999))
564                         self.scan_sat.inversion = ConfigSelection(default = defaultSat["inversion"], choices = [("off", _("off")), ("on", _("on")), ("auto", _("Auto"))])
565                         self.scan_sat.symbolrate = ConfigInteger(default = defaultSat["symbolrate"], limits = (1, 99999))
566                         self.scan_sat.polarization = ConfigSelection(default = defaultSat["polarization"], choices = [("horizontal", _("horizontal")), ("vertical", _("vertical")),  ("circular_left", _("circular left")), ("circular_right", _("circular right"))])
567                         self.scan_sat.fec = ConfigSelection(default = defaultSat["fec"], choices = [("auto", _("Auto")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("none", _("None"))])
568                         self.scan_sat.fec_s2 = ConfigSelection(default = defaultSat["fec_s2"], choices = [("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("3_5", "3/5"), ("4_5", "4/5"), ("5_6", "5/6"), ("7_8", "7/8"), ("8_9", "8/9"), ("9_10", "9/10")])
569                         self.scan_sat.modulation = ConfigSelection(default = defaultSat["modulation"], choices = [("qpsk", "QPSK"), ("8psk", "8PSK")])
570                         self.scan_sat.rolloff = ConfigSelection(default = defaultSat.get("rolloff", "0_35"), choices = [("0_35", "0.35"), ("0_25", "0.25"), ("0_20", "0.20")])
571                         self.scan_sat.pilot = ConfigSelection(default = defaultSat.get("pilot", "auto"), choices = [("off", _("off")), ("on", _("on")), ("auto", _("Auto"))])
572
573                         # cable
574                         self.scan_cab.frequency = ConfigInteger(default = defaultCab["frequency"], limits = (50, 999))
575                         self.scan_cab.inversion = ConfigSelection(default = defaultCab["inversion"], choices = [("off", _("off")), ("on", _("on")), ("auto", _("Auto"))])
576                         self.scan_cab.modulation = ConfigSelection(default = defaultCab["modulation"], choices = [("16qam", "16-QAM"), ("32qam", "32-QAM"), ("64qam", "64-QAM"), ("128qam", "128-QAM"), ("256qam", "256-QAM")])
577                         self.scan_cab.fec = ConfigSelection(default = defaultCab["fec"], choices = [("auto", _("Auto")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("8_9", "8/9"), ("none", _("None"))])
578                         self.scan_cab.symbolrate = ConfigInteger(default = defaultCab["symbolrate"], limits = (1, 99999))
579
580                         # terrestial
581                         self.scan_ter.frequency = ConfigInteger(default = 466000, limits = (50000, 999000))
582                         self.scan_ter.inversion = ConfigSelection(default = "auto", choices = [("off", _("off")), ("on", _("on")), ("auto", _("Auto"))])
583                         # WORKAROUND: we can't use BW-auto
584                         self.scan_ter.bandwidth = ConfigSelection(default = "8MHz", choices = [("8MHz", "8MHz"), ("7MHz", "7MHz"), ("6MHz", "6MHz")])
585                         #, ("auto", _("Auto"))))
586                         self.scan_ter.fechigh = ConfigSelection(default = "auto", choices = [("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("auto", _("Auto"))])
587                         self.scan_ter.feclow = ConfigSelection(default = "auto", choices = [("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("auto", _("Auto"))])
588                         self.scan_ter.modulation = ConfigSelection(default = "auto", choices = [("qpsk", "QPSK"), ("qam16", "QAM16"), ("qam64", "QAM64"), ("auto", _("Auto"))])
589                         self.scan_ter.transmission = ConfigSelection(default = "auto", choices = [("2k", "2K"), ("8k", "8K"), ("auto", _("Auto"))])
590                         self.scan_ter.guard = ConfigSelection(default = "auto", choices = [("1_32", "1/32"), ("1_16", "1/16"), ("1_8", "1/8"), ("1_4", "1/4"), ("auto", _("Auto"))])
591                         self.scan_ter.hierarchy = ConfigSelection(default = "auto", choices = [("none", _("None")), ("1", "1"), ("2", "2"), ("4", "4"), ("auto", _("Auto"))])
592
593                         self.scan_scansat = {}
594                         for sat in nimmanager.satList:
595                                 #print sat[1]
596                                 self.scan_scansat[sat[0]] = ConfigYesNo(default = False)
597
598                         self.scan_satselection = []
599                         for slot in nimmanager.nim_slots:
600                                 if slot.isCompatible("DVB-S"):
601                                         self.scan_satselection.append(getConfigSatlist(int(defaultSat["orbpos"]), self.satList[slot.slot]))
602                                 else:
603                                         self.scan_satselection.append(None)
604
605                         return True
606
607         def keyLeft(self):
608                 ConfigListScreen.keyLeft(self)
609                 self.newConfig()
610
611         def keyRight(self):
612                 ConfigListScreen.keyRight(self)
613                 self.newConfig()
614
615         def updateStatus(self):
616                 print "updatestatus"
617
618         fecmap = { "auto": 0,
619                            "1_2": 1,
620                            "2_3": 2,
621                            "3_4": 3,
622                            "5_6": 4,
623                            "7_8": 5,
624                            "8_9": 6,
625                            "3_5": 7,
626                            "4_5": 8,
627                            "9_10": 9,
628                            "none": 15
629                            }
630
631         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position, system, modulation, rolloff, pilot):
632                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(self.fecmap[fec]) + " inversion: " + str(inversion) + " modulation: " + str(modulation) + " system: " + str(system) + " rolloff" + str(rolloff) + " pilot" + str(pilot)
633                 print "orbpos: " + str(orbital_position)
634                 parm = eDVBFrontendParametersSatellite()
635                 if modulation == 1:
636                         parm.modulation = 2 # eDVBFrontendParametersSatellite.Modulation.8PSK
637                 else:
638                         parm.modulation = 1 # eDVBFrontendParametersSatellite.Modulation.QPSK
639                 parm.system = system
640                 parm.frequency = frequency * 1000
641                 parm.symbol_rate = symbol_rate * 1000
642                 parm.polarisation = polarisation
643                 parm.fec = self.fecmap[fec]
644                 parm.inversion = inversion
645                 parm.orbital_position = int(orbital_position)
646                 parm.rolloff = int(rolloff)
647                 parm.pilot = int(pilot)
648                 tlist.append(parm)
649
650         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
651                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
652                 parm = eDVBFrontendParametersCable()
653                 parm.frequency = frequency * 1000
654                 parm.symbol_rate = symbol_rate * 1000
655                 parm.modulation = modulation
656                 parm.fec = self.fecmap[fec]
657                 parm.inversion = inversion
658                 tlist.append(parm)
659
660         def addTerTransponder(self, tlist, *args, **kwargs):
661                 tlist.append(buildTerTransponder(*args, **kwargs))
662
663         def keyGo(self):
664                 tlist = []
665                 flags = None
666                 extFlags = True
667                 
668                 startScan = True
669                 index_to_scan = int(self.scan_nims.value)
670                 
671                 if self.scan_nims == [ ]:
672                         self.session.open(MessageBox, _("No tuner is enabled!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
673                         return
674
675                 nim = nimmanager.nim_slots[index_to_scan]
676                 print "nim", nim.slot
677                 if nim.isCompatible("DVB-S"):
678                         print "is compatible with DVB-S"
679                         if self.scan_type.value == "single_transponder":
680                                 # these lists are generated for each tuner, so this has work.
681                                 assert len(self.satList) > index_to_scan
682                                 assert len(self.scan_satselection) > index_to_scan
683                                 
684                                 nimsats = self.satList[index_to_scan]
685                                 selsatidx = self.scan_satselection[index_to_scan].index
686
687                                 # however, the satList itself could be empty. in that case, "index" is 0 (for "None").
688                                 if len(nimsats):
689                                         orbpos = nimsats[selsatidx][0]
690                                         if self.scan_sat.system.value == "dvb-s":
691                                                 fec = self.scan_sat.fec.value
692                                         else:
693                                                 fec = self.scan_sat.fec_s2.value
694                                         print "add sat transponder"
695                                         self.addSatTransponder(tlist, self.scan_sat.frequency.value,
696                                                                 self.scan_sat.symbolrate.value,
697                                                                 self.scan_sat.polarization.index,
698                                                                 fec,
699                                                                 self.scan_sat.inversion.index,
700                                                                 orbpos,
701                                                                 self.scan_sat.system.index,
702                                                                 self.scan_sat.modulation.index,
703                                                                 self.scan_sat.rolloff.index,
704                                                                 self.scan_sat.pilot.index)
705                                 flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
706                                 extFlags = False
707                         elif self.scan_type.value == "single_satellite":
708                                 sat = self.satList[index_to_scan][self.scan_satselection[index_to_scan].index]
709                                 getInitialTransponderList(tlist, sat[0])
710                         elif self.scan_type.value == "multisat":
711                                 SatList = nimmanager.getSatListForNim(index_to_scan)
712                                 for x in self.multiscanlist:
713                                         if x[1].value:
714                                                 print "   " + str(x[0])
715                                                 getInitialTransponderList(tlist, x[0])
716
717                 elif nim.isCompatible("DVB-C"):
718                         if self.scan_typecable.value == "single_transponder":
719                                 fec = self.scan_cab.fec.value
720                                 self.addCabTransponder(tlist, self.scan_cab.frequency.value,
721                                                                                           self.scan_cab.symbolrate.value,
722                                                                                           self.scan_cab.modulation.index + 1,
723                                                                                           fec,
724                                                                                           self.scan_cab.inversion.index)
725                                 flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
726                                 extFlags = False
727                         elif self.scan_typecable.value == "complete":
728                                 if config.Nims[index_to_scan].cable.scan_type.value == "provider":
729                                         getInitialCableTransponderList(tlist, index_to_scan)
730                                 else:
731                                         startScan = False
732
733                 elif nim.isCompatible("DVB-T"):
734                         if self.scan_typeterrestrial.value == "single_transponder":
735                                 self.addTerTransponder(tlist,
736                                                 self.scan_ter.frequency.value * 1000,
737                                                 inversion = self.scan_ter.inversion.index,
738                                                 bandwidth = self.scan_ter.bandwidth.index,
739                                                 fechigh = self.scan_ter.fechigh.index,
740                                                 feclow = self.scan_ter.feclow.index,
741                                                 modulation = self.scan_ter.modulation.index,
742                                                 transmission = self.scan_ter.transmission.index,
743                                                 guard = self.scan_ter.guard.index,
744                                                 hierarchy = self.scan_ter.hierarchy.index)
745                                 flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
746                                 extFlags = False
747                         elif self.scan_typeterrestrial.value == "complete":
748                                 getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(index_to_scan))
749
750                 if flags is None:
751                         flags = eComponentScan.scanNetworkSearch
752
753                 if extFlags:
754                         tmp = self.scan_clearallservices.value
755                         if tmp == "yes":
756                                 flags |= eComponentScan.scanRemoveServices
757                         elif tmp == "yes_hold_feeds":
758                                 flags |= eComponentScan.scanRemoveServices
759                                 flags |= eComponentScan.scanDontRemoveFeeds
760
761                 for x in self["config"].list:
762                         x[1].save()
763
764                 if startScan:
765                         self.startScan(tlist, flags, index_to_scan)
766                 else:
767                         self.flags = flags
768                         self.feid = index_to_scan
769                         self.tlist = []
770                         self.startCableTransponderSearch(self.feid)
771
772         def setCableTransponderSearchResult(self, tlist):
773                 self.tlist = tlist
774
775         def cableTransponderSearchFinished(self):
776                 self.startScan(self.tlist, self.flags, self.feid)
777
778         def startScan(self, tlist, flags, feid):
779                 if len(tlist):
780                         # flags |= eComponentScan.scanSearchBAT
781                         if self.finished_cb:
782                                 self.session.openWithCallback(self.finished_cb, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
783                         else:
784                                 self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
785                 else:
786                         if self.finished_cb:
787                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
788                         else:
789                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
790
791         def keyCancel(self):
792                 for x in self["config"].list:
793                         x[1].cancel()
794                 self.close()
795
796 class ScanSimple(ConfigListScreen, Screen, CableTransponderSearchSupport):
797         def getNetworksForNim(self, nim):
798                 if nim.isCompatible("DVB-S"):
799                         networks = nimmanager.getSatListForNim(nim.slot)
800                 elif not nim.empty:
801                         networks = [ nim.type ] # "DVB-C" or "DVB-T". TODO: seperate networks for different C/T tuners, if we want to support that.
802                 else:
803                         # empty tuners provide no networks.
804                         networks = [ ]
805                 return networks
806
807         def __init__(self, session):
808                 Screen.__init__(self, session)
809
810                 self["actions"] = ActionMap(["SetupActions"],
811                 {
812                         "ok": self.keyGo,
813                         "cancel": self.keyCancel,
814                 }, -2)
815
816                 self.list = []
817                 tlist = []
818
819                 known_networks = [ ]
820                 nims_to_scan = [ ]
821                 self.finished_cb = None
822
823                 for nim in nimmanager.nim_slots:
824                         # collect networks provided by this tuner
825
826                         need_scan = False
827                         networks = self.getNetworksForNim(nim)
828                         
829                         print "nim %d provides" % nim.slot, networks
830                         print "known:", known_networks
831
832                         # we only need to scan on the first tuner which provides a network.
833                         # this gives the first tuner for each network priority for scanning.
834                         for x in networks:
835                                 if x not in known_networks:
836                                         need_scan = True
837                                         print x, "not in ", known_networks
838                                         known_networks.append(x)
839
840                         if need_scan:
841                                 nims_to_scan.append(nim)
842
843                 # we save the config elements to use them on keyGo
844                 self.nim_enable = [ ]
845
846                 if len(nims_to_scan):
847                         self.scan_clearallservices = ConfigSelection(default = "yes", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
848                         self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
849
850                         for nim in nims_to_scan:
851                                 nimconfig = ConfigYesNo(default = True)
852                                 nimconfig.nim_index = nim.slot
853                                 self.nim_enable.append(nimconfig)
854                                 self.list.append(getConfigListEntry(_("Scan ") + nim.slot_name + " (" + nim.friendly_type + ")", nimconfig))
855
856                 ConfigListScreen.__init__(self, self.list)
857                 self["header"] = Label(_("Automatic Scan"))
858                 self["footer"] = Label(_("Press OK to scan"))
859
860         def runAsync(self, finished_cb):
861                 self.finished_cb = finished_cb
862                 self.keyGo()
863
864         def keyGo(self):
865                 self.scanList = []
866                 self.known_networks = set()
867                 self.nim_iter=0
868                 self.buildTransponderList()
869
870         def buildTransponderList(self): # this method is called multiple times because of asynchronous stuff
871                 APPEND_NOW = 0
872                 SEARCH_CABLE_TRANSPONDERS = 1
873                 action = APPEND_NOW
874
875                 n = self.nim_iter < len(self.nim_enable) and self.nim_enable[self.nim_iter] or None
876                 self.nim_iter += 1
877                 if n:
878                         if n.value: # check if nim is enabled
879                                 flags = 0
880                                 nim = nimmanager.nim_slots[n.nim_index]
881                                 networks = set(self.getNetworksForNim(nim))
882
883                                 # don't scan anything twice
884                                 networks.discard(self.known_networks)
885
886                                 tlist = [ ]
887                                 if nim.isCompatible("DVB-S"):
888                                         # get initial transponders for each satellite to be scanned
889                                         for sat in networks:
890                                                 getInitialTransponderList(tlist, sat[0])
891                                 elif nim.isCompatible("DVB-C"):
892                                         if config.Nims[nim.slot].cable.scan_type.value == "provider":
893                                                 getInitialCableTransponderList(tlist, nim.slot)
894                                         else:
895                                                 action = SEARCH_CABLE_TRANSPONDERS
896                                 elif nim.isCompatible("DVB-T"):
897                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(nim.slot))
898                                 else:
899                                         assert False
900
901                                 flags |= eComponentScan.scanNetworkSearch #FIXMEEE.. use flags from cables / satellites / terrestrial.xml
902                                 tmp = self.scan_clearallservices.value
903                                 if tmp == "yes":
904                                         flags |= eComponentScan.scanRemoveServices
905                                 elif tmp == "yes_hold_feeds":
906                                         flags |= eComponentScan.scanRemoveServices
907                                         flags |= eComponentScan.scanDontRemoveFeeds
908
909                                 if action == APPEND_NOW:
910                                         self.scanList.append({"transponders": tlist, "feid": nim.slot, "flags": flags})
911                                 elif action == SEARCH_CABLE_TRANSPONDERS:
912                                         self.flags = flags
913                                         self.feid = nim.slot
914                                         self.startCableTransponderSearch(nim.slot)
915                                         return
916                                 else:
917                                         assert False
918
919                         self.buildTransponderList() # recursive call of this function !!!
920                         return
921                 # when we are here, then the recursion is finished and all enabled nims are checked
922                 # so we now start the real transponder scan
923                 self.startScan(self.scanList)
924
925         def startScan(self, scanList):
926                 if len(scanList):
927                         if self.finished_cb:
928                                 self.session.openWithCallback(self.finished_cb, ServiceScan, scanList = scanList)
929                         else:
930                                 self.session.open(ServiceScan, scanList = scanList)
931                 else:
932                         if self.finished_cb:
933                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
934                         else:
935                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
936
937         def setCableTransponderSearchResult(self, tlist):
938                 self.scanList.append({"transponders": tlist, "feid": self.feid, "flags": self.flags})
939
940         def cableTransponderSearchFinished(self):
941                 self.buildTransponderList()
942
943         def keyCancel(self):
944                 self.close()
945
946         def Satexists(self, tlist, pos):
947                 for x in tlist:
948                         if x == pos:
949                                 return 1
950                 return 0
951