Merge branch '0826-jxj' into 'dbus-interface'
Feature: Function of connecting/disconnecting wlan. See merge request kylin-desktop/kylin-nm!197
This commit is contained in:
commit
145b8e2102
|
@ -65,6 +65,7 @@ void ListItem::initConnection()
|
|||
{
|
||||
connect(this->m_netButton, &RadioItemButton::clicked, this, &ListItem::onNetButtonClicked);
|
||||
connect(this->m_infoButton, &InfoButton::clicked, this, &ListItem::onInfoButtonClicked);
|
||||
//connect(this->m_nameLabel, &QLabel::)
|
||||
}
|
||||
|
||||
void ListItem::onInfoButtonClicked()
|
||||
|
@ -76,3 +77,8 @@ void ListItem::onNetButtonClicked()
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
//void ListItem::onNameLableClicked()
|
||||
//{
|
||||
|
||||
//}
|
||||
|
|
|
@ -31,6 +31,7 @@ private:
|
|||
protected slots:
|
||||
virtual void onInfoButtonClicked();
|
||||
virtual void onNetButtonClicked();
|
||||
// virtual void onNameLableClicked();
|
||||
};
|
||||
|
||||
#endif // LISTITEM_H
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#include "wlanlistitem.h"
|
||||
#include <QResizeEvent>
|
||||
|
||||
WlanListItem::WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *data, QWidget *parent) : ListItem(parent)
|
||||
WlanListItem::WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *data, QString device, QWidget *parent) : ListItem(parent)
|
||||
{
|
||||
m_data = data;
|
||||
m_resource = resource;
|
||||
m_wlanDevice = device;
|
||||
m_connoperation = new KyWirelessConnectOperation(this);
|
||||
initWlanUI();
|
||||
setExpanded(false);
|
||||
initWlanConnection();
|
||||
|
@ -15,11 +18,15 @@ WlanListItem::WlanListItem(QWidget *parent) : ListItem(parent)
|
|||
const QString str="未连接任何wifi";
|
||||
setExpanded(false);
|
||||
this->setName(str);
|
||||
this->m_netButton->setEnabled(false);
|
||||
this->m_infoButton->hide();
|
||||
}
|
||||
|
||||
WlanListItem::~WlanListItem()
|
||||
{
|
||||
disconnect(m_resource, &KyWirelessNetResource::secuTypeChange, this, &WlanListItem::onSecurityChanged);
|
||||
disconnect(m_resource, &KyWirelessNetResource::connectionAdd, this, &WlanListItem::onConnectionAdd);
|
||||
disconnect(m_resource, &KyWirelessNetResource::connectionRemove, this, &WlanListItem::onConnectionRemove);
|
||||
}
|
||||
|
||||
void WlanListItem::setWlanSignal(const int &signal)
|
||||
|
@ -36,8 +43,32 @@ void WlanListItem::setWlanState(const int &state)
|
|||
|
||||
void WlanListItem::setExpanded(const bool &expanded)
|
||||
{
|
||||
m_isExpanded = expanded;
|
||||
if (!m_pwdFrame || !m_autoConnectFrame) {
|
||||
this->setFixedHeight(NORMAL_HEIGHT);
|
||||
return;
|
||||
}
|
||||
this->setFixedHeight(expanded ? EXPANDED_HEIGHT : NORMAL_HEIGHT);
|
||||
|
||||
m_pwdFrame->setVisible(expanded);
|
||||
m_autoConnectFrame->setVisible(expanded);
|
||||
emit this->itemHeightChanged(m_data->m_NetSsid);
|
||||
}
|
||||
|
||||
void WlanListItem::setActivated(bool activated)
|
||||
{
|
||||
this->m_isActivated = activated;
|
||||
}
|
||||
|
||||
void WlanListItem::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
this->blockSignals(true);
|
||||
if (this->height() == EXPANDED_HEIGHT) {
|
||||
this->setExpanded(true);
|
||||
} else {
|
||||
this->setExpanded(false);
|
||||
}
|
||||
this->blockSignals(false);
|
||||
return ListItem::resizeEvent(event);
|
||||
}
|
||||
|
||||
void WlanListItem::initWlanUI()
|
||||
|
@ -47,11 +78,68 @@ void WlanListItem::initWlanUI()
|
|||
this->setName((m_data->m_connName != "") ? m_data->m_connName : m_data->m_NetSsid);
|
||||
//刷新左侧按钮图标
|
||||
refreshIcon();
|
||||
|
||||
#define PWD_AREA_HEIGHT 36
|
||||
#define CONNECT_BUTTON_WIDTH 96
|
||||
#define FRAME_CONTENT_MARGINS 56,4,16,4
|
||||
#define FRAME_SPACING 8
|
||||
#define PWD_CONTENT_MARGINS 8,0,32,0
|
||||
#define SHOW_PWD_BUTTON_SIZE 16,16
|
||||
#define PWD_LAYOUT_MARGINS 8,0,8,0
|
||||
//密码输入区域的UI
|
||||
m_pwdFrame = new QFrame(this);
|
||||
m_pwdFrameLyt = new QHBoxLayout(m_pwdFrame);
|
||||
m_pwdFrameLyt->setContentsMargins(FRAME_CONTENT_MARGINS);
|
||||
m_pwdFrameLyt->setSpacing(FRAME_SPACING);
|
||||
m_pwdFrame->setLayout(m_pwdFrameLyt);
|
||||
{
|
||||
m_pwdLineEdit = new QLineEdit(m_pwdFrame);
|
||||
connect(m_pwdLineEdit, &QLineEdit::textChanged, this, &WlanListItem::onPwdEditorTextChanged);
|
||||
m_pwdLineEdit->setFixedHeight(PWD_AREA_HEIGHT);
|
||||
m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Password);
|
||||
m_pwdLineEditLyt = new QHBoxLayout(m_pwdLineEdit);
|
||||
m_pwdLineEditLyt->setContentsMargins(PWD_LAYOUT_MARGINS);
|
||||
m_pwdLineEdit->setLayout(m_pwdLineEditLyt);
|
||||
m_showPwdButton = new QPushButton(m_pwdLineEdit);
|
||||
m_showPwdButton->setFixedSize(SHOW_PWD_BUTTON_SIZE);
|
||||
connect(m_showPwdButton, &QPushButton::clicked, this, &WlanListItem::onShowPwdButtonClicked);
|
||||
m_pwdLineEditLyt->addStretch();
|
||||
m_pwdLineEditLyt->addWidget(m_showPwdButton);
|
||||
}
|
||||
m_connectButton = new QPushButton(m_pwdFrame);
|
||||
m_connectButton->setFixedSize(CONNECT_BUTTON_WIDTH, PWD_AREA_HEIGHT);
|
||||
m_connectButton->setText(tr("Connect"));
|
||||
m_connectButton->setEnabled(false);
|
||||
connect(m_connectButton, &QPushButton::clicked, this, &WlanListItem::onConnectButtonClicked);
|
||||
m_pwdFrameLyt->addWidget(m_pwdLineEdit);
|
||||
m_pwdFrameLyt->addWidget(m_connectButton);
|
||||
|
||||
//自动连接选择区域UI
|
||||
m_autoConnectFrame = new QFrame(this);
|
||||
m_autoConnectFrameLyt = new QHBoxLayout(m_autoConnectFrame);
|
||||
m_autoConnectFrameLyt->setContentsMargins(FRAME_CONTENT_MARGINS);
|
||||
m_autoConnectFrameLyt->setSpacing(FRAME_SPACING);
|
||||
m_autoConnectFrame->setLayout(m_autoConnectFrameLyt);
|
||||
m_autoConnectCheckBox = new QCheckBox(m_autoConnectFrame);
|
||||
m_autoConnectCheckBox->setChecked(true);
|
||||
m_autoConnectCheckBox->setFixedSize(SHOW_PWD_BUTTON_SIZE);
|
||||
m_autoConnectLabel = new QLabel(m_autoConnectFrame);
|
||||
m_autoConnectLabel->setText(tr("Auto Connect"));
|
||||
m_autoConnectFrameLyt->addWidget(m_autoConnectCheckBox);
|
||||
m_autoConnectFrameLyt->addWidget(m_autoConnectLabel);
|
||||
m_autoConnectFrameLyt->addStretch();
|
||||
|
||||
m_mainLayout->addWidget(m_pwdFrame);
|
||||
m_mainLayout->addWidget(m_autoConnectFrame);
|
||||
m_pwdFrame->hide();
|
||||
m_autoConnectFrame->hide();
|
||||
}
|
||||
|
||||
void WlanListItem::initWlanConnection()
|
||||
{
|
||||
connect(m_resource, &KyWirelessNetResource::secuTypeChange, this, &WlanListItem::onSecurityChanged);
|
||||
connect(m_resource, &KyWirelessNetResource::connectionAdd, this, &WlanListItem::onConnectionAdd);
|
||||
connect(m_resource, &KyWirelessNetResource::connectionRemove, this, &WlanListItem::onConnectionRemove);
|
||||
}
|
||||
|
||||
void WlanListItem::refreshIcon()
|
||||
|
@ -120,15 +208,66 @@ void WlanListItem::onInfoButtonClicked()
|
|||
|
||||
void WlanListItem::onNetButtonClicked()
|
||||
{
|
||||
//ZJP_TODO 点击连接/断开
|
||||
if(m_data){
|
||||
qDebug() << "On wlan clicked! ssid = " << m_data->m_NetSsid << "; name = " << m_data->m_connName << "." <<Q_FUNC_INFO << __LINE__;
|
||||
if(!m_data){
|
||||
qDebug() << "On wlan clicked! But there is no wlan connect!" << Q_FUNC_INFO << __LINE__;
|
||||
return;
|
||||
}
|
||||
else{
|
||||
qDebug() << "On wlan clicked! But there is no wlan connect " ;
|
||||
qDebug() << "On wlan clicked! ssid = " << m_data->m_NetSsid << "; name = " << m_data->m_connName << "." << Q_FUNC_INFO << __LINE__;
|
||||
|
||||
//判断当前item处于连接还是断开对比activessid
|
||||
QString activedssid;
|
||||
QMap<QString,QStringList> actMap;
|
||||
m_resource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap);
|
||||
QMap<QString,QStringList>::iterator iter = actMap.begin();
|
||||
while (iter != actMap.end()) {
|
||||
if (iter.key() == m_wlanDevice && !iter.value().isEmpty()) {
|
||||
activedssid = iter.value().at(0);
|
||||
break;
|
||||
}
|
||||
iter ++;
|
||||
}
|
||||
qDebug()<<"Get activated wlan succeed! ssid = " << activedssid <<Q_FUNC_INFO << __LINE__;
|
||||
|
||||
//执行连接或断开
|
||||
if (m_data->m_NetSsid == activedssid) {
|
||||
m_connoperation->deActivateWirelessConnection(m_wlanDevice,m_data->m_connectUuid);
|
||||
qDebug()<<"Clicked on connected wifi, it will be inactivated. ssid = " << m_data->m_NetSsid << Q_FUNC_INFO << __LINE__;
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_data->m_isConfigured) {
|
||||
m_connoperation->activeWirelessConnect(m_wlanDevice,m_data->m_connectUuid);
|
||||
qDebug()<<"Has configuration, will be activated. ssid = " << m_data->m_NetSsid << Q_FUNC_INFO << __LINE__;
|
||||
return;
|
||||
}
|
||||
if (!this->m_connectButton->isVisible() && m_data->m_secuType != "") {
|
||||
this->setExpanded(true);
|
||||
} else {
|
||||
onConnectButtonClicked();
|
||||
}
|
||||
}
|
||||
|
||||
//void WlanListItem::onNameLableClicked()
|
||||
//{
|
||||
// m_mainLayout = new QVBoxLayout(this);
|
||||
// m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||
// m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING);
|
||||
// this->setLayout(m_mainLayout);
|
||||
|
||||
// m_itemFrame = new QFrame(this);
|
||||
|
||||
// m_hItemLayout = new QHBoxLayout(m_itemFrame);
|
||||
// m_hItemLayout->setContentsMargins(ITEM_FRAME_MARGINS);
|
||||
// m_hItemLayout->setSpacing(ITEM_FRAME_SPACING);
|
||||
|
||||
// m_lineEdit = new QLineEdit(m_itemFrame);
|
||||
|
||||
// m_hItemLayout->addWidget(m_lineEdit);
|
||||
// m_hItemLayout->addStretch();
|
||||
|
||||
// m_mainLayout->addWidget(m_itemFrame);
|
||||
//}
|
||||
|
||||
void WlanListItem::onSecurityChanged(QString interface, QString ssid, QString securityType)
|
||||
{
|
||||
if (ssid != m_data->m_NetSsid) {
|
||||
|
@ -142,3 +281,72 @@ void WlanListItem::onSecurityChanged(QString interface, QString ssid, QString se
|
|||
refreshIcon();
|
||||
}
|
||||
}
|
||||
|
||||
void WlanListItem::onPwdEditorTextChanged()
|
||||
{
|
||||
if (!m_pwdLineEdit || !m_connectButton) {
|
||||
return;
|
||||
}
|
||||
if (m_pwdLineEdit->text().length() < PWD_LENGTH_LIMIT) {
|
||||
m_connectButton->setEnabled(false);
|
||||
} else {
|
||||
m_connectButton->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void WlanListItem::onShowPwdButtonClicked()
|
||||
{
|
||||
if (!m_pwdLineEdit) {
|
||||
return;
|
||||
}
|
||||
if (m_pwdLineEdit->echoMode() == QLineEdit::EchoMode::Password) {
|
||||
//TODO 按钮图标要发生改变
|
||||
|
||||
m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Normal);
|
||||
} else {
|
||||
//TODO 按钮图标要发生改变
|
||||
m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Password);
|
||||
}
|
||||
}
|
||||
|
||||
void WlanListItem::onConnectButtonClicked()
|
||||
{
|
||||
if (!m_connectButton->isEnabled() || !m_data) {
|
||||
return;
|
||||
}
|
||||
KyWirelessConnectSetting settings;
|
||||
settings.m_connectName = m_data->m_NetSsid;
|
||||
settings.m_ssid = m_data->m_NetSsid;
|
||||
settings.isAutoConnect = m_autoConnectCheckBox->isChecked();
|
||||
settings.m_psk = m_pwdLineEdit->text();
|
||||
if (m_data->m_secuType.isEmpty() || m_data->m_secuType == "") {
|
||||
settings.m_type = WpaNone;
|
||||
} else if (m_data->m_secuType.contains("WPA1") || m_data->m_secuType.contains("WPA2")) {
|
||||
settings.m_type = WpaPsk;
|
||||
} else if (m_data->m_secuType.contains("WPA3")) {
|
||||
settings.m_type = SAE;
|
||||
}
|
||||
qDebug() << "On button connect clicked, will connect wlan. ssid = " << m_data->m_NetSsid << Q_FUNC_INFO <<__LINE__;
|
||||
|
||||
emit this->connectButtonClicked(settings, false);
|
||||
}
|
||||
|
||||
void WlanListItem::onConnectionAdd(QString deviceName, QString ssid)
|
||||
{
|
||||
if (!m_data) {
|
||||
return;
|
||||
}
|
||||
if (ssid == m_data->m_NetSsid) {
|
||||
m_data->m_isConfigured = true;
|
||||
}
|
||||
}
|
||||
|
||||
void WlanListItem::onConnectionRemove(QString deviceName, QString ssid)
|
||||
{
|
||||
if (!m_data) {
|
||||
return;
|
||||
}
|
||||
if (ssid == m_data->m_NetSsid) {
|
||||
m_data->m_isConfigured = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,15 +3,23 @@
|
|||
#include "listitem.h"
|
||||
#include "kywirelessnetitem.h"
|
||||
#include "kywirelessnetresource.h"
|
||||
#include "wlanpage.h"
|
||||
#include "kywirelessconnectoperation.h"
|
||||
#include <QCheckBox>
|
||||
|
||||
#include <networkmanagerqt/wirelesssecuritysetting.h>
|
||||
|
||||
#define PSK_SETTING_NAME "802-11-wireless-security"
|
||||
|
||||
#define NORMAL_HEIGHT 48
|
||||
#define EXPANDED_HEIGHT 120
|
||||
#define PWD_LENGTH_LIMIT 8
|
||||
|
||||
class WlanListItem : public ListItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *data, QWidget *parent = nullptr);
|
||||
WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *data, QString device, QWidget *parent = nullptr);
|
||||
WlanListItem(QWidget *parent = nullptr);
|
||||
~WlanListItem();
|
||||
|
||||
|
@ -19,6 +27,14 @@ public:
|
|||
void setWlanSignal(const int &signal);
|
||||
void setWlanState(const int &state);
|
||||
void setExpanded(const bool &expanded);
|
||||
void setActivated(bool activated);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
signals:
|
||||
void itemHeightChanged(const QString &ssid);
|
||||
void connectButtonClicked(KyWirelessConnectSetting &connSettingInfo, const bool &isHidden);
|
||||
|
||||
private:
|
||||
void initWlanUI();
|
||||
|
@ -28,13 +44,42 @@ private:
|
|||
private:
|
||||
KyWirelessNetResource *m_resource = nullptr;
|
||||
KyWirelessNetItem *m_data = nullptr;
|
||||
bool m_isExpanded = false;
|
||||
KyWirelessConnectOperation *m_connoperation = nullptr;
|
||||
bool m_hasPwd = true;
|
||||
bool m_isActivated = false;
|
||||
QString m_wlanDevice;
|
||||
|
||||
//密码输入区域的UI
|
||||
QFrame *m_pwdFrame = nullptr;
|
||||
QHBoxLayout *m_pwdFrameLyt = nullptr;
|
||||
|
||||
QLineEdit * m_pwdLineEdit = nullptr;
|
||||
QHBoxLayout *m_pwdLineEditLyt = nullptr;
|
||||
QPushButton *m_showPwdButton = nullptr;
|
||||
|
||||
QPushButton *m_connectButton = nullptr;
|
||||
|
||||
//自动连接选择区域UI
|
||||
QFrame *m_autoConnectFrame = nullptr;
|
||||
QHBoxLayout *m_autoConnectFrameLyt = nullptr;
|
||||
QCheckBox *m_autoConnectCheckBox = nullptr;
|
||||
QLabel *m_autoConnectLabel = nullptr;
|
||||
|
||||
// QVBoxLayout * m_mainLayout = nullptr;
|
||||
// QFrame * m_itemFrame = nullptr;
|
||||
// QHBoxLayout * m_hItemLayout = nullptr;
|
||||
// QLineEdit * m_lineEdit = nullptr;
|
||||
|
||||
private slots:
|
||||
void onInfoButtonClicked();
|
||||
void onNetButtonClicked();
|
||||
// void onNameLableClicked();
|
||||
void onSecurityChanged(QString interface, QString ssid, QString securityType);
|
||||
void onPwdEditorTextChanged();
|
||||
void onShowPwdButtonClicked();
|
||||
void onConnectButtonClicked();
|
||||
void onConnectionAdd(QString deviceName, QString ssid);
|
||||
void onConnectionRemove(QString deviceName, QString ssid);
|
||||
};
|
||||
|
||||
#endif // WLANLISTITEM_H
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "wlanpage.h"
|
||||
#include "wlanlistitem.h"
|
||||
#include "kywirelessnetitem.h"
|
||||
#include "dbusadaptor.h"
|
||||
#include <QEvent>
|
||||
|
@ -14,9 +13,8 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
|
|||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
m_netDeviceResource=new KyNetworkDeviceResourse(this);
|
||||
devList.empty();
|
||||
|
||||
initDevice();
|
||||
getWirelessIface();
|
||||
m_wirelessConnectOpreation = new KyWirelessConnectOperation(this);
|
||||
initWlanUI();
|
||||
initConnections();
|
||||
getActiveWlan();
|
||||
|
@ -27,6 +25,11 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
|
|||
connect(m_netDeviceResource, &KyNetworkDeviceResourse::deviceNameUpdate, this, &WlanPage::onDeviceNameUpdate);
|
||||
}
|
||||
|
||||
//QString WlanPage::getSsidFromUuid(const QString &uuid)
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
bool WlanPage::eventFilter(QObject *w, QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::MouseButtonPress) {
|
||||
|
@ -74,8 +77,8 @@ void WlanPage::initWlanUI()
|
|||
m_inactivatedWlanListAreaLayout->addStretch();
|
||||
|
||||
m_activatedNetListWidget->setFixedHeight(NORMAL_HEIGHT);
|
||||
// m_inactivatedNetListArea->setFixedHeight(SCROLLAREA_HEIGHT);
|
||||
m_inactivatedNetListArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
m_inactivatedNetListArea->setFixedHeight(SCROLLAREA_HEIGHT);
|
||||
// m_inactivatedNetListArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,22 +92,6 @@ void WlanPage::initConnections()
|
|||
connect(m_connectResource, &KyActiveConnectResourse::stateChangeReason, this, &WlanPage::onActivatedWlanChanged);
|
||||
}
|
||||
|
||||
void WlanPage::getWirelessIface()
|
||||
{
|
||||
QStringList netDeviceList;//临时存储网卡列表
|
||||
|
||||
m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, netDeviceList);
|
||||
if (netDeviceList.isEmpty()) {
|
||||
m_wlanDevice = "wlx5841207b85f0";
|
||||
qDebug() << "Wlan device is not exist." << Q_FUNC_INFO << __LINE__;
|
||||
} else {
|
||||
m_wlanDevice=netDeviceList.at(0);
|
||||
qDebug() << "Get device successfully, its name is " << m_wlanDevice <<Q_FUNC_INFO << __LINE__;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief WlanPage::initDevice 初始化默认网卡
|
||||
*/
|
||||
|
@ -142,22 +129,9 @@ void WlanPage::getActiveWlan()
|
|||
QMap<QString,QStringList>::iterator iter = actMap.begin();
|
||||
int height = 0;
|
||||
while (iter != actMap.end()) {
|
||||
if (iter.key() == m_wlanDevice && !iter.value().isEmpty()) {
|
||||
if (iter.key() == defaultDevice && !iter.value().isEmpty()) {
|
||||
QString ssid = iter.value().at(0);
|
||||
m_activatedWlanSSid = ssid;
|
||||
|
||||
KyWirelessNetItem data;
|
||||
if (!m_resource->getWifiNetwork(m_wlanDevice, ssid, data)) {
|
||||
return;
|
||||
}
|
||||
KyWirelessNetItem *item_data = new KyWirelessNetItem(data);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data);
|
||||
qDebug() << "Activated wlan: ssid = " << item_data->m_NetSsid;
|
||||
QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget);
|
||||
wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height()));
|
||||
m_activatedNetListWidget->addItem(wlanItem);
|
||||
m_activatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
|
||||
height += wlanItemWidget->height();
|
||||
appendActiveWlan(ssid, height);
|
||||
break;
|
||||
}
|
||||
iter ++;
|
||||
|
@ -165,7 +139,7 @@ void WlanPage::getActiveWlan()
|
|||
if (height > 0) {
|
||||
m_activatedNetListWidget->setFixedHeight(height);
|
||||
} else {
|
||||
//ZJP_TODO 未连接任何WiFi的情况
|
||||
//未连接任何WiFi的情况
|
||||
m_activatedWlanSSid.clear();
|
||||
WlanListItem *wlanItemWidget = new WlanListItem();
|
||||
qDebug() << "There is no activated wlan." << Q_FUNC_INFO << __LINE__ ;
|
||||
|
@ -177,6 +151,26 @@ void WlanPage::getActiveWlan()
|
|||
}
|
||||
}
|
||||
|
||||
void WlanPage::appendActiveWlan(const QString &ssid, int &height)
|
||||
{
|
||||
m_activatedWlanSSid = ssid;
|
||||
|
||||
KyWirelessNetItem data;
|
||||
if (!m_resource->getWifiNetwork(defaultDevice, ssid, data)) {
|
||||
return;
|
||||
}
|
||||
KyWirelessNetItem *item_data = new KyWirelessNetItem(data);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data, defaultDevice);
|
||||
wlanItemWidget->setActivated(true);
|
||||
qDebug() << "Activated wlan: ssid = " << item_data->m_NetSsid;
|
||||
QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget);
|
||||
wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height()));
|
||||
m_activatedNetListWidget->addItem(wlanItem);
|
||||
m_activatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
|
||||
|
||||
height += wlanItemWidget->height();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief WlanPage::getAllWlan 获取所有Wlan //ZJP_TODO 需要针对网卡进行筛选
|
||||
*/
|
||||
|
@ -187,7 +181,7 @@ void WlanPage::getAllWlan()
|
|||
m_itemsMap.clear();
|
||||
QList<KyWirelessNetItem> wlanList;
|
||||
// if (!m_resource->getAllDeviceWifiNetwork(map))
|
||||
if (!m_resource->getDeviceWifiNetwork(m_wlanDevice, wlanList)) //ZJP_TODO 获取默认网卡并传入
|
||||
if (!m_resource->getDeviceWifiNetwork(defaultDevice, wlanList)) //ZJP_TODO 获取默认网卡并传入
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -198,8 +192,10 @@ void WlanPage::getAllWlan()
|
|||
}
|
||||
|
||||
KyWirelessNetItem *data = new KyWirelessNetItem(itemData);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, defaultDevice);
|
||||
QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget);
|
||||
connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged);
|
||||
connect(wlanItemWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked);
|
||||
m_itemsMap.insert(data->m_NetSsid, wlanItem);
|
||||
wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height()));
|
||||
m_inactivatedNetListWidget->addItem(wlanItem);
|
||||
|
@ -219,7 +215,8 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item)
|
|||
qDebug() << "A Wlan Added! interface = " << interface << "; ssid = " << item.m_NetSsid << Q_FUNC_INFO <<__LINE__;
|
||||
|
||||
KyWirelessNetItem *data = new KyWirelessNetItem(item);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, defaultDevice);
|
||||
connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged);
|
||||
QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget);
|
||||
wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height()));
|
||||
m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
|
||||
|
@ -234,6 +231,7 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item)
|
|||
void WlanPage::onWlanRemoved(QString interface, QString ssid)
|
||||
{
|
||||
if (!m_itemsMap.contains(ssid)) { return; }
|
||||
if (m_expandedItem == m_itemsMap.value(ssid)) { m_expandedItem = nullptr; }
|
||||
qDebug() << "A Wlan Removed! interface = " << interface << "; ssid = " << ssid << Q_FUNC_INFO <<__LINE__;
|
||||
int height = m_inactivatedNetListWidget->itemWidget(m_itemsMap.value(ssid))->height();
|
||||
m_inactivatedNetListWidget->takeItem(m_inactivatedNetListWidget->row(m_itemsMap.value(ssid)));
|
||||
|
@ -245,6 +243,7 @@ void WlanPage::onWlanRemoved(QString interface, QString ssid)
|
|||
void WlanPage::onWlanUpdated()
|
||||
{
|
||||
//ZJP_TODO 某些特定情况下不可重绘整个列表,此处代码需要修改
|
||||
m_expandedItem = nullptr;
|
||||
getActiveWlan();
|
||||
getAllWlan();
|
||||
}
|
||||
|
@ -261,6 +260,7 @@ void WlanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type devi
|
|||
{
|
||||
updateDefaultDevice(deviceName);
|
||||
setDefaultDevice(WIRELESS, deviceName);
|
||||
|
||||
}
|
||||
emit deviceStatusChanged();
|
||||
}
|
||||
|
@ -304,6 +304,43 @@ void WlanPage::onDeviceNameUpdate(QString oldName, QString newName)
|
|||
void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason)
|
||||
{
|
||||
qDebug()<< "Activated wlan changed, uuid = " << uuid << "; state = " << state << "; reason = " << reason << Q_FUNC_INFO <<__LINE__;
|
||||
onWlanUpdated();
|
||||
|
||||
if (state == NetworkManager::ActiveConnection::State::Activated) {
|
||||
//onWlanRemoved(m_wlanDevice, ssid);
|
||||
QString ssid;
|
||||
m_resource->getSsidByUuid(uuid, ssid);
|
||||
m_activatedNetListWidget->clear();
|
||||
int height = 0;
|
||||
appendActiveWlan(ssid, height);
|
||||
onWlanRemoved(defaultDevice, ssid);
|
||||
} else {
|
||||
onWlanUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
void WlanPage::onItemHeightChanged(const QString &ssid)
|
||||
{
|
||||
if (!m_itemsMap.contains(ssid)) { return; }
|
||||
QListWidgetItem *item = m_itemsMap.value(ssid);
|
||||
|
||||
if (m_expandedItem && m_expandedItem != item) {
|
||||
QSize size(m_inactivatedNetListWidget->itemWidget(m_expandedItem)->size().width(), NORMAL_HEIGHT);
|
||||
//旧的收起
|
||||
m_expandedItem->setSizeHint(size);
|
||||
m_inactivatedNetListWidget->itemWidget(m_expandedItem)->setFixedHeight(NORMAL_HEIGHT);
|
||||
//新的展开
|
||||
m_expandedItem = item;
|
||||
item->setSizeHint(m_inactivatedNetListWidget->itemWidget(item)->size());
|
||||
} else if (!m_expandedItem) {
|
||||
m_expandedItem = item;
|
||||
m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_inactivatedNetListWidget->itemWidget(item)->height() - item->sizeHint().height());
|
||||
m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height());
|
||||
item->setSizeHint(m_inactivatedNetListWidget->itemWidget(item)->size());
|
||||
}
|
||||
}
|
||||
|
||||
void WlanPage::onConnectButtonClicked(KyWirelessConnectSetting &connSettingInfo, const bool &isHidden)
|
||||
{
|
||||
qDebug() << "Received signal of connecting wlan, ssid = " << connSettingInfo.m_ssid << Q_FUNC_INFO << __LINE__;
|
||||
m_wirelessConnectOpreation->addAndActiveWirelessConnect(defaultDevice, connSettingInfo, isHidden);
|
||||
}
|
||||
|
|
|
@ -5,9 +5,12 @@
|
|||
#include "kywirelessnetresource.h"
|
||||
#include "kylinactiveconnectresource.h"
|
||||
#include "kylinnetworkdeviceresource.h"
|
||||
#include "kywirelessconnectoperation.h"
|
||||
#include "wlanlistitem.h"
|
||||
|
||||
//#define SCROLLAREA_HEIGHT 150
|
||||
#define MORE_TEXT_MARGINS 16,0,0,0
|
||||
#define SCROLLAREA_HEIGHT 200
|
||||
|
||||
class WlanPage : public TabPage
|
||||
{
|
||||
|
@ -16,18 +19,25 @@ public:
|
|||
explicit WlanPage(QWidget *parent = nullptr);
|
||||
~WlanPage() = default;
|
||||
|
||||
//static QString getSsidFromUuid(const QString &uuid);
|
||||
|
||||
signals:
|
||||
void oneItemExpanded(const QString &ssid);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
void initWlanUI();
|
||||
void initConnections();
|
||||
|
||||
void initDevice();//初始化默认设备
|
||||
QString m_wlanDevice; //临时用来存储网卡名
|
||||
void getWirelessIface(); //一个临时用于获取网卡的函数
|
||||
|
||||
void getActiveWlan();
|
||||
void appendActiveWlan(const QString &ssid, int &height);
|
||||
void getAllWlan();
|
||||
QMap<QString, QListWidgetItem*> m_itemsMap;
|
||||
QListWidgetItem *m_expandedItem = nullptr;
|
||||
QFrame * m_inactivatedWlanListAreaCentralWidget = nullptr;
|
||||
QVBoxLayout * m_inactivatedWlanListAreaLayout = nullptr;
|
||||
QFrame * m_hiddenWlanWidget = nullptr;
|
||||
|
@ -40,7 +50,8 @@ private:
|
|||
KyWirelessNetResource *m_resource = nullptr;
|
||||
KyActiveConnectResourse *m_connectResource = nullptr;
|
||||
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
|
||||
KyNetworkDeviceResourse *m_netDeviceResource=nullptr;
|
||||
KyNetworkDeviceResourse *m_netDeviceResource = nullptr;
|
||||
KyWirelessConnectOperation * m_wirelessConnectOpreation = nullptr;
|
||||
|
||||
|
||||
private slots:
|
||||
|
@ -54,6 +65,8 @@ private slots:
|
|||
void onActivatedWlanChanged(QString uuid,
|
||||
NetworkManager::ActiveConnection::State state,
|
||||
NetworkManager::ActiveConnection::Reason reason);
|
||||
void onItemHeightChanged(const QString &ssid);
|
||||
void onConnectButtonClicked(KyWirelessConnectSetting &connSettingInfo, const bool &isHidden);
|
||||
};
|
||||
|
||||
#endif // WLANPAGE_H
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include "radioitembutton.h"
|
||||
#define BUTTON_SIZE 32,32
|
||||
|
||||
#define FRAMESPEED 60 //帧与帧之间的间隔时间(ms)
|
||||
#define ALLTIME 40*1000 //等待动画持续总时间
|
||||
|
||||
RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
connect(this, &RadioItemButton::requestStartLoading, this, &RadioItemButton::onLoadingStarted);
|
||||
|
@ -10,6 +13,32 @@ RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButto
|
|||
m_iconLabel = new QLabel(this);
|
||||
m_iconLabel->setScaledContents(true);
|
||||
this->setFixedSize(BUTTON_SIZE);
|
||||
|
||||
this->switchTimer = new QTimer(this); //QTimer对象,控制等待动画播放
|
||||
|
||||
this->raise();
|
||||
this->hide();
|
||||
}
|
||||
|
||||
void RadioItemButton::switchAnimStep()
|
||||
{
|
||||
//另外一种加载方法
|
||||
QString qpmQss = ":/res/s/conning-b/";
|
||||
qpmQss.append(QString::number(this->currentPage));
|
||||
qpmQss.append(".png");
|
||||
m_iconLabel->setPixmap(QPixmap(qpmQss));
|
||||
m_iconLabel->setProperty("useIconHighlightEffect", true);
|
||||
m_iconLabel->setProperty("iconHighlightEffectMode", true);
|
||||
|
||||
this->currentPage --;
|
||||
|
||||
if (this->currentPage < 1) {
|
||||
this->currentPage = 12; //循环播放
|
||||
}
|
||||
this->countCurrentTime += FRAMESPEED;
|
||||
if (this->countCurrentTime >= ALLTIME) {
|
||||
emit this->toStopLoading(); //发出信号停止主界面和托盘区的等待动画
|
||||
}
|
||||
}
|
||||
|
||||
void RadioItemButton::startLoading()
|
||||
|
@ -40,7 +69,9 @@ void RadioItemButton::setReleased()
|
|||
|
||||
void RadioItemButton::setButtonIcon(QIcon *icon)
|
||||
{
|
||||
if (!icon) { return; }
|
||||
if (!icon) {
|
||||
return;
|
||||
}
|
||||
//ZJP_TODO 绘制圆形按钮
|
||||
m_iconLabel->setPixmap(icon->pixmap(this->size()));
|
||||
}
|
||||
|
@ -48,9 +79,18 @@ void RadioItemButton::setButtonIcon(QIcon *icon)
|
|||
void RadioItemButton::onLoadingStarted()
|
||||
{
|
||||
//ZJP_TODO 开始播放转圈动画
|
||||
this->currentPage = 12;
|
||||
this->countCurrentTime = 0;
|
||||
this->switchTimer->start(FRAMESPEED);
|
||||
this->show();
|
||||
if (this->countCurrentTime >= ALLTIME) {
|
||||
emit this->requestStopLoading(); //发出信号停止主界面和托盘区的等待动画
|
||||
}
|
||||
}
|
||||
|
||||
void RadioItemButton::onLoadingStopped()
|
||||
{
|
||||
//ZJP_TODO 停止播放转圈动画
|
||||
this->switchTimer->stop();
|
||||
this->hide();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue