Fix bug UI stucked sometimes if use in-use property to refresh wifi list

This commit is contained in:
chenlelin 2021-02-24 11:12:46 +08:00
parent 99daef74a9
commit c48faca769
5 changed files with 40 additions and 68 deletions

View File

@ -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");
}
//获取保存的网络列表数据

View File

@ -1014,7 +1014,7 @@ bool KylinDBus::checkNetworkConnectivity()
}
//获取已经连接无线网络的ssid和uuid
QList<QString> KylinDBus::getAtiveWifiBSsidUuid()
QList<QString> KylinDBus::getAtiveWifiBSsidUuid(QStringList wifilist)
{
QList<QString> strBSsidUuid;
@ -1047,73 +1047,46 @@ QList<QString> KylinDBus::getAtiveWifiBSsidUuid()
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
//获取uuid
//获取已经连接wifi的uuid
QDBusReply<QVariant> 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<QVariant> outArgsConnection = resultConnection.arguments();
// QVariant firstConnection = outArgsConnection.at(0);
// QDBusVariant dbvFirstConnection = firstConnection.value<QDBusVariant>();
// QVariant vFirstConnection = dbvFirstConnection.variant();
// QDBusObjectPath dbusArgsConnection = vFirstConnection.value<QDBusObjectPath>();
// 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<QDBusArgument>();
// QMap<QString,QMap<QString,QVariant>> mapSet;
// dbusArg1stSet >> mapSet;
// for (QString setKey : mapSet.keys() ) {
// QMap<QString,QVariant> subSetMap = mapSet.value(setKey);
// if (setKey == "802-11-wireless") {
// for (QString searchKey : subSetMap.keys()) {
// if (searchKey == "seen-bssids") {
// //qDebug() << "wifi bssid : "<<subSetMap.value(searchKey).toStringList();
// QStringList strBssidList = subSetMap.value(searchKey).toStringList();
// foreach (QString strBssid, strBssidList) {
// strBSsidUuid.append(strBssid);
// }
// }
// }
// }
// }
}
}
dbusArgs.endArray();
QStringList wifiBSsid;
QString connWifiBSsid = "--";
QProcess * processWifiBSsid = new QProcess;
processWifiBSsid->start("nmcli -f IN-USE,BSSID device wifi");
connect(processWifiBSsid, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&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;
}

View File

@ -52,7 +52,7 @@ public:
void showDesktopNotify(QString message);
void initConnectionInfo();
QList<QString> getAtiveLanSsidUuidState();
QList<QString> getAtiveWifiBSsidUuid();
QList<QString> 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;

View File

@ -1705,7 +1705,7 @@ void MainWindow::loadWifiListDone(QStringList slist)
QList<QString> currConnWifiBSsidUuid;
bool isLoop = true;
do {
currConnWifiBSsidUuid = objKyDBus->getAtiveWifiBSsidUuid();
currConnWifiBSsidUuid = objKyDBus->getAtiveWifiBSsidUuid(slist);
if (currConnWifiBSsidUuid.size() == 1 && currConnWifiBSsidUuid.at(0).length() != 17) {
sleep(1); //等于1说明只获取到uuid1秒后再获取一次
} 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();

View File

@ -963,8 +963,9 @@ void OneConnForm::on_btnCancel_clicked()
// }
KylinDBus myKylinDbus;
QList<QString> wifiSsidAndUuid = myKylinDbus.getAtiveWifiBSsidUuid();
if (wifiSsidAndUuid.size() >= 1) {
QStringList wifiListInfo;
QList<QString> 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());
}