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