d7e6f66cf64363cfbe331fc1c7627917db094eaf
[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
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                 DefaultWizard.__init__(self, session, silent, showSteps, neededTag = "services")
285
286         def setDirectory(self):
287                 self.directory = resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR)
288                 self.xmlfile = "defaultsatlists.xml"            
289
290 class ScanSetup(ConfigListScreen, Screen, CableTransponderSearchSupport):
291         def __init__(self, session):
292                 Screen.__init__(self, session)
293
294                 self.finished_cb = None
295                 self.updateSatList()
296                 self.service = session.nav.getCurrentService()
297                 self.feinfo = None
298                 frontendData = None
299                 if self.service is not None:
300                         self.feinfo = self.service.frontendInfo()
301                         frontendData = self.feinfo and self.feinfo.getAll(True)
302                 
303                 self.createConfig(frontendData)
304
305                 del self.feinfo
306                 del self.service
307
308                 self["actions"] = NumberActionMap(["SetupActions"],
309                 {
310                         "ok": self.keyGo,
311                         "cancel": self.keyCancel,
312                 }, -2)
313
314                 self.statusTimer = eTimer()
315                 self.statusTimer.callback.append(self.updateStatus)
316                 #self.statusTimer.start(5000, True)
317
318                 self.list = []
319                 ConfigListScreen.__init__(self, self.list)
320                 self.createSetup()
321
322                 self["introduction"] = Label(_("Press OK to start the scan"))
323
324         def runAsync(self, finished_cb):
325                 self.finished_cb = finished_cb
326                 self.keyGo()
327
328         def updateSatList(self):
329                 self.satList = []
330                 for slot in nimmanager.nim_slots:
331                         if slot.isCompatible("DVB-S"):
332                                 self.satList.append(nimmanager.getSatListForNim(slot.slot))
333                         else:
334                                 self.satList.append(None)
335
336         def createSetup(self):
337                 self.list = []
338                 self.multiscanlist = []
339                 index_to_scan = int(self.scan_nims.value)
340                 print "ID: ", index_to_scan
341
342                 self.tunerEntry = getConfigListEntry(_("Tuner"), self.scan_nims)
343                 self.list.append(self.tunerEntry)
344                 
345                 if self.scan_nims == [ ]:
346                         return
347                 
348                 self.typeOfScanEntry = None
349                 self.systemEntry = None
350                 self.modulationEntry = None
351                 nim = nimmanager.nim_slots[index_to_scan]
352                 if nim.isCompatible("DVB-S"):
353                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_type)
354                         self.list.append(self.typeOfScanEntry)
355                 elif nim.isCompatible("DVB-C"):
356                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typecable)
357                         self.list.append(self.typeOfScanEntry)
358                 elif nim.isCompatible("DVB-T"):
359                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typeterrestrial)
360                         self.list.append(self.typeOfScanEntry)
361
362                 if nim.isCompatible("DVB-S"):
363                         if self.scan_type.value == "single_transponder":
364                                 self.updateSatList()
365                                 if nim.isCompatible("DVB-S2"):
366                                         self.systemEntry = getConfigListEntry(_('System'), self.scan_sat.system)
367                                         self.list.append(self.systemEntry)
368                                 else:
369                                         # downgrade to dvb-s, in case a -s2 config was active
370                                         self.scan_sat.system.value = "dvb-s"
371                                 self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[index_to_scan]))
372                                 self.list.append(getConfigListEntry(_('Frequency'), self.scan_sat.frequency))
373                                 self.list.append(getConfigListEntry(_('Inversion'), self.scan_sat.inversion))
374                                 self.list.append(getConfigListEntry(_('Symbol Rate'), self.scan_sat.symbolrate))
375                                 self.list.append(getConfigListEntry(_("Polarity"), self.scan_sat.polarization))
376                                 if self.scan_sat.system.value == "dvb-s":
377                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec))
378                                 elif self.scan_sat.system.value == "dvb-s2":
379                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2))
380                                         self.modulationEntry = getConfigListEntry(_('Modulation'), self.scan_sat.modulation)
381                                         self.list.append(self.modulationEntry)
382                                         self.list.append(getConfigListEntry(_('Rolloff'), self.scan_sat.rolloff))
383                                         if self.scan_sat.modulation.value == "8psk":
384                                                 self.list.append(getConfigListEntry(_('Pilot'), self.scan_sat.pilot))
385                                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_networkScan))
386                         elif self.scan_type.value == "single_satellite":
387                                 self.updateSatList()
388                                 print self.scan_satselection[index_to_scan]
389                                 self.list.append(getConfigListEntry(_("Satellite"), self.scan_satselection[index_to_scan]))
390                                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
391                         elif self.scan_type.value == "multisat":
392                                 # if (norotor)
393                                 tlist = []
394                                 SatList = nimmanager.getSatListForNim(index_to_scan)
395                                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
396                                 for x in SatList:
397                                         if self.Satexists(tlist, x[0]) == 0:
398                                                 tlist.append(x[0])
399                                                 sat = ConfigEnableDisable(default = True)
400                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[0]), sat)
401                                                 self.list.append(configEntry)
402                                                 self.multiscanlist.append((x[0], sat))
403                                 # if (rotor):
404                            # for sat in nimmanager.satList:
405                                 #       self.list.append(getConfigListEntry(sat[1], self.scan_scansat[sat[0]]))
406                 elif nim.isCompatible("DVB-C"):
407                         if self.scan_typecable.value == "single_transponder":
408                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_cab.frequency))
409                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_cab.inversion))
410                                 self.list.append(getConfigListEntry(_("Symbol Rate"), self.scan_cab.symbolrate))
411                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_cab.modulation))
412                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_cab.fec))
413                                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_networkScan))
414                         elif self.scan_typecable.value == "complete":
415                                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
416                 elif nim.isCompatible("DVB-T"):
417                         if self.scan_typeterrestrial.value == "single_transponder":
418                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_ter.frequency))
419                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_ter.inversion))
420                                 self.list.append(getConfigListEntry(_("Bandwidth"), self.scan_ter.bandwidth))
421                                 self.list.append(getConfigListEntry(_("Code rate high"), self.scan_ter.fechigh))
422                                 self.list.append(getConfigListEntry(_("Code rate low"), self.scan_ter.feclow))
423                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_ter.modulation))
424                                 self.list.append(getConfigListEntry(_("Transmission mode"), self.scan_ter.transmission))
425                                 self.list.append(getConfigListEntry(_("Guard interval mode"), self.scan_ter.guard))
426                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), self.scan_ter.hierarchy))
427                                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_networkScan))
428                         elif self.scan_typeterrestrial.value == "complete":
429                                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
430
431 #               if (nim.isCompatible("DVB-S") and self.scan_type.type == "single_transponder") or \
432 #                       (nim.isCompatbile("DVB-C") and self.scan_typecable.type == "single_transponder") or \
433 #                       (nim.isCompatible("DVB-T") and self.scan_typeterrestrial.type == "single_transponder"):
434 #                               self.configElementSNR = getConfigListEntry(_("SNR"), self.scan_snr)
435 #                               self.list.append(self.configElementSNR)
436 #                               self.configElementACG = getConfigListEntry(_("AGC"), self.scan_agc)
437 #                               self.list.append(self.configElementACG)
438 #                               self.configElementBER = getConfigListEntry(_("BER"), self.scan_ber)
439 #                               self.list.append(self.configElementBER)
440 #                               self.statusTimer.start(500, False)
441 #               else:
442 #                       self.statusTimer.stop()
443
444                 self["config"].list = self.list
445                 self["config"].l.setList(self.list)
446
447         def Satexists(self, tlist, pos):
448                 for x in tlist:
449                         if x == pos:
450                                 return 1
451                 return 0
452
453         def newConfig(self):
454                 cur = self["config"].getCurrent()
455                 print "cur is", cur
456                 if cur == self.typeOfScanEntry or \
457                         cur == self.tunerEntry or \
458                         cur == self.systemEntry or \
459                         (self.modulationEntry and self.systemEntry[1].value == "dvb-s2" and cur == self.modulationEntry):
460                         self.createSetup()
461
462         def createConfig(self, frontendData):
463                                                            #("Type", frontendData["system"], TYPE_TEXT),
464                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
465                                            #("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
466                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
467                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
468                                            #("Polarization", frontendData["polarization"], TYPE_TEXT),
469                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
470                                            #("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
471                                                 #)
472                 #elif frontendData["tuner_type"] == "DVB-C":
473                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
474                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
475                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
476                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
477                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
478                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
479                         #                  ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
480                                                 #)
481                 #elif frontendData["tuner_type"] == "DVB-T":
482                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
483                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
484                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
485                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
486                                            #("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
487                                            #("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
488                                            #("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
489                                            #("Constellation", frontendData["constellation"], TYPE_TEXT),
490                                            #("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
491                                            #("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
492                                            #("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT),
493                         defaultSat = { "orbpos": 192, "system": "dvb-s", "frequency": 11836, "inversion": "auto", "symbolrate": 27500, "polarization": "horizontal", "fec": "auto", "fec_s2": "9_10", "modulation": "qpsk" }
494                         defaultCab = {"frequency": 466, "inversion": "auto", "modulation": "64qam", "fec": "auto", "symbolrate": 6900}
495                         if frontendData is not None:
496                                 ttype = frontendData.get("tuner_type", "UNKNOWN")
497                                 if ttype == "DVB-S":
498                                         defaultSat["system"] = {"DVB-S": "dvb-s", "DVB-S2": "dvb-s2"}[frontendData.get("system", "DVB-S")]
499                                         defaultSat["frequency"] = int(frontendData.get("frequency", 0) / 1000)
500                                         defaultSat["inversion"] = {"INVERSION_OFF": "off", "INVERSION_ON": "on", "INVERSION_AUTO": "auto"}[frontendData.get("inversion", "INVERSION_AUTO")]
501                                         defaultSat["symbolrate"] = int(frontendData.get("symbol_rate", 0) / 1000)
502                                         defaultSat["polarization"] = {"HORIZONTAL": "horizontal", "VERTICAL": "vertical", "CIRCULAR_LEFT": "circular_left", "CIRCULAR_RIGHT": "circular_right", "UNKNOWN": None}[frontendData.get("polarization", "HORIZONTAL")]
503
504                                         if frontendData.get("system", "DVB-S") == "DVB-S2":
505                                                 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"} \
506                                                                                         [frontendData.get("fec_inner", "FEC_AUTO")]
507                                                 defaultSat["rolloff"] = {"ROLLOFF_0_35" : "0_35", "ROLLOFF_0_25" : "0_25", "0_20" : "ROLLOFF_0_20"}[frontendData.get("rolloff", "ROLLOFF_0_35")]
508                                                 defaultSat["pilot"] = {"PILOT_ON" : "on", "PILOT_OFF" : "off", "PILOT_AUTO" : "auto"}[frontendData.get("pilot", "PILOT_AUTO")]
509                                         else:
510                                                 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"} \
511                                                         [frontendData.get("fec_inner", "FEC_AUTO")]
512
513                                         defaultSat["modulation"] = {"QPSK": "qpsk", "8PSK": "8psk"}[frontendData.get("modulation", "QPSK")]
514                                         defaultSat["orbpos"] = frontendData.get("orbital_position", 0)
515                                 elif ttype == "DVB-C":
516                                         defaultCab["frequency"] = int(frontendData.get("frequency", 0) / 1000)
517                                         defaultCab["symbolrate"] = int(frontendData.get("symbol_rate", 0) / 1000)
518                                         defaultCab["inversion"] = {"INVERSION_OFF": "off", "INVERSION_ON": "on", "INVERSION_AUTO": "auto"}[frontendData.get("inversion", "INVERSION_AUTO")]
519                                         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")]
520                                         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")]
521
522                         self.scan_sat = ConfigSubsection()
523                         self.scan_cab = ConfigSubsection()
524                         self.scan_ter = ConfigSubsection()
525
526                         self.scan_type = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat"))])
527                         self.scan_typecable = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
528                         self.scan_typeterrestrial = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
529                         self.scan_clearallservices = ConfigSelection(default = "no", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
530                         self.scan_networkScan = ConfigYesNo(default = False)
531
532                         nim_list = []
533                         # collect all nims which are *not* set to "nothing"
534                         for n in nimmanager.nim_slots:
535                                 if n.config_mode != "nothing":
536                                         nim_list.append((str(n.slot), n.friendly_full_description))
537
538                         self.scan_nims = ConfigSelection(choices = nim_list)
539
540                         # status
541                         self.scan_snr = ConfigSlider()
542                         self.scan_snr.enabled = False
543                         self.scan_agc = ConfigSlider()
544                         self.scan_agc.enabled = False
545                         self.scan_ber = ConfigSlider()
546                         self.scan_ber.enabled = False
547
548                         # sat
549                         self.scan_sat.system = ConfigSelection(default = defaultSat["system"], choices = [("dvb-s", _("DVB-S")), ("dvb-s2", _("DVB-S2"))])
550                         self.scan_sat.frequency = ConfigInteger(default = defaultSat["frequency"], limits = (1, 99999))
551                         self.scan_sat.inversion = ConfigSelection(default = defaultSat["inversion"], choices = [("off", _("off")), ("on", _("on")), ("auto", _("Auto"))])
552                         self.scan_sat.symbolrate = ConfigInteger(default = defaultSat["symbolrate"], limits = (1, 99999))
553                         self.scan_sat.polarization = ConfigSelection(default = defaultSat["polarization"], choices = [("horizontal", _("horizontal")), ("vertical", _("vertical")),  ("circular_left", _("circular left")), ("circular_right", _("circular right"))])
554                         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"))])
555                         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")])
556                         self.scan_sat.modulation = ConfigSelection(default = defaultSat["modulation"], choices = [("qpsk", "QPSK"), ("8psk", "8PSK")])
557                         self.scan_sat.rolloff = ConfigSelection(default = defaultSat.get("rolloff", "0_35"), choices = [("0_35", "0.35"), ("0_25", "0.25"), ("0_20", "0.20")])
558                         self.scan_sat.pilot = ConfigSelection(default = defaultSat.get("pilot", "auto"), choices = [("off", _("off")), ("on", _("on")), ("auto", _("Auto"))])
559
560                         # cable
561                         self.scan_cab.frequency = ConfigInteger(default = defaultCab["frequency"], limits = (50, 999))
562                         self.scan_cab.inversion = ConfigSelection(default = defaultCab["inversion"], choices = [("off", _("off")), ("on", _("on")), ("auto", _("Auto"))])
563                         self.scan_cab.modulation = ConfigSelection(default = defaultCab["modulation"], choices = [("16qam", "16-QAM"), ("32qam", "32-QAM"), ("64qam", "64-QAM"), ("128qam", "128-QAM"), ("256qam", "256-QAM")])
564                         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"))])
565                         self.scan_cab.symbolrate = ConfigInteger(default = defaultCab["symbolrate"], limits = (1, 99999))
566
567                         # terrestial
568                         self.scan_ter.frequency = ConfigInteger(default = 466000, limits = (50000, 999000))
569                         self.scan_ter.inversion = ConfigSelection(default = "auto", choices = [("off", _("off")), ("on", _("on")), ("auto", _("Auto"))])
570                         # WORKAROUND: we can't use BW-auto
571                         self.scan_ter.bandwidth = ConfigSelection(default = "8MHz", choices = [("8MHz", "8MHz"), ("7MHz", "7MHz"), ("6MHz", "6MHz")])
572                         #, ("auto", _("Auto"))))
573                         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"))])
574                         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"))])
575                         self.scan_ter.modulation = ConfigSelection(default = "auto", choices = [("qpsk", "QPSK"), ("qam16", "QAM16"), ("qam64", "QAM64"), ("auto", _("Auto"))])
576                         self.scan_ter.transmission = ConfigSelection(default = "auto", choices = [("2k", "2K"), ("8k", "8K"), ("auto", _("Auto"))])
577                         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"))])
578                         self.scan_ter.hierarchy = ConfigSelection(default = "auto", choices = [("none", _("None")), ("1", "1"), ("2", "2"), ("4", "4"), ("auto", _("Auto"))])
579
580                         self.scan_scansat = {}
581                         for sat in nimmanager.satList:
582                                 #print sat[1]
583                                 self.scan_scansat[sat[0]] = ConfigYesNo(default = False)
584
585                         self.scan_satselection = []
586                         for slot in nimmanager.nim_slots:
587                                 if slot.isCompatible("DVB-S"):
588                                         self.scan_satselection.append(getConfigSatlist(int(defaultSat["orbpos"]), self.satList[slot.slot]))
589                                 else:
590                                         self.scan_satselection.append(None)
591
592                         return True
593
594         def keyLeft(self):
595                 ConfigListScreen.keyLeft(self)
596                 self.newConfig()
597
598         def keyRight(self):
599                 ConfigListScreen.keyRight(self)
600                 self.newConfig()
601
602         def updateStatus(self):
603                 print "updatestatus"
604
605         fecmap = { "auto": 0,
606                            "1_2": 1,
607                            "2_3": 2,
608                            "3_4": 3,
609                            "5_6": 4,
610                            "7_8": 5,
611                            "8_9": 6,
612                            "3_5": 7,
613                            "4_5": 8,
614                            "9_10": 9,
615                            "none": 15
616                            }
617
618         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position, system, modulation, rolloff, pilot):
619                 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)
620                 print "orbpos: " + str(orbital_position)
621                 parm = eDVBFrontendParametersSatellite()
622                 if modulation == 1:
623                         parm.modulation = 2 # eDVBFrontendParametersSatellite.Modulation.8PSK
624                 else:
625                         parm.modulation = 1 # eDVBFrontendParametersSatellite.Modulation.QPSK
626                 parm.system = system
627                 parm.frequency = frequency * 1000
628                 parm.symbol_rate = symbol_rate * 1000
629                 parm.polarisation = polarisation
630                 parm.fec = self.fecmap[fec]
631                 parm.inversion = inversion
632                 parm.orbital_position = int(orbital_position)
633                 parm.rolloff = int(rolloff)
634                 parm.pilot = int(pilot)
635                 tlist.append(parm)
636
637         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
638                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
639                 parm = eDVBFrontendParametersCable()
640                 parm.frequency = frequency * 1000
641                 parm.symbol_rate = symbol_rate * 1000
642                 parm.modulation = modulation
643                 parm.fec = self.fecmap[fec]
644                 parm.inversion = inversion
645                 tlist.append(parm)
646
647         def addTerTransponder(self, tlist, *args, **kwargs):
648                 tlist.append(buildTerTransponder(*args, **kwargs))
649
650         def keyGo(self):
651                 tlist = []
652                 flags = None
653                 extFlags = True
654                 
655                 startScan = True
656                 index_to_scan = int(self.scan_nims.value)
657                 
658                 if self.scan_nims == [ ]:
659                         self.session.open(MessageBox, _("No tuner is enabled!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
660                         return
661
662                 nim = nimmanager.nim_slots[index_to_scan]
663                 print "nim", nim.slot
664                 if nim.isCompatible("DVB-S"):
665                         print "is compatible with DVB-S"
666                         if self.scan_type.value == "single_transponder":
667                                 # these lists are generated for each tuner, so this has work.
668                                 assert len(self.satList) > index_to_scan
669                                 assert len(self.scan_satselection) > index_to_scan
670                                 
671                                 nimsats = self.satList[index_to_scan]
672                                 selsatidx = self.scan_satselection[index_to_scan].index
673
674                                 # however, the satList itself could be empty. in that case, "index" is 0 (for "None").
675                                 if len(nimsats):
676                                         orbpos = nimsats[selsatidx][0]
677                                         if self.scan_sat.system.value == "dvb-s":
678                                                 fec = self.scan_sat.fec.value
679                                         else:
680                                                 fec = self.scan_sat.fec_s2.value
681                                         print "add sat transponder"
682                                         self.addSatTransponder(tlist, self.scan_sat.frequency.value,
683                                                                 self.scan_sat.symbolrate.value,
684                                                                 self.scan_sat.polarization.index,
685                                                                 fec,
686                                                                 self.scan_sat.inversion.index,
687                                                                 orbpos,
688                                                                 self.scan_sat.system.index,
689                                                                 self.scan_sat.modulation.index,
690                                                                 self.scan_sat.rolloff.index,
691                                                                 self.scan_sat.pilot.index)
692                                 flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
693                                 extFlags = False
694                         elif self.scan_type.value == "single_satellite":
695                                 sat = self.satList[index_to_scan][self.scan_satselection[index_to_scan].index]
696                                 getInitialTransponderList(tlist, sat[0])
697                         elif self.scan_type.value == "multisat":
698                                 SatList = nimmanager.getSatListForNim(index_to_scan)
699                                 for x in self.multiscanlist:
700                                         if x[1].value:
701                                                 print "   " + str(x[0])
702                                                 getInitialTransponderList(tlist, x[0])
703
704                 elif nim.isCompatible("DVB-C"):
705                         if self.scan_typecable.value == "single_transponder":
706                                 fec = self.scan_cab.fec.value
707                                 self.addCabTransponder(tlist, self.scan_cab.frequency.value,
708                                                                                           self.scan_cab.symbolrate.value,
709                                                                                           self.scan_cab.modulation.index + 1,
710                                                                                           fec,
711                                                                                           self.scan_cab.inversion.index)
712                                 flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
713                                 extFlags = False
714                         elif self.scan_typecable.value == "complete":
715                                 if config.Nims[index_to_scan].cable.scan_type.value == "provider":
716                                         getInitialCableTransponderList(tlist, index_to_scan)
717                                 else:
718                                         startScan = False
719
720                 elif nim.isCompatible("DVB-T"):
721                         if self.scan_typeterrestrial.value == "single_transponder":
722                                 self.addTerTransponder(tlist,
723                                                 self.scan_ter.frequency.value * 1000,
724                                                 inversion = self.scan_ter.inversion.index,
725                                                 bandwidth = self.scan_ter.bandwidth.index,
726                                                 fechigh = self.scan_ter.fechigh.index,
727                                                 feclow = self.scan_ter.feclow.index,
728                                                 modulation = self.scan_ter.modulation.index,
729                                                 transmission = self.scan_ter.transmission.index,
730                                                 guard = self.scan_ter.guard.index,
731                                                 hierarchy = self.scan_ter.hierarchy.index)
732                                 flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
733                                 extFlags = False
734                         elif self.scan_typeterrestrial.value == "complete":
735                                 getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(index_to_scan))
736
737                 if flags is None:
738                         flags = eComponentScan.scanNetworkSearch
739
740                 if extFlags:
741                         tmp = self.scan_clearallservices.value
742                         if tmp == "yes":
743                                 flags |= eComponentScan.scanRemoveServices
744                         elif tmp == "yes_hold_feeds":
745                                 flags |= eComponentScan.scanRemoveServices
746                                 flags |= eComponentScan.scanDontRemoveFeeds
747
748                 for x in self["config"].list:
749                         x[1].save()
750
751                 if startScan:
752                         self.startScan(tlist, flags, index_to_scan)
753                 else:
754                         self.flags = flags
755                         self.feid = index_to_scan
756                         self.tlist = []
757                         self.startCableTransponderSearch(self.feid)
758
759         def setCableTransponderSearchResult(self, tlist):
760                 self.tlist = tlist
761
762         def cableTransponderSearchFinished(self):
763                 self.startScan(self.tlist, self.flags, self.feid)
764
765         def startScan(self, tlist, flags, feid):
766                 if len(tlist):
767                         # flags |= eComponentScan.scanSearchBAT
768                         if self.finished_cb:
769                                 self.session.openWithCallback(self.finished_cb, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
770                         else:
771                                 self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
772                 else:
773                         if self.finished_cb:
774                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
775                         else:
776                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
777
778         def keyCancel(self):
779                 for x in self["config"].list:
780                         x[1].cancel()
781                 self.close()
782
783 class ScanSimple(ConfigListScreen, Screen, CableTransponderSearchSupport):
784         def getNetworksForNim(self, nim):
785                 if nim.isCompatible("DVB-S"):
786                         networks = nimmanager.getSatListForNim(nim.slot)
787 # the original code took "loopthrough" etc. into account. Do we need this?
788 #                       if nimmanager.getNimConfigMode(1) in ["loopthrough", "satposdepends", "equal", "nothing"]:
789 #                               return False
790 #                       sec = eDVBSatelliteEquipmentControl.getInstance()
791 #                       if sec is not None:
792 #                               exclusive_satellites = sec.get_exclusive_satellites(0,1)
793 #                               if len(exclusive_satellites) == 2:
794 #                                       return False
795 #                               idx = exclusive_satellites[0]+1
796 #                               exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
797 #                               if len(exclusive_nim_sats):
798 #                                       return True
799                 elif not nim.empty:
800                         networks = [ nim.type ] # "DVB-C" or "DVB-T". TODO: seperate networks for different C/T tuners, if we want to support that.
801                 else:
802                         # empty tuners provide no networks.
803                         networks = [ ]
804                 return networks
805
806         def __init__(self, session):
807                 Screen.__init__(self, session)
808
809                 self["actions"] = ActionMap(["SetupActions"],
810                 {
811                         "ok": self.keyGo,
812                         "cancel": self.keyCancel,
813                 }, -2)
814
815                 self.list = []
816                 tlist = []
817
818                 known_networks = [ ]
819                 nims_to_scan = [ ]
820                 self.finished_cb = None
821
822                 for nim in nimmanager.nim_slots:
823                         # collect networks provided by this tuner
824
825                         need_scan = False
826                         networks = self.getNetworksForNim(nim)
827                         
828                         print "nim %d provides" % nim.slot, networks
829                         print "known:", known_networks
830
831                         # we only need to scan on the first tuner which provides a network.
832                         # this gives the first tuner for each network priority for scanning.
833                         for x in networks:
834                                 if x not in known_networks:
835                                         need_scan = True
836                                         print x, "not in ", known_networks
837                                         known_networks.append(x)
838
839                         if need_scan:
840                                 nims_to_scan.append(nim)
841
842                 # we save the config elements to use them on keyGo
843                 self.nim_enable = [ ]
844
845                 if len(nims_to_scan):
846                         self.scan_clearallservices = ConfigSelection(default = "yes", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
847                         self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
848
849                         for nim in nims_to_scan:
850                                 nimconfig = ConfigYesNo(default = True)
851                                 nimconfig.nim_index = nim.slot
852                                 self.nim_enable.append(nimconfig)
853                                 self.list.append(getConfigListEntry(_("Scan ") + nim.slot_name + " (" + nim.friendly_type + ")", nimconfig))
854
855                 ConfigListScreen.__init__(self, self.list)
856                 self["header"] = Label(_("Automatic Scan"))
857                 self["footer"] = Label(_("Press OK to scan"))
858
859         def runAsync(self, finished_cb):
860                 self.finished_cb = finished_cb
861                 self.keyGo()
862
863         def keyGo(self):
864                 self.scanList = []
865                 self.known_networks = set()
866                 self.nim_iter=0
867                 self.buildTransponderList()
868
869         def buildTransponderList(self): # this method is called multiple times because of asynchronous stuff
870                 APPEND_NOW = 0
871                 SEARCH_CABLE_TRANSPONDERS = 1
872                 action = APPEND_NOW
873
874                 n = self.nim_iter < len(self.nim_enable) and self.nim_enable[self.nim_iter] or None
875                 self.nim_iter += 1
876                 if n:
877                         if n.value: # check if nim is enabled
878                                 flags = 0
879                                 nim = nimmanager.nim_slots[n.nim_index]
880                                 networks = set(self.getNetworksForNim(nim))
881
882                                 # don't scan anything twice
883                                 networks.discard(self.known_networks)
884
885                                 tlist = [ ]
886                                 if nim.isCompatible("DVB-S"):
887                                         # get initial transponders for each satellite to be scanned
888                                         for sat in networks:
889                                                 getInitialTransponderList(tlist, sat[0])
890                                 elif nim.isCompatible("DVB-C"):
891                                         if config.Nims[nim.slot].cable.scan_type.value == "provider":
892                                                 getInitialCableTransponderList(tlist, nim.slot)
893                                         else:
894                                                 action = SEARCH_CABLE_TRANSPONDERS
895                                 elif nim.isCompatible("DVB-T"):
896                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(nim.slot))
897                                 else:
898                                         assert False
899
900                                 flags |= eComponentScan.scanNetworkSearch #FIXMEEE.. use flags from cables / satellites / terrestrial.xml
901                                 tmp = self.scan_clearallservices.value
902                                 if tmp == "yes":
903                                         flags |= eComponentScan.scanRemoveServices
904                                 elif tmp == "yes_hold_feeds":
905                                         flags |= eComponentScan.scanRemoveServices
906                                         flags |= eComponentScan.scanDontRemoveFeeds
907
908                                 if action == APPEND_NOW:
909                                         self.scanList.append({"transponders": tlist, "feid": nim.slot, "flags": flags})
910                                 elif action == SEARCH_CABLE_TRANSPONDERS:
911                                         self.flags = flags
912                                         self.feid = nim.slot
913                                         self.startCableTransponderSearch(nim.slot)
914                                         return
915                                 else:
916                                         assert False
917
918                         self.buildTransponderList() # recursive call of this function !!!
919                         return
920                 # when we are here, then the recursion is finished and all enabled nims are checked
921                 # so we now start the real transponder scan
922                 self.startScan(self.scanList)
923
924         def startScan(self, scanList):
925                 if len(scanList):
926                         if self.finished_cb:
927                                 self.session.openWithCallback(self.finished_cb, ServiceScan, scanList = scanList)
928                         else:
929                                 self.session.open(ServiceScan, scanList = scanList)
930                 else:
931                         if self.finished_cb:
932                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
933                         else:
934                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
935
936         def setCableTransponderSearchResult(self, tlist):
937                 self.scanList.append({"transponders": tlist, "feid": self.feid, "flags": self.flags})
938
939         def cableTransponderSearchFinished(self):
940                 self.buildTransponderList()
941
942         def keyCancel(self):
943                 self.close()
944
945         def Satexists(self, tlist, pos):
946                 for x in tlist:
947                         if x == pos:
948                                 return 1
949                 return 0
950