Fix bug Modifying the WiFi IP address acquisition method does not take effect

This commit is contained in:
chenlelin 2021-01-27 20:58:53 +08:00
parent c15f59f527
commit da223a32ea
4 changed files with 73 additions and 56 deletions

View File

@ -156,7 +156,7 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt
ui->leName->setText(connName);
lastConnName = connName;
lastIpv4 = addr;
theUuid = uuidName;
netUuid = uuidName;
if (isWiFi) {
ui->leName->setEnabled(false);
@ -249,48 +249,76 @@ void ConfForm::on_btnCreate_clicked()
void ConfForm::on_btnSave_clicked()
{
KylinDBus kylindbus;
kylindbus.getWiredCardName();
QString mIfname;
if (kylindbus.multiWiredIfName.size() == 0) {
QString tip(tr("Can not create new wired network for without wired card"));
kylindbus.showDesktopNotify(tip);
//this->close();
this->hide();
return;
} else {
mIfname = kylindbus.multiWiredIfName.at(0);
}
if (isActWifi) {
kylindbus.getWirelessCardName();
QString mWifiIfname = kylindbus.dbusWiFiCardName;
this->isCreateNewNet = false;
//如果网络的名称已经修改,则删掉当前网络,新建一个网络
if (ui->leName->text() != lastConnName) {
QString cmd = "nmcli connection delete '" + theUuid + "'";
int status = system(cmd.toUtf8().data());
if (status != 0) {
syslog(LOG_ERR, "execute 'nmcli connection delete' in function 'on_btnSave_clicked' failed");
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
//在手动配置网络的情况下以及当前的IP参数有更改的情况下检测IP冲突
if (check_ip_conflict(mWifiIfname)) {
return;
}
}
//this->hide();
//QString cmdStr = "nmcli connection add con-name '" + ui->leName->text() + "' ifname '" + mIfname + "' type ethernet";
//Utils::m_system(cmdStr.toUtf8().data());
this->saveNetworkConfiguration();
} else {
kylindbus.getWiredCardName();
QString mIfname;
this->isCreateNewNet = true;
newUuid = "--";
if (kylindbus.multiWiredIfName.size() == 0) {
QString tip(tr("Can not save wired network for without wired card"));
kylindbus.showDesktopNotify(tip);
//this->close();
this->hide();
return;
} else {
mIfname = kylindbus.multiWiredIfName.at(0);
}
QProcess * processAdd = new QProcess;
QString cmdAdd = "nmcli connection add con-name '" + ui->leName->text() + "' ifname '" + mIfname + "' type ethernet";
QStringList options;
options << "-c" << cmdAdd;
processAdd->start("/bin/bash",options);
connect(processAdd, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
processAdd->deleteLater();
});
connect(processAdd, &QProcess::channelReadyRead, this, [ = ]() {
QString str = processAdd->readAll();
QString regExpPattern("[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}");
QRegExp regExpTest(regExpPattern);
int pos = str.indexOf(regExpTest);
newUuid = str.mid(pos,36); //36是uuid的长度
//如果网络的名称已经修改,则删掉当前网络,新建一个网络
if (ui->leName->text() != lastConnName) {
QString cmd = "nmcli connection delete '" + netUuid + "'";
int status = system(cmd.toUtf8().data());
if (status != 0) {
syslog(LOG_ERR, "execute 'nmcli connection delete' in function 'on_btnSave_clicked' failed");
}
//this->hide();
//QString cmdStr = "nmcli connection add con-name '" + ui->leName->text() + "' ifname '" + mIfname + "' type ethernet";
//Utils::m_system(cmdStr.toUtf8().data());
this->isCreateNewNet = true;
newUuid = "--";
QProcess * processAdd = new QProcess;
QString cmdAdd = "nmcli connection add con-name '" + ui->leName->text() + "' ifname '" + mIfname + "' type ethernet";
QStringList options;
options << "-c" << cmdAdd;
processAdd->start("/bin/bash",options);
connect(processAdd, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
processAdd->deleteLater();
});
connect(processAdd, &QProcess::channelReadyRead, this, [ = ]() {
QString str = processAdd->readAll();
QString regExpPattern("[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}");
QRegExp regExpTest(regExpPattern);
int pos = str.indexOf(regExpTest);
newUuid = str.mid(pos,36); //36是uuid的长度
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
//在手动配置网络的情况下以及当前的IP参数有更改的情况下检测IP冲突
if (check_ip_conflict(mIfname)) {
return;
}
}
this->saveNetworkConfiguration();
});
processAdd->waitForFinished();
} else {
this->isCreateNewNet = false;
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
//在手动配置网络的情况下以及当前的IP参数有更改的情况下检测IP冲突
@ -300,22 +328,10 @@ void ConfForm::on_btnSave_clicked()
}
this->saveNetworkConfiguration();
});
processAdd->waitForFinished();
} else {
this->isCreateNewNet = false;
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
//在手动配置网络的情况下以及当前的IP参数有更改的情况下检测IP冲突
if (check_ip_conflict(mIfname)) {
return;
}
}
this->saveNetworkConfiguration();
}
if (!ui->leAddr_ipv6->text().isEmpty()) {
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());
}
@ -346,7 +362,7 @@ void ConfForm::saveNetworkConfiguration()
if (ui->cbType->currentIndex() == 0) {
if (!this->isCreateNewNet) {
//kylin_network_set_automethod(ui->leName->text().toUtf8().data());
kylin_network_set_automethod(theUuid.toUtf8().data());
kylin_network_set_automethod(netUuid.toUtf8().data());
}
} else {
QString dnss = ui->leDns->text();
@ -361,7 +377,7 @@ void ConfForm::saveNetworkConfiguration()
kylin_network_set_manualall(ui->leName->text().toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data());
}
} else {
kylin_network_set_manualall(theUuid.toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data());
kylin_network_set_manualall(netUuid.toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data());
}
}

View File

@ -88,7 +88,7 @@ private:
bool isActConf; //是否对已经连接的网络进行的更改
bool isCreateNewNet = false; //是否是创建的新网络
bool isShowSaveBtn = true; //是否显示保存按钮,即是否是编辑网络界面
QString lastConnName, lastIpv4, theUuid, newUuid;
QString lastConnName, lastIpv4, netUuid, newUuid;
bool isActWifi; //是否是wifi网络
QString labelQss, cbxQss, leQss, lineQss, btnOnQss, btnOffQss;

View File

@ -2713,11 +2713,12 @@ void MainWindow::onExternalConnectionChange(QString type, bool isConnUp)
is_connect_net_failed = 0;
is_stop_check_net_state = 0;
} else {
QTimer::singleShot(4*1000, this, SLOT(onExternalWifiChange() ));
if (!isWifiBeDisConn) {
QString txt(tr("WiFi already disconnect"));
objKyDBus->showDesktopNotify(txt);
onExternalWifiChange();
} else {
QTimer::singleShot(4*1000, this, SLOT(onExternalWifiChange() ));
}
}
}

View File

@ -789,7 +789,7 @@ void OneConnForm::on_btnInfo_clicked()
}
// qDebug()<<"v4method:"<<v4method<<" addr:"<<addr<<" mask:"<<mask<<" gateway:"<<gateway<<" dns:"<<dns;
cf->setProp(lbNameText->text(), "--", v4method, addr, mask, gateway, dns, this->isActive, true);
cf->setProp(lbNameText->text(), wifiUuid, v4method, addr, mask, gateway, dns, this->isActive, true);
cf->move(primaryGeometry.width() / 2 - cf->width() / 2, primaryGeometry.height() / 2 - cf->height() / 2);
cf->exec();
cf->raise();