parsing for /etc/timezone.xml added
[enigma2.git] / lib / python / Screens / NetworkSetup.py
1 from Screen import Screen
2 from Components.ActionMap import NumberActionMap
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 from Components.Label import Label
8
9 class NetworkSetup(Screen):
10     def __init__(self, session):
11         Screen.__init__(self, session)
12         
13         self["actions"] = NumberActionMap(["SetupActions"],
14         {
15             "ok": self.keySave,
16             "cancel": self.keyCancel,
17             "left": self.keyLeft,
18             "right": self.keyRight,
19             "1": self.keyNumberGlobal,
20             "2": self.keyNumberGlobal,
21             "3": self.keyNumberGlobal,
22             "4": self.keyNumberGlobal,
23             "5": self.keyNumberGlobal,
24             "6": self.keyNumberGlobal,
25             "7": self.keyNumberGlobal,
26             "8": self.keyNumberGlobal,
27             "9": self.keyNumberGlobal,
28             "0": self.keyNumberGlobal
29         }, -1)
30
31         self.list = []
32         self["config"] = ConfigList(self.list)
33         self.createSetup()
34         
35         self["introduction"] = Label("Press OK to activate the settings.")
36         
37     def createSetup(self):
38         self.list = []
39         
40         self.list.append(getConfigListEntry("Use DHCP", config.network.dhcp))
41         if (config.network.dhcp.value == 0):
42             self.list.append(getConfigListEntry("IP Address", config.network.ip))
43             self.list.append(getConfigListEntry("Netmask", config.network.netmask))
44             self.list.append(getConfigListEntry("Gateway", config.network.gateway))
45             self.list.append(getConfigListEntry("Nameserver", config.network.dns))
46         
47         self["config"].list = self.list
48         self["config"].l.setList(self.list)
49         
50     def newConfig(self):
51         print self["config"].getCurrent()
52         if self["config"].getCurrent()[0] == "Use DHCP":
53             self.createSetup()
54
55     def keyLeft(self):
56         self["config"].handleKey(config.key["prevElement"])
57         self.newConfig()
58
59     def keyRight(self):
60         self["config"].handleKey(config.key["nextElement"])
61         self.newConfig()
62     
63     def keyNumberGlobal(self, number):
64         print "You pressed number " + str(number)
65         if (self["config"].getCurrent()[1].parent.enabled == True):
66             self["config"].handleKey(config.key[str(number)])
67         
68     def keySave(self):
69         #for x in self["config"].list:
70             #x[1].save()
71         
72         iNetwork.writeNetworkConfig()    
73         iNetwork.activateNetworkConfig()
74         self.close()
75
76     def keyCancel(self):
77         for x in self["config"].list:
78             x[1].cancel()
79         iNetwork.loadNetworkConfig()
80         self.close()