diff --git a/src/kylin-dbus-interface.cpp b/src/kylin-dbus-interface.cpp index 3694097b..98583308 100644 --- a/src/kylin-dbus-interface.cpp +++ b/src/kylin-dbus-interface.cpp @@ -1330,7 +1330,7 @@ QString KylinDBus::getWifiSsid(QString accessPointPath) //检查wifi连接状态 int KylinDBus::checkWifiConnectivity() { - int wifiState = 3; + int wifiState = WIFI_DISCONNECTED; QDBusInterface interface( "org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", diff --git a/src/kylin-dbus-interface.h b/src/kylin-dbus-interface.h index 3b151c78..f42b16e5 100644 --- a/src/kylin-dbus-interface.h +++ b/src/kylin-dbus-interface.h @@ -33,6 +33,10 @@ #include #include +#define WIFI_CONNECTING 1 +#define WIFI_CONNECTED 2 +#define WIFI_DISCONNECTED 3 + class MainWindow; class Utils; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fc2f82a7..48a43f74 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -812,6 +812,7 @@ void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) is_stop_check_net_state = 0; } } else { + this->m_is_inputting_wifi_password = false; this->hide(); numberForWifiScan = 0; } @@ -2052,7 +2053,7 @@ void MainWindow::getWifiListDone(QStringList slist) return; } - if (current_wifi_list_state == LOAD_WIFI_LIST || current_wifi_list_state == REFRESH_WIFI) { + if ((current_wifi_list_state == LOAD_WIFI_LIST || current_wifi_list_state == REFRESH_WIFI) && !this->m_is_inputting_wifi_password) { if (!isReconnectingWifi) { loadWifiListDone(slist); is_init_wifi_list = 0; @@ -2063,12 +2064,12 @@ void MainWindow::getWifiListDone(QStringList slist) } } - if (current_wifi_list_state == UPDATE_WIFI_LIST) { + if (current_wifi_list_state == UPDATE_WIFI_LIST || this->m_is_inputting_wifi_password) { //如果WiFi连接状态发生了改变,需要刷新整个列表,否则只需要比对新旧列表更新即可 - if (m_isWifiConnected && objKyDBus->checkWifiConnectivity() != 2) { + if (m_isWifiConnected && objKyDBus->checkWifiConnectivity() != WIFI_CONNECTED) { //qDebug() << "loadwifi的列表"; loadWifiListDone(slist); - } else if (!m_isWifiConnected && objKyDBus->checkWifiConnectivity() == 2) { + } else if (!m_isWifiConnected && objKyDBus->checkWifiConnectivity() == WIFI_CONNECTED) { loadWifiListDone(slist); } else { //qDebug() << "updatewifi的列表"; @@ -2582,7 +2583,7 @@ void MainWindow::loadWifiListDone(QStringList slist) // 获取当前无线网的连接状态,正在连接wifiActState==1,已经连接wifiActState==2, 未连接wifiActState==3 int wifiActState = objKyDBus->checkWifiConnectivity(); //检查wifi的连接状态 - if (wifiActState == 2) { + if (wifiActState == WIFI_CONNECTED) { m_isWifiConnected = true; } else { m_isWifiConnected = false; @@ -2683,7 +2684,7 @@ void MainWindow::loadWifiListDone(QStringList slist) // 根据当前连接的wifi 设置OneConnForm OneConnForm *ccf = new OneConnForm(topWifiListWidget, this, confForm, ksnm); - if (actWifiName == "--" || wifiActState == 1 || actWifiBssidList.at(0) == "--" || actWifiBssid == " ") { + if (actWifiName == "--" || wifiActState == WIFI_CONNECTING || actWifiBssidList.at(0) == "--" || actWifiBssid == " ") { ccf->setWifiName(tr("Not connected"), "--", "--", "--", isHuaWeiPC, isHuaWei9006C);//"当前未连接任何 Wifi" ccf->setSignal("0", "--" , "0", false); activeWifiSignalLv = 0; @@ -2802,7 +2803,7 @@ void MainWindow::loadWifiListDone(QStringList slist) if (wname != "" && wname != "--") { //qDebug() << "wifi的 actWifiBssid: " << actWifiBssid << " wcate = " << wcate; //qDebug() << "wifi的 bssid: " << wbssid << "当前连接的wifi的bssid: " << actWifiBssidList; - if (actWifiBssid == wbssid && wifiActState == 2) { + if (actWifiBssid == wbssid && wifiActState == WIFI_CONNECTED) { //对于已经连接的wifi connect(this, &MainWindow::actWifiSignalLvChanaged, ccf, [ = ](const int &signalLv) { ccf->setSignal(QString::number(signalLv), wsecu, wcate, true); @@ -2904,7 +2905,7 @@ void MainWindow::loadWifiListDone(QStringList slist) ocf->setSelected(false, false); ocf->show(); - if ((actWifiBssidList.contains(wbssid) && wifiActState == 1) || (actWifiId == wname && wifiActState == 1)) { + if ((actWifiBssidList.contains(wbssid) && wifiActState == WIFI_CONNECTING) || (actWifiId == wname && wifiActState == WIFI_CONNECTING)) { ocf->startWifiWaiting(true); } @@ -3520,6 +3521,11 @@ void MainWindow::oneWifiFormSelected(QString wifibssid, int extendLength) //与win逻辑一致,点击同一选项不再缩小选项卡 return; } + if (extendLength == H_WIFI_ITEM_SMALL_EXTEND) { + this->m_is_inputting_wifi_password = true; + } else { + this->m_is_inputting_wifi_password = false; + } QListtopWifiList = topWifiListWidget->findChildren(); QList wifiList = wifiListWidget->findChildren(); @@ -4378,6 +4384,7 @@ bool MainWindow::event(QEvent *event) { if (event->type() == QEvent::ActivationChange) { if (QApplication::activeWindow() != this) { + this->m_is_inputting_wifi_password = false; this->hide(); numberForWifiScan = 0; } diff --git a/src/mainwindow.h b/src/mainwindow.h index fde8b4a1..321f09e1 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -184,6 +184,7 @@ public: bool isToSetWifiValue = true; //本次执行是否进行赋值 bool isReconnectingWifi = false; //是否正在执行wifi的回连 bool isReconnectingLan = false; //是否正在执行lan的回连 + bool m_is_inputting_wifi_password = false; //是否正在输入密码 int addNumberForWifi = 0; //短时间内收到关于wifi连接信号的次数 bool isHuaWeiPC; bool isHuaWei9006C; diff --git a/src/oneconnform.cpp b/src/oneconnform.cpp index a77ba9e4..8486492e 100644 --- a/src/oneconnform.cpp +++ b/src/oneconnform.cpp @@ -871,9 +871,13 @@ void OneConnForm::toConnectWirelessNetwork() //需要密码的wifi连接 void OneConnForm::on_btnConnPWD_clicked() { + mw->m_is_inputting_wifi_password = false; //点击连接表示密码输入已完成 m_connWithPwd = true; qDebug()<<"A button named btnConnPWD about wifi net is clicked."; if (lbPwdTip->isVisible()) { + QString modifyCmd = "nmcli connection modify \""+ wifiName + "\" " + "802-11-wireless-security.psk " + ui->lePassword->text(); + int mdf_res = system(modifyCmd.toUtf8().data()); + qDebug()<<"Modified wifi password, cmd="<hide(); mw->m_wifi_list_pwd_changed.removeOne(wifiName); } @@ -1115,7 +1119,7 @@ void OneConnForm::slotConnWifiResult(int connFlag) } if (connFlag == 1 || connFlag == 4) { - if (!m_connWithPwd) { + if (!m_connWithPwd && hasPwd) { //用原有配置文件连接失败,显示密码错误 qDebug()<<"Connected failed with old configuration. ssid="<