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