4983f768f8bd7c158f3f6665543b6380e79366bc
[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                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
206                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
207                                 # if (norotor)
208                                 tlist = []
209                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
210                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
211                                 for x in SatList:
212                                         if self.Satexists(tlist, x[1]) == 0:
213                                                 tlist.append(x[1])
214                                                 sat = configElement_nonSave(x[1], configSelection, 0, (("enable", _("Enable")), ("disable", _("Disable"))))
215                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[1]), sat)
216                                                 self.list.append(configEntry)
217                                                 self.multiscanlist.append(configEntry)
218                                 # if (rotor):
219                            # for sat in nimmanager.satList:
220                                 #       self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))
221
222
223                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
224                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
225                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.cab.frequency))
226                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.cab.inversion))
227                                 self.list.append(getConfigListEntry(_("Symbol Rate"), config.scan.cab.symbolrate))
228                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.cab.modulation))
229                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.cab.fec))
230                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.cab.networkScan))
231                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
232                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
233                                 
234                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
235                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
236                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.ter.frequency))
237                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.ter.networkScan))
238                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.ter.inversion))
239                                 self.list.append(getConfigListEntry(_("Bandwidth"), config.scan.ter.bandwidth))
240                                 self.list.append(getConfigListEntry(_("Code rate high"), config.scan.ter.fechigh))
241                                 self.list.append(getConfigListEntry(_("Code rate low"), config.scan.ter.feclow))
242                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.ter.modulation))
243                                 self.list.append(getConfigListEntry(_("Transmission mode"), config.scan.ter.transmission))
244                                 self.list.append(getConfigListEntry(_("Guard interval mode"), config.scan.ter.guard))
245                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), config.scan.ter.hierarchy))
246                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
247                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
248
249                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"] and currentConfigSelectionElement(config.scan.type) == "single_transponder") or \
250                         (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"] and currentConfigSelectionElement(config.scan.typecable) == "single_transponder") or \
251                         (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"] and currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder"):
252                                 self.configElementSNR = getConfigListEntry(_("SNR"), config.scan.snr)
253                                 self.list.append(self.configElementSNR)
254                                 self.configElementACG = getConfigListEntry(_("AGC"), config.scan.agc)
255                                 self.list.append(self.configElementACG)
256                                 self.configElementBER = getConfigListEntry(_("BER"), config.scan.ber)
257                                 self.list.append(self.configElementBER)
258                                 self.statusTimer.start(500, False)
259                 else:
260                         self.statusTimer.stop()
261
262                 self["config"].list = self.list
263                 self["config"].l.setList(self.list)
264
265         def Satexists(self, tlist, pos):
266                 for x in tlist:
267                         if x == pos:
268                                 return 1
269                 return 0
270
271         def newConfig(self):
272                 print self["config"].getCurrent()
273                 if self["config"].getCurrent() == self.typeOfScanEntry:
274                         self.createSetup()
275                 if self["config"].getCurrent() == self.tunerEntry:
276                         self.createSetup()
277
278         def createConfig(self):
279                         config.scan = ConfigSubsection()
280                         config.scan.sat = ConfigSubsection()
281                         config.scan.cab = ConfigSubsection()
282                         config.scan.ter = ConfigSubsection()
283
284                         config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, (("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat"))))
285                         config.scan.typecable = configElement_nonSave("config.scan.typecable", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
286                         config.scan.typeterrestrial = configElement_nonSave("config.scan.typeterrestrial", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
287                         config.scan.clearallservices = configElement_nonSave("config.scan.clearallservices", configSelection, 0, (("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (hold feeds)"))))
288
289                         nimList = [ ]
290                         for nim in nimmanager.nimList():
291                                 nimList.append(nim[0])
292                         #nimList.append("all")
293                         config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
294                         
295                         # status
296                         config.scan.snr = configElement_nonSave("config.scan.snr", configSlider, 0, (1, 100))
297                         config.scan.snr.enabled = False
298                         config.scan.agc = configElement_nonSave("config.scan.agc", configSlider, 0, (1, 100))
299                         config.scan.agc.enabled = False
300                         config.scan.ber = configElement_nonSave("config.scan.ber", configSlider, 0, (1, 100))
301                         config.scan.ber.enabled = False
302
303                         # sat
304                         config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, [11836], configsequencearg.get("INTEGER", (1, 99999)))
305                         config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), _("Auto")))
306                         config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, [27500], configsequencearg.get("INTEGER", (1, 99999)))
307                         config.scan.sat.polarization = configElement_nonSave("config.scan.sat.polarization", configSelection, 0, (("horizontal", _("horizontal")), ("vertical", _("vertical")),  ("circular_left", _("circular left")), ("circular_right", _("circular right"))))
308                         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"))))
309
310                         # cable
311                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (50, 999)))
312                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
313                         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")))
314                         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"))))
315                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 9999)))
316                         config.scan.cab.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
317
318                         # terrestial
319                         config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (100, 900)))
320                         config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
321                         # WORKAROUND: we can't use BW-auto
322                         config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 0, (("8MHz", "8MHz"), ("7MHz", "7MHz"), ("6MHz", "6MHz")))
323                         #, ("auto", _("Auto"))))
324                         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")))
325                         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"))))
326                         config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 2, (("qpsk", "QPSK"), ("qam16", "QAM16"), ("auto", _("Auto"))))
327                         config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 2, (("2k", "2K"), ("8k", "8K"), ("auto", _("Auto"))))
328                         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"))))
329                         config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 4, (("none", _("None")), ("1", "1"), ("2", "2"), ("4", "4"), ("auto", _("Auto"))))
330                         config.scan.ter.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
331
332                         config.scan.scansat = {}
333                         for sat in nimmanager.satList:
334                                 #print sat[1]
335                                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
336
337                         config.scan.satselection = []
338                         slotid = 0
339                         for slot in nimmanager.nimslots:
340                                 if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
341                                         print str(slot.slotid) + " : " + str(self.satList)
342                                         config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, 0, self.satList[slot.slotid]))
343                                 else:
344                                         config.scan.satselection.append(None)
345         def keyLeft(self):
346                 self["config"].handleKey(config.key["prevElement"])
347                 self.newConfig()
348
349         def keyRight(self):
350                 self["config"].handleKey(config.key["nextElement"])
351                 self.newConfig()
352
353         def updateStatus(self):
354                 print "updatestatus"
355
356         def keyNumberGlobal(self, number):
357                 print "You pressed number " + str(number)
358                 if (self["config"].getCurrent()[1].parent.enabled == True):
359                         self["config"].handleKey(config.key[str(number)])
360
361         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
362                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
363                 print "orbpos: " + str(orbital_position)
364                 parm = eDVBFrontendParametersSatellite()
365                 parm.frequency = frequency * 1000
366                 parm.symbol_rate = symbol_rate * 1000
367                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti
368                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
369                 #parm.fec = 6                                   # AUTO
370                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
371                 #parm.inversion = 2             #AUTO
372                 parm.orbital_position = int(orbital_position)
373                 tlist.append(parm)
374
375         # FIXME use correct parameters
376         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
377                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
378                 parm = eDVBFrontendParametersCable()
379                 parm.frequency = frequency * 1000
380                 parm.symbol_rate = symbol_rate * 1000
381                 parm.modulation = modulation # modulation # eDVBFrontendParametersSatellite.Polarisation.Verti
382                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
383                 #parm.fec = 6                                   # AUTO
384                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
385                 #parm.inversion = 2             #AUTO
386                 tlist.append(parm)
387
388         def addTerTransponder(self, tlist, *args, **kwargs):
389                 tlist.append(buildTerTransponder(*args, **kwargs))
390
391         def keyGo(self):
392                 tlist = []
393                 flags = 0
394                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
395                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
396                                 l = len(self.satList)
397                                 if l and l > config.scan.nims.value:
398                                         nimsats=self.satList[config.scan.nims.value]
399                                         l = len(config.scan.satselection)
400                                         if l and l > config.scan.nims.value:
401                                                 selsatidx=config.scan.satselection[config.scan.nims.value].value
402                                                 l = len(nimsats)
403                                                 if l and l > selsatidx:
404                                                         orbpos=nimsats[selsatidx][1]
405                                                         self.addSatTransponder(tlist, config.scan.sat.frequency.value[0],
406                                                                                 config.scan.sat.symbolrate.value[0],
407                                                                                 config.scan.sat.polarization.value,
408                                                                                 config.scan.sat.fec.value,
409                                                                                 config.scan.sat.inversion.value,
410                                                                                 orbpos)
411                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
412                                 sat = self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value]
413                                 getInitialTransponderList(tlist, int(sat[1]))
414                                 flags |= eComponentScan.scanNetworkSearch
415                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
416                                 if tmp == "yes":
417                                         flags |= eComponentScan.scanRemoveServices
418                                 elif tmp == "yes_hold_feeds":
419                                         flags |= eComponentScan.scanRemoveServices
420                                         flags |= eComponentScan.scanDontRemoveFeeds
421                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
422                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
423                                 for x in self.multiscanlist:
424                                         if x[1].parent.value == 0:
425                                                 print "   " + str(x[1].parent.configPath)
426                                                 getInitialTransponderList(tlist, x[1].parent.configPath)
427                                 flags |= eComponentScan.scanNetworkSearch
428                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
429                                 if tmp == "yes":
430                                         flags |= eComponentScan.scanRemoveServices
431                                 elif tmp == "yes_hold_feeds":
432                                         flags |= eComponentScan.scanRemoveServices
433                                         flags |= eComponentScan.scanDontRemoveFeeds
434
435                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
436                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
437                                 self.addCabTransponder(tlist, config.scan.cab.frequency.value[0],
438                                                                                           config.scan.cab.symbolrate.value[0],
439                                                                                           config.scan.cab.modulation.value,
440                                                                                           config.scan.cab.fec.value,
441                                                                                           config.scan.cab.inversion.value)
442                                 if currentConfigSelectionElement(config.scan.cab.networkScan) == "yes":
443                                         flags |= eComponentScan.scanNetworkSearch
444                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
445                                 getInitialCableTransponderList(tlist, nimmanager.getCableDescription(config.scan.nims.value))
446                                 flags |= eComponentScan.scanNetworkSearch
447                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
448                                 if tmp == "yes":
449                                         flags |= eComponentScan.scanRemoveServices
450                                 elif tmp == "yes_hold_feeds":
451                                         flags |= eComponentScan.scanRemoveServices
452                                         flags |= eComponentScan.scanDontRemoveFeeds
453
454                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
455                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
456                                 self.addTerTransponder(tlist,
457                                                 config.scan.ter.frequency.value[0] * 1000000,
458                                                 inversion = config.scan.ter.inversion.value,
459                                                 bandwidth = config.scan.ter.bandwidth.value,
460                                                 fechigh = config.scan.ter.fechigh.value,
461                                                 feclow = config.scan.ter.feclow.value,
462                                                 modulation = config.scan.ter.modulation.value,
463                                                 transmission = config.scan.ter.transmission.value,
464                                                 guard = config.scan.ter.guard.value,
465                                                 hierarchy = config.scan.ter.hierarchy.value)
466                                 if currentConfigSelectionElement(config.scan.ter.networkScan) == "yes":
467                                         flags |= eComponentScan.scanNetworkSearch
468                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
469                                 getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(config.scan.nims.value))
470                                 flags |= eComponentScan.scanNetworkSearch
471                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
472                                 if tmp == "yes":
473                                         flags |= eComponentScan.scanRemoveServices
474                                 elif tmp == "yes_hold_feeds":
475                                         flags |= eComponentScan.scanRemoveServices
476                                         flags |= eComponentScan.scanDontRemoveFeeds
477
478                 for x in self["config"].list:
479                         x[1].save()
480
481                 if len(tlist):
482                         feid = config.scan.nims.value
483                         # flags |= eComponentScan.scanSearchBAT
484                         self.session.openWithCallback(self.doNothing, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
485                 else:
486                         self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
487
488         def doNothing(self):
489                 pass
490
491         def keyCancel(self):
492                 for x in self["config"].list:
493                         x[1].cancel()
494                 self.close()
495
496 class ScanSimple(Screen):
497         def run(self):
498                 self.keyGo()
499
500         def keyGo(self):
501                 scanList = []
502                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"] and nimmanager.getNimType(0) == nimmanager.getNimType(1):
503                         sec = eDVBSatelliteEquipmentControl.getInstance()
504                         if sec is not None:
505                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
506                         else:
507                                 exclusive_satellites = [0,0]
508                         print "exclusive satellites", exclusive_satellites
509                         two_sat_tuners = True
510                 else:
511                         two_sat_tuners = False
512
513                 for x in self.list:
514                         slotid = x[1].parent.configPath
515                         print "Scan Tuner", slotid, "-", currentConfigSelectionElement(x[1].parent)
516                         if currentConfigSelectionElement(x[1].parent) == "yes":
517                                 scanPossible = False
518                                 tlist = [ ]
519                                 if nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-S"]:
520                                         if two_sat_tuners:
521                                                 if slotid > 0:
522                                                         idx = exclusive_satellites[0]+1
523                                                 else:
524                                                         idx = 0
525                                                 exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
526                                                 print "exclusive_nim_sats", exclusive_nim_sats
527                                         SatList = nimmanager.getSatListForNim(slotid)
528                                         for sat in SatList:
529                                                 if not two_sat_tuners or (sat[1] in exclusive_nim_sats or slotid == 0):
530                                                         scanPossible = True
531                                                         print sat
532                                                         getInitialTransponderList(tlist, sat[1])
533                                 elif nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-C"]:
534                                         scanPossible = True
535                                         getInitialCableTransponderList(tlist, nimmanager.getCableDescription(slotid))
536                                 elif nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-T"]:
537                                         scanPossible = True
538                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(slotid))
539                                 if scanPossible:
540                                         flags=eComponentScan.scanNetworkSearch
541                                         tmp = currentConfigSelectionElement(config.scan.clearallservices)
542                                         if tmp == "yes":
543                                                 flags |= eComponentScan.scanRemoveServices
544                                         elif tmp == "yes_hold_feeds":
545                                                 flags |= eComponentScan.scanRemoveServices
546                                                 flags |= eComponentScan.scanDontRemoveFeeds
547                                         scanList.append({"transponders": tlist, "feid": slotid, "flags": flags})
548                 if len(scanList):
549                         self.session.openWithCallback(self.doNothing, ServiceScan, scanList = scanList)
550                 else:
551                         self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
552
553         def doNothing(self):
554                 pass
555
556         def keyCancel(self):
557                 self.close()
558
559         def keyLeft(self):
560                 self["config"].handleKey(config.key["prevElement"])
561
562         def keyRight(self):
563                 self["config"].handleKey(config.key["nextElement"])
564
565         def Satexists(self, tlist, pos):
566                 for x in tlist:
567                         if x == pos:
568                                 return 1
569                 return 0
570
571         def ScanNimTwoNeeded(self):
572                 if nimmanager.getNimType(0) != nimmanager.getNimType(1):
573                         return True
574                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"]: #two dvb-s nims
575                         if nimmanager.getNimConfigMode(1) in ["loopthrough", "satposdepends", "equal", "nothing"]:
576                                 return False
577                         sec = eDVBSatelliteEquipmentControl.getInstance()
578                         if sec is not None:
579                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
580                                 if len(exclusive_satellites) == 2:
581                                         return False
582                                 idx = exclusive_satellites[0]+1
583                                 exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
584                                 if len(exclusive_nim_sats):
585                                         return True
586                 return False # two -C or two -T tuners
587
588         def __init__(self, session):
589                 Screen.__init__(self, session)
590
591                 self["actions"] = ActionMap(["SetupActions"],
592                 {
593                         "ok": self.keyGo,
594                         "cancel": self.keyCancel,
595                         "left": self.keyLeft,
596                         "right": self.keyRight,
597                 }, -1)
598
599                 self.list = []
600                 tlist = []
601
602                 nimcount = nimmanager.getNimSocketCount()
603                 if nimcount > 0:
604                         scan_possible=True
605                         config.scan = ConfigSubsection()
606                         config.scan.clearallservices = configElement_nonSave("config.scan.clearallservices", configSelection, 0, (("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (hold feeds)"))))
607                         self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
608                         nim = configElement_nonSave(0, configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
609                         if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"] and not len(nimmanager.getSatListForNim(0)):
610                                 scan_possible=False
611                         if scan_possible:
612                                 self.list.append(getConfigListEntry(_("Scan NIM") + " 0 (" + nimmanager.getNimTypeName(0) + ")", nim))
613                 if nimcount > 1 and self.ScanNimTwoNeeded():
614                         nim = configElement_nonSave(1, configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
615                         self.list.append(getConfigListEntry(_("Scan NIM") + " 1 (" + nimmanager.getNimTypeName(1) + ")", nim))
616
617                 self["config"] = ConfigList(self.list)
618                 self["header"] = Label(_("Automatic Scan"))
619                 self["footer"] = Label(_("Press OK to scan"))