补充接口 无线开关监听gsetting 修改移动热点状态变化信号

This commit is contained in:
zhangyuanyuan1 2023-03-01 11:35:59 +08:00
parent b8b6b8660b
commit af822db78a
7 changed files with 66 additions and 5 deletions

View File

@ -14,7 +14,7 @@ public:
void getApConnections(QList<KyApConnectItem> &apConnectItemList); void getApConnections(QList<KyApConnectItem> &apConnectItemList);
Q_SIGNALS: Q_SIGNALS:
void wirelessApConnectStateChange(); void wirelessApConnectStateChange(QString devName, QString ssid, QString uuid, KyConnectState state);
private: private:
KyApConnectItem getApConnectItem(NetworkManager::Connection::Ptr connectPtr); KyApConnectItem getApConnectItem(NetworkManager::Connection::Ptr connectPtr);
KyApConnectItem getApConnectionByUuid(QString connectUuid); KyApConnectItem getApConnectionByUuid(QString connectUuid);

View File

@ -27,6 +27,8 @@
#define LOG_FLAG "[KyNetworkResourceManager]" #define LOG_FLAG "[KyNetworkResourceManager]"
const QString WIRED_SWITCH = "wiredswitch";
//单例部分 //单例部分
KyNetworkResourceManager* KyNetworkResourceManager::m_pInstance = nullptr; KyNetworkResourceManager* KyNetworkResourceManager::m_pInstance = nullptr;
@ -53,6 +55,11 @@ KyNetworkResourceManager::KyNetworkResourceManager(QObject *parent) : QObject(pa
qRegisterMetaType<KyConnectState>("KyConnectState"); qRegisterMetaType<KyConnectState>("KyConnectState");
qRegisterMetaType<KyConnectivity>("KyConnectivity"); qRegisterMetaType<KyConnectivity>("KyConnectivity");
qRegisterMetaType<KyDeviceType>("KyDeviceType"); qRegisterMetaType<KyDeviceType>("KyDeviceType");
//GSettings
const QByteArray id(GSETTINGS_SCHEMA);
if (QGSettings::isSchemaInstalled(id)) {
m_switchGsettings = new QGSettings(id, QByteArray(), this);
}
} }
//start后执行 循环检查m_initFinished 非true阻塞 //start后执行 循环检查m_initFinished 非true阻塞
@ -87,7 +94,7 @@ void KyNetworkResourceManager::onInitNetwork()
connect(NetworkManager::notifier(), &NetworkManager::Notifier::networkingEnabledChanged, connect(NetworkManager::notifier(), &NetworkManager::Notifier::networkingEnabledChanged,
this, &KyNetworkResourceManager::networkingEnabledChanged); this, &KyNetworkResourceManager::networkingEnabledChanged);
connect(NetworkManager::notifier(), &NetworkManager::Notifier::wirelessEnabledChanged, connect(NetworkManager::notifier(), &NetworkManager::Notifier::wirelessEnabledChanged,
this, &KyNetworkResourceManager::wifiEnabledChanged); this, &KyNetworkResourceManager::onWirelessEnabledChanged);
connect(NetworkManager::notifier(), &NetworkManager::Notifier::primaryConnectionTypeChanged, connect(NetworkManager::notifier(), &NetworkManager::Notifier::primaryConnectionTypeChanged,
this, &KyNetworkResourceManager::onPrimaryConnectionTypeChanged); this, &KyNetworkResourceManager::onPrimaryConnectionTypeChanged);
@ -605,11 +612,22 @@ void KyNetworkResourceManager::onPropertiesChanged(QVariantMap qvm)
if (keyStr == "WiredEnabled") { if (keyStr == "WiredEnabled") {
bool wiredEnable = qvm.value("WiredEnabled").toBool(); bool wiredEnable = qvm.value("WiredEnabled").toBool();
qDebug() << "wiredEnabledChanged" << wiredEnable; qDebug() << "wiredEnabledChanged" << wiredEnable;
if (m_switchGsettings != nullptr && m_switchGsettings->get(WIRED_SWITCH).toBool() != wiredEnable) {
m_switchGsettings->set(WIRED_SWITCH, wiredEnable);
}
Q_EMIT wiredEnabledChanged(wiredEnable); Q_EMIT wiredEnabledChanged(wiredEnable);
} }
} }
} }
void KyNetworkResourceManager::onWirelessEnabledChanged(bool enable)
{
if (m_switchGsettings != nullptr && m_switchGsettings->get(WIRELESS_SWITCH).toBool() != enable) {
m_switchGsettings->set(WIRELESS_SWITCH, enable);
}
Q_EMIT wifiEnabledChanged(enable);
}
void KyNetworkResourceManager::onConnectionUpdated() void KyNetworkResourceManager::onConnectionUpdated()
{ {
@ -675,7 +693,8 @@ void KyNetworkResourceManager::connectActiveStateChange(NetworkManager::Connecti
= connectSettingsPtr->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>(); = connectSettingsPtr->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
if (NetworkManager::WirelessSetting::NetworkMode::Ap if (NetworkManager::WirelessSetting::NetworkMode::Ap
== wirelessSetting->mode()) { == wirelessSetting->mode()) {
Q_EMIT wirelessApConnectStateChange(); QString ssid = wirelessSetting->ssid();
Q_EMIT wirelessApConnectStateChange(deviceName, ssid, uuid, state);
} }
} else if (connectionType == CONNECT_TYPE_WIRED) { } else if (connectionType == CONNECT_TYPE_WIRED) {
wiredActiveStateChange(connectPtr->path(), deviceName, uuid, state); wiredActiveStateChange(connectPtr->path(), deviceName, uuid, state);

View File

@ -43,6 +43,7 @@
#include "NetworkManagerQt/Security8021xSetting" #include "NetworkManagerQt/Security8021xSetting"
#include <QDBusPendingCallWatcher> #include <QDBusPendingCallWatcher>
#include <QMetaEnum> #include <QMetaEnum>
#include <QGSettings/QGSettings>
#include "kylinnetworkresourcetype.h" #include "kylinnetworkresourcetype.h"
@ -126,6 +127,7 @@ private:
private Q_SLOTS: private Q_SLOTS:
void onServiceAppear(QString, QString, QString); void onServiceAppear(QString, QString, QString);
void onPropertiesChanged(QVariantMap qvm); void onPropertiesChanged(QVariantMap qvm);
void onWirelessEnabledChanged(bool enable);
Q_SIGNALS: Q_SIGNALS:
@ -176,7 +178,7 @@ Q_SIGNALS:
void wiredConnectStateChange(QString deviceName, QString uuid, KyConnectState state); void wiredConnectStateChange(QString deviceName, QString uuid, KyConnectState state);
void wirelessConnectStateChange(QString deviceName, QString ssid, QString uuid, KyConnectState state); void wirelessConnectStateChange(QString deviceName, QString ssid, QString uuid, KyConnectState state);
void wirelessApConnectStateChange(); void wirelessApConnectStateChange(QString devName, QString ssid, QString uuid, KyConnectState state);
//general //general
@ -239,6 +241,7 @@ private:
NetworkManager::WirelessNetwork::List m_wifiNetList; NetworkManager::WirelessNetwork::List m_wifiNetList;
QMap<QString, QString> m_deviceMap; QMap<QString, QString> m_deviceMap;
QGSettings *m_switchGsettings;
}; };

View File

@ -593,6 +593,9 @@ void KyWirelessNetResource::onDeviceNameUpdate(QString oldName, QString newName)
void KyWirelessNetResource::updateList() void KyWirelessNetResource::updateList()
{ {
QMap<QString, QVector<QStringList> > map;
QVector<QStringList> vector;
for (int i = 0; i< m_WifiNetworkList.keys().size(); ++i) { for (int i = 0; i< m_WifiNetworkList.keys().size(); ++i) {
QString devName = m_WifiNetworkList.keys().at(i); QString devName = m_WifiNetworkList.keys().at(i);
QList<KyActivateItem> connectItemList; QList<KyActivateItem> connectItemList;
@ -601,7 +604,39 @@ void KyWirelessNetResource::updateList()
QList<KyWirelessNetItem> list = m_WifiNetworkList[devName]; QList<KyWirelessNetItem> list = m_WifiNetworkList[devName];
wifiListSort(list); wifiListSort(list);
Q_EMIT updateWifiList(devName, connectItemList, list); Q_EMIT updateWifiList(devName, connectItemList, list);
QString activeSsid;
vector.clear();
if (!connectItemList.isEmpty()) {
QString secuType = "";
int category = 0;
activeSsid = connectItemList.at(0).m_ssid;
getWirelessConnectInfo(devName, secuType, category);
vector.append(QStringList() << activeSsid
<< QString::number(actResource.getAcivateWifiSignal())
<< secuType
<< connectItemList.at(0).m_uuid
<< QString::number(isApConnection(connectItemList.at(0).m_uuid))
<< QString::number(category));
} else {
vector.append(QStringList("--"));
} }
if (!list.isEmpty()) {
for (const auto itemData : list) {
if (itemData.m_NetSsid == activeSsid) {
continue;
} else {
vector.append(QStringList()<<itemData.m_NetSsid
<< QString::number(itemData.m_signalStrength)
<< itemData.m_secuType
<< QString::number(itemData.m_isApConnection)
<< QString::number(itemData.m_category));
}
}
}
map.insert(devName, vector);
}
Q_EMIT updateWifiListInCtrlCenter(map);
} }
QString KyWirelessNetResource::getDeviceIFace(NetworkManager::WirelessNetwork::Ptr net) QString KyWirelessNetResource::getDeviceIFace(NetworkManager::WirelessNetwork::Ptr net)

View File

@ -78,6 +78,7 @@ Q_SIGNALS:
void wirelessDeviceNameUpdate(QString oldName, QString newName); void wirelessDeviceNameUpdate(QString oldName, QString newName);
void updateWifiList(QString, QList<KyActivateItem>, QList<KyWirelessNetItem>); void updateWifiList(QString, QList<KyActivateItem>, QList<KyWirelessNetItem>);
void updateWifiListInCtrlCenter(QMap<QString, QVector<QStringList>>);
private: private:
QMap<QString, QList<KyWirelessNetItem>> m_WifiNetworkList; QMap<QString, QList<KyWirelessNetItem>> m_WifiNetworkList;

View File

@ -77,9 +77,10 @@ Q_SIGNALS:
void wirelessDeviceNameUpdate(QString oldName, QString newName); void wirelessDeviceNameUpdate(QString oldName, QString newName);
void updateWifiList(QString, QList<KyActivateItem>, QList<KyWirelessNetItem>); void updateWifiList(QString, QList<KyActivateItem>, QList<KyWirelessNetItem>);
void updateWifiListInCtrlCenter(QMap<QString, QVector<QStringList>>);
//移动热点 //移动热点
void wirelessApConnectStateChange(); void wirelessApConnectStateChange(QString devName, QString ssid, QString uuid, KyConnectState state);

View File

@ -95,6 +95,8 @@ void KyNetworkManager::initConnect()
this, &KyNetworkManager::wirelessDeviceNameUpdate); this, &KyNetworkManager::wirelessDeviceNameUpdate);
connect(m_wirelessNetResource, &KyWirelessNetResource::updateWifiList, connect(m_wirelessNetResource, &KyWirelessNetResource::updateWifiList,
this, &KyNetworkManager::updateWifiList); this, &KyNetworkManager::updateWifiList);
connect(m_wirelessNetResource, &KyWirelessNetResource::updateWifiListInCtrlCenter,
this, &KyNetworkManager::updateWifiListInCtrlCenter);
} }
//同步方法 //同步方法