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..c1bd87ea 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(); } } @@ -1727,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); }); } } @@ -1738,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); @@ -1745,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; @@ -2226,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; // } @@ -3414,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 9b557a49..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代号 @@ -407,6 +408,7 @@ signals: void disConnSparedNet(QString type); void waitLanStop(); + void configurationChanged(); void reConnectWifi(const QString& uuid); void actWifiSignalLvChanaged(const int& currentLevel); void getWifiListFinished(); 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;