some changes to the configSelection stuff
[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, nim, list, mode):
12                 if mode == 0:                   #single Sat
13                         list.append(getConfigListEntry(_("Satellite"), config.Nims[nim.slotid].diseqcA))
14                 else:                                                   # > 1 Sats
15                         list.append(getConfigListEntry(_("Port A"), config.Nims[nim.slotid].diseqcA))
16
17                 if mode >= 1:                   # > 1 Sats
18                         list.append(getConfigListEntry(_("Port B"), config.Nims[nim.slotid].diseqcB))
19                         if mode >= 3:           # > 2 Sats
20                                 list.append(getConfigListEntry(_("Port C"), config.Nims[nim.slotid].diseqcC))
21                                 list.append(getConfigListEntry(_("Port D"), config.Nims[nim.slotid].diseqcD))
22         
23         def createPositionerSetup(self, nim, list):
24                 list.append(getConfigListEntry(_("Positioner mode"), config.Nims[nim.slotid].positionerMode))
25                 if (currentConfigSelectionElement(config.Nims[nim.slotid].positionerMode) == "usals"): # USALS
26                         list.append(getConfigListEntry(_("Longitude"), config.Nims[nim.slotid].longitude))
27                         list.append(getConfigListEntry("", config.Nims[nim.slotid].longitudeOrientation))
28                         list.append(getConfigListEntry(_("Latitude"), config.Nims[nim.slotid].latitude))
29                         list.append(getConfigListEntry("", config.Nims[nim.slotid].latitudeOrientation))
30                 elif (currentConfigSelectionElement(config.Nims[nim.slotid].positionerMode) == "manual"): # manual
31                         pass
32         
33         def createSetup(self):
34                 self.list = [ ]
35                 self.diseqcModeEntry = None
36                 
37                 if (nimmanager.getNimType(self.nim.slotid) == nimmanager.nimType["DVB-S"]):
38                         self.configMode = getConfigListEntry(_("Configuration Mode"), config.Nims[self.nim.slotid].configMode)
39                         self.list.append(self.configMode)
40                         
41                         if currentConfigSelectionElement(config.Nims[self.nim.slotid].configMode) == "simple":                  #simple setup
42                                 self.diseqcModeEntry = getConfigListEntry(_("DiSEqC Mode"), config.Nims[self.nim.slotid].diseqcMode)
43                                 self.list.append(self.diseqcModeEntry)
44                         
45                                 if (0 <= config.Nims[self.nim.slotid].diseqcMode.value < 4):
46                                         self.createSimpleSetup(self.nim, self.list, config.Nims[self.nim.slotid].diseqcMode.value)
47                                 if (config.Nims[self.nim.slotid].diseqcMode.value == 4):
48                                         self.createPositionerSetup(self.nim, self.list)
49                         elif currentConfigSelectionElement(config.Nims[self.nim.slotid].configMode) == "nothing": # nothing
50                                 #self.list.append(getConfigListEntry(_("Linked to"), config.Nims[self.nim.slotid].linkedTo))
51                                 pass
52                         elif currentConfigSelectionElement(config.Nims[self.nim.slotid].configMode) == "loopthrough": # linked
53                                 pass
54                 
55                 elif (nimmanager.getNimType(self.nim.slotid) == nimmanager.nimType["DVB-C"]):
56                         self.list.append(getConfigListEntry(_("Cable provider"), config.Nims[self.nim.slotid].cable))
57                 elif (nimmanager.getNimType(self.nim.slotid) == nimmanager.nimType["DVB-T"]):
58                         self.list.append(getConfigListEntry(_("Terrestrial provider"), config.Nims[self.nim.slotid].terrestrial))
59
60
61                 self["config"].list = self.list
62                 self["config"].l.setList(self.list)
63                 
64         def newConfig(self):    
65                 if self["config"].getCurrent() == self.configMode:
66                         self.createSetup()
67                 if self["config"].getCurrent() == self.diseqcModeEntry:
68                         self.createSetup()
69                 
70         def keyLeft(self):
71                 if self["config"].getCurrent() == self.configMode:
72                         if self.nim.slotid == 0:
73                                 return
74                 self["config"].handleKey(config.key["prevElement"])
75                 self.newConfig()
76
77         def keyRight(self):
78                 #forbid to enable advanced mode until its ready
79                 #perhaps its better to use an own element here
80                 #this suckz .. how enable advanced config?
81                 if self["config"].getCurrent() == self.configMode:
82                         if self.nim.slotid == 0:
83                                 return
84
85                 self["config"].handleKey(config.key["nextElement"])
86                 self.newConfig()
87
88         def keyNumberGlobal(self, number):
89                 print "You pressed number " + str(number)
90                 if (self["config"].getCurrent()[1].parent.enabled == True):
91                         self["config"].handleKey(config.key[str(number)])
92
93         def run(self):
94                 for x in self["config"].list:
95                         x[1].save()
96                 nimmanager.sec.update() 
97
98         def keySave(self):
99                 self.run()
100                 self.close()
101
102         def keyCancel(self):
103                 for x in self["config"].list:
104                         x[1].cancel()
105                 self.close()
106
107         def __init__(self, session, slotid):
108                 Screen.__init__(self, session)
109                 
110                 self.nim = nimmanager.nimList()[slotid][1]
111                 
112                 self["actions"] = NumberActionMap(["SetupActions"],
113                 {
114                         "ok": self.keySave,
115                         "cancel": self.keyCancel,
116                         "left": self.keyLeft,
117                         "right": self.keyRight,
118                         "1": self.keyNumberGlobal,
119                         "2": self.keyNumberGlobal,
120                         "3": self.keyNumberGlobal,
121                         "4": self.keyNumberGlobal,
122                         "5": self.keyNumberGlobal,
123                         "6": self.keyNumberGlobal,
124                         "7": self.keyNumberGlobal,
125                         "8": self.keyNumberGlobal,
126                         "9": self.keyNumberGlobal,
127                         "0": self.keyNumberGlobal
128                 }, -1)
129
130                 self.list = [ ]
131                 self["config"] = ConfigList(self.list)
132                 
133                 self.createSetup()
134
135 class NimSelection(Screen):
136         def __init__(self, session):
137                 Screen.__init__(self, session)
138
139                 self["nimlist"] = MenuList(nimmanager.nimList())
140
141                 self["actions"] = ActionMap(["OkCancelActions"],
142                 {
143                         "ok": self.okbuttonClick ,
144                         "cancel": self.close
145                 }, -1)
146
147         def okbuttonClick(self):
148                 selection = self["nimlist"].getCurrent()
149                 if selection[1].nimType != -1:  #unknown/empty
150                         self.session.open(NimSetup, selection[1].slotid)
151