From af822db78a36b6a92d6b7790d7efd73088c37fec Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Wed, 1 Mar 2023 11:35:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=8E=A5=E5=8F=A3=20?= =?UTF-8?q?=E6=97=A0=E7=BA=BF=E5=BC=80=E5=85=B3=E7=9B=91=E5=90=ACgsetting?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E7=A7=BB=E5=8A=A8=E7=83=AD=E7=82=B9?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=8F=98=E5=8C=96=E4=BF=A1=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../libnm-base-kylin/depend/kyapnetresource.h | 2 +- .../depend/kylinnetworkresourcemanager.cpp | 23 ++++++++++-- .../depend/kylinnetworkresourcemanager.h | 5 ++- .../depend/kywirelessnetresource.cpp | 35 +++++++++++++++++++ .../depend/kywirelessnetresource.h | 1 + .../libnm-base-kylin/kylinnetworkmanager.h | 3 +- .../libnm-base-kylin/kylinnetworkmanger.cpp | 2 ++ 7 files changed, 66 insertions(+), 5 deletions(-) diff --git a/libnm-kylin/libnm-base-kylin/depend/kyapnetresource.h b/libnm-kylin/libnm-base-kylin/depend/kyapnetresource.h index acc4e020..9b1f3793 100644 --- a/libnm-kylin/libnm-base-kylin/depend/kyapnetresource.h +++ b/libnm-kylin/libnm-base-kylin/depend/kyapnetresource.h @@ -14,7 +14,7 @@ public: void getApConnections(QList &apConnectItemList); Q_SIGNALS: - void wirelessApConnectStateChange(); + void wirelessApConnectStateChange(QString devName, QString ssid, QString uuid, KyConnectState state); private: KyApConnectItem getApConnectItem(NetworkManager::Connection::Ptr connectPtr); KyApConnectItem getApConnectionByUuid(QString connectUuid); diff --git a/libnm-kylin/libnm-base-kylin/depend/kylinnetworkresourcemanager.cpp b/libnm-kylin/libnm-base-kylin/depend/kylinnetworkresourcemanager.cpp index 3aa51e0c..3f25236f 100644 --- a/libnm-kylin/libnm-base-kylin/depend/kylinnetworkresourcemanager.cpp +++ b/libnm-kylin/libnm-base-kylin/depend/kylinnetworkresourcemanager.cpp @@ -27,6 +27,8 @@ #define LOG_FLAG "[KyNetworkResourceManager]" +const QString WIRED_SWITCH = "wiredswitch"; + //单例部分 KyNetworkResourceManager* KyNetworkResourceManager::m_pInstance = nullptr; @@ -53,6 +55,11 @@ KyNetworkResourceManager::KyNetworkResourceManager(QObject *parent) : QObject(pa qRegisterMetaType("KyConnectState"); qRegisterMetaType("KyConnectivity"); qRegisterMetaType("KyDeviceType"); + //GSettings + const QByteArray id(GSETTINGS_SCHEMA); + if (QGSettings::isSchemaInstalled(id)) { + m_switchGsettings = new QGSettings(id, QByteArray(), this); + } } //start后执行 循环检查m_initFinished 非true阻塞 @@ -87,7 +94,7 @@ void KyNetworkResourceManager::onInitNetwork() connect(NetworkManager::notifier(), &NetworkManager::Notifier::networkingEnabledChanged, this, &KyNetworkResourceManager::networkingEnabledChanged); connect(NetworkManager::notifier(), &NetworkManager::Notifier::wirelessEnabledChanged, - this, &KyNetworkResourceManager::wifiEnabledChanged); + this, &KyNetworkResourceManager::onWirelessEnabledChanged); connect(NetworkManager::notifier(), &NetworkManager::Notifier::primaryConnectionTypeChanged, this, &KyNetworkResourceManager::onPrimaryConnectionTypeChanged); @@ -605,11 +612,22 @@ void KyNetworkResourceManager::onPropertiesChanged(QVariantMap qvm) if (keyStr == "WiredEnabled") { bool wiredEnable = qvm.value("WiredEnabled").toBool(); qDebug() << "wiredEnabledChanged" << wiredEnable; + if (m_switchGsettings != nullptr && m_switchGsettings->get(WIRED_SWITCH).toBool() != wiredEnable) { + m_switchGsettings->set(WIRED_SWITCH, 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() { @@ -675,7 +693,8 @@ void KyNetworkResourceManager::connectActiveStateChange(NetworkManager::Connecti = connectSettingsPtr->setting(NetworkManager::Setting::Wireless).dynamicCast(); if (NetworkManager::WirelessSetting::NetworkMode::Ap == wirelessSetting->mode()) { - Q_EMIT wirelessApConnectStateChange(); + QString ssid = wirelessSetting->ssid(); + Q_EMIT wirelessApConnectStateChange(deviceName, ssid, uuid, state); } } else if (connectionType == CONNECT_TYPE_WIRED) { wiredActiveStateChange(connectPtr->path(), deviceName, uuid, state); diff --git a/libnm-kylin/libnm-base-kylin/depend/kylinnetworkresourcemanager.h b/libnm-kylin/libnm-base-kylin/depend/kylinnetworkresourcemanager.h index c8e6eef9..a02c01ef 100644 --- a/libnm-kylin/libnm-base-kylin/depend/kylinnetworkresourcemanager.h +++ b/libnm-kylin/libnm-base-kylin/depend/kylinnetworkresourcemanager.h @@ -43,6 +43,7 @@ #include "NetworkManagerQt/Security8021xSetting" #include #include +#include #include "kylinnetworkresourcetype.h" @@ -126,6 +127,7 @@ private: private Q_SLOTS: void onServiceAppear(QString, QString, QString); void onPropertiesChanged(QVariantMap qvm); + void onWirelessEnabledChanged(bool enable); Q_SIGNALS: @@ -176,7 +178,7 @@ Q_SIGNALS: void wiredConnectStateChange(QString deviceName, 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 @@ -239,6 +241,7 @@ private: NetworkManager::WirelessNetwork::List m_wifiNetList; QMap m_deviceMap; + QGSettings *m_switchGsettings; }; diff --git a/libnm-kylin/libnm-base-kylin/depend/kywirelessnetresource.cpp b/libnm-kylin/libnm-base-kylin/depend/kywirelessnetresource.cpp index 37f55df8..99caab98 100644 --- a/libnm-kylin/libnm-base-kylin/depend/kywirelessnetresource.cpp +++ b/libnm-kylin/libnm-base-kylin/depend/kywirelessnetresource.cpp @@ -593,6 +593,9 @@ void KyWirelessNetResource::onDeviceNameUpdate(QString oldName, QString newName) void KyWirelessNetResource::updateList() { + QMap > map; + QVector vector; + for (int i = 0; i< m_WifiNetworkList.keys().size(); ++i) { QString devName = m_WifiNetworkList.keys().at(i); QList connectItemList; @@ -601,7 +604,39 @@ void KyWirelessNetResource::updateList() QList list = m_WifiNetworkList[devName]; wifiListSort(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()<, QList); + void updateWifiListInCtrlCenter(QMap>); private: QMap> m_WifiNetworkList; diff --git a/libnm-kylin/libnm-base-kylin/kylinnetworkmanager.h b/libnm-kylin/libnm-base-kylin/kylinnetworkmanager.h index bcf6d10a..3803d7c0 100644 --- a/libnm-kylin/libnm-base-kylin/kylinnetworkmanager.h +++ b/libnm-kylin/libnm-base-kylin/kylinnetworkmanager.h @@ -77,9 +77,10 @@ Q_SIGNALS: void wirelessDeviceNameUpdate(QString oldName, QString newName); void updateWifiList(QString, QList, QList); + void updateWifiListInCtrlCenter(QMap>); //移动热点 - void wirelessApConnectStateChange(); + void wirelessApConnectStateChange(QString devName, QString ssid, QString uuid, KyConnectState state); diff --git a/libnm-kylin/libnm-base-kylin/kylinnetworkmanger.cpp b/libnm-kylin/libnm-base-kylin/kylinnetworkmanger.cpp index 83342849..ce2a31e7 100644 --- a/libnm-kylin/libnm-base-kylin/kylinnetworkmanger.cpp +++ b/libnm-kylin/libnm-base-kylin/kylinnetworkmanger.cpp @@ -95,6 +95,8 @@ void KyNetworkManager::initConnect() this, &KyNetworkManager::wirelessDeviceNameUpdate); connect(m_wirelessNetResource, &KyWirelessNetResource::updateWifiList, this, &KyNetworkManager::updateWifiList); + connect(m_wirelessNetResource, &KyWirelessNetResource::updateWifiListInCtrlCenter, + this, &KyNetworkManager::updateWifiListInCtrlCenter); } //同步方法