fix storing config entries (used by startwizzard)
[enigma2.git] / lib / python / Screens / Satconfig.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.ConfigList import ConfigListScreen
4 from Components.MenuList import MenuList
5 from Components.NimManager import nimmanager
6 from Components.config import getConfigListEntry, config, ConfigNothing
7
8 from time import mktime, localtime
9 from datetime import datetime
10
11 class NimSetup(Screen, ConfigListScreen):
12         def createSimpleSetup(self, list, mode):
13                 if mode == "single":
14                         list.append(getConfigListEntry(_("Satellite"), self.nimConfig.diseqcA))
15                 else:
16                         list.append(getConfigListEntry(_("Port A"), self.nimConfig.diseqcA))
17
18                 if mode in ["toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
19                         list.append(getConfigListEntry(_("Port B"), self.nimConfig.diseqcB))
20                         if mode == "diseqc_a_b_c_d":
21                                 list.append(getConfigListEntry(_("Port C"), self.nimConfig.diseqcC))
22                                 list.append(getConfigListEntry(_("Port D"), self.nimConfig.diseqcD))
23
24         def createPositionerSetup(self, list):
25                 nim = self.nimConfig
26                 list.append(getConfigListEntry(_("Longitude"), nim.longitude))
27                 list.append(getConfigListEntry(" ", nim.longitudeOrientation))
28                 list.append(getConfigListEntry(_("Latitude"), nim.latitude))
29                 list.append(getConfigListEntry(" ", nim.latitudeOrientation))
30
31                 self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), nim.powerMeasurement)
32                 list.append(self.advancedPowerMeasurement)
33                 if nim.powerMeasurement.value:
34                         list.append(getConfigListEntry(_("Power threshold in mA"), nim.powerThreshold))
35                         self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), nim.turningSpeed)
36                         list.append(self.turningSpeed)
37                         if nim.turningSpeed.value == "fast epoch":
38                                 self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), nim.fastTurningBegin)
39                                 self.turnFastEpochEnd = getConfigListEntry(_("End time"), nim.fastTurningEnd)
40                                 list.append(self.turnFastEpochBegin)
41                                 list.append(self.turnFastEpochEnd)
42
43         def createSetup(self):
44                 print "Creating setup"
45                 self.list = [ ]
46
47                 self.configMode = None
48                 self.diseqcModeEntry = None
49                 self.advancedSatsEntry = None
50                 self.advancedLnbsEntry = None
51                 self.advancedDiseqcMode = None
52                 self.advancedUsalsEntry = None
53                 self.advancedLof = None
54                 self.advancedPowerMeasurement = None
55                 self.turningSpeed = None
56                 self.turnFastEpochBegin = None
57                 self.turnFastEpochEnd = None
58
59                 self.cableScanType = None
60
61                 if self.nim.isCompatible("DVB-S"):
62                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
63                         self.list.append(self.configMode)
64
65                         if self.nimConfig.configMode.value == "simple":                 #simple setup
66                                 self.diseqcModeEntry = getConfigListEntry(_("DiSEqC Mode"), self.nimConfig.diseqcMode)
67                                 self.list.append(self.diseqcModeEntry)
68                                 if self.nimConfig.diseqcMode.value in ["single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
69                                         self.createSimpleSetup(self.list, self.nimConfig.diseqcMode.value)
70                                 if self.nimConfig.diseqcMode.value == "positioner":
71                                         self.createPositionerSetup(self.list)
72                         elif self.nimConfig.configMode.value in ["loopthrough", "satposdepends", "nothing", "equal"]:
73                                 pass
74                         elif self.nimConfig.configMode.value == "advanced": # advanced
75                                 # SATs
76                                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
77                                 self.list.append(self.advancedSatsEntry)
78                                 cur_orb_pos = self.nimConfig.advanced.sats.orbital_position
79                                 satlist = self.nimConfig.advanced.sat.keys()
80                                 if cur_orb_pos not in satlist:
81                                         cur_orb_pos = satlist[0]
82                                 currSat = self.nimConfig.advanced.sat[cur_orb_pos]
83                                 self.fillListWithAdvancedSatEntrys(currSat)
84                         self.have_advanced = True
85                 elif self.nim.isCompatible("DVB-C"):
86                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
87                         self.list.append(self.configMode)
88                         if self.nimConfig.configMode.value == "enabled":
89                                 self.cableScanType=getConfigListEntry(_("Used service scan type"), self.nimConfig.cable.scan_type)
90                                 self.list.append(self.cableScanType)
91                                 if self.nimConfig.cable.scan_type.value == "provider":
92                                         self.list.append(getConfigListEntry(_("Provider to scan"), self.nimConfig.cable.scan_provider))
93                                 else:
94                                         if self.nimConfig.cable.scan_type.value == "bands":
95                                                 self.list.append(getConfigListEntry(_("Scan band EU VHF I"), self.nimConfig.cable.scan_band_EU_VHF_I))
96                                                 self.list.append(getConfigListEntry(_("Scan band EU MID"), self.nimConfig.cable.scan_band_EU_MID))
97                                                 self.list.append(getConfigListEntry(_("Scan band EU VHF III"), self.nimConfig.cable.scan_band_EU_VHF_III))
98                                                 self.list.append(getConfigListEntry(_("Scan band EU UHF IV"), self.nimConfig.cable.scan_band_EU_UHF_IV))
99                                                 self.list.append(getConfigListEntry(_("Scan band EU UHF V"), self.nimConfig.cable.scan_band_EU_UHF_V))
100                                                 self.list.append(getConfigListEntry(_("Scan band EU SUPER"), self.nimConfig.cable.scan_band_EU_SUPER))
101                                                 self.list.append(getConfigListEntry(_("Scan band EU HYPER"), self.nimConfig.cable.scan_band_EU_HYPER))
102                                                 self.list.append(getConfigListEntry(_("Scan band US LOW"), self.nimConfig.cable.scan_band_US_LOW))
103                                                 self.list.append(getConfigListEntry(_("Scan band US MID"), self.nimConfig.cable.scan_band_US_MID))
104                                                 self.list.append(getConfigListEntry(_("Scan band US HIGH"), self.nimConfig.cable.scan_band_US_HIGH))
105                                                 self.list.append(getConfigListEntry(_("Scan band US SUPER"), self.nimConfig.cable.scan_band_US_SUPER))
106                                                 self.list.append(getConfigListEntry(_("Scan band US HYPER"), self.nimConfig.cable.scan_band_US_HYPER))
107                                         elif self.nimConfig.cable.scan_type.value == "steps":
108                                                 self.list.append(getConfigListEntry(_("Frequency scan step size(khz)"), self.nimConfig.cable.scan_frequency_steps))
109                                         self.list.append(getConfigListEntry(_("Scan QAM16"), self.nimConfig.cable.scan_mod_qam16))
110                                         self.list.append(getConfigListEntry(_("Scan QAM32"), self.nimConfig.cable.scan_mod_qam32))
111                                         self.list.append(getConfigListEntry(_("Scan QAM64"), self.nimConfig.cable.scan_mod_qam64))
112                                         self.list.append(getConfigListEntry(_("Scan QAM128"), self.nimConfig.cable.scan_mod_qam128))
113                                         self.list.append(getConfigListEntry(_("Scan QAM256"), self.nimConfig.cable.scan_mod_qam256))
114                                         self.list.append(getConfigListEntry(_("Scan SR6900"), self.nimConfig.cable.scan_sr_6900))
115                                         self.list.append(getConfigListEntry(_("Scan SR6875"), self.nimConfig.cable.scan_sr_6875))
116                                         self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext1))
117                                         self.list.append(getConfigListEntry(_("Scan additional SR"), self.nimConfig.cable.scan_sr_ext2))
118                         self.have_advanced = False
119                 elif self.nim.isCompatible("DVB-T"):
120                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
121                         self.list.append(self.configMode)
122                         self.have_advanced = False
123                         if self.nimConfig.configMode.value == "enabled":
124                                 self.list.append(getConfigListEntry(_("Terrestrial provider"), self.nimConfig.terrestrial))
125                                 self.list.append(getConfigListEntry(_("Enable 5V for active antenna"), self.nimConfig.terrestrial_5V))
126                 else:
127                         self.have_advanced = False
128                 self["config"].list = self.list
129                 self["config"].l.setList(self.list)
130
131         def newConfig(self):
132                 checkList = (self.configMode, self.diseqcModeEntry, self.advancedSatsEntry, \
133                         self.advancedLnbsEntry, self.advancedDiseqcMode, self.advancedUsalsEntry, \
134                         self.advancedLof, self.advancedPowerMeasurement, self.turningSpeed, self.cableScanType)
135                 for x in checkList:
136                         if self["config"].getCurrent() == x:
137                                 self.createSetup()
138
139         def run(self):
140                 if self.have_advanced and self.nim.config_mode == "advanced":
141                         self.fillAdvancedList()
142                 for x in self.list:
143                         if x in [self.turnFastEpochBegin, self.turnFastEpochEnd]:
144                                 # workaround for storing only hour*3600+min*60 value in configfile
145                                 # not really needed.. just for cosmetics..
146                                 tm = localtime(x[1].value)
147                                 dt = datetime(1970, 1, 1, tm.tm_hour, tm.tm_min)
148                                 x[1].value = int(mktime(dt.timetuple()))
149                         x[1].save()
150                 nimmanager.sec.update()
151
152         def fillListWithAdvancedSatEntrys(self, Sat):
153                 currLnb = self.nimConfig.advanced.lnb[int(Sat.lnb.value)]
154                 
155                 if isinstance(currLnb, ConfigNothing):
156                         currLnb = None
157
158                 self.list.append(getConfigListEntry(_("Voltage mode"), Sat.voltage))
159                 self.list.append(getConfigListEntry(_("Tone mode"), Sat.tonemode))
160                 if currLnb and currLnb.diseqcMode.value == "1_2":
161                         self.advancedUsalsEntry = getConfigListEntry(_("Use usals for this sat"), Sat.usals)
162                         self.list.append(self.advancedUsalsEntry)
163                         if not Sat.usals.value:
164                                 self.list.append(getConfigListEntry(_("Stored position"), Sat.rotorposition))
165
166                 # LNBs
167                 self.advancedLnbsEntry = getConfigListEntry(_("LNB"), Sat.lnb)
168                 self.list.append(self.advancedLnbsEntry)
169                 if currLnb:
170                         self.advancedDiseqcMode = getConfigListEntry(_("DiSEqC mode"), currLnb.diseqcMode)
171                         self.list.append(self.advancedDiseqcMode)
172                         if currLnb.diseqcMode.value != "none":
173                                 self.list.append(getConfigListEntry(_("Toneburst"), currLnb.toneburst))
174                                 self.list.append(getConfigListEntry(_("Committed DiSEqC command"), currLnb.commitedDiseqcCommand))
175                                 self.list.append(getConfigListEntry(_("Fast DiSEqC"), currLnb.fastDiseqc))
176                                 self.list.append(getConfigListEntry(_("Sequence repeat"), currLnb.sequenceRepeat))
177                                 if currLnb.diseqcMode.value == "1_0":
178                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder1_0))
179                                 else:
180                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder))
181                                         self.list.append(getConfigListEntry(_("Uncommitted DiSEqC command"), currLnb.uncommittedDiseqcCommand))
182                                         self.list.append(getConfigListEntry(_("DiSEqC repeats"), currLnb.diseqcRepeats))
183                                 if currLnb.diseqcMode.value == "1_2":
184                                         self.list.append(getConfigListEntry(_("Longitude"), currLnb.longitude))
185                                         self.list.append(getConfigListEntry(" ", currLnb.longitudeOrientation))
186                                         self.list.append(getConfigListEntry(_("Latitude"), currLnb.latitude))
187                                         self.list.append(getConfigListEntry(" ", currLnb.latitudeOrientation))
188                                         self.advancedPowerMeasurement = getConfigListEntry(_("Use Power Measurement"), currLnb.powerMeasurement)
189                                         self.list.append(self.advancedPowerMeasurement)
190                                         if currLnb.powerMeasurement.value:
191                                                 self.list.append(getConfigListEntry(_("Power threshold in mA"), currLnb.powerThreshold))
192                                                 self.turningSpeed = getConfigListEntry(_("Rotor turning speed"), currLnb.turningSpeed)
193                                                 self.list.append(self.turningSpeed)
194                                                 if currLnb.turningSpeed.value == "fast epoch":
195                                                         self.turnFastEpochBegin = getConfigListEntry(_("Begin time"), currLnb.fastTurningBegin)
196                                                         self.turnFastEpochEnd = getConfigListEntry(_("End time"), currLnb.fastTurningEnd)
197                                                         self.list.append(self.turnFastEpochBegin)
198                                                         self.list.append(self.turnFastEpochEnd)
199                         self.advancedLof = getConfigListEntry(_("LOF"), currLnb.lof)
200                         self.list.append(self.advancedLof)
201                         if currLnb.lof.value == "user_defined":
202                                 self.list.append(getConfigListEntry(_("LOF/L"), currLnb.lofl))
203                                 self.list.append(getConfigListEntry(_("LOF/H"), currLnb.lofh))
204                                 self.list.append(getConfigListEntry(_("Threshold"), currLnb.threshold))
205 #                       self.list.append(getConfigListEntry(_("12V Output"), currLnb.output_12v))
206                         self.list.append(getConfigListEntry(_("Increased voltage"), currLnb.increased_voltage))
207
208         def fillAdvancedList(self):
209                 self.list = [ ]
210                 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
211                 self.list.append(self.configMode)
212                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
213                 self.list.append(self.advancedSatsEntry)
214                 for x in nimmanager.satList:
215                         Sat = self.nimConfig.advanced.sat[x[0]]
216                         self.fillListWithAdvancedSatEntrys(Sat)
217                 self["config"].list = self.list
218
219         def keySave(self):
220                 self.run()
221                 self.close()
222
223         def __init__(self, session, slotid):
224                 Screen.__init__(self, session)
225                 self.list = [ ]
226
227                 ConfigListScreen.__init__(self, self.list)
228
229                 self["actions"] = ActionMap(["SetupActions"],
230                 {
231                         "ok": self.keySave,
232                         "cancel": self.keyCancel,
233                 }, -2)
234
235                 self.nim = nimmanager.nim_slots[slotid]
236                 self.nimConfig = self.nim.config
237                 self.createSetup()
238
239         def keyLeft(self):
240                 ConfigListScreen.keyLeft(self)
241                 self.newConfig()
242
243         def keyRight(self):
244                 ConfigListScreen.keyRight(self)
245                 self.newConfig()
246
247 class NimSelection(Screen):
248         def __init__(self, session):
249                 Screen.__init__(self, session)
250                 
251                 menu = [ ]
252                 for x in nimmanager.nim_slots:
253                         menu.append((x.friendly_full_description, x))
254
255                 self["nimlist"] = MenuList(menu)
256
257                 self["actions"] = ActionMap(["OkCancelActions"],
258                 {
259                         "ok": self.okbuttonClick ,
260                         "cancel": self.close
261                 }, -2)
262
263         def okbuttonClick(self):
264                 nim = self["nimlist"].getCurrent()
265                 nim = nim and nim[1]
266                 if nim is not None and not nim.empty:
267                         self.session.open(NimSetup, nim.slot)