Merge commit 'origin/translations'
[enigma2.git] / lib / python / Screens / ScanSetup.py
1 from Screen import Screen
2 from Screens.DefaultWizard import DefaultWizard
3 from ServiceScan import ServiceScan
4 from Components.config import config, ConfigSubsection, ConfigSelection, \
5         ConfigYesNo, ConfigInteger, getConfigListEntry, ConfigSlider, ConfigEnableDisable
6 from Components.ActionMap import NumberActionMap, ActionMap
7 from Components.ConfigList import ConfigListScreen
8 from Components.NimManager import nimmanager, getConfigSatlist
9 from Components.Label import Label
10 from Tools.Directories import resolveFilename, SCOPE_DEFAULTPARTITIONMOUNTDIR, SCOPE_DEFAULTDIR, SCOPE_DEFAULTPARTITION
11 from Screens.MessageBox import MessageBox
12 from enigma import eTimer, eDVBFrontendParametersSatellite, eComponentScan, \
13         eDVBSatelliteEquipmentControl, eDVBFrontendParametersTerrestrial, \
14         eDVBFrontendParametersCable, eConsoleAppContainer, eDVBResourceManager
15
16 def buildTerTransponder(frequency, 
17                 inversion=2, bandwidth = 3, fechigh = 6, feclow = 6,
18                 modulation = 2, transmission = 2, guard = 4,
19                 hierarchy = 4):
20 #       print "freq", frequency, "inv", inversion, "bw", bandwidth, "fech", fechigh, "fecl", feclow, "mod", modulation, "tm", transmission, "guard", guard, "hierarchy", hierarchy
21         parm = eDVBFrontendParametersTerrestrial()
22         parm.frequency = frequency
23         parm.inversion = inversion
24         parm.bandwidth = bandwidth
25         parm.code_rate_HP = fechigh
26         parm.code_rate_LP = feclow
27         parm.modulation = modulation
28         parm.transmission_mode = transmission
29         parm.guard_interval = guard
30         parm.hierarchy = hierarchy
31         return parm
32
33 def getInitialTransponderList(tlist, pos):
34         list = nimmanager.getTransponders(pos)
35         for x in list:
36                 if x[0] == 0:           #SAT
37                         parm = eDVBFrontendParametersSatellite()
38                         parm.frequency = x[1]
39                         parm.symbol_rate = x[2]
40                         parm.polarisation = x[3]
41                         parm.fec = x[4]
42                         parm.inversion = x[7]
43                         parm.orbital_position = pos
44                         parm.system = x[5]
45                         parm.modulation = x[6]
46                         parm.rolloff = x[8]
47                         parm.pilot = x[9]
48                         tlist.append(parm)
49
50 def getInitialCableTransponderList(tlist, nim):
51         list = nimmanager.getTranspondersCable(nim)
52         for x in list:
53                 if x[0] == 1: #CABLE
54                         parm = eDVBFrontendParametersCable()
55                         parm.frequency = x[1]
56                         parm.symbol_rate = x[2]
57                         parm.modulation = x[3]
58                         parm.fec_inner = x[4]
59                         parm.inversion = parm.Inversion_Unknown
60                         #print "frequency:", x[1]
61                         #print "symbol_rate:", x[2]
62                         #print "modulation:", x[3]
63                         #print "fec_inner:", x[4]
64                         #print "inversion:", 2
65                         tlist.append(parm)
66
67 def getInitialTerrestrialTransponderList(tlist, region):
68         list = nimmanager.getTranspondersTerrestrial(region)
69
70         #self.transponders[self.parsedTer].append((2,freq,bw,const,crh,crl,guard,transm,hierarchy,inv))
71
72         #def buildTerTransponder(frequency, inversion = 2, bandwidth = 3, fechigh = 6, feclow = 6,
73                                 #modulation = 2, transmission = 2, guard = 4, hierarchy = 4):
74
75         for x in list:
76                 if x[0] == 2: #TERRESTRIAL
77                         parm = buildTerTransponder(x[1], x[9], x[2], x[4], x[5], x[3], x[7], x[6], x[8])
78                         tlist.append(parm)
79
80 cable_bands = {
81         "DVBC_BAND_EU_VHF_I" : 1 << 0,
82         "DVBC_BAND_EU_MID" : 1 << 1,
83         "DVBC_BAND_EU_VHF_III" : 1 << 2,
84         "DVBC_BAND_EU_SUPER" : 1 << 3,
85         "DVBC_BAND_EU_HYPER" : 1 << 4,
86         "DVBC_BAND_EU_UHF_IV" : 1 << 5,
87         "DVBC_BAND_EU_UHF_V" : 1 << 6,
88         "DVBC_BAND_US_LO" : 1 << 7,
89         "DVBC_BAND_US_MID" : 1 << 8,
90         "DVBC_BAND_US_HI" : 1 << 9,
91         "DVBC_BAND_US_SUPER" : 1 << 10,
92         "DVBC_BAND_US_HYPER" : 1 << 11,
93 }
94
95 class CableTransponderSearchSupport:
96 #       def setCableTransponderSearchResult(self, tlist):
97 #               pass
98
99 #       def cableTransponderSearchFinished(self):
100 #               pass
101
102         def tryGetRawFrontend(self, feid):
103                 res_mgr = eDVBResourceManager.getInstance()
104                 if res_mgr:
105                         raw_channel = res_mgr.allocateRawChannel(self.feid)
106                         if raw_channel:
107                                 frontend = raw_channel.getFrontend()
108                                 if frontend:
109                                         del frontend
110                                         del raw_channel
111                                         return True
112                 return False
113
114         def cableTransponderSearchSessionClosed(self, *val):
115                 print "cableTransponderSearchSessionClosed, val", val
116                 self.cable_search_container.appClosed.remove(self.cableTransponderSearchClosed)
117                 self.cable_search_container.dataAvail.remove(self.getCableTransponderData)
118                 self.cable_search_container = None
119                 self.cable_search_session = None
120                 if val and len(val) and val[0]:
121                         self.setCableTransponderSearchResult(self.__tlist)
122                 self.__tlist = None
123                 self.cableTransponderSearchFinished()
124
125         def cableTransponderSearchClosed(self, retval):
126                 print "cableTransponderSearch finished", retval
127                 self.cable_search_session.close(True)
128
129         def getCableTransponderData(self, str):
130                 data = str.split()
131                 if len(data):
132                         if data[0] == 'OK':
133                                 print str
134                                 parm = eDVBFrontendParametersCable()
135                                 qam = { "QAM16" : parm.Modulation_QAM16,
136                                         "QAM32" : parm.Modulation_QAM32,
137                                         "QAM64" : parm.Modulation_QAM64,
138                                         "QAM128" : parm.Modulation_QAM128,
139                                         "QAM256" : parm.Modulation_QAM256 }
140                                 inv = { "INVERSION_OFF" : parm.Inversion_Off,
141                                         "INVERSION_ON" : parm.Inversion_On,
142                                         "INVERSION_AUTO" : parm.Inversion_Unknown }
143                                 fec = { "FEC_AUTO" : parm.FEC_Auto,
144                                         "FEC_1_2" : parm.FEC_1_2,
145                                         "FEC_2_3" : parm.FEC_2_3,
146                                         "FEC_3_4" : parm.FEC_3_4,
147                                         "FEC_5_6": parm.FEC_5_6,
148                                         "FEC_7_8" : parm.FEC_7_8,
149                                         "FEC_8_9" : parm.FEC_8_9,
150                                         "FEC_NONE" : parm.FEC_None }
151                                 parm.frequency = int(data[1])
152                                 parm.symbol_rate = int(data[2])
153                                 parm.fec_inner = fec[data[3]]
154                                 parm.modulation = qam[data[4]]
155                                 parm.inversion = inv[data[5]]
156                                 self.__tlist.append(parm)
157                 tmpstr = _("Try to find used Transponders in cable network.. please wait...")
158                 tmpstr += "\n\n"
159                 tmpstr += data[1]
160                 tmpstr += " kHz "
161                 tmpstr += data[0]
162                 self.cable_search_session["text"].setText(tmpstr)
163
164         def startCableTransponderSearch(self, nim_idx):
165                 if not self.tryGetRawFrontend(nim_idx):
166                         self.session.nav.stopService()
167                         if not self.tryGetRawFrontend(nim_idx):
168                                 if self.session.pipshown: # try to disable pip
169                                         self.session.pipshown = False
170                                         del self.session.pip
171                                 if not self.tryGetRawFrontend(nim_idx):
172                                         self.cableTransponderSearchFinished()
173                                         return
174                 self.__tlist = [ ]
175                 self.cable_search_container = eConsoleAppContainer()
176                 self.cable_search_container.appClosed.append(self.cableTransponderSearchClosed)
177                 self.cable_search_container.dataAvail.append(self.getCableTransponderData)
178                 cableConfig = config.Nims[nim_idx].cable
179                 cmd = "tda1002x --init --scan --verbose --wakeup --inv 2 --bus "
180                 #FIXMEEEEEE hardcoded i2c devices for dm7025 and dm8000
181                 if nim_idx < 2:
182                         cmd += str(nim_idx)
183                 else:
184                         if nim_idx == 2:
185                                 cmd += "2" # first nim socket on DM8000 use /dev/i2c/2
186                         else:
187                                 cmd += "4" # second nim socket on DM8000 use /dev/i2c/4
188                 if cableConfig.scan_type.value == "bands":
189                         cmd += " --scan-bands "
190                         bands = 0
191                         if cableConfig.scan_band_EU_VHF_I.value:
192                                 bands |= cable_bands["DVBC_BAND_EU_VHF_I"]
193                         if cableConfig.scan_band_EU_MID.value:
194                                 bands |= cable_bands["DVBC_BAND_EU_MID"]
195                         if cableConfig.scan_band_EU_VHF_III.value:
196                                 bands |= cable_bands["DVBC_BAND_EU_VHF_III"]
197                         if cableConfig.scan_band_EU_UHF_IV.value:
198                                 bands |= cable_bands["DVBC_BAND_EU_UHF_IV"]
199                         if cableConfig.scan_band_EU_UHF_V.value:
200                                 bands |= cable_bands["DVBC_BAND_EU_UHF_V"]
201                         if cableConfig.scan_band_EU_SUPER.value:
202                                 bands |= cable_bands["DVBC_BAND_EU_SUPER"]
203                         if cableConfig.scan_band_EU_HYPER.value:
204                                 bands |= cable_bands["DVBC_BAND_EU_HYPER"]
205                         if cableConfig.scan_band_US_LOW.value:
206                                 bands |= cable_bands["DVBC_BAND_US_LO"]
207                         if cableConfig.scan_band_US_MID.value:
208                                 bands |= cable_bands["DVBC_BAND_US_MID"]
209                         if cableConfig.scan_band_US_HIGH.value:
210                                 bands |= cable_bands["DVBC_BAND_US_HI"]
211                         if cableConfig.scan_band_US_SUPER.value:
212                                 bands |= cable_bands["DVBC_BAND_US_SUPER"]
213                         if cableConfig.scan_band_US_HYPER.value:
214                                 bands |= cable_bands["DVBC_BAND_US_HYPER"]
215                         cmd += str(bands)
216                 else:
217                         cmd += " --scan-stepsize "
218                         cmd += str(cableConfig.scan_frequency_steps.value)
219                 if cableConfig.scan_mod_qam16.value:
220                         cmd += " --mod 16"
221                 if cableConfig.scan_mod_qam32.value:
222                         cmd += " --mod 32"
223                 if cableConfig.scan_mod_qam64.value:
224                         cmd += " --mod 64"
225                 if cableConfig.scan_mod_qam128.value:
226                         cmd += " --mod 128"
227                 if cableConfig.scan_mod_qam256.value:
228                         cmd += " --mod 256"
229                 if cableConfig.scan_sr_6900.value:
230                         cmd += " --sr 6900000"
231                 if cableConfig.scan_sr_6875.value:
232                         cmd += " --sr 6875000"
233                 if cableConfig.scan_sr_ext1.value > 450:
234                         cmd += " --sr "
235                         cmd += str(cableConfig.scan_sr_ext1.value)
236                         cmd += "000"
237                 if cableConfig.scan_sr_ext2.value > 450:
238                         cmd += " --sr "
239                         cmd += str(cableConfig.scan_sr_ext2.value)
240                         cmd += "000"
241                 print "TDA1002x CMD is", cmd
242
243                 self.cable_search_container.execute(cmd)
244                 tmpstr = _("Try to find used transponders in cable network.. please wait...")
245                 tmpstr += "\n\n..."
246                 self.cable_search_session = self.session.openWithCallback(self.cableTransponderSearchSessionClosed, MessageBox, tmpstr, MessageBox.TYPE_INFO)
247
248 class DefaultSatLists(DefaultWizard):
249         def __init__(self, session, silent = True, showSteps = False):
250                 self.xmlfile = "defaultsatlists.xml"
251                 DefaultWizard.__init__(self, session, silent, showSteps, neededTag = "services")
252                 print "configuredSats:", nimmanager.getConfiguredSats()
253
254         def setDirectory(self):
255                 self.directory = []
256                 self.directory.append(resolveFilename(SCOPE_DEFAULTDIR))
257                 import os
258                 os.system("mount %s %s" % (resolveFilename(SCOPE_DEFAULTPARTITION), resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR)))
259                 self.directory.append(resolveFilename(SCOPE_DEFAULTPARTITIONMOUNTDIR))
260                                 
261         def statusCallback(self, status, progress):
262                 print "statusCallback:", status, progress
263                 from Components.DreamInfoHandler import DreamInfoHandler
264                 if status == DreamInfoHandler.STATUS_DONE:
265                         self["text"].setText(_("The installation of the default services lists is finished.") + "\n\n" + _("Please press OK to continue."))
266                         self.markDone()
267                         self.disableKeys = False        
268
269 class ScanSetup(ConfigListScreen, Screen, CableTransponderSearchSupport):
270         def __init__(self, session):
271                 Screen.__init__(self, session)
272
273                 self.finished_cb = None
274                 self.updateSatList()
275                 self.service = session.nav.getCurrentService()
276                 self.feinfo = None
277                 frontendData = None
278                 if self.service is not None:
279                         self.feinfo = self.service.frontendInfo()
280                         frontendData = self.feinfo and self.feinfo.getAll(True)
281                 
282                 self.createConfig(frontendData)
283
284                 del self.feinfo
285                 del self.service
286
287                 self["actions"] = NumberActionMap(["SetupActions"],
288                 {
289                         "ok": self.keyGo,
290                         "cancel": self.keyCancel,
291                 }, -2)
292
293                 self.statusTimer = eTimer()
294                 self.statusTimer.callback.append(self.updateStatus)
295                 #self.statusTimer.start(5000, True)
296
297                 self.list = []
298                 ConfigListScreen.__init__(self, self.list)
299                 if not self.scan_nims.value == "":
300                         self.createSetup()
301                         self["introduction"] = Label(_("Press OK to start the scan"))
302                 else:
303                         self["introduction"] = Label(_("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."))
304
305         def runAsync(self, finished_cb):
306                 self.finished_cb = finished_cb
307                 self.keyGo()
308
309         def updateSatList(self):
310                 self.satList = []
311                 for slot in nimmanager.nim_slots:
312                         if slot.isCompatible("DVB-S"):
313                                 self.satList.append(nimmanager.getSatListForNim(slot.slot))
314                         else:
315                                 self.satList.append(None)
316
317         def createSetup(self):
318                 self.list = []
319                 self.multiscanlist = []
320                 index_to_scan = int(self.scan_nims.value)
321                 print "ID: ", index_to_scan
322
323                 self.tunerEntry = getConfigListEntry(_("Tuner"), self.scan_nims)
324                 self.list.append(self.tunerEntry)
325                 
326                 if self.scan_nims == [ ]:
327                         return
328                 
329                 self.typeOfScanEntry = None
330                 self.systemEntry = None
331                 self.modulationEntry = None
332                 nim = nimmanager.nim_slots[index_to_scan]
333                 if nim.isCompatible("DVB-S"):
334                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_type)
335                         self.list.append(self.typeOfScanEntry)
336                 elif nim.isCompatible("DVB-C"):
337                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typecable)
338                         self.list.append(self.typeOfScanEntry)
339                 elif nim.isCompatible("DVB-T"):
340                         self.typeOfScanEntry = getConfigListEntry(_("Type of scan"), self.scan_typeterrestrial)
341                         self.list.append(self.typeOfScanEntry)
342
343                 self.scan_networkScan.value = False
344                 if nim.isCompatible("DVB-S"):
345                         if self.scan_type.value == "single_transponder":
346                                 self.updateSatList()
347                                 if nim.isCompatible("DVB-S2"):
348                                         self.systemEntry = getConfigListEntry(_('System'), self.scan_sat.system)
349                                         self.list.append(self.systemEntry)
350                                 else:
351                                         # downgrade to dvb-s, in case a -s2 config was active
352                                         self.scan_sat.system.value = eDVBFrontendParametersSatellite.System_DVB_S
353                                 self.list.append(getConfigListEntry(_('Satellite'), self.scan_satselection[index_to_scan]))
354                                 self.list.append(getConfigListEntry(_('Frequency'), self.scan_sat.frequency))
355                                 self.list.append(getConfigListEntry(_('Inversion'), self.scan_sat.inversion))
356                                 self.list.append(getConfigListEntry(_('Symbol Rate'), self.scan_sat.symbolrate))
357                                 self.list.append(getConfigListEntry(_("Polarity"), self.scan_sat.polarization))
358                                 if self.scan_sat.system.value == eDVBFrontendParametersSatellite.System_DVB_S:
359                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec))
360                                 elif self.scan_sat.system.value == eDVBFrontendParametersSatellite.System_DVB_S2:
361                                         self.list.append(getConfigListEntry(_("FEC"), self.scan_sat.fec_s2))
362                                         self.modulationEntry = getConfigListEntry(_('Modulation'), self.scan_sat.modulation)
363                                         self.list.append(self.modulationEntry)
364                                         self.list.append(getConfigListEntry(_('Rolloff'), self.scan_sat.rolloff))
365                                         self.list.append(getConfigListEntry(_('Pilot'), self.scan_sat.pilot))
366                         elif self.scan_type.value == "single_satellite":
367                                 self.updateSatList()
368                                 print self.scan_satselection[index_to_scan]
369                                 self.list.append(getConfigListEntry(_("Satellite"), self.scan_satselection[index_to_scan]))
370                                 self.scan_networkScan.value = True
371                         elif self.scan_type.value.find("multisat") != -1:
372                                 tlist = []
373                                 SatList = nimmanager.getSatListForNim(index_to_scan)
374                                 for x in SatList:
375                                         if self.Satexists(tlist, x[0]) == 0:
376                                                 tlist.append(x[0])
377                                                 sat = ConfigEnableDisable(default = self.scan_type.value.find("_yes") != -1 and True or False)
378                                                 configEntry = getConfigListEntry(nimmanager.getSatDescription(x[0]), sat)
379                                                 self.list.append(configEntry)
380                                                 self.multiscanlist.append((x[0], sat))
381                                 self.scan_networkScan.value = True
382                 elif nim.isCompatible("DVB-C"):
383                         if self.scan_typecable.value == "single_transponder":
384                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_cab.frequency))
385                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_cab.inversion))
386                                 self.list.append(getConfigListEntry(_("Symbol Rate"), self.scan_cab.symbolrate))
387                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_cab.modulation))
388                                 self.list.append(getConfigListEntry(_("FEC"), self.scan_cab.fec))
389                 elif nim.isCompatible("DVB-T"):
390                         if self.scan_typeterrestrial.value == "single_transponder":
391                                 self.list.append(getConfigListEntry(_("Frequency"), self.scan_ter.frequency))
392                                 self.list.append(getConfigListEntry(_("Inversion"), self.scan_ter.inversion))
393                                 self.list.append(getConfigListEntry(_("Bandwidth"), self.scan_ter.bandwidth))
394                                 self.list.append(getConfigListEntry(_("Code rate high"), self.scan_ter.fechigh))
395                                 self.list.append(getConfigListEntry(_("Code rate low"), self.scan_ter.feclow))
396                                 self.list.append(getConfigListEntry(_("Modulation"), self.scan_ter.modulation))
397                                 self.list.append(getConfigListEntry(_("Transmission mode"), self.scan_ter.transmission))
398                                 self.list.append(getConfigListEntry(_("Guard interval mode"), self.scan_ter.guard))
399                                 self.list.append(getConfigListEntry(_("Hierarchy mode"), self.scan_ter.hierarchy))
400                 self.list.append(getConfigListEntry(_("Network scan"), self.scan_networkScan))
401                 self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
402                 self.list.append(getConfigListEntry(_("Only Free scan"), self.scan_onlyfree))
403                 self["config"].list = self.list
404                 self["config"].l.setList(self.list)
405
406         def Satexists(self, tlist, pos):
407                 for x in tlist:
408                         if x == pos:
409                                 return 1
410                 return 0
411
412         def newConfig(self):
413                 cur = self["config"].getCurrent()
414                 print "cur is", cur
415                 if cur == self.typeOfScanEntry or \
416                         cur == self.tunerEntry or \
417                         cur == self.systemEntry or \
418                         (self.modulationEntry and self.systemEntry[1].value == eDVBFrontendParametersSatellite.System_DVB_S2 and cur == self.modulationEntry):
419                         self.createSetup()
420
421         def createConfig(self, frontendData):
422                                                            #("Type", frontendData["system"], TYPE_TEXT),
423                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
424                                            #("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
425                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
426                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
427                                            #("Polarization", frontendData["polarization"], TYPE_TEXT),
428                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
429                                            #("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
430                                                 #)
431                 #elif frontendData["tuner_type"] == "DVB-C":
432                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
433                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
434                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
435                                            #("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
436                                            #("Modulation", frontendData["modulation"], TYPE_TEXT),
437                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
438                         #                  ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
439                                                 #)
440                 #elif frontendData["tuner_type"] == "DVB-T":
441                         #return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
442                                            #("Type", frontendData["tuner_type"], TYPE_TEXT),
443                                            #("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
444                                            #("Inversion", frontendData["inversion"], TYPE_TEXT),
445                                            #("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
446                                            #("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
447                                            #("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
448                                            #("Constellation", frontendData["constellation"], TYPE_TEXT),
449                                            #("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
450                                            #("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
451                                            #("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT),
452                         defaultSat = {
453                                 "orbpos": 192,
454                                 "system": eDVBFrontendParametersSatellite.System_DVB_S,
455                                 "frequency": 11836,
456                                 "inversion": eDVBFrontendParametersSatellite.Inversion_Unknown,
457                                 "symbolrate": 27500,
458                                 "polarization": eDVBFrontendParametersSatellite.Polarisation_Horizontal,
459                                 "fec": eDVBFrontendParametersSatellite.FEC_Auto,
460                                 "fec_s2": eDVBFrontendParametersSatellite.FEC_9_10,
461                                 "modulation": eDVBFrontendParametersSatellite.Modulation_QPSK }
462                         defaultCab = {
463                                 "frequency": 466,
464                                 "inversion": eDVBFrontendParametersCable.Inversion_Unknown,
465                                 "modulation": eDVBFrontendParametersCable.Modulation_QAM64,
466                                 "fec": eDVBFrontendParametersCable.FEC_Auto,
467                                 "symbolrate": 6900 }
468                         defaultTer = {
469                                 "frequency" : 466000,
470                                 "inversion" : eDVBFrontendParametersTerrestrial.Inversion_Unknown,
471                                 "bandwidth" : eDVBFrontendParametersTerrestrial.Bandwidth_7MHz,
472                                 "fechigh" : eDVBFrontendParametersTerrestrial.FEC_Auto,
473                                 "feclow" : eDVBFrontendParametersTerrestrial.FEC_Auto,
474                                 "modulation" : eDVBFrontendParametersTerrestrial.Modulation_Auto,
475                                 "transmission_mode" : eDVBFrontendParametersTerrestrial.TransmissionMode_Auto,
476                                 "guard_interval" : eDVBFrontendParametersTerrestrial.GuardInterval_Auto,
477                                 "hierarchy": eDVBFrontendParametersTerrestrial.Hierarchy_Auto }
478
479                         if frontendData is not None:
480                                 ttype = frontendData.get("tuner_type", "UNKNOWN")
481                                 if ttype == "DVB-S":
482                                         defaultSat["system"] = frontendData.get("system", eDVBFrontendParametersSatellite.System_DVB_S)
483                                         defaultSat["frequency"] = frontendData.get("frequency", 0) / 1000
484                                         defaultSat["inversion"] = frontendData.get("inversion", eDVBFrontendParametersSatellite.Inversion_Unknown)
485                                         defaultSat["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
486                                         defaultSat["polarization"] = frontendData.get("polarization", eDVBFrontendParametersSatellite.Polarisation_Horizontal)
487                                         if defaultSat["system"] == eDVBFrontendParametersSatellite.System_DVB_S2:
488                                                 defaultSat["fec_s2"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
489                                                 defaultSat["rolloff"] = frontendData.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35)
490                                                 defaultSat["pilot"] = frontendData.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown)
491                                         else:
492                                                 defaultSat["fec"] = frontendData.get("fec_inner", eDVBFrontendParametersSatellite.FEC_Auto)
493                                         defaultSat["modulation"] = frontendData.get("modulation", eDVBFrontendParametersSatellite.Modulation_QPSK)
494                                         defaultSat["orbpos"] = frontendData.get("orbital_position", 0)
495                                 elif ttype == "DVB-C":
496                                         defaultCab["frequency"] = frontendData.get("frequency", 0) / 1000
497                                         defaultCab["symbolrate"] = frontendData.get("symbol_rate", 0) / 1000
498                                         defaultCab["inversion"] = frontendData.get("inversion", eDVBFrontendParametersCable.Inversion_Unknown)
499                                         defaultCab["fec"] = frontendData.get("fec_inner", eDVBFrontendParametersCable.FEC_Auto)
500                                         defaultCab["modulation"] = frontendData.get("modulation", eDVBFrontendParametersCable.Modulation_QAM16)
501                                 elif ttype == "DVB-T":
502                                         defaultTer["frequency"] = frontendData.get("frequency", 0)
503                                         defaultTer["inversion"] = frontendData.get("inversion", eDVBFrontendParametersTerrestrial.Inversion_Unknown)
504                                         defaultTer["bandwidth"] = frontendData.get("bandwidth", eDVBFrontendParametersTerrestrial.Bandwidth_7MHz)
505                                         defaultTer["fechigh"] = frontendData.get("code_rate_hp", eDVBFrontendParametersTerrestrial.FEC_Auto)
506                                         defaultTer["feclow"] = frontendData.get("code_rate_lp", eDVBFrontendParametersTerrestrial.FEC_Auto)
507                                         defaultTer["modulation"] = frontendData.get("constellation", eDVBFrontendParametersTerrestrial.Modulation_Auto)
508                                         defaultTer["transmission_mode"] = frontendData.get("transmission_mode", eDVBFrontendParametersTerrestrial.TransmissionMode_Auto)
509                                         defaultTer["guard_interval"] = frontendData.get("guard_interval", eDVBFrontendParametersTerrestrial.GuardInterval_Auto)
510                                         defaultTer["hierarchy"] = frontendData.get("hierarchy_information", eDVBFrontendParametersTerrestrial.Hierarchy_Auto)
511
512                         self.scan_sat = ConfigSubsection()
513                         self.scan_cab = ConfigSubsection()
514                         self.scan_ter = ConfigSubsection()
515
516                         self.scan_type = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("single_satellite", _("Single satellite")), ("multisat", _("Multisat")), ("multisat_yes", _("Multisat"))])
517                         self.scan_typecable = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
518                         self.scan_typeterrestrial = ConfigSelection(default = "single_transponder", choices = [("single_transponder", _("Single transponder")), ("complete", _("Complete"))])
519                         self.scan_clearallservices = ConfigSelection(default = "no", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
520                         self.scan_onlyfree = ConfigYesNo(default = False)
521                         self.scan_networkScan = ConfigYesNo(default = False)
522
523                         nim_list = []
524                         # collect all nims which are *not* set to "nothing"
525                         for n in nimmanager.nim_slots:
526                                 if n.config_mode == "nothing":
527                                         continue
528                                 if n.config_mode == "advanced" and len(nimmanager.getSatListForNim(n.slot)) < 1:
529                                         continue
530                                 if n.config_mode in ("loopthrough", "satposdepends"):
531                                         root_id = nimmanager.sec.getRoot(n.slot_id, int(n.config.connectedTo.value))
532                                         if n.type == nimmanager.nim_slots[root_id].type: # check if connected from a DVB-S to DVB-S2 Nim or vice versa
533                                                 continue
534                                 nim_list.append((str(n.slot), n.friendly_full_description))
535
536                         self.scan_nims = ConfigSelection(choices = nim_list)
537
538                         # status
539                         self.scan_snr = ConfigSlider()
540                         self.scan_snr.enabled = False
541                         self.scan_agc = ConfigSlider()
542                         self.scan_agc.enabled = False
543                         self.scan_ber = ConfigSlider()
544                         self.scan_ber.enabled = False
545
546                         # sat
547                         self.scan_sat.system = ConfigSelection(default = defaultSat["system"], choices = [
548                                 (eDVBFrontendParametersSatellite.System_DVB_S, _("DVB-S")),
549                                 (eDVBFrontendParametersSatellite.System_DVB_S2, _("DVB-S2"))])
550                         self.scan_sat.frequency = ConfigInteger(default = defaultSat["frequency"], limits = (1, 99999))
551                         self.scan_sat.inversion = ConfigSelection(default = defaultSat["inversion"], choices = [
552                                 (eDVBFrontendParametersSatellite.Inversion_Off, _("off")),
553                                 (eDVBFrontendParametersSatellite.Inversion_On, _("on")),
554                                 (eDVBFrontendParametersSatellite.Inversion_Unknown, _("Auto"))])
555                         self.scan_sat.symbolrate = ConfigInteger(default = defaultSat["symbolrate"], limits = (1, 99999))
556                         self.scan_sat.polarization = ConfigSelection(default = defaultSat["polarization"], choices = [
557                                 (eDVBFrontendParametersSatellite.Polarisation_Horizontal, _("horizontal")),
558                                 (eDVBFrontendParametersSatellite.Polarisation_Vertical, _("vertical")),
559                                 (eDVBFrontendParametersSatellite.Polarisation_CircularLeft, _("circular left")),
560                                 (eDVBFrontendParametersSatellite.Polarisation_CircularRight, _("circular right"))])
561                         self.scan_sat.fec = ConfigSelection(default = defaultSat["fec"], choices = [
562                                 (eDVBFrontendParametersSatellite.FEC_Auto, _("Auto")),
563                                 (eDVBFrontendParametersSatellite.FEC_1_2, "1/2"),
564                                 (eDVBFrontendParametersSatellite.FEC_2_3, "2/3"),
565                                 (eDVBFrontendParametersSatellite.FEC_3_4, "3/4"),
566                                 (eDVBFrontendParametersSatellite.FEC_5_6, "5/6"),
567                                 (eDVBFrontendParametersSatellite.FEC_7_8, "7/8"),
568                                 (eDVBFrontendParametersSatellite.FEC_None, _("None"))])
569                         self.scan_sat.fec_s2 = ConfigSelection(default = defaultSat["fec_s2"], choices = [
570                                 (eDVBFrontendParametersSatellite.FEC_1_2, "1/2"),
571                                 (eDVBFrontendParametersSatellite.FEC_2_3, "2/3"),
572                                 (eDVBFrontendParametersSatellite.FEC_3_4, "3/4"),
573                                 (eDVBFrontendParametersSatellite.FEC_3_5, "3/5"),
574                                 (eDVBFrontendParametersSatellite.FEC_4_5, "4/5"),
575                                 (eDVBFrontendParametersSatellite.FEC_5_6, "5/6"),
576                                 (eDVBFrontendParametersSatellite.FEC_7_8, "7/8"),
577                                 (eDVBFrontendParametersSatellite.FEC_8_9, "8/9"),
578                                 (eDVBFrontendParametersSatellite.FEC_9_10, "9/10")])
579                         self.scan_sat.modulation = ConfigSelection(default = defaultSat["modulation"], choices = [
580                                 (eDVBFrontendParametersSatellite.Modulation_QPSK, "QPSK"),
581                                 (eDVBFrontendParametersSatellite.Modulation_8PSK, "8PSK")])
582                         self.scan_sat.rolloff = ConfigSelection(default = defaultSat.get("rolloff", eDVBFrontendParametersSatellite.RollOff_alpha_0_35), choices = [
583                                 (eDVBFrontendParametersSatellite.RollOff_alpha_0_35, "0.35"),
584                                 (eDVBFrontendParametersSatellite.RollOff_alpha_0_25, "0.25"),
585                                 (eDVBFrontendParametersSatellite.RollOff_alpha_0_20, "0.20")])
586                         self.scan_sat.pilot = ConfigSelection(default = defaultSat.get("pilot", eDVBFrontendParametersSatellite.Pilot_Unknown), choices = [
587                                 (eDVBFrontendParametersSatellite.Pilot_Off, _("off")),
588                                 (eDVBFrontendParametersSatellite.Pilot_On, _("on")),
589                                 (eDVBFrontendParametersSatellite.Pilot_Unknown, _("Auto"))])
590
591                         # cable
592                         self.scan_cab.frequency = ConfigInteger(default = defaultCab["frequency"], limits = (50, 999))
593                         self.scan_cab.inversion = ConfigSelection(default = defaultCab["inversion"], choices = [
594                                 (eDVBFrontendParametersCable.Inversion_Off, _("off")),
595                                 (eDVBFrontendParametersCable.Inversion_On, _("on")),
596                                 (eDVBFrontendParametersCable.Inversion_Unknown, _("Auto"))])
597                         self.scan_cab.modulation = ConfigSelection(default = defaultCab["modulation"], choices = [
598                                 (eDVBFrontendParametersCable.Modulation_QAM16, "16-QAM"),
599                                 (eDVBFrontendParametersCable.Modulation_QAM32, "32-QAM"),
600                                 (eDVBFrontendParametersCable.Modulation_QAM64, "64-QAM"),
601                                 (eDVBFrontendParametersCable.Modulation_QAM128, "128-QAM"),
602                                 (eDVBFrontendParametersCable.Modulation_QAM256, "256-QAM")])
603                         self.scan_cab.fec = ConfigSelection(default = defaultCab["fec"], choices = [
604                                 (eDVBFrontendParametersCable.FEC_Auto, _("Auto")),
605                                 (eDVBFrontendParametersCable.FEC_1_2, "1/2"),
606                                 (eDVBFrontendParametersCable.FEC_2_3, "2/3"),
607                                 (eDVBFrontendParametersCable.FEC_3_4, "3/4"),
608                                 (eDVBFrontendParametersCable.FEC_5_6, "5/6"),
609                                 (eDVBFrontendParametersCable.FEC_7_8, "7/8"),
610                                 (eDVBFrontendParametersCable.FEC_8_9, "8/9"),
611                                 (eDVBFrontendParametersCable.FEC_None, _("None"))])
612                         self.scan_cab.symbolrate = ConfigInteger(default = defaultCab["symbolrate"], limits = (1, 99999))
613
614                         # terrestial
615                         self.scan_ter.frequency = ConfigInteger(default = 466000, limits = (50000, 999000))
616                         self.scan_ter.inversion = ConfigSelection(default = defaultTer["inversion"], choices = [
617                                 (eDVBFrontendParametersTerrestrial.Inversion_Off, _("off")),
618                                 (eDVBFrontendParametersTerrestrial.Inversion_On, _("on")),
619                                 (eDVBFrontendParametersTerrestrial.Inversion_Unknown, _("Auto"))])
620                         # WORKAROUND: we can't use BW-auto
621                         self.scan_ter.bandwidth = ConfigSelection(default = defaultTer["bandwidth"], choices = [
622                                 (eDVBFrontendParametersTerrestrial.Bandwidth_8MHz, "8MHz"),
623                                 (eDVBFrontendParametersTerrestrial.Bandwidth_7MHz, "7MHz"),
624                                 (eDVBFrontendParametersTerrestrial.Bandwidth_6MHz, "6MHz")])
625                         #, (eDVBFrontendParametersTerrestrial.Bandwidth_Auto, _("Auto"))))
626                         self.scan_ter.fechigh = ConfigSelection(default = defaultTer["fechigh"], choices = [
627                                 (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
628                                 (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
629                                 (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
630                                 (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
631                                 (eDVBFrontendParametersTerrestrial.FEC_7_8, "7/8"),
632                                 (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
633                         self.scan_ter.feclow = ConfigSelection(default = defaultTer["feclow"], choices = [
634                                 (eDVBFrontendParametersTerrestrial.FEC_1_2, "1/2"),
635                                 (eDVBFrontendParametersTerrestrial.FEC_2_3, "2/3"),
636                                 (eDVBFrontendParametersTerrestrial.FEC_3_4, "3/4"),
637                                 (eDVBFrontendParametersTerrestrial.FEC_5_6, "5/6"),
638                                 (eDVBFrontendParametersTerrestrial.FEC_7_8, "7/8"),
639                                 (eDVBFrontendParametersTerrestrial.FEC_Auto, _("Auto"))])
640                         self.scan_ter.modulation = ConfigSelection(default = defaultTer["modulation"], choices = [
641                                 (eDVBFrontendParametersTerrestrial.Modulation_QPSK, "QPSK"),
642                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM16, "QAM16"),
643                                 (eDVBFrontendParametersTerrestrial.Modulation_QAM64, "QAM64"),
644                                 (eDVBFrontendParametersTerrestrial.Modulation_Auto, _("Auto"))])
645                         self.scan_ter.transmission = ConfigSelection(default = defaultTer["transmission_mode"], choices = [
646                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_2k, "2K"),
647                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_8k, "8K"),
648                                 (eDVBFrontendParametersTerrestrial.TransmissionMode_Auto, _("Auto"))])
649                         self.scan_ter.guard = ConfigSelection(default = defaultTer["guard_interval"], choices = [
650                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_32, "1/32"),
651                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_16, "1/16"),
652                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_8, "1/8"),
653                                 (eDVBFrontendParametersTerrestrial.GuardInterval_1_4, "1/4"),
654                                 (eDVBFrontendParametersTerrestrial.GuardInterval_Auto, _("Auto"))])
655                         self.scan_ter.hierarchy = ConfigSelection(default = defaultTer["hierarchy"], choices = [
656                                 (eDVBFrontendParametersTerrestrial.Hierarchy_None, _("None")),
657                                 (eDVBFrontendParametersTerrestrial.Hierarchy_1, "1"),
658                                 (eDVBFrontendParametersTerrestrial.Hierarchy_2, "2"),
659                                 (eDVBFrontendParametersTerrestrial.Hierarchy_4, "4"),
660                                 (eDVBFrontendParametersTerrestrial.Hierarchy_Auto, _("Auto"))])
661
662                         self.scan_scansat = {}
663                         for sat in nimmanager.satList:
664                                 #print sat[1]
665                                 self.scan_scansat[sat[0]] = ConfigYesNo(default = False)
666
667                         self.scan_satselection = []
668                         for slot in nimmanager.nim_slots:
669                                 if slot.isCompatible("DVB-S"):
670                                         self.scan_satselection.append(getConfigSatlist(defaultSat["orbpos"], self.satList[slot.slot]))
671                                 else:
672                                         self.scan_satselection.append(None)
673
674                         return True
675
676         def keyLeft(self):
677                 ConfigListScreen.keyLeft(self)
678                 self.newConfig()
679
680         def keyRight(self):
681                 ConfigListScreen.keyRight(self)
682                 self.newConfig()
683
684         def updateStatus(self):
685                 print "updatestatus"
686
687         def addSatTransponder(self, tlist, frequency, symbol_rate, polarisation, fec, inversion, orbital_position, system, modulation, rolloff, pilot):
688                 print "Add Sat: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(polarisation) + " fec: " + str(fec) + " inversion: " + str(inversion) + " modulation: " + str(modulation) + " system: " + str(system) + " rolloff" + str(rolloff) + " pilot" + str(pilot)
689                 print "orbpos: " + str(orbital_position)
690                 parm = eDVBFrontendParametersSatellite()
691                 parm.modulation = modulation
692                 parm.system = system
693                 parm.frequency = frequency * 1000
694                 parm.symbol_rate = symbol_rate * 1000
695                 parm.polarisation = polarisation
696                 parm.fec = fec
697                 parm.inversion = inversion
698                 parm.orbital_position = orbital_position
699                 parm.rolloff = rolloff
700                 parm.pilot = pilot
701                 tlist.append(parm)
702
703         def addCabTransponder(self, tlist, frequency, symbol_rate, modulation, fec, inversion):
704                 print "Add Cab: frequ: " + str(frequency) + " symbol: " + str(symbol_rate) + " pol: " + str(modulation) + " fec: " + str(fec) + " inversion: " + str(inversion)
705                 parm = eDVBFrontendParametersCable()
706                 parm.frequency = frequency * 1000
707                 parm.symbol_rate = symbol_rate * 1000
708                 parm.modulation = modulation
709                 parm.fec = fec
710                 parm.inversion = inversion
711                 tlist.append(parm)
712
713         def addTerTransponder(self, tlist, *args, **kwargs):
714                 tlist.append(buildTerTransponder(*args, **kwargs))
715
716         def keyGo(self):
717                 if self.scan_nims.value == "":
718                         return
719                 tlist = []
720                 flags = None
721                 startScan = True
722                 removeAll = True
723                 index_to_scan = int(self.scan_nims.value)
724                 
725                 if self.scan_nims == [ ]:
726                         self.session.open(MessageBox, _("No tuner is enabled!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
727                         return
728
729                 nim = nimmanager.nim_slots[index_to_scan]
730                 print "nim", nim.slot
731                 if nim.isCompatible("DVB-S"):
732                         print "is compatible with DVB-S"
733                         if self.scan_type.value == "single_transponder":
734                                 # these lists are generated for each tuner, so this has work.
735                                 assert len(self.satList) > index_to_scan
736                                 assert len(self.scan_satselection) > index_to_scan
737                                 
738                                 nimsats = self.satList[index_to_scan]
739                                 selsatidx = self.scan_satselection[index_to_scan].index
740
741                                 # however, the satList itself could be empty. in that case, "index" is 0 (for "None").
742                                 if len(nimsats):
743                                         orbpos = nimsats[selsatidx][0]
744                                         if self.scan_sat.system.value == eDVBFrontendParametersSatellite.System_DVB_S:
745                                                 fec = self.scan_sat.fec.value
746                                         else:
747                                                 fec = self.scan_sat.fec_s2.value
748                                         print "add sat transponder"
749                                         self.addSatTransponder(tlist, self.scan_sat.frequency.value,
750                                                                 self.scan_sat.symbolrate.value,
751                                                                 self.scan_sat.polarization.value,
752                                                                 fec,
753                                                                 self.scan_sat.inversion.value,
754                                                                 orbpos,
755                                                                 self.scan_sat.system.value,
756                                                                 self.scan_sat.modulation.value,
757                                                                 self.scan_sat.rolloff.value,
758                                                                 self.scan_sat.pilot.value)
759                                 removeAll = False
760                         elif self.scan_type.value == "single_satellite":
761                                 sat = self.satList[index_to_scan][self.scan_satselection[index_to_scan].index]
762                                 getInitialTransponderList(tlist, sat[0])
763                         elif self.scan_type.value.find("multisat") != -1:
764                                 SatList = nimmanager.getSatListForNim(index_to_scan)
765                                 for x in self.multiscanlist:
766                                         if x[1].value:
767                                                 print "   " + str(x[0])
768                                                 getInitialTransponderList(tlist, x[0])
769
770                 elif nim.isCompatible("DVB-C"):
771                         if self.scan_typecable.value == "single_transponder":
772                                 self.addCabTransponder(tlist, self.scan_cab.frequency.value,
773                                                                                           self.scan_cab.symbolrate.value,
774                                                                                           self.scan_cab.modulation.value,
775                                                                                           self.scan_cab.fec.value,
776                                                                                           self.scan_cab.inversion.value)
777                                 removeAll = False
778                         elif self.scan_typecable.value == "complete":
779                                 if config.Nims[index_to_scan].cable.scan_type.value == "provider":
780                                         getInitialCableTransponderList(tlist, index_to_scan)
781                                 else:
782                                         startScan = False
783
784                 elif nim.isCompatible("DVB-T"):
785                         if self.scan_typeterrestrial.value == "single_transponder":
786                                 self.addTerTransponder(tlist,
787                                                 self.scan_ter.frequency.value * 1000,
788                                                 inversion = self.scan_ter.inversion.value,
789                                                 bandwidth = self.scan_ter.bandwidth.value,
790                                                 fechigh = self.scan_ter.fechigh.value,
791                                                 feclow = self.scan_ter.feclow.value,
792                                                 modulation = self.scan_ter.modulation.value,
793                                                 transmission = self.scan_ter.transmission.value,
794                                                 guard = self.scan_ter.guard.value,
795                                                 hierarchy = self.scan_ter.hierarchy.value)
796                                 removeAll = False
797                         elif self.scan_typeterrestrial.value == "complete":
798                                 getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(index_to_scan))
799
800                 flags = self.scan_networkScan.value and eComponentScan.scanNetworkSearch or 0
801
802                 tmp = self.scan_clearallservices.value
803                 if tmp == "yes":
804                         flags |= eComponentScan.scanRemoveServices
805                 elif tmp == "yes_hold_feeds":
806                         flags |= eComponentScan.scanRemoveServices
807                         flags |= eComponentScan.scanDontRemoveFeeds
808
809                 if tmp != "no" and not removeAll:
810                         flags |= eComponentScan.scanDontRemoveUnscanned
811
812                 if self.scan_onlyfree.value:
813                         flags |= eComponentScan.scanOnlyFree
814
815                 for x in self["config"].list:
816                         x[1].save()
817
818                 if startScan:
819                         self.startScan(tlist, flags, index_to_scan)
820                 else:
821                         self.flags = flags
822                         self.feid = index_to_scan
823                         self.tlist = []
824                         self.startCableTransponderSearch(self.feid)
825
826         def setCableTransponderSearchResult(self, tlist):
827                 self.tlist = tlist
828
829         def cableTransponderSearchFinished(self):
830                 self.startScan(self.tlist, self.flags, self.feid)
831
832         def startScan(self, tlist, flags, feid):
833                 if len(tlist):
834                         # flags |= eComponentScan.scanSearchBAT
835                         if self.finished_cb:
836                                 self.session.openWithCallback(self.finished_cb, ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
837                         else:
838                                 self.session.open(ServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
839                 else:
840                         if self.finished_cb:
841                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
842                         else:
843                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
844
845         def keyCancel(self):
846                 for x in self["config"].list:
847                         x[1].cancel()
848                 self.close()
849
850 class ScanSimple(ConfigListScreen, Screen, CableTransponderSearchSupport):
851         def getNetworksForNim(self, nim):
852                 if nim.isCompatible("DVB-S"):
853                         networks = nimmanager.getSatListForNim(nim.slot)
854                 elif not nim.empty:
855                         networks = [ nim.type ] # "DVB-C" or "DVB-T". TODO: seperate networks for different C/T tuners, if we want to support that.
856                 else:
857                         # empty tuners provide no networks.
858                         networks = [ ]
859                 return networks
860
861         def __init__(self, session):
862                 Screen.__init__(self, session)
863
864                 self["actions"] = ActionMap(["SetupActions"],
865                 {
866                         "ok": self.keyGo,
867                         "cancel": self.keyCancel,
868                 }, -2)
869
870                 self.list = []
871                 tlist = []
872
873                 known_networks = [ ]
874                 nims_to_scan = [ ]
875                 self.finished_cb = None
876
877                 for nim in nimmanager.nim_slots:
878                         # collect networks provided by this tuner
879
880                         need_scan = False
881                         networks = self.getNetworksForNim(nim)
882                         
883                         print "nim %d provides" % nim.slot, networks
884                         print "known:", known_networks
885
886                         # we only need to scan on the first tuner which provides a network.
887                         # this gives the first tuner for each network priority for scanning.
888                         for x in networks:
889                                 if x not in known_networks:
890                                         need_scan = True
891                                         print x, "not in ", known_networks
892                                         known_networks.append(x)
893                                         
894                         # don't offer to scan nims if nothing is connected
895                         if not nimmanager.somethingConnected(nim.slot):
896                                 need_scan = False                               
897
898                         if need_scan:
899                                 nims_to_scan.append(nim)
900
901                 # we save the config elements to use them on keyGo
902                 self.nim_enable = [ ]
903
904                 if len(nims_to_scan):
905                         self.scan_clearallservices = ConfigSelection(default = "yes", choices = [("no", _("no")), ("yes", _("yes")), ("yes_hold_feeds", _("yes (keep feeds)"))])
906                         self.list.append(getConfigListEntry(_("Clear before scan"), self.scan_clearallservices))
907
908                         for nim in nims_to_scan:
909                                 nimconfig = ConfigYesNo(default = True)
910                                 nimconfig.nim_index = nim.slot
911                                 self.nim_enable.append(nimconfig)
912                                 self.list.append(getConfigListEntry(_("Scan ") + nim.slot_name + " (" + nim.friendly_type + ")", nimconfig))
913
914                 ConfigListScreen.__init__(self, self.list)
915                 self["header"] = Label(_("Automatic Scan"))
916                 self["footer"] = Label(_("Press OK to scan"))
917
918         def runAsync(self, finished_cb):
919                 self.finished_cb = finished_cb
920                 self.keyGo()
921
922         def keyGo(self):
923                 self.scanList = []
924                 self.known_networks = set()
925                 self.nim_iter=0
926                 self.buildTransponderList()
927
928         def buildTransponderList(self): # this method is called multiple times because of asynchronous stuff
929                 APPEND_NOW = 0
930                 SEARCH_CABLE_TRANSPONDERS = 1
931                 action = APPEND_NOW
932
933                 n = self.nim_iter < len(self.nim_enable) and self.nim_enable[self.nim_iter] or None
934                 self.nim_iter += 1
935                 if n:
936                         if n.value: # check if nim is enabled
937                                 flags = 0
938                                 nim = nimmanager.nim_slots[n.nim_index]
939                                 networks = set(self.getNetworksForNim(nim))
940
941                                 # don't scan anything twice
942                                 networks.discard(self.known_networks)
943
944                                 tlist = [ ]
945                                 if nim.isCompatible("DVB-S"):
946                                         # get initial transponders for each satellite to be scanned
947                                         for sat in networks:
948                                                 getInitialTransponderList(tlist, sat[0])
949                                 elif nim.isCompatible("DVB-C"):
950                                         if config.Nims[nim.slot].cable.scan_type.value == "provider":
951                                                 getInitialCableTransponderList(tlist, nim.slot)
952                                         else:
953                                                 action = SEARCH_CABLE_TRANSPONDERS
954                                 elif nim.isCompatible("DVB-T"):
955                                         getInitialTerrestrialTransponderList(tlist, nimmanager.getTerrestrialDescription(nim.slot))
956                                 else:
957                                         assert False
958
959                                 flags |= eComponentScan.scanNetworkSearch #FIXMEEE.. use flags from cables / satellites / terrestrial.xml
960                                 tmp = self.scan_clearallservices.value
961                                 if tmp == "yes":
962                                         flags |= eComponentScan.scanRemoveServices
963                                 elif tmp == "yes_hold_feeds":
964                                         flags |= eComponentScan.scanRemoveServices
965                                         flags |= eComponentScan.scanDontRemoveFeeds
966
967                                 if action == APPEND_NOW:
968                                         self.scanList.append({"transponders": tlist, "feid": nim.slot, "flags": flags})
969                                 elif action == SEARCH_CABLE_TRANSPONDERS:
970                                         self.flags = flags
971                                         self.feid = nim.slot
972                                         self.startCableTransponderSearch(nim.slot)
973                                         return
974                                 else:
975                                         assert False
976
977                         self.buildTransponderList() # recursive call of this function !!!
978                         return
979                 # when we are here, then the recursion is finished and all enabled nims are checked
980                 # so we now start the real transponder scan
981                 self.startScan(self.scanList)
982
983         def startScan(self, scanList):
984                 if len(scanList):
985                         if self.finished_cb:
986                                 self.session.openWithCallback(self.finished_cb, ServiceScan, scanList = scanList)
987                         else:
988                                 self.session.open(ServiceScan, scanList = scanList)
989                 else:
990                         if self.finished_cb:
991                                 self.session.openWithCallback(self.finished_cb, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
992                         else:
993                                 self.session.open(MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
994
995         def setCableTransponderSearchResult(self, tlist):
996                 self.scanList.append({"transponders": tlist, "feid": self.feid, "flags": self.flags})
997
998         def cableTransponderSearchFinished(self):
999                 self.buildTransponderList()
1000
1001         def keyCancel(self):
1002                 self.close()
1003
1004         def Satexists(self, tlist, pos):
1005                 for x in tlist:
1006                         if x == pos:
1007                                 return 1
1008                 return 0
1009