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