diff --git a/src/ksimplenm.cpp b/src/ksimplenm.cpp index ec4bd96a..8a0f5f81 100644 --- a/src/ksimplenm.cpp +++ b/src/ksimplenm.cpp @@ -85,7 +85,7 @@ void KSimpleNM::execGetWifiList() isExecutingGetWifiList = true; shellOutputWifi = ""; - runProcessWifi->start("nmcli -f signal,security,freq,bssid,ssid device wifi"); + runProcessWifi->start("nmcli -f in-use,signal,security,freq,bssid,ssid device wifi"); } //获取保存的网络列表数据 diff --git a/src/kylin-dbus-interface.cpp b/src/kylin-dbus-interface.cpp index d366797c..6555d838 100644 --- a/src/kylin-dbus-interface.cpp +++ b/src/kylin-dbus-interface.cpp @@ -1014,7 +1014,7 @@ bool KylinDBus::checkNetworkConnectivity() } //获取已经连接无线网络的ssid和uuid -QList KylinDBus::getAtiveWifiBSsidUuid() +QList KylinDBus::getAtiveWifiBSsidUuid(QStringList wifilist) { QList strBSsidUuid; @@ -1047,73 +1047,46 @@ QList KylinDBus::getAtiveWifiBSsidUuid() "org.freedesktop.DBus.Properties", QDBusConnection::systemBus() ); - //先获取uuid + //获取已经连接wifi的uuid QDBusReply replyUuid = interfaceInfo.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Uuid"); //qDebug() << "wifi uuid : "<< replyUuid.value().toString(); strBSsidUuid.append(replyUuid.value().toString()); - - - //再获取bssid -// QDBusMessage resultConnection = interfaceInfo.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Connection"); - -// QList outArgsConnection = resultConnection.arguments(); -// QVariant firstConnection = outArgsConnection.at(0); -// QDBusVariant dbvFirstConnection = firstConnection.value(); -// QVariant vFirstConnection = dbvFirstConnection.variant(); -// QDBusObjectPath dbusArgsConnection = vFirstConnection.value(); - -// QDBusInterface interfaceSet("org.freedesktop.NetworkManager", -// dbusArgsConnection.path(), -// "org.freedesktop.NetworkManager.Settings.Connection", -// QDBusConnection::systemBus()); -// QDBusMessage resultSet = interfaceSet.call("GetSettings"); - -// const QDBusArgument &dbusArg1stSet = resultSet.arguments().at( 0 ).value(); -// QMap> mapSet; -// dbusArg1stSet >> mapSet; - -// for (QString setKey : mapSet.keys() ) { -// QMap subSetMap = mapSet.value(setKey); -// if (setKey == "802-11-wireless") { -// for (QString searchKey : subSetMap.keys()) { -// if (searchKey == "seen-bssids") { -// //qDebug() << "wifi bssid : "<start("nmcli -f IN-USE,BSSID device wifi"); - connect(processWifiBSsid, static_cast(&QProcess::finished), this, [ = ]() { - processWifiBSsid->deleteLater(); - }); - connect(processWifiBSsid, &QProcess::readyReadStandardOutput, this, [ = ]() { - QString strOutput = processWifiBSsid->readAllStandardOutput(); - actWifiListInfo += strOutput; - }); - processWifiBSsid->waitForFinished(); + //获取已经连接wifi的bssid + if (wifilist.size() != 0) { + // 填充可用网络列表 + QString headLine = wifilist.at(0); + int indexSignal,indexSecu, indexFreq, indexBSsid, indexName; + headLine = headLine.trimmed(); - wifiBSsid = actWifiListInfo.split("\n"); - foreach (QString strActWifiBSsid, wifiBSsid) { - if (strActWifiBSsid.indexOf("*") != -1) { - connWifiBSsid = strActWifiBSsid.mid(3).trimmed(); + bool isChineseExist = headLine.contains(QRegExp("[\\x4e00-\\x9fa5]+")); + if (isChineseExist) { + indexSignal = headLine.indexOf("SIGNAL"); + indexSecu = headLine.indexOf("安全性"); + indexFreq = headLine.indexOf("频率") + 4; + indexBSsid = headLine.indexOf("BSSID") + 6; + indexName = indexBSsid + 19; + } else { + indexSignal = headLine.indexOf("SIGNAL"); + indexSecu = headLine.indexOf("SECURITY"); + indexFreq = headLine.indexOf("FREQ"); + indexBSsid = headLine.indexOf("BSSID"); + indexName = indexBSsid + 19; + } + + for (int i = 1, j = 0; i < wifilist.size(); i ++) { + QString line = wifilist.at(i); + QString winuse = line.mid(0, indexSignal).trimmed(); + QString wbssid = line.mid(indexBSsid, 17).trimmed(); + if (winuse == "*") { + strBSsidUuid.append(wbssid); + } } } - if (connWifiBSsid != "--") { - strBSsidUuid.append(connWifiBSsid); - } - actWifiListInfo = ""; return strBSsidUuid; } diff --git a/src/kylin-dbus-interface.h b/src/kylin-dbus-interface.h index 4f5e596f..1f47b7de 100644 --- a/src/kylin-dbus-interface.h +++ b/src/kylin-dbus-interface.h @@ -52,7 +52,7 @@ public: void showDesktopNotify(QString message); void initConnectionInfo(); QList getAtiveLanSsidUuidState(); - QList getAtiveWifiBSsidUuid(); + QList getAtiveWifiBSsidUuid(QStringList wifilist); void reConnectWiredNet(QString netUuid); bool toConnectWiredNet(QString netUuid, QString netIfName); void getConnectNetIp(QString netUuid); @@ -118,8 +118,6 @@ private: Utils *mUtils; QThread *mUtilsThread; - QString actWifiListInfo; - int a = 0; bool isRunningFunction = false; QTimer *time = nullptr; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4fab948f..0e8e7f3d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1705,7 +1705,7 @@ void MainWindow::loadWifiListDone(QStringList slist) QList currConnWifiBSsidUuid; bool isLoop = true; do { - currConnWifiBSsidUuid = objKyDBus->getAtiveWifiBSsidUuid(); + currConnWifiBSsidUuid = objKyDBus->getAtiveWifiBSsidUuid(slist); if (currConnWifiBSsidUuid.size() == 1 && currConnWifiBSsidUuid.at(0).length() != 17) { sleep(1); //等于1说明只获取到uuid,1秒后再获取一次 } else { @@ -1777,21 +1777,21 @@ void MainWindow::loadWifiListDone(QStringList slist) // 填充可用网络列表 QString headLine = slist.at(0); - int indexSecu, indexFreq, indexBSsid, indexName; + int indexSignal,indexSecu, indexFreq, indexBSsid, indexName; headLine = headLine.trimmed(); bool isChineseExist = headLine.contains(QRegExp("[\\x4e00-\\x9fa5]+")); if (isChineseExist) { + indexSignal = headLine.indexOf("SIGNAL"); indexSecu = headLine.indexOf("安全性"); indexFreq = headLine.indexOf("频率") + 4; indexBSsid = headLine.indexOf("BSSID") + 6; - //indexName = headLine.indexOf("SSID") + 6; indexName = indexBSsid + 19; } else { + indexSignal = headLine.indexOf("SIGNAL"); indexSecu = headLine.indexOf("SECURITY"); indexFreq = headLine.indexOf("FREQ"); indexBSsid = headLine.indexOf("BSSID"); - //indexName = headLine.indexOf("SSID"); indexName = indexBSsid + 19; } QStringList wnames; @@ -1809,7 +1809,7 @@ void MainWindow::loadWifiListDone(QStringList slist) for (int i = 1, j = 0; i < slist.size(); i ++) { QString line = slist.at(i); - QString wsignal = line.mid(0, indexSecu).trimmed(); + QString wsignal = line.mid(indexSignal, 3).trimmed(); QString wsecu = line.mid(indexSecu, indexFreq - indexSecu).trimmed(); QString wbssid = line.mid(indexBSsid, 17).trimmed(); QString wname = line.mid(indexName).trimmed(); diff --git a/src/oneconnform.cpp b/src/oneconnform.cpp index 05c68bc1..9cf772fd 100644 --- a/src/oneconnform.cpp +++ b/src/oneconnform.cpp @@ -963,8 +963,9 @@ void OneConnForm::on_btnCancel_clicked() // } KylinDBus myKylinDbus; - QList wifiSsidAndUuid = myKylinDbus.getAtiveWifiBSsidUuid(); - if (wifiSsidAndUuid.size() >= 1) { + QStringList wifiListInfo; + QList wifiSsidAndUuid = myKylinDbus.getAtiveWifiBSsidUuid(wifiListInfo); + if (wifiSsidAndUuid.size() >= 1 && wifiSsidAndUuid.at(0).length() != 17) { QString currentConnectWifiUuid = wifiSsidAndUuid.at(0); kylin_network_set_con_down(currentConnectWifiUuid.toUtf8().data()); }