feature: 支持有线连接连接、断开、新增、删除功能
This commit is contained in:
parent
0d23cc614a
commit
8ad37e4a43
|
@ -24,14 +24,16 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QTimer>
|
||||
#include <QProcess>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusArgument>
|
||||
#include <QSettings>
|
||||
#include "tab-pages/tabpage.h"
|
||||
|
||||
#define CONFIG_FILE_PATH QDir::homePath() + "/.config/ukui/kylin-nm.conf"
|
||||
//#define CONFIG_FILE_PATH QDir::homePath() + "/.config/ukui/kylin-nm.conf"
|
||||
#define WIFI_SWITCH_OPENED "wifi_switch_opened"
|
||||
#define LAN_SWITCH_OPENED "lan_switch_opened"
|
||||
|
||||
|
|
|
@ -1,28 +1,56 @@
|
|||
#include "lanlistitem.h"
|
||||
#include "backend/dbus-interface/kylinconnectitem.h"
|
||||
|
||||
LanListItem::LanListItem(KyConnectItem *data, QWidget *parent) : ListItem(parent)
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
LanListItem::LanListItem(KyConnectItem *data, QString deviceName, QWidget *parent)
|
||||
: m_data(data), deviceName(deviceName), ListItem(parent) //item数据传入
|
||||
{
|
||||
m_wiredActivatelist = new KyActiveConnectResourse;
|
||||
m_connect_operation = new KyWiredConnectOperation;
|
||||
|
||||
if (m_data != nullptr) {
|
||||
if (m_data->m_connectState == NetworkManager::ActiveConnection::State::Activated) {
|
||||
m_data = data;
|
||||
m_nameLabel->setText(m_data->m_connectName);
|
||||
setIcon(true);
|
||||
m_activated = true;
|
||||
} else {
|
||||
m_data = data;
|
||||
m_nameLabel->setText(m_data->m_connectName);
|
||||
setIcon(false);
|
||||
m_activated = false;
|
||||
}
|
||||
}
|
||||
m_itemFrame->installEventFilter(this);
|
||||
}
|
||||
|
||||
void LanListItem::initLanUI()
|
||||
bool LanListItem::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
this->setName(m_data->m_connectName);
|
||||
if (watched == m_itemFrame) {
|
||||
if (event->type() == QEvent::MouseButtonPress) {
|
||||
if (!m_activated) {
|
||||
//未连接,点击后连
|
||||
m_connect_operation->activateWiredConnection(m_data->m_connectUuid, deviceName);
|
||||
qDebug() << m_data->m_connectName << "点击后连接";
|
||||
m_activated = true;
|
||||
} else {
|
||||
//连接,点击后断开
|
||||
m_connect_operation->deactivateWiredConnection(m_data->m_connectName, m_data->m_connectUuid);
|
||||
qDebug() << m_data->m_connectName << "点击后断开";
|
||||
m_activated = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ListItem::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void LanListItem::refreshIcon()
|
||||
void LanListItem::setIcon(bool isOn)
|
||||
{
|
||||
// if (m_data->m_connectState) //ZJP_TODO
|
||||
if (isOn) {
|
||||
m_netButton->setIcon(QIcon::fromTheme("network-wired-connected-symbolic"));
|
||||
} else {
|
||||
m_netButton->setIcon(QIcon::fromTheme("network-wired-disconnected-symbolic"));
|
||||
}
|
||||
|
||||
void LanListItem::onInfoButtonClicked()
|
||||
{
|
||||
//ZJP_TODO 呼出有线详情页
|
||||
qDebug() << "On lan info button clicked! name = " << m_data->m_connectName << "; uuid = " << m_data->m_connectUuid << "." <<Q_FUNC_INFO << __LINE__;
|
||||
}
|
||||
|
||||
void LanListItem::onNetButtonClicked()
|
||||
{
|
||||
//ZJP_TODO 点击连接/断开
|
||||
qDebug() << "On lan clicked! name = " << m_data->m_connectName << "; uuid = " << m_data->m_connectUuid << "." <<Q_FUNC_INFO << __LINE__;
|
||||
}
|
||||
|
|
|
@ -1,26 +1,31 @@
|
|||
#ifndef LANLISTITEM_H
|
||||
#define LANLISTITEM_H
|
||||
#include "listitem.h"
|
||||
#include "kylinconnectitem.h"
|
||||
#include "kylinwiredwidget.h"
|
||||
#include "kylinactiveconnectresource.h"
|
||||
|
||||
#include <QDBusInterface>
|
||||
#include <QEvent>
|
||||
|
||||
class LanListItem : public ListItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LanListItem(KyConnectItem *data, QWidget *parent = nullptr);
|
||||
LanListItem(KyConnectItem *data, QString deviceName, QWidget *parent = nullptr);
|
||||
~LanListItem() = default;
|
||||
|
||||
protected:
|
||||
void setIcon(bool isOn);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
KyConnectItem *m_data = nullptr;
|
||||
|
||||
private:
|
||||
void initLanUI();
|
||||
void refreshIcon();
|
||||
|
||||
private slots:
|
||||
void onInfoButtonClicked();
|
||||
void onNetButtonClicked();
|
||||
KyActiveConnectResourse *m_wiredActivatelist = nullptr;
|
||||
KyWiredConnectOperation *m_connect_operation = nullptr;
|
||||
bool m_flag = false; //用户点击连接与否
|
||||
bool m_activated = false;
|
||||
QString deviceName = nullptr;
|
||||
};
|
||||
|
||||
#endif // LANLISTITEM_H
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
#include "listitem.h"
|
||||
#include <QEvent>
|
||||
|
||||
#define MAIN_LAYOUT_MARGINS 0,0,0,0
|
||||
#define MAIN_LAYOUT_SPACING 0
|
||||
#define ITEM_FRAME_MARGINS 16,6,16,6
|
||||
#define ITEM_FRAME_SPACING 10
|
||||
|
||||
#define INFO_ICON_WIDTH 16
|
||||
#define INFO_ICON_HEIGHT 16
|
||||
|
||||
ListItem::ListItem(QWidget *parent) : QFrame(parent)
|
||||
{
|
||||
initUI();
|
||||
initConnection();
|
||||
}
|
||||
|
||||
ListItem::~ListItem()
|
||||
|
@ -21,15 +22,6 @@ ListItem::~ListItem()
|
|||
m_infoButton = NULL;
|
||||
}
|
||||
|
||||
bool ListItem::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == this) {
|
||||
if (event->type() == QEvent::MouseButtonPress) {
|
||||
this->onNetButtonClicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ListItem::setName(const QString &name)
|
||||
{
|
||||
m_nameLabel->setText(name);
|
||||
|
@ -37,20 +29,21 @@ void ListItem::setName(const QString &name)
|
|||
|
||||
void ListItem::initUI()
|
||||
{
|
||||
m_mainLayout = new QVBoxLayout(this);
|
||||
m_mainLayout = new QVBoxLayout;
|
||||
m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||
m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING);
|
||||
this->setLayout(m_mainLayout);
|
||||
|
||||
m_itemFrame = new QFrame(this);
|
||||
m_itemFrame = new QFrame;
|
||||
|
||||
m_hItemLayout = new QHBoxLayout(m_itemFrame);
|
||||
m_hItemLayout->setContentsMargins(ITEM_FRAME_MARGINS);
|
||||
m_hItemLayout->setSpacing(ITEM_FRAME_SPACING);
|
||||
|
||||
m_netButton = new RadioItemButton(m_itemFrame);
|
||||
m_netButton = new NetButton(m_itemFrame);
|
||||
m_nameLabel = new QLabel(m_itemFrame);
|
||||
m_infoButton = new InfoButton(m_itemFrame);
|
||||
m_infoButton->setIconSize(QSize(INFO_ICON_WIDTH,INFO_ICON_HEIGHT));
|
||||
|
||||
m_hItemLayout->addWidget(m_netButton);
|
||||
m_hItemLayout->addWidget(m_nameLabel);
|
||||
|
@ -59,19 +52,3 @@ void ListItem::initUI()
|
|||
|
||||
m_mainLayout->addWidget(m_itemFrame);
|
||||
}
|
||||
|
||||
void ListItem::initConnection()
|
||||
{
|
||||
connect(this->m_netButton, &RadioItemButton::clicked, this, &ListItem::onNetButtonClicked);
|
||||
connect(this->m_infoButton, &InfoButton::clicked, this, &ListItem::onInfoButtonClicked);
|
||||
}
|
||||
|
||||
void ListItem::onInfoButtonClicked()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ListItem::onNetButtonClicked()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define LISTITEM_H
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include "radioitembutton.h"
|
||||
#include "netbutton.h"
|
||||
#include "infobutton.h"
|
||||
|
||||
class ListItem : public QFrame
|
||||
|
@ -14,23 +14,17 @@ public:
|
|||
void setName(const QString &name);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
protected:
|
||||
QVBoxLayout * m_mainLayout = nullptr;
|
||||
QFrame * m_itemFrame = nullptr;
|
||||
QHBoxLayout * m_hItemLayout = nullptr;
|
||||
RadioItemButton * m_netButton = nullptr;
|
||||
QLabel * m_nameLabel = nullptr;
|
||||
QFrame * m_itemFrame = nullptr;
|
||||
NetButton * m_netButton = nullptr;
|
||||
|
||||
private:
|
||||
QVBoxLayout * m_mainLayout = nullptr;
|
||||
QHBoxLayout * m_hItemLayout = nullptr;
|
||||
InfoButton * m_infoButton = nullptr;
|
||||
|
||||
private:
|
||||
void initUI();
|
||||
void initConnection();
|
||||
|
||||
protected slots:
|
||||
virtual void onInfoButtonClicked();
|
||||
virtual void onNetButtonClicked();
|
||||
};
|
||||
|
||||
#endif // LISTITEM_H
|
||||
|
|
|
@ -1,38 +1,80 @@
|
|||
#include "lanpage.h"
|
||||
#include <QSettings>
|
||||
#include <QDebug>
|
||||
|
||||
#define MAIN_LAYOUT_MARGINS 0,0,0,0
|
||||
#define MAIN_LAYOUT_SPACING 0
|
||||
#define TITLE_FRAME_HEIGHT 52
|
||||
#define TITLE_LAYOUT_MARGINS 24,0,24,0
|
||||
#define LAN_LAYOUT_MARGINS 8,8,8,8
|
||||
#define LAN_LAYOUT_SPACING 8
|
||||
#define LAN_LIST_SPACING 2
|
||||
#define TEXT_MARGINS 16,0,0,0
|
||||
//#define SCROLL_AREA_HEIGHT 200
|
||||
#define SETTINGS_LAYOUT_MARGINS 24,16,24,16
|
||||
#define TRANSPARENT_COLOR QColor(0,0,0,0)
|
||||
#define SWITCH_WIDTH 48
|
||||
#define SWITCH_HEIGHT 24
|
||||
|
||||
LanPage::LanPage(QWidget *parent) : TabPage(parent)
|
||||
{
|
||||
m_activeResourse = new KyActiveConnectResourse;
|
||||
m_connectResourse = new KyConnectResourse;
|
||||
m_device = new KyNetworkDeviceResourse;
|
||||
initDevice();
|
||||
initLanUI();
|
||||
initUI();
|
||||
initList();
|
||||
connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist);
|
||||
connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &LanPage::addConnectionSlot);
|
||||
connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &LanPage::RemoveConnectionSlot);
|
||||
}
|
||||
|
||||
|
||||
void LanPage::initLanUI()
|
||||
LanPage::~LanPage()
|
||||
{
|
||||
m_titleLabel->setText(tr("LAN"));
|
||||
m_activatedNetLabel->setText(tr("Activated LAN"));
|
||||
m_inactivatedNetLabel->setText(tr("Inactivated LAN"));
|
||||
|
||||
m_inactivatedNetListWidget = new QListWidget(m_inactivatedNetListArea);
|
||||
m_inactivatedNetListArea->setWidget(m_inactivatedNetListWidget);
|
||||
m_inactivatedNetListArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_inactivatedNetListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
m_inactivatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||
m_inactivatedNetListWidget->setSpacing(NET_LIST_SPACING);
|
||||
m_inactivatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
||||
}
|
||||
|
||||
void LanPage::RemoveConnectionSlot(QString path)
|
||||
{
|
||||
qDebug()<<"___remove____";
|
||||
QEventLoop loop;
|
||||
QTimer::singleShot(200, &loop, SLOT(quit()));
|
||||
loop.exec();
|
||||
QMap<KyConnectItem *, QListWidgetItem *>::iterator iters;
|
||||
for (iters = m_deactiveMap.begin(); iters != m_deactiveMap.end(); ++iters) {
|
||||
KyConnectItem *item = iters.key();
|
||||
if (item->m_connectPath == path) {
|
||||
qDebug() << "D_E_L_E_T_E___D_E_A_C_T_I_V_E";
|
||||
m_inactivatedLanListWidget->removeItemWidget(iters.value());
|
||||
delete(iters.value());
|
||||
m_deactiveMap.erase(iters);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void LanPage::addConnectionSlot(QString uuid)
|
||||
{
|
||||
KyConnectItem * newItem = m_connectResourse->getConnectionItemByUuid(uuid, deviceName);
|
||||
if (newItem != nullptr) {
|
||||
LanListItem * newListItem = new LanListItem(newItem, deviceName);
|
||||
qDebug() << "N_E_W";
|
||||
newListItem->setFixedHeight(48);
|
||||
m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget);
|
||||
m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),48));
|
||||
|
||||
m_inactivatedLanListWidget->addItem(m_listWidgetItem);
|
||||
m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, newListItem);
|
||||
m_deactiveMap.insert(newItem, m_listWidgetItem);
|
||||
} else {
|
||||
qDebug()<<"getConnectionItemByUuid is empty!";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief WlanPage::initDevice 初始化默认网卡
|
||||
*/
|
||||
void LanPage::initDevice()
|
||||
{
|
||||
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
|
||||
m_settings->beginGroup("DEFAULTCARD");
|
||||
QString key("wired");
|
||||
QString deviceName = m_settings->value(key, "").toString();
|
||||
deviceName = m_settings->value(key, "").toString();
|
||||
if (deviceName.isEmpty()) {
|
||||
qDebug() << "initDevice but defalut wired card is null";
|
||||
QStringList list;
|
||||
|
@ -52,3 +94,168 @@ void LanPage::initDevice()
|
|||
m_settings = nullptr;
|
||||
|
||||
}
|
||||
|
||||
void LanPage::initUI()
|
||||
{
|
||||
m_titleLabel->setText(tr("LAN"));
|
||||
|
||||
m_netSwitch->resize(SWITCH_WIDTH, SWITCH_HEIGHT);
|
||||
|
||||
m_activatedNetLabel->setText(tr("Activated LAN"));
|
||||
m_activatedLanListWidget = new QListWidget(m_activatedNetFrame);
|
||||
m_activatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
||||
m_activatedLanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||
m_activatedLanListWidget->setSpacing(LAN_LIST_SPACING);
|
||||
m_activatedLanListWidget->setFixedHeight(48); //active区域固定高度?
|
||||
m_activatedNetLayout->addWidget(m_activatedLanListWidget);
|
||||
|
||||
m_inactivatedNetLabel->setText(tr("Inactivated LAN"));
|
||||
|
||||
QPalette pal = this->palette();
|
||||
pal.setColor(QPalette::Window, Qt::transparent/*TRANSPARENT_COLOR*/);
|
||||
m_inactivatedNetListArea->setPalette(pal);
|
||||
m_inactivatedLanListWidget = new QListWidget(m_inactivatedNetListArea);
|
||||
m_inactivatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
||||
QHBoxLayout *inLanListLayout = new QHBoxLayout(m_inactivatedNetListArea);
|
||||
inLanListLayout->addWidget(m_inactivatedLanListWidget);
|
||||
|
||||
m_inactivatedLanListWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
m_inactivatedNetListArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_inactivatedNetListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
m_inactivatedLanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||
m_inactivatedLanListWidget->setSpacing(LAN_LIST_SPACING);
|
||||
|
||||
m_inactivatedNetLayout->addWidget(m_inactivatedNetListArea);
|
||||
|
||||
// KyConnectItem *activeConnectItem = new KyConnectItem();
|
||||
// activeConnectItem->m_connectUuid = "e8f384a4-2214-361b-b328-eb36b36136ee";
|
||||
// activeConnectItem->m_connectName = "有线连接1";
|
||||
// activeConnectItem->m_connectPath = "fsfsef";
|
||||
//// activeConnectItem->m_connectState = NetworkManager::ActiveConnection::State::Activated;
|
||||
// m_testLanItem = new LanListItem(activeConnectItem);
|
||||
// m_testLanItem->setMinimumHeight(48);
|
||||
|
||||
// m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget);
|
||||
// m_inactivatedLanListWidget->addItem(m_listWidgetItem);
|
||||
// m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, m_testLanItem);
|
||||
|
||||
}
|
||||
|
||||
void LanPage::initList() //程序拉起,初始化显示
|
||||
{
|
||||
m_activatedLanListWidget->setFixedHeight(60);
|
||||
m_activeResourse->getActiveConnectionList(deviceName,NetworkManager::ConnectionSettings::Wired,m_activedList); //激活列表的显示
|
||||
if (!m_activedList.isEmpty()) {
|
||||
m_listWidgetItem = new QListWidgetItem(m_activatedLanListWidget);
|
||||
m_listWidgetItem->setSizeHint(QSize(m_activatedLanListWidget->width(),48));
|
||||
m_activatedLanListWidget->addItem(m_listWidgetItem);
|
||||
for (int i = 0; i < m_activedList.size(); i++) {
|
||||
KyConnectItem *activeItemData = m_activedList.at(i);
|
||||
activeConnectItem = new LanListItem(activeItemData, deviceName);
|
||||
m_activeMap.insert(activeItemData, m_listWidgetItem);
|
||||
activeConnectItem->setFixedHeight(48);
|
||||
m_activatedLanListWidget->setItemWidget(m_listWidgetItem, activeConnectItem); //还未确保激活!
|
||||
}
|
||||
}
|
||||
|
||||
m_connectResourse->getConnectionList(deviceName, NetworkManager::ConnectionSettings::Wired, m_deactivedList); //未激活列表的显示
|
||||
if (!m_deactivedList.isEmpty()) {
|
||||
for (int i = 0; i < m_deactivedList.size(); i++) {
|
||||
m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget);
|
||||
m_listWidgetItem->setSizeHint(QSize(100,48));
|
||||
m_inactivatedLanListWidget->addItem(m_listWidgetItem);
|
||||
|
||||
KyConnectItem *deactiveItemData = m_deactivedList.at(i);
|
||||
// qDebug()<<m_activedList.at(i);
|
||||
deactiveConnectItem = new LanListItem(deactiveItemData ,deviceName);
|
||||
|
||||
m_deactiveMap.insert(deactiveItemData, m_listWidgetItem);
|
||||
|
||||
deactiveConnectItem->setFixedHeight(48);
|
||||
m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, deactiveConnectItem); //显示时要不要确保状态?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason)
|
||||
{
|
||||
qDebug() << "S_T_A_T_E:" << state;
|
||||
if (state == NetworkManager::ActiveConnection::State::Activated) {
|
||||
QMap<KyConnectItem *, QListWidgetItem *>::iterator i; //在未激活列表里删除
|
||||
for (i = m_deactiveMap.begin(); i != m_deactiveMap.constEnd(); ++i) {
|
||||
KyConnectItem *m_Item = i.key();
|
||||
if (m_Item->m_connectUuid == uuid) {
|
||||
m_Item->m_connectState = state;
|
||||
m_activeItem = new LanListItem(m_Item ,deviceName);
|
||||
m_activeItem->setFixedHeight(48);
|
||||
m_listWidgetItem = new QListWidgetItem(m_activatedLanListWidget);
|
||||
m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),48));
|
||||
|
||||
m_activatedLanListWidget->addItem(i.value());
|
||||
m_activatedLanListWidget->setItemWidget(m_listWidgetItem, m_activeItem);
|
||||
|
||||
m_activeMap.insert(m_Item, m_listWidgetItem);
|
||||
m_inactivatedLanListWidget->removeItemWidget(i.value());
|
||||
delete(i.value());
|
||||
m_deactiveMap.erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (state == NetworkManager::ActiveConnection::State::Deactivated) {
|
||||
qDebug()<<"deactivated happend, begin remove item";
|
||||
QMap<KyConnectItem *, QListWidgetItem *>::iterator i;
|
||||
for (i = m_activeMap.begin(); i != m_activeMap.constEnd(); ++i) { //有新断开,在激活列表里删掉
|
||||
KyConnectItem *m_Item = i.key();
|
||||
if (m_Item->m_connectUuid == uuid) {
|
||||
m_inactivatedLanListWidget->removeItemWidget(i.value());
|
||||
delete(i.value());
|
||||
break;
|
||||
}
|
||||
}
|
||||
qDebug()<<"deactivated happend, begin add new item";
|
||||
bool hasDeactiveNet = false;
|
||||
QMap<KyConnectItem *, QListWidgetItem *>::iterator iter;
|
||||
for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.end(); ++iter) {
|
||||
KyConnectItem *m_Item = iter.key();
|
||||
if (m_Item->m_connectUuid == uuid) {
|
||||
hasDeactiveNet = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
qDebug()<<"hasDeactiveNet:"<<hasDeactiveNet;
|
||||
|
||||
QMap<KyConnectItem *, QListWidgetItem *>::iterator iters;
|
||||
for (iters = m_activeMap.begin(); iters != m_activeMap.end(); ++iters) {
|
||||
KyConnectItem *m_Item = iters.key();
|
||||
if (m_Item->m_connectUuid == uuid && !hasDeactiveNet) {
|
||||
m_Item->m_connectState = state;
|
||||
m_deactiveItem = new LanListItem(m_Item ,deviceName);
|
||||
m_deactiveItem->setFixedHeight(48);
|
||||
|
||||
m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget);
|
||||
m_listWidgetItem->setSizeHint(QSize(100,48));
|
||||
|
||||
m_inactivatedLanListWidget->addItem(m_listWidgetItem);
|
||||
m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, m_deactiveItem);
|
||||
|
||||
m_deactiveMap.insert(m_Item, m_listWidgetItem);
|
||||
m_activeMap.erase(iters);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (state == NetworkManager::ActiveConnection::State::Activating){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool LanPage::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == m_netSwitch) {
|
||||
// if(event == click)
|
||||
// {
|
||||
|
||||
// }
|
||||
}
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +1,63 @@
|
|||
#ifndef LANPAGE_H
|
||||
#define LANPAGE_H
|
||||
|
||||
#include "tabpage.h"
|
||||
#include "kylinnetworkdeviceresource.h"
|
||||
#include "divider.h"
|
||||
#include "switchbutton.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QScrollArea>
|
||||
#include <QListWidget>
|
||||
#include <QMap>
|
||||
|
||||
#include "list-items/listitem.h"
|
||||
#include "list-items/lanlistitem.h"
|
||||
#include "tab-pages/tabpage.h"
|
||||
|
||||
class LanPage : public TabPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LanPage(QWidget *parent = nullptr);
|
||||
~LanPage()=default;
|
||||
~LanPage();
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
void initUI();
|
||||
void initList();
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
void initDevice();//初始化默认设备
|
||||
|
||||
private:
|
||||
KyNetworkDeviceResourse *m_device = nullptr;
|
||||
|
||||
void initLanUI();
|
||||
void initDevice();//初始化默认设备
|
||||
QListWidget * m_activatedLanListWidget = nullptr;
|
||||
QListWidget * m_inactivatedLanListWidget = nullptr;
|
||||
|
||||
LanListItem * m_testLanItem = nullptr;
|
||||
LanListItem * activeConnectItem = nullptr;
|
||||
LanListItem * deactiveConnectItem = nullptr;
|
||||
LanListItem * m_activeItem = nullptr;
|
||||
LanListItem * m_deactiveItem = nullptr;
|
||||
|
||||
QListWidgetItem *m_listWidgetItem = nullptr;
|
||||
|
||||
KyNetworkDeviceResourse * m_deviceSource = nullptr;
|
||||
KyActiveConnectResourse *m_activeResourse = nullptr;
|
||||
|
||||
KyConnectResourse *m_connectResourse = nullptr;
|
||||
|
||||
QList<KyConnectItem *> m_activedList;
|
||||
QList<KyConnectItem *> m_deactivedList;
|
||||
|
||||
QMap<KyConnectItem *, QListWidgetItem *> m_deactiveMap;
|
||||
QMap<KyConnectItem *, QListWidgetItem *> m_activeMap;
|
||||
QString deviceName;
|
||||
private slots:
|
||||
void updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason);
|
||||
void addConnectionSlot(QString uuid);
|
||||
void RemoveConnectionSlot(QString path);
|
||||
};
|
||||
|
||||
#endif // LANPAGE_H
|
||||
|
|
|
@ -36,12 +36,7 @@ void TabPage::initUI()
|
|||
m_activatedNetLayout->setSpacing(NET_LAYOUT_SPACING);
|
||||
m_activatedNetLabel = new QLabel(m_activatedNetFrame);
|
||||
m_activatedNetLabel->setContentsMargins(TEXT_MARGINS);
|
||||
m_activatedNetListWidget = new QListWidget(m_activatedNetFrame);
|
||||
m_activatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
||||
m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||
m_activatedNetListWidget->setSpacing(NET_LIST_SPACING);
|
||||
m_activatedNetLayout->addWidget(m_activatedNetLabel);
|
||||
m_activatedNetLayout->addWidget(m_activatedNetListWidget);
|
||||
m_activatedNetDivider = new Divider(this);
|
||||
|
||||
m_inactivatedNetFrame = new QFrame(this);
|
||||
|
|
|
@ -50,7 +50,6 @@ protected:
|
|||
QFrame * m_activatedNetFrame = nullptr;
|
||||
QVBoxLayout * m_activatedNetLayout = nullptr;
|
||||
QLabel * m_activatedNetLabel = nullptr;
|
||||
QListWidget * m_activatedNetListWidget = nullptr;
|
||||
Divider * m_activatedNetDivider = nullptr;
|
||||
|
||||
QFrame * m_inactivatedNetFrame = nullptr;
|
||||
|
|
|
@ -62,8 +62,12 @@ void WlanPage::initWlanUI()
|
|||
m_inactivatedWlanListAreaLayout->addWidget(m_inactivatedNetListWidget);
|
||||
m_inactivatedWlanListAreaLayout->addWidget(m_hiddenWlanLabel);
|
||||
m_inactivatedWlanListAreaLayout->addStretch();
|
||||
|
||||
m_activatedNetListWidget = new QListWidget(m_activatedNetFrame);
|
||||
m_activatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
||||
m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||
m_activatedNetListWidget->setSpacing(NET_LIST_SPACING);
|
||||
m_activatedNetListWidget->setFixedHeight(NORMAL_HEIGHT);
|
||||
m_activatedNetLayout->addWidget(m_activatedNetListWidget);
|
||||
// m_inactivatedNetListArea->setFixedHeight(SCROLLAREA_HEIGHT);
|
||||
m_inactivatedNetListArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ private:
|
|||
QVBoxLayout * m_inactivatedWlanListAreaLayout = nullptr;
|
||||
QFrame * m_hiddenWlanWidget = nullptr;
|
||||
QHBoxLayout * m_hiddenWlanLayout = nullptr;
|
||||
QListWidget * m_activatedNetListWidget = nullptr;
|
||||
QLabel * m_hiddenWlanLabel = nullptr;
|
||||
|
||||
QString m_activatedWlanSSid;
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
#include "infobutton.h"
|
||||
#include <QEvent>
|
||||
#include <QIcon>
|
||||
|
||||
#define BUTTON_SIZE 16,16
|
||||
|
||||
InfoButton::InfoButton(QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
|
@ -12,27 +9,47 @@ InfoButton::InfoButton(QWidget *parent) : QPushButton(parent)
|
|||
|
||||
void InfoButton::initUI()
|
||||
{
|
||||
this->setFixedSize(BUTTON_SIZE);
|
||||
this->setText("i");
|
||||
info_img = QIcon::fromTheme("network-wired-connected-symbolic", QIcon::fromTheme("network-wired-symbolic", QIcon(":/res/l/network-online.svg")));
|
||||
info_imgHover = QIcon::fromTheme("network-wireless-signal-excellent-symbolic", QIcon(":/res/x/wifi-list-bg.svg"));
|
||||
info_imgPressed = QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png"));
|
||||
setIcon(info_img);
|
||||
}
|
||||
|
||||
bool InfoButton::event(QEvent *event)
|
||||
{
|
||||
switch(event->type())
|
||||
{
|
||||
case QEvent::Enter:
|
||||
setIcon(info_imgHover);
|
||||
break;
|
||||
case QEvent::Leave:
|
||||
setIcon(info_img);
|
||||
break;
|
||||
case QEvent::MouseButtonPress:
|
||||
setIcon(info_imgPressed);
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
setIcon(info_imgHover);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QPushButton::event(event);
|
||||
}
|
||||
|
||||
void InfoButton::enterEvent(QEvent *)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void InfoButton::leaveEvent(QEvent *)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool InfoButton::eventFilter(QObject *w, QEvent *e)
|
||||
{
|
||||
if(e->type() == QEvent::MouseButtonPress) {
|
||||
emit this->clicked();
|
||||
}
|
||||
return QPushButton::eventFilter(w, e);
|
||||
}
|
||||
|
||||
void InfoButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
return QPushButton::paintEvent(event);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef INFOBUTTON_H
|
||||
#define INFOBUTTON_H
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QIcon>
|
||||
|
||||
class InfoButton : public QPushButton
|
||||
{
|
||||
|
@ -10,20 +10,17 @@ public:
|
|||
explicit InfoButton(QWidget * parent = nullptr);
|
||||
~InfoButton() = default;
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
private:
|
||||
void initUI();
|
||||
|
||||
private:
|
||||
QLabel *m_iconLabel = nullptr;
|
||||
QIcon info_img;
|
||||
QIcon info_imgHover;
|
||||
QIcon info_imgPressed;
|
||||
|
||||
protected:
|
||||
virtual void enterEvent(QEvent *event);
|
||||
bool event(QEvent *event);
|
||||
virtual void enterEvent(QEvent *event) override;
|
||||
virtual void leaveEvent(QEvent *event);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
};
|
||||
|
||||
#endif // INFOBUTTON_H
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
#include "netbutton.h"
|
||||
|
||||
NetButton::NetButton(bool isActivated, QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
connect(this, &NetButton::requestStartLoading, this, &NetButton::onLoadingStarted);
|
||||
connect(this, &NetButton::requestStopLoading, this, &NetButton::onLoadingStopped);
|
||||
m_isActivated = isActivated;
|
||||
this->setAutoFillBackground(false);
|
||||
m_iconLabel = new QLabel(this);
|
||||
m_iconLabel->setScaledContents(true);
|
||||
}
|
||||
|
||||
void NetButton::startLoading()
|
||||
{
|
||||
emit this->requestStartLoading();
|
||||
}
|
||||
|
||||
void NetButton::stopLoading()
|
||||
{
|
||||
emit this->requestStopLoading();
|
||||
}
|
||||
|
||||
void NetButton::setPressed()
|
||||
{
|
||||
//ZJP_TODO 设置颜色为点击颜色,注意区分已连接/未连接
|
||||
if (m_isActivated)
|
||||
;
|
||||
;
|
||||
}
|
||||
|
||||
void NetButton::setReleased()
|
||||
{
|
||||
//ZJP_TODO 设置颜色为未点击颜色,注意区分已连接/未连接
|
||||
if (m_isActivated)
|
||||
;
|
||||
;
|
||||
}
|
||||
|
||||
void NetButton::setButtonIcon(QIcon *icon)
|
||||
{
|
||||
if (!icon) { return; }
|
||||
m_iconLabel->setPixmap(icon->pixmap(this->size()));
|
||||
}
|
||||
|
||||
void NetButton::onLoadingStarted()
|
||||
{
|
||||
//ZJP_TODO 开始播放转圈动画
|
||||
}
|
||||
|
||||
void NetButton::onLoadingStopped()
|
||||
{
|
||||
//ZJP_TODO 停止播放转圈动画
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef NETBUTTON_H
|
||||
#define NETBUTTON_H
|
||||
#include <QPushButton>
|
||||
#include <QIcon>
|
||||
#include <QLabel>
|
||||
#define ACTIVATED true
|
||||
#define INACTIVATED false
|
||||
|
||||
class NetButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
NetButton(bool isActivated = INACTIVATED, QWidget * parent = nullptr);
|
||||
~NetButton() = default;
|
||||
void startLoading();
|
||||
void stopLoading();
|
||||
void setPressed();
|
||||
void setReleased();
|
||||
void setButtonIcon(QIcon *);
|
||||
|
||||
signals:
|
||||
void requestStartLoading();
|
||||
void requestStopLoading();
|
||||
|
||||
private:
|
||||
bool m_isActivated = INACTIVATED;
|
||||
QLabel * m_iconLabel = nullptr;
|
||||
|
||||
private slots:
|
||||
void onLoadingStarted();
|
||||
void onLoadingStopped();
|
||||
};
|
||||
|
||||
#endif // NETBUTTON_H
|
|
@ -4,6 +4,7 @@ HEADERS += \
|
|||
$$PWD/divider.h \
|
||||
$$PWD/infobutton.h \
|
||||
$$PWD/loadingdiv.h \
|
||||
$$PWD/netbutton.h \
|
||||
$$PWD/radioitembutton.h \
|
||||
$$PWD/switchbutton.h
|
||||
|
||||
|
@ -12,5 +13,6 @@ SOURCES += \
|
|||
$$PWD/divider.cpp \
|
||||
$$PWD/infobutton.cpp \
|
||||
$$PWD/loadingdiv.cpp \
|
||||
$$PWD/netbutton.cpp \
|
||||
$$PWD/radioitembutton.cpp \
|
||||
$$PWD/switchbutton.cpp
|
||||
|
|
Loading…
Reference in New Issue