def buildGui(self): layout = QFormLayout(self) self.is_default = False self.setTitle(tr("Route specification")) self.setSubTitle(tr("Specify a route")) self.network = NetworkCombo(parent=self, modelname=MODEL_NETWORKS_EXCL_HA) layout.addRow(tr("Network :"), self.network) dst_group = QGroupBox() layout.addRow(dst_group) dst_group.setTitle(tr("Route parameters")) form = QGridLayout(dst_group) self.destination = NetworkEdit() self.gateway = IpEdit() self.registerField("destination", self.destination) form.addWidget(QLabel(tr("Destination")), 0, 0) form.addWidget(self.destination, 0, 1) self.connect(self.gateway, SIGNAL('textChanged(QString)'), self.ifCompleteChanged) self.connect(self.destination, SIGNAL('textChanged(QString)'), self.ifCompleteChanged) build_default = QPushButton(tr("Build a default route")) form.addWidget(build_default, 0, 2) self.connect(build_default, SIGNAL('clicked()'), self.setDefaultRoute) self.registerField("gateway", self.gateway) form.addWidget(QLabel(tr("Gateway")), 2, 0) form.addWidget(self.gateway, 2, 1) self.message = Help() form.addWidget(self.message, 3, 0, 1, 3)
class FormPage(QWizardPage): def __init__(self, data, ip_version=4, parent=None): QWizardPage.__init__(self, parent) self.__editing_default_state = _strdefault(unicode(data[DESTINATION])) self.qnetobject = QNetObject.getInstance() self.buildGui() self.fillView(data) def _isEditingDefaultV4Route(self): return self.__editing_default_state == 4 def _isEditingDefaultV6Route(self): return self.__editing_default_state == 6 def buildGui(self): layout = QFormLayout(self) self.is_default = False self.setTitle(tr("Route specification")) self.setSubTitle(tr("Specify a route")) self.network = NetworkCombo(parent=self, modelname=MODEL_NETWORKS_EXCL_HA) layout.addRow(tr("Network :"), self.network) dst_group = QGroupBox() layout.addRow(dst_group) dst_group.setTitle(tr("Route parameters")) form = QGridLayout(dst_group) self.destination = NetworkEdit() self.gateway = IpEdit() self.registerField("destination", self.destination) form.addWidget(QLabel(tr("Destination")), 0, 0) form.addWidget(self.destination, 0, 1) self.connect(self.gateway, SIGNAL('textChanged(QString)'), self.ifCompleteChanged) self.connect(self.destination, SIGNAL('textChanged(QString)'), self.ifCompleteChanged) build_default = QPushButton(tr("Build a default route")) form.addWidget(build_default, 0, 2) self.connect(build_default, SIGNAL('clicked()'), self.setDefaultRoute) self.registerField("gateway", self.gateway) form.addWidget(QLabel(tr("Gateway")), 2, 0) form.addWidget(self.gateway, 2, 1) self.message = Help() form.addWidget(self.message, 3, 0, 1, 3) def fillView(self, data): if data[DESTINATION]: self.destination.setText(data[DESTINATION]) if data[GATEWAY]: self.gateway.setText(data[GATEWAY]) gateway = IP(unicode(data[GATEWAY])) net = self.qnetobject.netcfg.getNetForIp(gateway) if net is not None: self.network.selectNet(net) def ifCompleteChanged(self, orig_value=False): new_value = self.isComplete() if new_value != orig_value: self.emit(SIGNAL('completeChanged()')) def setDefaultRoute(self): selected_net = self.network.getNet() if selected_net is None: self.message.setMessage("<i>%s</i>" % tr("There is no network configuration, you cannot configure routes")) version = 4 else: version = selected_net.net.version() if 4 == version: default = Route.IPV4_DEFAULT else: default = Route.IPV6_DEFAULT self.destination.setText(default) def isComplete(self): gw_text = unicode(self.field('gateway').toString()) dst_text = unicode(self.field('destination').toString()) if not gw_text: self.message.setMessage("<i>%s</i>" % tr("Please fill the gateway field")) return False if (not self.gateway.isValid()): self.message.setMessage("<i>%s</i>" % tr("Invalid gateway")) return False if not dst_text: self.message.setMessage("<i>%s</i>" % tr("Please fill the destination field")) return False if not self.destination.isValid(): self.message.setMessage("<i>%s</i>" % tr("Invalid destination")) return False destination_version, gateway_version = \ (item.version() for item in (self.destination.value(), self.gateway.value())) if destination_version != gateway_version: error = "%s (%s) %s (%s)." % ( tr("The gateway IP version"), gateway_version, tr("does not match the destination IP version"), destination_version ) self.message.setMessage(error) return False str_gateway = unicode(self.field('gateway').toString()) gateway_ip = IP(str_gateway) selected_net = self.network.getNet() if selected_net is None: self.message.setMessage("<i>%s</i>" % tr("There is no network configuration, you cannot configure routes")) return False ok, msg = _valid_gateway_on_network(gateway_ip, str_gateway, selected_net) if not ok: self.message.setMessage(msg) return False ok, msg = _valid_not_too_much_default_gw( self.qnetobject.netcfg, self.destination.value(), destination_version, self._isEditingDefaultV4Route(), self._isEditingDefaultV6Route() ) if not ok: self.message.setMessage(msg) return False ok, msg = self.qnetobject.netcfg.isValidWithMsg() if not ok: self.message.setMessage(msg) return False self.message.setNoMessage() return True def validatePage(self): route = self.integrate_route() if not route.isDefault(): return True try: default_router, interface = self.qnetobject.netcfg.getDefaultGateway( route.dst.version() ) except NoMatch: return True default_route = None for other_route in interface.routes: if other_route.isDefault(): default_route = other_route if default_route is not None: interface.routes.discard(default_route) ok, msg = self.qnetobject.netcfg.isValidWithMsg() if not ok: self.message.setMessage(msg) return False return True def integrate_route(self): route = RouteRW( self.destination.value(), self.gateway.value(), ) return route