diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.cpp b/src/backend/dbus-interface/kywirelessconnectoperation.cpp index aa338bb0..65060974 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.cpp +++ b/src/backend/dbus-interface/kywirelessconnectoperation.cpp @@ -613,6 +613,12 @@ void KyWirelessConnectOperation::addAndActiveWirelessEnterPriseTtlsConnect(KyEap void KyWirelessConnectOperation::setWirelessEnabled(bool enabled) { NetworkManager::setWirelessEnabled(enabled); + if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { + QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA); + gsetting->set(WIRELESS_SWITCH, enabled); + } else { + qDebug()<<"isSchemaInstalled false"; + } } bool KyWirelessConnectOperation::getWirelessEnabled() diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.h b/src/backend/dbus-interface/kywirelessconnectoperation.h index 935ec717..8b2dc624 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.h +++ b/src/backend/dbus-interface/kywirelessconnectoperation.h @@ -2,10 +2,14 @@ #define KYWIRELESSCONNECTOPERATION_H #include +#include #include "kyenterpricesettinginfo.h" #include "kylinconnectoperation.h" #include "kyenterpricesettinginfo.h" +const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.switch"; +const QString WIRELESS_SWITCH = "wirelessswitch"; + enum KySecuType { NONE = 0, WPA_AND_WPA2_PERSONAL, diff --git a/src/frontend/list-items/listitem.cpp b/src/frontend/list-items/listitem.cpp index b6f76192..f7cf5744 100644 --- a/src/frontend/list-items/listitem.cpp +++ b/src/frontend/list-items/listitem.cpp @@ -11,6 +11,7 @@ ListItem::ListItem(QWidget *parent) : QFrame(parent) { initUI(); + initConnection(); } ListItem::~ListItem() diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index c386be6c..37de66ea 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -16,6 +16,7 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent) initDevice(); m_wirelessConnectOpreation = new KyWirelessConnectOperation(this); initWlanUI(); + //要在initUI之后调用,保证UI的信号槽顺利绑定 initConnections(); getActiveWlan(); getAllWlan(); @@ -80,6 +81,7 @@ void WlanPage::initWlanUI() m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS); m_activatedNetListWidget->setSpacing(NET_LIST_SPACING); m_activatedNetListWidget->setFixedHeight(NORMAL_HEIGHT); + m_activatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_activatedNetLayout->addWidget(m_activatedNetListWidget); // m_inactivatedNetListArea->setFixedHeight(SCROLLAREA_HEIGHT); m_inactivatedNetListArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -94,6 +96,21 @@ void WlanPage::initConnections() connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::onWlanRemoved); // connect(m_resource, &KyWirelessNetResource::wifiNetworkUpdate, this, &WlanPage::onWlanUpdated); connect(m_connectResource, &KyActiveConnectResourse::stateChangeReason, this, &WlanPage::onActivatedWlanChanged); + connect(m_netSwitch, &SwitchButton::clicked, this, &WlanPage::onWlanSwitchClicked); + if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { + m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); + if (m_switchGsettings->keys().contains(WIRELESS_SWITCH)) { + m_netSwitch->setSwitchStatus(m_switchGsettings->get(WIRELESS_SWITCH).toBool()); + connect(m_switchGsettings, &QGSettings::changed, this, [ = ](const QString &key) { + if (key == WIRELESS_SWITCH) { + onWlanSwitchStatusChanged(m_switchGsettings->get(WIRELESS_SWITCH).toBool()); + } + }); + return; + } + } + qDebug()<<"isSchemaInstalled false" << Q_FUNC_INFO << __LINE__; + m_netSwitch->setSwitchStatus(m_wirelessConnectOpreation->getWirelessEnabled()); } /** @@ -348,3 +365,19 @@ void WlanPage::onConnectButtonClicked(KyWirelessConnectSetting &connSettingInfo, qDebug() << "Received signal of connecting wlan, ssid = " << connSettingInfo.m_ssid << Q_FUNC_INFO << __LINE__; m_wirelessConnectOpreation->addAndActiveWirelessConnect(defaultDevice, connSettingInfo, isHidden); } + +/** + * @brief WlanPage::onWlanSwitchClicked 点击无线网开关 + */ +void WlanPage::onWlanSwitchClicked() +{ + qDebug() << "On wlan switch button clicked! old state = " << !m_netSwitch->getSwitchStatus() << Q_FUNC_INFO << __LINE__; + m_wirelessConnectOpreation->setWirelessEnabled(m_netSwitch->getSwitchStatus()); +} + +void WlanPage::onWlanSwitchStatusChanged(const bool &checked) +{ + m_netSwitch->setSwitchStatus(checked); + qDebug() << "On wlan switch status changed! new state = " << m_netSwitch->getSwitchStatus() << Q_FUNC_INFO << __LINE__; + onWlanUpdated(); +} diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index ff0b6db4..b159f861 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -7,6 +7,7 @@ #include "kylinnetworkdeviceresource.h" #include "kywirelessconnectoperation.h" #include "wlanlistitem.h" +#include //#define SCROLLAREA_HEIGHT 150 #define MORE_TEXT_MARGINS 16,0,0,0 @@ -53,6 +54,7 @@ private: KyNetworkResourceManager *m_networkResourceInstance = nullptr; KyNetworkDeviceResourse *m_netDeviceResource = nullptr; KyWirelessConnectOperation * m_wirelessConnectOpreation = nullptr; + QGSettings *m_switchGsettings = nullptr; private slots: @@ -68,6 +70,8 @@ private slots: NetworkManager::ActiveConnection::Reason reason); void onItemHeightChanged(const QString &ssid); void onConnectButtonClicked(KyWirelessConnectSetting &connSettingInfo, const bool &isHidden); + void onWlanSwitchClicked(); + void onWlanSwitchStatusChanged(const bool &checked); }; #endif // WLANPAGE_H