From 9a49f2bd3a056a2b515cde5390b33f9ceca52e16 Mon Sep 17 00:00:00 2001 From: ksn Date: Thu, 23 Sep 2021 18:41:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BD=91=E7=BA=BF=E6=8F=92?= =?UTF-8?q?=E6=8B=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kylinnetworkdeviceresource.cpp | 2 +- src/frontend/list-items/lanlistitem.cpp | 15 ++-- src/frontend/list-items/lanlistitem.h | 1 + src/frontend/tab-pages/lanpage.cpp | 78 +++++++++++-------- src/frontend/tab-pages/lanpage.h | 2 + 5 files changed, 58 insertions(+), 40 deletions(-) diff --git a/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp b/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp index 5919b10d..1f185adf 100644 --- a/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp +++ b/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp @@ -137,7 +137,7 @@ bool KyNetworkDeviceResourse::wiredDeviceCarriered(QString deviceName) NetworkManager::Device::Ptr connectDevice = m_networkResourceInstance->findDeviceInterface(deviceName); if (connectDevice->isValid() - && NetworkManager::Ethernet == connectDevice->type()) { + && NetworkManager::Device::Type::Ethernet == connectDevice->type()) { NetworkManager::WiredDevice *wiredDevicePtr = qobject_cast(connectDevice.data()); return wiredDevicePtr->carrier(); diff --git a/src/frontend/list-items/lanlistitem.cpp b/src/frontend/list-items/lanlistitem.cpp index 1db6a642..b5548eed 100644 --- a/src/frontend/list-items/lanlistitem.cpp +++ b/src/frontend/list-items/lanlistitem.cpp @@ -10,6 +10,7 @@ LanListItem::LanListItem(KyConnectItem *data, QString deviceName, QWidget *paren m_connectOperation = new KyWiredConnectOperation(this); m_activeConnectResource = new KyActiveConnectResourse(this); m_connectResource = new KyConnectResourse(this); + m_deviceResource = new KyNetworkDeviceResourse(this); m_data = data; m_nameLabel->setText(m_data->m_connectName); @@ -55,15 +56,19 @@ void LanListItem::onNetButtonClicked() } if (!m_isActive) { //未连接,点击后连 - m_connectOperation->activateWiredConnection(m_data->m_connectUuid, deviceName); - qDebug() << m_data->m_connectName << "Connect after user clicked!" << deviceName; -// m_data->m_connectState = NetworkManager::ActiveConnection::State::Activating; - m_isActive = true; + if (m_deviceResource->wiredDeviceCarriered(deviceName)) { + m_connectOperation->activateWiredConnection(m_data->m_connectUuid, deviceName); + qDebug() << m_data->m_connectName << "Connect after user clicked!" << deviceName; + m_isActive = true; + } + else { + qDebug() << "[LanListItem] Wired Device not carried"; + m_isActive = false; + } } else { //连接,点击后断开 m_connectOperation->deactivateWiredConnection(m_data->m_connectName, m_data->m_connectUuid); qDebug() << m_data->m_connectName << "Disconnect after user clicked!" << deviceName; -// m_data->m_connectState = NetworkManager::ActiveConnection::State::Deactivated; m_isActive = false; } } diff --git a/src/frontend/list-items/lanlistitem.h b/src/frontend/list-items/lanlistitem.h index bd46ae9e..50a25997 100644 --- a/src/frontend/list-items/lanlistitem.h +++ b/src/frontend/list-items/lanlistitem.h @@ -20,6 +20,7 @@ public: KyWiredConnectOperation *m_connectOperation = nullptr; KyActiveConnectResourse *m_activeConnectResource = nullptr; KyConnectResourse *m_connectResource = nullptr; + KyNetworkDeviceResourse *m_deviceResource = nullptr; QString deviceName = ""; diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 13a683ab..9d058059 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -22,10 +22,11 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent) m_activeResourse = new KyActiveConnectResourse(this); m_connectResourse = new KyConnectResourse(this); m_device = new KyNetworkDeviceResourse(this); - m_nullLanItem = new LanListItem(); +// m_nullLanItem = new LanListItem(); m_devList.empty(); + initUI(); if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { @@ -35,7 +36,7 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent) qDebug()<<"[LanPage] org.ukui.kylin-nm.switch is not installed!"; } - initDeviceCombox(); +// initDeviceCombox(); initList(m_deviceName); connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist); @@ -170,7 +171,7 @@ void LanPage::initDeviceCombox() //TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框;m_devList记录插入的所有设备,deviceMap记录设备状态 QMap deviceMap; getDeviceEnableState(0,deviceMap); - QStringList enableDevice; + m_deviceComboBox->clear(); m_devList.clear(); enableDevice.clear(); @@ -217,6 +218,7 @@ void LanPage::initDeviceCombox() if (enableDevice.count() == 1) { m_deviceFrame->hide(); m_deviceName = enableDevice.at(0); + qDebug() << "[LanPage]Current device:" << m_deviceName; initList(m_deviceName); return; } else { @@ -224,7 +226,7 @@ void LanPage::initDeviceCombox() m_tipsLabel->hide(); m_deviceComboBox->show(); for (int j=0; jaddItem(enableDevice.at(j)); + m_deviceComboBox->addItem(enableDevice.at(j)); } } @@ -295,9 +297,11 @@ void LanPage::onDeviceNameUpdate(QString oldName, QString newName) void LanPage::onDeviceComboxIndexChanged(int currentIndex) { //TODO 设备变更时更新设备和列表 - m_deviceName = m_deviceComboBox->currentText(); - qDebug() << "[LanPage]Current Device Changed to:" << m_deviceName; - initList(m_deviceName); + if (enableDevice.count() == m_deviceComboBox->count()) { + m_deviceName = m_deviceComboBox->currentText(); + qDebug() << "[LanPage]Current Device Changed to:" << m_deviceName; + initList(m_deviceName); + } } void LanPage::initUI() @@ -339,8 +343,14 @@ void LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget) m_listWidgetItem->setSizeHint(QSize(listWidget->width(),ITEM_HEIGHT)); listWidget->addItem(m_listWidgetItem); - m_testLanItem = new LanListItem(itemData, m_deviceName); - qDebug() << "[LanPage] addNewItem, connection: " << itemData->m_connectName << "deviceName: " << m_deviceName; + if (itemData != nullptr) { + m_testLanItem = new LanListItem(itemData, m_deviceName); + qDebug() << "[LanPage] addNewItem, connection: " << itemData->m_connectName << "deviceName: " << m_deviceName; + } + else { + m_testLanItem = new LanListItem(); + qDebug() << "[LanPage] Add nullItem!"; + } listWidget->setItemWidget(m_listWidgetItem, m_testLanItem); } @@ -353,25 +363,6 @@ void LanPage::initList(QString m_deviceName) //程序拉起,初始化显 m_activedList.clear(); m_deactivedList.clear(); - m_activeResourse->getActiveConnectionList(m_deviceName, - NetworkManager::ConnectionSettings::Wired, m_activedList); //激活列表的显示 - qDebug() << "[LanPage]init list! Active list:" << m_activedList.size() << "Deactive list:" << m_deactivedList.size(); - if (!m_activedList.isEmpty()) { - for (int i = 0; i < m_activedList.size(); i++) { - KyConnectItem *activeItemData = m_activedList.at(i); - addNewItem(activeItemData, m_activatedLanListWidget); - - m_activeMap.insert(activeItemData, m_listWidgetItem); - } - } else { - m_nullItem = new QListWidgetItem(m_activatedLanListWidget); - m_nullItem->setSizeHint(QSize(m_activatedLanListWidget->width(),ITEM_HEIGHT)); - m_activatedLanListWidget->addItem(m_nullItem); - - m_nullLanItem = new LanListItem(); - m_activatedLanListWidget->setItemWidget(m_nullItem, m_nullLanItem); - } - m_connectResourse->getConnectionList(m_deviceName, NetworkManager::ConnectionSettings::Wired, m_deactivedList); //未激活列表的显示 if (!m_deactivedList.isEmpty()) { for (int i = 0; i < m_deactivedList.size(); i++) { @@ -381,6 +372,30 @@ void LanPage::initList(QString m_deviceName) //程序拉起,初始化显 m_deactiveMap.insert(deactiveItemData, m_listWidgetItem); } } + + bool isCarriered = true; + if (!m_device->wiredDeviceCarriered(m_deviceName)) { + isCarriered = false; + } + + m_activeResourse->getActiveConnectionList(m_deviceName, NetworkManager::ConnectionSettings::Wired, m_activedList); //激活列表的显示 + qDebug() << "[LanPage]init list! Active list:" << m_activedList.size() << "Deactive list:" << m_deactivedList.size(); + if (!m_activedList.isEmpty()) { + for (int i = 0; i < m_activedList.size(); i++) { + KyConnectItem *activeItemData = m_activedList.at(i); + if (isCarriered) { + addNewItem(activeItemData, m_activatedLanListWidget); + m_activeMap.insert(activeItemData, m_listWidgetItem); + } else { + addNewItem(activeItemData, m_inactivatedLanListWidget); + m_deactiveMap.insert(activeItemData, m_listWidgetItem); + } + } + } else { + addNewItem(nullptr, m_activatedLanListWidget); //显示一个未激活任何连接的item + } + + } void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason) @@ -478,12 +493,7 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat if (m_activeMap.count() <= 0) { m_activatedLanListWidget->clear(); - m_nullItem = new QListWidgetItem(m_activatedLanListWidget); - m_nullItem->setSizeHint(QSize(m_activatedLanListWidget->width(),ITEM_HEIGHT)); - m_activatedLanListWidget->addItem(m_nullItem); - m_nullLanItem = new LanListItem(); - qDebug() << "[LanPage] Add nullItem!"; - m_activatedLanListWidget->setItemWidget(m_nullItem, m_nullLanItem); + addNewItem(nullptr, m_activatedLanListWidget); //显示一个未激活任何连接的item } } diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index d2d97f5e..487a60f1 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -38,6 +38,7 @@ private: void initUI(); void initList(QString m_deviceName); void addNewItem(KyConnectItem *itemData, QListWidget *listWidget); + void addNUllItem(QListWidget *listWidget); void initNetSwitch(); private: @@ -67,6 +68,7 @@ private: QString m_deviceName; QStringList m_devList; + QStringList enableDevice; QGSettings * m_switchGsettings = nullptr; private slots: