fixes bug #380
[enigma2.git] / lib / python / Screens / Satconfig.py
1 from enigma import eDVBDB
2 from Screen import Screen
3 from Components.SystemInfo import SystemInfo
4 from Components.ActionMap import ActionMap
5 from Components.ConfigList import ConfigListScreen
6 from Components.MenuList import MenuList
7 from Components.NimManager import nimmanager
8 from Components.config import getConfigListEntry, config, ConfigNothing, ConfigSelection, updateConfigElement,\
9         ConfigSatlist
10 from Components.Sources.List import List
11 from Screens.MessageBox import MessageBox
12 from Screens.ChoiceBox import ChoiceBox
13 from Screens.ServiceStopScreen import ServiceStopScreen
14
15 from time import mktime, localtime
16 from datetime import datetime
17
18 class NimSetup(Screen, ConfigListScreen, ServiceStopScreen):
19         def createSimpleSetup(self, list, mode):
20                 nim = self.nimConfig
21                 if mode == "single":
22                         list.append(getConfigListEntry(_("Satellite"), nim.diseqcA))
23                         list.append(getConfigListEntry(_("Send DiSEqC"), nim.simpleSingleSendDiSEqC))
24                 else:
25                         list.append(getConfigListEntry(_("Port A"), nim.diseqcA))
26
27                 if mode in ("toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
28                         list.append(getConfigListEntry(_("Port B"), nim.diseqcB))
29                         if mode == "diseqc_a_b_c_d":
30                                 list.append(getConfigListEntry(_("Port C"), nim.diseqcC))
31                                 list.append(getConfigListEntry(_("Port D"), nim.diseqcD))
32                         if mode != "toneburst_a_b":
33                                 list.append(getConfigListEntry(_("Set Voltage and 22KHz"), nim.simpleDiSEqCSetVoltageTone))
34                                 list.append(getConfigListEntry(_("Send DiSEqC only on satellite change"), nim.simpleDiSEqCOnlyOnSatChange))
35
36         def createPositionerSetup(self, list):
37                 nim = self.nimConfig
38                 list.append(getConfigListEntry(_("Longitude"), nim.longitude))
39                 list.append(getConfigListEntry(" ", nim.longitudeOrientation))
40                 list.append(getConfigListEntry(_("Latitude"), nim.latitude))
41                 list.append(getConfigListEntry(" ", nim.latitudeOrientation))
42                 if SystemInfo["CanMeasureFrontendInputPower"]:
43                         self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), nim.powerMeasurement)
44                         list.append(self.advancedPowerMeasurement)
45                         if nim.powerMeasurement.value:
46                                 list.append(getConfigListEntry(_("Power threshold in mA"), nim.powerThreshold))
47                                 self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), nim.turningSpeed)
48                                 list.append(self.turningSpeed)
49                                 if nim.turningSpeed.value == "fast epoch":
50                                         self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), nim.fastTurningBegin)
51                                         self.turnFastEpochEnd = getConfigListEntry(_("End time"), nim.fastTurningEnd)
52                                         list.append(self.turnFastEpochBegin)
53                                         list.append(self.turnFastEpochEnd)
54                 else:
55                         if nim.powerMeasurement.value:
56                                 nim.powerMeasurement.value = False
57                                 nim.powerMeasurement.save()
58                 
59         def createConfigMode(self):
60                 if self.nim.isCompatible("DVB-S"):
61                         choices = { "nothing": _("nothing connected"),
62                                                 "simple": _("simple"),
63                                                 "advanced": _("advanced")}
64                         #if len(nimmanager.getNimListOfType(nimmanager.getNimType(self.slotid), exception = x)) > 0:
65                         #       choices["equal"] = _("equal to")
66                         #       choices["satposdepends"] = _("second cable of motorized LNB")
67                         if len(nimmanager.canEqualTo(self.slotid)) > 0:
68                                 choices["equal"] = _("equal to")
69                         if len(nimmanager.canDependOn(self.slotid)) > 0:
70                                 choices["satposdepends"] = _("second cable of motorized LNB")
71                         if len(nimmanager.canConnectTo(self.slotid)) > 0:
72                                 choices["loopthrough"] = _("loopthrough to")
73                         self.nimConfig.configMode.setChoices(choices, default = "nothing")
74
75         def createSetup(self):
76                 print "Creating setup"
77                 self.list = [ ]
78
79                 self.configMode = None
80                 self.diseqcModeEntry = None
81                 self.advancedSatsEntry = None
82                 self.advancedLnbsEntry = None
83                 self.advancedDiseqcMode = None
84                 self.advancedUsalsEntry = None
85                 self.advancedLof = None
86                 self.advancedPowerMeasurement = None
87                 self.turningSpeed = None
88                 self.turnFastEpochBegin = None
89                 self.turnFastEpochEnd = None
90                 self.uncommittedDiseqcCommand = None
91                 self.cableScanType = None
92                 self.have_advanced = False
93                 self.advancedUnicable = None
94                 self.advancedType = None
95                 self.advancedManufacturer = None
96                 self.advancedSCR = None
97
98                 if self.nim.isCompatible("DVB-S"):
99                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
100                         self.list.append(self.configMode)
101
102                         if self.nimConfig.configMode.value == "simple":                 #simple setup
103                                 self.diseqcModeEntry = getConfigListEntry(_("Mode"), self.nimConfig.diseqcMode)
104                                 self.list.append(self.diseqcModeEntry)
105                                 if self.nimConfig.diseqcMode.value in ("single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
106                                         self.createSimpleSetup(self.list, self.nimConfig.diseqcMode.value)
107                                 if self.nimConfig.diseqcMode.value == "positioner":
108                                         self.createPositionerSetup(self.list)
109                         elif self.nimConfig.configMode.value == "equal":
110                                 choices = []
111                                 nimlist = nimmanager.canEqualTo(self.nim.slot)
112                                 for id in nimlist:
113                                         #choices.append((str(id), str(chr(65 + id))))
114                                         choices.append((str(id), nimmanager.getNimDescription(id)))
115                                 self.nimConfig.connectedTo.setChoices(choices)
116                                 #self.nimConfig.connectedTo = updateConfigElement(self.nimConfig.connectedTo, ConfigSelection(choices = choices))
117                                 self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo))
118                         elif self.nimConfig.configMode.value == "satposdepends":
119                                 choices = []
120                                 nimlist = nimmanager.canDependOn(self.nim.slot)
121                                 for id in nimlist:
122                                         #choices.append((str(id), str(chr(65 + id))))
123                                         choices.append((str(id), nimmanager.getNimDescription(id)))
124                                 self.nimConfig.connectedTo.setChoices(choices)
125                                 #self.nimConfig.connectedTo = updateConfigElement(self.nimConfig.connectedTo, ConfigSelection(choices = choices))
126                                 self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo))
127                         elif self.nimConfig.configMode.value == "loopthrough":
128                                 choices = []
129                                 print "connectable to:", nimmanager.canConnectTo(self.slotid)
130                                 connectable = nimmanager.canConnectTo(self.slotid)
131                                 for id in connectable:
132                                         choices.append((str(id), nimmanager.getNimDescription(id)))
133                                 self.nimConfig.connectedTo.setChoices(choices)
134                                 #self.nimConfig.connectedTo = updateConfigElement(self.nimConfig.connectedTo, ConfigSelection(choices = choices))
135                                 self.list.append(getConfigListEntry(_("Connected to"), self.nimConfig.connectedTo))
136                         elif self.nimConfig.configMode.value == "nothing":
137                                 pass
138                         elif self.nimConfig.configMode.value == "advanced": # advanced
139                                 # SATs
140                                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
141                                 self.list.append(self.advancedSatsEntry)
142                                 cur_orb_pos = self.nimConfig.advanced.sats.orbital_position
143                                 satlist = self.nimConfig.advanced.sat.keys()
144                                 if cur_orb_pos is not None:
145                                         if cur_orb_pos not in satlist:
146                                                 cur_orb_pos = satlist[0]
147                                         currSat = self.nimConfig.advanced.sat[cur_orb_pos]
148                                         self.fillListWithAdvancedSatEntrys(currSat)
149                                 self.have_advanced = True
150                         if self.nim.description == "Alps BSBE2" and config.usage.setup_level.index >= 2: # expert
151                                 self.list.append(getConfigListEntry(_("Tone Amplitude"), self.nimConfig.toneAmplitude))
152                 elif self.nim.isCompatible("DVB-C"):
153                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
154                         self.list.append(self.configMode)
155                         if self.nimConfig.configMode.value == "enabled":
156                                 self.cableScanType=getConfigListEntry(_("Used service scan type"), self.nimConfig.cable.scan_type)
157                                 self.list.append(self.cableScanType)
158                                 if self.nimConfig.cable.scan_type.value == "provider":
159                                         self.list.append(getConfigListEntry(_("Provider to scan"), self.nimConfig.cable.scan_provider))
160                                 else:
161                                         if self.nimConfig.cable.scan_type.value == "bands":
162                                                 self.list.append(getConfigListEntry(_("Scan band EU VHF I"), self.nimConfig.cable.scan_band_EU_VHF_I))
163                                                 self.list.append(getConfigListEntry(_("Scan band EU MID"), self.nimConfig.cable.scan_band_EU_MID))
164                                                 self.list.append(getConfigListEntry(_("Scan band EU VHF III"), self.nimConfig.cable.scan_band_EU_VHF_III))
165                                                 self.list.append(getConfigListEntry(_("Scan band EU UHF IV"), self.nimConfig.cable.scan_band_EU_UHF_IV))
166                                                 self.list.append(getConfigListEntry(_("Scan band EU UHF V"), self.nimConfig.cable.scan_band_EU_UHF_V))
167                                                 self.list.append(getConfigListEntry(_("Scan band EU SUPER"), self.nimConfig.cable.scan_band_EU_SUPER))
168                                                 self.list.append(getConfigListEntry(_("Scan band EU HYPER"), self.nimConfig.cable.scan_band_EU_HYPER))
169                                                 self.list.append(getConfigListEntry(_("Scan band US LOW"), self.nimConfig.cable.scan_band_US_LOW))
170                                                 self.list.append(getConfigListEntry(_("Scan band US MID"), self.nimConfig.cable.scan_band_US_MID))
171                                                 self.list.append(getConfigListEntry(_("Scan band US HIGH"), self.nimConfig.cable.scan_band_US_HIGH))
172                                                 self.list.append(getConfigListEntry(_("Scan band US SUPER"), self.nimConfig.cable.scan_band_US_SUPER))
173                                                 self.list.append(getConfigListEntry(_("Scan band US HYPER"), self.nimConfig.cable.scan_band_US_HYPER))
174                                         elif self.nimConfig.cable.scan_type.value == "steps":
175                                                 self.list.append(getConfigListEntry(_("Frequency scan step size(khz)"), self.nimConfig.cable.scan_frequency_steps))
176                                         self.list.append(getConfigListEntry(_("Scan QAM16"), self.nimConfig.cable.scan_mod_qam16))
177                                         self.list.append(getConfigListEntry(_("Scan QAM32"), self.nimConfig.cable.scan_mod_qam32))
178                                         self.list.append(getConfigListEntry(_("Scan QAM64"), self.nimConfig.cable.scan_mod_qam64))
179                                         self.list.append(getConfigListEntry(_("Scan QAM128"), self.nimConfig.cable.scan_mod_qam128))
180                                         self.list.append(getConfigListEntry(_("Scan QAM256"), self.nimConfig.cable.scan_mod_qam256))
181                                         self.list.append(getConfigListEntry(_("Scan SR6900"), self.nimConfig.cable.scan_sr_6900))
182                                         self.list.append(getConfigListEntry(_("Scan SR6875"), self.nimConfig.cable.scan_sr_6875))
183                                         self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext1))
184                                         self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext2))
185                         self.have_advanced = False
186                 elif self.nim.isCompatible("DVB-T"):
187                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
188                         self.list.append(self.configMode)
189                         self.have_advanced = False
190                         if self.nimConfig.configMode.value == "enabled":
191                                 self.list.append(getConfigListEntry(_("Terrestrial provider"), self.nimConfig.terrestrial))
192                                 self.list.append(getConfigListEntry(_("Enable 5V for active antenna"), self.nimConfig.terrestrial_5V))
193                 else:
194                         self.have_advanced = False
195                 self["config"].list = self.list
196                 self["config"].l.setList(self.list)
197
198         def newConfig(self):
199                 checkList = (self.configMode, self.diseqcModeEntry, self.advancedSatsEntry, \
200                         self.advancedLnbsEntry, self.advancedDiseqcMode, self.advancedUsalsEntry, \
201                         self.advancedLof, self.advancedPowerMeasurement, self.turningSpeed, \
202                         self.advancedType, self.advancedSCR, self.advancedManufacturer, self.advancedUnicable, \
203                         self.uncommittedDiseqcCommand, self.cableScanType)
204                 for x in checkList:
205                         if self["config"].getCurrent() == x:
206                                 self.createSetup()
207
208         def run(self):
209                 if self.have_advanced and self.nim.config_mode == "advanced":
210                         self.fillAdvancedList()
211                 for x in self.list:
212                         if x in (self.turnFastEpochBegin, self.turnFastEpochEnd):
213                                 # workaround for storing only hour*3600+min*60 value in configfile
214                                 # not really needed.. just for cosmetics..
215                                 tm = localtime(x[1].value)
216                                 dt = datetime(1970, 1, 1, tm.tm_hour, tm.tm_min)
217                                 x[1].value = int(mktime(dt.timetuple()))
218                         x[1].save()
219                 nimmanager.sec.update()
220                 self.saveAll()
221
222         def fillListWithAdvancedSatEntrys(self, Sat):
223                 lnbnum = int(Sat.lnb.value)
224                 currLnb = self.nimConfig.advanced.lnb[lnbnum]
225                 
226                 if isinstance(currLnb, ConfigNothing):
227                         currLnb = None
228
229                 # LNBs
230                 self.advancedLnbsEntry = getConfigListEntry(_("LNB"), Sat.lnb)
231                 self.list.append(self.advancedLnbsEntry)
232
233                 if currLnb:
234                         self.list.append(getConfigListEntry(_("Priority"), currLnb.prio))
235                         self.advancedLof = getConfigListEntry(_("LOF"), currLnb.lof)
236                         self.list.append(self.advancedLof)
237                         if currLnb.lof.value == "user_defined":
238                                 self.list.append(getConfigListEntry(_("LOF/L"), currLnb.lofl))
239                                 self.list.append(getConfigListEntry(_("LOF/H"), currLnb.lofh))
240                                 self.list.append(getConfigListEntry(_("Threshold"), currLnb.threshold))
241 #                       self.list.append(getConfigListEntry(_("12V Output"), currLnb.output_12v))
242                         
243                         if currLnb.lof.value == "unicable":
244                                 self.advancedUnicable = getConfigListEntry("Unicable "+_("Configuration Mode"), currLnb.unicable)
245                                 self.list.append(self.advancedUnicable)
246                                 if currLnb.unicable.value == "unicable_user":
247                                         self.advancedSCR = getConfigListEntry(_("Channel"), currLnb.satcruser)
248                                         self.list.append(self.advancedSCR)
249                                         self.list.append(getConfigListEntry(_("Frequency"), currLnb.satcrvcouser[currLnb.satcruser.index]))
250                                         self.list.append(getConfigListEntry(_("LOF/L"), currLnb.lofl))
251                                         self.list.append(getConfigListEntry(_("LOF/H"), currLnb.lofh))
252                                         self.list.append(getConfigListEntry(_("Threshold"), currLnb.threshold))
253                                 elif currLnb.unicable.value == "unicable_matrix":
254                                         manufacturer_name = currLnb.unicableMatrixManufacturer.value
255                                         manufacturer = currLnb.unicableMatrix[manufacturer_name]
256                                         product_name = manufacturer.product.value
257                                         self.advancedManufacturer = getConfigListEntry(_("Manufacturer"), currLnb.unicableMatrixManufacturer)
258                                         self.advancedType = getConfigListEntry(_("Type"), manufacturer.product)
259                                         self.advancedSCR = getConfigListEntry(_("Channel"), manufacturer.scr[product_name])
260                                         self.list.append(self.advancedManufacturer)
261                                         self.list.append(self.advancedType)
262                                         self.list.append(self.advancedSCR)
263                                         self.list.append(getConfigListEntry(_("Frequency"), manufacturer.vco[product_name][manufacturer.scr[product_name].index])) 
264                                 elif currLnb.unicable.value == "unicable_lnb":
265                                         manufacturer_name = currLnb.unicableLnbManufacturer.value
266                                         manufacturer = currLnb.unicableLnb[manufacturer_name]
267                                         product_name = manufacturer.product.value
268                                         self.advancedManufacturer = getConfigListEntry(_("Manufacturer"), currLnb.unicableLnbManufacturer)
269                                         self.advancedType = getConfigListEntry(_("Type"), manufacturer.product)
270                                         self.advancedSCR = getConfigListEntry(_("Channel"), manufacturer.scr[product_name])
271                                         self.list.append(self.advancedManufacturer)
272                                         self.list.append(self.advancedType)
273                                         self.list.append(self.advancedSCR)
274                                         self.list.append(getConfigListEntry(_("Frequency"), manufacturer.vco[product_name][manufacturer.scr[product_name].index])) 
275                         else:   #kein Unicable
276                                 self.list.append(getConfigListEntry(_("Voltage mode"), Sat.voltage))
277                                 self.list.append(getConfigListEntry(_("Increased voltage"), currLnb.increased_voltage))
278                                 self.list.append(getConfigListEntry(_("Tone mode"), Sat.tonemode))
279
280                         if lnbnum < 33:
281                                 self.advancedDiseqcMode = getConfigListEntry(_("DiSEqC mode"), currLnb.diseqcMode)
282                                 self.list.append(self.advancedDiseqcMode)
283                         if currLnb.diseqcMode.value != "none":
284                                 self.list.append(getConfigListEntry(_("Toneburst"), currLnb.toneburst))
285                                 self.list.append(getConfigListEntry(_("Committed DiSEqC command"), currLnb.commitedDiseqcCommand))
286                                 self.list.append(getConfigListEntry(_("Fast DiSEqC"), currLnb.fastDiseqc))
287                                 self.list.append(getConfigListEntry(_("Sequence repeat"), currLnb.sequenceRepeat))
288                                 if currLnb.diseqcMode.value == "1_0":
289                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder1_0))
290                                 else:
291                                         if currLnb.uncommittedDiseqcCommand.index:
292                                                 if currLnb.commandOrder.value == "ct":
293                                                         currLnb.commandOrder.value = "cut"
294                                                 elif currLnb.commandOrder.value == "tc":
295                                                         currLnb.commandOrder.value = "tcu"
296                                         else:
297                                                 if currLnb.commandOrder.index & 1:
298                                                         currLnb.commandOrder.value = "tc"
299                                                 else:
300                                                         currLnb.commandOrder.value = "ct"
301                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder))
302                                         self.uncommittedDiseqcCommand = getConfigListEntry(_("Uncommitted DiSEqC command"), currLnb.uncommittedDiseqcCommand)
303                                         self.list.append(self.uncommittedDiseqcCommand)
304                                         self.list.append(getConfigListEntry(_("DiSEqC repeats"), currLnb.diseqcRepeats))
305                                 if currLnb.diseqcMode.value == "1_2":
306                                         self.list.append(getConfigListEntry(_("Longitude"), currLnb.longitude))
307                                         self.list.append(getConfigListEntry(" ", currLnb.longitudeOrientation))
308                                         self.list.append(getConfigListEntry(_("Latitude"), currLnb.latitude))
309                                         self.list.append(getConfigListEntry(" ", currLnb.latitudeOrientation))
310                                         if SystemInfo["CanMeasureFrontendInputPower"]:
311                                                 self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), currLnb.powerMeasurement)
312                                                 self.list.append(self.advancedPowerMeasurement)
313                                                 if currLnb.powerMeasurement.value:
314                                                         self.list.append(getConfigListEntry(_("Power threshold in mA"), currLnb.powerThreshold))
315                                                         self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), currLnb.turningSpeed)
316                                                         self.list.append(self.turningSpeed)
317                                                         if currLnb.turningSpeed.value == "fast epoch":
318                                                                 self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), currLnb.fastTurningBegin)
319                                                                 self.turnFastEpochEnd = getConfigListEntry(_("End time"), currLnb.fastTurningEnd)
320                                                                 self.list.append(self.turnFastEpochBegin)
321                                                                 self.list.append(self.turnFastEpochEnd)
322                                         else:
323                                                 if currLnb.powerMeasurement.value:
324                                                         currLnb.powerMeasurement.value = False
325                                                         currLnb.powerMeasurement.save()
326                                         self.advancedUsalsEntry = getConfigListEntry(_("Use usals for this sat"), Sat.usals)
327                                         self.list.append(self.advancedUsalsEntry)
328                                         if not Sat.usals.value:
329                                                 self.list.append(getConfigListEntry(_("Stored position"), Sat.rotorposition))
330
331         
332
333         def fillAdvancedList(self):
334                 self.list = [ ]
335                 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
336                 self.list.append(self.configMode)
337                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
338                 self.list.append(self.advancedSatsEntry)
339                 for x in self.nimConfig.advanced.sat.keys():
340                         Sat = self.nimConfig.advanced.sat[x]
341                         self.fillListWithAdvancedSatEntrys(Sat)
342                 self["config"].list = self.list
343
344         def keySave(self):
345                 old_configured_sats = nimmanager.getConfiguredSats()
346                 self.run()
347                 new_configured_sats = nimmanager.getConfiguredSats()
348                 self.unconfed_sats = old_configured_sats - new_configured_sats
349                 self.satpos_to_remove = None
350                 self.restoreService(_("Zap back to service before tuner setup?"))
351                 self.deleteConfirmed((None, "no"))
352
353         def deleteConfirmed(self, confirmed):
354                 if confirmed[1] == "yes" or confirmed[1] == "yestoall":
355                         eDVBDB.getInstance().removeServices(-1, -1, -1, self.satpos_to_remove)
356
357                 if self.satpos_to_remove is not None:
358                         self.unconfed_sats.remove(self.satpos_to_remove)
359
360                 self.satpos_to_remove = None
361                 for orbpos in self.unconfed_sats:
362                         self.satpos_to_remove = orbpos
363                         orbpos = self.satpos_to_remove
364                         try:
365                                 # why we need this cast?
366                                 sat_name = str(nimmanager.getSatDescription(orbpos))
367                         except:
368                                 if orbpos > 1800: # west
369                                         orbpos = 3600 - orbpos
370                                         h = _("W")
371                                 else:
372                                         h = _("E")
373                                 sat_name = ("%d.%d" + h) % (orbpos / 10, orbpos % 10)
374                                 
375                         if confirmed[1] == "yes" or confirmed[1] == "no":
376                                 self.session.openWithCallback(self.deleteConfirmed, ChoiceBox, _("Delete no more configured satellite\n%s?") %(sat_name), [(_("Yes"), "yes"), (_("No"), "no"), (_("Yes to all"), "yestoall"), (_("No to all"), "notoall")])
377                         if confirmed[1] == "yestoall" or confirmed[1] == "notoall":
378                                 self.deleteConfirmed(confirmed)
379                         break
380                 
381         def __init__(self, session, slotid):
382                 Screen.__init__(self, session)
383                 self.list = [ ]
384                 
385                 ServiceStopScreen.__init__(self)
386                 self.stopService()
387
388                 ConfigListScreen.__init__(self, self.list)
389
390                 self["actions"] = ActionMap(["SetupActions", "SatlistShortcutAction"],
391                 {
392                         "ok": self.keySave,
393                         "cancel": self.keyCancel,
394                         "nothingconnected": self.nothingConnectedShortcut
395                 }, -2)
396
397                 self.slotid = slotid
398                 self.nim = nimmanager.nim_slots[slotid]
399                 self.nimConfig = self.nim.config
400                 self.createConfigMode()
401                 self.createSetup()
402
403         def keyLeft(self):
404                 ConfigListScreen.keyLeft(self)
405                 self.newConfig()
406
407         def keyRight(self):
408                 ConfigListScreen.keyRight(self)
409                 self.newConfig()
410                 
411         def keyCancel(self):
412                 if self["config"].isChanged():
413                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
414                 else:
415                         self.restoreService(_("Zap back to service before tuner setup?"))
416                 
417         def saveAll(self):
418                 if self.nim.isCompatible("DVB-S"):
419                         # reset connectedTo to all choices to properly store the default value
420                         choices = []
421                         nimlist = nimmanager.getNimListOfType("DVB-S", self.slotid)
422                         for id in nimlist:
423                                 choices.append((str(id), nimmanager.getNimDescription(id)))
424                         self.nimConfig.connectedTo.setChoices(choices)
425                 for x in self["config"].list:
426                         x[1].save()
427                         
428         def cancelConfirm(self, result):
429                 if not result:
430                         return
431
432                 for x in self["config"].list:
433                         x[1].cancel()
434                 # we need to call saveAll to reset the connectedTo choices
435                 self.saveAll()
436                 self.restoreService(_("Zap back to service before tuner setup?"))
437                 
438         def nothingConnectedShortcut(self):
439                 if type(self["config"].getCurrent()[1]) is ConfigSatlist:
440                         self["config"].getCurrent()[1].setValue("3601")
441                         self["config"].invalidateCurrent()
442                         
443 class NimSelection(Screen):
444         def __init__(self, session):
445                 Screen.__init__(self, session)
446                 
447                 self.list = [None] * nimmanager.getSlotCount()
448                 self["nimlist"] = List(self.list)
449                 self.updateList()
450                 
451                 self.setResultClass()
452
453                 self["actions"] = ActionMap(["OkCancelActions"],
454                 {
455                         "ok": self.okbuttonClick ,
456                         "cancel": self.close
457                 }, -2)
458                 
459         def setResultClass(self):
460                 self.resultclass = NimSetup
461
462         def okbuttonClick(self):
463                 nim = self["nimlist"].getCurrent()
464                 nim = nim and nim[3]
465                 if nim is not None and not nim.empty:
466                         self.session.openWithCallback(self.updateList, self.resultclass, nim.slot)
467                         
468         def showNim(self, nim):
469                 return True
470
471         def updateList(self):
472                 self.list = [ ]
473                 for x in nimmanager.nim_slots:
474                         slotid = x.slot
475                         nimConfig = nimmanager.getNimConfig(x.slot)
476                         text = nimConfig.configMode.value
477                         if self.showNim(x):
478                                 if x.isCompatible("DVB-S"):
479                                         if nimConfig.configMode.value in ("loopthrough", "equal", "satposdepends"):
480                                                 text = { "loopthrough": _("loopthrough to"),
481                                                                  "equal": _("equal to"),
482                                                                  "satposdepends": _("second cable of motorized LNB") } [nimConfig.configMode.value]
483                                                 text += " " + _("Tuner") + " " + ["A", "B", "C", "D"][int(nimConfig.connectedTo.value)]
484                                         elif nimConfig.configMode.value == "nothing":
485                                                 text = _("nothing connected")
486                                         elif nimConfig.configMode.value == "simple":
487                                                 if nimConfig.diseqcMode.value in ("single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
488                                                         text = _("Sats") + ": " 
489                                                         if nimConfig.diseqcA.orbital_position != 3601:
490                                                                 text += nimmanager.getSatName(int(nimConfig.diseqcA.value))
491                                                         if nimConfig.diseqcMode.value in ("toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
492                                                                 if nimConfig.diseqcB.orbital_position != 3601:
493                                                                         text += "," + nimmanager.getSatName(int(nimConfig.diseqcB.value))
494                                                         if nimConfig.diseqcMode.value == "diseqc_a_b_c_d":
495                                                                 if nimConfig.diseqcC.orbital_position != 3601:
496                                                                         text += "," + nimmanager.getSatName(int(nimConfig.diseqcC.value))
497                                                                 if nimConfig.diseqcD.orbital_position != 3601:
498                                                                         text += "," + nimmanager.getSatName(int(nimConfig.diseqcD.value))
499                                                 elif nimConfig.diseqcMode.value == "positioner":
500                                                         text = _("Positioner") + ":"
501                                                         if nimConfig.positionerMode.value == "usals":
502                                                                 text += _("USALS")
503                                                         elif nimConfig.positionerMode.value == "manual":
504                                                                 text += _("manual")
505                                                 else:   
506                                                         text = _("simple")
507                                         elif nimConfig.configMode.value == "advanced":
508                                                 text = _("advanced")
509                                 elif x.isCompatible("DVB-T") or x.isCompatible("DVB-C"):
510                                         if nimConfig.configMode.value == "nothing":
511                                                 text = _("nothing connected")
512                                         elif nimConfig.configMode.value == "enabled":
513                                                 text = _("enabled")
514                                         
515                                 self.list.append((slotid, x.friendly_full_description, text, x))
516                 self["nimlist"].setList(self.list)
517                 self["nimlist"].updateList(self.list)