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