-class NetworkSetup(Screen):
- def __init__(self, session):
- Screen.__init__(self, session)
-
- self["actions"] = NumberActionMap(["SetupActions"],
- {
- "ok": self.keySave,
- "cancel": self.keyCancel,
- "left": self.keyLeft,
- "right": self.keyRight,
- "1": self.keyNumberGlobal,
- "2": self.keyNumberGlobal,
- "3": self.keyNumberGlobal,
- "4": self.keyNumberGlobal,
- "5": self.keyNumberGlobal,
- "6": self.keyNumberGlobal,
- "7": self.keyNumberGlobal,
- "8": self.keyNumberGlobal,
- "9": self.keyNumberGlobal,
- "0": self.keyNumberGlobal
- }, -1)
-
- self.list = []
- self["config"] = ConfigList(self.list)
- self.createSetup()
-
- def createSetup(self):
- self.list = []
-
- self.list.append(getConfigListEntry("Use DHCP", config.network.dhcp))
- if (config.network.dhcp.value == 0):
- self.list.append(getConfigListEntry("IP Address", config.network.ip))
- self.list.append(getConfigListEntry("Netmask", config.network.netmask))
- self.list.append(getConfigListEntry("Gateway", config.network.gateway))
- self.list.append(getConfigListEntry("Nameserver", config.network.dns))
-
- self["config"].list = self.list
- self["config"].l.setList(self.list)
-
- def newConfig(self):
- print self["config"].getCurrent()
- if self["config"].getCurrent()[0] == "Use DHCP":
- self.createSetup()
-
- def keyLeft(self):
- self["config"].handleKey(config.key["prevElement"])
- self.newConfig()
-
- def keyRight(self):
- self["config"].handleKey(config.key["nextElement"])
- self.newConfig()
-
- def keyNumberGlobal(self, number):
- print "You pressed number " + str(number)
- if (self["config"].getCurrent()[1].parent.enabled == True):
- self["config"].handleKey(config.key[str(number)])
-
- def keySave(self):
- #for x in self["config"].list:
- #x[1].save()
+
+class NetworkAdapterSelection(Screen):
+ def __init__(self, session):
+ Screen.__init__(self, session)
+
+ self["adapterlist"] = MenuList(iNetwork.getAdapterList())
+
+ self["actions"] = ActionMap(["OkCancelActions"],
+ {
+ "ok": self.okbuttonClick ,
+ "cancel": self.close
+ })
+
+ def okbuttonClick(self):
+ selection = self["adapterlist"].getCurrent()
+ print "selection:", selection
+ if selection is not None:
+ self.session.open(AdapterSetup, selection)
+
+class NameserverSetup(Screen, ConfigListScreen):
+ def __init__(self, session):
+ Screen.__init__(self, session)
+ self.backupNameserverList = iNetwork.getNameserverList()[:]
+ print "backup-list:", self.backupNameserverList
+
+ self["red"] = Label(_("Delete"))
+ self["green"] = Label(_("Add"))
+
+ self.createConfig()
+
+ self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
+ {
+ "ok": self.ok,
+ "cancel": self.cancel,
+ "green": self.add,
+ "red": self.remove
+ }, -2)
+
+ self.list = []
+ ConfigListScreen.__init__(self, self.list)
+ self.createSetup()
+
+ def createConfig(self):
+ self.nameservers = iNetwork.getNameserverList()
+ self.nameserverEntries = []
+
+ for nameserver in self.nameservers:
+ self.nameserverEntries.append(NoSave(ConfigIP(default=nameserver)))
+
+ def createSetup(self):
+ self.list = []
+
+ #self.nameserverConfigEntries = []
+ for i in range(len(self.nameserverEntries)):
+ self.list.append(getConfigListEntry(_("Nameserver %d") % (i + 1), self.nameserverEntries[i]))
+
+ self["config"].list = self.list
+ self["config"].l.setList(self.list)
+
+ def ok(self):
+ iNetwork.clearNameservers()
+ for nameserver in self.nameserverEntries:
+ iNetwork.addNameserver(nameserver.value)
+ iNetwork.writeNameserverConfig()
+ self.close()
+
+ def cancel(self):
+ iNetwork.clearNameservers()
+ print "backup-list:", self.backupNameserverList
+ for nameserver in self.backupNameserverList:
+ iNetwork.addNameserver(nameserver)
+ self.close()
+
+ def add(self):
+ iNetwork.addNameserver([0,0,0,0])
+ self.createConfig()
+ self.createSetup()
+
+ def remove(self):
+ print "currentIndex:", self["config"].getCurrentIndex()
+
+ index = self["config"].getCurrentIndex()
+ if index < len(self.nameservers):
+ iNetwork.removeNameserver(self.nameservers[index])
+ self.createConfig()
+ self.createSetup()
+
+
+class AdapterSetup(Screen, ConfigListScreen):
+ def __init__(self, session, iface):
+ Screen.__init__(self, session)
+
+ self.iface = iface
+
+ print iNetwork.getAdapterAttribute(self.iface, "dhcp")
+ self.dhcpConfigEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "dhcp")))
+ self.hasGatewayConfigEntry = NoSave(ConfigYesNo(default=True))
+ self.ipConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")))
+ self.netmaskConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask")))
+ self.gatewayConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway")))