- added resolv.conf parsing
[enigma2.git] / lib / python / Screens / NetworkSetup.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.ConfigList import ConfigList
4 from Components.config import config
5 from Components.config import getConfigListEntry
6 from Components.Network import iNetwork
7
8 class NetworkSetup(Screen):
9     def __init__(self, session):
10         Screen.__init__(self, session)
11         
12         self["actions"] = ActionMap(["SetupActions"],
13         {
14             "ok": self.keySave,
15             "cancel": self.keyCancel,
16             "left": self.keyLeft,
17             "right": self.keyRight,
18             "1": self.keyNumber1,
19             "2": self.keyNumber2,
20             "3": self.keyNumber3,
21             "4": self.keyNumber4,
22             "5": self.keyNumber5,
23             "6": self.keyNumber6,
24             "7": self.keyNumber7,
25             "8": self.keyNumber8,
26             "9": self.keyNumber9,
27             "0": self.keyNumber0
28         }, -1)
29
30         self.list = []
31         self["config"] = ConfigList(self.list)
32         self.createSetup()
33         
34     def createSetup(self):
35         self.list = []
36         
37         self.list.append(getConfigListEntry("Use DHCP", config.network.dhcp))
38         if (config.network.dhcp.value == 0):
39             self.list.append(getConfigListEntry("IP Address", config.network.ip))
40             self.list.append(getConfigListEntry("Netmask", config.network.netmask))
41             self.list.append(getConfigListEntry("Gateway", config.network.gateway))
42             self.list.append(getConfigListEntry("Nameserver", config.network.dns))
43         
44         self["config"].list = self.list
45         self["config"].l.setList(self.list)
46         
47     def newConfig(self):
48         print self["config"].getCurrent()
49         if self["config"].getCurrent()[0] == "Use DHCP":
50             self.createSetup()
51
52     def keyLeft(self):
53         self["config"].handleKey(config.key["prevElement"])
54         self.newConfig()
55
56     def keyRight(self):
57         self["config"].handleKey(config.key["nextElement"])
58         self.newConfig()
59     
60     def keyNumberGlobal(self, number):
61         print "You pressed number " + str(number)
62         if (self["config"].getCurrent()[1].parent.enabled == True):
63             self["config"].handleKey(config.key[str(number)])
64         
65     def keyNumber1(self):
66         self.keyNumberGlobal(1)
67     def keyNumber2(self):
68         self.keyNumberGlobal(2)
69     def keyNumber3(self):
70         self.keyNumberGlobal(3)
71     def keyNumber4(self):
72         self.keyNumberGlobal(4)
73     def keyNumber5(self):
74         self.keyNumberGlobal(5)
75     def keyNumber6(self):
76         self.keyNumberGlobal(6)
77     def keyNumber7(self):
78         self.keyNumberGlobal(7)
79     def keyNumber8(self):
80         self.keyNumberGlobal(8)
81     def keyNumber9(self):
82         self.keyNumberGlobal(9)
83     def keyNumber0(self):
84         self.keyNumberGlobal(0)        
85
86     def keySave(self):
87         #for x in self["config"].list:
88             #x[1].save()
89         
90         iNetwork.writeNetworkConfig()    
91         iNetwork.activateNetworkConfig()
92         self.close()
93
94     def keyCancel(self):
95         for x in self["config"].list:
96             x[1].cancel()
97         iNetwork.loadNetworkConfig()
98         self.close()