3930aaa321bd9ecdf91f253b54b4694879f78c05
[enigma2.git] / lib / python / Screens / Satconfig.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.ConfigList import ConfigList, ConfigListScreen
4 from Components.MenuList import MenuList
5 from Components.NimManager import nimmanager
6 from Components.config import getConfigListEntry, config, ConfigDummy
7
8 class NimSetup(Screen, ConfigListScreen):
9         def createSimpleSetup(self, list, mode):
10                 if mode == "single":
11                         list.append(getConfigListEntry(_("Satellite"), self.nimConfig.diseqcA))
12                 else:
13                         list.append(getConfigListEntry(_("Port A"), self.nimConfig.diseqcA))
14
15                 if mode in ["toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
16                         list.append(getConfigListEntry(_("Port B"), self.nimConfig.diseqcB))
17                         if mode == "diseqc_a_b_c_d":
18                                 list.append(getConfigListEntry(_("Port C"), self.nimConfig.diseqcC))
19                                 list.append(getConfigListEntry(_("Port D"), self.nimConfig.diseqcD))
20
21         def createPositionerSetup(self, list):
22 #               list.append(getConfigListEntry(_("Positioner mode"), self.nimConfig.positionerMode))
23 #               if self.nimConfig.positionerMode.value == "usals": # USALS
24                 list.append(getConfigListEntry(_("Longitude"), self.nimConfig.longitude))
25                 list.append(getConfigListEntry(" ", self.nimConfig.longitudeOrientation))
26                 list.append(getConfigListEntry(_("Latitude"), self.nimConfig.latitude))
27                 list.append(getConfigListEntry(" ", self.nimConfig.latitudeOrientation))
28 #               elif self.nimConfig.positionerMode.value == "manual": # manual
29 #                       pass
30
31         def createSetup(self):
32                 print "Creating setup"
33                 self.list = [ ]
34
35                 self.configMode = None
36                 self.diseqcModeEntry = None
37                 self.advancedSatsEntry = None
38                 self.advancedLnbsEntry = None
39                 self.advancedDiseqcMode = None
40                 self.advancedUsalsEntry = None
41                 self.advancedLof = None
42                 self.advancedPowerMeasurement = None
43                 
44                 self.nim_type = nimmanager.getNimType(self.nim.slotid)
45
46                 if self.nim_type == nimmanager.nimType["DVB-S"]:
47                         self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
48                         self.list.append(self.configMode)
49                         
50                         if self.nimConfig.configMode.value == "simple":                 #simple setup
51                                 self.diseqcModeEntry = getConfigListEntry(_("DiSEqC Mode"), self.nimConfig.diseqcMode)
52                                 self.list.append(self.diseqcModeEntry)
53                                 if self.nimConfig.diseqcMode.value in ["single", "toneburst_a_b", "diseqc_a_b", "diseqc_a_b_c_d"]:
54                                         self.createSimpleSetup(self.list, self.nimConfig.diseqcMode.value)
55                                 if self.nimConfig.diseqcMode.value == "positioner":
56                                         self.createPositionerSetup(self.list)
57                         elif self.nimConfig.configMode.value in ["loopthrough", "satposdepends", "nothing", "equal"]:
58                                 pass
59                         elif self.nimConfig.configMode.value == "advanced": # advanced
60                                 # SATs
61                                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
62                                 self.list.append(self.advancedSatsEntry)
63                                 print "blub", self.nimConfig.advanced.sat
64                                 currSat = self.nimConfig.advanced.sat[self.nimConfig.advanced.sats.orbital_position]
65                                 self.fillListWithAdvancedSatEntrys(currSat)
66                         self.have_advanced = True
67                 elif self.nim_type == nimmanager.nimType["DVB-C"]:
68                         self.list.append(getConfigListEntry(_("Cable provider"), self.nimConfig.cable))
69                         self.have_advanced = False
70                 elif self.nim_type == nimmanager.nimType["DVB-T"]:
71                         self.have_advanced = False
72                         self.list.append(getConfigListEntry(_("Terrestrial provider"), self.nimConfig.terrestrial))
73                         self.list.append(getConfigListEntry(_("Enable 5V for active antenna"), self.nimConfig.terrestrial_5V))
74                 else:
75                         self.have_advanced = False
76
77                 self["config"].list = self.list
78                 self["config"].l.setList(self.list)
79
80         def newConfig(self):
81                 checkList = (self.configMode, self.diseqcModeEntry, self.advancedSatsEntry, self.advancedLnbsEntry, self.advancedDiseqcMode, self.advancedUsalsEntry, self.advancedLof, self.advancedPowerMeasurement)
82                 for x in checkList:
83                         if self["config"].getCurrent() == x:
84                                 self.createSetup()
85
86         def run(self):
87                 if self.have_advanced and config.Nims[self.nim.slotid].configMode.value == "advanced":
88                         self.fillAdvancedList()
89                 for x in self["config"].list:
90                         x[1].save()
91                 nimmanager.sec.update()
92
93         def fillListWithAdvancedSatEntrys(self, Sat):
94                 currLnb = self.nimConfig.advanced.lnb[int(Sat.lnb.value)]
95                 
96                 if isinstance(currLnb, ConfigDummy):
97                         currLnb = None
98
99                 self.list.append(getConfigListEntry(_("Voltage mode"), Sat.voltage))
100                 self.list.append(getConfigListEntry(_("Tone mode"), Sat.tonemode))
101                 if currLnb and currLnb.diseqcMode.value == "1_2":
102                         self.advancedUsalsEntry = getConfigListEntry(_("Use usals for this sat"), Sat.usals)
103                         self.list.append(self.advancedUsalsEntry)
104                         if not Sat.usals.value:
105                                 self.list.append(getConfigListEntry(_("Stored position"), Sat.rotorposition))
106
107                 # LNBs
108                 self.advancedLnbsEntry = getConfigListEntry(_("LNB"), Sat.lnb)
109                 self.list.append(self.advancedLnbsEntry)
110                 if currLnb:
111                         self.advancedDiseqcMode = getConfigListEntry(_("DiSEqC mode"), currLnb.diseqcMode)
112                         self.list.append(self.advancedDiseqcMode)
113                         if currLnb.diseqcMode.value != "none":
114                                 self.list.append(getConfigListEntry(_("Toneburst"), currLnb.toneburst))
115                                 self.list.append(getConfigListEntry(_("Committed DiSEqC command"), currLnb.commitedDiseqcCommand))
116                                 self.list.append(getConfigListEntry(_("Fast DiSEqC"), currLnb.fastDiseqc))
117                                 self.list.append(getConfigListEntry(_("Sequence repeat"), currLnb.sequenceRepeat))
118                                 if currLnb.diseqcMode.value == "1_0":
119                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder1_0))
120                                 else:
121                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder))
122                                         self.list.append(getConfigListEntry(_("Uncommitted DiSEqC command"), currLnb.uncommittedDiseqcCommand))
123                                         self.list.append(getConfigListEntry(_("DiSEqC repeats"), currLnb.diseqcRepeats))
124                                 if currLnb.diseqcMode.value == "1_2":
125                                         self.list.append(getConfigListEntry(_("Longitude"), currLnb.longitude))
126                                         self.list.append(getConfigListEntry(" ", currLnb.longitudeOrientation))
127                                         self.list.append(getConfigListEntry(_("Latitude"), currLnb.latitude))
128                                         self.list.append(getConfigListEntry(" ", currLnb.latitudeOrientation))
129                                         self.advancedPowerMeasurement = getConfigListEntry("Use Power Measurement", currLnb.powerMeasurement)
130                                         self.list.append(self.advancedPowerMeasurement)
131                                         if currLnb.powerMeasurement.value == "yes":
132                                                 self.list.append(getConfigListEntry("Power Threshold in mA", currLnb.powerThreshold))
133                         self.advancedLof = getConfigListEntry(_("LOF"), currLnb.lof)
134                         self.list.append(self.advancedLof)
135                         if currLnb.lof.value == "user_defined":
136                                 self.list.append(getConfigListEntry(_("LOF/L"), currLnb.lofl))
137                                 self.list.append(getConfigListEntry(_("LOF/H"), currLnb.lofh))
138                                 self.list.append(getConfigListEntry(_("Threshold"), currLnb.threshold))
139                         self.list.append(getConfigListEntry(_("12V Output"), currLnb.output_12v))
140                         self.list.append(getConfigListEntry(_("Increased voltage"), currLnb.increased_voltage))
141
142         def fillAdvancedList(self):
143                 self.list = [ ]
144                 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
145                 self.list.append(self.configMode)
146                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
147                 self.list.append(self.advancedSatsEntry)
148                 for x in nimmanager.satList:
149                         Sat = self.nimConfig.advanced.sat[x[0]]
150                         self.fillListWithAdvancedSatEntrys(Sat)
151                 self["config"].list = self.list
152
153         def keySave(self):
154                 self.run()
155                 self.close()
156
157         def keyCancel(self):
158                 for x in self["config"].list:
159                         x[1].cancel()
160                 self.close()
161
162         def __init__(self, session, slotid):
163                 Screen.__init__(self, session)
164                 self.list = [ ]
165
166                 ConfigListScreen.__init__(self, self.list)
167
168                 self["actions"] = ActionMap(["SetupActions"],
169                 {
170                         "ok": self.keySave,
171                         "cancel": self.keyCancel,
172                 }, -1)
173
174                 self.nim = nimmanager.nimList()[slotid][1]
175                 self.nimConfig = config.Nims[self.nim.slotid]
176                 self.createSetup()
177
178         def keyLeft(self):
179                 ConfigListScreen.keyLeft(self)
180                 self.newConfig()
181
182         def keyRight(self):
183                 ConfigListScreen.keyRight(self)
184                 self.newConfig()
185
186 class NimSelection(Screen):
187         def __init__(self, session):
188                 Screen.__init__(self, session)
189
190                 self["nimlist"] = MenuList(nimmanager.nimList())
191
192                 self["actions"] = ActionMap(["OkCancelActions"],
193                 {
194                         "ok": self.okbuttonClick ,
195                         "cancel": self.close
196                 }, -2)
197
198         def okbuttonClick(self):
199                 selection = self["nimlist"].getCurrent()
200                 if selection[1].nimType != -1:  #unknown/empty
201                         self.session.open(NimSetup, selection[1].slotid)
202