Update wlan page.

This commit is contained in:
jinxujie 2021-09-10 18:05:08 +08:00
parent ab23eb4183
commit 4186076f61
11 changed files with 207 additions and 38 deletions

View File

@ -49,6 +49,11 @@ void LanListItem::setIcon(bool isOn)
}
}
void LanListItem::onRightButtonClicked()
{
//右键点击事件
}
void LanListItem::onInfoButtonClicked()
{
if(m_data){

View File

@ -17,6 +17,7 @@ public:
protected:
void setIcon(bool isOn);
void onRightButtonClicked();
private:
KyConnectItem *m_data = nullptr;

View File

@ -13,7 +13,7 @@ ListItem::ListItem(QWidget *parent) : QFrame(parent)
{
initUI();
initConnection();
m_itemFrame->installEventFilter(this);
// m_itemFrame->installEventFilter(this);
}
ListItem::~ListItem()
@ -37,16 +37,44 @@ void ListItem::setActive(const bool &isActive)
m_isActive = isActive;
}
bool ListItem::eventFilter(QObject *watched, QEvent *event)
void ListItem::showDesktopNotify(const QString &message)
{
if (watched == m_itemFrame) {
if (event->type() == QEvent::MouseButtonPress) {
onNetButtonClicked();
}
}
return QFrame::eventFilter(watched, event);
QDBusInterface iface("org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications",
QDBusConnection::sessionBus());
QList<QVariant> args;
args<<(tr("Kylin NM"))
<<((unsigned int) 0)
<<QString("/usr/share/icons/ukui-icon-theme-default/24x24/devices/gnome-dev-ethernet.png")
<<tr("kylin network applet desktop message") //显示的是什么类型的信息
<<message //显示的具体信息
<<QStringList()
<<QVariantMap()
<<(int)-1;
iface.callWithArgumentList(QDBus::AutoDetect,"Notify",args);
}
void ListItem::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
onNetButtonClicked();
} else if (event->button() == Qt::RightButton) {
onRightButtonClicked();
}
return QFrame::mousePressEvent(event);
}
//bool ListItem::eventFilter(QObject *watched, QEvent *event)
//{
// if (watched == m_itemFrame) {
// if (event->type() == QEvent::MouseButtonPress) {
// onNetButtonClicked();
// }
// }
// return QFrame::eventFilter(watched, event);
//}
void ListItem::initUI()
{
m_mainLayout = new QVBoxLayout(this);

View File

@ -4,6 +4,7 @@
#include <QEvent>
#include <QHBoxLayout>
#include <QDebug>
#include <QMouseEvent>
#include "radioitembutton.h"
#include "infobutton.h"
#include "netdetails/netdetail.h"
@ -16,9 +17,12 @@ public:
~ListItem();
void setName(const QString &name);
void setActive(const bool &isActive);
static void showDesktopNotify(const QString &message);
protected:
bool eventFilter(QObject *watched, QEvent *event);
// bool eventFilter(QObject *watched, QEvent *event);
void mousePressEvent(QMouseEvent *event);
virtual void onRightButtonClicked() = 0;
protected:
QFrame * m_itemFrame = nullptr;

View File

@ -7,9 +7,13 @@ WlanListItem::WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *d
m_resource = resource;
m_wlanDevice = device;
m_connoperation = new KyWirelessConnectOperation(this);
m_connectResource = new KyActiveConnectResourse();
initWlanUI();
setExpanded(false);
initWlanConnection();
m_menu = new QMenu();//右键菜单
connect(m_menu, &QMenu::triggered, this, &WlanListItem::onMenuTriggered);
}
WlanListItem::WlanListItem(QWidget *parent) : ListItem(parent)
@ -67,6 +71,23 @@ void WlanListItem::resizeEvent(QResizeEvent *event)
return ListItem::resizeEvent(event);
}
void WlanListItem::onRightButtonClicked()
{
m_menu->clear();
if (!this->m_data) {
return;
}
if (this->m_isActive) {
m_menu->addAction(new QAction(tr("Disconnect"), this));
} else {
m_menu->addAction(new QAction(tr("Connect"), this));
}
if (m_data->m_isConfigured)
m_menu->addAction(new QAction(tr("Forget"), this));
m_menu->move(cursor().pos());
m_menu->show();
}
void WlanListItem::initWlanUI()
{
m_hasPwd = (m_data->m_secuType.isEmpty() || m_data->m_secuType == "") ? false : true;
@ -137,6 +158,7 @@ void WlanListItem::initWlanConnection()
connect(m_resource, &KyWirelessNetResource::connectionAdd, this, &WlanListItem::onConnectionAdd);
connect(m_resource, &KyWirelessNetResource::connectionRemove, this, &WlanListItem::onConnectionRemove);
connect(this->m_infoButton, &InfoButton::clicked, this, &WlanListItem::onInfoButtonClicked);
connect(m_connectResource, &KyActiveConnectResourse::stateChangeReason, this, &WlanListItem::onWlanStatusChange);
}
void WlanListItem::refreshIcon()
@ -222,7 +244,6 @@ void WlanListItem::onNetButtonClicked()
if (m_data->m_isConfigured) {
m_connoperation->activeWirelessConnect(m_wlanDevice,m_data->m_connectUuid);
// m_netButton->startLoading();
qDebug()<<"Has configuration, will be activated. ssid = " << m_data->m_NetSsid << Q_FUNC_INFO << __LINE__;
return;
}
@ -337,3 +358,55 @@ void WlanListItem::onConnectionRemove(QString deviceName, QString ssid)
}
}
void WlanListItem::onWlanStatusChange(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason)
{
QString ssid;
m_resource->getSsidByUuid(uuid,ssid);
if (m_data->m_NetSsid == ssid) {
qDebug() << "[WlanPage] State changed to :" << state << Q_FUNC_INFO <<__LINE__;
if (state == NetworkManager::ActiveConnection::State::Activating) {
m_netButton->startLoading();
} else {
m_netButton->stopLoading();
}
}
//TODO 网络状态改变的通知
// if (state == NetworkManager::ActiveConnection::State::Activated) {
//// this->showDesktopNotify(tr("WLAN Connected Successfully"));
// } else if (state == NetworkManager::ActiveConnection::State::Deactivated) {
// switch (reason) {
// case NetworkManager::ActiveConnection::Reason::UserDisconnected:
// this->showDesktopNotify(tr("WLAN Disconnected Successfully"));
// break;
// case NetworkManager::ActiveConnection::Reason::ServiceStopped:
// this->showDesktopNotify(tr("The service providing the VPN connection was stopped"));
// break;
// case NetworkManager::ActiveConnection::Reason::IpConfigInvalid:
// this->showDesktopNotify(tr("The IP config of the active connection was invalid"));
// break;
// case NetworkManager::ActiveConnection::Reason::ConnectTimeout:
// this->showDesktopNotify(tr("The connection attempt to the VPN service timed out"));
// break;
// case NetworkManager::ActiveConnection::Reason::NoSecrets:
// this->showDesktopNotify(tr("Necessary secrets for the connection were not provided"));
// break;
// case NetworkManager::ActiveConnection::Reason::LoginFailed:
// this->showDesktopNotify(tr("Authentication to the server failed"));
// break;
// default:
// qDebug() << "Wlan disconnected with unkown reason." << Q_FUNC_INFO << __LINE__;
// break;
// }
// }
}
void WlanListItem::onMenuTriggered(QAction *action)
{
if (action->text() == tr("Disconnect") || action->text() == tr("Connect")) {
this->onNetButtonClicked();
} else if (action->text() == tr("Forget")) {
m_connoperation->deleteWirelessConnect(m_data->m_connectUuid);
}
}

View File

@ -6,6 +6,9 @@
#include "wlanpage.h"
#include "kywirelessconnectoperation.h"
#include <QCheckBox>
#include "kylinactiveconnectresource.h"
#include <QMenu>
#include <QAction>
#include <networkmanagerqt/wirelesssecuritysetting.h>
@ -29,6 +32,7 @@ public:
void setExpanded(const bool &expanded);
protected:
void resizeEvent(QResizeEvent *event);
void onRightButtonClicked();
signals:
void itemHeightChanged(const QString &ssid);
@ -43,6 +47,7 @@ private:
KyWirelessNetResource *m_resource = nullptr;
KyWirelessNetItem *m_data = nullptr;
KyWirelessConnectOperation *m_connoperation = nullptr;
KyActiveConnectResourse *m_connectResource = nullptr;
bool m_hasPwd = true;
QString m_wlanDevice;
@ -62,6 +67,10 @@ private:
QCheckBox *m_autoConnectCheckBox = nullptr;
QLabel *m_autoConnectLabel = nullptr;
QMenu *m_menu = nullptr;
NetworkManager::ActiveConnection::State m_state;
// QVBoxLayout * m_mainLayout = nullptr;
// QFrame * m_itemFrame = nullptr;
// QHBoxLayout * m_hItemLayout = nullptr;
@ -79,6 +88,10 @@ private slots:
void onConnectButtonClicked();
void onConnectionAdd(QString deviceName, QString ssid);
void onConnectionRemove(QString deviceName, QString ssid);
void onWlanStatusChange(QString uuid,
NetworkManager::ActiveConnection::State state,
NetworkManager::ActiveConnection::Reason reason);
void onMenuTriggered(QAction *action);
};
#endif // WLANLISTITEM_H

View File

@ -1,5 +1,6 @@
#include "tabpage.h"
#include <qsettings.h>
#include <QDBusInterface>
TabPage::TabPage(QWidget *parent) : QWidget(parent)
{

View File

@ -16,6 +16,7 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
m_devList.empty();
initDevice();
m_wirelessConnectOpreation = new KyWirelessConnectOperation(this);
m_connectoperation = new KyConnectOperation(this);
initWlanUI();
//要在initUI之后调用保证UI的信号槽顺利绑定
initConnections();
@ -30,6 +31,8 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::activateConnectionError, this, &WlanPage::activateFailed);
connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::addAndActivateConnectionError, this, &WlanPage::activateFailed);
connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::deactivateConnectionError, this, &WlanPage::deactivateFailed);
connect(this, &WlanPage::hiddenWlanClicked, this, &WlanPage::onHiddenWlanClicked);
}
//QString WlanPage::getSsidFromUuid(const QString &uuid)
@ -42,6 +45,7 @@ bool WlanPage::eventFilter(QObject *w, QEvent *e)
if (e->type() == QEvent::MouseButtonPress) {
if (w == m_hiddenWlanLabel) {
//ZJP_TODO 打开隐藏WiFi添加弹窗
emit this->hiddenWlanClicked();
} else if (w == m_settingsLabel) {
//ZJP_TODO 打开控制面板
}
@ -77,6 +81,7 @@ void WlanPage::initWlanUI()
m_hiddenWlanLabel = new QLabel(m_hiddenWlanWidget);
m_hiddenWlanLabel->setText(tr("More..."));
m_hiddenWlanLabel->setContentsMargins(MORE_TEXT_MARGINS);
m_hiddenWlanLabel->installEventFilter(this);
m_hiddenWlanLayout->addWidget(m_hiddenWlanLabel);
m_hiddenWlanLayout->addStretch();
@ -105,6 +110,10 @@ void WlanPage::initConnections()
connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::listUpdate);
// connect(m_resource, &KyWirelessNetResource::wifiNetworkUpdate, this, &WlanPage::onWlanUpdated);
connect(m_connectResource, &KyActiveConnectResourse::stateChangeReason, this, &WlanPage::onActivatedWlanChanged);
// connect(m_connectoperation, &KyConnectOperation::activateConnectionError, this, &WlanPage::showDesktopNotify);
// connect(m_connectoperation, &KyConnectOperation::createConnectionError, this, &WlanPage::showDesktopNotify);
// connect(m_connectoperation, &KyConnectOperation::deactivateConnectionError, this, &WlanPage::showDesktopNotify);
// connect(m_connectoperation, &KyConnectOperation::deleteConnectionError, this, &WlanPage::showDesktopNotify);
connect(m_netSwitch, &SwitchButton::clicked, this, &WlanPage::onWlanSwitchClicked);
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
@ -445,6 +454,10 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec
int height = 0;
appendActiveWlan(ssid, height);
onWlanRemoved(defaultDevice, ssid);
// this->showDesktopNotify(tr("Connect WLAN succeed"));
} else if (state == NetworkManager::ActiveConnection::State::Deactivated) {
onWlanUpdated();
// this->showDesktopNotify(tr("Disconnect WLAN succeed"));
} else {
onWlanUpdated();
}
@ -515,6 +528,13 @@ void WlanPage::requestScan()
m_wirelessConnectOpreation->requestWirelessScan();
}
void WlanPage::onHiddenWlanClicked()
{
qDebug() << "[wlanPage] AddHideWifi Clicked! " << Q_FUNC_INFO << __LINE__ ;
NetDetail *netDetail = new NetDetail("", "", false, true, false);
netDetail->show();
}
//for dbus
void WlanPage::getWirelessList(QMap<QString, QVector<QStringList> > &map)

View File

@ -7,7 +7,9 @@
#include "kylinnetworkdeviceresource.h"
#include "kywirelessconnectoperation.h"
#include "wlanlistitem.h"
#include "kylinconnectoperation.h"
#include <QGSettings>
#include "netdetails/netdetail.h"
//#define SCROLLAREA_HEIGHT 150
#define MORE_TEXT_MARGINS 16,0,0,0
@ -36,6 +38,7 @@ signals:
void wirelessActivating(QString devName, QString ssid);
void hotspotDeactivated(QString devName, QString ssid);
void hotspotActivated(QString devName, QString ssid);
void hiddenWlanClicked();
public slots:
void onMainWindowVisibleChanged(const bool &visible);
@ -74,6 +77,7 @@ private:
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
KyNetworkDeviceResourse *m_netDeviceResource = nullptr;
KyWirelessConnectOperation * m_wirelessConnectOpreation = nullptr;
KyConnectOperation *m_connectoperation = nullptr;
KyConnectResourse * m_apConnectResource = nullptr;
QGSettings *m_switchGsettings = nullptr;
@ -95,6 +99,7 @@ private slots:
void onWlanSwitchStatusChanged(const bool &checked);
void onDeviceComboxIndexChanged(int currentIndex);
void requestScan();
void onHiddenWlanClicked();
};
#endif // WLANPAGE_H

View File

@ -1,7 +1,9 @@
#include "radioitembutton.h"
#include <QPainter>
#include <QStyle>
#include <QDebug>
#define FLASH_SPEED 100
#define TIMEOUT_TIMER 90*1000
#define BUTTON_SIZE 36,36
#define ICON_SIZE 16,16
#define BACKGROUND_COLOR QColor(0,0,0,0)
@ -12,8 +14,6 @@
RadioItemButton::RadioItemButton(QWidget *parent) : QPushButton(parent)
{
connect(this, &RadioItemButton::requestStartLoading, this, &RadioItemButton::onLoadingStarted);
connect(this, &RadioItemButton::requestStopLoading, this, &RadioItemButton::onLoadingStopped);
this->setAutoFillBackground(false);
m_iconLabel = new QLabel(this);
@ -23,8 +23,8 @@ RadioItemButton::RadioItemButton(QWidget *parent) : QPushButton(parent)
setActive(false);
//JXJ_TODO loading动画
// switchTimer = new QTimer(this);
// connect(switchTimer, &QTimer::timeout, this, &RadioItemButton::onLoadingStarted);
connect(this, &RadioItemButton::requestStartLoading, this, &RadioItemButton::onLoadingStarted);
connect(this , &RadioItemButton::requestStopLoading, this, &RadioItemButton::onLoadingStopped);
}
void RadioItemButton::startLoading()
@ -52,32 +52,50 @@ void RadioItemButton::setActive(const bool &isActive)
}
void RadioItemButton::onLoadingStarted()
{
//ZJP_TODO 开始播放转圈动画
// switchTimer->start(FRAMESPEED);
// 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->onLoadingStopped();
// }
if (!m_loadingTimer) {
m_loadingTimer = new QTimer();
connect(m_loadingTimer, &QTimer::timeout, this, &RadioItemButton::onLoadingTimerTimeout);
}
if (!m_timeoutTimer) {
m_timeoutTimer = new QTimer();
connect(m_timeoutTimer, &QTimer::timeout, this, &RadioItemButton::onLoadingStopped);
}
if (m_loadingTimer->isActive()) {
return;
}
m_loadingTimer->start(FLASH_SPEED);
m_timeoutTimer->stop();
m_timeoutTimer->start(TIMEOUT_TIMER);
}
void RadioItemButton::onLoadingStopped()
{
//ZJP_TODO 停止播放转圈动画
this->switchTimer->stop();
if (this->m_loadingTimer) {
this->m_loadingTimer->stop();
} else {
qWarning() << "Stop loading failed, m_loadingTimer is nullptr." << Q_FUNC_INFO << __LINE__;
}
if (this->m_timeoutTimer) {
this->m_timeoutTimer->stop();
} else {
qWarning() << "Stop timeout_timer failed, m_timeoutTimer is nullptr." << Q_FUNC_INFO << __LINE__;
}
}
void RadioItemButton::onLoadingTimerTimeout()
{
QString qpmQss = ":/res/s/conning-a/";
qpmQss.append(QString::number(this->currentPage));
qpmQss.append(".png");
qDebug()<<qpmQss;
m_iconLabel->setPixmap(QPixmap(qpmQss));
this->currentPage --;
if (this->currentPage < 1) {
this->currentPage = 8; //循环播放
}
}
void RadioItemButton::paintEvent(QPaintEvent *event)

View File

@ -28,15 +28,16 @@ protected:
private:
bool m_isActivated = false;
QLabel * m_iconLabel = nullptr;
QTimer * switchTimer = nullptr;
QTimer * m_loadingTimer = nullptr;
QTimer * m_timeoutTimer = nullptr;
QColor m_backgroundColor;
int currentPage;
int countCurrentTime;
int currentPage = 8;
private slots:
void onLoadingStarted();
void onLoadingStopped();
void onLoadingTimerTimeout();
};
#endif // NETBUTTON_H