+ iNetwork.restartNetwork(self.applyConfigDataAvail)
+ self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
+ else:
+ self.cancel()
+
+ def applyConfigDataAvail(self, data):
+ if data is True:
+ iNetwork.getInterfaces(self.getInterfacesDataAvail)
+
+ def getInterfacesDataAvail(self, data):
+ if data is True:
+ self.applyConfigRef.close(True)
+
+ def applyConfigfinishedCB(self,data):
+ if data is True:
+ num_configured_if = len(iNetwork.getConfiguredAdapters())
+ if num_configured_if >= 2:
+ self.session.openWithCallback(self.secondIfaceFoundCB, MessageBox, _("Your network configuration has been activated.\nA second configured interface has been found.\n\nDo you want to disable the second network interface?"), default = True)
+ else:
+ if self.finished_cb:
+ self.session.openWithCallback(lambda x : self.finished_cb(), MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
+ else:
+ self.session.openWithCallback(self.ConfigfinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
+
+ def secondIfaceFoundCB(self,data):
+ if data is False:
+ self.close('ok')
+ else:
+ configuredInterfaces = iNetwork.getConfiguredAdapters()
+ for interface in configuredInterfaces:
+ if interface == self.iface:
+ continue
+ iNetwork.setAdapterAttribute(interface, "up", False)
+ iNetwork.deactivateInterface(interface)
+ self.applyConfig(True)
+
+ def ConfigfinishedCB(self,data):
+ if data is not None:
+ if data is True:
+ self.close('ok')
+
+ def cancel(self):
+ if self.oldInterfaceState is False:
+ iNetwork.deactivateInterface(self.iface,self.cancelCB)
+ else:
+ self.close('cancel')
+
+ def cancelCB(self,data):
+ if data is not None:
+ if data is True:
+ self.close('cancel')
+
+ def runAsync(self, finished_cb):
+ self.finished_cb = finished_cb
+ self.ok()
+
+ def NameserverSetupClosed(self, *ret):
+ iNetwork.loadNameserverConfig()
+ nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
+ self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
+ self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
+ self.createSetup()
+ self.layoutFinished()
+
+ def cleanup(self):
+ iNetwork.stopLinkStateConsole()
+
+
+class AdapterSetupConfiguration(Screen, HelpableScreen):
+ def __init__(self, session,iface):
+ Screen.__init__(self, session)
+ HelpableScreen.__init__(self)
+ self.session = session
+ self.iface = iface
+ self.restartLanRef = None
+ self.mainmenu = self.genMainMenu()
+ self["menulist"] = MenuList(self.mainmenu)
+ self["key_red"] = StaticText(_("Close"))
+ self["description"] = StaticText()
+ self["IFtext"] = StaticText()
+ self["IF"] = StaticText()
+ self["Statustext"] = StaticText()
+ self["statuspic"] = MultiPixmap()
+ self["statuspic"].hide()
+
+ self.oktext = _("Press OK on your remote control to continue.")
+ self.reboottext = _("Your Dreambox will restart after pressing OK on your remote control.")
+ self.errortext = _("No working wireless network interface found.\n Please verify that you have attached a compatible WLAN device or enable your local network interface.")
+
+ self["WizardActions"] = HelpableActionMap(self, "WizardActions",
+ {
+ "up": (self.up, _("move up to previous entry")),
+ "down": (self.down, _("move down to next entry")),
+ "left": (self.left, _("move up to first entry")),
+ "right": (self.right, _("move down to last entry")),
+ })
+
+ self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
+ {
+ "cancel": (self.close, _("exit networkadapter setup menu")),
+ "ok": (self.ok, _("select menu entry")),
+ })
+
+ self["ColorActions"] = HelpableActionMap(self, "ColorActions",
+ {
+ "red": (self.close, _("exit networkadapter setup menu")),
+ })
+
+ self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
+ {
+ "ok": self.ok,
+ "back": self.close,
+ "up": self.up,
+ "down": self.down,
+ "red": self.close,
+ "left": self.left,
+ "right": self.right,
+ }, -2)
+
+ self.updateStatusbar()
+ self.onLayoutFinish.append(self.layoutFinished)
+ self.onClose.append(self.cleanup)
+
+ def ok(self):
+ if self["menulist"].getCurrent()[1] == 'edit':
+ if self.iface == 'wlan0' or self.iface == 'ath0':
+ try:
+ from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
+ from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
+ except ImportError:
+ self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
+ else:
+ ifobj = Wireless(self.iface) # a Wireless NIC Object
+ self.wlanresponse = ifobj.getStatistics()
+ if self.wlanresponse[0] != 19: # Wlan Interface found.
+ self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
+ else:
+ # Display Wlan not available Message
+ self.showErrorMessage()
+ else:
+ self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
+ if self["menulist"].getCurrent()[1] == 'test':
+ self.session.open(NetworkAdapterTest,self.iface)
+ if self["menulist"].getCurrent()[1] == 'dns':
+ self.session.open(NameserverSetup)
+ if self["menulist"].getCurrent()[1] == 'scanwlan':
+ try:
+ from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
+ from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
+ except ImportError:
+ self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
+ else:
+ ifobj = Wireless(self.iface) # a Wireless NIC Object
+ self.wlanresponse = ifobj.getStatistics()
+ if self.wlanresponse[0] != 19:
+ self.session.openWithCallback(self.WlanScanClosed, WlanScan, self.iface)
+ else:
+ # Display Wlan not available Message
+ self.showErrorMessage()
+ if self["menulist"].getCurrent()[1] == 'wlanstatus':
+ try:
+ from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
+ from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
+ except ImportError:
+ self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
+ else:
+ ifobj = Wireless(self.iface) # a Wireless NIC Object
+ self.wlanresponse = ifobj.getStatistics()
+ if self.wlanresponse[0] != 19:
+ self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
+ else:
+ # Display Wlan not available Message
+ self.showErrorMessage()
+ if self["menulist"].getCurrent()[1] == 'lanrestart':
+ self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
+ if self["menulist"].getCurrent()[1] == 'openwizard':
+ from Plugins.SystemPlugins.NetworkWizard.NetworkWizard import NetworkWizard
+ self.session.openWithCallback(self.AdapterSetupClosed, NetworkWizard)
+ if self["menulist"].getCurrent()[1][0] == 'extendedSetup':
+ self.extended = self["menulist"].getCurrent()[1][2]
+ self.extended(self.session, self.iface)
+
+ def up(self):
+ self["menulist"].up()
+ self.loadDescription()
+
+ def down(self):
+ self["menulist"].down()
+ self.loadDescription()
+
+ def left(self):
+ self["menulist"].pageUp()
+ self.loadDescription()
+
+ def right(self):
+ self["menulist"].pageDown()
+ self.loadDescription()
+
+ def layoutFinished(self):
+ idx = 0
+ self["menulist"].moveToIndex(idx)
+ self.loadDescription()
+
+ def loadDescription(self):
+ print self["menulist"].getCurrent()[1]
+ if self["menulist"].getCurrent()[1] == 'edit':
+ self["description"].setText(_("Edit the network configuration of your Dreambox.\n" ) + self.oktext )
+ if self["menulist"].getCurrent()[1] == 'test':
+ self["description"].setText(_("Test the network configuration of your Dreambox.\n" ) + self.oktext )
+ if self["menulist"].getCurrent()[1] == 'dns':
+ self["description"].setText(_("Edit the Nameserver configuration of your Dreambox.\n" ) + self.oktext )
+ if self["menulist"].getCurrent()[1] == 'scanwlan':
+ self["description"].setText(_("Scan your network for wireless Access Points and connect to them using your selected wireless device.\n" ) + self.oktext )
+ if self["menulist"].getCurrent()[1] == 'wlanstatus':
+ self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
+ if self["menulist"].getCurrent()[1] == 'lanrestart':
+ self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
+ if self["menulist"].getCurrent()[1] == 'openwizard':
+ self["description"].setText(_("Use the Networkwizard to configure your Network\n" ) + self.oktext )
+ if self["menulist"].getCurrent()[1][0] == 'extendedSetup':
+ self["description"].setText(_(self["menulist"].getCurrent()[1][1]) + self.oktext )
+
+ def updateStatusbar(self, data = None):
+ self["IFtext"].setText(_("Network:"))
+ self["IF"].setText(iNetwork.getFriendlyAdapterName(self.iface))
+ self["Statustext"].setText(_("Link:"))
+
+ if self.iface == 'wlan0' or self.iface == 'ath0':
+ try:
+ from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+ except:
+ self["statuspic"].setPixmapNum(1)
+ self["statuspic"].show()
+ else:
+ iStatus.getDataForInterface(self.iface,self.getInfoCB)
+ else:
+ iNetwork.getLinkState(self.iface,self.dataAvail)
+
+ def doNothing(self):
+ pass
+
+ def genMainMenu(self):
+ menu = []
+ menu.append((_("Adapter settings"), "edit"))
+ menu.append((_("Nameserver settings"), "dns"))
+ menu.append((_("Network test"), "test"))
+ menu.append((_("Restart network"), "lanrestart"))
+
+ self.extended = None
+ self.extendedSetup = None
+ for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
+ callFnc = p.__call__["ifaceSupported"](self.iface)
+ if callFnc is not None:
+ self.extended = callFnc
+ print p.__call__
+ if p.__call__.has_key("WlanPluginEntry"): # internally used only for WLAN Plugin
+ menu.append((_("Scan Wireless Networks"), "scanwlan"))
+ if iNetwork.getAdapterAttribute(self.iface, "up"):
+ menu.append((_("Show WLAN Status"), "wlanstatus"))
+ else:
+ if p.__call__.has_key("menuEntryName"):
+ menuEntryName = p.__call__["menuEntryName"](self.iface)
+ else:
+ menuEntryName = _('Extended Setup...')
+ if p.__call__.has_key("menuEntryDescription"):
+ menuEntryDescription = p.__call__["menuEntryDescription"](self.iface)
+ else:
+ menuEntryDescription = _('Extended Networksetup Plugin...')
+ self.extendedSetup = ('extendedSetup',menuEntryDescription, self.extended)
+ menu.append((menuEntryName,self.extendedSetup))
+
+ if os_path.exists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")):
+ menu.append((_("NetworkWizard"), "openwizard"))
+
+ return menu
+
+ def AdapterSetupClosed(self, *ret):
+ if ret is not None and len(ret):
+ if ret[0] == 'ok' and (self.iface == 'wlan0' or self.iface == 'ath0') and iNetwork.getAdapterAttribute(self.iface, "up") is True:
+ try:
+ from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
+ from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
+ except ImportError:
+ self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
+ else:
+ ifobj = Wireless(self.iface) # a Wireless NIC Object
+ self.wlanresponse = ifobj.getStatistics()
+ if self.wlanresponse[0] != 19:
+ self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
+ else:
+ # Display Wlan not available Message
+ self.showErrorMessage()
+ else:
+ self.mainmenu = self.genMainMenu()
+ self["menulist"].l.setList(self.mainmenu)
+ self.updateStatusbar()
+ else:
+ self.mainmenu = self.genMainMenu()
+ self["menulist"].l.setList(self.mainmenu)
+ self.updateStatusbar()
+
+ def WlanStatusClosed(self, *ret):
+ if ret is not None and len(ret):
+ from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+ iStatus.stopWlanConsole()
+ self.mainmenu = self.genMainMenu()
+ self["menulist"].l.setList(self.mainmenu)
+ self.updateStatusbar()
+
+ def WlanScanClosed(self,*ret):
+ if ret[0] is not None:
+ self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0],ret[1])
+ else:
+ from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+ iStatus.stopWlanConsole()
+ self.mainmenu = self.genMainMenu()
+ self["menulist"].l.setList(self.mainmenu)
+ self.updateStatusbar()
+
+ def restartLan(self, ret = False):
+ if (ret == True):
+ iNetwork.restartNetwork(self.restartLanDataAvail)
+ self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)
+
+ def restartLanDataAvail(self, data):
+ if data is True:
+ iNetwork.getInterfaces(self.getInterfacesDataAvail)
+
+ def getInterfacesDataAvail(self, data):
+ if data is True:
+ self.restartLanRef.close(True)
+
+ def restartfinishedCB(self,data):
+ if data is True:
+ self.updateStatusbar()
+ self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 10, default = False)
+
+ def dataAvail(self,data):
+ self.output = data.strip()
+ result = self.output.split('\n')
+ pattern = re_compile("Link detected: yes")
+ for item in result:
+ if re_search(pattern, item):
+ self["statuspic"].setPixmapNum(0)
+ else:
+ self["statuspic"].setPixmapNum(1)
+ self["statuspic"].show()
+
+ def showErrorMessage(self):
+ self.session.open(MessageBox, self.errortext, type = MessageBox.TYPE_INFO,timeout = 10 )
+
+ def cleanup(self):
+ iNetwork.stopLinkStateConsole()
+ iNetwork.stopDeactivateInterfaceConsole()
+ try:
+ from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+ except ImportError:
+ pass
+ else:
+ iStatus.stopWlanConsole()
+
+ def getInfoCB(self,data,status):
+ if data is not None:
+ if data is True:
+ if status is not None:
+ if status[self.iface]["acesspoint"] == "No Connection" or status[self.iface]["acesspoint"] == "Not-Associated" or status[self.iface]["acesspoint"] == False:
+ self["statuspic"].setPixmapNum(1)
+ else:
+ self["statuspic"].setPixmapNum(0)
+ self["statuspic"].show()
+
+class NetworkAdapterTest(Screen):
+ def __init__(self, session,iface):
+ Screen.__init__(self, session)
+ self.iface = iface
+ self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
+ self.setLabels()
+ self.onClose.append(self.cleanup)
+ self.onHide.append(self.cleanup)
+
+ self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
+ {
+ "ok": self.KeyOK,
+ "blue": self.KeyOK,
+ "up": lambda: self.updownhandler('up'),
+ "down": lambda: self.updownhandler('down'),
+
+ }, -2)
+
+ self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
+ {
+ "red": self.cancel,
+ "back": self.cancel,
+ }, -2)
+ self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
+ {
+ "red": self.closeInfo,
+ "back": self.closeInfo,
+ }, -2)
+ self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
+ {
+ "green": self.KeyGreen,
+ }, -2)
+ self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
+ {
+ "green": self.KeyGreenRestart,
+ }, -2)
+ self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
+ {
+ "yellow": self.KeyYellow,
+ }, -2)
+
+ self["shortcutsgreen_restart"].setEnabled(False)
+ self["updown_actions"].setEnabled(False)
+ self["infoshortcuts"].setEnabled(False)
+ self.onClose.append(self.delTimer)
+ self.onLayoutFinish.append(self.layoutFinished)
+ self.steptimer = False
+ self.nextstep = 0
+ self.activebutton = 0
+ self.nextStepTimer = eTimer()
+ self.nextStepTimer.callback.append(self.nextStepTimerFire)