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