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