From 9899f573a5056fb5618c480849c90f0a93bd5b0d Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Sun, 7 Feb 2021 14:34:02 +0800 Subject: [PATCH] fix(confform): Set ipv6.address failed. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 修复设置ipv6地址失败的Bug Log: 修复设置ipv6地址失败的Bug Bug: http://172.17.66.192/biz/bug-view-38287.html --- src/backthread.cpp | 24 ++++++++++++++++++++++-- src/confform.cpp | 26 +++++++++++++++++++------- src/confform.h | 2 +- src/oneconnform.cpp | 10 ++++++++-- src/onelancform.cpp | 12 +++++++++--- 5 files changed, 59 insertions(+), 15 deletions(-) diff --git a/src/backthread.cpp b/src/backthread.cpp index c0749d13..58f31053 100644 --- a/src/backthread.cpp +++ b/src/backthread.cpp @@ -407,15 +407,35 @@ QString BackThread::getConnProp(QString connName) if (line.startsWith("ipv4.addresses:")) { QString value = line.mid(15).trimmed(); if (value == "--" || value == "") { - rtn += "addr:|mask:|"; + rtn += "v4addr:|mask:|"; } else { QString addr = value.split("/").at(0); QString mask = value.trimmed().split("/").at(1); - rtn += "addr:" + addr + "|"; + rtn += "v4addr:" + addr + "|"; 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:")) { QString value = line.mid(13).trimmed(); if (value == "--" || value == "") { diff --git a/src/confform.cpp b/src/confform.cpp index d303a03c..f472f228 100644 --- a/src/confform.cpp +++ b/src/confform.cpp @@ -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; ui->leName->setText(connName); lastConnName = connName; - lastIpv4 = addr; + lastIpv4 = v4addr; netUuid = uuidName; if (isWiFi) { @@ -183,7 +183,11 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt cbTypeChanged(1); } - ui->leAddr->setText(addr); + if (v6method == "manual") { + ui->leAddr_ipv6->setText(v6addr); + } + + ui->leAddr->setText(v4addr); ui->leGateway->setText(gateway); // 配置中有多个DNS,只处理前两个 @@ -250,7 +254,10 @@ void ConfForm::on_btnCreate_clicked() } 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()); } @@ -343,9 +350,14 @@ void ConfForm::on_btnSave_clicked() } } - if (ui->cbType->currentIndex() == 1 && !ui->leAddr_ipv6->text().isEmpty()) { - QString cmdStr = "nmcli connection modify " + ui->leName->text() + " ipv6.addresses " + ui->leAddr_ipv6->text(); - Utils::m_system(cmdStr.toUtf8().data()); + if (ui->cbType->currentIndex() == 1) { + 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()); + } 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")); diff --git a/src/confform.h b/src/confform.h index c087a52c..59835d1b 100644 --- a/src/confform.h +++ b/src/confform.h @@ -40,7 +40,7 @@ public: explicit ConfForm(QWidget *parent = 0); ~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: void cbTypeChanged(int index); diff --git a/src/oneconnform.cpp b/src/oneconnform.cpp index 82475028..e30322f4 100644 --- a/src/oneconnform.cpp +++ b/src/oneconnform.cpp @@ -791,7 +791,7 @@ void OneConnForm::on_btnInfo_clicked() BackThread *bt = new BackThread(); QString connProp = bt->getConnProp(lbNameText->text()); QStringList propList = connProp.split("|"); - QString v4method, addr, mask, gateway, dns; + QString v4method, addr, mask, gateway, dns, v6method, v6addr; foreach (QString line, propList) { if (line.startsWith("method:")) { v4method = line.split(":").at(1); @@ -802,6 +802,12 @@ void OneConnForm::on_btnInfo_clicked() if (line.startsWith("mask:")) { 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:")) { gateway= line.split(":").at(1); } @@ -811,7 +817,7 @@ void OneConnForm::on_btnInfo_clicked() } // qDebug()<<"v4method:"<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->show(); cf->raise(); diff --git a/src/onelancform.cpp b/src/onelancform.cpp index d4f6975f..75bdf647 100644 --- a/src/onelancform.cpp +++ b/src/onelancform.cpp @@ -408,17 +408,23 @@ void OneLancForm::on_btnInfo_clicked() BackThread *bt = new BackThread(); QString connProp = bt->getConnProp(uuidName); QStringList propList = connProp.split("|"); - QString v4method, addr, mask, gateway, dns; + QString v4method, addr, mask, gateway, dns, v6method, v6addr; foreach (QString line, propList) { if (line.startsWith("method:")) { v4method = line.split(":").at(1); } - if (line.startsWith("addr:")) { + if (line.startsWith("v4addr:")) { addr = line.split(":").at(1); } if (line.startsWith("mask:")) { 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:")) { gateway= line.split(":").at(1); } @@ -429,7 +435,7 @@ void OneLancForm::on_btnInfo_clicked() // qDebug()<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->exec(); cf->raise();