enigma2 20131118 (master) -> 20140214 (master)
[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, ConfigEnableDisable
6 from Components.ActionMap import NumberActionMap, ActionMap
7 from Components.ConfigList import ConfigListScreen
8 from Components.NimManager import nimmanager, getConfigSatlist
9 from Components.Label import Label
10 from Tools.Directories import resolveFilename, SCOPE_DEFAULTPARTITIONMOUNTDIR, SCOPE_DEFAULTDIR, SCOPE_DEFAULTPARTITION
11 from Tools.Transponder import ConvertToHumanReadable
12 from Screens.MessageBox import MessageBox
13 from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, \
14         eDVBSatelliteEquipmentControl as secClass, eDVBFrontendParametersTerrestrial, \
15         eDVBFrontendParametersCable, eConsoleAppContainer, eDVBResourceManager, \
16         eDVBFrontendParameters
17
18 def buildTerTransponder(frequency,
19                 inversion=2, bandwidth = 3, fechigh = 6, feclow = 6,
20                 modulation = 2, transmission = 2, guard = 4,
21                 hierarchy = 4):
22 #       print "freq", frequency, "inv", inversion, "bw", bandwidth, "fech", fechigh, "fecl", feclow, "mod", modulation, "tm", transmission, "guard", guard, "hierarchy", hierarchy
23         parm = eDVBFrontendParametersTerrestrial()
24         parm.frequency = frequency
25         parm.inversion = inversion
26         parm.bandwidth = bandwidth
27         parm.code_rate_HP = fechigh
28         parm.code_rate_LP = feclow
29         parm.modulation = modulation
30         parm.transmission_mode = transmission
31         parm.guard_interval = guard
32         parm.hierarchy = hierarchy
33         return parm
34
35 def getInitialTransponderList(tlist, pos):
36         list = nimmanager.getTransponders(pos)
37         for x in list:
38                 if x[0] == 0:           #SAT
39                         parm = eDVBFrontendParametersSatellite()
40                         parm.frequency = x[1]
41                         parm.symbol_rate = x[2]
42                         parm.polarisation = x[3]
43                         parm.fec = x[4]
44                         parm.inversion = x[7]
45                         parm.orbital_position = pos
46                         parm.system = x[5]
47                         parm.modulation = x[6]
48                         parm.rolloff = x[8]
49                         parm.pilot = x[9]
50                         tlist.append(parm)
51
52 def getInitialCableTransponderList(tlist, nim):
53         list = nimmanager.getTranspondersCable(nim)
54         for x in list:
55                 if x[0] == 1: #CABLE
56                         parm = eDVBFrontendParametersCable()
57                         parm.frequency = x[1]
58                         parm.symbol_rate = x[2]
59                         parm.modulation = x[3]
60                         parm.fec_inner = x[4]
61                         parm.inversion = parm.Inversion_Unknown
62                         #print "frequency:", x[1]
63                         #print "symbol_rate:", x[2]
64                         #print "modulation:", x[3]
65                         #print "fec_inner:", x[4]
66                         #print "inversion:", 2
67                         tlist.append(parm)
68
69 def getInitialTerrestrialTransponderList(tlist, region):
70         list = nimmanager.getTranspondersTerrestrial(region)
71
72         #self.transponders[self.parsedTer].append((2,freq,bw,const,crh,crl,guard,transm,hierarchy,inv))
73
74         #def buildTerTransponder(frequency, inversion = 2, bandwidth = 3, fechigh = 6, feclow = 6,
75                                 #modulation = 2, transmission = 2, guard = 4, hierarchy = 4):
76
77         for x in list:
78                 if x[0] == 2: #TERRESTRIAL
79                         parm = buildTerTransponder(x[1], x[9], x[2], x[4], x[5], x[3], x[7], x[6], x[8])
80                         tlist.append(parm)
81
82 cable_bands = {
83         "DVBC_BAND_EU_VHF_I" : 1 << 0,
84         "DVBC_BAND_EU_MID" : 1 << 1,
85         "DVBC_BAND_EU_VHF_III" : 1 << 2,
86         "DVBC_BAND_EU_SUPER" : 1 << 3,
87         "DVBC_BAND_EU_HYPER" : 1 << 4,
88         "DVBC_BAND_EU_UHF_IV" : 1 << 5,
89         "DVBC_BAND_EU_UHF_V" : 1 << 6,
90         "DVBC_BAND_US_LO" : 1 << 7,
91         "DVBC_BAND_US_MID" : 1 << 8,
92         "DVBC_BAND_US_HI" : 1 << 9,
93         "DVBC_BAND_US_SUPER" : 1 << 10,
94         "DVBC_BAND_US_HYPER" : 1 << 11,
95 }
96
97 class TransponderSearchSupport:
98         def tryGetRawFrontend(self, feid, ret_boolean=True, do_close=True):
99                 res_mgr = eDVBResourceManager.getInstance()
100                 if res_mgr:
101                         raw_channel = res_mgr.allocateRawChannel(self.feid)
102                         if raw_channel:
103                                 frontend = raw_channel.getFrontend()
104                                 if frontend:
105                                         if do_close:
106                                                 frontend.closeFrontend() # immediate close... 
107                                         if ret_boolean:
108                                                 del raw_channel
109                                                 del frontend
110                                                 return True
111                                         return raw_channel, frontend
112                 if ret_boolean:
113                         return False
114                 return (False, False)
115
116 def CableScanHelperDMM(nim_idx):
117         bus = nimmanager.getI2CDevice(nim_idx)
118         tunername = nimmanager.getNimName(nim_idx)
119         cableScanHelpers = {
120                 'CXD1981': 'cxd1978',
121                 'Philips CU1216Mk3': 'tda1002x',
122         }
123         cmd = cableScanHelpers.get(tunername, None)
124         if cmd is not None:
125                 cmd += " --init --scan --verbose --wakeup --inv 2 --bus %d" % bus
126         return cmd
127
128 class CableTransponderSearchSupport:
129         CableScanHelpers = [ CableScanHelperDMM ]
130
131         def cableTransponderSearchSessionClosed(self, *val):
132                 print "cableTransponderSearchSessionClosed, val", val
133                 self.cable_search_container.appClosed.remove(self.cableTransponderSearchClosed)
134                 self.cable_search_container.dataAvail.remove(self.getCableTransponderData)
135                 if val and len(val):
136                         if val[0]:
137                                 self.setTransponderSearchResult(self.__tlist)
138                         else:
139                                 self.cable_search_container.sendCtrlC()
140                                 self.setTransponderSearchResult(None)
141                 self.cable_search_container = None
142                 self.cable_search_session = None
143                 self.__tlist = None
144                 self.TransponderSearchFinished()
145
146         def cableTransponderSearchClosed(self, retval):
147                 print "cableTransponderSearch finished", retval
148                 self.cable_search_session.close(True)
149
150         def getCableTransponderData(self, str):
151                 data = str.split()
152                 if len(data) and data[0] in ("OK", "FAILED"):
153                         if data[0] == 'OK':
154                                 print str
155                                 parm = eDVBFrontendParametersCable()
156                                 qam = { "QAM16" : parm.Modulation_QAM16,
157                                         "QAM32" : parm.Modulation_QAM32,
158                                         "QAM64" : parm.Modulation_QAM64,
159                                         "QAM128" : parm.Modulation_QAM128,
160                                         "QAM256" : parm.Modulation_QAM256 }
161                                 inv = { "INVERSION_OFF" : parm.Inversion_Off,
162                                         "INVERSION_ON" : parm.Inversion_On,
163                                         "INVERSION_AUTO" : parm.Inversion_Unknown }
164                                 fec = { "FEC_AUTO" : parm.FEC_Auto,
165                                         "FEC_1_2" : parm.FEC_1_2,
166                                         "FEC_2_3" : parm.FEC_2_3,
167                                         "FEC_3_4" : parm.FEC_3_4,
168                                         "FEC_5_6": parm.FEC_5_6,
169                                         "FEC_7_8" : parm.FEC_7_8,
170                                         "FEC_8_9" : parm.FEC_8_9,
171                                         "FEC_NONE" : parm.FEC_None }
172                                 parm.frequency = int(data[1])
173                                 parm.symbol_rate = int(data[2])
174                                 parm.fec_inner = fec[data[3]]
175                                 parm.modulation = qam[data[4]]
176                                 parm.inversion = inv[data[5]]
177                                 self.__tlist.append(parm)
178                                 status = _("OK")
179                         else:
180                                 status = _("No signal")
181
182                         tmpstr = _("Try to find used Transponders in cable network.. please wait...")
183                         tmpstr += "\n\n"
184                         tmpstr += data[1]
185                         tmpstr += " "
186                         tmpstr += _("kHz")
187                         tmpstr += " - "
188                         tmpstr += status
189                         self.cable_search_session["text"].setText(tmpstr)
190
191         def getCableScanHelper(self, nim_idx):
192                 bus = nimmanager.getI2CDevice(nim_idx)
193                 tunername = nimmanager.getNimName(nim_idx)
194                 cableScanHelpers = {
195                         'CXD1981': 'cxd1978',
196                         'Philips CU1216Mk3': 'tda1002x',
197                 }
198                 cmd = cableScanHelpers.get(tunername, None)
199                 if cmd is not None:
200                         cmd += " --init --scan --verbose --wakeup --inv 2 --bus %d" % bus
201                 return cmd
202
203         def startCableTransponderSearch(self, nim_idx):
204                 if not self.tryGetRawFrontend(nim_idx):
205                         self.session.nav.stopService()
206                         if not self.tryGetRawFrontend(nim_idx):
207                                 if self.session.pipshown: # try to disable pip
208                                         self.session.pipshown = False
209                                         del self.session.pip
210                                 if not self.tryGetRawFrontend(nim_idx):
211                                         self.TransponderSearchFinished()
212                                         return
213                 self.__tlist = [ ]
214                 self.cable_search_container = eConsoleAppContainer()
215                 self.cable_search_container.appClosed.append(self.cableTransponderSearchClosed)
216                 self.cable_search_container.dataAvail.append(self.getCableTransponderData)
217                 cableConfig = config.Nims[nim_idx].cable
218
219                 cmd = None
220                 for fnc in self.CableScanHelpers:
221                         cmd = fnc(nim_idx)
222                         if cmd is not None:
223                                 break
224
225                 if cmd is not None:
226                         if cableConfig.scan_type.value == "bands":
227                                 cmd += " --scan-bands "
228                                 bands = 0
229                                 if cableConfig.scan_band_EU_VHF_I.value:
230                                         bands |= cable_bands["DVBC_BAND_EU_VHF_I"]
231                                 if cableConfig.scan_band_EU_MID.value:
232                                         bands |= cable_bands["DVBC_BAND_EU_MID"]
233                                 if cableConfig.scan_band_EU_VHF_III.value:
234                                         bands |= cable_bands["DVBC_BAND_EU_VHF_III"]
235                                 if cableConfig.scan_band_EU_UHF_IV.value:
236                                         bands |= cable_bands["DVBC_BAND_EU_UHF_IV"]
237                                 if cableConfig.scan_band_EU_UHF_V.value:
238                                         bands |= cable_bands["DVBC_BAND_EU_UHF_V"]
239                                 if cableConfig.scan_band_EU_SUPER.value:
240                                         bands |= cable_bands["DVBC_BAND_EU_SUPER"]
241                                 if cableConfig.scan_band_EU_HYPER.value:
242                                         bands |= cable_bands["DVBC_BAND_EU_HYPER"]
243                                 if cableConfig.scan_band_US_LOW.value:
244                                         bands |= cable_bands["DVBC_BAND_US_LO"]
245                                 if cableConfig.scan_band_US_MID.value:
246                                         bands |= cable_bands["DVBC_BAND_US_MID"]
247                                 if cableConfig.scan_band_US_HIGH.value:
248                                         bands |= cable_bands["DVBC_BAND_US_HI"]
249                                 if cableConfig.scan_band_US_SUPER.value:
250                                         bands |= cable_bands["DVBC_BAND_US_SUPER"]
251                                 if cableConfig.scan_band_US_HYPER.value:
252                                         bands |= cable_bands["DVBC_BAND_US_HYPER"]
253                                 cmd += str(bands)
254                         else:
255                                 cmd += " --scan-stepsize "
256                                 cmd += str(cableConfig.scan_frequency_steps.value)
257                         if cableConfig.scan_mod_qam16.value:
258                                 cmd += " --mod 16"
259                         if cableConfig.scan_mod_qam32.value:
260                                 cmd += " --mod 32"
261                         if cableConfig.scan_mod_qam64.value:
262                                 cmd += " --mod 64"
263                         if cableConfig.scan_mod_qam128.value:
264                                 cmd += " --mod 128"
265                         if cableConfig.scan_mod_qam256.value:
266                                 cmd += " --mod 256"
267                         if cableConfig.scan_sr_6900.value:
268                                 cmd += " --sr 6900000"
269                         if cableConfig.scan_sr_6875.value:
270                                 cmd += " --sr 6875000"
271                         if cableConfig.scan_sr_ext1.value > 450:
272                                 cmd += " --sr "
273                                 cmd += str(cableConfig.scan_sr_ext1.value)
274                                 cmd += "000"
275                         if cableConfig.scan_sr_ext2.value > 450:
276                                 cmd += " --sr "
277                                 cmd += str(cableConfig.scan_sr_ext2.value)
278                                 cmd += "000"
279
280                         print "DVB-C scan command: ", cmd
281
282                         self.cable_search_container.execute(cmd)
283                         tmpstr = _("Try to find used transponders in cable network.. please wait...")
284                         tmpstr += "\n\n..."
285                         self.cable_search_session = self.session.openWithCallback(self.cableTransponderSearchSessionClosed, MessageBox, tmpstr, MessageBox.TYPE_INFO)
286                 else:
287                         modulations = []
288                         symbol_rates = []
289                         frequencies = []
290
291                         if cableConfig.scan_type.value == "bands":
292                                 if cableConfig.scan_band_US_LOW.value:
293                                         frequencies.extend(range(48000, 84000 + 1, 6000))
294                                 if cableConfig.scan_band_US_MID.value:
295                                         frequencies.extend(range(91250, 115250 + 1, 6000))
296                                         frequencies.extend(range(120000, 168000 + 1, 6000))
297                                 if cableConfig.scan_band_US_HIGH.value:
298                                         frequencies.extend(range(174000, 210000 + 1, 6000))
299                                 if cableConfig.scan_band_US_SUPER.value:
300                                         frequencies.extend(range(216000, 294000 + 1, 6000))
301                                 if cableConfig.scan_band_US_HYPER.value:
302                                         frequencies.extend(range(300000, 546000 + 1, 6000))
303                                 if cableConfig.scan_band_EU_VHF_I.value:
304                                         frequencies.extend(range(50500, 64500 + 1, 7000))
305                                         frequencies.extend(range(73000, 81000 + 1, 8000))
306                                 if cableConfig.scan_band_EU_MID.value:
307                                         frequencies.append(107500)
308                                         frequencies.extend(range(113000, 121000 + 1, 8000))
309                                         frequencies.extend(range(128500, 170500 + 1, 7000))
310                                 if cableConfig.scan_band_EU_VHF_III.value:
311                                         frequencies.extend(range(177500, 226500 + 1, 7000))
312                                 if cableConfig.scan_band_EU_SUPER.value:
313                                         frequencies.extend(range(233500, 296500 + 1, 7000))
314                                 if cableConfig.scan_band_EU_HYPER.value:
315                                         frequencies.extend(range(306000, 466000 + 1, 8000))
316                                 if cableConfig.scan_band_EU_UHF_IV.value:
317                                         frequencies.extend(range(474000, 602000 + 1, 8000))
318                                 if cableConfig.scan_band_EU_UHF_V.value:
319                                         frequencies.extend(range(610000, 858000 + 1, 8000))
320                         else:
321                                 frequencies.extend(range(17000, 887000 + 1, cableConfig.scan_frequency_steps.value))
322
323                         if cableConfig.scan_mod_qam16.value:
324                                 modulations.append(eDVBFrontendParametersCable.Modulation_QAM16)
325                         if cableConfig.scan_mod_qam32.value:
326                                 modulations.append(eDVBFrontendParametersCable.Modulation_QAM32)
327                         if cableConfig.scan_mod_qam64.value:
328                                 modulations.append(eDVBFrontendParametersCable.Modulation_QAM64)
329                         if cableConfig.scan_mod_qam128.value:
330                                 modulations.append(eDVBFrontendParametersCable.Modulation_QAM128)
331                         if cableConfig.scan_mod_qam256.value:
332                                 modulations.append(eDVBFrontendParametersCable.Modulation_QAM256)
333                         if cableConfig.scan_sr_6900.value:
334                                 symbol_rates.append(6900000)
335                         if cableConfig.scan_sr_6875.value:
336                                 symbol_rates.append(6875000)
337                         if cableConfig.scan_sr_ext1.value > 450:
338                                 symbol_rates.append(cableConfig.scan_sr_ext1.value * 1000)
339                         if cableConfig.scan_sr_ext2.value > 450:
340                                 symbol_rates.append(cableConfig.scan_sr_ext2.value * 1000)
341
342                         for frequency in frequencies:
343                                 for modulation in modulations:
344                                         for symbol_rate in symbol_rates:
345                                                 parm = eDVBFrontendParametersCable()
346                                                 parm.frequency = frequency
347                                                 parm.symbol_rate = symbol_rate
348                                                 parm.fec_inner = eDVBFrontendParametersCable.FEC_Auto
349                                                 parm.modulation = modulation
350                                                 parm.inversion = eDVBFrontendParametersCable.Inversion_Unknown
351                                                 self.__tlist.append(parm)
352
353                         # XXX: I'm a hack. Please replace me!
354                         self.cable_search_session = self.session.openWithCallback(self.cableTransponderSearchSessionClosed, MessageBox, "", MessageBox.TYPE_INFO)
355                         self.cable_search_session.close(True)
356
357 from time import time
358
359 FOUND_HISTORY_SIZE = 8
360
361 from Components.Sources.CanvasSource import CanvasSource
362 from Components.Sources.List import List
363 from Tools.Directories import fileExists
364 from enigma import eTimer
365
366 class SatBlindscanState(Screen):
367         def __init__(self, session, fe_num, text):
368                 Screen.__init__(self, session)
369                 self["list"]=List()
370                 self["text"]=Label()
371                 self["text"].setText(text)
372                 self["post_action"]=Label()
373                 self["progress"]=Label()
374                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
375                 {
376                         "ok": self.keyOk,
377                         "cancel": self.keyCancel,
378                         "green": self.keyGreen,
379                 }, -2)
380                 self.fe_num = fe_num
381                 self["constellation"] = CanvasSource()
382                 self.onLayoutFinish.append(self.updateConstellation)
383                 self.tmr = eTimer()
384                 self.tmr.callback.append(self.updateConstellation)
385                 self.constellation_supported = None
386                 if fe_num != -1:
387                         self.post_action=1
388                         self.finished=0
389                         self.keyGreen()
390                 else:
391                         self.post_action=-1
392
393         def keyGreen(self):
394                 if self.finished:
395                         self.close(True)
396                 elif self.post_action != -1:
397                         self.post_action ^= 1
398                         if self.post_action:
399                                 self["post_action"].setText(_("MANUALLY start service searching, press green to change"))
400                         else:
401                                 self["post_action"].setText(_("AUTOMATICALLY start service searching, press green to change"))
402
403         def setFinished(self):
404                 if self.post_action:
405                         self.finished=1
406                         self["text"].setText(_("Transponder searching finished!"))
407                         self["post_action"].setText(_("Press green to start service searching!"))
408                 else:
409                         self.close(True)
410
411         def getConstellationBitmap(self, cnt=1):
412                 ret = []
413                 path = "/proc/stb/frontend/%d/constellation_bitmap" %self.fe_num
414                 if self.constellation_supported is None:
415                         s = fileExists(path)
416                         self.constellation_supported = s
417                         if not s:
418                                 self["constellation"].fill(0,0,256,256,0x25101010)
419                                 self["constellation"].flush()
420
421                 if self.constellation_supported:
422                         while cnt > 0:
423                                 f = open(path, "r")
424                                 ret.append(f.readline())
425                                 cnt -= 1
426                                 f.close()
427                 return ret
428
429         def updateConstellation(self, constellation_bitmap_list=None):
430                 if self.constellation_supported or self.constellation_supported is None:
431                         pass
432                 else:
433                         return
434                 self["constellation"].fill(0,0,256,256,0x25101010)
435                 if constellation_bitmap_list:
436                         bitmap_list = constellation_bitmap_list
437                 else:
438                         bitmap_list = self.getConstellationBitmap()
439                 for bitmap in bitmap_list:
440                         Q = []
441                         I = []
442                         for pos in range(0,30,2):
443                                 try:
444                                         val = int(bitmap[pos:pos+2], 16)
445                                 except ValueError:
446                                         print "I constellation data broken at pos", pos
447                                         val = 0
448                                 I.append(val)
449                         for pos in range(30,60,2):
450                                 try:
451                                         val = int(bitmap[pos:pos+2], 16)
452                                 except ValueError:
453                                         print "Q constellation data broken at pos", pos
454                                         val = 0
455                                 Q.append(val)
456                         for i in range(15):
457                                 self["constellation"].fill(I[i],Q[i],1,1,0x25ffffff)
458                 self["constellation"].flush()
459                 if constellation_bitmap_list:
460                         self.tmr.start(3000, True)
461                 else:
462                         self.tmr.start(50, True)
463
464         def keyOk(self):
465                 cur_sel = self["list"].current
466                 if cur_sel:
467                         self.updateConstellation(cur_sel[1])
468
469         def keyCancel(self):
470                 self.tmr.stop()
471                 self.close(False)
472
473 class SatelliteTransponderSearchSupport:
474         def satelliteTransponderSearchSessionClosed(self, *val):
475                 if self.frontend:
476                         self.frontend.getStateChangeSignal().remove(self.frontendStateChanged)
477                         self.frontend = None
478                         self.channel = None
479                 print "satelliteTransponderSearchSessionClosed, val", val
480                 if val and len(val):
481                         if val[0]:
482                                 self.setTransponderSearchResult(self.__tlist)
483                         else:
484                                 self.setTransponderSearchResult(None)
485                 self.satellite_search_session = None
486                 self.__tlist = None
487                 self.TransponderSearchFinished()
488
489         def frontendStateChanged(self, frontend_ptr):
490                 x = { }
491                 self.frontend.getFrontendStatus(x)
492                 assert x, "getFrontendStatus failed!"
493                 if x["tuner_state"] in ("LOCKED", "FAILED"):
494                         state = self.satellite_search_session
495
496                         d = { }
497                         self.frontend.getTransponderData(d, False)
498                         d["tuner_type"] = 'DVB-S'
499                         r = ConvertToHumanReadable(d)
500
501                         if x["tuner_state"] == "LOCKED":
502                                 freq = d["frequency"]
503                                 parm = eDVBFrontendParametersSatellite()
504                                 parm.frequency = int(round(float(freq*2) / 1000)) * 1000
505                                 parm.frequency /= 2
506                                 fstr = str(parm.frequency)
507                                 if self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_Horizontal:
508                                         fstr += "H KHz SR"
509                                 elif self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_Vertical:
510                                         fstr += "V KHz SR"
511                                 elif self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_CircularLeft:
512                                         fstr += "L KHz SR"
513                                 elif self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_CircularRight:
514                                         fstr += "R KHz SR"
515                                 sr = d["symbol_rate"]
516 #                               print "SR before round", sr
517                                 if sr < 0:
518                                         print "WARNING blind SR is < 0... skip"
519                                         self.parm.frequency += self.parm.symbol_rate
520                                 else:
521                                         sr_rounded = round(float(sr*2L) / 1000) * 1000
522                                         sr_rounded /= 2
523 #                                       print "SR after round", sr_rounded
524                                         parm.symbol_rate = int(sr_rounded)
525                                         fstr += str(parm.symbol_rate/1000)
526                                         parm.fec = d["fec_inner"]
527                                         fstr += " "
528                                         fstr += r["fec_inner"]
529                                         parm.inversion = d["inversion"]
530                                         parm.polarisation = d["polarization"]
531                                         parm.orbital_position = d["orbital_position"]
532                                         parm.system = d["system"]
533                                         fstr += " "
534                                         fstr += r["system"]
535                                         parm.modulation = d["modulation"]
536                                         fstr += " "
537                                         fstr += r["modulation"]
538
539                                         if parm.system == eDVBFrontendParametersSatellite.System_DVB_S2:
540                                                 parm.rolloff = d["rolloff"]
541                                                 parm.pilot = d["pilot"]
542                                         self.__tlist.append(parm)
543
544                                         print "LOCKED at", freq, "SEARCHED at", self.parm.frequency, "half bw", (135L*((sr+1000)/1000)/200), "half search range", (self.parm.symbol_rate/2)
545                                         self.parm.frequency = freq
546                                         self.parm.frequency += (135L*((sr+999)/1000)/200)
547                                         self.parm.frequency += self.parm.symbol_rate/2
548
549                                         bm = state.getConstellationBitmap(5)
550                                         self.tp_found.append((fstr, bm))
551                                         state.updateConstellation(bm)
552
553                                         if len(self.tp_found):
554                                                 state["list"].updateList(self.tp_found)
555                                         else:
556                                                 state["list"].setList(self.tp_found)
557                                                 state["list"].setIndex(0)
558                         else:
559                                 self.parm.frequency += self.parm.symbol_rate
560
561                         print "NEXT freq", self.parm.frequency
562
563                         mhz_complete, mhz_done = self.stats()
564                         seconds_done = int(time() - self.start_time)
565
566                         if self.parm.frequency > self.range_list[self.current_range][1]:
567                                 self.parm = self.setNextRange()
568                                 if self.parm is not None:
569                                         tparm = eDVBFrontendParameters()
570                                         tparm.setDVBS(self.parm, False)
571                                         self.frontend.tune(tparm)
572                                 else:
573                                         tmpstr = _("%dMhz scanned") %mhz_complete
574                                         tmpstr += ', '
575                                         tmpstr += _("%d transponders found at %d:%02dmin") %(len(self.tp_found),seconds_done / 60, seconds_done % 60)
576                                         state["progress"].setText(tmpstr)
577                                         state.setFinished()
578                                         self.frontend.getStateChangeSignal().remove(self.frontendStateChanged)
579                                         self.frontend = None
580                                         self.channel = None
581                                         return
582
583                         tmpstr = str((self.parm.frequency+500)/1000)
584                         if self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_Horizontal:
585                                 tmpstr += "H"
586                         elif self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_Vertical:
587                                 tmpstr += "V"
588                         elif self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_CircularLeft:
589                                 tmpstr += "L"
590                         elif self.parm.polarisation == eDVBFrontendParametersSatellite.Polarisation_CircularRight:
591                                 tmpstr += "R"
592
593                         tmpstr += ', '
594                         tmpstr += "%d/%dMhz" %(mhz_done, mhz_complete)
595
596                         tmpstr += ", "
597                         tmpstr += _("%d transponder(s) found") %len(self.tp_found)
598
599                         tmpstr += ', '
600
601                         seconds_complete = (seconds_done * mhz_complete) / mhz_done
602                         tmpstr += _("%d:%02d/%d:%02dmin") %(seconds_done / 60, seconds_done % 60, seconds_complete / 60, seconds_complete % 60)
603
604                         state["progress"].setText(tmpstr)
605
606                         self.tuneNext()
607                 else:
608                         print "unhandled tuner state", x["tuner_state"]
609
610         def tuneNext(self):
611                 tparm = eDVBFrontendParameters()
612                 tparm.setDVBS(self.parm, False)
613                 self.frontend.tune(tparm)
614
615         def setNextRange(self):
616                 if self.current_range is None:
617                         self.current_range = 0
618                 else:
619                         self.current_range += 1
620                 if len(self.range_list) > self.current_range:
621                         bs_range = self.range_list[self.current_range]
622                         parm = eDVBFrontendParametersSatellite()
623                         parm.frequency = bs_range[0]
624                         if self.nim.isCompatible("DVB-S2"):
625                                 steps = { 5 : 2000, 4 : 4000, 3 : 6000, 2 : 8000, 1 : 10000 }[self.scan_sat.bs_accuracy.value]
626                                 parm.system = self.scan_sat.bs_system.value
627                                 parm.pilot = eDVBFrontendParametersSatellite.Pilot_Unknown
628                                 parm.rolloff = eDVBFrontendParametersSatellite.RollOff_alpha_0_35
629                         else:
630                                 steps = 4000
631                                 parm.system = eDVBFrontendParametersSatellite.System_DVB_S
632                         parm.symbol_rate = steps
633                         parm.fec = eDVBFrontendParametersSatellite.FEC_Auto
634                         parm.inversion = eDVBFrontendParametersSatellite.Inversion_Unknown
635                         parm.polarisation = bs_range[2]
636                         parm.orbital_position = self.orb_pos
637                         parm.modulation = eDVBFrontendParametersSatellite.Modulation_QPSK
638                         return parm
639                 return None
640
641         def stats(self):
642                 mhz_complete = 0
643                 mhz_done = 0
644                 cnt = 0
645                 for range in self.range_list:
646                         mhz = (range[1] - range[0]) / 1000
647                         mhz_complete += mhz
648                         if cnt == self.current_range:
649                                 mhz_done += (self.parm.frequency - range[0]) / 1000
650                         elif cnt < self.current_range:
651                                 mhz_done += mhz
652                         cnt += 1
653                 return mhz_complete, mhz_done
654
655         def startSatelliteTransponderSearch(self, nim_idx, orb_pos):
656                 self.frontend = None
657                 self.orb_pos = orb_pos
658                 self.nim = nimmanager.nim_slots[nim_idx]
659                 tunername = nimmanager.getNimName(nim_idx)
660                 self.__tlist = [ ]
661                 self.tp_found = [ ]
662                 self.current_range = None
663                 self.range_list = [ ]
664                 tuner_no = -1
665
666                 print "tunername", tunername
667                 if tunername in ("BCM4505", "BCM4506 (internal)", "Alps BSBE1 C01A/D01A."):
668                         (self.channel, self.frontend) = self.tryGetRawFrontend(nim_idx, False, False)
669                         if not self.frontend:
670                                 self.session.nav.stopService()
671                                 (self.channel, self.frontend) = self.tryGetRawFrontend(nim_idx, False, False)
672                                 if not self.frontend:
673                                         if self.session.pipshown: # try to disable pip
674                                                 self.session.pipshown = False
675                                                 del self.session.pip
676                                         (self.channel, self.frontend) = self.tryGetRawFrontend(nim_idx, False, False)
677                                         if not self.frontend:
678                                                 print "couldn't allocate tuner %d for blindscan!!!" %nim_idx
679                                                 return
680                         self.frontend.getStateChangeSignal().append(self.frontendStateChanged)
681
682                         if self.scan_sat.bs_vertical.value:
683                                 self.range_list.append((self.scan_sat.bs_freq_start.value * 1000, self.scan_sat.bs_freq_stop.value * 1000, eDVBFrontendParametersSatellite.Polarisation_Vertical))
684                         if self.scan_sat.bs_horizontal.value:
685                                 self.range_list.append((self.scan_sat.bs_freq_start.value * 1000, self.scan_sat.bs_freq_stop.value * 1000, eDVBFrontendParametersSatellite.Polarisation_Horizontal))
686
687                         self.parm = self.setNextRange()
688                         if self.parm is not None:
689                                 tparm = eDVBFrontendParameters()
690                                 tparm.setDVBS(self.parm, False)
691                                 self.frontend.tune(tparm)
692                                 self.start_time = time()
693                                 tmpstr = _("Try to find used satellite transponders...")
694                         else:
695                                 tmpstr = _("Nothing to scan! Press Exit!")
696                         x = { }
697                         data = self.frontend.getFrontendData(x)
698                         tuner_no = x["tuner_number"]
699                 else:
700                         tmpstr = _("Blindscan is not supported by this tuner (%s)") %tunername
701                 self.satellite_search_session = self.session.openWithCallback(self.satelliteTransponderSearchSessionClosed, SatBlindscanState, tuner_no, tmpstr)
702                 self.tuneNextTimer = eTimer()
703                 self.tuneNextTimer.callback.append(self.tuneNext)
704
705 class DefaultSatLists(DefaultWizard):
706         def __init__(self, session, silent = True, showSteps = False):
707                 self.xmlfile = "defaultsatlists.xml"
708                 DefaultWizard.__init__(self, session, silent, showSteps, neededTag = "services")
709                 print "configuredSats:", nimmanager.getConfiguredSats()
710
711         def setDirectory(self):
712                 self.directory = []
713                 self.directory.append(resolveFilename(SCOPE_DEFAULTDIR))
714                 import os
715                 os.system("mount %s %s" % (resolveFilename(SCOPE_DEFAULTPARTITION), resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR)))
716                 self.directory.append(resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR))
717                                 
718         def statusCallback(self, status, progress):
719                 print "statusCallback:", status, progress
720                 from Components.DreamInfoHandler import DreamInfoHandler
721                 if status == DreamInfoHandler.STATUS_DONE:
722                         self["text"].setText(_("The installation of the default services lists is finished.") + "\n\n" + _("Please press OK to continue."))
723                         self.markDone()
724                         self.disableKeys = False
725
726 class ScanSetup(ConfigListScreen, Screen, TransponderSearchSupport, CableTransponderSearchSupport, SatelliteTransponderSearchSupport):
727         def __init__(self, session):
728                 Screen.__init__(self, session)
729
730                 self.finished_cb = None
731                 self.updateSatList()
732                 self.service = session.nav.getCurrentService()
733                 self.feinfo = None
734                 frontendData = None
735                 if self.service is not None:
736                         self.feinfo = self.service.frontendInfo()
737                         frontendData = self.feinfo and self.feinfo.getAll(True)
738                 
739                 self.createConfig(frontendData)
740
741                 del self.feinfo
742                 del self.service
743
744                 self["actions"] = NumberActionMap(["SetupActions"],
745                 {
746                         "ok": self.keyGo,
747                         "cancel": self.keyCancel,
748                 }, -2)
749
750                 self.statusTimer = eTimer()
751                 self.statusTimer.callback.append(self.updateStatus)
752                 #self.statusTimer.start(5000, True)
753
754                 self.list = []
755                 ConfigListScreen.__init__(self, self.list)
756                 if not self.scan_nims.value == "":
757                         self.createSetup()
758                         self["introduction"] = Label(_("Press OK to start the scan"))
759                 else:
760                         self["introduction"] = Label(_("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."))
761
762         def runAsync(self, finished_cb):
763                 self.finished_cb = finished_cb
764                 self.keyGo()
765
766         def updateSatList(self):
767                 self.satList = []
768                 for slot in nimmanager.nim_slots:
769                         if slot.isCompatible("DVB-S"):
770                                 self.satList.append(nimmanager.getSatListForNim(slot.slot))
771                         else:
772                                 self.satList.append(None)
773
774         def createSetup(self):
775                 self.list = []
776                 self.multiscanlist = []
777                 if self.scan_nims.value == "":
778                         return
779                 index_to_scan = int(self.scan_nims.value)
780                 print "ID: ", index_to_scan
781
782                 self.tunerEntry = getConfigListEntry(_("Tuner"), self.scan_nims)
783                 self.list.append(self.tunerEntry)
784                 
785                 if self.scan_nims == [ ]:
786                         return
787                 
788                 self.typeOfScanEntry = None
789                 self.systemEntry = None
790                 self.modulationEntry = None
791                 self.satelliteEntry = None
792                 nim = nimmanager.nim_slots[index_to_scan]
793                 if nim.isCompatible("DVB-S"):
794                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_type)
795                         self.list.append(self.typeOfScanEntry)
796                 elif nim.isCompatible("DVB-C"):
797                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typecable)
798                         self.list.append(self.typeOfScanEntry)
799                 elif nim.isCompatible("DVB-T"):
800                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typeterrestrial)
801                         self.list.append(self.typeOfScanEntry)
802
803                 self.scan_networkScan.value = False
804                 self.scan_otherSDT.value = False
805                 if nim.isCompatible("DVB-S"):
806                         if self.scan_type.value == "single_transponder":
807                                 self.updateSatList()
808                                 if nim.isCompatible("DVB-S2"):
809                                         self.systemEntry = getConfigListEntry(_('System'), self.scan_sat.system)
810                                         self.list.append(self.systemEntry)
811                                 else:
812                                         # downgrade to dvb-s, in case a -s2 config was active
813                                         self.scan_sat.system.value = eDVBFrontendParametersSatellite.System_DVB_S
814                                 self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[index_to_scan]))
815                                 self.list.append(getConfigListEntry(_('Frequency'), self.scan_sat.frequency))
816                                 self.list.append(getConfigListEntry(_('Inversion'), self.scan_sat.inversion))
817                                 self.list.append(getConfigListEntry(_('Symbol rate'), self.scan_sat.symbolrate))
818                                 self.list.append(getConfigListEntry(_('Polarization'), self.scan_sat.polarization))
819                                 if self.scan_sat.system.value == eDVBFrontendParametersSatellite.System_DVB_S:
820                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec))
821                                 elif self.scan_sat.system.value == eDVBFrontendParametersSatellite.System_DVB_S2:
822                                         if self.scan_sat.modulation.value == eDVBFrontendParametersSatellite.Modulation_8PSK:
823                                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2_8psk))
824                                         else:
825                                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2_qpsk))
826                                         self.modulationEntry = getConfigListEntry(_('Modulation'), self.scan_sat.modulation)
827                                         self.list.append(self.modulationEntry)
828                                         self.list.append(getConfigListEntry(_('Roll-off'), self.scan_sat.rolloff))
829                                         self.list.append(getConfigListEntry(_('Pilot'), self.scan_sat.pilot))
830                         elif self.scan_type.value == "single_satellite":
831                                 self.updateSatList()
832                                 self.list.append(getConfigListEntry(_("Satellite"), self.scan_satselection[index_to_scan]))
833                                 self.scan_networkScan.value = True
834                         elif self.scan_type.value == "blind_scan":
835                                 self.updateSatList()
836                                 selected_sat_pos = self.scan_satselection[index_to_scan].value
837                                 limit_list = self.nim_sat_frequency_range[index_to_scan][int(selected_sat_pos)]
838                                 l = limit_list[0]
839                                 limits = ( l[0]/1000, l[1]/1000 )
840                                 self.scan_sat.bs_freq_start = ConfigInteger(default = limits[0], limits = (limits[0], limits[1]))
841                                 self.scan_sat.bs_freq_stop = ConfigInteger(default = limits[1], limits = (limits[0], limits[1]))
842                                 self.satelliteEntry = getConfigListEntry(_("Satellite"), self.scan_satselection[index_to_scan])
843                                 self.list.append(self.satelliteEntry)
844                                 self.list.append(getConfigListEntry(_("Frequency start"), self.scan_sat.bs_freq_start))
845                                 self.list.append(getConfigListEntry(_("Frequency stop"), self.scan_sat.bs_freq_stop))
846                                 if nim.isCompatible("DVB-S2"):
847                                         self.list.append(getConfigListEntry(_("Accuracy (higher is better)"), self.scan_sat.bs_accuracy))
848                                 self.list.append(getConfigListEntry(_("Horizontal"), self.scan_sat.bs_horizontal))
849                                 self.list.append(getConfigListEntry(_("Vertical"), self.scan_sat.bs_vertical))
850                                 self.scan_networkScan.value = True
851                         elif self.scan_type.value.find("multisat") != -1:
852                                 tlist = []
853                                 SatList = nimmanager.getSatListForNim(index_to_scan)
854                                 for x in SatList:
855                                         if self.Satexists(tlist, x[0]) == 0:
856                                                 tlist.append(x[0])
857                                                 sat = ConfigEnableDisable(default = self.scan_type.value.find("_yes") != -1 and True or False)
858                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[0]), sat)
859                                                 self.list.append(configEntry)
860                                                 self.multiscanlist.append((x[0], sat))
861                                 self.scan_networkScan.value = True
862                 elif nim.isCompatible("DVB-C"):
863                         if self.scan_typecable.value == "single_transponder":
864                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_cab.frequency))
865                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_cab.inversion))
866                                 self.list.append(getConfigListEntry(_("Symbol rate"), self.scan_cab.symbolrate))
867                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_cab.modulation))
868                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_cab.fec))
869                 elif nim.isCompatible("DVB-T"):
870                         if self.scan_typeterrestrial.value == "single_transponder":
871                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_ter.frequency))
872                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_ter.inversion))
873                                 self.list.append(getConfigListEntry(_("Bandwidth"), self.scan_ter.bandwidth))
874                                 self.list.append(getConfigListEntry(_("Code rate HP"), self.scan_ter.fechigh))
875                                 self.list.append(getConfigListEntry(_("Code rate LP"), self.scan_ter.feclow))
876                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_ter.modulation))
877                                 self.list.append(getConfigListEntry(_("Transmission mode"), self.scan_ter.transmission))
878                                 self.list.append(getConfigListEntry(_("Guard interval"), self.scan_ter.guard))
879                                 self.list.append(getConfigListEntry(_("Hierarchy info"), self.scan_ter.hierarchy))
880                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_networkScan))
881                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
882                 self.list.append(getConfigListEntry(_("Only Free scan"), self.scan_onlyfree))
883                 if config.usage.setup_level.index >= 2:
884                         self.list.append(getConfigListEntry(_("Lookup other SDT"), self.scan_otherSDT))
885                         self.list.append(getConfigListEntry(_("Skip empty transponders"), self.scan_skipEmpty))
886                 self["config"].list = self.list
887                 self["config"].l.setList(self.list)
888
889         def Satexists(self, tlist, pos):
890                 for x in tlist:
891                         if x == pos:
892                                 return 1
893                 return 0
894
895         def newConfig(self):
896                 cur = self["config"].getCurrent()
897                 print "cur is", cur
898                 if cur == self.typeOfScanEntry or \
899                         cur == self.tunerEntry or \
900                         cur == self.systemEntry or \
901                         (self.modulationEntry and self.systemEntry[1].value == eDVBFrontendParametersSatellite.System_DVB_S2 and cur == self.modulationEntry) or \
902                         (self.satelliteEntry and cur == self.satelliteEntry):
903                         self.createSetup()
904
905         def createConfig(self, frontendData):
906                                                            #("Type", frontendData["system"], TYPE_TEXT),
907                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
908                                            #("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
909                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
910                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
911                                            #("Polarization", frontendData["polarization"], TYPE_TEXT),
912                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
913                                            #("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
914                                                 #)
915                 #elif frontendData["tuner_type"] == "DVB-C":
916                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
917                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
918                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
919                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
920                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
921                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
922                         #                  ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
923                                                 #)
924                 #elif frontendData["tuner_type"] == "DVB-T":
925                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
926                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
927                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
928                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
929                                            #("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
930                                            #("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
931                                            #("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
932                                            #("Constellation", frontendData["constellation"], TYPE_TEXT),
933                                            #("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
934                                            #("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
935                                            #("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT),
936                         defaultSat = {
937                                 "orbpos": 192,
938                                 "system": eDVBFrontendParametersSatellite.System_DVB_S,
939                                 "frequency": 11836,
940                                 "inversion": eDVBFrontendParametersSatellite.Inversion_Unknown,
941                                 "symbolrate": 27500,
942                                 "polarization": eDVBFrontendParametersSatellite.Polarisation_Horizontal,
943                                 "fec": eDVBFrontendParametersSatellite.FEC_Auto,
944                                 "fec_s2_8psk": eDVBFrontendParametersSatellite.FEC_2_3,
945                                 "fec_s2_qpsk": eDVBFrontendParametersSatellite.FEC_2_3,
946                                 "modulation": eDVBFrontendParametersSatellite.Modulation_QPSK }
947                         defaultCab = {
948                                 "frequency": 466,
949                                 "inversion": eDVBFrontendParametersCable.Inversion_Unknown,
950                                 "modulation": eDVBFrontendParametersCable.Modulation_QAM64,
951                                 "fec": eDVBFrontendParametersCable.FEC_Auto,
952                                 "symbolrate": 6900 }
953                         defaultTer = {
954                                 "frequency" : 466000,
955                                 "inversion" : eDVBFrontendParametersTerrestrial.Inversion_Unknown,
956                                 "bandwidth" : eDVBFrontendParametersTerrestrial.Bandwidth_7MHz,
957                                 "fechigh" : eDVBFrontendParametersTerrestrial.FEC_Auto,
958                                 "feclow" : eDVBFrontendParametersTerrestrial.FEC_Auto,
959                                 "modulation" : eDVBFrontendParametersTerrestrial.Modulation_Auto,
960                                 "transmission_mode" : eDVBFrontendParametersTerrestrial.TransmissionMode_Auto,
961                                 "guard_interval" : eDVBFrontendParametersTerrestrial.GuardInterval_Auto,
962                                 "hierarchy": eDVBFrontendParametersTerrestrial.Hierarchy_Auto }
963
964                         if frontendData is not None:
965                                 ttype = frontendData.get("tuner_type", "UNKNOWN")
966                                 if ttype == "DVB-S":
967                                         defaultSat["system"] = frontendData.get("system", eDVBFrontendParametersSatellite.System_DVB_S)
968                                         defaultSat["frequency"] = frontendData.get("frequency", 0) / 1000
969                                         defaultSat["inversion"] = frontendData.get("inversion", eDVBFrontendParametersSatellite.Inversion_Unknown)
970                                         defaultSat["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
971                                         defaultSat["polarization"] = frontendData.get("polarization", eDVBFrontendParametersSatellite.Polarisation_Horizontal)
972                                         defaultSat["modulation"] = frontendData.get("modulation", eDVBFrontendParametersSatellite.Modulation_QPSK)
973                                         if defaultSat["system"] == eDVBFrontendParametersSatellite.System_DVB_S2:
974                                                 if defaultSat["modulation"] == eDVBFrontendParametersSatellite.Modulation_QPSK:
975                                                         defaultSat["fec_s2_qpsk"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_2_3)
976                                                 else:
977                                                         defaultSat["fec_s2_8psk"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_2_3)
978                                                 defaultSat["rolloff"] = frontendData.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35)
979                                                 defaultSat["pilot"] = frontendData.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown)
980                                         else:
981                                                 defaultSat["fec"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
982                                         defaultSat["orbpos"] = frontendData.get("orbital_position", 0)
983                                 elif ttype == "DVB-C":
984                                         defaultCab["frequency"] = frontendData.get("frequency", 0) / 1000
985                                         defaultCab["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
986                                         defaultCab["inversion"] = frontendData.get("inversion", eDVBFrontendParametersCable.Inversion_Unknown)
987                                         defaultCab["fec"] = frontendData.get("fec_inner", eDVBFrontendParametersCable.FEC_Auto)
988                                         defaultCab["modulation"] = frontendData.get("modulation", eDVBFrontendParametersCable.Modulation_QAM16)
989                                 elif ttype == "DVB-T":
990                                         defaultTer["frequency"] = frontendData.get("frequency", 0)
991                                         defaultTer["inversion"] = frontendData.get("inversion", eDVBFrontendParametersTerrestrial.Inversion_Unknown)
992                                         defaultTer["bandwidth"] = frontendData.get("bandwidth", eDVBFrontendParametersTerrestrial.Bandwidth_7MHz)
993                                         defaultTer["fechigh"] = frontendData.get("code_rate_hp", eDVBFrontendParametersTerrestrial.FEC_Auto)
994                                         defaultTer["feclow"] = frontendData.get("code_rate_lp", eDVBFrontendParametersTerrestrial.FEC_Auto)
995                                         defaultTer["modulation"] = frontendData.get("constellation", eDVBFrontendParametersTerrestrial.Modulation_Auto)
996                                         defaultTer["transmission_mode"] = frontendData.get("transmission_mode", eDVBFrontendParametersTerrestrial.TransmissionMode_Auto)
997                                         defaultTer["guard_interval"] = frontendData.get("guard_interval", eDVBFrontendParametersTerrestrial.GuardInterval_Auto)
998                                         defaultTer["hierarchy"] = frontendData.get("hierarchy_information", eDVBFrontendParametersTerrestrial.Hierarchy_Auto)
999
1000                         self.scan_sat = ConfigSubsection()
1001                         self.scan_cab = ConfigSubsection()
1002                         self.scan_ter = ConfigSubsection()
1003
1004                         self.scan_type = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat")), ("multisat_yes", _("Multisat")), ("blind_scan", _("Blindscan"))])
1005                         self.scan_typecable = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
1006                         self.scan_typeterrestrial = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
1007                         self.scan_clearallservices = ConfigSelection(default = "no", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
1008                         self.scan_onlyfree = ConfigYesNo(default = False)
1009                         self.scan_networkScan = ConfigYesNo(default = False)
1010                         self.scan_skipEmpty = ConfigYesNo(default = True)
1011                         self.scan_otherSDT = ConfigYesNo(default = False)
1012
1013                         nim_list = []
1014                         # collect all nims which are *not* set to "nothing"
1015                         for n in nimmanager.nim_slots:
1016                                 if n.config_mode == "nothing":
1017                                         continue
1018                                 if n.config_mode == "advanced" and len(nimmanager.getSatListForNim(n.slot)) < 1:
1019                                         continue
1020                                 if n.config_mode in ("loopthrough", "satposdepends"):
1021                                         root_id = nimmanager.sec.getRoot(n.slot_id, int(n.config.connectedTo.value))
1022                                         if n.type == nimmanager.nim_slots[root_id].type: # check if connected from a DVB-S to DVB-S2 Nim or vice versa
1023                                                 continue
1024                                 nim_list.append((str(n.slot), n.friendly_full_description))
1025
1026                         self.scan_nims = ConfigSelection(choices = nim_list)
1027
1028                         # status
1029                         self.scan_snr = ConfigSlider()
1030                         self.scan_snr.enabled = False
1031                         self.scan_agc = ConfigSlider()
1032                         self.scan_agc.enabled = False
1033                         self.scan_ber = ConfigSlider()
1034                         self.scan_ber.enabled = False
1035
1036                         # sat
1037                         self.scan_sat.system = ConfigSelection(default = defaultSat["system"], choices = [
1038                                 (eDVBFrontendParametersSatellite.System_DVB_S, _("DVB-S")),
1039                                 (eDVBFrontendParametersSatellite.System_DVB_S2, _("DVB-S2"))])
1040                         self.scan_sat.frequency = ConfigInteger(default = defaultSat["frequency"], limits = (1, 99999))
1041                         self.scan_sat.inversion = ConfigSelection(default = defaultSat["inversion"], choices = [
1042                                 (eDVBFrontendParametersSatellite.Inversion_Off, _("Off")),
1043                                 (eDVBFrontendParametersSatellite.Inversion_On, _("On")),
1044                                 (eDVBFrontendParametersSatellite.Inversion_Unknown, _("Auto"))])
1045                         self.scan_sat.symbolrate = ConfigInteger(default = defaultSat["symbolrate"], limits = (1, 99999))
1046                         self.scan_sat.polarization = ConfigSelection(default = defaultSat["polarization"], choices = [
1047                                 (eDVBFrontendParametersSatellite.Polarisation_Horizontal, _("horizontal")),
1048                                 (eDVBFrontendParametersSatellite.Polarisation_Vertical, _("vertical")),
1049                                 (eDVBFrontendParametersSatellite.Polarisation_CircularLeft, _("circular left")),
1050                                 (eDVBFrontendParametersSatellite.Polarisation_CircularRight, _("circular right"))])
1051                         self.scan_sat.fec = ConfigSelection(default = defaultSat["fec"], choices = [
1052                                 (eDVBFrontendParametersSatellite.FEC_Auto, _("Auto")),
1053                                 (eDVBFrontendParametersSatellite.FEC_1_2, "1/2"),
1054                                 (eDVBFrontendParametersSatellite.FEC_2_3, "2/3"),
1055                                 (eDVBFrontendParametersSatellite.FEC_3_4, "3/4"),
1056                                 (eDVBFrontendParametersSatellite.FEC_5_6, "5/6"),
1057                                 (eDVBFrontendParametersSatellite.FEC_7_8, "7/8"),
1058                                 (eDVBFrontendParametersSatellite.FEC_None, _("None"))])
1059                         self.scan_sat.fec_s2_qpsk = ConfigSelection(default = defaultSat["fec_s2_qpsk"], choices = [
1060                                 (eDVBFrontendParametersSatellite.FEC_1_2, "1/2"),
1061                                 (eDVBFrontendParametersSatellite.FEC_2_3, "2/3"),
1062                                 (eDVBFrontendParametersSatellite.FEC_3_4, "3/4"),
1063                                 (eDVBFrontendParametersSatellite.FEC_3_5, "3/5"),
1064                                 (eDVBFrontendParametersSatellite.FEC_4_5, "4/5"),
1065                                 (eDVBFrontendParametersSatellite.FEC_5_6, "5/6"),
1066                                 (eDVBFrontendParametersSatellite.FEC_8_9, "8/9"),
1067                                 (eDVBFrontendParametersSatellite.FEC_9_10, "9/10")])
1068                         self.scan_sat.fec_s2_8psk = ConfigSelection(default = defaultSat["fec_s2_8psk"], choices = [
1069                                 (eDVBFrontendParametersSatellite.FEC_2_3, "2/3"),
1070                                 (eDVBFrontendParametersSatellite.FEC_3_4, "3/4"),
1071                                 (eDVBFrontendParametersSatellite.FEC_3_5, "3/5"),
1072                                 (eDVBFrontendParametersSatellite.FEC_5_6, "5/6"),
1073                                 (eDVBFrontendParametersSatellite.FEC_8_9, "8/9"),
1074                                 (eDVBFrontendParametersSatellite.FEC_9_10, "9/10")])
1075                         self.scan_sat.modulation = ConfigSelection(default = defaultSat["modulation"], choices = [
1076                                 (eDVBFrontendParametersSatellite.Modulation_QPSK, "QPSK"),
1077                                 (eDVBFrontendParametersSatellite.Modulation_8PSK, "8PSK")])
1078                         self.scan_sat.rolloff = ConfigSelection(default = defaultSat.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35), choices = [
1079                                 (eDVBFrontendParametersSatellite.RollOff_alpha_0_35, "0.35"),
1080                                 (eDVBFrontendParametersSatellite.RollOff_alpha_0_25, "0.25"),
1081                                 (eDVBFrontendParametersSatellite.RollOff_alpha_0_20, "0.20")])
1082                         self.scan_sat.pilot = ConfigSelection(default = defaultSat.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown), choices = [
1083                                 (eDVBFrontendParametersSatellite.Pilot_Off, _("Off")),
1084                                 (eDVBFrontendParametersSatellite.Pilot_On, _("On")),
1085                                 (eDVBFrontendParametersSatellite.Pilot_Unknown, _("Auto"))])
1086
1087
1088                         self.scan_sat.bs_system = ConfigSelection(default = eDVBFrontendParametersSatellite.System_DVB_S2, 
1089                                 choices = [ (eDVBFrontendParametersSatellite.System_DVB_S2, _("DVB-S + DVB-S2")),
1090                                         (eDVBFrontendParametersSatellite.System_DVB_S, _("DVB-S only"))])
1091
1092                         self.scan_sat.bs_accuracy = ConfigSelection(default = 2, choices = [ (1, "1"), (2, "2"), (3, "3"), (4, "4"), (5, "5")])
1093
1094                         self.scan_sat.bs_horizontal = ConfigYesNo(default = True)
1095                         self.scan_sat.bs_vertical = ConfigYesNo(default = True)
1096
1097                         # cable
1098                         self.scan_cab.frequency = ConfigInteger(default = defaultCab["frequency"], limits = (50, 999))
1099                         self.scan_cab.inversion = ConfigSelection(default = defaultCab["inversion"], choices = [
1100                                 (eDVBFrontendParametersCable.Inversion_Off, _("Off")),
1101                                 (eDVBFrontendParametersCable.Inversion_On, _("On")),
1102                                 (eDVBFrontendParametersCable.Inversion_Unknown, _("Auto"))])
1103                         self.scan_cab.modulation = ConfigSelection(default = defaultCab["modulation"], choices = [
1104                                 (eDVBFrontendParametersCable.Modulation_QAM16, "16-QAM"),
1105                                 (eDVBFrontendParametersCable.Modulation_QAM32, "32-QAM"),
1106                                 (eDVBFrontendParametersCable.Modulation_QAM64, "64-QAM"),
1107                                 (eDVBFrontendParametersCable.Modulation_QAM128, "128-QAM"),
1108                                 (eDVBFrontendParametersCable.Modulation_QAM256, "256-QAM")])
1109                         self.scan_cab.fec = ConfigSelection(default = defaultCab["fec"], choices = [
1110                                 (eDVBFrontendParametersCable.FEC_Auto, _("Auto")),
1111                                 (eDVBFrontendParametersCable.FEC_1_2, "1/2"),
1112                                 (eDVBFrontendParametersCable.FEC_2_3, "2/3"),
1113                                 (eDVBFrontendParametersCable.FEC_3_4, "3/4"),
1114                                 (eDVBFrontendParametersCable.FEC_5_6, "5/6"),
1115                                 (eDVBFrontendParametersCable.FEC_7_8, "7/8"),
1116                                 (eDVBFrontendParametersCable.FEC_8_9, "8/9"),
1117                                 (eDVBFrontendParametersCable.FEC_None, _("None"))])
1118                         self.scan_cab.symbolrate = ConfigInteger(default = defaultCab["symbolrate"], limits = (1, 99999))
1119
1120                         # terrestial
1121                         self.scan_ter.frequency = ConfigInteger(default = 466000, limits = (50000, 999000))
1122                         self.scan_ter.inversion = ConfigSelection(default = defaultTer["inversion"], choices = [
1123                                 (eDVBFrontendParametersTerrestrial.Inversion_Off, _("Off")),
1124                                 (eDVBFrontendParametersTerrestrial.Inversion_On, _("On")),
1125                                 (eDVBFrontendParametersTerrestrial.Inversion_Unknown, _("Auto"))])
1126                         # WORKAROUND: we can't use BW-auto
1127                         self.scan_ter.bandwidth = ConfigSelection(default = defaultTer["bandwidth"], choices = [
1128                                 (eDVBFrontendParametersTerrestrial.Bandwidth_8MHz, "8MHz"),
1129                                 (eDVBFrontendParametersTerrestrial.Bandwidth_7MHz, "7MHz"),
1130                                 (eDVBFrontendParametersTerrestrial.Bandwidth_6MHz, "6MHz")])
1131                         #, (eDVBFrontendParametersTerrestrial.Bandwidth_Auto, _("Auto"))))
1132                         self.scan_ter.fechigh = ConfigSelection(default = defaultTer["fechigh"], choices = [
1133                                 (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
1134                                 (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
1135                                 (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
1136                                 (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
1137                                 (eDVBFrontendParametersTerrestrial.FEC_7_8, "7/8"),
1138                                 (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
1139                         self.scan_ter.feclow = ConfigSelection(default = defaultTer["feclow"], choices = [
1140                                 (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
1141                                 (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
1142                                 (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
1143                                 (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
1144                                 (eDVBFrontendParametersTerrestrial.FEC_7_8, "7/8"),
1145                                 (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
1146                         self.scan_ter.modulation = ConfigSelection(default = defaultTer["modulation"], choices = [
1147                                 (eDVBFrontendParametersTerrestrial.Modulation_QPSK, "QPSK"),
1148                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM16, "QAM16"),
1149                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM64, "QAM64"),
1150                                 (eDVBFrontendParametersTerrestrial.Modulation_Auto, _("Auto"))])
1151                         self.scan_ter.transmission = ConfigSelection(default = defaultTer["transmission_mode"], choices = [
1152                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_2k, "2K"),
1153                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_8k, "8K"),
1154                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_Auto, _("Auto"))])
1155                         self.scan_ter.guard = ConfigSelection(default = defaultTer["guard_interval"], choices = [
1156                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_32, "1/32"),
1157                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_16, "1/16"),
1158                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_8, "1/8"),
1159                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_4, "1/4"),
1160                                 (eDVBFrontendParametersTerrestrial.GuardInterval_Auto, _("Auto"))])
1161                         self.scan_ter.hierarchy = ConfigSelection(default = defaultTer["hierarchy"], choices = [
1162                                 (eDVBFrontendParametersTerrestrial.Hierarchy_None, _("None")),
1163                                 (eDVBFrontendParametersTerrestrial.Hierarchy_1, "1"),
1164                                 (eDVBFrontendParametersTerrestrial.Hierarchy_2, "2"),
1165                                 (eDVBFrontendParametersTerrestrial.Hierarchy_4, "4"),
1166                                 (eDVBFrontendParametersTerrestrial.Hierarchy_Auto, _("Auto"))])
1167
1168                         self.scan_scansat = {}
1169                         for sat in nimmanager.satList:
1170                                 #print sat[1]
1171                                 self.scan_scansat[sat[0]] = ConfigYesNo(default = False)
1172
1173                         sec = secClass.getInstance()
1174
1175                         self.nim_sat_frequency_range = []
1176                         self.scan_satselection = []
1177                         for slot in nimmanager.nim_slots:
1178                                 slot_id = slot.slot
1179                                 self.nim_sat_frequency_range.append
1180                                 if slot.isCompatible("DVB-S"):
1181                                         satlist_for_slot = self.satList[slot_id]
1182                                         self.scan_satselection.append(getConfigSatlist(defaultSat["orbpos"], satlist_for_slot))
1183                                         sat_freq_range = { }
1184                                         for sat in satlist_for_slot:
1185                                                 orbpos = sat[0]
1186                                                 sat_freq_range[orbpos] = sec.getFrequencyRangeList(slot_id, orbpos)
1187                                         self.nim_sat_frequency_range.append(sat_freq_range)
1188                                 else:
1189                                         self.nim_sat_frequency_range.append(None)
1190                                         self.scan_satselection.append(None)
1191
1192                         return True
1193
1194         def keyLeft(self):
1195                 ConfigListScreen.keyLeft(self)
1196                 self.newConfig()
1197
1198         def keyRight(self):
1199                 ConfigListScreen.keyRight(self)
1200                 self.newConfig()
1201
1202         def updateStatus(self):
1203                 print "updatestatus"
1204
1205         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position, system, modulation, rolloff, pilot):
1206                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion) + " modulation: " + str(modulation) + " system: " + str(system) + " rolloff" + str(rolloff) + " pilot" + str(pilot)
1207                 print "orbpos: " + str(orbital_position)
1208                 parm = eDVBFrontendParametersSatellite()
1209                 parm.modulation = modulation
1210                 parm.system = system
1211                 parm.frequency = frequency * 1000
1212                 parm.symbol_rate = symbol_rate * 1000
1213                 parm.polarisation = polarisation
1214                 parm.fec = fec
1215                 parm.inversion = inversion
1216                 parm.orbital_position = orbital_position
1217                 parm.rolloff = rolloff
1218                 parm.pilot = pilot
1219                 tlist.append(parm)
1220
1221         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
1222                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
1223                 parm = eDVBFrontendParametersCable()
1224                 parm.frequency = frequency * 1000
1225                 parm.symbol_rate = symbol_rate * 1000
1226                 parm.modulation = modulation
1227                 parm.fec = fec
1228                 parm.inversion = inversion
1229                 tlist.append(parm)
1230
1231         def addTerTransponder(self, tlist, *args, **kwargs):
1232                 tlist.append(buildTerTransponder(*args, **kwargs))
1233
1234         def keyGo(self):
1235                 if self.scan_nims.value == "":
1236                         return
1237                 tlist = []
1238                 flags = None
1239                 startScan = True
1240                 removeAll = True
1241                 index_to_scan = int(self.scan_nims.value)
1242                 
1243                 if self.scan_nims == [ ]:
1244                         self.session.open(MessageBox, _("No tuner is enabled!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1245                         return
1246
1247                 nim = nimmanager.nim_slots[index_to_scan]
1248                 print "nim", nim.slot
1249                 if nim.isCompatible("DVB-S"):
1250                         print "is compatible with DVB-S"
1251                         if self.scan_type.value == "single_transponder":
1252                                 # these lists are generated for each tuner, so this has work.
1253                                 assert len(self.satList) > index_to_scan
1254                                 assert len(self.scan_satselection) > index_to_scan
1255                                 
1256                                 nimsats = self.satList[index_to_scan]
1257                                 selsatidx = self.scan_satselection[index_to_scan].index
1258
1259                                 # however, the satList itself could be empty. in that case, "index" is 0 (for "None").
1260                                 if len(nimsats):
1261                                         orbpos = nimsats[selsatidx][0]
1262                                         if self.scan_sat.system.value == eDVBFrontendParametersSatellite.System_DVB_S:
1263                                                 fec = self.scan_sat.fec.value
1264                                         else:
1265                                                 if self.scan_sat.modulation.value == eDVBFrontendParametersSatellite.Modulation_QPSK:
1266                                                         fec = self.scan_sat.fec_s2_qpsk.value
1267                                                 else:
1268                                                         fec = self.scan_sat.fec_s2_8psk.value
1269                                         print "add sat transponder"
1270                                         self.addSatTransponder(tlist, self.scan_sat.frequency.value,
1271                                                                 self.scan_sat.symbolrate.value,
1272                                                                 self.scan_sat.polarization.value,
1273                                                                 fec,
1274                                                                 self.scan_sat.inversion.value,
1275                                                                 orbpos,
1276                                                                 self.scan_sat.system.value,
1277                                                                 self.scan_sat.modulation.value,
1278                                                                 self.scan_sat.rolloff.value,
1279                                                                 self.scan_sat.pilot.value)
1280                                 removeAll = False
1281                         elif self.scan_type.value == "single_satellite":
1282                                 sat = self.satList[index_to_scan][self.scan_satselection[index_to_scan].index]
1283                                 getInitialTransponderList(tlist, sat[0])
1284                         elif self.scan_type.value.find("multisat") != -1:
1285                                 SatList = nimmanager.getSatListForNim(index_to_scan)
1286                                 for x in self.multiscanlist:
1287                                         if x[1].value:
1288                                                 print "   " + str(x[0])
1289                                                 getInitialTransponderList(tlist, x[0])
1290                         elif self.scan_type.value.find("blind_scan") != -1:
1291                                 startScan = False
1292
1293
1294                 elif nim.isCompatible("DVB-C"):
1295                         if self.scan_typecable.value == "single_transponder":
1296                                 self.addCabTransponder(tlist, self.scan_cab.frequency.value,
1297                                                                                           self.scan_cab.symbolrate.value,
1298                                                                                           self.scan_cab.modulation.value,
1299                                                                                           self.scan_cab.fec.value,
1300                                                                                           self.scan_cab.inversion.value)
1301                                 removeAll = False
1302                         elif self.scan_typecable.value == "complete":
1303                                 if config.Nims[index_to_scan].cable.scan_type.value == "provider":
1304                                         getInitialCableTransponderList(tlist, index_to_scan)
1305                                 else:
1306                                         startScan = False
1307
1308                 elif nim.isCompatible("DVB-T"):
1309                         if self.scan_typeterrestrial.value == "single_transponder":
1310                                 self.addTerTransponder(tlist,
1311                                                 self.scan_ter.frequency.value * 1000,
1312                                                 inversion = self.scan_ter.inversion.value,
1313                                                 bandwidth = self.scan_ter.bandwidth.value,
1314                                                 fechigh = self.scan_ter.fechigh.value,
1315                                                 feclow = self.scan_ter.feclow.value,
1316                                                 modulation = self.scan_ter.modulation.value,
1317                                                 transmission = self.scan_ter.transmission.value,
1318                                                 guard = self.scan_ter.guard.value,
1319                                                 hierarchy = self.scan_ter.hierarchy.value)
1320                                 removeAll = False
1321                         elif self.scan_typeterrestrial.value == "complete":
1322                                 getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(index_to_scan))
1323
1324                 flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
1325
1326                 if self.scan_otherSDT.value:
1327                         flags |= eComponentScan.scanOtherSDT
1328
1329                 if not self.scan_skipEmpty.value:
1330                         flags |= eComponentScan.scanDontSkipEmptyTransponders
1331
1332                 tmp = self.scan_clearallservices.value
1333                 if tmp == "yes":
1334                         flags |= eComponentScan.scanRemoveServices
1335                 elif tmp == "yes_hold_feeds":
1336                         flags |= eComponentScan.scanRemoveServices
1337                         flags |= eComponentScan.scanDontRemoveFeeds
1338
1339                 if tmp != "no" and not removeAll:
1340                         flags |= eComponentScan.scanDontRemoveUnscanned
1341
1342                 if self.scan_onlyfree.value:
1343                         flags |= eComponentScan.scanOnlyFree
1344
1345                 for x in self["config"].list:
1346                         x[1].save()
1347
1348                 if startScan:
1349                         self.startScan(tlist, flags, index_to_scan)
1350                 else:
1351                         self.flags = flags
1352                         self.feid = index_to_scan
1353                         self.tlist = []
1354                         if nim.isCompatible("DVB-C"):
1355                                 self.startCableTransponderSearch(self.feid)
1356                         else:
1357                                 sat = self.satList[index_to_scan][self.scan_satselection[index_to_scan].index]
1358                                 self.startSatelliteTransponderSearch(self.feid, sat[0])
1359
1360         def setTransponderSearchResult(self, tlist):
1361                 self.tlist = tlist
1362
1363         def TransponderSearchFinished(self):
1364                 if self.tlist is None:
1365                         self.tlist = []
1366                 else:
1367                         self.startScan(self.tlist, self.flags, self.feid)
1368
1369         def startScan(self, tlist, flags, feid):
1370                 if len(tlist):
1371                         # flags |= eComponentScan.scanSearchBAT
1372                         if self.finished_cb:
1373                                 self.session.openWithCallback(self.finished_cb, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
1374                         else:
1375                                 self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
1376                 else:
1377                         if self.finished_cb:
1378                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1379                         else:
1380                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1381
1382         def keyCancel(self):
1383                 for x in self["config"].list:
1384                         x[1].cancel()
1385                 self.close()
1386
1387 class ScanSimple(ConfigListScreen, Screen, TransponderSearchSupport, CableTransponderSearchSupport):
1388         def getNetworksForNim(self, nim):
1389                 if nim.isCompatible("DVB-S"):
1390                         networks = nimmanager.getSatListForNim(nim.slot)
1391                 elif not nim.empty:
1392                         networks = [ nim.type ] # "DVB-C" or "DVB-T". TODO: seperate networks for different C/T tuners, if we want to support that.
1393                 else:
1394                         # empty tuners provide no networks.
1395                         networks = [ ]
1396                 return networks
1397
1398         def __init__(self, session):
1399                 Screen.__init__(self, session)
1400
1401                 self["actions"] = ActionMap(["SetupActions"],
1402                 {
1403                         "ok": self.keyGo,
1404                         "cancel": self.keyCancel,
1405                 }, -2)
1406
1407                 self.list = []
1408                 tlist = []
1409
1410                 known_networks = [ ]
1411                 nims_to_scan = [ ]
1412                 self.finished_cb = None
1413
1414                 for nim in nimmanager.nim_slots:
1415                         # collect networks provided by this tuner
1416
1417                         networks_to_scan = [ ]
1418                         need_scan = False
1419                         networks = self.getNetworksForNim(nim)
1420                         print "nim %d provides" % nim.slot, networks
1421                         print "known:", known_networks
1422
1423                         # we only need to scan on the first tuner which provides a network.
1424                         # this gives the first tuner for each network priority for scanning.
1425                         for x in networks:
1426                                 if x not in known_networks:
1427                                         need_scan = True
1428                                         print x, "not in ", known_networks
1429                                         networks_to_scan.append(x)
1430
1431                         # don't offer to scan nims if nothing is connected
1432                         if not nimmanager.somethingConnected(nim.slot):
1433                                 need_scan = False
1434
1435                         if need_scan:
1436                                 known_networks += networks_to_scan
1437                                 nims_to_scan.append(nim)
1438
1439                 # we save the config elements to use them on keyGo
1440                 self.nim_enable = [ ]
1441
1442                 if len(nims_to_scan):
1443                         self.scan_otherSDT = ConfigYesNo(default = False)
1444                         self.scan_clearallservices = ConfigSelection(default = "yes", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
1445                         self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
1446                         if config.usage.setup_level.index >= 2:
1447                                 self.list.append(getConfigListEntry(_("Lookup other SDT"), self.scan_otherSDT))
1448
1449                         for nim in nims_to_scan:
1450                                 nimconfig = ConfigYesNo(default = True)
1451                                 nimconfig.nim_index = nim.slot
1452                                 self.nim_enable.append(nimconfig)
1453                                 self.list.append(getConfigListEntry(_("Scan ") + nim.slot_name + " (" + nim.friendly_type + ")", nimconfig))
1454
1455                 ConfigListScreen.__init__(self, self.list)
1456                 self["header"] = Label(_("Automatic Scan"))
1457                 self["footer"] = Label(_("Press OK to scan"))
1458
1459         def runAsync(self, finished_cb):
1460                 self.finished_cb = finished_cb
1461                 self.keyGo()
1462
1463         def keyGo(self):
1464                 self.scanList = []
1465                 self.known_networks = set()
1466                 self.nim_iter=0
1467                 self.buildTransponderList()
1468
1469         def buildTransponderList(self): # this method is called multiple times because of asynchronous stuff
1470                 APPEND_NOW = 0
1471                 SEARCH_CABLE_TRANSPONDERS = 1
1472                 action = APPEND_NOW
1473
1474                 n = self.nim_iter < len(self.nim_enable) and self.nim_enable[self.nim_iter] or None
1475                 self.nim_iter += 1
1476                 if n:
1477                         if n.value: # check if nim is enabled
1478                                 flags = 0
1479                                 nim = nimmanager.nim_slots[n.nim_index]
1480                                 networks = set(self.getNetworksForNim(nim))
1481
1482                                 # don't scan anything twice
1483                                 networks.discard(self.known_networks)
1484
1485                                 tlist = [ ]
1486                                 if nim.isCompatible("DVB-S"):
1487                                         # get initial transponders for each satellite to be scanned
1488                                         for sat in networks:
1489                                                 getInitialTransponderList(tlist, sat[0])
1490                                 elif nim.isCompatible("DVB-C"):
1491                                         if config.Nims[nim.slot].cable.scan_type.value == "provider":
1492                                                 getInitialCableTransponderList(tlist, nim.slot)
1493                                         else:
1494                                                 action = SEARCH_CABLE_TRANSPONDERS
1495                                 elif nim.isCompatible("DVB-T"):
1496                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(nim.slot))
1497                                 else:
1498                                         assert False
1499
1500                                 if self.scan_otherSDT.value:
1501                                         flags |= eComponentScan.scanOtherSDT
1502                                 flags |= eComponentScan.scanNetworkSearch #FIXMEEE.. use flags from cables / satellites / terrestrial.xml
1503                                 tmp = self.scan_clearallservices.value
1504                                 if tmp == "yes":
1505                                         flags |= eComponentScan.scanRemoveServices
1506                                 elif tmp == "yes_hold_feeds":
1507                                         flags |= eComponentScan.scanRemoveServices
1508                                         flags |= eComponentScan.scanDontRemoveFeeds
1509
1510                                 if action == APPEND_NOW:
1511                                         self.scanList.append({"transponders": tlist, "feid": nim.slot, "flags": flags})
1512                                 elif action == SEARCH_CABLE_TRANSPONDERS:
1513                                         self.flags = flags
1514                                         self.feid = nim.slot
1515                                         self.startCableTransponderSearch(nim.slot)
1516                                         return
1517                                 else:
1518                                         assert False
1519
1520                         self.buildTransponderList() # recursive call of this function !!!
1521                         return
1522                 # when we are here, then the recursion is finished and all enabled nims are checked
1523                 # so we now start the real transponder scan
1524                 self.startScan(self.scanList)
1525
1526         def startScan(self, scanList):
1527                 if len(scanList):
1528                         if self.finished_cb:
1529                                 self.session.openWithCallback(self.finished_cb, ServiceScan, scanList = scanList)
1530                         else:
1531                                 self.session.open(ServiceScan, scanList = scanList)
1532                 else:
1533                         if self.finished_cb:
1534                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1535                         else:
1536                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
1537
1538         def setTransponderSearchResult(self, tlist):
1539                 if tlist is not None:
1540                         self.scanList.append({"transponders": tlist, "feid": self.feid, "flags": self.flags})
1541
1542         def TransponderSearchFinished(self):
1543                 self.buildTransponderList()
1544
1545         def keyCancel(self):
1546                 self.close()
1547
1548         def Satexists(self, tlist, pos):
1549                 for x in tlist:
1550                         if x == pos:
1551                                 return 1
1552                 return 0
1553