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