Merge branch '0827-new' into 'dbus-interface'

Feature:Add wlan switch function.

See merge request kylin-desktop/kylin-nm!200
This commit is contained in:
Kang Shuning 2021-08-30 02:23:16 +00:00
commit 619e370a54
5 changed files with 48 additions and 0 deletions

View File

@ -613,6 +613,12 @@ void KyWirelessConnectOperation::addAndActiveWirelessEnterPriseTtlsConnect(KyEap
void KyWirelessConnectOperation::setWirelessEnabled(bool enabled) void KyWirelessConnectOperation::setWirelessEnabled(bool enabled)
{ {
NetworkManager::setWirelessEnabled(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() bool KyWirelessConnectOperation::getWirelessEnabled()

View File

@ -2,10 +2,14 @@
#define KYWIRELESSCONNECTOPERATION_H #define KYWIRELESSCONNECTOPERATION_H
#include <QObject> #include <QObject>
#include <QGSettings>
#include "kyenterpricesettinginfo.h" #include "kyenterpricesettinginfo.h"
#include "kylinconnectoperation.h" #include "kylinconnectoperation.h"
#include "kyenterpricesettinginfo.h" #include "kyenterpricesettinginfo.h"
const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.switch";
const QString WIRELESS_SWITCH = "wirelessswitch";
enum KySecuType { enum KySecuType {
NONE = 0, NONE = 0,
WPA_AND_WPA2_PERSONAL, WPA_AND_WPA2_PERSONAL,

View File

@ -11,6 +11,7 @@
ListItem::ListItem(QWidget *parent) : QFrame(parent) ListItem::ListItem(QWidget *parent) : QFrame(parent)
{ {
initUI(); initUI();
initConnection();
} }
ListItem::~ListItem() ListItem::~ListItem()

View File

@ -16,6 +16,7 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
initDevice(); initDevice();
m_wirelessConnectOpreation = new KyWirelessConnectOperation(this); m_wirelessConnectOpreation = new KyWirelessConnectOperation(this);
initWlanUI(); initWlanUI();
//要在initUI之后调用保证UI的信号槽顺利绑定
initConnections(); initConnections();
getActiveWlan(); getActiveWlan();
getAllWlan(); getAllWlan();
@ -80,6 +81,7 @@ void WlanPage::initWlanUI()
m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS); m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_activatedNetListWidget->setSpacing(NET_LIST_SPACING); m_activatedNetListWidget->setSpacing(NET_LIST_SPACING);
m_activatedNetListWidget->setFixedHeight(NORMAL_HEIGHT); m_activatedNetListWidget->setFixedHeight(NORMAL_HEIGHT);
m_activatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_activatedNetLayout->addWidget(m_activatedNetListWidget); m_activatedNetLayout->addWidget(m_activatedNetListWidget);
// m_inactivatedNetListArea->setFixedHeight(SCROLLAREA_HEIGHT); // m_inactivatedNetListArea->setFixedHeight(SCROLLAREA_HEIGHT);
m_inactivatedNetListArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 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::wifiNetworkRemove, this, &WlanPage::onWlanRemoved);
// connect(m_resource, &KyWirelessNetResource::wifiNetworkUpdate, this, &WlanPage::onWlanUpdated); // connect(m_resource, &KyWirelessNetResource::wifiNetworkUpdate, this, &WlanPage::onWlanUpdated);
connect(m_connectResource, &KyActiveConnectResourse::stateChangeReason, this, &WlanPage::onActivatedWlanChanged); 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__; qDebug() << "Received signal of connecting wlan, ssid = " << connSettingInfo.m_ssid << Q_FUNC_INFO << __LINE__;
m_wirelessConnectOpreation->addAndActiveWirelessConnect(defaultDevice, connSettingInfo, isHidden); 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();
}

View File

@ -7,6 +7,7 @@
#include "kylinnetworkdeviceresource.h" #include "kylinnetworkdeviceresource.h"
#include "kywirelessconnectoperation.h" #include "kywirelessconnectoperation.h"
#include "wlanlistitem.h" #include "wlanlistitem.h"
#include <QGSettings>
//#define SCROLLAREA_HEIGHT 150 //#define SCROLLAREA_HEIGHT 150
#define MORE_TEXT_MARGINS 16,0,0,0 #define MORE_TEXT_MARGINS 16,0,0,0
@ -53,6 +54,7 @@ private:
KyNetworkResourceManager *m_networkResourceInstance = nullptr; KyNetworkResourceManager *m_networkResourceInstance = nullptr;
KyNetworkDeviceResourse *m_netDeviceResource = nullptr; KyNetworkDeviceResourse *m_netDeviceResource = nullptr;
KyWirelessConnectOperation * m_wirelessConnectOpreation = nullptr; KyWirelessConnectOperation * m_wirelessConnectOpreation = nullptr;
QGSettings *m_switchGsettings = nullptr;
private slots: private slots:
@ -68,6 +70,8 @@ private slots:
NetworkManager::ActiveConnection::Reason reason); NetworkManager::ActiveConnection::Reason reason);
void onItemHeightChanged(const QString &ssid); void onItemHeightChanged(const QString &ssid);
void onConnectButtonClicked(KyWirelessConnectSetting &connSettingInfo, const bool &isHidden); void onConnectButtonClicked(KyWirelessConnectSetting &connSettingInfo, const bool &isHidden);
void onWlanSwitchClicked();
void onWlanSwitchStatusChanged(const bool &checked);
}; };
#endif // WLANPAGE_H #endif // WLANPAGE_H