4.3.1r21
[enigma2.git] / usr / lib / enigma2 / 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, ConfigOnOff, ConfigText, ConfigFloat
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.Transponder import ConvertToHumanReadable
12 from Tools.BoundFunction import boundFunction
13 from Screens.MessageBox import MessageBox
14 from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, \
15         eDVBSatelliteEquipmentControl as secClass, eDVBFrontendParametersTerrestrial, \
16         eDVBFrontendParametersCable, eConsoleAppContainer, eDVBResourceManager, \
17         eDVBFrontendParameters, iDVBFrontend
18
19 feTerrestrial = iDVBFrontend.feTerrestrial
20 feSatellite = iDVBFrontend.feSatellite
21 feCable = iDVBFrontend.feCable
22 stateLock = iDVBFrontend.stateLock
23 stateFailed = iDVBFrontend.stateFailed
24 stateTuning = iDVBFrontend.stateTuning
25
26 can_t_t2_auto_delsys = [ 'Si2169C', 'Si2169D', 'ATBM781x' ]
27
28 def buildTerTransponder(frequency,
29                 system = eDVBFrontendParametersTerrestrial.System_DVB_T,
30                 inversion = 2, bandwidth = 0, crh = 5, crl = 5,
31                 modulation = 2, transmission = 2, guard = 4,
32                 hierarchy = 4, plp_id = -1):
33 #       print "system", system, "freq", frequency, "inv", inversion, "bw", bandwidth, "fech", crh, "fecl", crl, "mod", modulation, "tm", transmission, "guard", guard, "hierarchy", hierarchy, "plp_id", plp_id
34
35         parm = eDVBFrontendParametersTerrestrial()
36         parm.system = system
37         parm.frequency = frequency
38         parm.inversion = inversion
39         parm.bandwidth = bandwidth
40         parm.code_rate_HP = crh # only DVB-T
41         parm.code_rate_LP = crl # this is the fec for DVB-T2
42         parm.modulation = modulation
43         parm.transmission_mode = transmission
44         parm.guard_interval = guard
45         parm.hierarchy = hierarchy # only DVB-T
46         parm.plp_id = plp_id # only DVB-T2
47         return parm
48
49 def getInitialTransponderList(tlist, pos):
50         list = nimmanager.getTransponders(pos)
51         for x in list:
52                 if x[0] == 0:           #SAT
53                         parm = eDVBFrontendParametersSatellite()
54                         parm.frequency = x[1]
55                         parm.symbol_rate = x[2]
56                         parm.polarisation = x[3]
57                         parm.fec = x[4]
58                         parm.inversion = x[7]
59                         parm.orbital_position = pos
60                         parm.system = x[5]
61                         parm.modulation = x[6]
62                         parm.rolloff = x[8]
63                         parm.pilot = x[9]
64                         parm.is_id = x[12]
65                         parm.pls_mode = x[13]
66                         parm.pls_code = x[14]
67                         tlist.append(parm)
68
69 def getInitialCableTransponderList(tlist, nim):
70         list = nimmanager.getTranspondersCable(nim)
71         for x in list:
72                 if x[0] == 1: #CABLE
73                         parm = eDVBFrontendParametersCable()
74                         parm.frequency = x[1]
75                         parm.symbol_rate = x[2]
76                         parm.modulation = x[3]
77                         parm.fec_inner = x[4]
78                         parm.inversion = parm.Inversion_Unknown
79                         #print "frequency:", x[1]
80                         #print "symbol_rate:", x[2]
81                         #print "modulation:", x[3]
82                         #print "fec_inner:", x[4]
83                         #print "inversion:", 2
84                         tlist.append(parm)
85
86 def getInitialTerrestrialTransponderList(tlist, region, can_t_t2_auto_delsys):
87         list = nimmanager.getTranspondersTerrestrial(region)
88
89         #self.transponders[self.parsedTer].append((2,freq,bw,const,crh,crl,guard,transm,hierarchy,inv))
90
91         #def buildTerTransponder(frequency,
92         #       system = eDVBFrontendParametersTerrestrial.System_DVB_T,
93         #       inversion = 2, bandwidth = 0, crh = 5, crl = 5,
94         #       modulation = 2, transmission = 2, guard = 4,
95         #       hierarchy = 4, plp_id = -1):
96
97         for x in list:
98                 if x[0] == 2: #TERRESTRIAL
99                         system = x[10] if not can_t_t2_auto_delsys or x[10] == eDVBFrontendParametersTerrestrial.System_DVB_T2 else eDVBFrontendParametersTerrestrial.System_DVB_T_T2
100                         parm = buildTerTransponder(x[1], system, x[9], x[2], x[4], x[5], x[3], x[7], x[6], x[8], x[11])
101                         tlist.append(parm)
102
103 cable_bands = {
104         "DVBC_BAND_EU_VHF_I" : 1 << 0,
105         "DVBC_BAND_EU_MID" : 1 << 1,
106         "DVBC_BAND_EU_VHF_III" : 1 << 2,
107         "DVBC_BAND_EU_SUPER" : 1 << 3,
108         "DVBC_BAND_EU_HYPER" : 1 << 4,
109         "DVBC_BAND_EU_UHF_IV" : 1 << 5,
110         "DVBC_BAND_EU_UHF_V" : 1 << 6,
111         "DVBC_BAND_US_LO" : 1 << 7,
112         "DVBC_BAND_US_MID" : 1 << 8,
113         "DVBC_BAND_US_HI" : 1 << 9,
114         "DVBC_BAND_US_SUPER" : 1 << 10,
115         "DVBC_BAND_US_HYPER" : 1 << 11,
116         "DVBC_BAND_US_ULTRA" : 1 << 12,
117         "DVBC_BAND_US_JUMBO" : 1 << 13,
118 }
119
120 class TransponderSearchSupport:
121         def tryGetRawFrontend(self, feid, ret_boolean=True, do_close=True):
122                 res_mgr = eDVBResourceManager.getInstance()
123                 if res_mgr:
124                         raw_channel = res_mgr.allocateRawChannel(self.feid)
125                         if raw_channel:
126                                 frontend = raw_channel.getFrontend()
127                                 if frontend:
128                                         if do_close:
129                                                 frontend.closeFrontend() # immediate close... 
130                                         if ret_boolean:
131                                                 del raw_channel
132                                                 del frontend
133                                                 return True
134                                         return raw_channel, frontend
135                 if ret_boolean:
136                         return False
137                 return (False, False)
138
139 def CableScanHelperDMM(nim_idx):
140         bus = nimmanager.getI2CDevice(nim_idx)
141         tunername = nimmanager.getNimName(nim_idx)
142         cableScanHelpers = {
143                 'CXD1981': 'cxd1978',
144                 'Philips CU1216Mk3': 'tda1002x',
145                 'ATBM781x': 'atbm781x',
146         }
147         cmd = cableScanHelpers.get(tunername, None)
148         if cmd is not None:
149                 cmd += " --init --scan --verbose --wakeup --inv 2 --bus %d" % bus
150         return cmd
151
152 class CableTransponderSearchSupport:
153         CableScanHelpers = [ CableScanHelperDMM ]
154
155 # functions for driver based blindscan
156
157         def updateStateCable(self):
158                 self.frontendStateChangedCable(None)
159
160         def frontendStateChangedCable(self, frontend_ptr):
161                 x = { }
162                 self.frontend.getFrontendStatus(x)
163                 assert x, "getFrontendStatus failed!"
164                 tuner_state = x["tuner_state"]
165                 if tuner_state in (stateLock, stateFailed) or frontend_ptr is None:
166                         d = { }
167                         self.frontend.getTransponderData(d, False)
168                         freq = int(round(float(d["frequency"]*2) / 1000)) * 1000
169                         freq /= 2
170
171                         if tuner_state == stateLock:
172                                 parm = eDVBFrontendParametersCable()
173                                 parm.frequency = freq
174                                 fstr = str(parm.frequency)
175
176                                 sr = d["symbol_rate"]
177                                 sr_rounded = round(float(sr*2L) / 1000) * 1000
178                                 sr_rounded /= 2
179 #                               print "SR after round", sr_rounded
180                                 parm.symbol_rate = int(sr_rounded)
181                                 fstr += " "
182                                 fstr += str(parm.symbol_rate/1000)
183
184                                 parm.fec = d["fec_inner"]
185                                 parm.inversion = eDVBFrontendParametersCable.Inversion_Unknown
186                                 parm.modulation = d["modulation"]
187
188                                 self.__tlist.append(parm)
189
190                                 print "LOCKED at", freq, sr
191
192                                 status = _("OK")
193
194                                 self.frontend.tune(self.tparm)
195                         elif frontend_ptr:
196                                 self.cable_search_session.close(True)
197                                 return
198                         else:
199                                 fstr = str(freq)
200                                 status = _("in progress")
201                                 print "SEARCHING at", freq
202
203                         tmpstr = _("Try to find used Transponders in cable network.. please wait...")
204                         tmpstr += "\n\n"
205                         tmpstr += fstr
206                         tmpstr += " "
207                         tmpstr += _("kHz")
208                         tmpstr += " - "
209                         tmpstr += status
210                         self.cable_search_session["text"].setText(tmpstr)
211
212                         self.updateStateTimer.start(1000, True)
213
214         def cableTransponderSearchSessionClosed(self, *val):
215                 print "cableTransponderSearchSessionClosed, val", val
216                 self.appClosed_conn = None
217                 self.dataAvail_conn = None
218
219                 # driver based scan...
220                 self.frontendStateChanged_conn = None
221                 self.frontend = None
222                 self.channel = None
223                 self.updateStateTimer_conn = None
224                 self.updateStateTimer = None
225
226                 if val and len(val):
227                         if val[0]:
228                                 self.setTransponderSearchResult(self.__tlist)
229                         else:
230                                 if self.cable_search_container is not None:
231                                         self.cable_search_container.sendCtrlC()
232                                 self.setTransponderSearchResult(None)
233
234                 # external app based scan
235                 self.cable_search_container = None
236                 self.cable_search_session = None
237
238                 self.__tlist = None
239                 self.TransponderSearchFinished()
240
241 # functions for external app based transponder search support
242
243         def cableTransponderSearchClosed(self, retval):
244                 print "cableTransponderSearch finished", retval
245                 self.cable_search_session.close(True)
246
247         def getCableTransponderData(self, str):
248                 data = str.split()
249                 if len(data) and data[0] in ("OK", "FAILED"):
250                         if data[0] == 'OK':
251                                 print str
252                                 parm = eDVBFrontendParametersCable()
253                                 qam = { "QAM16" : parm.Modulation_QAM16,
254                                         "QAM32" : parm.Modulation_QAM32,
255                                         "QAM64" : parm.Modulation_QAM64,
256                                         "QAM128" : parm.Modulation_QAM128,
257                                         "QAM256" : parm.Modulation_QAM256,
258                                         "QAM_AUTO" : parm.Modulation_Auto }
259                                 #inv = { "INVERSION_OFF" : parm.Inversion_Off,
260                                 #       "INVERSION_ON" : parm.Inversion_On,
261                                 #       "INVERSION_AUTO" : parm.Inversion_Unknown }
262                                 fec = { "FEC_AUTO" : parm.FEC_Auto,
263                                         "FEC_1_2" : parm.FEC_1_2,
264                                         "FEC_2_3" : parm.FEC_2_3,
265                                         "FEC_3_4" : parm.FEC_3_4,
266                                         "FEC_5_6": parm.FEC_5_6,
267                                         "FEC_7_8" : parm.FEC_7_8,
268                                         "FEC_8_9" : parm.FEC_8_9,
269                                         "FEC_NONE" : parm.FEC_None }
270                                 parm.frequency = int(data[1])
271                                 parm.symbol_rate = int(data[2])
272                                 parm.fec_inner = fec[data[3]]
273                                 parm.modulation = qam[data[4]]
274 #                               parm.inversion = inv[data[5]]
275                                 parm.inversion = eDVBFrontendParametersCable.Inversion_Unknown
276                                 self.__tlist.append(parm)
277                                 status = _("OK")
278                         else:
279                                 status = _("No signal")
280
281                         tmpstr = _("Try to find used Transponders in cable network.. please wait...")
282                         tmpstr += "\n\n"
283                         tmpstr += data[1]
284                         tmpstr += " "
285                         tmpstr += _("kHz")
286                         tmpstr += " - "
287                         tmpstr += status
288                         self.cable_search_session["text"].setText(tmpstr)
289
290         def startCableTransponderSearch(self, nim_idx):
291                 tunername = nimmanager.getNimName(nim_idx)
292                 self.cable_search_container = None
293                 if tunername.startswith("Si2169"):
294                         (self.channel, self.frontend) = self.tryGetRawFrontend(nim_idx, False, False)
295                         if not self.frontend:
296                                 self.session.nav.stopService()
297                                 (self.channel, self.frontend) = self.tryGetRawFrontend(nim_idx, False, False)
298                                 if not self.frontend:
299                                         if self.session.pipshown: # try to disable pip
300                                                 self.session.pipshown = False
301                                                 self.session.deleteDialog(self.session.pip)
302                                                 del self.session.pip
303                                         (self.channel, self.frontend) = self.tryGetRawFrontend(nim_idx, False, False)
304                                         if not self.frontend:
305                                                 print "couldn't allocate tuner %d for blindscan!!!" %nim_idx
306                                                 return
307                         self.__tlist = [ ]
308                         self.frontendStateChanged_conn = self.frontend.getStateChangeSignal().connect(self.frontendStateChangedCable)
309
310                         parm = eDVBFrontendParametersCable()
311                         parm.frequency = 47000
312                         parm.symbol_rate = (862000 - parm.frequency) / 1000
313                         parm.fec_inner = eDVBFrontendParametersCable.FEC_Auto
314                         parm.modulation = eDVBFrontendParametersCable.Modulation_Auto
315                         parm.inversion = eDVBFrontendParametersCable.Inversion_Unknown
316
317                         self.tparm = eDVBFrontendParameters()
318                         self.tparm.setDVBC(parm)
319                         self.frontend.tune(self.tparm)
320
321                         self.updateStateTimer = eTimer()
322                         self.updateStateTimer_conn = self.updateStateTimer.timeout.connect(self.updateStateCable)
323                         self.updateStateTimer.start(1000, True)
324
325                         tmpstr = _("Try to find used transponders in cable network.. please wait...")
326                         tmpstr += "\n\n..."
327                         self.cable_search_session = self.session.openWithCallback(self.cableTransponderSearchSessionClosed, MessageBox, tmpstr, MessageBox.TYPE_INFO)
328                 else:
329                         if not self.tryGetRawFrontend(nim_idx):
330                                 self.session.nav.stopService()
331                                 if not self.tryGetRawFrontend(nim_idx):
332                                         if self.session.pipshown: # try to disable pip
333                                                 self.session.pipshown = False
334                                                 self.session.deleteDialog(self.session.pip)
335                                                 del self.session.pip
336                                         if not self.tryGetRawFrontend(nim_idx):
337                                                 self.TransponderSearchFinished()
338                                                 return
339                         self.__tlist = [ ]
340                         self.cable_search_container = eConsoleAppContainer()
341                         self.appClosed_conn = self.cable_search_container.appClosed.connect(self.cableTransponderSearchClosed)
342                         self.dataAvail_conn = self.cable_search_container.dataAvail.connect(self.getCableTransponderData)
343                         cableConfig = config.Nims[nim_idx].cable
344
345                         cmd = None
346                         for fnc in self.CableScanHelpers:
347                                 cmd = fnc(nim_idx)
348                                 if cmd is not None:
349                                         break
350
351                         if cmd is not None:
352                                 if cableConfig.scan_type.value == "bands":
353                                         if cmd.startswith("cxd1978") or cmd.startswith("tda1002x") or cmd.startswith("atbm781x"):
354                                                 cmd += " --scan-flags DVB-C"
355                                                 EU = False
356                                                 US = False
357                                                 VHF_I = False
358                                                 VHF_II = False
359                                                 VHF_III = False
360                                                 UHF_IV = False
361                                                 UHF_V = False
362                                                 SUPER = False
363                                                 HYPER = False
364
365                                                 if cableConfig.scan_band_EU_VHF_I.value:
366                                                         VHF_I = True
367                                                         EU = True
368                                                 if cableConfig.scan_band_EU_MID.value:
369                                                         VHF_II = True
370                                                         EU = True
371                                                 if cableConfig.scan_band_EU_VHF_III.value:
372                                                         VHF_III = True
373                                                         EU = True
374                                                 if cableConfig.scan_band_EU_UHF_IV.value:
375                                                         UHF_IV = True
376                                                         EU = True
377                                                 if cableConfig.scan_band_EU_UHF_V.value:
378                                                         UHF_V = True
379                                                         EU = True
380                                                 if cableConfig.scan_band_EU_SUPER.value:
381                                                         SUPER = True
382                                                         EU = True
383                                                 if cableConfig.scan_band_EU_HYPER.value:
384                                                         HYPER = True
385                                                         EU = True
386
387                                                 if cableConfig.scan_band_US_LOW.value:
388                                                         VHF_I = True
389                                                         US = True
390                                                 if cableConfig.scan_band_US_MID.value:
391                                                         VHF_II = True
392                                                         US = True
393                                                 if cableConfig.scan_band_US_HIGH.value:
394                                                         VHF_III = True
395                                                         US = True
396                                                 if cableConfig.scan_band_US_SUPER.value:
397                                                         SUPER = True
398                                                         US = True
399                                                 if cableConfig.scan_band_US_HYPER.value:
400                                                         HYPER = True
401                                                         US = True
402                                                 if cableConfig.scan_band_US_ULTRA.value:
403                                                         UHF_IV = True
404                                                         US = True
405                                                 if cableConfig.scan_band_US_JUMBO.value:
406                                                         UHF_V = True
407                                                         US = True
408
409                                                 if EU:
410                                                         cmd += ":EU"
411                                                 if US:
412                                                         cmd += ":US"
413                                                 if VHF_I:
414                                                         cmd += ":VHF_I"
415                                                 if VHF_II:
416                                                         cmd += ":VHF_II"
417                                                 if VHF_III:
418                                                         cmd += ":VHF_III"
419                                                 if UHF_IV:
420                                                         cmd += ":UHF_IV"
421                                                 if UHF_V:
422                                                         cmd += ":UHF_V"
423                                                 if SUPER:
424                                                         cmd += ":SUPER"
425                                                 if HYPER:
426                                                         cmd += ":HYPER"
427                                         else: # legacy api maybe for external USB tuners...
428                                                 cmd += " --scan-bands "
429                                                 bands = 0
430                                                 if cableConfig.scan_band_EU_VHF_I.value:
431                                                         bands |= cable_bands["DVBC_BAND_EU_VHF_I"]
432                                                 if cableConfig.scan_band_EU_MID.value:
433                                                         bands |= cable_bands["DVBC_BAND_EU_MID"]
434                                                 if cableConfig.scan_band_EU_VHF_III.value:
435                                                         bands |= cable_bands["DVBC_BAND_EU_VHF_III"]
436                                                 if cableConfig.scan_band_EU_UHF_IV.value:
437                                                         bands |= cable_bands["DVBC_BAND_EU_UHF_IV"]
438                                                 if cableConfig.scan_band_EU_UHF_V.value:
439                                                         bands |= cable_bands["DVBC_BAND_EU_UHF_V"]
440                                                 if cableConfig.scan_band_EU_SUPER.value:
441                                                         bands |= cable_bands["DVBC_BAND_EU_SUPER"]
442                                                 if cableConfig.scan_band_EU_HYPER.value:
443                                                         bands |= cable_bands["DVBC_BAND_EU_HYPER"]
444                                                 if cableConfig.scan_band_US_LOW.value:
445                                                         bands |= cable_bands["DVBC_BAND_US_LO"]
446                                                 if cableConfig.scan_band_US_MID.value:
447                                                         bands |= cable_bands["DVBC_BAND_US_MID"]
448                                                 if cableConfig.scan_band_US_HIGH.value:
449                                                         bands |= cable_bands["DVBC_BAND_US_HI"]
450                                                 if cableConfig.scan_band_US_SUPER.value:
451                                                         bands |= cable_bands["DVBC_BAND_US_SUPER"]
452                                                 if cableConfig.scan_band_US_HYPER.value:
453                                                         bands |= cable_bands["DVBC_BAND_US_HYPER"]
454                                                 if cableConfig.scan_band_US_ULTRA.value:
455                                                         bands |= cable_bands["DVBC_BAND_US_ULTRA"]
456                                                 if cableConfig.scan_band_US_JUMBO.value:
457                                                         bands |= cable_bands["DVBC_BAND_US_JUMBO"]
458                                                 cmd += str(bands)
459                                 else:
460                                         cmd += " --scan-stepsize "
461                                         cmd += str(cableConfig.scan_frequency_steps.value)
462
463                                 if cmd.startswith("atbm781x"):
464                                         cmd += " --timeout 800"
465                                 else:
466                                         if cableConfig.scan_mod_qam16.value:
467                                                 cmd += " --mod 16"
468                                         if cableConfig.scan_mod_qam32.value:
469                                                 cmd += " --mod 32"
470                                         if cableConfig.scan_mod_qam64.value:
471                                                 cmd += " --mod 64"
472                                         if cableConfig.scan_mod_qam128.value:
473                                                 cmd += " --mod 128"
474                                         if cableConfig.scan_mod_qam256.value:
475                                                 cmd += " --mod 256"
476                                         if cableConfig.scan_sr_6900.value:
477                                                 cmd += " --sr 6900000"
478                                         if cableConfig.scan_sr_6875.value:
479                                                 cmd += " --sr 6875000"
480                                         if cableConfig.scan_sr_ext1.value > 450:
481                                                 cmd += " --sr "
482                                                 cmd += str(cableConfig.scan_sr_ext1.value)
483                                                 cmd += "000"
484                                         if cableConfig.scan_sr_ext2.value > 450:
485                                                 cmd += " --sr "
486                                                 cmd += str(cableConfig.scan_sr_ext2.value)
487                                                 cmd += "000"
488
489                                 print "DVB-C scan command: ", cmd
490
491                                 # we need a timer here because our frontends are running in other threads... so delay is called later...
492                                 self.delayTimer = eTimer()
493                                 self.delayTimer_conn = self.delayTimer.timeout.connect(boundFunction(lambda self, cmd: self.cable_search_container and self.cable_search_container.execute(cmd), self, cmd))
494                                 self.delayTimer.start(1000, True)
495
496                                 tmpstr = _("Try to find used transponders in cable network.. please wait...")
497                                 tmpstr += "\n\n..."
498                                 self.cable_search_session = self.session.openWithCallback(self.cableTransponderSearchSessionClosed, MessageBox, tmpstr, MessageBox.TYPE_INFO)
499                         else:
500                                 modulations = []
501                                 symbol_rates = []
502                                 frequencies = []
503
504                                 if cableConfig.scan_type.value == "bands":
505                                         if cableConfig.scan_band_US_LOW.value:
506                                                 frequencies.extend(range(54000, 84000 + 1, 6000))
507                                         if cableConfig.scan_band_US_MID.value:
508                                                 frequencies.extend(range(91250, 115250 + 1, 6000))
509                                                 frequencies.extend(range(120000, 168000 + 1, 6000))
510                                         if cableConfig.scan_band_US_HIGH.value:
511                                                 frequencies.extend(range(174000, 210000 + 1, 6000))
512                                         if cableConfig.scan_band_US_SUPER.value:
513                                                 frequencies.extend(range(216000, 294000 + 1, 6000))
514                                         if cableConfig.scan_band_US_HYPER.value:
515                                                 frequencies.extend(range(300000, 462000 + 1, 6000))
516                                         if cableConfig.scan_band_US_ULTRA.value:
517                                                 frequencies.extend(range(468000, 642000 + 1, 6000))
518                                         if cableConfig.scan_band_US_JUMBO.value:
519                                                 frequencies.extend(range(648000, 996000 + 1, 6000))
520
521                                         if cableConfig.scan_band_EU_VHF_I.value:
522                                                 frequencies.extend(range(50500, 64500 + 1, 7000))
523                                                 frequencies.extend(range(69000, 77000 + 1, 8000))
524                                         if cableConfig.scan_band_EU_MID.value:
525                                                 frequencies.append(101000)
526                                                 frequencies.extend(range(113000, 121000 + 1, 8000))
527                                                 frequencies.extend(range(128500, 170500 + 1, 7000))
528                                         if cableConfig.scan_band_EU_VHF_III.value:
529                                                 frequencies.extend(range(177500, 226500 + 1, 7000))
530                                         if cableConfig.scan_band_EU_SUPER.value:
531                                                 frequencies.extend(range(233500, 296500 + 1, 7000))
532                                         if cableConfig.scan_band_EU_HYPER.value:
533                                                 frequencies.extend(range(306000, 466000 + 1, 8000))
534                                         if cableConfig.scan_band_EU_UHF_IV.value:
535                                                 frequencies.extend(range(474000, 602000 + 1, 8000))
536                                         if cableConfig.scan_band_EU_UHF_V.value:
537                                                 frequencies.extend(range(610000, 858000 + 1, 8000))
538                                 else:
539                                         frequencies.extend(range(17000, 999000 + 1, cableConfig.scan_frequency_steps.value))
540
541                                 if cableConfig.scan_mod_qam16.value:
542                                         modulations.append(eDVBFrontendParametersCable.Modulation_QAM16)
543                                 if cableConfig.scan_mod_qam32.value:
544                                         modulations.append(eDVBFrontendParametersCable.Modulation_QAM32)
545                                 if cableConfig.scan_mod_qam64.value:
546                                         modulations.append(eDVBFrontendParametersCable.Modulation_QAM64)
547                                 if cableConfig.scan_mod_qam128.value:
548                                         modulations.append(eDVBFrontendParametersCable.Modulation_QAM128)
549                                 if cableConfig.scan_mod_qam256.value:
550                                         modulations.append(eDVBFrontendParametersCable.Modulation_QAM256)
551                                 if cableConfig.scan_sr_6900.value:
552                                         symbol_rates.append(6900000)
553                                 if cableConfig.scan_sr_6875.value:
554                                         symbol_rates.append(6875000)
555                                 if cableConfig.scan_sr_ext1.value > 450:
556                                         symbol_rates.append(cableConfig.scan_sr_ext1.value * 1000)
557                                 if cableConfig.scan_sr_ext2.value > 450:
558                                         symbol_rates.append(cableConfig.scan_sr_ext2.value * 1000)
559
560                                 for frequency in frequencies:
561                                         for modulation in modulations:
562                                                 for symbol_rate in symbol_rates:
563                                                         parm = eDVBFrontendParametersCable()
564                                                         parm.frequency = frequency
565                                                         parm.symbol_rate = symbol_rate
566                                                         parm.fec_inner = eDVBFrontendParametersCable.FEC_Auto
567                                                         parm.modulation = modulation
568                                                         parm.inversion = eDVBFrontendParametersCable.Inversion_Unknown
569                                                         self.__tlist.append(parm)
570
571                                 # XXX: I'm a hack. Please replace me!
572                                 self.cable_search_session = self.session.openWithCallback(self.cableTransponderSearchSessionClosed, MessageBox, "", MessageBox.TYPE_INFO)
573                                 self.cable_search_session.close(True)
574
575 class TerrestrialTransponderSearchSupport:
576
577         def updateStateTerrestrial(self):
578                 self.frontendStateChangedTerrestrial(None)
579
580         def frontendStateChangedTerrestrial(self, frontend_ptr):
581                 x = { }
582                 self.frontend.getFrontendStatus(x)
583                 assert x, "getFrontendStatus failed!"
584                 tuner_state = x["tuner_state"]
585                 if tuner_state in (stateLock, stateFailed) or frontend_ptr is None:
586                         d = { }
587                         self.frontend.getTransponderData(d, False)
588
589                         freq = int(round(float(d["frequency"]*2) / 1000)) * 1000
590                         freq /= 2
591
592                         if tuner_state == stateLock:
593                                 d["tuner_type"] = feTerrestrial
594                                 r = ConvertToHumanReadable(d)
595
596                                 parm = eDVBFrontendParametersTerrestrial()
597                                 parm.system = d["system"]
598                                 parm.frequency = freq
599                                 parm.bandwidth = d["bandwidth"]
600                                 parm.guard_interval = d["guard_interval"]
601                                 parm.modulation = d["constellation"]
602                                 parm.transmission_mode = d["transmission_mode"]
603                                 parm.inversion = eDVBFrontendParametersTerrestrial.Inversion_Unknown
604                                 if parm.system == eDVBFrontendParametersTerrestrial.System_DVB_T:
605                                         parm.code_rate_LP = d["code_rate_lp"]
606                                         parm.code_rate_HP = d["code_rate_hp"]
607                                         parm.hierarchy = d["hierarchy_information"]
608                                 else:
609                                         parm.code_rate_LP = d["fec_inner"]
610                                         parm.plpid = d["plp_id"]
611
612                                 fstr = r["system"] + " "
613
614                                 fstr += str(parm.frequency)
615
616                                 self.__tlist.append(parm)
617
618                                 print "LOCKED", r["system"], freq
619
620                                 status = _("OK")
621
622                                 self.frontend.tune(self.tparm)
623                         elif frontend_ptr:
624                                 self.terrestrial_search_session.close(True)
625                                 return
626                         else:
627                                 fstr = str(freq)
628                                 status = _("in progress")
629                                 print "SEARCHING at", freq
630
631                         tmpstr = _("Try to find used Transponders in terrestrial network.. please wait...")
632                         tmpstr += "\n\n"
633                         tmpstr += fstr
634                         tmpstr += " "
635                         tmpstr += _("kHz")
636                         tmpstr += " - "
637                         tmpstr += status
638                         self.terrestrial_search_session["text"].setText(tmpstr)
639
640                         self.updateStateTimer.start(1000, True)
641
642         def terrestrialTransponderSearchSessionClosed(self, *val):
643                 print "terrestrialTransponderSearchSessionClosed, val", val
644                 # driver based scan...
645                 self.frontendStateChanged_conn = None
646                 self.frontend = None
647                 self.channel = None
648                 self.updateStateTimer_conn = None
649                 self.updateStateTimer = None
650
651                 if val and len(val):
652                         if val[0]:
653                                 self.setTransponderSearchResult(self.__tlist)
654                         else:
655                                 self.setTransponderSearchResult(None)
656
657                 self.__tlist = None
658                 self.TransponderSearchFinished()
659
660         def startTerrestrialTransponderSearch(self, nim_idx):
661                 self.cable_search_container = None
662                 (self.channel, self.frontend) = self.tryGetRawFrontend(nim_idx, False, False)
663                 if not self.frontend:
664                         self.session.nav.stopService()
665                         (self.channel, self.frontend) = self.tryGetRawFrontend(nim_idx, False, False)
666                         if not self.frontend:
667                                 if self.session.pipshown: # try to disable pip
668                                         self.session.pipshown = False
669                                         self.session.deleteDialog(self.session.pip)
670                                         del self.session.pip
671                                 (self.channel, self.frontend) = self.tryGetRawFrontend(nim_idx, False, False)
672                                 if not self.frontend:
673                                         print "couldn't allocate tuner %d for blindscan!!!" %nim_idx
674                                         return
675                 self.__tlist = [ ]
676                 self.frontendStateChanged_conn = self.frontend.getStateChangeSignal().connect(self.frontendStateChangedTerrestrial)
677
678                 parm = eDVBFrontendParametersTerrestrial()
679                 parm.frequency = 47000000;
680                 parm.bandwidth = (862000000 - parm.frequency) / 1000000
681                 parm.code_rate_LP = parm.code_rate_HP = eDVBFrontendParametersTerrestrial.FEC_Auto
682                 parm.transmission_mode = eDVBFrontendParametersTerrestrial.TransmissionMode_Auto
683                 parm.guard_interval = eDVBFrontendParametersTerrestrial.GuardInterval_Auto
684                 parm.modulation = eDVBFrontendParametersTerrestrial.Modulation_Auto
685                 parm.inversion = eDVBFrontendParametersTerrestrial.Inversion_Unknown
686                 parm.hierarchy = eDVBFrontendParametersTerrestrial.Hierarchy_Auto
687                 parm.system = eDVBFrontendParametersTerrestrial.System_DVB_T2
688
689                 self.tparm = eDVBFrontendParameters()
690                 self.tparm.setDVBT(parm)
691                 self.frontend.tune(self.tparm)
692
693                 self.updateStateTimer = eTimer()
694                 self.updateStateTimer_conn = self.updateStateTimer.timeout.connect(self.updateStateTerrestrial)
695                 self.updateStateTimer.start(1000, True)
696
697                 tmpstr = _("Try to find used transponders in terrestrial network.. please wait...")
698                 tmpstr += "\n\n..."
699                 self.terrestrial_search_session = self.session.openWithCallback(self.terrestrialTransponderSearchSessionClosed, MessageBox, tmpstr, MessageBox.TYPE_INFO)
700
701 from time import time
702
703 FOUND_HISTORY_SIZE = 8
704
705 from Components.Sources.CanvasSource import CanvasSource
706 from Components.Sources.List import List
707 from Tools.Directories import fileExists
708
709 class SatBlindscanState(Screen):
710         def __init__(self, session, fe_num, text):
711                 Screen.__init__(self, session)
712                 self["list"]=List()
713                 self["text"]=Label()
714                 self["text"].setText(text)
715                 self["post_action"]=Label()
716                 self["progress"]=Label()
717                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
718                 {
719                         "ok": self.keyOk,
720                         "cancel": self.keyCancel,
721                         "green": self.keyGreen,
722                 }, -2)
723                 self.fe_num = fe_num
724                 self["constellation"] = CanvasSource()
725                 self.onLayoutFinish.append(self.updateConstellation)
726                 self.tmr = eTimer()
727                 self.tmr_conn = self.tmr.timeout.connect(self.updateConstellation)
728                 self.constellation_supported = None
729                 if fe_num != -1:
730                         self.post_action=1
731                         self.finished=0
732                         self.keyGreen()
733                 else:
734                         self.post_action=-1
735
736         def keyGreen(self):
737                 if self.finished:
738                         self.close(True)
739                 elif self.post_action != -1:
740                         self.post_action ^= 1
741                         if self.post_action:
742                                 self["post_action"].setText(_("MANUALLY start service searching, press green to change"))
743                         else:
744                                 self["post_action"].setText(_("AUTOMATICALLY start service searching, press green to change"))
745
746         def setFinished(self):
747                 if self.post_action:
748                         self.finished=1
749                         self["text"].setText(_("Transponder searching finished!"))
750                         self["post_action"].setText(_("Press green to start service searching!"))
751                 else:
752                         self.close(True)
753
754         def getConstellationBitmap(self, cnt=1):
755                 ret = []
756                 path = "/proc/stb/frontend/%d/constellation_bitmap" %self.fe_num
757                 if self.constellation_supported is None:
758                         s = fileExists(path)
759                         self.constellation_supported = s
760                         if not s:
761                                 self["constellation"].fill(0,0,256,256,0x25101010)
762                                 self["constellation"].flush()
763
764                 if self.constellation_supported:
765                         while cnt > 0:
766                                 f = open(path, "r")
767                                 ret.append(f.readline())
768                                 cnt -= 1
769                                 f.close()
770                 return ret
771
772         def updateConstellation(self, constellation_bitmap_list=None):
773                 if self.constellation_supported or self.constellation_supported is None:
774                         pass
775                 else:
776                         return
777                 self["constellation"].fill(0,0,256,256,0x25101010)
778                 if constellation_bitmap_list:
779                         bitmap_list = constellation_bitmap_list
780                 else:
781                         bitmap_list = self.getConstellationBitmap()
782                 for bitmap in bitmap_list:
783                         Q = []
784                         I = []
785                         for pos in range(0,30,2):
786                                 try:
787                                         val = int(bitmap[pos:pos+2], 16)
788                                         val = 128 + (val - 256 if val > 127 else val)
789                                 except ValueError:
790                                         print "I constellation data broken at pos", pos
791                                         val = 0
792                                 I.append(val)
793                         for pos in range(30,60,2):
794                                 try:
795                                         val = int(bitmap[pos:pos+2], 16)
796                                         val = 128 + (val - 256 if val > 127 else val)
797                                 except ValueError:
798                                         print "Q constellation data broken at pos", pos
799                                         val = 0
800                                 Q.append(val)
801                         for i in range(15):
802                                 self["constellation"].fill(I[i],Q[i],1,1,0x25ffffff)
803                 self["constellation"].flush()
804                 if constellation_bitmap_list:
805                         self.tmr.start(3000, True)
806                 else:
807                         self.tmr.start(50, True)
808
809         def keyOk(self):
810                 cur_sel = self["list"].current
811                 if cur_sel:
812                         self.updateConstellation(cur_sel[1])
813
814         def keyCancel(self):
815                 self.tmr.stop()
816                 self.close(False)
817
818 def freq_round(freq, val):
819         mod = freq % val
820         return freq + val - mod if mod >= (val / 2) else freq - mod
821
822 class SatelliteTransponderSearchSupport:
823         def satelliteTransponderSearchSessionClosed(self, *val):
824                 if self.frontend:
825                         self.frontendStateChanged_conn = None
826                         self.frontend = None
827                         self.channel = None
828                         self.updateStateTimer_conn = None
829                         self.updateStateTimer = None
830
831                 print "satelliteTransponderSearchSessionClosed, val", val
832                 if val and len(val):
833                         if val[0]:
834                                 self.setTransponderSearchResult(self.__tlist)
835                         else:
836                                 self.setTransponderSearchResult(None)
837                 self.satellite_search_session = None
838                 self.__tlist = None
839                 self.TransponderSearchFinished()
840
841         def updateStateSat(self):
842                 self.frontendStateChangedSat(None)
843
844         def frontendStateChangedSat(self, frontend_ptr):
845                 x = { }
846                 self.frontend.getFrontendStatus(x)
847                 assert x, "getFrontendStatus failed!"
848                 tuner_state = x["tuner_state"]
849
850                 if self.driver_wa and frontend_ptr and tuner_state in (stateLock, stateFailed):
851                         self.parm.symbol_rate = self.driver_wa
852                         self.driver_wa = False
853                         self.tuneNext()
854                         return
855
856                 if tuner_state in (stateLock, stateFailed) or frontend_ptr is None:
857                         band_base_freq = self.parm.frequency
858                         state = self.satellite_search_session
859
860                         d = { }
861                         self.frontend.getTransponderData(d, False)
862                         d["tuner_type"] = feSatellite
863                         r = ConvertToHumanReadable(d)
864
865                         if tuner_state == stateLock:
866                                 freq = d["frequency"]
867
868                                 # Hack for C-Band
869                                 if self.scan_sat.bs_freq_limits[0] == 3400000 and self.scan_sat.bs_freq_limits[1] == 4200000:
870                                         tuned_freq = abs(band_base_freq - 5150000)
871                                         tune_offs = band_base_freq - tuned_freq
872                                         freq -= tune_offs
873                                         freq = 5150000 - freq
874
875                                 parm = eDVBFrontendParametersSatellite()
876                                 parm.frequency = freq_round(freq, 250)
877                                 fstr = str(parm.frequency / 1000)
878                                 if self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_Horizontal:
879                                         fstr += "H "
880                                 elif self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_Vertical:
881                                         fstr += "V "
882                                 elif self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_CircularLeft:
883                                         fstr += "L "
884                                 elif self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_CircularRight:
885                                         fstr += "R "
886                                 sr = d["symbol_rate"]
887 #                               print "SR before round", sr
888                                 if sr < 0:
889                                         print "WARNING blind SR is < 0... skip"
890                                         if not self.auto_scan:
891                                                 self.parm.frequency += self.parm.symbol_rate
892                                 else:
893                                         sr_rounded = freq_round(sr, 500)
894                                         if sr_rounded > 45000000:
895                                                 sr_rounded = 45000000
896 #                                       print "SR after round", sr_rounded
897                                         parm.symbol_rate = sr_rounded
898                                         fstr += str(parm.symbol_rate/1000)
899                                         parm.fec = d["fec_inner"]
900                                         fstr += " "
901                                         fstr += r["fec_inner"]
902                                         parm.inversion = eDVBFrontendParametersSatellite.Inversion_Unknown
903                                         parm.polarisation = d["polarization"]
904                                         parm.orbital_position = d["orbital_position"]
905                                         parm.system = d["system"]
906                                         fstr += " "
907                                         fstr += r["system"]
908                                         parm.modulation = d["modulation"]
909                                         fstr += " "
910                                         fstr += r["modulation"]
911
912                                         parm.is_id = -1
913                                         parm.pls_mode = eDVBFrontendParametersSatellite.PLS_Unknown
914                                         parm.pls_code = 0
915                                         if parm.system == eDVBFrontendParametersSatellite.System_DVB_S2:
916                                                 parm.rolloff = d["rolloff"]
917                                                 parm.pilot = d["pilot"]
918
919                                         if self.auto_scan:
920                                                 print "LOCKED at", freq
921                                         else:
922                                                 print "LOCKED at", freq, "SEARCHED at", self.parm.frequency, "half bw", (135L*((sr+1000)/1000)/200), "half search range", (self.parm.symbol_rate/2)
923                                                 self.parm.frequency = freq
924                                                 self.parm.frequency += (135L*((sr+999)/1000)/200)
925                                                 self.parm.frequency += self.parm.symbol_rate/2
926
927                                         if freq < self.min_freq or freq > self.max_freq:
928                                                 print "SKIPPED", freq, "out of search range"
929                                         else:
930                                                 self.__tlist.append(parm)
931                                                 bm = state.getConstellationBitmap(5)
932                                                 self.tp_found.append((fstr, bm))
933                                                 state.updateConstellation(bm)
934
935                                         if len(self.tp_found):
936                                                 state["list"].updateList(self.tp_found)
937                                         else:
938                                                 state["list"].setList(self.tp_found)
939                                                 state["list"].setIndex(0)
940                         elif frontend_ptr:
941                                 if self.auto_scan: #when driver based auto scan is used we got a tuneFailed event when the scan has scanned the last frequency...
942                                         freq_old = self.parm.frequency
943                                         sr_old = self.parm.symbol_rate
944                                         self.parm = self.setNextRange()
945                                         self.driver_wa = self.parm is not None and freq_old == self.parm.frequency and sr_old == self.parm.symbol_rate
946                                 else:
947                                         self.parm.frequency += self.parm.symbol_rate
948
949                         if self.auto_scan:
950                                 freq = d["frequency"]
951
952                                 # Hack for C-Band
953                                 if self.scan_sat.bs_freq_limits[0] == 3400000 and self.scan_sat.bs_freq_limits[1] == 4200000:
954                                         tuned_freq = abs(band_base_freq - 5150000)
955                                         tune_offs = band_base_freq - tuned_freq
956                                         freq -= tune_offs
957                                         freq = 5150000 - freq
958
959                                 mhz_complete, mhz_done = self.stats(freq)
960
961                                 print "CURRENT freq", freq, "%d/%d" %(mhz_done, mhz_complete)
962
963                                 check_finished = self.parm is None
964                         else:
965                                 print "NEXT freq", self.parm.frequency
966                                 mhz_complete, mhz_done = self.stats()
967                                 check_finished = self.parm.frequency > self.range_list[self.current_range][1]
968                                 if check_finished:
969                                         self.parm = self.setNextRange()
970
971                         seconds_done = int(time() - self.start_time)
972
973                         if check_finished:
974                                 if self.parm is None:
975                                         tmpstr = _("%dMHz scanned") %mhz_complete
976                                         tmpstr += ', '
977                                         tmpstr += _("%d transponders found at %d:%02dmin") %(len(self.tp_found),seconds_done / 60, seconds_done % 60)
978                                         state["progress"].setText(tmpstr)
979                                         state.setFinished()
980
981                                         self.frontendStateChanged_conn = None
982                                         self.frontend = None
983                                         self.channel = None
984                                         self.updateStateTimer_conn = None
985                                         self.updateStateTimer = None
986                                         return
987
988                         if self.auto_scan:
989                                 tmpstr = str((freq+500)/1000)
990                         else:
991                                 tmpstr = str((self.parm.frequency+500)/1000)
992
993                         if self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_Horizontal:
994                                 tmpstr += "H"
995                         elif self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_Vertical:
996                                 tmpstr += "V"
997                         elif self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_CircularLeft:
998                                 tmpstr += "L"
999                         elif self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_CircularRight:
1000                                 tmpstr += "R"
1001
1002                         tmpstr += ', '
1003                         tmpstr += "%d/%dMHz" %(mhz_done, mhz_complete)
1004
1005                         tmpstr += ", "
1006                         tmpstr += _("%d transponder(s) found") %len(self.tp_found)
1007
1008                         tmpstr += ', '
1009
1010                         seconds_complete = (seconds_done * mhz_complete) / max(mhz_done, 1)
1011                         tmpstr += _("%d:%02d/%d:%02dmin") %(seconds_done / 60, seconds_done % 60, seconds_complete / 60, seconds_complete % 60)
1012
1013                         state["progress"].setText(tmpstr)
1014
1015                         if self.auto_scan:
1016                                 self.updateStateTimer.start(1000, True)
1017
1018                         if not self.auto_scan or frontend_ptr is not None:
1019                                 if self.driver_wa:
1020                                         self.driver_wa = self.parm.symbol_rate
1021                                         self.parm.symbol_rate = 12345000
1022                                         tparm = eDVBFrontendParameters()
1023                                         tparm.setDVBS(self.parm, False)
1024                                         self.frontend.tune(tparm)
1025                                 else:
1026                                         self.tuneNext()
1027                 elif tuner_state != stateTuning:
1028                         print "unhandled tuner state", tuner_state
1029
1030         def tuneNext(self):
1031                 tparm = eDVBFrontendParameters()
1032                 tparm.setDVBS(self.parm, False)
1033                 self.frontend.tune(tparm)
1034
1035         def setNextRange(self):
1036                 if self.current_range is None:
1037                         self.current_range = 0
1038                 else:
1039                         self.current_range += 1
1040                 if len(self.range_list) > self.current_range:
1041                         bs_range = self.range_list[self.current_range]
1042                         print "Sat Blindscan current range", bs_range
1043                         parm = eDVBFrontendParametersSatellite()
1044
1045                         # Hack for C-Band
1046                         limits = self.scan_sat.bs_freq_limits
1047                         idx = 1 if self.auto_scan and limits[0] == 3400000 and limits[1] == 4200000 else 0
1048                         parm.frequency = bs_range[idx]
1049
1050                         if self.nim.isCompatible("DVB-S2"):
1051                                 steps = { 5 : 2000, 4 : 4000, 3 : 6000, 2 : 8000, 1 : 10000 }[self.scan_sat.bs_accuracy.value]
1052                                 parm.system = self.scan_sat.bs_system.value
1053                                 parm.pilot = eDVBFrontendParametersSatellite.Pilot_Unknown
1054                                 parm.rolloff = eDVBFrontendParametersSatellite.RollOff_alpha_0_35
1055                         else:
1056                                 steps = 4000
1057                                 parm.system = eDVBFrontendParametersSatellite.System_DVB_S
1058                         if self.auto_scan:
1059                                 parm.symbol_rate = (bs_range[1] - bs_range[0]) / 1000
1060                         else:
1061                                 parm.symbol_rate = steps
1062                         parm.fec = eDVBFrontendParametersSatellite.FEC_Auto
1063                         parm.inversion = eDVBFrontendParametersSatellite.Inversion_Unknown
1064                         parm.polarisation = bs_range[2]
1065                         parm.orbital_position = self.orb_pos
1066                         parm.modulation = eDVBFrontendParametersSatellite.Modulation_QPSK
1067                         return parm
1068                 return None
1069
1070         def stats(self, freq=None):
1071                 if freq is None:
1072                         freq = self.parm.frequency
1073                 mhz_complete = 0
1074                 mhz_done = 0
1075                 cnt = 0
1076                 for range in self.range_list:
1077                         mhz = (range[1] - range[0]) / 1000
1078                         mhz_complete += mhz
1079                         if cnt == self.current_range:
1080                                 # Hack for C-Band
1081                                 limits = self.scan_sat.bs_freq_limits
1082                                 if self.auto_scan and limits[0] == 3400000 and limits[1] == 4200000:
1083                                         mhz_done += (range[1] - freq) / 1000
1084                                 else:
1085                                         mhz_done += (freq - range[0]) / 1000
1086                         elif cnt < self.current_range:
1087                                 mhz_done += mhz
1088                         cnt += 1
1089                 return mhz_complete, mhz_done
1090
1091         def startSatelliteTransponderSearch(self, nim_idx, orb_pos):
1092                 self.frontend = None
1093                 self.orb_pos = orb_pos
1094                 self.nim = nimmanager.nim_slots[nim_idx]
1095                 tunername = nimmanager.getNimName(nim_idx)
1096                 self.__tlist = [ ]
1097                 self.tp_found = [ ]
1098                 self.current_range = None
1099                 self.range_list = [ ]
1100                 tuner_no = -1
1101                 self.auto_scan = False
1102                 self.driver_wa = False
1103
1104                 self.auto_scan = tunername.startswith('Si216')
1105                 if self.auto_scan or tunername == "Alps BSBE1 C01A/D01A." or (tunername.startswith("BCM45") and tunername != "BCM4501"):
1106                         (self.channel, self.frontend) = self.tryGetRawFrontend(nim_idx, False, False)
1107                         if not self.frontend:
1108                                 self.session.nav.stopService()
1109                                 (self.channel, self.frontend) = self.tryGetRawFrontend(nim_idx, False, False)
1110                                 if not self.frontend:
1111                                         if self.session.pipshown: # try to disable pip
1112                                                 self.session.pipshown = False
1113                                                 self.session.deleteDialog(self.session.pip)
1114                                                 del self.session.pip
1115                                         (self.channel, self.frontend) = self.tryGetRawFrontend(nim_idx, False, False)
1116                                         if not self.frontend:
1117                                                 print "couldn't allocate tuner %d for blindscan!!!" %nim_idx
1118                                                 return
1119                         self.frontendStateChanged_conn = self.frontend.getStateChangeSignal().connect(self.frontendStateChangedSat)
1120
1121                         band_cutoff_frequency = self.nim_sat_band_cutoff_frequency[nim_idx][orb_pos][0]
1122
1123                         s1 = self.scan_sat.bs_freq_start.value * 1000
1124                         s2 = self.scan_sat.bs_freq_stop.value * 1000
1125
1126                         start = self.min_freq = min(s1,s2)
1127                         stop = self.max_freq = max(s1,s2)
1128
1129                         if self.auto_scan: # hack for driver based blindscan... extend search range +/- 50Mhz
1130                                 limits = self.scan_sat.bs_freq_limits
1131                                 start -= 50000
1132                                 stop += 50000
1133                                 if start < limits[0]:
1134                                         start = limits[0]
1135                                 if stop >limits[1]:
1136                                         stop = limits[1]
1137
1138                         if self.scan_sat.bs_horizontal.value:
1139                                 if self.auto_scan and band_cutoff_frequency and stop > band_cutoff_frequency:
1140                                         if start < band_cutoff_frequency:
1141                                                 self.range_list.append((start, min(stop, band_cutoff_frequency), eDVBFrontendParametersSatellite.Polarisation_Horizontal))
1142                                         if stop > band_cutoff_frequency:
1143                                                 self.range_list.append((max(band_cutoff_frequency, start), stop, eDVBFrontendParametersSatellite.Polarisation_Horizontal))
1144                                 else:
1145                                         self.range_list.append((start, stop, eDVBFrontendParametersSatellite.Polarisation_Horizontal))
1146
1147                         if self.scan_sat.bs_vertical.value:
1148                                 if self.auto_scan and band_cutoff_frequency:
1149                                         if start < band_cutoff_frequency:
1150                                                 self.range_list.append((start, min(stop, band_cutoff_frequency), eDVBFrontendParametersSatellite.Polarisation_Vertical))
1151                                         if stop > band_cutoff_frequency:
1152                                                 self.range_list.append((max(band_cutoff_frequency, start), stop, eDVBFrontendParametersSatellite.Polarisation_Vertical))
1153                                 else:
1154                                         self.range_list.append((start, stop, eDVBFrontendParametersSatellite.Polarisation_Vertical))
1155
1156                         self.parm = self.setNextRange()
1157                         if self.parm is not None:
1158                                 tparm = eDVBFrontendParameters()
1159                                 tparm.setDVBS(self.parm, False)
1160                                 self.frontend.tune(tparm)
1161                                 self.start_time = time()
1162                                 tmpstr = _("Try to find used satellite transponders...")
1163                         else:
1164                                 tmpstr = _("Nothing to scan! Press Exit!")
1165                         x = { }
1166                         self.frontend.getFrontendData(x)
1167                         tuner_no = x["tuner_number"]
1168                 else:
1169                         tmpstr = _("Blindscan is not supported by this tuner (%s)") %tunername
1170                 self.satellite_search_session = self.session.openWithCallback(self.satelliteTransponderSearchSessionClosed, SatBlindscanState, tuner_no, tmpstr)
1171                 if self.auto_scan:
1172                         self.updateStateTimer = eTimer()
1173                         self.updateStateTimer_conn = self.updateStateTimer.timeout.connect(self.updateStateSat)
1174                         self.updateStateTimer.start(1000, True)
1175
1176 class DefaultSatLists(DefaultWizard):
1177         def __init__(self, session, silent = True, showSteps = False, default = False):
1178                 self.xmlfile = "defaultsatlists.xml"
1179                 DefaultWizard.__init__(self, session, silent, showSteps, neededTag = "services", default = default)
1180                 print "configuredSats:", nimmanager.getConfiguredSats()
1181
1182         def setDirectory(self):
1183                 self.directory = []
1184                 self.directory.append(resolveFilename(SCOPE_DEFAULTDIR))
1185                 import os
1186                 os.system("mount %s %s" % (resolveFilename(SCOPE_DEFAULTPARTITION), resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR)))
1187                 self.directory.append(resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR))
1188
1189         def statusCallback(self, status, progress):
1190                 print "statusCallback:", status, progress
1191                 from Components.DreamInfoHandler import DreamInfoHandler
1192                 if status == DreamInfoHandler.STATUS_DONE:
1193                         self["text"].setText(_("The installation of the default services lists is finished.") + "\n\n" + _("Please press OK to continue."))
1194                         self.markDone()
1195                         self.disableKeys = False
1196
1197 class ScanSetup(ConfigListScreen, Screen, TransponderSearchSupport, CableTransponderSearchSupport, SatelliteTransponderSearchSupport, TerrestrialTransponderSearchSupport):
1198         def __init__(self, session, systems_enabled = "SCT"):
1199                 Screen.__init__(self, session)
1200
1201                 self.systems_enabled = systems_enabled
1202                 self.finished_cb = None
1203                 self.updateSatList()
1204                 self.service = session.nav.getCurrentService()
1205                 self.feinfo = None
1206                 frontendData = None
1207                 if self.service is not None:
1208                         self.feinfo = self.service.frontendInfo()
1209                         frontendData = self.feinfo and self.feinfo.getAll(True)
1210
1211                 self.createConfig(frontendData)
1212
1213                 del self.feinfo
1214                 del self.service
1215
1216                 self["actions"] = NumberActionMap(["SetupActions"],
1217                 {
1218                         "ok": self.keyGo,
1219                         "cancel": self.keyCancel,
1220                 }, -2)
1221
1222                 self.list = []
1223                 ConfigListScreen.__init__(self, self.list)
1224                 if not self.scan_nims.value == "":
1225                         self.createSetup()
1226                         self["introduction"] = Label(_("Press OK to start the scan"))
1227                 else:
1228                         self["introduction"] = Label(_("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."))
1229
1230         def runAsync(self, finished_cb):
1231                 self.finished_cb = finished_cb
1232                 self.keyGo()
1233
1234         def updateSatList(self):
1235                 self.satList = []
1236                 for slot in nimmanager.nim_slots:
1237                         if slot.isCompatible("DVB-S"):
1238                                 self.satList.append(nimmanager.getSatListForNim(slot.slot))
1239                         else:
1240                                 self.satList.append(None)
1241
1242         # systemChanged and satSystemChanged are needed for compatibility
1243         # with some DVB-S(2) specific plugins like satfinder, positioner setup...
1244         # no desire to adjust the whole plugins ;-)
1245
1246         # notifier for self.scan_system
1247         def systemChanged(self, configElement):
1248                 if configElement.value == "DVB-S":
1249                         if self.scan_sat.system.value != eDVBFrontendParametersSatellite.System_DVB_S:
1250                                 self.scan_sat.system.value = eDVBFrontendParametersSatellite.System_DVB_S
1251                 elif configElement.value == "DVB-S2":
1252                         if self.scan_sat.system.value != eDVBFrontendParametersSatellite.System_DVB_S2:
1253                                 self.scan_sat.system.value = eDVBFrontendParametersSatellite.System_DVB_S2
1254
1255         # notifier for self.scan_sat.system
1256         def satSystemChanged(self, configElement):
1257                 if configElement.value == eDVBFrontendParametersSatellite.System_DVB_S:
1258                         if self.scan_system.value != "DVB-S":
1259                                 self.scan_system.value = "DVB-S"
1260                 elif configElement.value == eDVBFrontendParametersSatellite.System_DVB_S2:
1261                         if self.scan_system.value != "DVB-S2":
1262                                 self.scan_system.value = "DVB-S2"
1263
1264         def createSetup(self):
1265                 self.list = []
1266                 self.multiscanlist = []
1267                 if self.scan_nims.value == "":
1268                         return
1269                 index_to_scan = int(self.scan_nims.value)
1270                 print "ID: ", index_to_scan
1271
1272                 self.tunerEntry = getConfigListEntry(_("Tuner"), self.scan_nims)
1273                 self.list.append(self.tunerEntry)
1274
1275                 if self.scan_nims == [ ]:
1276                         return
1277
1278                 try:
1279                         oldTypeOfScan = self.typeOfScanEntry[1].value
1280                 except:
1281                         oldTypeOfScan = None
1282
1283                 self.typeOfScanEntry = None
1284                 self.plpidAutoEntry = None
1285                 self.fecEntry = None
1286                 self.systemEntry = None
1287                 self.modulationEntry = None
1288                 self.satelliteEntry = None
1289                 self.enableMisEntry = None
1290                 self.plsModeEntry = None
1291                 nim = nimmanager.nim_slots[index_to_scan]
1292
1293                 if self.scan_system.value in ("DVB-S", "DVB-S2"):
1294                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_type)
1295                         self.list.append(self.typeOfScanEntry)
1296                 elif self.scan_system.value == "DVB-C":
1297                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typecable)
1298                         self.list.append(self.typeOfScanEntry)
1299                 elif self.scan_system.value in ("DVB-T", "DVB-T2"):
1300                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typeterrestrial)
1301                         self.list.append(self.typeOfScanEntry)
1302
1303                 # try to use the same scan type after system change
1304                 current = self.typeOfScanEntry[1].value
1305                 if oldTypeOfScan and current != oldTypeOfScan:
1306                         # we map complete to multisat_yes and vice versa
1307                         if oldTypeOfScan == "complete" and self.scan_system.value in ("DVB-S", "DVB-S2"):
1308                                 oldTypeOfScan = "multisat_yes"
1309                         elif oldTypeOfScan == "multisat_yes" and self.scan_system.value in ("DVB-T", "DVB-T2", "DVB-C"):
1310                                 oldTypeOfScan = "complete"
1311                         choices = self.typeOfScanEntry[1].getChoices()
1312                         for ch in choices:
1313                                 if ch[0] == oldTypeOfScan:
1314                                         self.typeOfScanEntry[1].value = oldTypeOfScan
1315                                         break
1316
1317                 if self.typeOfScanEntry[1].value == 'single_transponder':
1318                         self.scan_system.setChoices(self.systems)
1319                 else:
1320                         self.scan_system.setChoices(self.systems_filtered)
1321
1322                 if len(self.scan_system.getChoices()) > 1:
1323                         self.systemEntry = getConfigListEntry(_('System'), self.scan_system)
1324                         self.list.append(self.systemEntry)
1325
1326                 self.scan_networkScan.value = False
1327                 self.scan_otherSDT.value = False
1328                 if self.scan_system.value in ("DVB-S", "DVB-S2"):
1329                         if self.scan_type.value == "single_transponder":
1330                                 self.updateSatList()
1331                                 self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[index_to_scan]))
1332                                 self.list.append(getConfigListEntry(_('Frequency'), self.scan_sat.frequency))
1333                                 self.list.append(getConfigListEntry(_('Inversion'), self.scan_sat.inversion))
1334                                 self.list.append(getConfigListEntry(_('Symbol rate'), self.scan_sat.symbolrate))
1335                                 self.list.append(getConfigListEntry(_('Polarization'), self.scan_sat.polarization))
1336                                 if self.scan_system.value == "DVB-S":
1337                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec))
1338                                 elif self.scan_system.value == "DVB-S2":
1339                                         self.modulationEntry = getConfigListEntry(_('Modulation'), nim.can_modulation_auto and self.scan_sat.modulation_auto or self.scan_sat.modulation)
1340                                         mod = self.modulationEntry[1].value
1341                                         if mod == eDVBFrontendParametersSatellite.Modulation_8PSK:
1342                                                 self.fecEntry = getConfigListEntry(_("FEC"), nim.can_auto_fec_s2 and self.scan_sat.fec_s2_8psk_auto or self.scan_sat.fec_s2_8psk)
1343                                         else:
1344                                                 self.fecEntry = getConfigListEntry(_("FEC"), nim.can_auto_fec_s2 and self.scan_sat.fec_s2_qpsk_auto or self.scan_sat.fec_s2_qpsk)
1345                                         self.list.append(self.fecEntry)
1346                                         self.list.append(self.modulationEntry)
1347                                         self.list.append(getConfigListEntry(_('Roll-off'), self.scan_sat.rolloff))
1348                                         self.list.append(getConfigListEntry(_('Pilot'), self.scan_sat.pilot))
1349                                         if nim.can_multistream_s2:
1350                                                 self.enableMisEntry = getConfigListEntry(_('Multistream'), self.scan_sat.enable_mis)
1351                                                 self.list.append(self.enableMisEntry)
1352                                                 if self.scan_sat.enable_mis.value:
1353                                                         self.list.append(getConfigListEntry(_('Stream ID'), self.scan_sat.is_id))
1354                                         if nim.can_pls_s2:
1355                                                 self.plsModeEntry = getConfigListEntry(_('PLS Mode'), self.scan_sat.pls_mode)
1356                                                 self.list.append(self.plsModeEntry)
1357                                                 if self.scan_sat.pls_mode.value != eDVBFrontendParametersSatellite.PLS_Unknown:
1358                                                         self.list.append(getConfigListEntry(_('PLS Code'), self.scan_sat.pls_code))
1359                         elif self.scan_type.value == "single_satellite":
1360                                 self.updateSatList()
1361                                 self.list.append(getConfigListEntry(_("Satellite"), self.scan_satselection[index_to_scan]))
1362                                 self.scan_networkScan.value = True
1363                         elif self.scan_type.value == "blind_scan":
1364                                 self.updateSatList()
1365                                 selected_sat_pos = self.scan_satselection[index_to_scan].value
1366                                 limit_list = self.nim_sat_frequency_range[index_to_scan][int(selected_sat_pos)]
1367                                 l = limit_list[0]
1368                                 self.scan_sat.bs_freq_limits = l
1369                                 limits = ( l[0]/1000, l[1]/1000 )
1370
1371                                 # Hack for C-Band
1372                                 if limits[0] == 6100 and limits[1] == 7300:
1373                                         limits = ( 3400, 4200 )
1374                                         self.scan_sat.bs_freq_limits = ( limits[0]*1000, limits[1]*1000 )
1375
1376                                 self.scan_sat.bs_freq_start = ConfigInteger(default = limits[0], limits = (limits[0], limits[1]))
1377                                 self.scan_sat.bs_freq_stop = ConfigInteger(default = limits[1], limits = (limits[0], limits[1]))
1378                                 self.satelliteEntry = getConfigListEntry(_("Satellite"), self.scan_satselection[index_to_scan])
1379                                 self.list.append(self.satelliteEntry)
1380                                 self.list.append(getConfigListEntry(_("Frequency start"), self.scan_sat.bs_freq_start))
1381                                 self.list.append(getConfigListEntry(_("Frequency stop"), self.scan_sat.bs_freq_stop))
1382                                 tunername = nimmanager.getNimName(index_to_scan)
1383                                 if tunername.startswith('BCM450'):
1384                                         self.list.append(getConfigListEntry(_("Accuracy (higher is better)"), self.scan_sat.bs_accuracy))
1385                                 else:
1386                                         # some frontends only support a low accuracy blindscan with SR > 10KSyms..
1387                                         # but better than nothing
1388                                         self.scan_sat.bs_accuracy.value = 1
1389                                 self.list.append(getConfigListEntry(_("Horizontal"), self.scan_sat.bs_horizontal))
1390                                 self.list.append(getConfigListEntry(_("Vertical"), self.scan_sat.bs_vertical))
1391                         elif self.scan_type.value.find("multisat") != -1:
1392                                 tlist = []
1393                                 SatList = nimmanager.getSatListForNim(index_to_scan)
1394                                 for x in SatList:
1395                                         if self.Satexists(tlist, x[0]) == 0:
1396                                                 tlist.append(x[0])
1397                                                 sat = ConfigOnOff(default = self.scan_type.value.find("_yes") != -1 and True or False)
1398                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[0]), sat)
1399                                                 self.list.append(configEntry)
1400                                                 self.multiscanlist.append((x[0], sat))
1401                                 self.scan_networkScan.value = True
1402                 elif self.scan_system.value == "DVB-C":
1403                         if self.scan_typecable.value == "single_transponder":
1404                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_cab.frequency))
1405                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_cab.inversion))
1406                                 self.list.append(getConfigListEntry(_("Symbol rate"), self.scan_cab.symbolrate))
1407                                 self.modulationEntry = getConfigListEntry(_('Modulation'), nim.can_modulation_auto and self.scan_cab.modulation_auto or self.scan_cab.modulation)
1408                                 self.list.append(self.modulationEntry)
1409                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_cab.fec))
1410                         elif nim.description == "ATBM781x" and self.scan_typecable.value == "complete":
1411                                 # the transponder searching of the external transponder search helper is not so good
1412                                 # for this frontend... so we enable network searching as default
1413                                 self.scan_networkScan.value = True
1414                 elif self.scan_system.value in ("DVB-T", "DVB-T2"):
1415                         if self.scan_typeterrestrial.value == "single_transponder":
1416                                 base_path = self.scan_ter if self.scan_system.value == "DVB-T" else self.scan_ter2
1417                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_ter.frequency))
1418                                 self.list.append(getConfigListEntry(_("Bandwidth"), base_path.bandwidth))
1419                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_ter.inversion))
1420                                 self.list.append(getConfigListEntry(_("Modulation"), base_path.modulation))
1421                                 self.list.append(getConfigListEntry(_("Transmission mode"), base_path.transmission))
1422                                 self.list.append(getConfigListEntry(_("Guard interval"), base_path.guard))
1423                                 if base_path == self.scan_ter2:
1424                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_ter2.fec))
1425                                         self.plpidAutoEntry = getConfigListEntry(_("PLP ID Auto"), base_path.plp_id_auto)
1426                                         self.list.append(self.plpidAutoEntry)
1427                                         if not base_path.plp_id_auto.value:
1428                                                 self.list.append(getConfigListEntry(_("PLP ID"), base_path.plp_id))
1429                                 else:
1430                                         self.list.append(getConfigListEntry(_("Hierarchy info"), self.scan_ter.hierarchy))
1431                                         self.list.append(getConfigListEntry(_("Code rate HP"), base_path.crh))
1432                                         self.list.append(getConfigListEntry(_("Code rate LP"), base_path.crl))
1433
1434                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_networkScan))
1435                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
1436                 self.list.append(getConfigListEntry(_("Only Free scan"), self.scan_onlyfree))
1437                 if config.usage.setup_level.index >= 2:
1438                         self.list.append(getConfigListEntry(_("Lookup other SDT"), self.scan_otherSDT))
1439                         self.list.append(getConfigListEntry(_("Skip empty transponders"), self.scan_skipEmpty))
1440                 self["config"].list = self.list
1441                 self["config"].l.setList(self.list)
1442
1443         def Satexists(self, tlist, pos):
1444                 for x in tlist:
1445                         if x == pos:
1446                                 return 1
1447                 return 0
1448
1449         def newConfig(self):
1450                 cur = self["config"].getCurrent()
1451                 print "cur is", cur
1452                 if cur is None:
1453                         pass
1454                 elif cur == self.typeOfScanEntry or \
1455                         cur == self.tunerEntry or \
1456                         (self.systemEntry and cur == self.systemEntry) or \
1457                         (self.modulationEntry and cur == self.modulationEntry) or \
1458                         (self.satelliteEntry and cur == self.satelliteEntry) or \
1459                         (self.enableMisEntry and cur == self.enableMisEntry) or \
1460                         (self.plsModeEntry and cur == self.plsModeEntry) or \
1461                         (self.plpidAutoEntry and cur == self.plpidAutoEntry):
1462                         self.createSetup()
1463
1464         def nimChanged(self, configElement):
1465                 choices = configElement.getChoices()
1466                 nim_idx = choices[configElement.index][2]
1467                 nim = nimmanager.nim_slots[nim_idx]
1468
1469                 systems = [ ]
1470                 systems_filtered = [ ]
1471                 if 'S' in self.systems_enabled:
1472                         s2_en = nim.isEnabled("DVB-S2")
1473                         if s2_en:
1474                                 systems.append(("DVB-S2", _("DVB-S2")))
1475                                 systems_filtered.append(("DVB-S2", _("DVB-S2")))
1476                         if nim.isEnabled("DVB-S"):
1477                                 systems.append(("DVB-S", _("DVB-S")))
1478                                 if not s2_en:
1479                                         systems_filtered.append(("DVB-S", _("DVB-S")))
1480
1481                 if 'C' in self.systems_enabled and nim.isEnabled("DVB-C"):
1482                         systems.append(("DVB-C", _("DVB-C")))
1483                         systems_filtered.append(("DVB-C", _("DVB-C")))
1484
1485                 if 'T' in self.systems_enabled:
1486                         t2_en = nim.isEnabled("DVB-T2")
1487                         if t2_en:
1488                                 systems.append(("DVB-T2", _("DVB-T2")))
1489                                 systems_filtered.append(("DVB-T2", _("DVB-T2")))
1490                         if nim.isEnabled("DVB-T"):
1491                                 systems.append(("DVB-T", _("DVB-T")))
1492                                 if not t2_en:
1493                                         systems_filtered.append(("DVB-T", _("DVB-T")))
1494
1495                 self.systems = systems
1496                 self.systems_filtered = systems_filtered
1497
1498                 # for compability with old plugins...
1499                 self.scan_sat.system = ConfigSelection(default = eDVBFrontendParametersSatellite.System_DVB_S, choices = [
1500                         (eDVBFrontendParametersSatellite.System_DVB_S, _("DVB-S")),
1501                         (eDVBFrontendParametersSatellite.System_DVB_S2, _("DVB-S2"))])
1502                 self.scan_sat.system.addNotifier(self.satSystemChanged, False, True, False)
1503
1504                 if nim_idx == self.tuned_slot:
1505                         if self.tuned_type == feSatellite:
1506                                 system = self.defaultSat["system"] == eDVBFrontendParametersSatellite.System_DVB_S and "DVB-S" or "DVB-S2"
1507                         elif self.tuned_type == feCable:
1508                                 system = "DVB-C"
1509                         elif self.tuned_type == feTerrestrial:
1510                                 system = self.defaultTer["system"] == eDVBFrontendParametersTerrestrial.System_DVB_T and "DVB-T" or "DVB-T2"
1511                         self.scan_system = ConfigSelection(default = system, choices = systems)
1512                 else:
1513                         self.scan_system = ConfigSelection(choices = systems)
1514
1515                 self.scan_system.addNotifier(self.systemChanged)
1516
1517                 self.scan_sat.pilot.value = eDVBFrontendParametersSatellite.Pilot_Unknown
1518                 if nim.can_modulation_auto:
1519                         self.scan_sat.modulation_auto.value = eDVBFrontendParametersSatellite.Modulation_Auto
1520                         self.scan_cab.modulation_auto.value = eDVBFrontendParametersSatellite.Modulation_Auto
1521                 if nim.can_auto_fec_s2:
1522                         self.scan_sat.fec_s2_8psk_auto.value = eDVBFrontendParametersSatellite.FEC_Auto
1523                         self.scan_sat.fec_s2_qpsk_auto.value = eDVBFrontendParametersSatellite.FEC_Auto
1524
1525         def createConfig(self, frontendData):
1526                                            #("Type", frontendData["system"], TYPE_TEXT),
1527                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
1528                                            #("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
1529                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
1530                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
1531                                            #("Polarization", frontendData["polarization"], TYPE_TEXT),
1532                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
1533                                            #("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
1534                                                 #)
1535                 #elif frontendData["tuner_type"] == "DVB-C":
1536                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
1537                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
1538                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
1539                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
1540                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
1541                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
1542                         #                  ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
1543                                                 #)
1544                 #elif frontendData["tuner_type"] == "DVB-T":
1545                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
1546                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
1547                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
1548                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
1549                                            #("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
1550                                            #("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
1551                                            #("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
1552                                            #("Constellation", frontendData["constellation"], TYPE_TEXT),
1553                                            #("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
1554                                            #("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
1555                                            #("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT),
1556
1557                         defaultSat = {
1558                                 "orbpos": 192,
1559                                 "system": eDVBFrontendParametersSatellite.System_DVB_S,
1560                                 "frequency": 11836,
1561                                 "inversion": eDVBFrontendParametersSatellite.Inversion_Unknown,
1562                                 "symbolrate": 27500,
1563                                 "polarization": eDVBFrontendParametersSatellite.Polarisation_Horizontal,
1564                                 "fec": eDVBFrontendParametersSatellite.FEC_Auto,
1565                                 "fec_s2_8psk": eDVBFrontendParametersSatellite.FEC_2_3,
1566                                 "fec_s2_qpsk": eDVBFrontendParametersSatellite.FEC_2_3,
1567                                 "modulation": eDVBFrontendParametersSatellite.Modulation_QPSK,
1568                                 "is_id" : -1,
1569                                 "pls_mode" : eDVBFrontendParametersSatellite.PLS_Unknown,
1570                                 "pls_code" : 0 }
1571                         defaultCab = {
1572                                 "frequency": 466,
1573                                 "inversion": eDVBFrontendParametersCable.Inversion_Unknown,
1574                                 "modulation": eDVBFrontendParametersCable.Modulation_QAM64,
1575                                 "fec": eDVBFrontendParametersCable.FEC_Auto,
1576                                 "symbolrate": 6900 }
1577                         defaultTer = {
1578                                 "system" : eDVBFrontendParametersTerrestrial.System_DVB_T,
1579                                 "frequency" : 466000,
1580                                 "inversion" : eDVBFrontendParametersTerrestrial.Inversion_Unknown,
1581                                 "bandwidth" : eDVBFrontendParametersTerrestrial.Bandwidth_8MHz,
1582                                 "crh" : eDVBFrontendParametersTerrestrial.FEC_Auto,
1583                                 "crl" : eDVBFrontendParametersTerrestrial.FEC_Auto,
1584                                 "fec" : eDVBFrontendParametersTerrestrial.FEC_Auto,
1585                                 "modulation" : eDVBFrontendParametersTerrestrial.Modulation_Auto,
1586                                 "transmission_mode" : eDVBFrontendParametersTerrestrial.TransmissionMode_Auto,
1587                                 "guard_interval" : eDVBFrontendParametersTerrestrial.GuardInterval_Auto,
1588                                 "hierarchy": eDVBFrontendParametersTerrestrial.Hierarchy_Auto,
1589                                 "plp_id": -1
1590                                 }
1591
1592                         slot_number = -1
1593                         ttype = 0
1594                         if frontendData is not None:
1595                                 slot_number = frontendData.get("slot_number", -1)
1596                                 ttype = frontendData.get("tuner_type", 0)
1597
1598                         if slot_number != -1 and ttype:
1599                                 self.tuned_slot = slot_number
1600                                 self.tuned_type = ttype
1601                                 if ttype == feSatellite:
1602                                         defaultSat["system"] = frontendData.get("system", eDVBFrontendParametersSatellite.System_DVB_S)
1603                                         defaultSat["frequency"] = frontendData.get("frequency", 0) / 1000
1604                                         defaultSat["inversion"] = frontendData.get("inversion", eDVBFrontendParametersSatellite.Inversion_Unknown)
1605                                         defaultSat["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
1606                                         defaultSat["polarization"] = frontendData.get("polarization", eDVBFrontendParametersSatellite.Polarisation_Horizontal)
1607                                         defaultSat["modulation"] = frontendData.get("modulation", eDVBFrontendParametersSatellite.Modulation_QPSK)
1608                                         if defaultSat["system"] == eDVBFrontendParametersSatellite.System_DVB_S2:
1609                                                 if defaultSat["modulation"] == eDVBFrontendParametersSatellite.Modulation_QPSK:
1610                                                         defaultSat["fec_s2_qpsk"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_2_3)
1611                                                 else:
1612                                                         defaultSat["fec_s2_8psk"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_2_3)
1613                                                 defaultSat["rolloff"] = frontendData.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35)
1614                                                 defaultSat["pilot"] = frontendData.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown)
1615                                                 defaultSat["is_id"] = frontendData.get("is_id", -1)
1616                                                 defaultSat["pls_mode"] = frontendData.get("pls_mode", eDVBFrontendParametersSatellite.PLS_Unknown)
1617                                                 defaultSat["pls_code"] = frontendData.get("pls_code", 0)
1618                                         defaultSat["orbpos"] = frontendData.get("orbital_position", 0)
1619                                 elif ttype == feCable:
1620                                         defaultCab["frequency"] = frontendData.get("frequency", 0) / 1000
1621                                         defaultCab["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
1622                                         defaultCab["inversion"] = frontendData.get("inversion", eDVBFrontendParametersCable.Inversion_Unknown)
1623                                         defaultCab["fec"] = frontendData.get("fec_inner", eDVBFrontendParametersCable.FEC_Auto)
1624                                         defaultCab["modulation"] = frontendData.get("modulation", eDVBFrontendParametersCable.Modulation_QAM16)
1625                                 elif ttype == feTerrestrial:
1626                                         defaultTer["system"] = frontendData.get("system", eDVBFrontendParametersTerrestrial.System_DVB_T)
1627                                         defaultTer["frequency"] = frontendData.get("frequency", 0)
1628                                         defaultTer["inversion"] = frontendData.get("inversion", eDVBFrontendParametersTerrestrial.Inversion_Unknown)
1629                                         defaultTer["bandwidth"] = frontendData.get("bandwidth", eDVBFrontendParametersTerrestrial.Bandwidth_8MHz)
1630                                         defaultTer["crh"] = frontendData.get("code_rate_hp", eDVBFrontendParametersTerrestrial.FEC_Auto)
1631                                         defaultTer["crl"] = frontendData.get("code_rate_lp", eDVBFrontendParametersTerrestrial.FEC_Auto)
1632                                         defaultTer["modulation"] = frontendData.get("constellation", eDVBFrontendParametersTerrestrial.Modulation_Auto)
1633                                         defaultTer["transmission_mode"] = frontendData.get("transmission_mode", eDVBFrontendParametersTerrestrial.TransmissionMode_Auto)
1634                                         defaultTer["guard_interval"] = frontendData.get("guard_interval", eDVBFrontendParametersTerrestrial.GuardInterval_Auto)
1635                                         defaultTer["hierarchy"] = frontendData.get("hierarchy_information", eDVBFrontendParametersTerrestrial.Hierarchy_Auto)
1636                                         defaultTer["plp_id"] = frontendData.get("plp_id", -1)
1637                         else:
1638                                 slot_number = 0
1639                                 self.tuned_slot = -1
1640
1641                         self.defaultTer = defaultTer
1642                         self.defaultCab = defaultCab
1643                         self.defaultSat = defaultSat 
1644
1645                         self.scan_sat = ConfigSubsection()
1646                         self.scan_cab = ConfigSubsection()
1647                         self.scan_ter = ConfigSubsection()
1648                         self.scan_ter2 = ConfigSubsection()
1649
1650                         self.scan_type = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat")), ("multisat_yes", _("Multisat")), ("blind_scan", _("Blindscan"))])
1651                         self.scan_typecable = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
1652                         self.scan_typeterrestrial = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
1653                         self.scan_clearallservices = ConfigSelection(default = "no", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
1654                         self.scan_onlyfree = ConfigYesNo(default = False)
1655                         self.scan_networkScan = ConfigYesNo(default = False)
1656                         self.scan_skipEmpty = ConfigYesNo(default = True)
1657                         self.scan_otherSDT = ConfigYesNo(default = False)
1658
1659                         tuned_slot = None
1660                         idx = -1
1661                         nim_list = []
1662                         # collect all nims which are *not* set to "nothing"
1663                         for n in nimmanager.nim_slots:
1664                                 idx += 1
1665 #                               if n.config_mode == "nothing":
1666 #                                       continue
1667 #                               if n.config_mode == "advanced" and len(nimmanager.getSatListForNim(n.slot)) < 1:
1668 #                                       continue
1669 #                               if n.config_mode in ("loopthrough", "satposdepends"):
1670 #                                       # Skip connected LNBs
1671 #                                       continue
1672                                         # TODO: this would cause trouble if someone connects a S2 tuner to an S Tuner
1673                                         # If so i'd propose we automatically only show the "most capable" tuner:
1674                                         #  * the T2 tuner if it's connected with a T-only tuner
1675                                         #  * the S2 tuner when it's connected with a S-only tuner ...
1676                                         # Listing both would be required whenever non-backwards-compatible demods show up
1677                                         # Currently none if the above is actually possible
1678                                 if n.isEnabled('DVB-S') or n.isEnabled('DVB-C') or n.isEnabled('DVB-T'):
1679                                         nim_list.append((str(n.slot), n.friendly_full_description, idx))
1680                                         if idx == slot_number:
1681                                                 tuned_slot = str(n.slot)
1682
1683                         if not nim_list:
1684                                 self.scan_nims = ConfigText('')
1685                         if tuned_slot:
1686                                 self.scan_nims = ConfigSelection(choices = nim_list, default = tuned_slot)
1687                         else:
1688                                 self.scan_nims = ConfigSelection(choices = nim_list)
1689
1690                         # status
1691                         self.scan_snr = ConfigSlider()
1692                         self.scan_snr.enabled = False
1693                         self.scan_agc = ConfigSlider()
1694                         self.scan_agc.enabled = False
1695                         self.scan_ber = ConfigSlider()
1696                         self.scan_ber.enabled = False
1697
1698                         # sat
1699                         self.scan_sat.frequency = ConfigFloat(default = [defaultSat["frequency"],0], limits = [(1,99999),(0,9)])
1700                         self.scan_sat.inversion = ConfigSelection(default = defaultSat["inversion"], choices = [
1701                                 (eDVBFrontendParametersSatellite.Inversion_Off, _("Off")),
1702                                 (eDVBFrontendParametersSatellite.Inversion_On, _("On")),
1703                                 (eDVBFrontendParametersSatellite.Inversion_Unknown, _("Auto"))])
1704                         self.scan_sat.symbolrate = ConfigInteger(default = defaultSat["symbolrate"], limits = (1, 99999))
1705                         self.scan_sat.polarization = ConfigSelection(default = defaultSat["polarization"], choices = [
1706                                 (eDVBFrontendParametersSatellite.Polarisation_Horizontal, _("horizontal")),
1707                                 (eDVBFrontendParametersSatellite.Polarisation_Vertical, _("vertical")),
1708                                 (eDVBFrontendParametersSatellite.Polarisation_CircularLeft, _("circular left")),
1709                                 (eDVBFrontendParametersSatellite.Polarisation_CircularRight, _("circular right"))])
1710                         self.scan_sat.fec = ConfigSelection(default = defaultSat["fec"], choices = [
1711                                 (eDVBFrontendParametersSatellite.FEC_Auto, _("Auto")),
1712                                 (eDVBFrontendParametersSatellite.FEC_1_2, "1/2"),
1713                                 (eDVBFrontendParametersSatellite.FEC_2_3, "2/3"),
1714                                 (eDVBFrontendParametersSatellite.FEC_3_4, "3/4"),
1715                                 (eDVBFrontendParametersSatellite.FEC_5_6, "5/6"),
1716                                 (eDVBFrontendParametersSatellite.FEC_7_8, "7/8"),
1717                                 (eDVBFrontendParametersSatellite.FEC_None, _("None"))])
1718
1719                         fec_s2_qpsk = [
1720                                 (eDVBFrontendParametersSatellite.FEC_1_2, "1/2"),
1721                                 (eDVBFrontendParametersSatellite.FEC_2_3, "2/3"),
1722                                 (eDVBFrontendParametersSatellite.FEC_3_4, "3/4"),
1723                                 (eDVBFrontendParametersSatellite.FEC_3_5, "3/5"),
1724                                 (eDVBFrontendParametersSatellite.FEC_4_5, "4/5"),
1725                                 (eDVBFrontendParametersSatellite.FEC_5_6, "5/6"),
1726                                 (eDVBFrontendParametersSatellite.FEC_8_9, "8/9"),
1727                                 (eDVBFrontendParametersSatellite.FEC_9_10, "9/10")]
1728                         fec_s2_8psk = [
1729                                 (eDVBFrontendParametersSatellite.FEC_2_3, "2/3"),
1730                                 (eDVBFrontendParametersSatellite.FEC_3_4, "3/4"),
1731                                 (eDVBFrontendParametersSatellite.FEC_3_5, "3/5"),
1732                                 (eDVBFrontendParametersSatellite.FEC_5_6, "5/6"),
1733                                 (eDVBFrontendParametersSatellite.FEC_8_9, "8/9"),
1734                                 (eDVBFrontendParametersSatellite.FEC_9_10, "9/10")]
1735                         self.scan_sat.fec_s2_qpsk = ConfigSelection(default = defaultSat["fec_s2_qpsk"], choices = fec_s2_qpsk[:])
1736                         self.scan_sat.fec_s2_8psk = ConfigSelection(default = defaultSat["fec_s2_8psk"], choices = fec_s2_8psk[:])
1737                         fec_s2_qpsk.insert(0,(eDVBFrontendParametersSatellite.FEC_Auto, _("Auto")))
1738                         fec_s2_8psk.insert(0,(eDVBFrontendParametersSatellite.FEC_Auto, _("Auto")))
1739                         self.scan_sat.fec_s2_qpsk_auto = ConfigSelection(default = defaultSat["fec_s2_qpsk"], choices = fec_s2_qpsk)
1740                         self.scan_sat.fec_s2_8psk_auto = ConfigSelection(default = defaultSat["fec_s2_8psk"], choices = fec_s2_8psk)
1741
1742                         modulations = [
1743                                 (eDVBFrontendParametersSatellite.Modulation_QPSK, "QPSK"),
1744                                 (eDVBFrontendParametersSatellite.Modulation_8PSK, "8PSK")]
1745                         self.scan_sat.modulation = ConfigSelection(default = defaultSat["modulation"], choices = modulations[:])
1746                         modulations.insert(0,(eDVBFrontendParametersSatellite.Modulation_Auto, _("Auto")))
1747                         self.scan_sat.modulation_auto = ConfigSelection(default = defaultSat["modulation"], choices = modulations)
1748
1749                         self.scan_sat.rolloff = ConfigSelection(default = defaultSat.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35), choices = [
1750                                 (eDVBFrontendParametersSatellite.RollOff_alpha_0_35, "0.35"),
1751                                 (eDVBFrontendParametersSatellite.RollOff_alpha_0_25, "0.25"),
1752                                 (eDVBFrontendParametersSatellite.RollOff_alpha_0_20, "0.20")])
1753                         self.scan_sat.pilot = ConfigSelection(default = defaultSat.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown), choices = [
1754                                 (eDVBFrontendParametersSatellite.Pilot_Off, _("Off")),
1755                                 (eDVBFrontendParametersSatellite.Pilot_On, _("On")),
1756                                 (eDVBFrontendParametersSatellite.Pilot_Unknown, _("Auto"))])
1757                         self.scan_sat.enable_mis = ConfigYesNo(default = defaultSat["is_id"] != -1)
1758                         self.scan_sat.is_id = ConfigInteger(default = defaultSat["is_id"] if defaultSat["is_id"] != -1 else 0, limits = (0, 255))
1759                         self.scan_sat.pls_mode = ConfigSelection(default = defaultSat["pls_mode"], choices = [
1760                                 (eDVBFrontendParametersSatellite.PLS_Root, "Root"),
1761                                 (eDVBFrontendParametersSatellite.PLS_Gold, "Gold"),
1762                                 (eDVBFrontendParametersSatellite.PLS_Unknown, "Auto")])
1763                         self.scan_sat.pls_code = ConfigInteger(default = defaultSat["pls_code"], limits = (0, 262143))
1764
1765                         self.scan_sat.bs_system = ConfigSelection(default = eDVBFrontendParametersSatellite.System_DVB_S2, 
1766                                 choices = [ (eDVBFrontendParametersSatellite.System_DVB_S2, _("DVB-S + DVB-S2")),
1767                                         (eDVBFrontendParametersSatellite.System_DVB_S, _("DVB-S only"))])
1768
1769                         self.scan_sat.bs_accuracy = ConfigSelection(default = 2, choices = [ (1, "1"), (2, "2"), (3, "3"), (4, "4"), (5, "5")])
1770
1771                         self.scan_sat.bs_horizontal = ConfigYesNo(default = True)
1772                         self.scan_sat.bs_vertical = ConfigYesNo(default = True)
1773
1774                         # cable
1775                         self.scan_cab.frequency = ConfigInteger(default = defaultCab["frequency"], limits = (50, 999))
1776                         self.scan_cab.inversion = ConfigSelection(default = defaultCab["inversion"], choices = [
1777                                 (eDVBFrontendParametersCable.Inversion_Off, _("Off")),
1778                                 (eDVBFrontendParametersCable.Inversion_On, _("On")),
1779                                 (eDVBFrontendParametersCable.Inversion_Unknown, _("Auto"))])
1780
1781                         modulations = [
1782                                 (eDVBFrontendParametersCable.Modulation_QAM16, "16-QAM"),
1783                                 (eDVBFrontendParametersCable.Modulation_QAM32, "32-QAM"),
1784                                 (eDVBFrontendParametersCable.Modulation_QAM64, "64-QAM"),
1785                                 (eDVBFrontendParametersCable.Modulation_QAM128, "128-QAM"),
1786                                 (eDVBFrontendParametersCable.Modulation_QAM256, "256-QAM")]
1787                         self.scan_cab.modulation = ConfigSelection(default = defaultCab["modulation"], choices = modulations[:])
1788                         modulations.insert(0,(eDVBFrontendParametersCable.Modulation_Auto, _("Auto")))
1789                         self.scan_cab.modulation_auto = ConfigSelection(default = defaultCab["modulation"], choices = modulations)
1790
1791                         self.scan_cab.fec = ConfigSelection(default = defaultCab["fec"], choices = [
1792                                 (eDVBFrontendParametersCable.FEC_Auto, _("Auto")),
1793                                 (eDVBFrontendParametersCable.FEC_1_2, "1/2"),
1794                                 (eDVBFrontendParametersCable.FEC_2_3, "2/3"),
1795                                 (eDVBFrontendParametersCable.FEC_3_4, "3/4"),
1796                                 (eDVBFrontendParametersCable.FEC_5_6, "5/6"),
1797                                 (eDVBFrontendParametersCable.FEC_7_8, "7/8"),
1798                                 (eDVBFrontendParametersCable.FEC_8_9, "8/9"),
1799                                 (eDVBFrontendParametersCable.FEC_None, _("None"))])
1800                         self.scan_cab.symbolrate = ConfigInteger(default = defaultCab["symbolrate"], limits = (1, 99999))
1801
1802                         # terrestial
1803                         self.scan_ter.frequency = ConfigInteger(default = 466000, limits = (50000, 999000))
1804                         self.scan_ter.inversion = ConfigSelection(default = defaultTer["inversion"], choices = [
1805                                 (eDVBFrontendParametersTerrestrial.Inversion_Off, _("Off")),
1806                                 (eDVBFrontendParametersTerrestrial.Inversion_On, _("On")),
1807                                 (eDVBFrontendParametersTerrestrial.Inversion_Unknown, _("Auto"))])
1808                         self.scan_ter.hierarchy = ConfigSelection(default = defaultTer["hierarchy"], choices = [
1809                                 (eDVBFrontendParametersTerrestrial.Hierarchy_None, _("None")),
1810                                 (eDVBFrontendParametersTerrestrial.Hierarchy_1, "1"),
1811                                 (eDVBFrontendParametersTerrestrial.Hierarchy_2, "2"),
1812                                 (eDVBFrontendParametersTerrestrial.Hierarchy_4, "4"),
1813                                 (eDVBFrontendParametersTerrestrial.Hierarchy_Auto, _("Auto"))])
1814
1815                         # DVB-T choices
1816                         self.scan_ter.bandwidth = ConfigSelection(default = defaultTer["bandwidth"], choices = [
1817                                 (eDVBFrontendParametersTerrestrial.Bandwidth_8MHz, "8MHz"),
1818                                 (eDVBFrontendParametersTerrestrial.Bandwidth_7MHz, "7MHz"),
1819                                 (eDVBFrontendParametersTerrestrial.Bandwidth_6MHz, "6MHz"),
1820                                 (eDVBFrontendParametersTerrestrial.Bandwidth_5MHz, "5MHz")])
1821                         self.scan_ter.crh = ConfigSelection(default = defaultTer["crh"], choices = [
1822                                 (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
1823                                 (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
1824                                 (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
1825                                 (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
1826                                 (eDVBFrontendParametersTerrestrial.FEC_7_8, "7/8"),
1827                                 (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
1828                         self.scan_ter.crl = ConfigSelection(default = defaultTer["crl"], choices = [
1829                                 (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
1830                                 (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
1831                                 (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
1832                                 (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
1833                                 (eDVBFrontendParametersTerrestrial.FEC_7_8, "7/8"),
1834                                 (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
1835                         self.scan_ter.modulation = ConfigSelection(default = defaultTer["modulation"], choices = [
1836                                 (eDVBFrontendParametersTerrestrial.Modulation_QPSK, "QPSK"),
1837                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM16, "QAM16"),
1838                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM64, "QAM64"),
1839                                 (eDVBFrontendParametersTerrestrial.Modulation_Auto, _("Auto"))])
1840                         self.scan_ter.transmission = ConfigSelection(default = defaultTer["transmission_mode"], choices = [
1841                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_2k, "2K"),
1842                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_4k, "4K"),
1843                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_8k, "8K"),
1844                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_Auto, _("Auto"))])
1845                         self.scan_ter.guard = ConfigSelection(default = defaultTer["guard_interval"], choices = [
1846                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_32, "1/32"),
1847                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_16, "1/16"),
1848                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_8, "1/8"),
1849                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_4, "1/4"),
1850                                 (eDVBFrontendParametersTerrestrial.GuardInterval_Auto, _("Auto"))])
1851
1852                         # DVB-T2 choices
1853                         self.scan_ter2.bandwidth = ConfigSelection(default = defaultTer["bandwidth"], choices = [
1854                                 (eDVBFrontendParametersTerrestrial.Bandwidth_10MHz, "10MHz"),
1855                                 (eDVBFrontendParametersTerrestrial.Bandwidth_8MHz, "8MHz"),
1856                                 (eDVBFrontendParametersTerrestrial.Bandwidth_7MHz, "7MHz"),
1857                                 (eDVBFrontendParametersTerrestrial.Bandwidth_6MHz, "6MHz"),
1858                                 (eDVBFrontendParametersTerrestrial.Bandwidth_5MHz, "5MHz"),
1859                                 (eDVBFrontendParametersTerrestrial.Bandwidth_1_712MHz, "1.712MHz")])
1860                         self.scan_ter2.fec = ConfigSelection(default = defaultTer["fec"], choices = [
1861                                 (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
1862                                 (eDVBFrontendParametersTerrestrial.FEC_3_5, "3/5"),
1863                                 (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
1864                                 (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
1865                                 (eDVBFrontendParametersTerrestrial.FEC_4_5, "4/5"),
1866                                 (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
1867                                 (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
1868                         self.scan_ter2.modulation = ConfigSelection(default = defaultTer["modulation"], choices = [
1869                                 (eDVBFrontendParametersTerrestrial.Modulation_QPSK, "QPSK"),
1870                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM16, "QAM16"),
1871                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM64, "QAM64"),
1872                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM256, "QAM256"),
1873                                 (eDVBFrontendParametersTerrestrial.Modulation_Auto, _("Auto"))])
1874                         self.scan_ter2.transmission = ConfigSelection(default = defaultTer["transmission_mode"], choices = [
1875                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_1k, "1K"),
1876                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_2k, "2K"),
1877                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_2k, "4K"),
1878                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_8k, "8K"),
1879                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_16k, "16K"),
1880                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_32k, "32K"),
1881                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_Auto, _("Auto"))])
1882                         self.scan_ter2.guard = ConfigSelection(default = defaultTer["guard_interval"], choices = [
1883                                 (eDVBFrontendParametersTerrestrial.GuardInterval_19_256, "19/256"),
1884                                 (eDVBFrontendParametersTerrestrial.GuardInterval_19_128, "19/128"),
1885                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_128, "1/128"),
1886                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_32, "1/32"),
1887                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_16, "1/16"),
1888                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_8, "1/8"),
1889                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_4, "1/4"),
1890                                 (eDVBFrontendParametersTerrestrial.GuardInterval_Auto, _("Auto"))])
1891                         plp_id = defaultTer["plp_id"]
1892                         self.scan_ter2.plp_id_auto = ConfigYesNo(default = plp_id == -1)
1893                         self.scan_ter2.plp_id = ConfigInteger(default = 0 if plp_id == -1 else plp_id, limits = (0, 255))
1894
1895                         self.scan_scansat = {}
1896                         for sat in nimmanager.satList:
1897                                 #print sat[1]
1898                                 self.scan_scansat[sat[0]] = ConfigYesNo(default = False)
1899
1900                         sec = secClass.getInstance()
1901
1902                         self.nim_sat_frequency_range = []
1903                         self.nim_sat_band_cutoff_frequency = []
1904                         self.scan_satselection = []
1905                         for slot in nimmanager.nim_slots:
1906                                 slot_id = slot.slot
1907                                 if slot.isCompatible("DVB-S"):
1908                                         satlist_for_slot = self.satList[slot_id]
1909                                         self.scan_satselection.append(getConfigSatlist(defaultSat["orbpos"], satlist_for_slot))
1910                                         sat_freq_range = { }
1911                                         sat_band_cutoff = { }
1912                                         for sat in satlist_for_slot:
1913                                                 orbpos = sat[0]
1914                                                 sat_freq_range[orbpos] = sec.getFrequencyRangeList(slot_id, orbpos)
1915                                                 sat_band_cutoff[orbpos] = sec.getBandCutOffFrequency(slot_id, orbpos)
1916                                         self.nim_sat_frequency_range.append(sat_freq_range)
1917                                         self.nim_sat_band_cutoff_frequency.append(sat_band_cutoff)
1918                                 else:
1919                                         self.nim_sat_frequency_range.append(None)
1920                                         self.nim_sat_band_cutoff_frequency.append(None)
1921                                         self.scan_satselection.append(None)
1922
1923                         if self.scan_nims.value != '':
1924                                 self.scan_nims.addNotifier(self.nimChanged)
1925
1926                         return True
1927
1928         def keyLeft(self):
1929                 ConfigListScreen.keyLeft(self)
1930                 self.newConfig()
1931
1932         def keyRight(self):
1933                 ConfigListScreen.keyRight(self)
1934                 self.newConfig()
1935
1936         def updateStatus(self):
1937                 print "updatestatus"
1938
1939         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position, system, modulation, rolloff, pilot, is_id, pls_mode, pls_code):
1940                 s = "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)
1941                 if is_id != -1:
1942                         s += " is_id: " + str(is_id)
1943                         if pls_mode != eDVBFrontendParametersSatellite.PLS_Unknown:
1944                                 s += "pls_mode: " + str(pls_mode) + " pls_code: " + str(pls_code)
1945                 s += "\norbpos: " + str(orbital_position)
1946                 print s
1947                 parm = eDVBFrontendParametersSatellite()
1948                 parm.modulation = modulation
1949                 parm.system = system
1950                 parm.frequency = int(frequency * 1000)
1951                 parm.symbol_rate = symbol_rate * 1000
1952                 parm.polarisation = polarisation
1953                 parm.fec = fec
1954                 parm.inversion = inversion
1955                 parm.orbital_position = orbital_position
1956                 parm.rolloff = rolloff
1957                 parm.pilot = pilot
1958                 parm.is_id = is_id
1959                 parm.pls_mode = pls_mode
1960                 parm.pls_code = pls_code
1961                 tlist.append(parm)
1962
1963         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
1964                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
1965                 parm = eDVBFrontendParametersCable()
1966                 parm.frequency = frequency * 1000
1967                 parm.symbol_rate = symbol_rate * 1000
1968                 parm.modulation = modulation
1969                 parm.fec = fec
1970                 parm.inversion = inversion
1971                 tlist.append(parm)
1972
1973         def addTerTransponder(self, tlist, *args, **kwargs):
1974                 tlist.append(buildTerTransponder(*args, **kwargs))
1975
1976         def keyGo(self):
1977                 if self.scan_nims.value == "":
1978                         return
1979                 tlist = []
1980                 flags = None
1981                 startScan = True
1982                 removeAll = True
1983                 index_to_scan = int(self.scan_nims.value)
1984
1985                 if self.scan_nims == [ ]:
1986                         self.session.open(MessageBox, _("No tuner is enabled!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1987                         return
1988
1989                 nim = nimmanager.nim_slots[index_to_scan]
1990                 print "nim", nim.slot
1991                 if self.scan_system.value in ("DVB-S", "DVB-S2"):
1992                         print "is compatible with DVB-S"
1993                         if self.scan_type.value == "single_transponder":
1994                                 # these lists are generated for each tuner, so this has work.
1995                                 assert len(self.satList) > index_to_scan
1996                                 assert len(self.scan_satselection) > index_to_scan
1997
1998                                 nimsats = self.satList[index_to_scan]
1999                                 selsatidx = self.scan_satselection[index_to_scan].index
2000
2001                                 # however, the satList itself could be empty. in that case, "index" is 0 (for "None").
2002                                 if len(nimsats):
2003                                         orbpos = nimsats[selsatidx][0]
2004                                         if self.scan_system.value == "DVB-S":
2005                                                 fec = self.scan_sat.fec.value
2006                                                 mod = eDVBFrontendParametersSatellite.Modulation_QPSK
2007                                         else:
2008                                                 mod = self.modulationEntry[1].value
2009                                                 fec = self.fecEntry[1].value
2010
2011                                         print "add sat transponder"
2012                                         self.addSatTransponder(tlist, self.scan_sat.frequency.float,
2013                                                                 self.scan_sat.symbolrate.value,
2014                                                                 self.scan_sat.polarization.value,
2015                                                                 fec,
2016                                                                 self.scan_sat.inversion.value,
2017                                                                 orbpos,
2018                                                                 eDVBFrontendParametersSatellite.System_DVB_S if self.scan_system.value == "DVB-S" else eDVBFrontendParametersSatellite.System_DVB_S2, 
2019                                                                 mod,
2020                                                                 self.scan_sat.rolloff.value,
2021                                                                 self.scan_sat.pilot.value,
2022                                                                 self.scan_sat.is_id.value if self.scan_sat.enable_mis.value else -1,
2023                                                                 self.scan_sat.pls_mode.value,
2024                                                                 self.scan_sat.pls_code.value if self.scan_sat.pls_mode.value < eDVBFrontendParametersSatellite.PLS_Unknown else 0)
2025                                 removeAll = False
2026                         elif self.scan_type.value == "single_satellite":
2027                                 sat = self.satList[index_to_scan][self.scan_satselection[index_to_scan].index]
2028                                 getInitialTransponderList(tlist, sat[0])
2029                         elif self.scan_type.value.find("multisat") != -1:
2030                                 for x in self.multiscanlist:
2031                                         if x[1].value:
2032                                                 print "   " + str(x[0])
2033                                                 getInitialTransponderList(tlist, x[0])
2034                         elif self.scan_type.value.find("blind_scan") != -1:
2035                                 startScan = False
2036
2037                 elif self.scan_system.value == "DVB-C":
2038                         if self.scan_typecable.value == "single_transponder":
2039                                 self.addCabTransponder(tlist, self.scan_cab.frequency.value,
2040                                                         self.scan_cab.symbolrate.value,
2041                                                         self.modulationEntry[1].value,
2042                                                         self.scan_cab.fec.value,
2043                                                         self.scan_cab.inversion.value)
2044                                 removeAll = False
2045                         elif self.scan_typecable.value == "complete":
2046                                 if config.Nims[index_to_scan].cable.scan_type.value == "provider":
2047                                         getInitialCableTransponderList(tlist, index_to_scan)
2048                                 else:
2049                                         startScan = False
2050
2051                 elif self.scan_system.value in ("DVB-T", "DVB-T2"):
2052                         if self.scan_typeterrestrial.value == "single_transponder":
2053                                 base_path = self.scan_ter if self.scan_system.value == "DVB-T" else self.scan_ter2
2054                                 self.addTerTransponder(tlist,
2055                                         system = eDVBFrontendParametersTerrestrial.System_DVB_T if self.scan_system.value == "DVB-T" else eDVBFrontendParametersTerrestrial.System_DVB_T2,
2056                                         frequency = self.scan_ter.frequency.value * 1000,
2057                                         inversion = self.scan_ter.inversion.value,
2058                                         bandwidth = base_path.bandwidth.value,
2059                                         crh = self.scan_ter.crh.value,
2060                                         crl = self.scan_ter.crl.value if base_path == self.scan_ter else base_path.fec.value,
2061                                         modulation = base_path.modulation.value,
2062                                         transmission = base_path.transmission.value,
2063                                         guard = base_path.guard.value,
2064                                         hierarchy = self.scan_ter.hierarchy.value,
2065                                         plp_id = -1 if base_path == self.scan_ter or base_path.plp_id_auto.value else base_path.plp_id.value
2066                                         )
2067                                 removeAll = False
2068                         elif self.scan_typeterrestrial.value == "complete":
2069                                 tunername = nimmanager.getNimName(index_to_scan)
2070                                 getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(index_to_scan), tunername in can_t_t2_auto_delsys)
2071
2072                 flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
2073
2074                 if self.scan_otherSDT.value:
2075                         flags |= eComponentScan.scanOtherSDT
2076
2077                 if not self.scan_skipEmpty.value:
2078                         flags |= eComponentScan.scanDontSkipEmptyTransponders
2079
2080                 tmp = self.scan_clearallservices.value
2081                 if tmp == "yes":
2082                         flags |= eComponentScan.scanRemoveServices
2083                 elif tmp == "yes_hold_feeds":
2084                         flags |= eComponentScan.scanRemoveServices
2085                         flags |= eComponentScan.scanDontRemoveFeeds
2086
2087                 if tmp != "no" and not removeAll:
2088                         flags |= eComponentScan.scanDontRemoveUnscanned
2089
2090                 if self.scan_onlyfree.value:
2091                         flags |= eComponentScan.scanOnlyFree
2092
2093                 for x in self["config"].list:
2094                         x[1].save()
2095
2096                 if startScan:
2097                         self.startScan(tlist, flags, index_to_scan)
2098                 else:
2099                         self.flags = flags
2100                         self.feid = index_to_scan
2101                         self.tlist = []
2102                         if self.scan_system.value == "DVB-C":
2103                                 self.startCableTransponderSearch(self.feid)
2104                         elif self.scan_system.value in ("DVB-T", "DVB-T2"):
2105                                 self.startTerrestrialTransponderSearch(self.feid)
2106                         else:
2107                                 sat = self.satList[index_to_scan][self.scan_satselection[index_to_scan].index]
2108                                 self.startSatelliteTransponderSearch(self.feid, sat[0])
2109
2110         def setTransponderSearchResult(self, tlist):
2111                 self.tlist = tlist
2112
2113         def TransponderSearchFinished(self):
2114                 if self.tlist is None:
2115                         self.tlist = []
2116                 else:
2117                         self.startScan(self.tlist, self.flags, self.feid)
2118
2119         def startScan(self, tlist, flags, feid):
2120                 if len(tlist):
2121                         # flags |= eComponentScan.scanSearchBAT
2122                         if self.finished_cb:
2123                                 self.session.openWithCallback(self.finished_cb, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
2124                         else:
2125                                 self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
2126                 else:
2127                         if self.finished_cb:
2128                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
2129                         else:
2130                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
2131
2132         def keyCancel(self):
2133                 for x in self["config"].list:
2134                         x[1].cancel()
2135                 self.close()
2136
2137 class ScanSimple(ConfigListScreen, Screen, TransponderSearchSupport, CableTransponderSearchSupport, TerrestrialTransponderSearchSupport):
2138         def getNetworksForNim(self, nim, type=None):
2139                 if (type is None or type == "DVB-S") and nim.isEnabled("DVB-S"): 
2140                         networks = nimmanager.getSatListForNim(nim.slot)
2141                 else:
2142                         networks = [ ]
2143                 if (type is None or type == "DVB-C") and nim.isEnabled("DVB-C"):
2144                         networks.append("DVB-C")
2145                 if (type is None or type == "DVB-T") and nim.isEnabled("DVB-T"):
2146                         networks.append("DVB-T")
2147                 return networks
2148
2149         def __init__(self, session):
2150                 Screen.__init__(self, session)
2151
2152                 self["actions"] = ActionMap(["SetupActions"],
2153                 {
2154                         "ok": self.keyGo,
2155                         "cancel": self.keyCancel,
2156                 }, -2)
2157
2158                 self.list = []
2159                 nim_networks = { }
2160                 self.finished_cb = None
2161
2162                 for nim in nimmanager.nim_slots:
2163                         # collect networks provided by this tuner
2164
2165                         networks = self.getNetworksForNim(nim)
2166                         print "nim %d provides" % nim.slot, networks
2167
2168                         if networks:
2169                                 nim_networks[nim] = networks
2170
2171                 # we save the config elements to use them on keyGo
2172                 self.nim_enable = [ ]
2173
2174                 if nim_networks:
2175                         dvb_c_nim = None
2176                         dvb_t_nim = None
2177                         nim_sat_networks = { }
2178
2179                         for nim, networks in nim_networks.iteritems():
2180                                 s = nim_sat_networks.get(nim, set())
2181                                 nim_sat_networks[nim] = s
2182                                 for x in networks:
2183                                         if isinstance(x, tuple):
2184                                                 s.add(x)
2185                                         elif x == "DVB-C" and dvb_c_nim is None:
2186                                                 dvb_c_nim = nim
2187                                         elif x == "DVB-T" and dvb_t_nim is None:
2188                                                 dvb_t_nim = nim
2189
2190                         networks_handled = set()
2191                         final_networks_sat = { }
2192
2193                         # remove nim for sat networkslist when another nim provides the same networks and more
2194                         for nim, networks in reversed(nim_sat_networks.items()):
2195                                 other_nim_networks = set()
2196                                 for nim2, networks2 in nim_sat_networks.iteritems():
2197                                         if nim2 != nim:
2198                                                 other_nim_networks |= networks2
2199
2200                                 if not networks.issubset(other_nim_networks) or other_nim_networks.issubset(networks):
2201                                         networks -= networks_handled
2202                                         if networks:
2203                                                 final_networks_sat[nim] = networks
2204                                                 networks_handled |= networks
2205                                                 # try to use the same nim for all systems when possible
2206                                                 if "DVB-C" in nim_networks[nim]:
2207                                                         dvb_c_nim = nim
2208                                                 if "DVB-T" in nim_networks[nim]:
2209                                                         dvb_t_nim = nim
2210
2211                         self.scan_otherSDT = ConfigYesNo(default = False)
2212                         self.scan_clearallservices = ConfigSelection(default = "yes", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
2213                         self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
2214                         if config.usage.setup_level.index >= 2:
2215                                 self.list.append(getConfigListEntry(_("Lookup other SDT"), self.scan_otherSDT))
2216
2217                         temp = { }
2218
2219                         for nim, networks in final_networks_sat.iteritems():
2220                                 if networks:
2221                                         sys = "DVB-S"
2222                                         nimconfig = ConfigYesNo(default = True)
2223                                         nimconfig.nim_index = nim.slot
2224                                         ent = getConfigListEntry(_("Scan ") + nim.slot_name + " - " + nim.description + " - " + sys, nimconfig)
2225                                         temp[ent[0]] = (ent, sys)
2226
2227                         if dvb_c_nim is not None:
2228                                 nim = dvb_c_nim
2229                                 sys = "DVB-C"
2230                                 nimconfig = ConfigYesNo(default = True)
2231                                 nimconfig.nim_index = nim.slot
2232                                 ent = getConfigListEntry(_("Scan ") + nim.slot_name + " - " + nim.description + " - " + sys, nimconfig)
2233                                 temp[ent[0]] = (ent, sys)
2234
2235                         if dvb_t_nim is not None:
2236                                 nim = dvb_t_nim
2237                                 sys = "DVB-T"
2238                                 nimconfig = ConfigYesNo(default = True)
2239                                 nimconfig.nim_index = nim.slot
2240                                 ent = getConfigListEntry(_("Scan ") + nim.slot_name + " - " + nim.description + " - " + sys, nimconfig)
2241                                 temp[ent[0]] = (ent, sys)
2242
2243                         for txt, ent in sorted(temp.iteritems()):
2244                                 configEntry = ent[0][1]
2245                                 if ent[1] == "DVB-S":
2246                                         nim = nimmanager.nim_slots[configEntry.nim_index]
2247                                         self.nim_enable.append((ent[1], configEntry, final_networks_sat[nim]))
2248                                 else:
2249                                         self.nim_enable.append((ent[1], configEntry))
2250                                 self.list.append(ent[0])
2251
2252                 ConfigListScreen.__init__(self, self.list)
2253                 self["header"] = Label(_("Automatic Scan"))
2254                 self["footer"] = Label(_("Press OK to scan"))
2255
2256         def runAsync(self, finished_cb):
2257                 self.finished_cb = finished_cb
2258                 self.keyGo()
2259
2260         def keyGo(self):
2261                 self.scanList = []
2262                 self.nim_iter=0
2263                 self.buildTransponderList()
2264
2265         def buildTransponderList(self): # this method is called multiple times because of asynchronous stuff
2266                 APPEND_NOW = 0
2267                 SEARCH_CABLE_TRANSPONDERS = 1
2268                 SEARCH_TERRESTRIAL_TRANSPONDERS = 2
2269                 action = APPEND_NOW
2270
2271                 scan_idx = self.nim_iter
2272                 n = self.nim_iter < len(self.nim_enable) and self.nim_enable[scan_idx][1] or None
2273                 self.nim_iter += 1
2274                 if n:
2275                         type = self.nim_enable[scan_idx][0]
2276
2277                         if n.value: # check if nim is enabled
2278                                 flags = 0
2279                                 nim = nimmanager.nim_slots[n.nim_index]
2280
2281                                 tlist = [ ]
2282                                 if type == "DVB-S" and nim.isEnabled("DVB-S"): 
2283                                         # get initial transponders for each satellite to be scanned
2284                                         networks = self.nim_enable[scan_idx][2]
2285                                         for sat in networks:
2286                                                 getInitialTransponderList(tlist, sat[0])
2287                                 elif type == "DVB-C" and nim.isEnabled("DVB-C"):
2288                                         if config.Nims[nim.slot].cable.scan_type.value == "provider":
2289                                                 getInitialCableTransponderList(tlist, nim.slot)
2290                                         else:
2291                                                 action = SEARCH_CABLE_TRANSPONDERS
2292                                 elif type == "DVB-T" and nim.isEnabled("DVB-T"):
2293                                         tunername = nimmanager.getNimName(n.nim_index)
2294                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(nim.slot), tunername in can_t_t2_auto_delsys)
2295
2296                                 if self.scan_otherSDT.value:
2297                                         flags |= eComponentScan.scanOtherSDT
2298                                 flags |= eComponentScan.scanNetworkSearch #FIXMEEE.. use flags from cables / satellites / terrestrial.xml
2299                                 tmp = self.scan_clearallservices.value
2300                                 if tmp == "yes":
2301                                         flags |= eComponentScan.scanRemoveServices
2302                                 elif tmp == "yes_hold_feeds":
2303                                         flags |= eComponentScan.scanRemoveServices
2304                                         flags |= eComponentScan.scanDontRemoveFeeds
2305
2306                                 if action == APPEND_NOW:
2307                                         self.scanList.append({"transponders": tlist, "feid": nim.slot, "flags": flags})
2308                                 elif action == SEARCH_CABLE_TRANSPONDERS:
2309                                         self.flags = flags
2310                                         self.feid = nim.slot
2311                                         self.startCableTransponderSearch(nim.slot)
2312                                         return
2313                                 elif action == SEARCH_TERRESTRIAL_TRANSPONDERS:
2314                                         self.flags = flags
2315                                         self.feid = nim.slot
2316                                         self.startTerrestrialTransponderSearch(nim.slot)
2317                                         return
2318                                 else:
2319                                         assert False
2320
2321                         self.buildTransponderList() # recursive call of this function !!!
2322                         return
2323                 # when we are here, then the recursion is finished and all enabled nims are checked
2324                 # so we now start the real transponder scan
2325                 self.startScan(self.scanList)
2326
2327         def startScan(self, scanList):
2328                 if len(scanList):
2329                         if self.finished_cb:
2330                                 self.session.openWithCallback(self.finished_cb, ServiceScan, scanList = scanList)
2331                         else:
2332                                 self.session.open(ServiceScan, scanList = scanList)
2333                 else:
2334                         if self.finished_cb:
2335                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
2336                         else:
2337                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
2338
2339         def setTransponderSearchResult(self, tlist):
2340                 if tlist is not None:
2341                         self.scanList.append({"transponders": tlist, "feid": self.feid, "flags": self.flags})
2342
2343         def TransponderSearchFinished(self):
2344                 self.buildTransponderList()
2345
2346         def keyCancel(self):
2347                 self.close()
2348
2349         def Satexists(self, tlist, pos):
2350                 for x in tlist:
2351                         if x == pos:
2352                                 return 1
2353                 return 0