add subtitle support, though still disabled in dvb service
[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                         parm.system = x[5]  #DVB-S or DVB-S2
87                         parm.modulation = x[6]
88                         tlist.append(parm)
89
90 def getInitialCableTransponderList(tlist, cable):
91         list = nimmanager.getTranspondersCable(cable)
92
93         for x in list:
94                 if x[0] == 1:           #CABLE
95                         parm = eDVBFrontendParametersCable()
96                         parm.frequency = x[1]
97                         parm.symbol_rate = x[2]
98                         parm.modulation = x[3] # AUTO
99                         parm.fec_inner = x[4] # AUTO
100                         parm.inversion = 2 # AUTO
101                         tlist.append(parm)
102
103 def getInitialTerrestrialTransponderList(tlist, region):
104         list = nimmanager.getTranspondersTerrestrial(region)
105         
106
107 #               inversion=2, bandwidth = 3, fechigh = 6, feclow = 6,
108 #               modulation = 2, transmission = 2, guard = 4,
109 #               hierarchy = 4):
110
111         for x in list:
112 #self.transponders[self.parsedTer].append((2, freq, bw, const, crh, crl, guard, transm, hierarchy, inv))
113                 if x[0] == 2:           #TERRESTRIAL
114                         # FIXME: we need to convert the other parameters...
115                         
116                                 # convert terrestrial.xml bandwidth to our enum
117                         #if x[2] in [0, 1]:
118                         #       bandwidth = [1, 0][x[2]]
119                         #else:
120                         #       bandwidth = 3 # auto
121                         #
122                         #parm = buildTerTransponder(x[1], bandwidth = [1, 0][x[2]])
123                         parm = buildTerTransponder(x[1], inversion = x[9], bandwidth = x[2])
124                         tlist.append(parm)
125
126
127 class ScanSetup(Screen):
128         def __init__(self, session):
129                 Screen.__init__(self, session)
130
131                 self.updateSatList()
132                 self.createConfig()
133
134
135                 self["actions"] = NumberActionMap(["SetupActions"],
136                 {
137                         "ok": self.keyGo,
138                         "cancel": self.keyCancel,
139                         "left": self.keyLeft,
140                         "right": self.keyRight,
141                         "1": self.keyNumberGlobal,
142                         "2": self.keyNumberGlobal,
143                         "3": self.keyNumberGlobal,
144                         "4": self.keyNumberGlobal,
145                         "5": self.keyNumberGlobal,
146                         "6": self.keyNumberGlobal,
147                         "7": self.keyNumberGlobal,
148                         "8": self.keyNumberGlobal,
149                         "9": self.keyNumberGlobal,
150                         "0": self.keyNumberGlobal
151                 }, -1)
152                 
153                 self.statusTimer = eTimer()
154                 self.statusTimer.timeout.get().append(self.updateStatus)
155                 #self.statusTimer.start(5000, True)
156
157                 self.list = []
158                 self["config"] = ConfigList(self.list)
159                 self.createSetup()
160
161                 self["introduction"] = Label(_("Press OK to start the scan"))
162
163         def run(self):
164                 self.keyGo()
165
166         def updateSatList(self):
167                 self.satList = []
168                 for slot in nimmanager.nimslots:
169                         if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
170                                 self.satList.append(nimmanager.getSatListForNim(slot.slotid))
171                         else:
172                                 self.satList.append(None)
173                                 
174         def createSetup(self):
175                 self.list = []
176                 self.multiscanlist = []
177                 print "ID: " + str(config.scan.nims.value)
178
179                 self.tunerEntry = getConfigListEntry(_("Tuner"), config.scan.nims)
180                 self.list.append(self.tunerEntry)
181                 
182                 self.typeOfScanEntry = None
183                 self.systemEntry = None
184                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
185                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.type)
186                         self.list.append(self.typeOfScanEntry)
187                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
188                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typecable)
189                         self.list.append(self.typeOfScanEntry)
190                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
191                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typeterrestrial)
192                         self.list.append(self.typeOfScanEntry)
193
194
195                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
196
197                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
198                                 self.systemEntry = getConfigListEntry(_('Transpondertype'), config.scan.sat.system)
199                                 self.list.append(self.systemEntry)
200                                 self.list.append(getConfigListEntry(_('Satellite'), config.scan.satselection[config.scan.nims.value]))
201                                 self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
202                                 self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
203                                 self.list.append(getConfigListEntry(_('Symbol Rate'), config.scan.sat.symbolrate))
204                                 self.list.append(getConfigListEntry(_("Polarity"), config.scan.sat.polarization))
205                                 if currentConfigSelectionElement(config.scan.sat.system) == "dvb-s":
206                                         self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec))
207                                 elif currentConfigSelectionElement(config.scan.sat.system) == "dvb-s2":
208                                         self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec_s2))
209                                         self.list.append(getConfigListEntry(_('Modulation'), config.scan.sat.modulation))
210                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
211                                 self.updateSatList()
212                                 print config.scan.satselection[config.scan.nims.value]
213                                 self.list.append(getConfigListEntry(_("Satellite"), config.scan.satselection[config.scan.nims.value]))
214                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
215                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
216                                 # if (norotor)
217                                 tlist = []
218                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
219                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
220                                 for x in SatList:
221                                         if self.Satexists(tlist, x[1]) == 0:
222                                                 tlist.append(x[1])
223                                                 sat = configElement_nonSave(x[1], configSelection, 0, (("enable", _("Enable")), ("disable", _("Disable"))))
224                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[1]), sat)
225                                                 self.list.append(configEntry)
226                                                 self.multiscanlist.append(configEntry)
227                                 # if (rotor):
228                            # for sat in nimmanager.satList:
229                                 #       self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))
230
231
232                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
233                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
234                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.cab.frequency))
235                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.cab.inversion))
236                                 self.list.append(getConfigListEntry(_("Symbol Rate"), config.scan.cab.symbolrate))
237                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.cab.modulation))
238                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.cab.fec))
239                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.cab.networkScan))
240                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
241                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
242                                 
243                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
244                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
245                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.ter.frequency))
246                                 self.list.append(getConfigListEntry(_("Network scan"), config.scan.ter.networkScan))
247                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.ter.inversion))
248                                 self.list.append(getConfigListEntry(_("Bandwidth"), config.scan.ter.bandwidth))
249                                 self.list.append(getConfigListEntry(_("Code rate high"), config.scan.ter.fechigh))
250                                 self.list.append(getConfigListEntry(_("Code rate low"), config.scan.ter.feclow))
251                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.ter.modulation))
252                                 self.list.append(getConfigListEntry(_("Transmission mode"), config.scan.ter.transmission))
253                                 self.list.append(getConfigListEntry(_("Guard interval mode"), config.scan.ter.guard))
254                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), config.scan.ter.hierarchy))
255                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
256                                 self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
257
258 #               if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"] and currentConfigSelectionElement(config.scan.type) == "single_transponder") or \
259 #                       (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"] and currentConfigSelectionElement(config.scan.typecable) == "single_transponder") or \
260 #                       (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"] and currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder"):
261 #                               self.configElementSNR = getConfigListEntry(_("SNR"), config.scan.snr)
262 #                               self.list.append(self.configElementSNR)
263 #                               self.configElementACG = getConfigListEntry(_("AGC"), config.scan.agc)
264 #                               self.list.append(self.configElementACG)
265 #                               self.configElementBER = getConfigListEntry(_("BER"), config.scan.ber)
266 #                               self.list.append(self.configElementBER)
267 #                               self.statusTimer.start(500, False)
268 #               else:
269 #                       self.statusTimer.stop()
270
271                 self["config"].list = self.list
272                 self["config"].l.setList(self.list)
273
274         def Satexists(self, tlist, pos):
275                 for x in tlist:
276                         if x == pos:
277                                 return 1
278                 return 0
279
280         def newConfig(self):
281                 print self["config"].getCurrent()
282                 if self["config"].getCurrent() == self.typeOfScanEntry:
283                         self.createSetup()
284                 elif self["config"].getCurrent() == self.tunerEntry:
285                         self.createSetup()
286                 elif self["config"].getCurrent() == self.systemEntry:
287                         self.createSetup()
288
289         def createConfig(self):
290                         config.scan = ConfigSubsection()
291                         config.scan.sat = ConfigSubsection()
292                         config.scan.cab = ConfigSubsection()
293                         config.scan.ter = ConfigSubsection()
294
295                         config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, (("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat"))))
296                         config.scan.typecable = configElement_nonSave("config.scan.typecable", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
297                         config.scan.typeterrestrial = configElement_nonSave("config.scan.typeterrestrial", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
298                         config.scan.clearallservices = configElement_nonSave("config.scan.clearallservices", configSelection, 0, (("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (hold feeds)"))))
299
300                         nimList = [ ]
301                         for nim in nimmanager.nimList():
302                                 nimList.append(nim[0])
303                         #nimList.append("all")
304                         config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
305                         
306                         # status
307                         config.scan.snr = configElement_nonSave("config.scan.snr", configSlider, 0, (1, 100))
308                         config.scan.snr.enabled = False
309                         config.scan.agc = configElement_nonSave("config.scan.agc", configSlider, 0, (1, 100))
310                         config.scan.agc.enabled = False
311                         config.scan.ber = configElement_nonSave("config.scan.ber", configSlider, 0, (1, 100))
312                         config.scan.ber.enabled = False
313
314                         # sat
315                         config.scan.sat.system = configElement_nonSave("config.scan.sat.system", configSelection, 0, (("dvb-s", _("DVB-S")), ("dvb-s2", _("DVB-S2"))))
316                         config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, [11836], configsequencearg.get("INTEGER", (1, 99999)))
317                         config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), _("Auto")))
318                         config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, [27500], configsequencearg.get("INTEGER", (1, 99999)))
319                         config.scan.sat.polarization = configElement_nonSave("config.scan.sat.polarization", configSelection, 0, (("horizontal", _("horizontal")), ("vertical", _("vertical")),  ("circular_left", _("circular left")), ("circular_right", _("circular right"))))
320                         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"))))
321                         config.scan.sat.fec_s2 = configElement_nonSave("config.scan.sat.fec_s2", configSelection, 8, (("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("3_5", "3/5"), ("4_5", "4/5"), ("5_6", "5/6"), ("7_8", "7/8"), ("8_9", "8/9"), ("9_10", "9/10")))
322                         config.scan.sat.modulation = configElement_nonSave("config.scan.sat.modulation", configSelection, 0, (("qpsk", "QPSK"), ("8psk", "8PSK")))
323         
324                         # cable
325                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (50, 999)))
326                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
327                         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")))
328                         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"))))
329                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 9999)))
330                         config.scan.cab.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
331
332                         # terrestial
333                         config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (100, 900)))
334                         config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
335                         # WORKAROUND: we can't use BW-auto
336                         config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 0, (("8MHz", "8MHz"), ("7MHz", "7MHz"), ("6MHz", "6MHz")))
337                         #, ("auto", _("Auto"))))
338                         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")))
339                         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"))))
340                         config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 2, (("qpsk", "QPSK"), ("qam16", "QAM16"), ("auto", _("Auto"))))
341                         config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 2, (("2k", "2K"), ("8k", "8K"), ("auto", _("Auto"))))
342                         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"))))
343                         config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 4, (("none", _("None")), ("1", "1"), ("2", "2"), ("4", "4"), ("auto", _("Auto"))))
344                         config.scan.ter.networkScan = configElement_nonSave("config.scan.cab.networkScan", configSelection, 0, (("no", _("no")), ("yes", _("yes"))))
345
346                         config.scan.scansat = {}
347                         for sat in nimmanager.satList:
348                                 #print sat[1]
349                                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
350
351                         config.scan.satselection = []
352                         slotid = 0
353                         for slot in nimmanager.nimslots:
354                                 if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
355                                         print str(slot.slotid) + " : " + str(self.satList)
356                                         config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, 0, self.satList[slot.slotid]))
357                                 else:
358                                         config.scan.satselection.append(None)
359         def keyLeft(self):
360                 self["config"].handleKey(config.key["prevElement"])
361                 self.newConfig()
362
363         def keyRight(self):
364                 self["config"].handleKey(config.key["nextElement"])
365                 self.newConfig()
366
367         def updateStatus(self):
368                 print "updatestatus"
369
370         def keyNumberGlobal(self, number):
371                 print "You pressed number " + str(number)
372                 if (self["config"].getCurrent()[1].parent.enabled == True):
373                         self["config"].handleKey(config.key[str(number)])
374
375         fecmap = { "auto": 0,
376                            "1_2": 1,
377                            "2_3": 2,
378                            "3_4": 3,
379                            "5_6": 4,
380                            "7_8": 5,
381                            "8_9": 6,
382                            "3_5": 7,
383                            "4_5": 8,
384                            "9_10": 9,
385                            "none": 15
386                            }
387
388         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position, system, modulation):
389                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
390                 print "orbpos: " + str(orbital_position)
391                 parm = eDVBFrontendParametersSatellite()
392                 if modulation == 1:
393                         parm.modulation = 2 # eDVBFrontendParametersSatellite.Modulation.8PSK
394                 else:
395                         parm.modulation = 1 # eDVBFrontendParametersSatellite.Modulation.QPSK
396                 parm.system = system
397                 parm.frequency = frequency * 1000
398                 parm.symbol_rate = symbol_rate * 1000
399                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti
400                 parm.fec = self.fecmap[fec]                     # eDVBFrontendParametersSatellite.FEC.f3_4;
401                 #parm.fec = 6                                   # AUTO
402                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
403                 #parm.inversion = 2             #AUTO
404                 parm.orbital_position = int(orbital_position)
405                 tlist.append(parm)
406
407         # FIXME use correct parameters
408         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
409                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
410                 parm = eDVBFrontendParametersCable()
411                 parm.frequency = frequency * 1000
412                 parm.symbol_rate = symbol_rate * 1000
413                 parm.modulation = modulation # modulation # eDVBFrontendParametersSatellite.Polarisation.Verti
414                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
415                 #parm.fec = 6                                   # AUTO
416                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
417                 #parm.inversion = 2             #AUTO
418                 tlist.append(parm)
419
420         def addTerTransponder(self, tlist, *args, **kwargs):
421                 tlist.append(buildTerTransponder(*args, **kwargs))
422
423         def keyGo(self):
424                 tlist = []
425                 flags = 0
426                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
427                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
428                                 l = len(self.satList)
429                                 if l and l > config.scan.nims.value:
430                                         nimsats=self.satList[config.scan.nims.value]
431                                         l = len(config.scan.satselection)
432                                         if l and l > config.scan.nims.value:
433                                                 selsatidx=config.scan.satselection[config.scan.nims.value].value
434                                                 l = len(nimsats)
435                                                 if l and l > selsatidx:
436                                                         orbpos=nimsats[selsatidx][1]
437                                                         if currentConfigSelectionElement(config.scan.sat.system) == "dvb-s":
438                                                                 fec = currentConfigSelectionElement(config.scan.sat.fec)
439                                                         else:
440                                                                 fec = currentConfigSelectionElement(config.scan.sat.fec_s2)
441                                                         self.addSatTransponder(tlist, config.scan.sat.frequency.value[0],
442                                                                                 config.scan.sat.symbolrate.value[0],
443                                                                                 config.scan.sat.polarization.value,
444                                                                                 fec,
445                                                                                 config.scan.sat.inversion.value,
446                                                                                 orbpos,
447                                                                                 config.scan.sat.system.value,
448                                                                                 config.scan.sat.modulation)
449                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
450                                 sat = self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value]
451                                 getInitialTransponderList(tlist, int(sat[1]))
452                                 flags |= eComponentScan.scanNetworkSearch
453                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
454                                 if tmp == "yes":
455                                         flags |= eComponentScan.scanRemoveServices
456                                 elif tmp == "yes_hold_feeds":
457                                         flags |= eComponentScan.scanRemoveServices
458                                         flags |= eComponentScan.scanDontRemoveFeeds
459                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
460                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
461                                 for x in self.multiscanlist:
462                                         if x[1].parent.value == 0:
463                                                 print "   " + str(x[1].parent.configPath)
464                                                 getInitialTransponderList(tlist, x[1].parent.configPath)
465                                 flags |= eComponentScan.scanNetworkSearch
466                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
467                                 if tmp == "yes":
468                                         flags |= eComponentScan.scanRemoveServices
469                                 elif tmp == "yes_hold_feeds":
470                                         flags |= eComponentScan.scanRemoveServices
471                                         flags |= eComponentScan.scanDontRemoveFeeds
472
473                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
474                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
475                                 self.addCabTransponder(tlist, config.scan.cab.frequency.value[0],
476                                                                                           config.scan.cab.symbolrate.value[0],
477                                                                                           config.scan.cab.modulation.value,
478                                                                                           config.scan.cab.fec.value,
479                                                                                           config.scan.cab.inversion.value)
480                                 if currentConfigSelectionElement(config.scan.cab.networkScan) == "yes":
481                                         flags |= eComponentScan.scanNetworkSearch
482                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
483                                 getInitialCableTransponderList(tlist, nimmanager.getCableDescription(config.scan.nims.value))
484                                 flags |= eComponentScan.scanNetworkSearch
485                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
486                                 if tmp == "yes":
487                                         flags |= eComponentScan.scanRemoveServices
488                                 elif tmp == "yes_hold_feeds":
489                                         flags |= eComponentScan.scanRemoveServices
490                                         flags |= eComponentScan.scanDontRemoveFeeds
491
492                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
493                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
494                                 self.addTerTransponder(tlist,
495                                                 config.scan.ter.frequency.value[0] * 1000000,
496                                                 inversion = config.scan.ter.inversion.value,
497                                                 bandwidth = config.scan.ter.bandwidth.value,
498                                                 fechigh = config.scan.ter.fechigh.value,
499                                                 feclow = config.scan.ter.feclow.value,
500                                                 modulation = config.scan.ter.modulation.value,
501                                                 transmission = config.scan.ter.transmission.value,
502                                                 guard = config.scan.ter.guard.value,
503                                                 hierarchy = config.scan.ter.hierarchy.value)
504                                 if currentConfigSelectionElement(config.scan.ter.networkScan) == "yes":
505                                         flags |= eComponentScan.scanNetworkSearch
506                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
507                                 getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(config.scan.nims.value))
508                                 flags |= eComponentScan.scanNetworkSearch
509                                 tmp = currentConfigSelectionElement(config.scan.clearallservices)
510                                 if tmp == "yes":
511                                         flags |= eComponentScan.scanRemoveServices
512                                 elif tmp == "yes_hold_feeds":
513                                         flags |= eComponentScan.scanRemoveServices
514                                         flags |= eComponentScan.scanDontRemoveFeeds
515
516                 for x in self["config"].list:
517                         x[1].save()
518
519                 if len(tlist):
520                         feid = config.scan.nims.value
521                         # flags |= eComponentScan.scanSearchBAT
522                         self.session.openWithCallback(self.doNothing, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
523                 else:
524                         self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
525
526         def doNothing(self):
527                 pass
528
529         def keyCancel(self):
530                 for x in self["config"].list:
531                         x[1].cancel()
532                 self.close()
533
534 class ScanSimple(Screen):
535         def run(self):
536                 self.keyGo()
537
538         def keyGo(self):
539                 scanList = []
540                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"] and nimmanager.getNimType(0) == nimmanager.getNimType(1):
541                         sec = eDVBSatelliteEquipmentControl.getInstance()
542                         if sec is not None:
543                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
544                         else:
545                                 exclusive_satellites = [0,0]
546                         print "exclusive satellites", exclusive_satellites
547                         two_sat_tuners = True
548                 else:
549                         two_sat_tuners = False
550
551                 for x in self.list:
552                         slotid = x[1].parent.configPath
553                         print "Scan Tuner", slotid, "-", currentConfigSelectionElement(x[1].parent)
554                         if currentConfigSelectionElement(x[1].parent) == "yes":
555                                 scanPossible = False
556                                 tlist = [ ]
557                                 if nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-S"]:
558                                         if two_sat_tuners:
559                                                 if slotid > 0:
560                                                         idx = exclusive_satellites[0]+1
561                                                 else:
562                                                         idx = 0
563                                                 exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
564                                                 print "exclusive_nim_sats", exclusive_nim_sats
565                                         SatList = nimmanager.getSatListForNim(slotid)
566                                         for sat in SatList:
567                                                 if not two_sat_tuners or (sat[1] in exclusive_nim_sats or slotid == 0):
568                                                         scanPossible = True
569                                                         print sat
570                                                         getInitialTransponderList(tlist, sat[1])
571                                 elif nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-C"]:
572                                         scanPossible = True
573                                         getInitialCableTransponderList(tlist, nimmanager.getCableDescription(slotid))
574                                 elif nimmanager.getNimType(x[1].parent.configPath) == nimmanager.nimType["DVB-T"]:
575                                         scanPossible = True
576                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(slotid))
577                                 if scanPossible:
578                                         flags=eComponentScan.scanNetworkSearch
579                                         tmp = currentConfigSelectionElement(config.scan.clearallservices)
580                                         if tmp == "yes":
581                                                 flags |= eComponentScan.scanRemoveServices
582                                         elif tmp == "yes_hold_feeds":
583                                                 flags |= eComponentScan.scanRemoveServices
584                                                 flags |= eComponentScan.scanDontRemoveFeeds
585                                         scanList.append({"transponders": tlist, "feid": slotid, "flags": flags})
586                 if len(scanList):
587                         self.session.openWithCallback(self.doNothing, ServiceScan, scanList = scanList)
588                 else:
589                         self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
590
591         def doNothing(self):
592                 pass
593
594         def keyCancel(self):
595                 self.close()
596
597         def keyLeft(self):
598                 self["config"].handleKey(config.key["prevElement"])
599
600         def keyRight(self):
601                 self["config"].handleKey(config.key["nextElement"])
602
603         def Satexists(self, tlist, pos):
604                 for x in tlist:
605                         if x == pos:
606                                 return 1
607                 return 0
608
609         def ScanNimTwoNeeded(self):
610                 if nimmanager.getNimType(0) != nimmanager.getNimType(1):
611                         return True
612                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"]: #two dvb-s nims
613                         if nimmanager.getNimConfigMode(1) in ["loopthrough", "satposdepends", "equal", "nothing"]:
614                                 return False
615                         sec = eDVBSatelliteEquipmentControl.getInstance()
616                         if sec is not None:
617                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
618                                 if len(exclusive_satellites) == 2:
619                                         return False
620                                 idx = exclusive_satellites[0]+1
621                                 exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
622                                 if len(exclusive_nim_sats):
623                                         return True
624                 return False # two -C or two -T tuners
625
626         def __init__(self, session):
627                 Screen.__init__(self, session)
628
629                 self["actions"] = ActionMap(["SetupActions"],
630                 {
631                         "ok": self.keyGo,
632                         "cancel": self.keyCancel,
633                         "left": self.keyLeft,
634                         "right": self.keyRight,
635                 }, -1)
636
637                 self.list = []
638                 tlist = []
639
640                 nimcount = nimmanager.getNimSocketCount()
641                 if nimcount > 0:
642                         scan_possible=True
643                         config.scan = ConfigSubsection()
644                         config.scan.clearallservices = configElement_nonSave("config.scan.clearallservices", configSelection, 0, (("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (hold feeds)"))))
645                         self.list.append(getConfigListEntry(_("Clear before scan"), config.scan.clearallservices))
646                         nim = configElement_nonSave(0, configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
647                         if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"] and not len(nimmanager.getSatListForNim(0)):
648                                 scan_possible=False
649                         if scan_possible:
650                                 self.list.append(getConfigListEntry(_("Scan NIM") + " 0 (" + nimmanager.getNimTypeName(0) + ")", nim))
651                 if nimcount > 1 and self.ScanNimTwoNeeded():
652                         nim = configElement_nonSave(1, configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
653                         self.list.append(getConfigListEntry(_("Scan NIM") + " 1 (" + nimmanager.getNimTypeName(1) + ")", nim))
654
655                 self["config"] = ConfigList(self.list)
656                 self["header"] = Label(_("Automatic Scan"))
657                 self["footer"] = Label(_("Press OK to scan"))