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