add ability to remove list and config from a wizard
[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 (config.Nims[nim.slotid].positionerMode.value == 0): # 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 (config.Nims[nim.slotid].positionerMode.value == 1): # manual
31                         pass
32         
33         def createSetup(self):
34                 self.list = [ ]
35                 
36                 if (nimmanager.getNimType(self.nim.slotid) == nimmanager.nimType["DVB-S"]):
37                         self.configMode = getConfigListEntry(_("Configuration Mode"), config.Nims[self.nim.slotid].configMode)
38                         self.list.append(self.configMode)
39                         
40                         if config.Nims[self.nim.slotid].configMode.value == 0:                  #simple setup
41                                 self.diseqcModeEntry = getConfigListEntry(_("DiSEqC Mode"), config.Nims[self.nim.slotid].diseqcMode)
42                                 self.list.append(self.diseqcModeEntry)
43                         
44                                 if (0 <= config.Nims[self.nim.slotid].diseqcMode.value < 4):
45                                         self.createSimpleSetup(self.nim, self.list, config.Nims[self.nim.slotid].diseqcMode.value)
46                                 if (config.Nims[self.nim.slotid].diseqcMode.value == 4):
47                                         self.createPositionerSetup(self.nim, self.list)
48                         elif config.Nims[self.nim.slotid].configMode.value == 1: # nothing
49                                 #self.list.append(getConfigListEntry(_("Linked to"), config.Nims[self.nim.slotid].linkedTo))
50                                 pass
51                         elif config.Nims[self.nim.slotid].configMode.value == 2: # linked
52                                 pass
53                 
54                 elif (nimmanager.getNimType(self.nim.slotid) == nimmanager.nimType["DVB-C"]):
55                         self.list.append(getConfigListEntry(_("Cable provider"), config.Nims[self.nim.slotid].cable))
56                 elif (nimmanager.getNimType(self.nim.slotid) == nimmanager.nimType["DVB-T"]):
57                         self.list.append(getConfigListEntry(_("Terrestrial provider"), config.Nims[self.nim.slotid].terrestrial))
58
59
60                 self["config"].list = self.list
61                 self["config"].l.setList(self.list)
62                 
63         def newConfig(self):    
64                 if self["config"].getCurrent() == self.diseqcModeEntry:
65                         self.createSetup()
66                 if self["config"].getCurrent() == self.configMode:
67                         self.createSetup()
68                 
69         def keyLeft(self):
70                 if self["config"].getCurrent() == self.configMode:
71                         if self.nim.slotid == 0:
72                                 return
73                 self["config"].handleKey(config.key["prevElement"])
74                 self.newConfig()
75
76         def keyRight(self):
77                 #forbid to enable advanced mode until its ready
78                 #perhaps its better to use an own element here
79                 #this suckz .. how enable advanced config?
80                 if self["config"].getCurrent() == self.configMode:
81                         if self.nim.slotid == 0:
82                                 return
83
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 keySave(self):
98                 self.run()
99                 self.close()
100
101         def keyCancel(self):
102                 for x in self["config"].list:
103                         x[1].cancel()
104                 self.close()
105
106         def __init__(self, session, slotid):
107                 Screen.__init__(self, session)
108                 
109                 self.nim = nimmanager.nimList()[slotid][1]
110                 
111                 self["actions"] = NumberActionMap(["SetupActions"],
112                 {
113                         "ok": self.keySave,
114                         "cancel": self.keyCancel,
115                         "left": self.keyLeft,
116                         "right": self.keyRight,
117                         "1": self.keyNumberGlobal,
118                         "2": self.keyNumberGlobal,
119                         "3": self.keyNumberGlobal,
120                         "4": self.keyNumberGlobal,
121                         "5": self.keyNumberGlobal,
122                         "6": self.keyNumberGlobal,
123                         "7": self.keyNumberGlobal,
124                         "8": self.keyNumberGlobal,
125                         "9": self.keyNumberGlobal,
126                         "0": self.keyNumberGlobal
127                 }, -1)
128
129                 self.list = [ ]
130                 self["config"] = ConfigList(self.list)
131                 
132                 self.createSetup()
133
134 class NimSelection(Screen):
135         def __init__(self, session):
136                 Screen.__init__(self, session)
137
138                 self["nimlist"] = MenuList(nimmanager.nimList())
139
140                 self["actions"] = ActionMap(["OkCancelActions"],
141                 {
142                         "ok": self.okbuttonClick ,
143                         "cancel": self.close
144                 }, -1)
145
146         def okbuttonClick(self):
147                 selection = self["nimlist"].getCurrent()
148                 if selection[1].nimType != -1:  #unknown/empty
149                         self.session.open(NimSetup, selection[1].slotid)
150