Add demo to get wifi list by dbus method

This commit is contained in:
chenlelin 2021-02-24 15:47:10 +08:00
parent c48faca769
commit d3b1824a1c
3 changed files with 67 additions and 0 deletions

View File

@ -1090,6 +1090,68 @@ QList<QString> KylinDBus::getAtiveWifiBSsidUuid(QStringList wifilist)
return strBSsidUuid;
}
void KylinDBus::execGetWifiList()
{
QStringList slist;
QDBusInterface interface( "org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
QDBusMessage resultAllDevices = interface.call("Get", "org.freedesktop.NetworkManager", "AllDevices");
QList<QVariant> outArgsAllDevices = resultAllDevices.arguments();
QVariant firstAllDevices = outArgsAllDevices.at(0);
QDBusVariant dbvFirstAllDevices = firstAllDevices.value<QDBusVariant>();
QVariant vFirstAllDevices = dbvFirstAllDevices.variant();
QDBusArgument dbusArgsAllDevices = vFirstAllDevices.value<QDBusArgument>();
QDBusObjectPath objPathDevice;
dbusArgsAllDevices.beginArray();
while (!dbusArgsAllDevices.atEnd()) {
dbusArgsAllDevices >> objPathDevice;
QDBusInterface interfacePro( "org.freedesktop.NetworkManager",
objPathDevice.path(),
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
QDBusMessage resultAccessPoints = interfacePro.call("Get", "org.freedesktop.NetworkManager.Device.Wireless", "AccessPoints");
QList<QVariant> outArgsAccessPoints = resultAccessPoints.arguments();
QVariant firstAccessPoints = outArgsAccessPoints.at(0);
QDBusVariant dbvFirstAccessPoints = firstAccessPoints.value<QDBusVariant>();
QVariant vFirstAccessPoints = dbvFirstAccessPoints.variant();
QDBusArgument dbusArgsAccessPoints = vFirstAccessPoints.value<QDBusArgument>();
QDBusObjectPath objPathAccessPoint;
dbusArgsAccessPoints.beginArray();
while (!dbusArgsAccessPoints.atEnd()) {
dbusArgsAccessPoints >> objPathAccessPoint;
QDBusInterface interfaceAP( "org.freedesktop.NetworkManager",
objPathAccessPoint.path(),
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
QDBusReply<QVariant> replyFlags = interfaceAP.call("Get", "org.freedesktop.NetworkManager.AccessPoint", "Flags"); //in-use
QDBusReply<QVariant> replyStrength = interfaceAP.call("Get", "org.freedesktop.NetworkManager.AccessPoint", "Strength"); //signal
QDBusReply<QVariant> replyWpaFlags = interfaceAP.call("Get", "org.freedesktop.NetworkManager.AccessPoint", "WpaFlags"); //security
QDBusReply<QVariant> replyFrequency = interfaceAP.call("Get", "org.freedesktop.NetworkManager.AccessPoint", "Frequency"); //freq
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 strSsid = replySsid.value().toString();
//slist.append(strSsid);
}
dbusArgsAccessPoints.endArray();
}
dbusArgsAllDevices.endArray();
emit getWifiListFinished(slist);
}
//网络连接变化时,如有新增或减少的网络,发信号通知更新主界面
void KylinDBus::onPropertiesChanged(QVariantMap qvm)
{

View File

@ -75,6 +75,8 @@ public:
int checkWifiConnectivity();
bool checkNetworkConnectivity();
void execGetWifiList();
QDBusObjectPath wirelessPath; //无线设备的路径
QList<QDBusObjectPath> multiWiredPaths; //Wired Device的对象路径列表
QList<QString> multiWiredCableState;//多有线网卡的情况,判断有线网卡对应网线是否插入
@ -134,6 +136,7 @@ signals:
void updateWiredList(int n);
void requestSendDesktopNotify(QString message);
void newConnAdded(int type);
void getWifiListFinished(QStringList slist);
};
#endif // KYLINDBUSINTERFACE_H

View File

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