remove unneeded (double) close
[enigma2.git] / lib / python / Screens / ScanSetup.py
1 from Screen import Screen
2 from ServiceScan import *
3 from Components.config import *
4 from Components.ActionMap import NumberActionMap
5 from Components.ConfigList import ConfigList
6 from Components.NimManager import nimmanager
7 from Components.Label import Label
8 from enigma import eDVBFrontendParametersSatellite, eComponentScan, eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial
9
10 def buildTerTransponder(frequency, 
11                 inversion=2, bandwidth = 3, fechigh = 6, feclow = 6,
12                 modulation = 2, transmission = 2, guard = 4,
13                 hierarchy = 4):
14         # WARNING: normally, enums are working directly.
15         # Don't copy this (very bad)!! Instead either fix swig (good) or
16         # move this into a central place.
17         Bw8MHz = 0
18         Bw7MHz = 1
19         Bw6MHz = 2
20         Bw5MHz = 3
21         BwAuto = 4
22         
23         f1_2 = 0
24         f2_3 = 1
25         f3_4 = 2
26         f5_6 = 3
27         f7_8 = 4
28         fAuto = 5
29         
30         TM2k = 0
31         TM8k = 1
32         TM4k = 2
33         TMAuto = 3
34         
35         GI_1_32 = 0
36         GI_1_16 = 1
37         GI_1_8 = 2
38         GI_1_4 = 3
39         GI_Auto = 4
40         
41         HNone = 0
42         H1 = 1
43         H2 = 2
44         H4 = 3
45         HAuto = 4
46
47         QPSK = 0
48         QAM16 = 1
49         QAM64 = 2
50         Auto = 3
51         
52         Off = 0
53         On = 1
54         Unknown = 2
55
56         parm = eDVBFrontendParametersTerrestrial()
57
58         parm.frequency = frequency
59
60         parm.inversion = [Off, On, Unknown][inversion]
61         parm.bandwidth = [Bw8MHz, Bw7MHz, Bw6MHz, BwAuto][bandwidth] # Bw5MHz unsupported
62         parm.code_rate_HP = [fAuto, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto][fechigh]
63         parm.code_rate_LP = [fAuto, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto][feclow]
64         parm.modulation = [QPSK, QAM16, Auto][modulation] # QAM64 unsupported
65         parm.transmission_mode = [TM2k, TM8k, TMAuto][transmission] # TM4k unsupported
66         parm.guard_interval = [GI_1_32, GI_1_16, GI_1_8, GI_1_4, GI_Auto][guard]
67         parm.hierarchy = [HNone, H1, H2, H4, HAuto][hierarchy]
68         
69         return parm
70
71 def getInitialTransponderList(tlist, pos):
72         list = nimmanager.getTransponders(pos)
73
74         for x in list:
75                 if x[0] == 0:           #SAT
76                         parm = eDVBFrontendParametersSatellite()
77                         parm.frequency = x[1]
78                         parm.symbol_rate = x[2]
79                         parm.polarisation = x[3]#lookup_sat_polarisation[x[3]] # eDVBFrontendParametersSatellite.Polarisation.Vertical
80                         parm.fec = x[4]                 # eDVBFrontendParametersSatellite.FEC.f3_4;
81                         #parm.fec = 6                                   # AUTO
82                         #parm.inversion = 1     #eDVBFrontendParametersSatellite.Inversion.Off;
83                         parm.inversion = 2              #AUTO
84                         parm.orbital_position = pos
85                         tlist.append(parm)
86
87 def getInitialCableTransponderList(tlist, cable):
88         list = nimmanager.getTranspondersCable(cable)
89
90         for x in list:
91                 if x[0] == 1:           #CABLE
92                         parm = eDVBFrontendParametersCable()
93                         parm.frequency = x[1]
94                         parm.symbol_rate = x[2]
95                         parm.modulation = x[3] # AUTO
96                         parm.fec_inner = x[4] # AUTO
97                         parm.inversion = 2 # AUTO
98                         tlist.append(parm)
99
100 def getInitialTerrestrialTransponderList(tlist, region):
101         list = nimmanager.getTranspondersTerrestrial(region)
102         
103
104 #               inversion=2, bandwidth = 3, fechigh = 6, feclow = 6,
105 #               modulation = 2, transmission = 2, guard = 4,
106 #               hierarchy = 4):
107
108         for x in list:
109 #self.transponders[self.parsedTer].append((2, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
110                 if x[0] == 2:           #TERRESTRIAL
111                         # FIXME: we need to convert the other parameters...
112                         
113                                 # convert terrestrial.xml bandwidth to our enum
114                         if x[2] in [0, 1]:
115                                 bandwidth = [1, 0][x[2]]
116                         else:
117                                 bandwidth = 3 # auto
118                         
119                         parm = buildTerTransponder(x[1], bandwidth = [1, 0][x[2]])
120                         tlist.append(parm)
121
122
123 class ScanSetup(Screen):
124         def __init__(self, session):
125                 Screen.__init__(self, session)
126
127                 self.updateSatList()
128                 self.createConfig()
129
130
131                 self["actions"] = NumberActionMap(["SetupActions"],
132                 {
133                         "ok": self.keyGo,
134                         "cancel": self.keyCancel,
135                         "left": self.keyLeft,
136                         "right": self.keyRight,
137                         "1": self.keyNumberGlobal,
138                         "2": self.keyNumberGlobal,
139                         "3": self.keyNumberGlobal,
140                         "4": self.keyNumberGlobal,
141                         "5": self.keyNumberGlobal,
142                         "6": self.keyNumberGlobal,
143                         "7": self.keyNumberGlobal,
144                         "8": self.keyNumberGlobal,
145                         "9": self.keyNumberGlobal,
146                         "0": self.keyNumberGlobal
147                 }, -1)
148                 
149                 self.statusTimer = eTimer()
150                 self.statusTimer.timeout.get().append(self.updateStatus)
151                 #self.statusTimer.start(5000, True)
152
153                 self.list = []
154                 self["config"] = ConfigList(self.list)
155                 self.createSetup()
156
157                 self["introduction"] = Label(_("Press OK to start the scan"))
158
159         def run(self):
160                 self.keyGo()
161
162         def updateSatList(self):
163                 self.satList = []
164                 for slot in nimmanager.nimslots:
165                         if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
166                                 self.satList.append(nimmanager.getSatListForNim(slot.slotid))
167                         else:
168                                 self.satList.append(None)
169                                 
170         def createSetup(self):
171                 self.list = []
172                 self.multiscanlist = []
173                 print "ID: " + str(config.scan.nims.value)
174
175                 self.tunerEntry = getConfigListEntry(_("Tuner"), config.scan.nims)
176                 self.list.append(self.tunerEntry)
177                 
178                 self.typeOfScanEntry = None
179                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
180                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.type)
181                         self.list.append(self.typeOfScanEntry)
182                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
183                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typecable)
184                         self.list.append(self.typeOfScanEntry)
185                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
186                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typeterrestrial)
187                         self.list.append(self.typeOfScanEntry)
188
189
190                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
191
192                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
193                                 self.list.append(getConfigListEntry(_('Satellite'), config.scan.satselection[config.scan.nims.value]))
194                                 self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
195                                 self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
196                                 self.list.append(getConfigListEntry(_('Symbol Rate'), config.scan.sat.symbolrate))
197                                 self.list.append(getConfigListEntry(_("Polarity"), config.scan.sat.polarization))
198                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec))
199                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
200                                 self.updateSatList()
201                                 print config.scan.satselection[config.scan.nims.value]
202                                 self.list.append(getConfigListEntry(_("Satellite"), config.scan.satselection[config.scan.nims.value]))
203                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
204                                 # if (norotor)
205                                 tlist = []
206                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
207         
208                                 for x in SatList:
209                                         if self.Satexists(tlist, x[1]) == 0:
210                                                 tlist.append(x[1])
211                                                 sat = configElement_nonSave(x[1], configSelection, 0, (("enable", _("Enable")), ("disable", _("Disable"))))
212                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[1]), sat)
213                                                 self.list.append(configEntry)
214                                                 self.multiscanlist.append(configEntry)
215                                 # if (rotor):
216                            # for sat in nimmanager.satList:
217                                 #       self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))
218
219
220                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
221                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
222                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.cab.frequency))
223                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.cab.inversion))
224                                 self.list.append(getConfigListEntry(_("Symbol Rate"), config.scan.cab.symbolrate))
225                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.cab.modulation))
226                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.cab.fec))
227                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.cab.networkScan))
228                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
229                                 pass
230                                 
231                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
232                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
233                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.ter.frequency))
234                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.ter.networkScan))
235                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.ter.inversion))
236                                 self.list.append(getConfigListEntry(_("Bandwidth"), config.scan.ter.bandwidth))
237                                 self.list.append(getConfigListEntry(_("Code rate high"), config.scan.ter.fechigh))
238                                 self.list.append(getConfigListEntry(_("Code rate low"), config.scan.ter.feclow))
239                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.ter.modulation))
240                                 self.list.append(getConfigListEntry(_("Transmission mode"), config.scan.ter.transmission))
241                                 self.list.append(getConfigListEntry(_("Guard interval mode"), config.scan.ter.guard))
242                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), config.scan.ter.hierarchy))
243                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
244                                 pass
245
246                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"] and currentConfigSelectionElement(config.scan.type) == "single_transponder") or \
247                         (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"] and currentConfigSelectionElement(config.scan.typecable) == "single_transponder") or \
248                         (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"] and currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder"):
249                                 self.configElementSNR = getConfigListEntry(_("SNR"), config.scan.snr)
250                                 self.list.append(self.configElementSNR)
251                                 self.configElementACG = getConfigListEntry(_("AGC"), config.scan.agc)
252                                 self.list.append(self.configElementACG)
253                                 self.configElementBER = getConfigListEntry(_("BER"), config.scan.ber)
254                                 self.list.append(self.configElementBER)
255                                 self.statusTimer.start(500, False)
256                 else:
257                         self.statusTimer.stop()
258
259                 self["config"].list = self.list
260                 self["config"].l.setList(self.list)
261
262         def Satexists(self, tlist, pos):
263                 for x in tlist:
264                         if x == pos:
265                                 return 1
266                 return 0
267
268         def newConfig(self):
269                 print self["config"].getCurrent()
270                 if self["config"].getCurrent() == self.typeOfScanEntry:
271                         self.createSetup()
272                 if self["config"].getCurrent() == self.tunerEntry:
273                         self.createSetup()
274
275         def createConfig(self):
276                         config.scan = ConfigSubsection()
277                         config.scan.sat = ConfigSubsection()
278                         config.scan.cab = ConfigSubsection()
279                         config.scan.ter = ConfigSubsection()
280
281                         config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, (("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat"))))
282                         config.scan.typecable = configElement_nonSave("config.scan.typecable", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
283                         config.scan.typeterrestrial = configElement_nonSave("config.scan.typeterrestrial", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
284
285                         nimList = [ ]
286                         for nim in nimmanager.nimList():
287                                 nimList.append(nim[0])
288                         #nimList.append("all")
289                         config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
290                         
291                         # status
292                         config.scan.snr = configElement_nonSave("config.scan.snr", configSlider, 0, (1, 100))
293                         config.scan.snr.enabled = False
294                         config.scan.agc = configElement_nonSave("config.scan.agc", configSlider, 0, (1, 100))
295                         config.scan.agc.enabled = False
296                         config.scan.ber = configElement_nonSave("config.scan.ber", configSlider, 0, (1, 100))
297                         config.scan.ber.enabled = False
298
299                         # sat
300                         config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, [11836], configsequencearg.get("INTEGER", (1, 99999)))
301                         config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), _("Auto")))
302                         config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, [27500], configsequencearg.get("INTEGER", (1, 99999)))
303                         config.scan.sat.polarization = configElement_nonSave("config.scan.sat.polarization", configSelection, 0, (("horizontal", _("horizontal")), ("vertical", _("vertical")),  ("circular_left", _("circular left")), ("circular_right", _("circular right"))))
304                         config.scan.sat.fec = configElement_nonSave("config.scan.sat.fec", configSelection, 7, (("auto", _("Auto")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("none", _("None"))))
305
306                         # cable
307                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (50, 999)))
308                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
309                         config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, 0, (("auto", _("Auto")), ("16qam", "16-QAM"), ("32qam", "32-QAM"), ("64qam", "64-QAM"), ("128qam", "128-QAM"), ("256qam", "256-QAM")))
310                         config.scan.cab.fec = configElement_nonSave("config.scan.cab.fec", configSelection, 0, (("auto", _("Auto")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("8_9", "8/9"), ("none", _("None"))))
311                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 9999)))
312                         config.scan.cab.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
313
314                         # terrestial
315                         config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (100, 900)))
316                         config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
317                         # WORKAROUND: we can't use BW-auto
318                         config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 0, (("8MHz", "8MHz"), ("7MHz", "7MHz"), ("6MHz", "6MHz")))
319                         #, ("auto", _("Auto"))))
320                         config.scan.ter.fechigh = configElement_nonSave("config.scan.ter.fechigh", configSelection, 6, (("none", _("None")), "1/2", "2/3", "3/4", "5/6", "7/8", _("Auto")))
321                         config.scan.ter.feclow = configElement_nonSave("config.scan.ter.feclow", configSelection, 6, (_("None"), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("auto", _("Auto"))))
322                         config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 2, (("qpsk", "QPSK"), ("qam16", "QAM16"), ("auto", _("Auto"))))
323                         config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 2, (("2k", "2K"), ("8k", "8K"), ("auto", _("Auto"))))
324                         config.scan.ter.guard = configElement_nonSave("config.scan.ter.guard", configSelection, 4, (("1_32", "1/32"), ("1_16", "1/16"), ("1_8", "1/8"), ("1_4", "1/4"), ("auto", _("Auto"))))
325                         config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 4, (("none", _("None")), ("1", "1"), ("2", "2"), ("4", "4"), ("auto", _("Auto"))))
326                         config.scan.ter.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
327
328                         config.scan.scansat = {}
329                         for sat in nimmanager.satList:
330                                 #print sat[1]
331                                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
332
333                         config.scan.satselection = []
334                         slotid = 0
335                         for slot in nimmanager.nimslots:
336                                 if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
337                                         print str(slot.slotid) + " : " + str(self.satList)
338                                         config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, 0, self.satList[slot.slotid]))
339                                 else:
340                                         config.scan.satselection.append(None)
341         def keyLeft(self):
342                 self["config"].handleKey(config.key["prevElement"])
343                 self.newConfig()
344
345         def keyRight(self):
346                 self["config"].handleKey(config.key["nextElement"])
347                 self.newConfig()
348
349         def updateStatus(self):
350                 print "updatestatus"
351
352         def keyNumberGlobal(self, number):
353                 print "You pressed number " + str(number)
354                 if (self["config"].getCurrent()[1].parent.enabled == True):
355                         self["config"].handleKey(config.key[str(number)])
356
357         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
358                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
359                 print "orbpos: " + str(orbital_position)
360                 parm = eDVBFrontendParametersSatellite()
361                 parm.frequency = frequency * 1000
362                 parm.symbol_rate = symbol_rate * 1000
363                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
364                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
365                 #parm.fec = 6                                   # AUTO
366                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
367                 #parm.inversion = 2             #AUTO
368                 parm.orbital_position = int(orbital_position)
369                 tlist.append(parm)
370
371         # FIXME use correct parameters
372         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
373                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
374                 parm = eDVBFrontendParametersCable()
375                 parm.frequency = frequency * 1000
376                 parm.symbol_rate = symbol_rate * 1000
377                 parm.modulation = modulation # modulation # eDVBFrontendParametersSatellite.Polarisation.Verti  
378                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
379                 #parm.fec = 6                                   # AUTO
380                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
381                 #parm.inversion = 2             #AUTO
382                 tlist.append(parm)
383
384         def addTerTransponder(self, tlist, *args, **kwargs):
385                 tlist.append(buildTerTransponder(*args, **kwargs))
386
387         def keyGo(self):
388                 tlist = []
389                 flags = 0
390                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
391                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
392
393                                 self.addSatTransponder(tlist, config.scan.sat.frequency.value[0],
394                                                                                           config.scan.sat.symbolrate.value[0],
395                                                                                           config.scan.sat.polarization.value,
396                                                                                           config.scan.sat.fec.value,
397                                                                                           config.scan.sat.inversion.value,
398                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
399                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
400                                 getInitialTransponderList(tlist, int(self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1]))
401                                 flags |= eComponentScan.scanNetworkSearch
402         
403                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
404                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
405         
406                                 for x in self.multiscanlist:
407                                         if x[1].parent.value == 0:
408                                                 print "   " + str(x[1].parent.configPath)
409                                                 getInitialTransponderList(tlist, x[1].parent.configPath)
410                                 flags |= eComponentScan.scanNetworkSearch
411
412                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
413                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
414                                 self.addCabTransponder(tlist, config.scan.cab.frequency.value[0],
415                                                                                           config.scan.cab.symbolrate.value[0],
416                                                                                           config.scan.cab.modulation.value,
417                                                                                           config.scan.cab.fec.value,
418                                                                                           config.scan.cab.inversion.value)
419                                 if  currentConfigSelectionElement(config.scan.cab.networkScan) == "yes":
420                                         flags |= eComponentScan.scanNetworkSearch
421                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
422                                 getInitialCableTransponderList(tlist, nimmanager.getCableDescription(config.scan.nims.value))
423                                 flags |= eComponentScan.scanNetworkSearch
424
425                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
426                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
427                                 self.addTerTransponder(tlist, 
428                                                 config.scan.ter.frequency.value[0] * 1000000,
429                                                 inversion = config.scan.ter.inversion.value,
430                                                 bandwidth = config.scan.ter.bandwidth.value,
431                                                 fechigh = config.scan.ter.fechigh.value,
432                                                 feclow = config.scan.ter.feclow.value,
433                                                 modulation = config.scan.ter.modulation.value,
434                                                 transmission = config.scan.ter.transmission.value,
435                                                 guard = config.scan.ter.guard.value,
436                                                 hierarchy = config.scan.ter.hierarchy.value)
437                                 if currentConfigSelectionElement(config.scan.ter.networkScan) == "yes":
438                                         flags |= eComponentScan.scanNetworkSearch
439                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
440                                 getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(config.scan.nims.value))
441                                 flags |= eComponentScan.scanNetworkSearch
442
443                 for x in self["config"].list:
444                         x[1].save()
445
446                 feid = config.scan.nims.value
447                 # flags |= eComponentScan.scanSearchBAT
448                 self.session.openWithCallback(self.doNothing, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
449
450                 #self.close()
451         def doNothing(self):
452                 pass
453
454         def keyCancel(self):
455                 for x in self["config"].list:
456                         x[1].cancel()
457                 self.close()
458
459 class ScanSimple(Screen):
460         def run(self):
461                 self.keyGo()
462
463         def keyGo(self):
464                 scanList = []
465                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"] and nimmanager.getNimType(0) == nimmanager.getNimType(1):
466                         sec = eDVBSatelliteEquipmentControl.getInstance()
467                         if sec is not None:
468                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
469                         else:
470                                 exclusive_satellites = [0,0]
471                         print "exclusive satellites", exclusive_satellites
472                         two_sat_tuners = True
473                 else:
474                         two_sat_tuners = False
475
476                 for x in self.list:
477                         slotid = x[1].parent.configPath
478                         print "Scan Tuner", slotid, "-", currentConfigSelectionElement(x[1].parent)
479                         if currentConfigSelectionElement(x[1].parent) == "yes":
480                                 tlist = [ ]
481                                 if nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-S"]:
482                                         if two_sat_tuners:
483                                                 if slotid > 0:
484                                                         idx = exclusive_satellites[0]+1
485                                                 else:
486                                                         idx = 0
487                                                 exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
488                                                 print "exclusive_nim_sats", exclusive_nim_sats
489                                         SatList = nimmanager.getSatListForNim(slotid)
490                                         for sat in SatList:
491                                                 if not two_sat_tuners or (sat[1] in exclusive_nim_sats or slotid == 0):
492                                                         print sat
493                                                         getInitialTransponderList(tlist, sat[1])
494                                 elif nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-C"]:
495                                         getInitialCableTransponderList(tlist, nimmanager.getCableDescription(slotid))
496                                 elif nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-T"]:
497                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(slotid))
498                                 scanList.append({"transponders": tlist, "feid": slotid, "flags": eComponentScan.scanNetworkSearch})
499                 self.session.openWithCallback(self.doNothing, ServiceScan, scanList = scanList)
500
501         def doNothing(self):
502                 pass
503         
504         def keyCancel(self):
505                 self.close()
506
507         def keyLeft(self):
508                 self["config"].handleKey(config.key["prevElement"])
509
510         def keyRight(self):
511                 self["config"].handleKey(config.key["nextElement"])
512
513         def Satexists(self, tlist, pos):
514                 for x in tlist:
515                         if x == pos:
516                                 return 1
517                 return 0
518
519         def ScanNimTwoNeeded(self):
520                 if nimmanager.getNimType(0) != nimmanager.getNimType(1):
521                         return True
522                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"]: #two dvb-s nims
523                         if nimmanager.getNimConfigMode(1) in ["loopthrough", "satposdepends", "equal", "nothing"]:
524                                 return False
525                         sec = eDVBSatelliteEquipmentControl.getInstance()
526                         if sec is not None:
527                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
528                                 if len(exclusive_satellites) == 0:
529                                         return False
530                         return True
531
532         def __init__(self, session):
533                 Screen.__init__(self, session)
534
535                 self["actions"] = ActionMap(["SetupActions"],
536                 {
537                         "ok": self.keyGo,
538                         "cancel": self.keyCancel,
539                         "left": self.keyLeft,
540                         "right": self.keyRight,
541                 }, -1)
542
543                 self.list = []
544                 tlist = []
545
546                 nimcount = nimmanager.getNimSocketCount()
547                 if nimcount > 0:
548                         nim = configElement_nonSave(0, configSelection, 0,(("yes", _("yes")),("no", _("no"))))
549                         self.list.append(getConfigListEntry(_("Scan NIM") + " 0 (" + nimmanager.getNimTypeName(0) + ")", nim))
550                 if nimcount > 1 and self.ScanNimTwoNeeded():
551                         nim = configElement_nonSave(1, configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
552                         self.list.append(getConfigListEntry(_("Scan NIM") + " 1 (" + nimmanager.getNimTypeName(1) + ")", nim))
553
554                 self["config"] = ConfigList(self.list)
555                 self["header"] = Label(_("Automatic Scan"))
556                 self["footer"] = Label(_("Press OK to scan"))