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