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