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