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