From db93d2c498189da12b1b1991af61719b58cea06d Mon Sep 17 00:00:00 2001 From: ksn Date: Fri, 27 Aug 2021 14:54:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/list-items/lanlistitem.cpp | 18 ++- src/frontend/list-items/lanlistitem.h | 5 +- src/frontend/list-items/listitem.cpp | 4 +- src/frontend/list-items/listitem.h | 6 +- src/frontend/tab-pages/lanpage.cpp | 151 ++++++++++++------------ src/frontend/tab-pages/lanpage.h | 14 ++- 6 files changed, 100 insertions(+), 98 deletions(-) diff --git a/src/frontend/list-items/lanlistitem.cpp b/src/frontend/list-items/lanlistitem.cpp index 60bf8c79..c1ed4c42 100644 --- a/src/frontend/list-items/lanlistitem.cpp +++ b/src/frontend/list-items/lanlistitem.cpp @@ -7,18 +7,14 @@ 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; - + m_connectOperation = new KyWiredConnectOperation; + m_data = data; + m_nameLabel->setText(m_data->m_connectName); 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; } @@ -32,13 +28,13 @@ bool LanListItem::eventFilter(QObject *watched, QEvent *event) if (event->type() == QEvent::MouseButtonPress) { if (!m_activated) { //未连接,点击后连 - m_connect_operation->activateWiredConnection(m_data->m_connectUuid, deviceName); - qDebug() << m_data->m_connectName << "点击后连接"; + m_connectOperation->activateWiredConnection(m_data->m_connectUuid, deviceName); + qDebug() << m_data->m_connectName << "Connect after user clicked!"; m_activated = true; } else { //连接,点击后断开 - m_connect_operation->deactivateWiredConnection(m_data->m_connectName, m_data->m_connectUuid); - qDebug() << m_data->m_connectName << "点击后断开"; + m_connectOperation->deactivateWiredConnection(m_data->m_connectName, m_data->m_connectUuid); + qDebug() << m_data->m_connectName << "Disconnect after user clicked!"; m_activated = false; } } diff --git a/src/frontend/list-items/lanlistitem.h b/src/frontend/list-items/lanlistitem.h index 02184058..44f75807 100644 --- a/src/frontend/list-items/lanlistitem.h +++ b/src/frontend/list-items/lanlistitem.h @@ -21,9 +21,8 @@ protected: private: KyConnectItem *m_data = nullptr; - KyActiveConnectResourse *m_wiredActivatelist = nullptr; - KyWiredConnectOperation *m_connect_operation = nullptr; - bool m_flag = false; //用户点击连接与否 + KyWiredConnectOperation *m_connectOperation = nullptr; + bool m_activated = false; QString deviceName = nullptr; }; diff --git a/src/frontend/list-items/listitem.cpp b/src/frontend/list-items/listitem.cpp index 9a96d9ef..8100bc0e 100644 --- a/src/frontend/list-items/listitem.cpp +++ b/src/frontend/list-items/listitem.cpp @@ -29,12 +29,12 @@ void ListItem::setName(const QString &name) void ListItem::initUI() { - m_mainLayout = new QVBoxLayout; + 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; + m_itemFrame = new QFrame(this); m_hItemLayout = new QHBoxLayout(m_itemFrame); m_hItemLayout->setContentsMargins(ITEM_FRAME_MARGINS); diff --git a/src/frontend/list-items/listitem.h b/src/frontend/list-items/listitem.h index cf27e49a..9ab5af16 100644 --- a/src/frontend/list-items/listitem.h +++ b/src/frontend/list-items/listitem.h @@ -14,14 +14,16 @@ public: void setName(const QString &name); protected: - QLabel * m_nameLabel = nullptr; QFrame * m_itemFrame = nullptr; + + QLabel * m_nameLabel = nullptr; NetButton * m_netButton = nullptr; + InfoButton * m_infoButton = nullptr; private: QVBoxLayout * m_mainLayout = nullptr; QHBoxLayout * m_hItemLayout = nullptr; - InfoButton * m_infoButton = nullptr; + private: void initUI(); diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 143afef5..126e8b1f 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -5,8 +5,6 @@ #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 @@ -14,6 +12,7 @@ #define TRANSPARENT_COLOR QColor(0,0,0,0) #define SWITCH_WIDTH 48 #define SWITCH_HEIGHT 24 +#define ITEM_HEIGHT 48 LanPage::LanPage(QWidget *parent) : TabPage(parent) { @@ -25,7 +24,7 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent) 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); + connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &LanPage::removeConnectionSlot); } LanPage::~LanPage() @@ -33,9 +32,9 @@ LanPage::~LanPage() } -void LanPage::RemoveConnectionSlot(QString path) +void LanPage::removeConnectionSlot(QString path) //删除时后端会自动断开激活,将其从未激活列表中删除 { - qDebug()<<"___remove____"; + qDebug()<<"[LanPage] Removing a connection, path:"<m_connectPath == path) { - qDebug() << "D_E_L_E_T_E___D_E_A_C_T_I_V_E"; + qDebug()<<"[LanPage] Remove a connection from inactive list"; m_inactivatedLanListWidget->removeItemWidget(iters.value()); delete(iters.value()); m_deactiveMap.erase(iters); @@ -51,21 +50,23 @@ void LanPage::RemoveConnectionSlot(QString path) } } } -void LanPage::addConnectionSlot(QString uuid) + +void LanPage::addConnectionSlot(QString uuid) //新增一个有线连接,将其加入到激活列表 { - KyConnectItem * newItem = m_connectResourse->getConnectionItemByUuid(uuid, deviceName); + KyConnectItem * newItem = m_connectResourse->getConnectionItemByUuid(uuid, m_deviceName); if (newItem != nullptr) { - LanListItem * newListItem = new LanListItem(newItem, deviceName); - qDebug() << "N_E_W"; - newListItem->setFixedHeight(48); + qDebug()<<"[LanPage] Add a new connection, name:"<m_connectName; + LanListItem * newListItem = new LanListItem(newItem, m_deviceName); + newListItem->setFixedHeight(ITEM_HEIGHT); + m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget); - m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),48)); + m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),ITEM_HEIGHT)); m_inactivatedLanListWidget->addItem(m_listWidgetItem); m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, newListItem); m_deactiveMap.insert(newItem, m_listWidgetItem); } else { - qDebug()<<"getConnectionItemByUuid is empty!"; + qDebug()<<"[LanPage] GetConnectionItemByUuid is empty when add a new!"; } } @@ -74,58 +75,51 @@ void LanPage::initDevice() QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); m_settings->beginGroup("DEFAULTCARD"); QString key("wired"); - deviceName = m_settings->value(key, "").toString(); - if (deviceName.isEmpty()) { + m_deviceName = m_settings->value(key, "").toString(); + if (m_deviceName.isEmpty()) { qDebug() << "initDevice but defalut wired card is null"; QStringList list; list.empty(); m_device->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, list); if (!list.isEmpty()) { - deviceName = list.at(0); - m_settings->setValue(key, deviceName); + m_deviceName = list.at(0); + m_settings->setValue(key, m_deviceName); } } - updateDefaultDevice(deviceName); - qDebug() << "[LanPage] initDevice defaultDevice = " << deviceName; + updateDefaultDevice(m_deviceName); + qDebug() << "[LanPage] initDevice defaultDevice = " << m_deviceName; m_settings->endGroup(); m_settings->sync(); delete m_settings; 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->setContentsMargins(MAIN_LAYOUT_MARGINS); m_activatedLanListWidget->setSpacing(LAN_LIST_SPACING); - m_activatedLanListWidget->setFixedHeight(48); //active区域固定高度? + m_activatedLanListWidget->setFixedHeight(ITEM_HEIGHT); //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->setBackgroundRole(QPalette::Base); + m_inactivatedNetListArea->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); + m_inactivatedLanListWidget = new QListWidget(m_inactivatedNetListArea); + m_inactivatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame); +// m_inactivatedLanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS); + m_inactivatedLanListWidget->setSpacing(LAN_LIST_SPACING); + QVBoxLayout *inactiveLanListLayout = new QVBoxLayout(m_inactivatedNetListArea); + inactiveLanListLayout->addWidget(m_inactivatedLanListWidget); // KyConnectItem *activeConnectItem = new KyConnectItem(); // activeConnectItem->m_connectUuid = "e8f384a4-2214-361b-b328-eb36b36136ee"; @@ -133,7 +127,7 @@ void LanPage::initUI() // activeConnectItem->m_connectPath = "fsfsef"; //// activeConnectItem->m_connectState = NetworkManager::ActiveConnection::State::Activated; // m_testLanItem = new LanListItem(activeConnectItem); -// m_testLanItem->setMinimumHeight(48); +// m_testLanItem->setMinimumHeight(ITEM_HEIGHT); // m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget); // m_inactivatedLanListWidget->addItem(m_listWidgetItem); @@ -143,102 +137,110 @@ void LanPage::initUI() void LanPage::initList() //程序拉起,初始化显示 { - m_activatedLanListWidget->setFixedHeight(60); - m_activeResourse->getActiveConnectionList(deviceName,NetworkManager::ConnectionSettings::Wired,m_activedList); //激活列表的显示 + m_activeResourse->getActiveConnectionList(m_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++) { + m_listWidgetItem = new QListWidgetItem(m_activatedLanListWidget); + m_listWidgetItem->setSizeHint(QSize(m_activatedLanListWidget->width(),ITEM_HEIGHT)); + m_activatedLanListWidget->addItem(m_listWidgetItem); + KyConnectItem *activeItemData = m_activedList.at(i); - activeConnectItem = new LanListItem(activeItemData, deviceName); + + activeConnectItem = new LanListItem(activeItemData, m_deviceName); + + m_activatedLanListWidget->setItemWidget(m_listWidgetItem, activeConnectItem); + m_activeMap.insert(activeItemData, m_listWidgetItem); - activeConnectItem->setFixedHeight(48); - m_activatedLanListWidget->setItemWidget(m_listWidgetItem, activeConnectItem); //还未确保激活! } } - m_connectResourse->getConnectionList(deviceName, NetworkManager::ConnectionSettings::Wired, m_deactivedList); //未激活列表的显示 + m_connectResourse->getConnectionList(m_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_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),ITEM_HEIGHT)); m_inactivatedLanListWidget->addItem(m_listWidgetItem); KyConnectItem *deactiveItemData = m_deactivedList.at(i); -// qDebug()<setFixedHeight(ITEM_HEIGHT); + m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, deactiveConnectItem); 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; + qDebug()<<"[LanPage] State change slot:"<::iterator i; //在未激活列表里删除 - for (i = m_deactiveMap.begin(); i != m_deactiveMap.constEnd(); ++i) { - KyConnectItem *m_Item = i.key(); + qDebug()<<"Get an actived connection, begin to move it from deactive to avtive!"; + QMap::iterator iter; //在未激活列表里删除 + for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.constEnd(); ++iter) { + KyConnectItem *m_Item = iter.key(); if (m_Item->m_connectUuid == uuid) { + qDebug()<<"Add an active connection to activeList:"<m_connectName; 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_listWidgetItem = new QListWidgetItem(m_activatedLanListWidget); + m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),ITEM_HEIGHT)); + m_activatedLanListWidget->addItem(iter.value()); + + m_activeItem = new LanListItem(m_Item ,m_deviceName); + m_activatedLanListWidget->setItemWidget(m_listWidgetItem, m_activeItem); + m_inactivatedLanListWidget->removeItemWidget(iter.value()); + delete(iter.value()); + m_activeMap.insert(m_Item, m_listWidgetItem); - m_inactivatedLanListWidget->removeItemWidget(i.value()); - delete(i.value()); - m_deactiveMap.erase(i); + m_deactiveMap.erase(iter); break; } } } else if (state == NetworkManager::ActiveConnection::State::Deactivated) { - qDebug()<<"deactivated happend, begin remove item"; + qDebug()<<"Get a deactivate, begin to remove it from activeList"; QMap::iterator i; - for (i = m_activeMap.begin(); i != m_activeMap.constEnd(); ++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()); + m_activatedLanListWidget->removeItemWidget(i.value()); delete(i.value()); break; } } - qDebug()<<"deactivated happend, begin add new item"; + bool hasDeactiveNet = false; QMap::iterator iter; - for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.end(); ++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:"<::iterator iters; - for (iters = m_activeMap.begin(); iters != m_activeMap.end(); ++iters) { + for (iters = m_activeMap.begin(); iters != m_activeMap.end(); ++iters) { //在未激活列表中增加一项连接 KyConnectItem *m_Item = iters.key(); if (m_Item->m_connectUuid == uuid && !hasDeactiveNet) { + qDebug()<<"Add a deactive connection to inactiveList:"<m_connectName; m_Item->m_connectState = state; - m_deactiveItem = new LanListItem(m_Item ,deviceName); - m_deactiveItem->setFixedHeight(48); + m_deactiveItem = new LanListItem(m_Item ,m_deviceName); + m_deactiveItem->setFixedHeight(ITEM_HEIGHT); m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget); - m_listWidgetItem->setSizeHint(QSize(100,48)); + m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),ITEM_HEIGHT)); m_inactivatedLanListWidget->addItem(m_listWidgetItem); m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, m_deactiveItem); m_deactiveMap.insert(m_Item, m_listWidgetItem); + m_activeMap.erase(iters); break; } @@ -248,6 +250,7 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat } } + bool LanPage::eventFilter(QObject *watched, QEvent *event) { if (watched == m_netSwitch) { diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index 611a421d..aedc004b 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -24,10 +24,12 @@ public: signals: private: + void initDevice();//初始化默认设备 void initUI(); void initList(); bool eventFilter(QObject *watched, QEvent *event); - void initDevice();//初始化默认设备 + void addNewItem(KyConnectItem *itemData, QListWidget *listWidget); + private: KyNetworkDeviceResourse *m_device = nullptr; @@ -44,20 +46,20 @@ private: QListWidgetItem *m_listWidgetItem = nullptr; KyNetworkDeviceResourse * m_deviceSource = nullptr; - KyActiveConnectResourse *m_activeResourse = nullptr; - - KyConnectResourse *m_connectResourse = nullptr; + KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接 + KyConnectResourse *m_connectResourse = nullptr; //未激活的连接 QList m_activedList; QList m_deactivedList; QMap m_deactiveMap; QMap m_activeMap; - QString deviceName; + QString m_deviceName; + private slots: void updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason); void addConnectionSlot(QString uuid); - void RemoveConnectionSlot(QString path); + void removeConnectionSlot(QString path); }; #endif // LANPAGE_H