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