cleanup the plugins to fit the new namespace
[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.dhcpEntry = getConfigListEntry(_("Use DHCP"), config.network.dhcp)
41                 self.list.append(self.dhcpEntry)
42                 self.list.append(getConfigListEntry(_('IP Address'), config.network.ip))
43                 if (config.network.dhcp.value == 0):
44                         self.list.append(getConfigListEntry(_('Netmask'), config.network.netmask))
45                         self.list.append(getConfigListEntry(_('Gateway'), config.network.gateway))
46                         self.list.append(getConfigListEntry(_('Nameserver'), config.network.dns))
47         
48                 self["config"].list = self.list
49                 self["config"].l.setList(self.list)
50         
51         def newConfig(self):
52                 print self["config"].getCurrent()
53                 if self["config"].getCurrent() == self.dhcpEntry:
54                         self.createSetup()
55
56         def keyLeft(self):
57                 self["config"].handleKey(config.key["prevElement"])
58                 self.newConfig()
59
60         def keyRight(self):
61                 self["config"].handleKey(config.key["nextElement"])
62                 self.newConfig()
63     
64         def keyNumberGlobal(self, number):
65                 print "You pressed number " + str(number)
66                 if (self["config"].getCurrent()[1].parent.enabled == True):
67                         self["config"].handleKey(config.key[str(number)])
68         
69         def keySave(self):
70                 #for x in self["config"].list:
71                         #x[1].save()
72         
73                 iNetwork.writeNetworkConfig()    
74                 iNetwork.activateNetworkConfig()
75                 self.close()
76
77         def keyCancel(self):
78                 for x in self["config"].list:
79                         x[1].cancel()
80                 iNetwork.loadNetworkConfig()
81                 self.close()