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