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