fixes bug #445
[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.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                         nimmanager.enumerateNIMs()
212                         from Components.NimManager import InitNimManager
213                         InitNimManager(nimmanager)
214                         self.nim = nimmanager.nim_slots[self.slotid]
215                         self.nimConfig = self.nim.config
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.restoreService(_("Zap back to service before tuner setup?"))
364                 self.deleteConfirmed((None, "no"))
365
366         def deleteConfirmed(self, confirmed):
367                 if confirmed[1] == "yes" or confirmed[1] == "yestoall":
368                         eDVBDB.getInstance().removeServices(-1, -1, -1, self.satpos_to_remove)
369
370                 if self.satpos_to_remove is not None:
371                         self.unconfed_sats.remove(self.satpos_to_remove)
372
373                 self.satpos_to_remove = None
374                 for orbpos in self.unconfed_sats:
375                         self.satpos_to_remove = orbpos
376                         orbpos = self.satpos_to_remove
377                         try:
378                                 # why we need this cast?
379                                 sat_name = str(nimmanager.getSatDescription(orbpos))
380                         except:
381                                 if orbpos > 1800: # west
382                                         orbpos = 3600 - orbpos
383                                         h = _("W")
384                                 else:
385                                         h = _("E")
386                                 sat_name = ("%d.%d" + h) % (orbpos / 10, orbpos % 10)
387                                 
388                         if confirmed[1] == "yes" or confirmed[1] == "no":
389                                 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")])
390                         if confirmed[1] == "yestoall" or confirmed[1] == "notoall":
391                                 self.deleteConfirmed(confirmed)
392                         break
393                 
394         def __init__(self, session, slotid):
395                 Screen.__init__(self, session)
396                 self.list = [ ]
397                 
398                 ServiceStopScreen.__init__(self)
399                 self.stopService()
400
401                 ConfigListScreen.__init__(self, self.list)
402
403                 self["actions"] = ActionMap(["SetupActions", "SatlistShortcutAction"],
404                 {
405                         "ok": self.keySave,
406                         "cancel": self.keyCancel,
407                         "nothingconnected": self.nothingConnectedShortcut
408                 }, -2)
409
410                 self.slotid = slotid
411                 self.nim = nimmanager.nim_slots[slotid]
412                 self.nimConfig = self.nim.config
413                 self.createConfigMode()
414                 self.createSetup()
415
416         def keyLeft(self):
417                 ConfigListScreen.keyLeft(self)
418                 self.newConfig()
419
420         def keyRight(self):
421                 ConfigListScreen.keyRight(self)
422                 self.newConfig()
423                 
424         def keyCancel(self):
425                 if self["config"].isChanged():
426                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
427                 else:
428                         self.restoreService(_("Zap back to service before tuner setup?"))
429                 
430         def saveAll(self):
431                 if self.nim.isCompatible("DVB-S"):
432                         # reset connectedTo to all choices to properly store the default value
433                         choices = []
434                         nimlist = nimmanager.getNimListOfType("DVB-S", self.slotid)
435                         for id in nimlist:
436                                 choices.append((str(id), nimmanager.getNimDescription(id)))
437                         self.nimConfig.connectedTo.setChoices(choices)
438                 for x in self["config"].list:
439                         x[1].save()
440                         
441         def cancelConfirm(self, result):
442                 if not result:
443                         return
444
445                 for x in self["config"].list:
446                         x[1].cancel()
447                 # we need to call saveAll to reset the connectedTo choices
448                 self.saveAll()
449                 self.restoreService(_("Zap back to service before tuner setup?"))
450                 
451         def nothingConnectedShortcut(self):
452                 if type(self["config"].getCurrent()[1]) is ConfigSatlist:
453                         self["config"].getCurrent()[1].setValue("3601")
454                         self["config"].invalidateCurrent()
455                         
456 class NimSelection(Screen):
457         def __init__(self, session):
458                 Screen.__init__(self, session)
459                 
460                 self.list = [None] * nimmanager.getSlotCount()
461                 self["nimlist"] = List(self.list)
462                 self.updateList()
463                 
464                 self.setResultClass()
465
466                 self["actions"] = ActionMap(["OkCancelActions"],
467                 {
468                         "ok": self.okbuttonClick ,
469                         "cancel": self.close
470                 }, -2)
471                 
472         def setResultClass(self):
473                 self.resultclass = NimSetup
474
475         def okbuttonClick(self):
476                 nim = self["nimlist"].getCurrent()
477                 nim = nim and nim[3]
478                 if nim is not None and not nim.empty:
479                         self.session.openWithCallback(self.updateList, self.resultclass, nim.slot)
480                         
481         def showNim(self, nim):
482                 return True
483
484         def updateList(self):
485                 self.list = [ ]
486                 for x in nimmanager.nim_slots:
487                         slotid = x.slot
488                         nimConfig = nimmanager.getNimConfig(x.slot)
489                         text = nimConfig.configMode.value
490                         if self.showNim(x):
491                                 if x.isCompatible("DVB-S"):
492                                         if nimConfig.configMode.value in ("loopthrough", "equal", "satposdepends"):
493                                                 text = { "loopthrough": _("loopthrough to"),
494                                                                  "equal": _("equal to"),
495                                                                  "satposdepends": _("second cable of motorized LNB") } [nimConfig.configMode.value]
496                                                 text += " " + _("Tuner") + " " + ["A", "B", "C", "D"][int(nimConfig.connectedTo.value)]
497                                         elif nimConfig.configMode.value == "nothing":
498                                                 text = _("nothing connected")
499                                         elif nimConfig.configMode.value == "simple":
500                                                 if nimConfig.diseqcMode.value in ("single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
501                                                         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"
502                                                         text += _("Sats") + ": " 
503                                                         satnames = []
504                                                         if nimConfig.diseqcA.orbital_position != 3601:
505                                                                 satnames.append(nimmanager.getSatName(int(nimConfig.diseqcA.value)))
506                                                         if nimConfig.diseqcMode.value in ("toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
507                                                                 if nimConfig.diseqcB.orbital_position != 3601:
508                                                                         satnames.append(nimmanager.getSatName(int(nimConfig.diseqcB.value)))
509                                                         if nimConfig.diseqcMode.value == "diseqc_a_b_c_d":
510                                                                 if nimConfig.diseqcC.orbital_position != 3601:
511                                                                         satnames.append(nimmanager.getSatName(int(nimConfig.diseqcC.value)))
512                                                                 if nimConfig.diseqcD.orbital_position != 3601:
513                                                                         satnames.append(nimmanager.getSatName(int(nimConfig.diseqcD.value)))
514                                                         if len(satnames) <= 2:
515                                                                 text += ", ".join(satnames)
516                                                         elif len(satnames) > 2:
517                                                                 # we need a newline here, since multi content lists don't support automtic line wrapping
518                                                                 text += ", ".join(satnames[:2]) + ",\n"
519                                                                 text += "         " + ", ".join(satnames[2:])
520                                                 elif nimConfig.diseqcMode.value == "positioner":
521                                                         text = _("Positioner") + ":"
522                                                         if nimConfig.positionerMode.value == "usals":
523                                                                 text += _("USALS")
524                                                         elif nimConfig.positionerMode.value == "manual":
525                                                                 text += _("manual")
526                                                 else:   
527                                                         text = _("simple")
528                                         elif nimConfig.configMode.value == "advanced":
529                                                 text = _("advanced")
530                                 elif x.isCompatible("DVB-T") or x.isCompatible("DVB-C"):
531                                         if nimConfig.configMode.value == "nothing":
532                                                 text = _("nothing connected")
533                                         elif nimConfig.configMode.value == "enabled":
534                                                 text = _("enabled")
535                                 if x.isMultiType():
536                                         text = _("Switchable tuner types:") + "(" + ','.join(x.getMultiTypeList().values()) + ")" + "\n" + text
537                                         
538                                 self.list.append((slotid, x.friendly_full_description, text, x))
539                 self["nimlist"].setList(self.list)
540                 self["nimlist"].updateList(self.list)