Fix bug wired network still use old DNS after change to a new one

This commit is contained in:
chenlelin 2020-12-03 14:26:42 +08:00
parent 51998cae1c
commit af634e7633
4 changed files with 50 additions and 7 deletions

View File

@ -271,7 +271,7 @@ void KylinDBus::getWirelessCardName()
} }
//获取没有连接的有线网ip //获取没有连接的有线网ip
void KylinDBus::getLanIp(QString netName) void KylinDBus::getLanIp(QString netName, bool isActNet)
{ {
QDBusInterface m_interface("org.freedesktop.NetworkManager", QDBusInterface m_interface("org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager/Settings", "/org/freedesktop/NetworkManager/Settings",
@ -306,6 +306,7 @@ void KylinDBus::getLanIp(QString netName)
//qDebug() << "Key: " << key; //qDebug() << "Key: " << key;
if (key == "ipv4") { if (key == "ipv4") {
for (QString inner_key : innerMap.keys()) { for (QString inner_key : innerMap.keys()) {
//获取ipv4
if (inner_key == "address-data") { if (inner_key == "address-data") {
const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value<QDBusArgument>(); const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value<QDBusArgument>();
QMap<QString,QVariant> m_map; QMap<QString,QVariant> m_map;
@ -319,6 +320,17 @@ void KylinDBus::getLanIp(QString netName)
//qDebug()<<" " << m_map.value("address").toString(); //qDebug()<<" " << m_map.value("address").toString();
dbusLanIpv4 = m_map.value("address").toString(); dbusLanIpv4 = m_map.value("address").toString();
} }
if (isActNet && inner_key == "dns") {
const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value<QDBusArgument>();
int strDns;
dbusArg2nd.beginArray();
while (!dbusArg2nd.atEnd()) {
dbusArg2nd >> strDns;// append map to a vector here if you want to keep it
}
dbusArg2nd.endArray();
dbusActLanDNS = strDns;
}
} }
} }
@ -740,7 +752,6 @@ void KylinDBus::onWifiPropertyChanged(QVariantMap qvm)
//有线网的Ip属性变化时的响应函数 //有线网的Ip属性变化时的响应函数
void KylinDBus::onIpPropertiesChanged() void KylinDBus::onIpPropertiesChanged()
{ {
qDebug() << "哈哈哈哈哈或或或或或";
emit this->updateWiredList(0); emit this->updateWiredList(0);
} }

View File

@ -86,6 +86,7 @@ public:
QString dbusLanMac = ""; QString dbusLanMac = "";
QString dbusWiFiCardName = ""; QString dbusWiFiCardName = "";
QString dbusWifiMac = ""; QString dbusWifiMac = "";
int dbusActLanDNS;
public slots: public slots:
void onNewConnection(QDBusObjectPath objPath); void onNewConnection(QDBusObjectPath objPath);
@ -99,7 +100,7 @@ public slots:
void getLanHwAddressState(); void getLanHwAddressState();
void getWiredCardName(); void getWiredCardName();
void getWirelessCardName(); void getWirelessCardName();
void getLanIp(QString netName); void getLanIp(QString netName, bool isActNet);
void getWifiMac(QString netName); void getWifiMac(QString netName);
void slot_timeout(); void slot_timeout();

View File

@ -99,6 +99,7 @@ MainWindow::MainWindow(QWidget *parent) :
getInitLanSlist(); //初始化有线网列表 getInitLanSlist(); //初始化有线网列表
initNetwork(); //初始化网络 initNetwork(); //初始化网络
initTimer(); //初始化定时器 initTimer(); //初始化定时器
initActNetDNS();//初始化已连接网络的DNS
getSystemFontFamily();//建立GSetting监听系统字体 getSystemFontFamily();//建立GSetting监听系统字体
connect(ui->btnNetList, &QPushButton::clicked, this, &MainWindow::onBtnNetListClicked); connect(ui->btnNetList, &QPushButton::clicked, this, &MainWindow::onBtnNetListClicked);
@ -555,6 +556,26 @@ void MainWindow::initTimer()
setNetSpeed->start(3000); setNetSpeed->start(3000);
} }
//初始化已经连接网络的DNS
void MainWindow::initActNetDNS()
{
QString actLanName = "--";
activecon *act = kylin_network_get_activecon_info();
int index = 0;
while (act[index].con_name != NULL) {
if (QString(act[index].type) == "ethernet" || QString(act[index].type) == "802-3-ethernet") {
actLanName = QString(act[index].con_name);
break;
}
index ++;
}
if (actLanName != "--") {
oldActLanName = actLanName;
objKyDBus->getLanIp(actLanName, true);
oldDbusActLanDNS = objKyDBus->dbusActLanDNS;
}
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// 任务栏托盘管理、托盘图标处理 // 任务栏托盘管理、托盘图标处理
@ -1426,7 +1447,7 @@ void MainWindow::getLanListDone(QStringList slist)
// 当前连接的lan // 当前连接的lan
if (nname == actLanName) { if (nname == actLanName) {
objKyDBus->getConnectNetIp(); objKyDBus->getConnectNetIp();
objKyDBus->getLanIp(nname); objKyDBus->getLanIp(nname, true);
actLanName = "--"; actLanName = "--";
if (mwBandWidth == "Unknown!") { getLanBandWidth(); } if (mwBandWidth == "Unknown!") { getLanBandWidth(); }
@ -1449,7 +1470,10 @@ void MainWindow::getLanListDone(QStringList slist)
if (!objKyDBus->dbusLanIpv4.isEmpty()) { if (!objKyDBus->dbusLanIpv4.isEmpty()) {
if (objKyDBus->dbusActiveLanIpv4 != objKyDBus->dbusLanIpv4) { if (objKyDBus->dbusActiveLanIpv4 != objKyDBus->dbusLanIpv4) {
//在第三方nm-connection-editor进行新的配置后重新连接网络 //在第三方nm-connection-editor进行新的IP配置后重新连接网络
objKyDBus->connectWiredNet(nname);
} else if ((oldActLanName == actLanName) && (oldDbusActLanDNS != objKyDBus->dbusActLanDNS)) {
//在第三方nm-connection-editor进行新的DNS配置后重新连接网络
objKyDBus->connectWiredNet(nname); objKyDBus->connectWiredNet(nname);
} }
} }
@ -1457,9 +1481,11 @@ void MainWindow::getLanListDone(QStringList slist)
currSelNetName = ""; currSelNetName = "";
objKyDBus->dbusActiveLanIpv4 = ""; objKyDBus->dbusActiveLanIpv4 = "";
objKyDBus->dbusActiveLanIpv6 = ""; objKyDBus->dbusActiveLanIpv6 = "";
oldActLanName = actLanName;
oldDbusActLanDNS = objKyDBus->dbusActLanDNS;
syslog(LOG_DEBUG, "already insert an active lannet in the top of lan list"); syslog(LOG_DEBUG, "already insert an active lannet in the top of lan list");
} else { } else {
objKyDBus->getLanIp(nname); objKyDBus->getLanIp(nname, false);
lanListWidget->resize(W_LIST_WIDGET, lanListWidget->height() + H_NORMAL_ITEM); lanListWidget->resize(W_LIST_WIDGET, lanListWidget->height() + H_NORMAL_ITEM);
//QString strLanName = TranslateLanName(nname); //QString strLanName = TranslateLanName(nname);
@ -2207,6 +2233,8 @@ void MainWindow::activeLanDisconn()
//if (status1 != 0){ syslog(LOG_ERR, "execute 'notify-send' in function 'execConnWifiPWD' failed");} //if (status1 != 0){ syslog(LOG_ERR, "execute 'notify-send' in function 'execConnWifiPWD' failed");}
currSelNetName = ""; currSelNetName = "";
oldActLanName = "";
oldDbusActLanDNS = 0;
//this->startLoading(); //this->startLoading();
emit this->waitLanStop(); emit this->waitLanStop();
this->ksnm->execGetLanList(); this->ksnm->execGetLanList();

View File

@ -134,6 +134,8 @@ public:
void initTimer(); void initTimer();
void checkIsWirelessDeviceOn(); void checkIsWirelessDeviceOn();
void initActNetDNS();
QIcon iconLanOnline, iconLanOffline; QIcon iconLanOnline, iconLanOffline;
QIcon iconWifiFull, iconWifiHigh, iconWifiMedium, iconWifiLow; QIcon iconWifiFull, iconWifiHigh, iconWifiMedium, iconWifiLow;
QIcon iconConnecting; QIcon iconConnecting;
@ -249,8 +251,9 @@ private:
QString scrollBarQss, leftBtnQss, funcBtnQss; QString scrollBarQss, leftBtnQss, funcBtnQss;
QStringList oldLanSlist; //上一次获取Lan列表 QStringList oldLanSlist; //上一次获取Lan列表
QStringList oldWifiSlist; //上一次获取wifi列表 QStringList oldWifiSlist; //上一次获取wifi列表
QString oldActLanName = ""; //上一次获取的已连接有线网名称
int oldDbusActLanDNS = 0; //上一次获取的已连接有线网的DNS代号
//循环检测网络连接状态 //循环检测网络连接状态
QTimer *iconTimer = nullptr; QTimer *iconTimer = nullptr;