finally fix priorities: ConfigListScreen's action must be -1 to override eListbox...
[vuplus_dvbapp] / lib / python / Screens / ScanSetup.py
1 from Screen import Screen
2 from ServiceScan import *
3 from Components.config import config, ConfigSubsection, ConfigSelection, ConfigYesNo, ConfigInteger, getConfigListEntry, ConfigSlider, ConfigSatlist, ConfigEnableDisable
4 from Components.ActionMap import NumberActionMap
5 from Components.ConfigList import ConfigList, ConfigListScreen
6 from Components.NimManager import nimmanager
7 from Components.Label import Label
8 from Screens.MessageBox import MessageBox
9 from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial, eDVBFrontendParametersCable
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
16 #       print "freq", frequency, "inv", inversion, "bw", bandwidth, "fech", fechigh, "fecl", feclow, "mod", modulation, "tm", transmission, "guard", guard, "hierarchy", hierarchy
17
18         # WARNING: normally, enums are working directly.
19         # Don't copy this (very bad)!! Instead either fix swig (good) or
20         # move this into a central place.
21         Bw8MHz = 0
22         Bw7MHz = 1
23         Bw6MHz = 2
24         #Bw5MHz = 3 #not implemented for e1 compatibilty
25         BwAuto = 3
26         
27         f1_2 = 0
28         f2_3 = 1
29         f3_4 = 2
30         f5_6 = 3
31         f7_8 = 4
32         fAuto = 5
33         
34         TM2k = 0
35         TM8k = 1
36         #TM4k = 2  #not implemented for e1 compatibilty
37         TMAuto = 2
38         
39         GI_1_32 = 0
40         GI_1_16 = 1
41         GI_1_8 = 2
42         GI_1_4 = 3
43         GI_Auto = 4
44         
45         HNone = 0
46         H1 = 1
47         H2 = 2
48         H4 = 3
49         HAuto = 4
50
51         QPSK = 0
52         QAM16 = 1
53         QAM64 = 2
54         Auto = 3
55         
56         Off = 0
57         On = 1
58         Unknown = 2
59
60         parm = eDVBFrontendParametersTerrestrial()
61
62         parm.frequency = frequency
63
64         parm.inversion = [Off, On, Unknown][inversion]
65         parm.bandwidth = [Bw8MHz, Bw7MHz, Bw6MHz, BwAuto][bandwidth] # Bw5MHz unsupported
66         parm.code_rate_HP = [f1_2, f2_3, f3_4, f5_6, f7_8, fAuto][fechigh]
67         parm.code_rate_LP = [f1_2, f2_3, f3_4, f5_6, f7_8, fAuto][feclow]
68         parm.modulation = [QPSK, QAM16, QAM64, Auto][modulation]
69         parm.transmission_mode = [TM2k, TM8k, TMAuto][transmission] # TM4k unsupported
70         parm.guard_interval = [GI_1_32, GI_1_16, GI_1_8, GI_1_4, GI_Auto][guard]
71         parm.hierarchy = [HNone, H1, H2, H4, HAuto][hierarchy]
72         
73         return parm
74
75 def getInitialTransponderList(tlist, pos):
76         list = nimmanager.getTransponders(pos)
77
78         for x in list:
79                 if x[0] == 0:           #SAT
80                         parm = eDVBFrontendParametersSatellite()
81                         parm.frequency = x[1]
82                         parm.symbol_rate = x[2]
83                         parm.polarisation = x[3]
84                         parm.fec = x[4]
85                         parm.inversion = 2 # AUTO
86                         parm.orbital_position = pos
87                         parm.system = x[5]
88                         parm.modulation = x[6]
89                         tlist.append(parm)
90
91 def getInitialCableTransponderList(tlist, cable):
92         list = nimmanager.getTranspondersCable(cable)
93
94         for x in list:
95                 if x[0] == 1: #CABLE
96                         parm = eDVBFrontendParametersCable()
97                         parm.frequency = x[1]
98                         parm.symbol_rate = x[2]
99                         parm.modulation = x[3]
100                         parm.fec_inner = x[4]
101                         parm.inversion = 2 # AUTO
102                         tlist.append(parm)
103
104 def getInitialTerrestrialTransponderList(tlist, region):
105         list = nimmanager.getTranspondersTerrestrial(region)
106
107         #self.transponders[self.parsedTer].append((2,freq,bw,const,crh,crl,guard,transm,hierarchy,inv))
108
109         #def buildTerTransponder(frequency, inversion = 2, bandwidth = 3, fechigh = 6, feclow = 6,
110                                 #modulation = 2, transmission = 2, guard = 4, hierarchy = 4):
111
112         for x in list:
113                 if x[0] == 2: #TERRESTRIAL
114                         parm = buildTerTransponder(x[1], x[9], x[2], x[4], x[5], x[3], x[7], x[6], x[8])
115                         tlist.append(parm)
116
117
118 class ScanSetup(ConfigListScreen, Screen):
119         def __init__(self, session):
120                 Screen.__init__(self, session)
121
122                 self.updateSatList()
123                 self.service = session.nav.getCurrentService()
124                 self.feinfo = None
125                 frontendData = None
126                 if self.service is not None:
127                         self.feinfo = self.service.frontendInfo()
128                         frontendData = self.feinfo and self.feinfo.getFrontendData(True)
129                 self.createConfig(frontendData)
130                 del self.feinfo
131                 del self.service
132
133
134                 self["actions"] = NumberActionMap(["SetupActions"],
135                 {
136                         "ok": self.keyGo,
137                         "cancel": self.keyCancel,
138                 }, -2)
139
140                 self.statusTimer = eTimer()
141                 self.statusTimer.timeout.get().append(self.updateStatus)
142                 #self.statusTimer.start(5000, True)
143
144                 self.list = []
145                 ConfigListScreen.__init__(self, self.list)
146                 self.createSetup()
147
148                 self["introduction"] = Label(_("Press OK to start the scan"))
149
150         def run(self):
151                 self.keyGo()
152
153         def updateSatList(self):
154                 self.satList = []
155                 for slot in nimmanager.nimslots:
156                         if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
157                                 self.satList.append(nimmanager.getSatListForNim(slot.slotid))
158                         else:
159                                 self.satList.append(None)
160                                 
161         def createSetup(self):
162                 self.list = []
163                 self.multiscanlist = []
164                 print "ID: ", self.scan_nims.index
165
166                 self.tunerEntry = getConfigListEntry(_("Tuner"), self.scan_nims)
167                 self.list.append(self.tunerEntry)
168                 
169                 self.typeOfScanEntry = None
170                 self.systemEntry = None
171                 if nimmanager.getNimType(self.scan_nims.index) == nimmanager.nimType["DVB-S"]:
172                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_type)
173                         self.list.append(self.typeOfScanEntry)
174                 elif nimmanager.getNimType(self.scan_nims.index) == nimmanager.nimType["DVB-C"]:
175                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typecable)
176                         self.list.append(self.typeOfScanEntry)
177                 elif nimmanager.getNimType(self.scan_nims.index) == nimmanager.nimType["DVB-T"]:
178                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typeterrestrial)
179                         self.list.append(self.typeOfScanEntry)
180
181                 if nimmanager.getNimType(self.scan_nims.index) == nimmanager.nimType["DVB-S"]:
182
183                         if self.scan_type.value == "single_transponder":
184                                 self.systemEntry = getConfigListEntry(_('Transpondertype'), self.scan_sat.system)
185                                 self.list.append(self.systemEntry)
186                                 self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[self.scan_nims.index]))
187                                 self.list.append(getConfigListEntry(_('Frequency'), self.scan_sat.frequency))
188                                 self.list.append(getConfigListEntry(_('Inversion'), self.scan_sat.inversion))
189                                 self.list.append(getConfigListEntry(_('Symbol Rate'), self.scan_sat.symbolrate))
190                                 self.list.append(getConfigListEntry(_("Polarity"), self.scan_sat.polarization))
191                                 if self.scan_sat.system.value == "dvb-s":
192                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec))
193                                 elif self.scan_sat.system.value == "dvb-s2":
194                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2))
195                                         self.list.append(getConfigListEntry(_('Modulation'), self.scan_sat.modulation))
196                         elif self.scan_type.value == "single_satellite":
197                                 self.updateSatList()
198                                 print self.scan_satselection[self.scan_nims.index]
199                                 self.list.append(getConfigListEntry(_("Satellite"), self.scan_satselection[self.scan_nims.index]))
200                                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
201                         elif self.scan_type.value == "multisat":
202                                 # if (norotor)
203                                 tlist = []
204                                 SatList = nimmanager.getSatListForNim(self.scan_nims.index)
205                                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
206                                 for x in SatList:
207                                         if self.Satexists(tlist, x[0]) == 0:
208                                                 tlist.append(x[0])
209                                                 sat = ConfigEnableDisable(default = True)
210                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[0]), sat)
211                                                 self.list.append(configEntry)
212                                                 self.multiscanlist.append((x[0], sat))
213                                 # if (rotor):
214                            # for sat in nimmanager.satList:
215                                 #       self.list.append(getConfigListEntry(sat[1], self.scan_scansat[sat[0]]))
216
217
218                 if nimmanager.getNimType(self.scan_nims.index) == nimmanager.nimType["DVB-C"]:
219                         if self.scan_typecable.value == "single_transponder":
220                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_cab.frequency))
221                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_cab.inversion))
222                                 self.list.append(getConfigListEntry(_("Symbol Rate"), self.scan_cab.symbolrate))
223                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_cab.modulation))
224                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_cab.fec))
225                                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_cab.networkScan))
226                         elif self.scan_typecable.value == "complete":
227                                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
228                                 
229                 if nimmanager.getNimType(self.scan_nims.index) == nimmanager.nimType["DVB-T"]:
230                         if self.scan_typeterrestrial.value == "single_transponder":
231                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_ter.frequency))
232                                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_ter.networkScan))
233                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_ter.inversion))
234                                 self.list.append(getConfigListEntry(_("Bandwidth"), self.scan_ter.bandwidth))
235                                 self.list.append(getConfigListEntry(_("Code rate high"), self.scan_ter.fechigh))
236                                 self.list.append(getConfigListEntry(_("Code rate low"), self.scan_ter.feclow))
237                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_ter.modulation))
238                                 self.list.append(getConfigListEntry(_("Transmission mode"), self.scan_ter.transmission))
239                                 self.list.append(getConfigListEntry(_("Guard interval mode"), self.scan_ter.guard))
240                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), self.scan_ter.hierarchy))
241                         elif self.scan_typeterrestrial.value == "complete":
242                                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
243
244 #               if (nimmanager.getNimType(self.scan_nims.index) == nimmanager.nimType["DVB-S"] and self.scan_type.type == "single_transponder") or \
245 #                       (nimmanager.getNimType(self.scan_nims.index) == nimmanager.nimType["DVB-C"] and self.scan_typecable.type == "single_transponder") or \
246 #                       (nimmanager.getNimType(self.scan_nims.index) == nimmanager.nimType["DVB-T"] and self.scan_typeterrestrial.type == "single_transponder"):
247 #                               self.configElementSNR = getConfigListEntry(_("SNR"), self.scan_snr)
248 #                               self.list.append(self.configElementSNR)
249 #                               self.configElementACG = getConfigListEntry(_("AGC"), self.scan_agc)
250 #                               self.list.append(self.configElementACG)
251 #                               self.configElementBER = getConfigListEntry(_("BER"), self.scan_ber)
252 #                               self.list.append(self.configElementBER)
253 #                               self.statusTimer.start(500, False)
254 #               else:
255 #                       self.statusTimer.stop()
256
257                 self["config"].list = self.list
258                 self["config"].l.setList(self.list)
259
260         def Satexists(self, tlist, pos):
261                 for x in tlist:
262                         if x == pos:
263                                 return 1
264                 return 0
265
266         def newConfig(self):
267                 print self["config"].getCurrent()
268                 if self["config"].getCurrent() == self.typeOfScanEntry:
269                         self.createSetup()
270                 elif self["config"].getCurrent() == self.tunerEntry:
271                         self.createSetup()
272                 elif self["config"].getCurrent() == self.systemEntry:
273                         self.createSetup()
274
275         def createConfig(self, frontendData):
276                                                            #("Type", frontendData["system"], TYPE_TEXT),
277                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
278                                            #("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
279                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
280                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
281                                            #("Polarization", frontendData["polarization"], TYPE_TEXT),
282                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
283                                            #("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
284                                                 #)
285                 #elif frontendData["tuner_type"] == "DVB-C":
286                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
287                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
288                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
289                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
290                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
291                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
292                         #                  ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
293                                                 #)
294                 #elif frontendData["tuner_type"] == "DVB-T":
295                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
296                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
297                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
298                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
299                                            #("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
300                                            #("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
301                                            #("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
302                                            #("Constellation", frontendData["constellation"], TYPE_TEXT),
303                                            #("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
304                                            #("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
305                                            #("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT),
306                         defaultSat = { "orbpos": 192, "system": "dvb-s", "frequency": 11836, "inversion": "auto", "symbolrate": 27500, "polarization": "horizontal", "fec": "auto", "fec_s2": "9_10", "modulation": "qpsk" }
307                         defaultCab = {"frequency": 466, "inversion": "auto", "modulation": "64qam", "fec": "auto", "symbolrate": 6900}
308                         if frontendData is not None:
309                                 if frontendData["tuner_type"] == "DVB-S":
310                                         defaultSat["system"] = {"DVB-S": "dvb-s", "DVB-S2": "dvb-s2"}[frontendData["system"]]
311                                         defaultSat["frequency"] = int(frontendData["frequency"] / 1000)
312                                         defaultSat["inversion"] = {"INVERSION_OFF": "off", "INVERSION_ON": "on", "INVERSION_AUTO": "auto"}[frontendData["inversion"]]
313                                         defaultSat["symbolrate"] = int(frontendData["symbol_rate"] / 1000)
314                                         defaultSat["polarization"] = {"HORIZONTAL": "horizontal", "VERTICAL": "vertical", "CIRCULAR_LEFT": "circular_left", "CIRCULAR_RIGHT": "circular_right", "UNKNOWN": None}[frontendData["polarization"]]
315                                         defaultSat["fec"] = {"DVB-S": {"FEC_AUTO": "auto", "FEC_1_2": "1_2", "FEC_2_3": "2_3", "FEC_3_4": "3_4", "FEC_5_6": "5_6", "FEC_7_8": "7_8", "FEC_NONE": "none"}, "DVB-S2": {"FEC_1_2": "1_2", "FEC_2_3": "2_3", "FEC_3_4": "3_4", "FEC_4_5": "4_5", "FEC_5_6": "5_6", "FEC_7_8": "7_8", "FEC_8_9": "8_9", "FEC_9_10": "9_10"}}[frontendData["system"]][frontendData["fec_inner"]]
316                                         defaultSat["modulation"] = {"QPSK": "qpsk", "8PSK": "8psk"}[frontendData["modulation"]]
317                                         defaultSat["orbpos"] = frontendData["orbital_position"]
318                                 elif frontendData["tuner_type"] == "DVB-C":
319                                         defaultCab["frequency"] = int(frontendData["frequency"] / 1000)
320                                         defaultCab["symbolrate"] = int(frontendData["symbol_rate"] / 1000)
321                                         defaultSat["inversion"] = {"INVERSION_OFF": "off", "INVERSION_ON": "on", "INVERSION_AUTO": "auto"}[frontendData["inversion"]]
322                                         defaultSat["fec"] = {"FEC_AUTO": "auto", "FEC_1_2": "1_2", "FEC_2_3": "2_3", "FEC_3_4": "3_4", "FEC_5_6": "5_6", "FEC_7_8": "7_8", "FEC_8_9": "8_9", "FEC_NONE": "none"}[frontendData["fec_inner"]]
323                                         defaultSat["modulation"] = {"QAM_AUTO": "auto", "QAM_16": "16qam", "QAM_32": "32qam", "QAM_64": "64qam", "QAM_128": "128qam", "QAM_256": "256qam"}[frontendData["modulation"]]
324
325                         self.scan_sat = ConfigSubsection()
326                         self.scan_cab = ConfigSubsection()
327                         self.scan_ter = ConfigSubsection()
328
329                         self.scan_type = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat"))])
330                         self.scan_typecable = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
331                         self.scan_typeterrestrial = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
332                         self.scan_clearallservices = ConfigSelection(default = "no", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
333
334                         nimList = [ ]
335                         for nim in nimmanager.nimList():
336                                 nimList.append(nim[0])
337                         #nimList.append("all")
338                         self.scan_nims = ConfigSelection(choices = nimList)
339                         
340                         # status
341                         self.scan_snr = ConfigSlider()
342                         self.scan_snr.enabled = False
343                         self.scan_agc = ConfigSlider()
344                         self.scan_agc.enabled = False
345                         self.scan_ber = ConfigSlider()
346                         self.scan_ber.enabled = False
347
348                         # sat
349                         self.scan_sat.system = ConfigSelection(default = defaultSat["system"], choices = [("dvb-s", _("DVB-S")), ("dvb-s2", _("DVB-S2"))])
350                         self.scan_sat.frequency = ConfigInteger(default = defaultSat["frequency"], limits = (1, 99999))
351                         self.scan_sat.inversion = ConfigSelection(default = defaultSat["inversion"], choices = [("off", _("off")), ("on", _("on")), ("auto", _("Auto"))])
352                         self.scan_sat.symbolrate = ConfigInteger(default = defaultSat["symbolrate"], limits = (1, 99999))
353                         self.scan_sat.polarization = ConfigSelection(default = defaultSat["polarization"], choices = [("horizontal", _("horizontal")), ("vertical", _("vertical")),  ("circular_left", _("circular left")), ("circular_right", _("circular right"))])
354                         self.scan_sat.fec = ConfigSelection(default = defaultSat["fec"], choices = [("auto", _("Auto")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("none", _("None"))])
355                         self.scan_sat.fec_s2 = ConfigSelection(default = defaultSat["fec_s2"], choices = [("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")])
356                         self.scan_sat.modulation = ConfigSelection(default = defaultSat["modulation"], choices = [("qpsk", "QPSK"), ("8psk", "8PSK")])
357         
358                         # cable
359                         self.scan_cab.frequency = ConfigInteger(default = defaultCab["frequency"], limits = (50, 999))
360                         self.scan_cab.inversion = ConfigSelection(default = defaultCab["inversion"], choices = [("off", _("off")), ("on", _("on")), ("auto", _("Auto"))])
361                         self.scan_cab.modulation = ConfigSelection(default = defaultCab["modulation"], choices = [("16qam", "16-QAM"), ("32qam", "32-QAM"), ("64qam", "64-QAM"), ("128qam", "128-QAM"), ("256qam", "256-QAM")])
362                         self.scan_cab.fec = ConfigSelection(default = defaultCab["fec"], choices = [("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"))])
363                         self.scan_cab.symbolrate = ConfigInteger(default = defaultCab["symbolrate"], limits = (1, 99999))
364                         self.scan_cab.networkScan = ConfigYesNo(default = False)
365
366                         # terrestial
367                         self.scan_ter.frequency = ConfigInteger(default = 466, limits = (100, 999))
368                         self.scan_ter.inversion = ConfigSelection(default = "auto", choices = [("off", _("off")), ("on", _("on")), ("auto", _("Auto"))])
369                         # WORKAROUND: we can't use BW-auto
370                         self.scan_ter.bandwidth = ConfigSelection(default = "8MHz", choices = [("8MHz", "8MHz"), ("7MHz", "7MHz"), ("6MHz", "6MHz")])
371                         #, ("auto", _("Auto"))))
372                         self.scan_ter.fechigh = ConfigSelection(default = "auto", choices = [("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("auto", _("Auto"))])
373                         self.scan_ter.feclow = ConfigSelection(default = "auto", choices = [("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("auto", _("Auto"))])
374                         self.scan_ter.modulation = ConfigSelection(default = "auto", choices = [("qpsk", "QPSK"), ("qam16", "QAM16"), ("qam64", "QAM64"), ("auto", _("Auto"))])
375                         self.scan_ter.transmission = ConfigSelection(default = "auto", choices = [("2k", "2K"), ("8k", "8K"), ("auto", _("Auto"))])
376                         self.scan_ter.guard = ConfigSelection(default = "auto", choices = [("1_32", "1/32"), ("1_16", "1/16"), ("1_8", "1/8"), ("1_4", "1/4"), ("auto", _("Auto"))])
377                         self.scan_ter.hierarchy = ConfigSelection(default = "auto", choices = [("none", _("None")), ("1", "1"), ("2", "2"), ("4", "4"), ("auto", _("Auto"))])
378                         self.scan_ter.networkScan = ConfigYesNo(default = False)
379
380                         self.scan_scansat = {}
381                         for sat in nimmanager.satList:
382                                 #print sat[1]
383                                 self.scan_scansat[sat[0]] = ConfigYesNo(default = False)
384
385                         self.scan_satselection = []
386                         slotid = 0
387                         for slot in nimmanager.nimslots:
388                                 if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
389                                         print str(slot.slotid) + " : " + str(self.satList)
390                                         self.scan_satselection.append(ConfigSatlist(default = defaultSat["orbpos"], list = self.satList[slot.slotid]))
391                                 else:
392                                         self.scan_satselection.append(None)
393
394         def keyLeft(self):
395                 ConfigListScreen.keyLeft(self)
396                 self.newConfig()
397
398         def keyRight(self):
399                 ConfigListScreen.keyRight(self)
400                 self.newConfig()
401
402         def updateStatus(self):
403                 print "updatestatus"
404
405         fecmap = { "auto": 0,
406                            "1_2": 1,
407                            "2_3": 2,
408                            "3_4": 3,
409                            "5_6": 4,
410                            "7_8": 5,
411                            "8_9": 6,
412                            "3_5": 7,
413                            "4_5": 8,
414                            "9_10": 9,
415                            "none": 15
416                            }
417
418         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position, system, modulation):
419                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(self.fecmap[fec]) + " inversion: " + str(inversion) + " modulation: " + str(modulation) + " system: " + str(system)
420                 print "orbpos: " + str(orbital_position)
421                 parm = eDVBFrontendParametersSatellite()
422                 if modulation == 1:
423                         parm.modulation = 2 # eDVBFrontendParametersSatellite.Modulation.8PSK
424                 else:
425                         parm.modulation = 1 # eDVBFrontendParametersSatellite.Modulation.QPSK
426                 parm.system = system
427                 parm.frequency = frequency * 1000
428                 parm.symbol_rate = symbol_rate * 1000
429                 parm.polarisation = polarisation
430                 parm.fec = self.fecmap[fec]
431                 parm.inversion = inversion
432                 parm.orbital_position = int(orbital_position)
433                 tlist.append(parm)
434
435         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
436                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
437                 parm = eDVBFrontendParametersCable()
438                 parm.frequency = frequency * 1000
439                 parm.symbol_rate = symbol_rate * 1000
440                 parm.modulation = modulation
441                 parm.fec = self.fecmap[fec]
442                 parm.inversion = inversion
443                 tlist.append(parm)
444
445         def addTerTransponder(self, tlist, *args, **kwargs):
446                 tlist.append(buildTerTransponder(*args, **kwargs))
447
448         def keyGo(self):
449                 tlist = []
450                 flags = 0
451                 if nimmanager.getNimType(self.scan_nims.index) == nimmanager.nimType["DVB-S"]:
452                         if self.scan_type.value == "single_transponder":
453                                 l = len(self.satList)
454                                 if l and l > self.scan_nims.index:
455                                         nimsats=self.satList[self.scan_nims.index]
456                                         l = len(self.scan_satselection)
457                                         if l and l > self.scan_nims.index:
458                                                 selsatidx=self.scan_satselection[self.scan_nims.index].index
459                                                 l = len(nimsats)
460                                                 if l and l > selsatidx:
461                                                         orbpos=nimsats[selsatidx][0]
462                                                         if self.scan_sat.system.value == "dvb-s":
463                                                                 fec = self.scan_sat.fec.value
464                                                         else:
465                                                                 fec = self.scan_sat.fec_s2.value
466                                                         self.addSatTransponder(tlist, self.scan_sat.frequency.value,
467                                                                                 self.scan_sat.symbolrate.value,
468                                                                                 self.scan_sat.polarization.index,
469                                                                                 fec,
470                                                                                 self.scan_sat.inversion.index,
471                                                                                 orbpos,
472                                                                                 self.scan_sat.system.index,
473                                                                                 self.scan_sat.modulation.index)
474                         elif self.scan_type.value == "single_satellite":
475                                 sat = self.satList[self.scan_nims.index][self.scan_satselection[self.scan_nims.index].index]
476                                 getInitialTransponderList(tlist, sat[0])
477                                 flags |= eComponentScan.scanNetworkSearch
478                                 tmp = self.scan_clearallservices.value
479                                 if tmp == "yes":
480                                         flags |= eComponentScan.scanRemoveServices
481                                 elif tmp == "yes_hold_feeds":
482                                         flags |= eComponentScan.scanRemoveServices
483                                         flags |= eComponentScan.scanDontRemoveFeeds
484                         elif self.scan_type.value == "multisat":
485                                 SatList = nimmanager.getSatListForNim(self.scan_nims.index)
486                                 for x in self.multiscanlist:
487                                         if x[1].value:
488                                                 print "   " + str(x[0])
489                                                 getInitialTransponderList(tlist, x[0])
490                                 flags |= eComponentScan.scanNetworkSearch
491                                 tmp = self.scan_clearallservices.value
492                                 if tmp == "yes":
493                                         flags |= eComponentScan.scanRemoveServices
494                                 elif tmp == "yes_hold_feeds":
495                                         flags |= eComponentScan.scanRemoveServices
496                                         flags |= eComponentScan.scanDontRemoveFeeds
497
498                 elif (nimmanager.getNimType(self.scan_nims.index) == nimmanager.nimType["DVB-C"]):
499                         if self.scan_typecable.value == "single_transponder":
500                                 fec = self.scan_cab.fec.value
501                                 self.addCabTransponder(tlist, self.scan_cab.frequency.value,
502                                                                                           self.scan_cab.symbolrate.value,
503                                                                                           self.scan_cab.modulation.index + 1,
504                                                                                           fec,
505                                                                                           self.scan_cab.inversion.index)
506                                 if self.scan_cab.networkScan.value:
507                                         flags |= eComponentScan.scanNetworkSearch
508                         elif self.scan_typecable.value == "complete":
509                                 getInitialCableTransponderList(tlist, nimmanager.getCableDescription(self.scan_nims.index))
510                                 flags |= eComponentScan.scanNetworkSearch
511                                 tmp = self.scan_clearallservices
512                                 if tmp == "yes":
513                                         flags |= eComponentScan.scanRemoveServices
514                                 elif tmp == "yes_hold_feeds":
515                                         flags |= eComponentScan.scanRemoveServices
516                                         flags |= eComponentScan.scanDontRemoveFeeds
517
518                 elif (nimmanager.getNimType(self.scan_nims.index) == nimmanager.nimType["DVB-T"]):
519                         if self.scan_typeterrestrial.value == "single_transponder":
520                                 self.addTerTransponder(tlist,
521                                                 self.scan_ter.frequency.value * 1000000,
522                                                 inversion = self.scan_ter.inversion.index,
523                                                 bandwidth = self.scan_ter.bandwidth.index,
524                                                 fechigh = self.scan_ter.fechigh.index,
525                                                 feclow = self.scan_ter.feclow.index,
526                                                 modulation = self.scan_ter.modulation.index,
527                                                 transmission = self.scan_ter.transmission.index,
528                                                 guard = self.scan_ter.guard.index,
529                                                 hierarchy = self.scan_ter.hierarchy.index)
530                                 if self.scan_ter.networkScan.value:
531                                         flags |= eComponentScan.scanNetworkSearch
532                         elif self.scan_typeterrestrial.value == "complete":
533                                 getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(self.scan_nims.index))
534                                 flags |= eComponentScan.scanNetworkSearch
535                                 tmp = self.scan_clearallservices.value
536                                 if tmp == "yes":
537                                         flags |= eComponentScan.scanRemoveServices
538                                 elif tmp == "yes_hold_feeds":
539                                         flags |= eComponentScan.scanRemoveServices
540                                         flags |= eComponentScan.scanDontRemoveFeeds
541
542                 for x in self["config"].list:
543                         x[1].save()
544
545                 if len(tlist):
546                         feid = self.scan_nims.index
547                         # flags |= eComponentScan.scanSearchBAT
548                         self.session.openWithCallback(self.doNothing, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
549                 else:
550                         self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
551
552         def doNothing(self):
553                 pass
554
555         def keyCancel(self):
556                 for x in self["config"].list:
557                         x[1].cancel()
558                 self.close()
559
560 class ScanSimple(ConfigListScreen, Screen):
561         def __init__(self, session):
562                 Screen.__init__(self, session)
563
564                 self["actions"] = ActionMap(["SetupActions"],
565                 {
566                         "ok": self.keyGo,
567                         "cancel": self.keyCancel,
568                 }, -2)
569
570                 self.list = []
571                 tlist = []
572
573                 nimcount = nimmanager.getNimSocketCount()
574                 if nimcount > 0:
575                         nimtype = nimmanager.getNimType(0)
576                         scan_possible=True
577                         self.scan_clearallservices = ConfigSelection(default = "yes", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
578                         self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
579                         nim = ConfigYesNo(default = True)
580                         nim.nim_index = 0
581                         if nimtype == nimmanager.nimType["DVB-S"] and not len(nimmanager.getSatListForNim(0)):
582                                 scan_possible=False
583                         if scan_possible:
584                                 self.list.append(getConfigListEntry(_("Scan NIM") + " 0 (" + nimmanager.getNimTypeName(0) + ")", nim))
585
586                 if nimcount > 1 and self.ScanNimTwoNeeded():
587                         nim = ConfigYesNo(default = True)
588                         nim.nim_index = 1
589                         self.list.append(getConfigListEntry(_("Scan NIM") + " 1 (" + nimmanager.getNimTypeName(1) + ")", nim))
590
591                 ConfigListScreen.__init__(self, self.list)
592                 self["header"] = Label(_("Automatic Scan"))
593                 self["footer"] = Label(_("Press OK to scan"))
594
595         def run(self):
596                 self.keyGo()
597
598         def keyGo(self):
599                 scanList = []
600                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"] and nimmanager.getNimType(0) == nimmanager.getNimType(1):
601                         sec = eDVBSatelliteEquipmentControl.getInstance()
602                         if sec is not None:
603                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
604                         else:
605                                 exclusive_satellites = [0,0]
606                         print "exclusive satellites", exclusive_satellites
607                         two_sat_tuners = True
608                 else:
609                         two_sat_tuners = False
610
611                 for (x, c) in self.list[1:]:
612                         slotid = c.nim_index
613                         print "Scan Tuner", slotid, "-", c.value
614                         if c.value:
615                                 scanPossible = False
616                                 tlist = [ ]
617                                 if nimmanager.getNimType(slotid) == nimmanager.nimType["DVB-S"]:
618                                         print "is sat"
619                                         if two_sat_tuners:
620                                                 if slotid > 0:
621                                                         idx = exclusive_satellites[0]+1
622                                                 else:
623                                                         idx = 0
624                                                 exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
625                                                 print "exclusive_nim_sats", exclusive_nim_sats
626                                         SatList = nimmanager.getSatListForNim(slotid)
627                                         for sat in SatList:
628                                                 if not two_sat_tuners or (sat[0] in exclusive_nim_sats or slotid == 0):
629                                                         scanPossible = True
630                                                         print sat
631                                                         getInitialTransponderList(tlist, sat[0])
632                                 elif nimmanager.getNimType(slotid) == nimmanager.nimType["DVB-C"]:
633                                         scanPossible = True
634                                         getInitialCableTransponderList(tlist, nimmanager.getCableDescription(slotid))
635                                 elif nimmanager.getNimType(slotid) == nimmanager.nimType["DVB-T"]:
636                                         scanPossible = True
637                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(slotid))
638                                 else:
639                                         assert False
640
641                                 if scanPossible:
642                                         flags=eComponentScan.scanNetworkSearch
643                                         tmp = self.scan_clearallservices.value
644                                         if tmp == "yes":
645                                                 flags |= eComponentScan.scanRemoveServices
646                                         elif tmp == "yes_hold_feeds":
647                                                 flags |= eComponentScan.scanRemoveServices
648                                                 flags |= eComponentScan.scanDontRemoveFeeds
649                                         scanList.append({"transponders": tlist, "feid": slotid, "flags": flags})
650                 if len(scanList):
651                         self.session.openWithCallback(self.doNothing, ServiceScan, scanList = scanList)
652                 else:
653                         self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
654
655         def doNothing(self):
656                 pass
657
658         def keyCancel(self):
659                 self.close()
660
661         def Satexists(self, tlist, pos):
662                 for x in tlist:
663                         if x == pos:
664                                 return 1
665                 return 0
666
667         def ScanNimTwoNeeded(self):
668                 if nimmanager.getNimType(0) != nimmanager.getNimType(1):
669                         return True
670                 if nimmanager.getNimType(0) == nimmanager.nimType["DVB-S"]: #two dvb-s nims
671                         if nimmanager.getNimConfigMode(1) in ["loopthrough", "satposdepends", "equal", "nothing"]:
672                                 return False
673                         sec = eDVBSatelliteEquipmentControl.getInstance()
674                         if sec is not None:
675                                 exclusive_satellites = sec.get_exclusive_satellites(0,1)
676                                 if len(exclusive_satellites) == 2:
677                                         return False
678                                 idx = exclusive_satellites[0]+1
679                                 exclusive_nim_sats = exclusive_satellites[idx+1:idx+1+exclusive_satellites[idx]]
680                                 if len(exclusive_nim_sats):
681                                         return True
682                 return False # two -C or two -T tuners
683