cleanup the configElements in ScanSetup
[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.config import config
7 from Components.config import getConfigListEntry
8 from Components.NimManager import nimmanager
9 from Components.Label import Label
10 from enigma import eDVBFrontendParametersSatellite, eComponentScan
11
12 def getInitialTransponderList(tlist, pos):
13         print "pos", pos
14         list = nimmanager.getTransponders(pos)
15
16         for x in list:
17                 if x[0] == 0:           #SAT
18                         parm = eDVBFrontendParametersSatellite()
19                         parm.frequency = x[1]
20                         parm.symbol_rate = x[2]
21                         parm.polarisation = x[3] # eDVBFrontendParametersSatellite.Polarisation.Vertical
22                         parm.fec = x[4]                 # eDVBFrontendParametersSatellite.FEC.f3_4;
23                         #parm.fec = 6                                   # AUTO
24                         #parm.inversion = 1     #eDVBFrontendParametersSatellite.Inversion.Off;
25                         parm.inversion = 2              #AUTO
26                         parm.orbital_position = pos
27                         tlist.append(parm)
28
29 class ScanSetup(Screen):
30         def __init__(self, session):
31                 Screen.__init__(self, session)
32
33                 self.updateSatList()
34                 self.createConfig()
35
36
37                 self["actions"] = NumberActionMap(["SetupActions"],
38                 {
39                         "ok": self.keyGo,
40                         "cancel": self.keyCancel,
41                         "left": self.keyLeft,
42                         "right": self.keyRight,
43                         "1": self.keyNumberGlobal,
44                         "2": self.keyNumberGlobal,
45                         "3": self.keyNumberGlobal,
46                         "4": self.keyNumberGlobal,
47                         "5": self.keyNumberGlobal,
48                         "6": self.keyNumberGlobal,
49                         "7": self.keyNumberGlobal,
50                         "8": self.keyNumberGlobal,
51                         "9": self.keyNumberGlobal,
52                         "0": self.keyNumberGlobal
53                 }, -1)
54
55                 self.list = []
56                 self["config"] = ConfigList(self.list)
57                 self.createSetup()
58
59                 self["introduction"] = Label(_("Press OK to start the scan"))
60
61         def updateSatList(self):
62                 self.satList = []
63                 for slot in nimmanager.nimslots:
64                         if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
65                                 self.satList.append(nimmanager.getSatListForNim(slot.slotid))
66                         else:
67                                 self.satList.append(None)
68                                 
69         def createSetup(self):
70                 self.list = []
71                 self.multiscanlist = []
72                 print "ID: " + str(config.scan.nims.value)
73
74                 self.tunerEntry = getConfigListEntry(_("Tuner"), config.scan.nims)
75                 self.list.append(self.tunerEntry)
76                 
77                 self.typeOfScanEntry = None
78                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
79                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.type)
80                         self.list.append(self.typeOfScanEntry)
81                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
82                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typecable)
83                         self.list.append(self.typeOfScanEntry)
84                 elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
85                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), config.scan.typeterrestrial)
86                         self.list.append(self.typeOfScanEntry)
87
88
89                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
90
91                         if currentConfigSelectionElement(config.scan.type) == "single_transponder":
92                                 self.list.append(getConfigListEntry(_('Satellite'), config.scan.satselection[config.scan.nims.value]))
93                                 self.list.append(getConfigListEntry(_('Frequency'), config.scan.sat.frequency))
94                                 self.list.append(getConfigListEntry(_('Inversion'), config.scan.sat.inversion))
95                                 self.list.append(getConfigListEntry(_('Symbol Rate'), config.scan.sat.symbolrate))
96                                 self.list.append(getConfigListEntry(_("Polarity"), config.scan.sat.polarization))
97                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.sat.fec))
98                         elif currentConfigSelectionElement(config.scan.type) == "single_satellite":
99                                 self.updateSatList()
100                                 print config.scan.satselection[config.scan.nims.value]
101                                 self.list.append(getConfigListEntry(_("Satellite"), config.scan.satselection[config.scan.nims.value]))
102                         elif currentConfigSelectionElement(config.scan.type) == "multisat":
103                                 # if (norotor)
104                                 tlist = []
105                                 SatList = nimmanager.getSatListForNim(config.scan.nims.value)
106         
107                                 for x in SatList:
108                                         if self.Satexists(tlist, x[1]) == 0:
109                                                 tlist.append(x[1])
110                                                 sat = configElement_nonSave(x[1], configSelection, 0, (("enable", _("Enable")), ("disable", _("Disable"))))
111                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[1]), sat)
112                                                 self.list.append(configEntry)
113                                                 self.multiscanlist.append(configEntry)
114                                 # if (rotor):
115                            # for sat in nimmanager.satList:
116                                 #       self.list.append(getConfigListEntry(sat[0], config.scan.scansat[sat[1]]))
117
118
119                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
120                         if currentConfigSelectionElement(config.scan.typecable) == "single_transponder":
121                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.cab.frequency))
122                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.cab.inversion))
123                                 self.list.append(getConfigListEntry(_("Symbol Rate"), config.scan.cab.symbolrate))
124                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.cab.modulation))
125                                 self.list.append(getConfigListEntry(_("FEC"), config.scan.cab.fec))
126                         elif currentConfigSelectionElement(config.scan.typecable) == "complete":
127                                 pass
128                                 
129                 if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
130                         if currentConfigSelectionElement(config.scan.typeterrestrial) == "single_transponder":
131                                 self.list.append(getConfigListEntry(_("Frequency"), config.scan.ter.frequency))
132                                 self.list.append(getConfigListEntry(_("Inversion"), config.scan.ter.inversion))
133                                 self.list.append(getConfigListEntry(_("Bandwidth"), config.scan.ter.bandwidth))
134                                 self.list.append(getConfigListEntry(_("Code rate high"), config.scan.ter.fechigh))
135                                 self.list.append(getConfigListEntry(_("Code rate low"), config.scan.ter.feclow))
136                                 self.list.append(getConfigListEntry(_("Modulation"), config.scan.ter.modulation))
137                                 self.list.append(getConfigListEntry(_("Transmission mode"), config.scan.ter.transmission))
138                                 self.list.append(getConfigListEntry(_("Guard interval mode"), config.scan.ter.guard))
139                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), config.scan.ter.hierarchy))
140                         elif currentConfigSelectionElement(config.scan.typeterrestrial) == "complete":
141                                 pass
142
143                 self["config"].list = self.list
144                 self["config"].l.setList(self.list)
145
146         def Satexists(self, tlist, pos):
147                 for x in tlist:
148                         if x == pos:
149                                 return 1
150                 return 0
151
152         def newConfig(self):
153                 print self["config"].getCurrent()
154                 if self["config"].getCurrent() == self.typeOfScanEntry:
155                         self.createSetup()
156                 if self["config"].getCurrent() == self.tunerEntry:
157                         self.createSetup()
158
159         def createConfig(self):
160                         config.scan = ConfigSubsection()
161                         config.scan.sat = ConfigSubsection()
162                         config.scan.cab = ConfigSubsection()
163                         config.scan.ter = ConfigSubsection()
164
165                         config.scan.type = configElement_nonSave("config.scan.type", configSelection, 0, (("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat"))))
166                         config.scan.typecable = configElement_nonSave("config.scan.typecable", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
167                         config.scan.typeterrestrial = configElement_nonSave("config.scan.typeterrestrial", configSelection, 0, (("single_transponder", _("Single transponder")), ("complete", _("Complete"))))
168
169                         nimList = [ ]
170                         for nim in nimmanager.nimList():
171                                 nimList.append(nim[0])
172                         #nimList.append("all")
173                         config.scan.nims = configElement_nonSave("config.scan.nims", configSelection, 0, nimList)
174
175                         # sat
176                         config.scan.sat.frequency = configElement_nonSave("config.scan.sat.frequency", configSequence, [11836], configsequencearg.get("INTEGER", (1, 99999)))
177                         config.scan.sat.inversion = configElement_nonSave("config.scan.sat.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), _("Auto")))
178                         config.scan.sat.symbolrate = configElement_nonSave("config.scan.sat.symbolrate", configSequence, [27500], configsequencearg.get("INTEGER", (1, 99999)))
179                         config.scan.sat.polarization = configElement_nonSave("config.scan.sat.polarization", configSelection, 0, (("horizontal", _("horizontal")), ("vertical", _("vertical")),  ("circular_left", _("circular left")), ("circular_right", _("circular right"))))
180                         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"))))
181
182                         # cable
183                         config.scan.cab.frequency = configElement_nonSave("config.scan.cab.frequency", configSequence, [466], configsequencearg.get("INTEGER", (50, 9999)))
184                         config.scan.cab.inversion = configElement_nonSave("config.scan.cab.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
185                         config.scan.cab.modulation = configElement_nonSave("config.scan.cab.modulation", configSelection, 2, (("16qam", "16-QAM"), ("32qam", "32-QAM"), ("64qam", "64-QAM"), ("128qam", "128-QAM"), ("256qam", "256-QAM"), ("auto", _("Auto"))))
186                         config.scan.cab.fec = configElement_nonSave("config.scan.cab.fec", configSelection, 9, (("none", _("None")), ("1_2", "1/2"), ("2_3", "2/3"), ("3_4", "3/4"), ("5_6", "5/6"), ("7_8", "7/8"), ("auto", _("Auto"))))
187                         config.scan.cab.symbolrate = configElement_nonSave("config.scan.cab.symbolrate", configSequence, [6900], configsequencearg.get("INTEGER", (1, 9999)))
188
189                         # terrestial
190                         config.scan.ter.frequency = configElement_nonSave("config.scan.ter.frequency", configSequence, [466], configsequencearg.get("INTEGER", (100, 900)))
191                         config.scan.ter.inversion = configElement_nonSave("config.scan.ter.inversion", configSelection, 2, (("off", _("off")), ("on", _("on")), ("auto", _("Auto"))))
192                         config.scan.ter.bandwidth = configElement_nonSave("config.scan.ter.bandwidth", configSelection, 3, (("8MHz", "8MHz"), ("7MHz", "7MHz"), ("6MHz", "6MHz"), ("auto", _("Auto"))))
193                         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")))
194                         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"))))
195                         config.scan.ter.modulation = configElement_nonSave("config.scan.ter.modulation", configSelection, 2, (("qpsk", "QPSK"), ("qam16", "QAM16"), ("auto", _("Auto"))))
196                         config.scan.ter.transmission = configElement_nonSave("config.scan.ter.transmission", configSelection, 2, (("2k", "2K"), ("8k", "8K"), ("auto", _("Auto"))))
197                         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"))))
198                         config.scan.ter.hierarchy = configElement_nonSave("config.scan.ter.hierarchy", configSelection, 4, (("none", _("None")), ("1", "1"), ("2", "2"), ("4", "4"), ("auto", _("Auto"))))
199
200                         config.scan.scansat = {}
201                         for sat in nimmanager.satList:
202                                 #print sat[1]
203                                 config.scan.scansat[sat[1]] = configElement_nonSave("config.scan.scansat[" + str(sat[1]) + "]", configSelection, 0, (("yes", _("yes")), ("no", _("no"))))
204
205                         config.scan.satselection = []
206                         slotid = 0
207                         for slot in nimmanager.nimslots:
208                                 if (nimmanager.getNimType(slot.slotid) == nimmanager.nimType["DVB-S"]):
209                                         print str(slot.slotid) + " : " + str(self.satList)
210                                         config.scan.satselection.append(configElement_nonSave("config.scan.satselection[" + str(slot.slotid) + "]", configSatlist, 0, self.satList[slot.slotid]))
211                                 else:
212                                         config.scan.satselection.append(None)
213         def keyLeft(self):
214                 self["config"].handleKey(config.key["prevElement"])
215                 self.newConfig()
216
217         def keyRight(self):
218                 self["config"].handleKey(config.key["nextElement"])
219                 self.newConfig()
220
221         def keyNumberGlobal(self, number):
222                 print "You pressed number " + str(number)
223                 if (self["config"].getCurrent()[1].parent.enabled == True):
224                         self["config"].handleKey(config.key[str(number)])
225
226         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position):
227                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion)
228                 print "orbpos: " + str(orbital_position)
229                 parm = eDVBFrontendParametersSatellite()
230                 parm.frequency = frequency * 1000
231                 parm.symbol_rate = symbol_rate * 1000
232                 parm.polarisation = polarisation # eDVBFrontendParametersSatellite.Polarisation.Verti   
233                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
234                 #parm.fec = 6                                   # AUTO
235                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
236                 #parm.inversion = 2             #AUTO
237                 parm.orbital_position = int(orbital_position)
238                 tlist.append(parm)
239
240         # FIXME use correct parameters
241         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
242                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
243                 parm = eDVBFrontendParametersCable()
244                 parm.frequency = frequency * 1000
245                 parm.symbol_rate = symbol_rate * 1000
246                 parm.modulation = modulation # eDVBFrontendParametersSatellite.Polarisation.Verti       
247                 parm.fec = fec                  # eDVBFrontendParametersSatellite.FEC.f3_4;
248                 #parm.fec = 6                                   # AUTO
249                 parm.inversion = inversion      #eDVBFrontendParametersSatellite.Inversion.Off;
250                 #parm.inversion = 2             #AUTO
251                 tlist.append(parm)
252
253         # FIXME use correct parameters
254         def addTerTransponder(self, tlist, frequency):
255                 parm = eDVBFrontendParametersTerrestrial()
256                 
257                 parm.frequency = frequency * 1000000
258                 parm.inversion = 2  # eDVBFrontendParametersTerrestrial.Inversion.Unknown;
259                 parm.bandwidth = 0  #eDVBFrontendParametersTerrestrial.Bandwidth.Bw8MHz;
260                 parm.code_rate_HP = parm.code_rate_LP = 6 #eDVBFrontendParametersTerrestrial.FEC.fAuto;
261                 parm.modulation = 1 #eDVBFrontendParametersTerrestrial.Modulation.QAM16;
262                 parm.transmission_mode = 1 # eDVBFrontendParametersTerrestrial.TransmissionMode.TM8k;
263                 parm.guard_interval = 0 # eDVBFrontendParametersTerrestrial.GuardInterval.GI_1_32;
264                 parm.hierarchy = 0 #eDVBFrontendParametersTerrestrial.Hierarchy.HNone;
265                 tlist.append(parm)
266
267         def keyGo(self):
268                 tlist = []
269                 flags = 0
270                 if currentConfigSelectionElement(config.scan.type) == "single_transponder":
271                         if (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-S"]):
272                                 self.addSatTransponder(tlist, config.scan.sat.frequency.value[0],
273                                                                                           config.scan.sat.symbolrate.value[0],
274                                                                                           config.scan.sat.polarization.value,
275                                                                                           config.scan.sat.fec.value,
276                                                                                           config.scan.sat.inversion.value,
277                                                                                           self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1])
278                         elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-C"]):
279                                 self.addCabTransponder(tlist, config.scan.cab.frequency.value[0],
280                                                                                           config.scan.cab.symbolrate.value[0],
281                                                                                           config.scan.cab.modulation.value,
282                                                                                           config.scan.cab.fec.value,
283                                                                                           config.scan.cab.inversion.value)
284                         elif (nimmanager.getNimType(config.scan.nims.value) == nimmanager.nimType["DVB-T"]):
285                                 self.addTerTransponder(tlist, 
286                                                                                           config.scan.ter.frequency.value[0])
287
288                 elif currentConfigSelectionElement(config.scan.type) == single_satellite:
289                         getInitialTransponderList(tlist, int(self.satList[config.scan.nims.value][config.scan.satselection[config.scan.nims.value].value][1]))
290                         flags |= eComponentScan.scanNetworkSearch
291
292                 elif currentConfigSelectionElement(config.scan.type) == "multisat":
293                         SatList = nimmanager.getSatListForNim(config.scan.nims.value)
294
295                         for x in self.multiscanlist:
296                                 if x[1].parent.value == 0:
297                                         print "   " + str(x[1].parent.configPath)
298                                         getInitialTransponderList(tlist, x[1].parent.configPath)
299                         flags |= eComponentScan.scanNetworkSearch
300
301                 for x in self["config"].list:
302                         x[1].save()
303
304                 feid = config.scan.nims.value
305                 # flags |= eComponentScan.scanSearchBAT
306                 self.session.openWithCallback(self.doNothing, ServiceScan, tlist, feid, flags)
307
308                 #self.close()
309         def doNothing(self):
310                 pass
311
312         def keyCancel(self):
313                 for x in self["config"].list:
314                         x[1].cancel()
315                 self.close()
316
317 class ScanSimple(Screen):
318
319         def run(self):
320                 print "start scan for sats:"
321                 tlist = [ ]
322                 for x in self.list:
323                         if x[1].parent.value == 0:
324                                 print "   " + str(x[1].parent.configPath)
325                                 getInitialTransponderList(tlist, x[1].parent.configPath)
326
327                 feid = 0 # FIXME
328                 self.session.openWithCallback(self.doNothing, ServiceScan, tlist, feid, eComponentScan.scanNetworkSearch)
329                 
330
331         def keyGo(self):
332                 print "start scan for sats:"
333                 tlist = [ ]
334                 for x in self.list:
335                         if x[1].parent.value == 0:
336                                 print "   " + str(x[1].parent.configPath)
337                                 getInitialTransponderList(tlist, x[1].parent.configPath)
338
339                 feid = 0 # FIXME
340                 self.session.openWithCallback(self.doNothing, ServiceScan, tlist, feid, eComponentScan.scanNetworkSearch)
341
342         def doNothing(self):
343                 pass
344         
345         def keyCancel(self):
346                 self.close()
347
348         def keyLeft(self):
349                 self["config"].handleKey(config.key["prevElement"])
350
351         def keyRight(self):
352                 self["config"].handleKey(config.key["nextElement"])
353
354         def Satexists(self, tlist, pos):
355                 for x in tlist:
356                         if x == pos:
357                                 return 1
358                 return 0
359
360         def __init__(self, session):
361                 Screen.__init__(self, session)
362
363                 self["actions"] = ActionMap(["SetupActions"],
364                 {
365                         "ok": self.keyGo,
366                         "cancel": self.keyCancel,
367                         "left": self.keyLeft,
368                         "right": self.keyRight,
369                 }, -1)
370
371                 self.list = []
372                 tlist = []
373
374
375                 for slotid in nimmanager.getNimListOfType(nimmanager.nimType["DVB-S"]):
376                         SatList = nimmanager.getSatListForNim(slotid)
377
378                         for x in SatList:
379                                 if self.Satexists(tlist, x[1]) == 0:
380                                         tlist.append(x[1])
381                                         sat = configElement_nonSave(x[1], configSelection, 0, (("enable", _("Enable")), ("disable", _("Disable"))))
382                                         self.list.append(getConfigListEntry(nimmanager.getSatDescription(x[1]), sat))
383
384                 self["config"] = ConfigList(self.list)
385                 self["header"] = Label(_("Automatic Scan"))
386                 self["footer"] = Label(_("Press OK to scan"))