Optimization demo to get wifi list by dbus method

This commit is contained in:
chenlelin 2021-02-24 17:27:09 +08:00
parent d3b1824a1c
commit 71c5fc0e2b
3 changed files with 31 additions and 8 deletions

View File

@ -1090,7 +1090,9 @@ QList<QString> KylinDBus::getAtiveWifiBSsidUuid(QStringList wifilist)
return strBSsidUuid;
}
void KylinDBus::execGetWifiList()
//使用dbus的方法获取wifi的信息形成包含每个wifi信息的列表
void KylinDBus::toGetWifiList()
{
QStringList slist;
@ -1140,16 +1142,37 @@ void KylinDBus::execGetWifiList()
QDBusReply<QVariant> replyHwAddress = interfaceAP.call("Get", "org.freedesktop.NetworkManager.AccessPoint", "HwAddress"); //bssid
QDBusReply<QVariant> replySsid = interfaceAP.call("Get", "org.freedesktop.NetworkManager.AccessPoint", "Ssid"); //ssid
QString strFlags = replyFlags.value().toString();
//QString strSsid = replySsid.value().toString();
//slist.append(strSsid);
QString strStrength;
QByteArray sesultStrength = replyStrength.value().toByteArray();
int addr = sesultStrength[0] & 0x000000FF;
addr |= ((sesultStrength[1] << 8) & 0x0000FF00);
addr |= ((sesultStrength[2] << 16) & 0x00FF0000);
addr |= ((sesultStrength[3] << 24) & 0xFF000000);
strStrength = QString::number(addr);
QString strWpaFlags = replyWpaFlags.value().toString();
QString strFrequency = replyFrequency.value().toString();
QString strHwAddress = replyHwAddress.value().toString();
QString strSsid = replySsid.value().toString();
slist.append(strFlags);
slist.append(strStrength);
slist.append(strWpaFlags);
slist.append(strFrequency);
slist.append(strHwAddress);
slist.append(strSsid);
}
dbusArgsAccessPoints.endArray();
}
dbusArgsAllDevices.endArray();
emit getWifiListFinished(slist);
emit toGetWifiListFinished(slist);
}
//网络连接变化时,如有新增或减少的网络,发信号通知更新主界面

View File

@ -75,7 +75,7 @@ public:
int checkWifiConnectivity();
bool checkNetworkConnectivity();
void execGetWifiList();
void toGetWifiList();
QDBusObjectPath wirelessPath; //无线设备的路径
QList<QDBusObjectPath> multiWiredPaths; //Wired Device的对象路径列表
@ -136,7 +136,7 @@ signals:
void updateWiredList(int n);
void requestSendDesktopNotify(QString message);
void newConnAdded(int type);
void getWifiListFinished(QStringList slist);
void toGetWifiListFinished(QStringList slist);
};
#endif // KYLINDBUSINTERFACE_H

View File

@ -81,7 +81,7 @@ MainWindow::MainWindow(QWidget *parent) :
objKyDBus = new KylinDBus(this);
objKyDBus->initConnectionInfo();
connect(objKyDBus, SIGNAL(getWifiListFinished(QStringList)), this, SLOT(getWifiListDone(QStringList)));
connect(objKyDBus, SIGNAL(toGetWifiListFinished(QStringList)), this, SLOT(loadWifiListDone(QStringList)));
objNetSpeed = new NetworkSpeed();
@ -1292,7 +1292,7 @@ void MainWindow::on_btnWifiList_clicked()
btnAddNet->show();
this->startLoading();
//this->objKyDBus->execGetWifiList();
//this->objKyDBus->toGetWifiList();
this->ksnm->execGetWifiList();
} else if (iface->wstate == 3) {
qDebug() << "debug: 连接中正在配置wifi设备";