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