add ability to enable/disable "change to next/prev bouquet when quickzap is used...
[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                 for x in self["config"].list:
94                         x[1].save()
95                 nimmanager.sec.update()
96
97         def fillListWithAdvancedSatEntrys(self, Sat):
98                 currLnb = self.nimConfig.advanced.lnb[Sat.lnb.value]
99
100                 self.list.append(getConfigListEntry(_("Voltage mode"), Sat.voltage))
101                 self.list.append(getConfigListEntry(_("Tone mode"), Sat.tonemode))
102                 if (currLnb != 0 and currentConfigSelectionElement(currLnb.diseqcMode) == "1_2"):
103                         self.advancedUsalsEntry = getConfigListEntry(_("Use usals for this sat"), Sat.usals)
104                         self.list.append(self.advancedUsalsEntry)
105                         if (currentConfigSelectionElement(Sat.usals) == "no"):
106                                 self.list.append(getConfigListEntry(_("Stored position"), Sat.rotorposition))
107
108                 # LNBs
109                 self.advancedLnbsEntry = getConfigListEntry(_("LNB"), Sat.lnb)
110                 self.list.append(self.advancedLnbsEntry)
111                 if currLnb != 0:
112                         self.advancedDiseqcMode = getConfigListEntry(_("DiSEqC mode"), currLnb.diseqcMode)
113                         self.list.append(self.advancedDiseqcMode)
114                         if currentConfigSelectionElement(currLnb.diseqcMode) != "none":
115                                 self.list.append(getConfigListEntry(_("Toneburst"), currLnb.toneburst))
116                                 self.list.append(getConfigListEntry(_("Committed DiSEqC command"), currLnb.commitedDiseqcCommand))
117                                 self.list.append(getConfigListEntry(_("Fast DiSEqC"), currLnb.fastDiseqc))
118                                 self.list.append(getConfigListEntry(_("Sequence repeat"), currLnb.sequenceRepeat))
119                                 if currentConfigSelectionElement(currLnb.diseqcMode) == "1_0":
120                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder1_0))
121                                 else:
122                                         self.list.append(getConfigListEntry(_("Command order"), currLnb.commandOrder))
123                                         self.list.append(getConfigListEntry(_("Uncommitted DiSEqC command"), currLnb.uncommittedDiseqcCommand))
124                                         self.list.append(getConfigListEntry(_("DiSEqC repeats"), currLnb.diseqcRepeats))
125                                 if currentConfigSelectionElement(currLnb.diseqcMode) == "1_2":
126                                         self.list.append(getConfigListEntry(_("Longitude"), currLnb.longitude))
127                                         self.list.append(getConfigListEntry(" ", currLnb.longitudeOrientation))
128                                         self.list.append(getConfigListEntry(_("Latitude"), currLnb.latitude))
129                                         self.list.append(getConfigListEntry(" ", currLnb.latitudeOrientation))
130                                         self.advancedPowerMeasurement = getConfigListEntry("Use Power Measurement", currLnb.powerMeasurement)
131                                         self.list.append(self.advancedPowerMeasurement)
132                                         if currentConfigSelectionElement(currLnb.powerMeasurement) == "yes":
133                                                 self.list.append(getConfigListEntry("Power Threshold in mA", currLnb.powerThreshold))
134                         self.advancedLof = getConfigListEntry(_("LOF"), currLnb.lof)
135                         self.list.append(self.advancedLof)
136                         if currentConfigSelectionElement(currLnb.lof) == "user_defined":
137                                 self.list.append(getConfigListEntry(_("LOF/L"), currLnb.lofl))
138                                 self.list.append(getConfigListEntry(_("LOF/H"), currLnb.lofh))
139                                 self.list.append(getConfigListEntry(_("Threshold"), currLnb.threshold))
140                         self.list.append(getConfigListEntry(_("12V Output"), currLnb.output_12v))
141                         self.list.append(getConfigListEntry(_("Increased voltage"), currLnb.increased_voltage))
142
143         def fillAdvancedList(self):
144                 self.list = [ ]
145                 self.configMode = getConfigListEntry(_("Configuration Mode"), self.nimConfig.configMode)
146                 self.list.append(self.configMode)
147                 self.advancedSatsEntry = getConfigListEntry(_("Satellite"), self.nimConfig.advanced.sats)
148                 self.list.append(self.advancedSatsEntry)
149                 for x in nimmanager.satList:
150                         Sat = self.nimConfig.advanced.sat[x[1]]
151                         self.fillListWithAdvancedSatEntrys(Sat)
152                 self["config"].list = self.list
153
154         def keySave(self):
155                 if currentConfigSelectionElement(config.Nims[self.nim.slotid].configMode) == "advanced":
156                         self.fillAdvancedList()
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