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