Use Uuid to reconnect after change configuration of wired network

This commit is contained in:
chenlelin 2021-01-19 17:38:13 +08:00
parent fb5bf1ff9e
commit e0230cff9e
6 changed files with 63 additions and 28 deletions

View File

@ -226,6 +226,7 @@ void ConfForm::on_btnCreate_clicked()
if (ui->cbType->currentIndex() == 1) {
//选择手动配置Ipv4、掩码、网关
this->isCreateNewNet = true;
newUuid = "--";
this->saveNetworkConfiguration();
} else {
//选择自动,则配置完成并发出桌面通知
@ -255,30 +256,56 @@ void ConfForm::on_btnSave_clicked()
//如果网络的名称已经修改,则删掉当前网络,新建一个网络
if (ui->leName->text() != lastConnName) {
QString cmd = "nmcli connection delete '" + 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");
}
//this->hide();
QString cmdStr = "nmcli connection add con-name '" + ui->leName->text() + "' ifname '" + mIfname + "' type ethernet";
Utils::m_system(cmdStr.toUtf8().data());
//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冲突
if (check_ip_conflict(mIfname)) {
return;
if (ui->cbType->currentIndex() == 1 && (ui->leAddr->text() != lastIpv4)) {
//在手动配置网络的情况下以及当前的IP参数有更改的情况下检测IP冲突
if (check_ip_conflict(mIfname)) {
return;
}
}
}
this->saveNetworkConfiguration();
this->hide();
this->saveNetworkConfiguration();
}
QString txt(tr("New network settings already finished"));
kylindbus.showDesktopNotify(txt);
@ -315,11 +342,17 @@ void ConfForm::saveNetworkConfiguration()
dnss.append(ui->leDns2->text());
}
if (this->isCreateNewNet) {
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());
if (newUuid != "--") {
kylin_network_set_manualall(newUuid.toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data());
} else {
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());
}
}
this->hide();
}
bool ConfForm::check_ip_conflict(QString ifname)

View File

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

View File

@ -1372,7 +1372,7 @@ void MainWindow::getLanListDone(QStringList slist)
// 若当前lan name为"--"设置OneConnForm
if (currConnLanSsidUuid.size() == 0) {
OneLancForm *ccf = new OneLancForm(topLanListWidget, this, confForm, ksnm);
ccf->setName(tr("Not connected"), "--", "--");//"当前未连接任何 以太网"
ccf->setName(tr("Not connected"), tr("Not connected"), "--", "--");//"当前未连接任何 以太网"
ccf->setIcon(false);
ccf->setConnedString(1, tr("Disconnected"), "");//"未连接"
ccf->isConnected = false;
@ -1453,7 +1453,7 @@ void MainWindow::getLanListDone(QStringList slist)
OneLancForm *ccfAct = new OneLancForm(topLanListWidget, this, confForm, ksnm);
connect(ccfAct, SIGNAL(selectedOneLanForm(QString, QString)), this, SLOT(oneTopLanFormSelected(QString, QString)));
connect(ccfAct, SIGNAL(disconnActiveLan()), this, SLOT(activeLanDisconn()));
ccfAct->setName(nname, nuuid, mIfName);
ccfAct->setName(nname, nname, nuuid, mIfName);//第二个参数本来是strLanName但目前不需要翻译
ccfAct->setIcon(true);
ccfAct->setLanInfo(objKyDBus->dbusLanIpv4, objKyDBus->dbusActiveLanIpv6, mwBandWidth, macInterface);
ccfAct->isConnected = true;
@ -1513,7 +1513,7 @@ void MainWindow::getLanListDone(QStringList slist)
OneLancForm *ocf = new OneLancForm(lanListWidget, this, confForm, ksnm);
connect(ocf, SIGNAL(selectedOneLanForm(QString, QString)), this, SLOT(oneLanFormSelected(QString, QString)));
ocf->setName(nname, nuuid, mIfName);
ocf->setName(nname, nname, nuuid, mIfName);
ocf->setIcon(true);
ocf->setLine(true);
ocf->setLanInfo(objKyDBus->dbusLanIpv4, objKyDBus->dbusLanIpv6, tr("Disconnected"), macInterface);
@ -2486,7 +2486,7 @@ void MainWindow::disNetDone()
// 当前连接的lan
OneLancForm *ccf = new OneLancForm(topLanListWidget, this, confForm, ksnm);
ccf->setName(tr("Not connected"), "--", "--");//"当前未连接任何 以太网"
ccf->setName(tr("Not connected"), tr("Not connected"), "--", "--");//"当前未连接任何 以太网"
ccf->setIcon(false);
ccf->setConnedString(1, tr("Disconnected"), "");//"未连接"
ccf->isConnected = false;

View File

@ -220,10 +220,11 @@ void OneLancForm::setTopItem(bool isSelected)
}
//设置网络名称
void OneLancForm::setName(QString ssid, QString uuid, QString interface)
void OneLancForm::setName(QString ssid, QString transSsid, QString uuid, QString interface)
{
ui->lbName->setText(ssid);
ui->lbName->setText(transSsid);
ssidName = ssid;
transSsidName = transSsid;
uuidName = uuid;
ifName = interface;
}

View File

@ -55,7 +55,7 @@ public:
explicit OneLancForm(QWidget *parent = 0, MainWindow *mw = 0, ConfForm *confForm = 0, KSimpleNM *ksnm = 0);
~OneLancForm();
void setName(QString ssid, QString uuid, QString interface);
void setName(QString ssid, QString transSsid, QString uuid, QString interface);
void setIcon(bool isOn);
void setLine(bool isShow);
void setLanInfo(QString str1, QString str2, QString str3, QString str4);
@ -71,6 +71,7 @@ public:
bool isActive;
bool isConnected;
QString ssidName;
QString transSsidName;
QString uuidName;
QString ifName;

View File

@ -1436,18 +1436,18 @@
<translation type="unfinished">线</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="1920"/>
<location filename="../src/mainwindow.cpp" line="1924"/>
<location filename="../src/mainwindow.cpp" line="1929"/>
<location filename="../src/mainwindow.cpp" line="1933"/>
<location filename="../src/mainwindow.cpp" line="1969"/>
<location filename="../src/mainwindow.cpp" line="1973"/>
<location filename="../src/mainwindow.cpp" line="1978"/>
<location filename="../src/mainwindow.cpp" line="1982"/>
<source>Wired connection</source>
<translation type="unfinished">线</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="1938"/>
<location filename="../src/mainwindow.cpp" line="1942"/>
<location filename="../src/mainwindow.cpp" line="1947"/>
<location filename="../src/mainwindow.cpp" line="1951"/>
<location filename="../src/mainwindow.cpp" line="1987"/>
<location filename="../src/mainwindow.cpp" line="1991"/>
<location filename="../src/mainwindow.cpp" line="1996"/>
<location filename="../src/mainwindow.cpp" line="2000"/>
<source>Ethernet connection</source>
<translation type="unfinished"></translation>
</message>