1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.ConfigList import ConfigListScreen
4 from Components.config import config, getConfigListEntry
5 from Components.Network import iNetwork
6 from Components.Label import Label
7 from Components.MenuList import MenuList
8 from Components.config import config, ConfigYesNo, ConfigIP, NoSave, ConfigNothing
9 from Components.PluginComponent import plugins
10 from Plugins.Plugin import PluginDescriptor
12 class NetworkAdapterSelection(Screen):
13 def __init__(self, session):
14 Screen.__init__(self, session)
16 self.adapters = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
18 self["adapterlist"] = MenuList(self.adapters)
19 self["actions"] = ActionMap(["OkCancelActions"],
21 "ok": self.okbuttonClick,
25 if len(self.adapters) == 1:
26 self.onFirstExecBegin.append(self.okbuttonClick)
28 def okbuttonClick(self):
29 selection = self["adapterlist"].getCurrent()
30 if selection is not None:
31 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, selection[1])
33 def AdapterSetupClosed(self, *ret):
34 if len(self.adapters) == 1: # just one network adapter.. close selection
37 class NameserverSetup(Screen, ConfigListScreen):
38 def __init__(self, session):
39 Screen.__init__(self, session)
40 self.backupNameserverList = iNetwork.getNameserverList()[:]
41 print "backup-list:", self.backupNameserverList
43 self["red"] = Label(_("Delete"))
44 self["green"] = Label(_("Add"))
48 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
51 "cancel": self.cancel,
57 ConfigListScreen.__init__(self, self.list)
60 def createConfig(self):
61 self.nameservers = iNetwork.getNameserverList()
62 self.nameserverEntries = []
64 for nameserver in self.nameservers:
65 self.nameserverEntries.append(NoSave(ConfigIP(default=nameserver)))
67 def createSetup(self):
70 #self.nameserverConfigEntries = []
71 for i in range(len(self.nameserverEntries)):
72 self.list.append(getConfigListEntry(_("Nameserver %d") % (i + 1), self.nameserverEntries[i]))
74 self["config"].list = self.list
75 self["config"].l.setList(self.list)
78 iNetwork.clearNameservers()
79 for nameserver in self.nameserverEntries:
80 iNetwork.addNameserver(nameserver.value)
81 iNetwork.writeNameserverConfig()
85 iNetwork.clearNameservers()
86 print "backup-list:", self.backupNameserverList
87 for nameserver in self.backupNameserverList:
88 iNetwork.addNameserver(nameserver)
92 iNetwork.addNameserver([0,0,0,0])
97 print "currentIndex:", self["config"].getCurrentIndex()
99 index = self["config"].getCurrentIndex()
100 if index < len(self.nameservers):
101 iNetwork.removeNameserver(self.nameservers[index])
105 class AdapterSetup(Screen, ConfigListScreen):
106 def __init__(self, session, iface):
107 Screen.__init__(self, session)
111 print iNetwork.getAdapterAttribute(self.iface, "dhcp")
112 self.dhcpConfigEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "dhcp") or False))
113 self.hasGatewayConfigEntry = NoSave(ConfigYesNo(default=True))
114 self.ipConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0])
115 self.netmaskConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0]))
116 self.gatewayConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0]))
118 self["iface"] = Label(iNetwork.getFriendlyAdapterName(self.iface))
120 self["actions"] = ActionMap(["SetupActions"],
123 "cancel": self.cancel,
127 ConfigListScreen.__init__(self, self.list)
130 self["introduction"] = Label(_("Press OK to activate the settings."))
131 self["introduction2"] = Label(_("Current settings:"))
133 self["IPtext"] = Label(_("IP Address"))
134 self["Netmasktext"] = Label(_("Netmask"))
135 self["Gatewaytext"] = Label(_("Gateway"))
137 self["IP"] = Label(self.ipConfigEntry.getText())
138 self["Mask"] = Label(self.netmaskConfigEntry.getText())
139 self["Gateway"] = Label(self.gatewayConfigEntry.getText())
141 def createSetup(self):
144 self.dhcpEntry = getConfigListEntry(_("Use DHCP"), self.dhcpConfigEntry)
145 self.list.append(self.dhcpEntry)
146 if not self.dhcpConfigEntry.value:
147 self.list.append(getConfigListEntry(_('IP Address'), self.ipConfigEntry))
148 self.list.append(getConfigListEntry(_('Netmask'), self.netmaskConfigEntry))
149 self.list.append(getConfigListEntry(_('Use a gateway'), self.hasGatewayConfigEntry))
150 if self.hasGatewayConfigEntry.value:
151 self.list.append(getConfigListEntry(_('Gateway'), self.gatewayConfigEntry))
154 self.extendedSetup = None
155 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
156 callFnc = p.__call__["ifaceSupported"](self.iface)
157 if callFnc is not None:
158 self.extended = callFnc
160 if p.__call__.has_key("configStrings"):
161 self.configStrings = p.__call__["configStrings"]
163 self.configStrings = None
165 if p.__call__.has_key("menuEntryName"):
166 menuEntryName = p.__call__["menuEntryName"](self.iface)
168 menuEntryName = _('Extended Setup...')
169 self.extendedSetup = getConfigListEntry(menuEntryName, NoSave(ConfigNothing()))
170 self.list.append(self.extendedSetup)
172 self["config"].list = self.list
173 self["config"].l.setList(self.list)
176 print self["config"].getCurrent()
177 if self["config"].getCurrent() == self.dhcpEntry:
181 ConfigListScreen.keyLeft(self)
185 ConfigListScreen.keyRight(self)
189 selection = self["config"].getCurrent()
190 if selection == self.extendedSetup:
191 self.extended(self.session, self.iface)
193 iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
194 iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
195 iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
196 if self.hasGatewayConfigEntry.value:
197 iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
199 iNetwork.removeAdapterAttribute(self.iface, "gateway")
201 if self.extended is not None and self.configStrings is not None:
202 iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
204 iNetwork.deactivateNetworkConfig()
205 iNetwork.writeNetworkConfig()
206 iNetwork.activateNetworkConfig()
210 iNetwork.getInterfaces()