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