Merge pull request #75 from mammonsama666/0207-dev

fix(confform): Set ipv6.address failed.
This commit is contained in:
chenlelin 2021-02-07 16:59:17 +08:00 committed by GitHub
commit 0df116d849
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 15 deletions

View File

@ -407,15 +407,35 @@ QString BackThread::getConnProp(QString connName)
if (line.startsWith("ipv4.addresses:")) { if (line.startsWith("ipv4.addresses:")) {
QString value = line.mid(15).trimmed(); QString value = line.mid(15).trimmed();
if (value == "--" || value == "") { if (value == "--" || value == "") {
rtn += "addr:|mask:|"; rtn += "v4addr:|mask:|";
} else { } else {
QString addr = value.split("/").at(0); QString addr = value.split("/").at(0);
QString mask = value.trimmed().split("/").at(1); QString mask = value.trimmed().split("/").at(1);
rtn += "addr:" + addr + "|"; rtn += "v4addr:" + addr + "|";
rtn += "mask:" + mask + "|"; rtn += "mask:" + mask + "|";
} }
} }
if (line.startsWith("ipv6.method:")) {
QString value = line.mid(12).trimmed();
if (value == "auto") {
rtn += "v6method:auto|v6addr:|";
} else {
rtn += "v6method:manual|";
}
}
if (line.startsWith("ipv6.addresses:")) {
QString value = line.mid(15).trimmed();
if (value == "--" || value == "") {
rtn += "v6addr:|";
} else {
QString addr = value.split("/").at(0);
rtn += "v6addr:" + addr + "|";
}
}
if (line.startsWith("ipv4.gateway:")) { if (line.startsWith("ipv4.gateway:")) {
QString value = line.mid(13).trimmed(); QString value = line.mid(13).trimmed();
if (value == "--" || value == "") { if (value == "--" || value == "") {

View File

@ -162,12 +162,12 @@ void ConfForm::mouseMoveEvent(QMouseEvent *event)
} }
//网络配置参数设置界面的显示内容 //网络配置参数设置界面的显示内容
void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QString addr, QString mask, QString gateway, QString dns, bool isActConf, bool isWiFi) void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QString v4addr, QString v6method, QString v6addr, QString mask, QString gateway, QString dns, bool isActConf, bool isWiFi)
{ {
this->isActConf = isActConf; this->isActConf = isActConf;
ui->leName->setText(connName); ui->leName->setText(connName);
lastConnName = connName; lastConnName = connName;
lastIpv4 = addr; lastIpv4 = v4addr;
netUuid = uuidName; netUuid = uuidName;
if (isWiFi) { if (isWiFi) {
@ -183,7 +183,11 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt
cbTypeChanged(1); cbTypeChanged(1);
} }
ui->leAddr->setText(addr); if (v6method == "manual") {
ui->leAddr_ipv6->setText(v6addr);
}
ui->leAddr->setText(v4addr);
ui->leGateway->setText(gateway); ui->leGateway->setText(gateway);
// 配置中有多个DNS只处理前两个 // 配置中有多个DNS只处理前两个
@ -250,7 +254,10 @@ void ConfForm::on_btnCreate_clicked()
} }
if (!ui->leAddr_ipv6->text().isEmpty()) { if (!ui->leAddr_ipv6->text().isEmpty()) {
QString cmdStr = "nmcli connection modify " + ui->leName->text() + " ipv6.addresses " + ui->leAddr_ipv6->text(); QString cmdStr = "nmcli connection modify " + ui->leName->text() + " ipv6.method manual ipv6.addresses " + ui->leAddr_ipv6->text();
Utils::m_system(cmdStr.toUtf8().data());
} else {
QString cmdStr = "nmcli connection modify " + ui->leName->text() + " ipv6.method auto";
Utils::m_system(cmdStr.toUtf8().data()); Utils::m_system(cmdStr.toUtf8().data());
} }
@ -343,9 +350,14 @@ void ConfForm::on_btnSave_clicked()
} }
} }
if (ui->cbType->currentIndex() == 1 && !ui->leAddr_ipv6->text().isEmpty()) { if (ui->cbType->currentIndex() == 1) {
QString cmdStr = "nmcli connection modify " + ui->leName->text() + " ipv6.addresses " + ui->leAddr_ipv6->text(); if (!ui->leAddr_ipv6->text().isEmpty()) {
QString cmdStr = "nmcli connection modify " + ui->leName->text() + " ipv6.method manual ipv6.addresses " + ui->leAddr_ipv6->text();
Utils::m_system(cmdStr.toUtf8().data()); Utils::m_system(cmdStr.toUtf8().data());
} else {
QString cmdStr = "nmcli connection modify " + ui->leName->text() + " ipv6.method auto";
Utils::m_system(cmdStr.toUtf8().data());
}
} }
QString txt(tr("New network settings already finished")); QString txt(tr("New network settings already finished"));

View File

@ -40,7 +40,7 @@ public:
explicit ConfForm(QWidget *parent = 0); explicit ConfForm(QWidget *parent = 0);
~ConfForm(); ~ConfForm();
void setProp(QString connName, QString uuidName, QString v4method, QString addr, QString mask, QString gateway, QString dns, bool isActConf, bool isWiFi); void setProp(QString connName, QString uuidName, QString v4method, QString v4addr, QString v6method, QString v6addr, QString mask, QString gateway, QString dns, bool isActConf, bool isWiFi);
public slots: public slots:
void cbTypeChanged(int index); void cbTypeChanged(int index);

View File

@ -791,7 +791,7 @@ void OneConnForm::on_btnInfo_clicked()
BackThread *bt = new BackThread(); BackThread *bt = new BackThread();
QString connProp = bt->getConnProp(lbNameText->text()); QString connProp = bt->getConnProp(lbNameText->text());
QStringList propList = connProp.split("|"); QStringList propList = connProp.split("|");
QString v4method, addr, mask, gateway, dns; QString v4method, addr, mask, gateway, dns, v6method, v6addr;
foreach (QString line, propList) { foreach (QString line, propList) {
if (line.startsWith("method:")) { if (line.startsWith("method:")) {
v4method = line.split(":").at(1); v4method = line.split(":").at(1);
@ -802,6 +802,12 @@ void OneConnForm::on_btnInfo_clicked()
if (line.startsWith("mask:")) { if (line.startsWith("mask:")) {
mask = line.split(":").at(1); mask = line.split(":").at(1);
} }
if (line.startsWith("v6method:")) {
v6method = line.split(":").at(1);
}
if (line.startsWith("v6addr:")) {
v6addr = line.right(line.length() - line.indexOf(":") - 1);
}
if (line.startsWith("gateway:")) { if (line.startsWith("gateway:")) {
gateway= line.split(":").at(1); gateway= line.split(":").at(1);
} }
@ -811,7 +817,7 @@ void OneConnForm::on_btnInfo_clicked()
} }
// qDebug()<<"v4method:"<<v4method<<" addr:"<<addr<<" mask:"<<mask<<" gateway:"<<gateway<<" dns:"<<dns; // qDebug()<<"v4method:"<<v4method<<" addr:"<<addr<<" mask:"<<mask<<" gateway:"<<gateway<<" dns:"<<dns;
cf->setProp(lbNameText->text(), wifiUuid, v4method, addr, mask, gateway, dns, this->isActive, true); cf->setProp(lbNameText->text(), wifiUuid, v4method, addr, v6method, v6addr, mask, gateway, dns, this->isActive, true);
cf->move(primaryGeometry.width() / 2 - cf->width() / 2, primaryGeometry.height() / 2 - cf->height() / 2); cf->move(primaryGeometry.width() / 2 - cf->width() / 2, primaryGeometry.height() / 2 - cf->height() / 2);
cf->show(); cf->show();
cf->raise(); cf->raise();

View File

@ -408,17 +408,23 @@ void OneLancForm::on_btnInfo_clicked()
BackThread *bt = new BackThread(); BackThread *bt = new BackThread();
QString connProp = bt->getConnProp(uuidName); QString connProp = bt->getConnProp(uuidName);
QStringList propList = connProp.split("|"); QStringList propList = connProp.split("|");
QString v4method, addr, mask, gateway, dns; QString v4method, addr, mask, gateway, dns, v6method, v6addr;
foreach (QString line, propList) { foreach (QString line, propList) {
if (line.startsWith("method:")) { if (line.startsWith("method:")) {
v4method = line.split(":").at(1); v4method = line.split(":").at(1);
} }
if (line.startsWith("addr:")) { if (line.startsWith("v4addr:")) {
addr = line.split(":").at(1); addr = line.split(":").at(1);
} }
if (line.startsWith("mask:")) { if (line.startsWith("mask:")) {
mask = line.split(":").at(1); mask = line.split(":").at(1);
} }
if (line.startsWith("v6method:")) {
v6method = line.split(":").at(1);
}
if (line.startsWith("v6addr:")) {
v6addr = line.right(line.length() - line.indexOf(":") - 1);
}
if (line.startsWith("gateway:")) { if (line.startsWith("gateway:")) {
gateway= line.split(":").at(1); gateway= line.split(":").at(1);
} }
@ -429,7 +435,7 @@ void OneLancForm::on_btnInfo_clicked()
// qDebug()<<v4method<<addr<<mask<<gateway<<dns; // qDebug()<<v4method<<addr<<mask<<gateway<<dns;
connect(cf, SIGNAL(requestRefreshLanList(int)), mw, SLOT(onBtnNetListClicked(int))); connect(cf, SIGNAL(requestRefreshLanList(int)), mw, SLOT(onBtnNetListClicked(int)));
cf->setProp(ui->lbName->text(), uuidName, v4method, addr, mask, gateway, dns, this->isActive, false); cf->setProp(ui->lbName->text(), uuidName, v4method, addr, v6method, v6addr, mask, gateway, dns, this->isActive, false);
cf->move(primaryGeometry.width() / 2 - cf->width() / 2, primaryGeometry.height() / 2 - cf->height() / 2); cf->move(primaryGeometry.width() / 2 - cf->width() / 2, primaryGeometry.height() / 2 - cf->height() / 2);
cf->exec(); cf->exec();
cf->raise(); cf->raise();