0d10a2c05b172e4b785bbd51eb0dfbacf33f7186
[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.isMultiType():
99                         multiType = self.nimConfig.multiType
100                         self.multiType = getConfigListEntry(_("Tuner type"), multiType)
101                         self.list.append(self.multiType)
102
103                 if self.nim.isCompatible("DVB-S"):
104                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
105                         self.list.append(self.configMode)
106
107                         if self.nimConfig.configMode.value == "simple":                 #simple setup
108                                 self.diseqcModeEntry = getConfigListEntry(_("Mode"), self.nimConfig.diseqcMode)
109                                 self.list.append(self.diseqcModeEntry)
110                                 if self.nimConfig.diseqcMode.value in ("single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
111                                         self.createSimpleSetup(self.list, self.nimConfig.diseqcMode.value)
112                                 if self.nimConfig.diseqcMode.value == "positioner":
113                                         self.createPositionerSetup(self.list)
114                         elif self.nimConfig.configMode.value == "equal":
115                                 choices = []
116                                 nimlist = nimmanager.canEqualTo(self.nim.slot)
117                                 for id in nimlist:
118                                         #choices.append((str(id), str(chr(65 + id))))
119                                         choices.append((str(id), nimmanager.getNimDescription(id)))
120                                 self.nimConfig.connectedTo.setChoices(choices)
121                                 #self.nimConfig.connectedTo = updateConfigElement(self.nimConfig.connectedTo, ConfigSelection(choices = choices))
122                                 self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo))
123                         elif self.nimConfig.configMode.value == "satposdepends":
124                                 choices = []
125                                 nimlist = nimmanager.canDependOn(self.nim.slot)
126                                 for id in nimlist:
127                                         #choices.append((str(id), str(chr(65 + id))))
128                                         choices.append((str(id), nimmanager.getNimDescription(id)))
129                                 self.nimConfig.connectedTo.setChoices(choices)
130                                 #self.nimConfig.connectedTo = updateConfigElement(self.nimConfig.connectedTo, ConfigSelection(choices = choices))
131                                 self.list.append(getConfigListEntry(_("Tuner"), self.nimConfig.connectedTo))
132                         elif self.nimConfig.configMode.value == "loopthrough":
133                                 choices = []
134                                 print "connectable to:", nimmanager.canConnectTo(self.slotid)
135                                 connectable = nimmanager.canConnectTo(self.slotid)
136                                 for id in connectable:
137                                         choices.append((str(id), nimmanager.getNimDescription(id)))
138                                 self.nimConfig.connectedTo.setChoices(choices)
139                                 #self.nimConfig.connectedTo = updateConfigElement(self.nimConfig.connectedTo, ConfigSelection(choices = choices))
140                                 self.list.append(getConfigListEntry(_("Connected to"), self.nimConfig.connectedTo))
141                         elif self.nimConfig.configMode.value == "nothing":
142                                 pass
143                         elif self.nimConfig.configMode.value == "advanced": # advanced
144                                 # SATs
145                                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
146                                 self.list.append(self.advancedSatsEntry)
147                                 cur_orb_pos = self.nimConfig.advanced.sats.orbital_position
148                                 satlist = self.nimConfig.advanced.sat.keys()
149                                 if cur_orb_pos is not None:
150                                         if cur_orb_pos not in satlist:
151                                                 cur_orb_pos = satlist[0]
152                                         currSat = self.nimConfig.advanced.sat[cur_orb_pos]
153                                         self.fillListWithAdvancedSatEntrys(currSat)
154                                 self.have_advanced = True
155                         if self.nim.description == "Alps BSBE2" and config.usage.setup_level.index >= 2: # expert
156                                 self.list.append(getConfigListEntry(_("Tone Amplitude"), self.nimConfig.toneAmplitude))
157                 elif self.nim.isCompatible("DVB-C"):
158                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
159                         self.list.append(self.configMode)
160                         if self.nimConfig.configMode.value == "enabled":
161                                 self.cableScanType=getConfigListEntry(_("Used service scan type"), self.nimConfig.cable.scan_type)
162                                 self.list.append(self.cableScanType)
163                                 if self.nimConfig.cable.scan_type.value == "provider":
164                                         self.list.append(getConfigListEntry(_("Provider to scan"), self.nimConfig.cable.scan_provider))
165                                 else:
166                                         if self.nimConfig.cable.scan_type.value == "bands":
167                                                 self.list.append(getConfigListEntry(_("Scan band EU VHF I"), self.nimConfig.cable.scan_band_EU_VHF_I))
168                                                 self.list.append(getConfigListEntry(_("Scan band EU MID"), self.nimConfig.cable.scan_band_EU_MID))
169                                                 self.list.append(getConfigListEntry(_("Scan band EU VHF III"), self.nimConfig.cable.scan_band_EU_VHF_III))
170                                                 self.list.append(getConfigListEntry(_("Scan band EU UHF IV"), self.nimConfig.cable.scan_band_EU_UHF_IV))
171                                                 self.list.append(getConfigListEntry(_("Scan band EU UHF V"), self.nimConfig.cable.scan_band_EU_UHF_V))
172                                                 self.list.append(getConfigListEntry(_("Scan band EU SUPER"), self.nimConfig.cable.scan_band_EU_SUPER))
173                                                 self.list.append(getConfigListEntry(_("Scan band EU HYPER"), self.nimConfig.cable.scan_band_EU_HYPER))
174                                                 self.list.append(getConfigListEntry(_("Scan band US LOW"), self.nimConfig.cable.scan_band_US_LOW))
175                                                 self.list.append(getConfigListEntry(_("Scan band US MID"), self.nimConfig.cable.scan_band_US_MID))
176                                                 self.list.append(getConfigListEntry(_("Scan band US HIGH"), self.nimConfig.cable.scan_band_US_HIGH))
177                                                 self.list.append(getConfigListEntry(_("Scan band US SUPER"), self.nimConfig.cable.scan_band_US_SUPER))
178                                                 self.list.append(getConfigListEntry(_("Scan band US HYPER"), self.nimConfig.cable.scan_band_US_HYPER))
179                                         elif self.nimConfig.cable.scan_type.value == "steps":
180                                                 self.list.append(getConfigListEntry(_("Frequency scan step size(khz)"), self.nimConfig.cable.scan_frequency_steps))
181                                         self.list.append(getConfigListEntry(_("Scan QAM16"), self.nimConfig.cable.scan_mod_qam16))
182                                         self.list.append(getConfigListEntry(_("Scan QAM32"), self.nimConfig.cable.scan_mod_qam32))
183                                         self.list.append(getConfigListEntry(_("Scan QAM64"), self.nimConfig.cable.scan_mod_qam64))
184                                         self.list.append(getConfigListEntry(_("Scan QAM128"), self.nimConfig.cable.scan_mod_qam128))
185                                         self.list.append(getConfigListEntry(_("Scan QAM256"), self.nimConfig.cable.scan_mod_qam256))
186                                         self.list.append(getConfigListEntry(_("Scan SR6900"), self.nimConfig.cable.scan_sr_6900))
187                                         self.list.append(getConfigListEntry(_("Scan SR6875"), self.nimConfig.cable.scan_sr_6875))
188                                         self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext1))
189                                         self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext2))
190                         self.have_advanced = False
191                 elif self.nim.isCompatible("DVB-T"):
192                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
193                         self.list.append(self.configMode)
194                         self.have_advanced = False
195                         if self.nimConfig.configMode.value == "enabled":
196                                 self.list.append(getConfigListEntry(_("Terrestrial provider"), self.nimConfig.terrestrial))
197                                 self.list.append(getConfigListEntry(_("Enable 5V for active antenna"), self.nimConfig.terrestrial_5V))
198                 else:
199                         self.have_advanced = False
200                 self["config"].list = self.list
201                 self["config"].l.setList(self.list)
202
203         def newConfig(self):
204                 checkList = (self.configMode, self.diseqcModeEntry, self.advancedSatsEntry, \
205                         self.advancedLnbsEntry, self.advancedDiseqcMode, self.advancedUsalsEntry, \
206                         self.advancedLof, self.advancedPowerMeasurement, self.turningSpeed, \
207                         self.advancedType, self.advancedSCR, self.advancedManufacturer, self.advancedUnicable, \
208                         self.uncommittedDiseqcCommand, self.cableScanType, self.multiType)
209                 if self["config"].getCurrent() == self.multiType:
210                         print "enumerating:"
211                         nimmanager.enumerateNIMs()
212                         print "mode value:", self.multiType[1].value
213                         from Components.NimManager import InitNimManager
214                         InitNimManager(nimmanager)
215                         self.nim = nimmanager.nim_slots[self.slotid]
216                         self.nimConfig = self.nim.config
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                         else:   #kein Unicable
290                                 self.list.append(getConfigListEntry(_("Voltage mode"), Sat.voltage))
291                                 self.list.append(getConfigListEntry(_("Increased voltage"), currLnb.increased_voltage))
292                                 self.list.append(getConfigListEntry(_("Tone mode"), Sat.tonemode))
293
294                         if lnbnum < 33:
295                                 self.advancedDiseqcMode = getConfigListEntry(_("DiSEqC mode"), currLnb.diseqcMode)
296                                 self.list.append(self.advancedDiseqcMode)
297                         if currLnb.diseqcMode.value != "none":
298                                 self.list.append(getConfigListEntry(_("Toneburst"), currLnb.toneburst))
299                                 self.list.append(getConfigListEntry(_("Committed DiSEqC command"), currLnb.commitedDiseqcCommand))
300                                 self.list.append(getConfigListEntry(_("Fast DiSEqC"), currLnb.fastDiseqc))
301                                 self.list.append(getConfigListEntry(_("Sequence repeat"), currLnb.sequenceRepeat))
302                                 if currLnb.diseqcMode.value == "1_0":
303                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder1_0))
304                                 else:
305                                         if currLnb.uncommittedDiseqcCommand.index:
306                                                 if currLnb.commandOrder.value == "ct":
307                                                         currLnb.commandOrder.value = "cut"
308                                                 elif currLnb.commandOrder.value == "tc":
309                                                         currLnb.commandOrder.value = "tcu"
310                                         else:
311                                                 if currLnb.commandOrder.index & 1:
312                                                         currLnb.commandOrder.value = "tc"
313                                                 else:
314                                                         currLnb.commandOrder.value = "ct"
315                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder))
316                                         self.uncommittedDiseqcCommand = getConfigListEntry(_("Uncommitted DiSEqC command"), currLnb.uncommittedDiseqcCommand)
317                                         self.list.append(self.uncommittedDiseqcCommand)
318                                         self.list.append(getConfigListEntry(_("DiSEqC repeats"), currLnb.diseqcRepeats))
319                                 if currLnb.diseqcMode.value == "1_2":
320                                         self.list.append(getConfigListEntry(_("Longitude"), currLnb.longitude))
321                                         self.list.append(getConfigListEntry(" ", currLnb.longitudeOrientation))
322                                         self.list.append(getConfigListEntry(_("Latitude"), currLnb.latitude))
323                                         self.list.append(getConfigListEntry(" ", currLnb.latitudeOrientation))
324                                         if SystemInfo["CanMeasureFrontendInputPower"]:
325                                                 self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), currLnb.powerMeasurement)
326                                                 self.list.append(self.advancedPowerMeasurement)
327                                                 if currLnb.powerMeasurement.value:
328                                                         self.list.append(getConfigListEntry(_("Power threshold in mA"), currLnb.powerThreshold))
329                                                         self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), currLnb.turningSpeed)
330                                                         self.list.append(self.turningSpeed)
331                                                         if currLnb.turningSpeed.value == "fast epoch":
332                                                                 self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), currLnb.fastTurningBegin)
333                                                                 self.turnFastEpochEnd = getConfigListEntry(_("End time"), currLnb.fastTurningEnd)
334                                                                 self.list.append(self.turnFastEpochBegin)
335                                                                 self.list.append(self.turnFastEpochEnd)
336                                         else:
337                                                 if currLnb.powerMeasurement.value:
338                                                         currLnb.powerMeasurement.value = False
339                                                         currLnb.powerMeasurement.save()
340                                         self.advancedUsalsEntry = getConfigListEntry(_("Use usals for this sat"), Sat.usals)
341                                         self.list.append(self.advancedUsalsEntry)
342                                         if not Sat.usals.value:
343                                                 self.list.append(getConfigListEntry(_("Stored position"), Sat.rotorposition))
344
345         
346
347         def fillAdvancedList(self):
348                 self.list = [ ]
349                 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
350                 self.list.append(self.configMode)
351                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
352                 self.list.append(self.advancedSatsEntry)
353                 for x in self.nimConfig.advanced.sat.keys():
354                         Sat = self.nimConfig.advanced.sat[x]
355                         self.fillListWithAdvancedSatEntrys(Sat)
356                 self["config"].list = self.list
357
358         def keySave(self):
359                 old_configured_sats = nimmanager.getConfiguredSats()
360                 self.run()
361                 new_configured_sats = nimmanager.getConfiguredSats()
362                 self.unconfed_sats = old_configured_sats - new_configured_sats
363                 self.satpos_to_remove = None
364                 self.restoreService(_("Zap back to service before tuner setup?"))
365                 self.deleteConfirmed((None, "no"))
366
367         def deleteConfirmed(self, confirmed):
368                 if confirmed[1] == "yes" or confirmed[1] == "yestoall":
369                         eDVBDB.getInstance().removeServices(-1, -1, -1, self.satpos_to_remove)
370
371                 if self.satpos_to_remove is not None:
372                         self.unconfed_sats.remove(self.satpos_to_remove)
373
374                 self.satpos_to_remove = None
375                 for orbpos in self.unconfed_sats:
376                         self.satpos_to_remove = orbpos
377                         orbpos = self.satpos_to_remove
378                         try:
379                                 # why we need this cast?
380                                 sat_name = str(nimmanager.getSatDescription(orbpos))
381                         except:
382                                 if orbpos > 1800: # west
383                                         orbpos = 3600 - orbpos
384                                         h = _("W")
385                                 else:
386                                         h = _("E")
387                                 sat_name = ("%d.%d" + h) % (orbpos / 10, orbpos % 10)
388                                 
389                         if confirmed[1] == "yes" or confirmed[1] == "no":
390                                 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")])
391                         if confirmed[1] == "yestoall" or confirmed[1] == "notoall":
392                                 self.deleteConfirmed(confirmed)
393                         break
394                 
395         def __init__(self, session, slotid):
396                 Screen.__init__(self, session)
397                 self.list = [ ]
398                 
399                 ServiceStopScreen.__init__(self)
400                 self.stopService()
401
402                 ConfigListScreen.__init__(self, self.list)
403
404                 self["actions"] = ActionMap(["SetupActions", "SatlistShortcutAction"],
405                 {
406                         "ok": self.keySave,
407                         "cancel": self.keyCancel,
408                         "nothingconnected": self.nothingConnectedShortcut
409                 }, -2)
410
411                 self.slotid = slotid
412                 self.nim = nimmanager.nim_slots[slotid]
413                 self.nimConfig = self.nim.config
414                 self.createConfigMode()
415                 self.createSetup()
416
417         def keyLeft(self):
418                 ConfigListScreen.keyLeft(self)
419                 self.newConfig()
420
421         def keyRight(self):
422                 ConfigListScreen.keyRight(self)
423                 self.newConfig()
424                 
425         def keyCancel(self):
426                 if self["config"].isChanged():
427                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
428                 else:
429                         self.restoreService(_("Zap back to service before tuner setup?"))
430                 
431         def saveAll(self):
432                 if self.nim.isCompatible("DVB-S"):
433                         # reset connectedTo to all choices to properly store the default value
434                         choices = []
435                         nimlist = nimmanager.getNimListOfType("DVB-S", self.slotid)
436                         for id in nimlist:
437                                 choices.append((str(id), nimmanager.getNimDescription(id)))
438                         self.nimConfig.connectedTo.setChoices(choices)
439                 for x in self["config"].list:
440                         x[1].save()
441                         
442         def cancelConfirm(self, result):
443                 if not result:
444                         return
445
446                 for x in self["config"].list:
447                         x[1].cancel()
448                 # we need to call saveAll to reset the connectedTo choices
449                 self.saveAll()
450                 self.restoreService(_("Zap back to service before tuner setup?"))
451                 
452         def nothingConnectedShortcut(self):
453                 if type(self["config"].getCurrent()[1]) is ConfigSatlist:
454                         self["config"].getCurrent()[1].setValue("3601")
455                         self["config"].invalidateCurrent()
456                         
457 class NimSelection(Screen):
458         def __init__(self, session):
459                 Screen.__init__(self, session)
460                 
461                 self.list = [None] * nimmanager.getSlotCount()
462                 self["nimlist"] = List(self.list)
463                 self.updateList()
464                 
465                 self.setResultClass()
466
467                 self["actions"] = ActionMap(["OkCancelActions"],
468                 {
469                         "ok": self.okbuttonClick ,
470                         "cancel": self.close
471                 }, -2)
472                 
473         def setResultClass(self):
474                 self.resultclass = NimSetup
475
476         def okbuttonClick(self):
477                 nim = self["nimlist"].getCurrent()
478                 nim = nim and nim[3]
479                 if nim is not None and not nim.empty:
480                         self.session.openWithCallback(self.updateList, self.resultclass, nim.slot)
481                         
482         def showNim(self, nim):
483                 return True
484
485         def updateList(self):
486                 self.list = [ ]
487                 for x in nimmanager.nim_slots:
488                         slotid = x.slot
489                         nimConfig = nimmanager.getNimConfig(x.slot)
490                         text = nimConfig.configMode.value
491                         if self.showNim(x):
492                                 if x.isCompatible("DVB-S"):
493                                         if nimConfig.configMode.value in ("loopthrough", "equal", "satposdepends"):
494                                                 text = { "loopthrough": _("loopthrough to"),
495                                                                  "equal": _("equal to"),
496                                                                  "satposdepends": _("second cable of motorized LNB") } [nimConfig.configMode.value]
497                                                 text += " " + _("Tuner") + " " + ["A", "B", "C", "D"][int(nimConfig.connectedTo.value)]
498                                         elif nimConfig.configMode.value == "nothing":
499                                                 text = _("nothing connected")
500                                         elif nimConfig.configMode.value == "simple":
501                                                 if nimConfig.diseqcMode.value in ("single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
502                                                         text = _("Sats") + ": " 
503                                                         if nimConfig.diseqcA.orbital_position != 3601:
504                                                                 text += nimmanager.getSatName(int(nimConfig.diseqcA.value))
505                                                         if nimConfig.diseqcMode.value in ("toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"):
506                                                                 if nimConfig.diseqcB.orbital_position != 3601:
507                                                                         text += "," + nimmanager.getSatName(int(nimConfig.diseqcB.value))
508                                                         if nimConfig.diseqcMode.value == "diseqc_a_b_c_d":
509                                                                 if nimConfig.diseqcC.orbital_position != 3601:
510                                                                         text += "," + nimmanager.getSatName(int(nimConfig.diseqcC.value))
511                                                                 if nimConfig.diseqcD.orbital_position != 3601:
512                                                                         text += "," + nimmanager.getSatName(int(nimConfig.diseqcD.value))
513                                                 elif nimConfig.diseqcMode.value == "positioner":
514                                                         text = _("Positioner") + ":"
515                                                         if nimConfig.positionerMode.value == "usals":
516                                                                 text += _("USALS")
517                                                         elif nimConfig.positionerMode.value == "manual":
518                                                                 text += _("manual")
519                                                 else:   
520                                                         text = _("simple")
521                                         elif nimConfig.configMode.value == "advanced":
522                                                 text = _("advanced")
523                                 elif x.isCompatible("DVB-T") or x.isCompatible("DVB-C"):
524                                         if nimConfig.configMode.value == "nothing":
525                                                 text = _("nothing connected")
526                                         elif nimConfig.configMode.value == "enabled":
527                                                 text = _("enabled")
528                                 if x.isMultiType():
529                                         text = _("Switchable tuner types:") + "(" + ','.join(x.getMultiTypeList().values()) + ")" + "\n" + text
530                                         
531                                 self.list.append((slotid, x.friendly_full_description, text, x))
532                 self["nimlist"].setList(self.list)
533                 self["nimlist"].updateList(self.list)