From c578253e3b786479e4d1622bea326c4374a5bb24 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Wed, 12 May 2021 18:38:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Fix:=20Wifi=20infomation=20is=20not=20sync?= =?UTF-8?q?=20with=20ukui-control-center.=20=E4=B8=BA=E4=BF=AE=E6=94=B9ip?= =?UTF-8?q?=E5=90=8E=E6=8E=A7=E5=88=B6=E9=9D=A2=E6=9D=BF=E6=9C=AA=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E7=9A=84=E9=97=AE=E9=A2=98=E6=8F=90=E4=BE=9B=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20http://172.17.66.192/biz/bug-view-54353.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dbusadaptor.h | 2 ++ src/mainwindow.cpp | 6 ++++++ src/mainwindow.h | 1 + 3 files changed, 9 insertions(+) diff --git a/src/dbusadaptor.h b/src/dbusadaptor.h index 093f6d08..d56ed49c 100644 --- a/src/dbusadaptor.h +++ b/src/dbusadaptor.h @@ -43,6 +43,7 @@ class DbusAdaptor: public QDBusAbstractAdaptor " \n" " \n" " \n" +" \n" " \n" "") public: @@ -59,6 +60,7 @@ public Q_SLOTS: // METHODS QVector getWifiList(); Q_SIGNALS: // SIGNALS void getWifiListFinished(); + void configurationChanged(); }; #endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ba188603..8a26e75f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1421,13 +1421,16 @@ void MainWindow::on_wifi_changed() oldWifiIpv4Method = "manual"; qDebug()<<"Ipv4.address of current activated wifi is:"<dbusActiveWifiIpv4 << ". Real ipv4.address is:" << objKyDBus->dbusWifiIpv4; emit this->reConnectWifi(actWifiUuid); + emit this->configurationChanged(); } else if (objKyDBus-> dbusWifiIpv4Method == "auto" && oldWifiIpv4Method == "manual") { oldWifiIpv4Method = "auto"; qDebug()<<"Ipv4.method is set to auto."; emit this->reConnectWifi(actWifiUuid); + emit this->configurationChanged(); } else if (!objKyDBus->dbusActiveWifiIpv6.isEmpty() && objKyDBus->dbusActiveWifiIpv6 != objKyDBus->dbusWifiIpv6 && objKyDBus->dbusWifiIpv6Method == "manual") { //在第三方nm-connection-editor或kylin-nm配置页进行新的IPV6配置后,重新连接网络 emit this->reConnectWifi(actWifiUuid); + emit this->configurationChanged(); } } @@ -1613,13 +1616,16 @@ void MainWindow::getLanListDone(QStringList slist) // qDebug() << Q_FUNC_INFO << __LINE__ << objKyDBus->dbusActiveLanIpv4 << objKyDBus->dbusLanIpv4; //在第三方nm-connection-editor进行新的IP配置后,重新连接网络 objKyDBus->reConnectWiredNet(nuuid); + emit this->configurationChanged(); } else if ((oldActLanName == actLanSsidName.at(kk)) && (oldDbusActLanDNS != objKyDBus->dbusActLanDNS)) { //在第三方nm-connection-editor进行新的DNS配置后,重新连接网络 objKyDBus->reConnectWiredNet(nuuid); + emit this->configurationChanged(); } else if (!objKyDBus->dbusActiveLanIpv6.isEmpty() && objKyDBus->dbusActiveLanIpv6 != objKyDBus->dbusLanIpv6 && objKyDBus->dbusLanIpv6Method == "manual") { // qDebug() << Q_FUNC_INFO << __LINE__ << objKyDBus->dbusActiveLanIpv6 << objKyDBus->dbusLanIpv6 << objKyDBus->dbusLanIpv6Method; //在第三方nm-connection-editor或kylin-nm配置页进行新的IPV6配置后,重新连接网络 objKyDBus->reConnectWiredNet(nuuid); + emit this->configurationChanged(); } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 9b557a49..899de776 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -407,6 +407,7 @@ signals: void disConnSparedNet(QString type); void waitLanStop(); + void configurationChanged(); void reConnectWifi(const QString& uuid); void actWifiSignalLvChanaged(const int& currentLevel); void getWifiListFinished(); From bc82609ff1d5bcca7a33c6473906a3bd8fdfc1d6 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Thu, 13 May 2021 11:07:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Fix:Connect=20wifi=20failed=20when=20passwo?= =?UTF-8?q?rd=20of=20wifi=20changed.=20=E4=BF=AE=E5=A4=8DWiFi=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E6=94=B9=E5=8F=98=E5=90=8E=E9=87=8D=E6=96=B0=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=A4=B1=E8=B4=A5=E4=B8=94=E4=B8=8D=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E5=AF=86=E7=A0=81=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82=20=E4=BF=AE=E5=A4=8DWiFi=E8=87=AA=E5=8A=A8=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=92=8C=E6=96=AD=E5=BC=80=E5=90=8EWiFi=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=8A=B6=E6=80=81=E6=9C=AA=E6=9B=B4=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20Link=EF=BC=9Ahttp://172.17.66.192/biz/bug-?= =?UTF-8?q?view-53041.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mainwindow.cpp | 45 +++++++++++++++++++++++++++++++++++++-------- src/mainwindow.h | 1 + src/oneconnform.cpp | 20 ++++++++++---------- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8a26e75f..c1bd87ea 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1733,8 +1733,23 @@ void MainWindow::getWifiListDone(QStringList slist) QString wifiSsid = objKyDBus->getWifiSsid(targetWifiStructList.at(0).objectPath); QString modityCmd = "nmcli connection modify \""+ wifiSsid + "\" " + "802-11-wireless.bssid " + targetWifiStructList.at(0).bssid; system(modityCmd.toUtf8().data()); - QString reconnectWifiCmd = "nmcli connection up \"" + wifiSsid + "\""; - system(reconnectWifiCmd.toUtf8().data()); +// QString reconnectWifiCmd = "nmcli connection up \"" + wifiSsid + "\""; +// system(reconnectWifiCmd.toUtf8().data()); + canReconnectWifiTimeInterval = false; + BackThread *bt = new BackThread(); + connect(bt, &BackThread::connDone, this, [ = ](int res) { + if (res == 1 || res == 4) { + // 使用配置文件连接失败,需要删除该配置文件 + QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection delete '" + wifiSsid + "'"; + int status = system(cmd.toUtf8().data()); + if (status != 0) { + syslog(LOG_ERR, "execute 'nmcli connection delete' in function 'slotConnWifiResult' failed"); + } + } + //连接结束后再开放重连,防止连接失败时针对一个连不上的wifi反复尝试重连 + timeIntervalToConnectWifi(); + }); + bt->execConnWifi(wifiSsid, this->wcardname); }); } } @@ -1744,6 +1759,7 @@ void MainWindow::getWifiListDone(QStringList slist) if (this->is_btnLanList_clicked == 1 && current_wifi_list_state != REFRESH_WIFI) { return; } + if (current_wifi_list_state == LOAD_WIFI_LIST || current_wifi_list_state == REFRESH_WIFI) { //qDebug() << "loadwifi的列表"; loadWifiListDone(slist); @@ -1751,9 +1767,17 @@ void MainWindow::getWifiListDone(QStringList slist) } if (current_wifi_list_state == UPDATE_WIFI_LIST) { - //qDebug() << "updatewifi的列表"; - updateWifiListDone(slist); - current_wifi_list_state = LOAD_WIFI_LIST; + //如果WiFi连接状态发生了改变,需要刷新整个列表,否则只需要比对新旧列表更新即可 + if (m_isWifiConnected && objKyDBus->checkWifiConnectivity() != 2) { + //qDebug() << "loadwifi的列表"; + loadWifiListDone(slist); + } else if (!m_isWifiConnected && objKyDBus->checkWifiConnectivity() == 2) { + loadWifiListDone(slist); + } else { + //qDebug() << "updatewifi的列表"; + updateWifiListDone(slist); + current_wifi_list_state = LOAD_WIFI_LIST; + } } oldWifiSlist = slist; @@ -2232,8 +2256,13 @@ void MainWindow::loadWifiListDone(QStringList slist) scrollAreaw->move(W_LEFT_AREA, Y_SCROLL_AREA); dbus_wifiList.clear(); - // 获取当前有线网的连接状态,正在连接wifiActState==1,已经连接wifiActState==2, 未连接wifiActState==3 + // 获取当前无线网的连接状态,正在连接wifiActState==1,已经连接wifiActState==2, 未连接wifiActState==3 int wifiActState = objKyDBus->checkWifiConnectivity(); //检查wifi的连接状态 + if (wifiActState == 2) { + m_isWifiConnected = true; + } else { + m_isWifiConnected = false; + } // if (isWifiBeConnUp && wifiActState == 1) { // wifiActState = 2; // } @@ -3420,8 +3449,8 @@ void MainWindow::on_btnHotspotState() void MainWindow::toReconnectWifi() { if (canReconnectWifiTimeInterval) { - canReconnectWifiTimeInterval = false; - QTimer::singleShot(2*1000, this, SLOT(timeIntervalToConnectWifi() )); +// canReconnectWifiTimeInterval = false; +// QTimer::singleShot(2*1000, this, SLOT(timeIntervalToConnectWifi() )); if (isHuaWeiPC) { current_wifi_list_state = RECONNECT_WIFI; diff --git a/src/mainwindow.h b/src/mainwindow.h index 899de776..c4a9e3c6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -313,6 +313,7 @@ private: QStringList oldConnSlist; //上一次获取的以保存网络列表 bool isInitConnList = true; bool isAddedWifi = false; + bool m_isWifiConnected = false; //专用于处理dbus获取的WiFi状态,用于对比每次刷新后的WiFi连接状态变化 QString lastAddedConn = ""; QString oldActLanName = ""; //上一次获取的已连接有线网名称 int oldDbusActLanDNS = 0; //上一次获取的已连接有线网的DNS代号 diff --git a/src/oneconnform.cpp b/src/oneconnform.cpp index 65f74eb5..ced74c64 100644 --- a/src/oneconnform.cpp +++ b/src/oneconnform.cpp @@ -984,7 +984,16 @@ void OneConnForm::slotConnWifiResult(int connFlag) disconnect(this, SIGNAL(selectedOneWifiForm(QString,int)), mw, SLOT(oneWifiFormSelected(QString,int))); } - if (connFlag == 2 || connFlag == 4) { + if (connFlag == 1 || connFlag == 4) { + // 使用配置文件连接失败,需要删除该配置文件 + QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection delete '" + wifiName + "'"; + int status = system(cmd.toUtf8().data()); + if (status != 0) { + syslog(LOG_ERR, "execute 'nmcli connection delete' in function 'slotConnWifiResult' failed"); + } + } + + if (connFlag == 2 || connFlag == 4 || connFlag == 1) { mw->currSelNetName = ""; emit selectedOneWifiForm(wifiBSsid, H_WIFI_ITEM_SMALL_EXTEND); @@ -1019,15 +1028,6 @@ void OneConnForm::slotConnWifiResult(int connFlag) ui->checkBoxPwd->setChecked(false); } - if (connFlag == 1) { - // 使用配置文件连接失败,需要删除该配置文件 - QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection delete '" + wifiName + "'"; - int status = system(cmd.toUtf8().data()); - if (status != 0) { - syslog(LOG_ERR, "execute 'nmcli connection delete' in function 'slotConnWifiResult' failed"); - } - } - // 设置全局变量,当前连接Wifi的信号强度 currentActWifiSignalLv = signalLv;