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