diff --git a/src/backend/dbus-interface/kylinwiredconnectoperation.cpp b/src/backend/dbus-interface/kylinwiredconnectoperation.cpp index 471d562b..a4146205 100644 --- a/src/backend/dbus-interface/kylinwiredconnectoperation.cpp +++ b/src/backend/dbus-interface/kylinwiredconnectoperation.cpp @@ -199,7 +199,7 @@ int KyWiredConnectOperation::closeWiredNetworkWithDevice(QString deviceName) NetworkManager::Device::Ptr wiredDevicePtr = m_networkResourceInstance->findDeviceInterface(deviceName); - if (!wiredDevicePtr->isValid()) { + if (wiredDevicePtr.isNull()) { qWarning()<<"[KyWiredConnectOperation]"<<"the network device" << deviceName <<"is not exist."; return -ENXIO; } diff --git a/src/frontend/list-items/lanlistitem.cpp b/src/frontend/list-items/lanlistitem.cpp index a06d8448..814ba804 100644 --- a/src/frontend/list-items/lanlistitem.cpp +++ b/src/frontend/list-items/lanlistitem.cpp @@ -7,9 +7,9 @@ LanListItem::LanListItem(KyConnectItem *data, QString deviceName, QWidget *parent) : m_data(data), deviceName(deviceName), ListItem(parent) //item数据传入 { - m_connectOperation = new KyWiredConnectOperation; - m_activeConnectResource = new KyActiveConnectResourse; - m_connectResource = new KyConnectResourse; + m_connectOperation = new KyWiredConnectOperation(this); + m_activeConnectResource = new KyActiveConnectResourse(this); + m_connectResource = new KyConnectResourse(this); m_data = data; m_nameLabel->setText(m_data->m_connectName); @@ -93,14 +93,12 @@ void LanListItem::onLanStatusChange(QString uuid, NetworkManager::ActiveConnecti if (state == NetworkManager::ActiveConnection::State::Activating || state == NetworkManager::ActiveConnection::State::Deactivating) { qDebug() << "[LanListItem]:Activating!Loading!" << state; m_netButton->startLoading(); - } - else { + } else { qDebug() << "[LanListItem]:Stop!" << state; m_netButton->stopLoading(); if (state == NetworkManager::ActiveConnection::State::Activated) { setIcon(true); - } - else { + } else { setIcon(false); } } diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index a43ecd8e..0038a65a 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -42,6 +42,7 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent) 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::connectionUpdate, this, &LanPage::connectionUpdateSlot); connect(m_connectResourse, &KyConnectResourse::connectionUpdate, this, &LanPage::onLanDataChange); @@ -88,11 +89,9 @@ void LanPage::onSwithGsettingsChanged(const QString &key) qDebug()<<"[LanPage] close wired device "<< m_devList.at(index); wiredOperation.closeWiredNetworkWithDevice(m_devList.at(index)); } - m_inactivatedLanListWidget->hide(); m_deviceFrame->hide(); } - m_netSwitch->setSwitchStatus(isOn); m_netSwitch->blockSignals(false); } @@ -102,24 +101,9 @@ void LanPage::onLanSwitchClicked() { qDebug()<<"[LanPage] On lan switch button clicked! Status:" <getSwitchStatus(); - KyWiredConnectOperation wiredOperation; - if (m_netSwitch->getSwitchStatus()) { - for (int index = 0; index < m_devList.size(); ++index) { - qDebug()<<"[LanPage] open wired device "<< m_devList.at(index); - wiredOperation.openWiredNetworkWithDevice(m_devList.at(index)); - } - - m_inactivatedLanListWidget->show(); m_switchGsettings->set(WIRED_SWITCH,true); - initDeviceCombox(); } else { - for (int index = 0; index < m_devList.size(); ++index) { - qDebug()<<"[LanPage] close wired device "<< m_devList.at(index); - wiredOperation.closeWiredNetworkWithDevice(m_devList.at(index)); - } - m_inactivatedLanListWidget->hide(); - m_deviceFrame->hide(); m_switchGsettings->set(WIRED_SWITCH,false); } } @@ -248,26 +232,61 @@ void LanPage::connectionUpdateSlot(QString uuid) void LanPage::initDeviceCombox() { - //TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框 - QMap enableMap; - getDeviceEnableState(0,enableMap); + //TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框;m_devList记录插入的所有设备,deviceMap记录设备状态 + QMap deviceMap; + getDeviceEnableState(0,deviceMap); + QStringList enableDevice; m_deviceComboBox->clear(); m_devList.clear(); + enableDevice.clear(); + + if (!m_switchGsettings) { + qDebug() << "[LanPage]:m_switchGsettings is null" << Q_FUNC_INFO << __LINE__; + return; + } bool isOn = m_switchGsettings->get(WIRED_SWITCH).toBool(); if (!isOn) { m_deviceFrame->hide(); } else { m_device->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, m_devList); - if (m_devList.size() == 1) { - m_deviceFrame->hide(); - m_deviceName = m_devList.at(0); - initList(m_deviceName); + for (int i=0; ishow(); + m_deviceComboBox->hide(); + m_tipsLabel->show(); + m_activatedNetFrame->hide(); + m_inactivatedNetFrame->hide(); + m_activatedNetDivider->hide(); + m_inactivatedNetDivider->hide(); return; } else { - for (int i=0; ishow(); + m_inactivatedNetFrame->show(); + m_activatedNetDivider->show(); + m_inactivatedNetDivider->show(); + if (enableDevice.count() == 1) { + m_deviceFrame->hide(); + m_deviceName = enableDevice.at(0); + initList(m_deviceName); + return; + } else { m_deviceFrame->show(); - m_deviceComboBox->addItem(m_devList.at(i)); + m_tipsLabel->hide(); + m_deviceComboBox->show(); + for (int j=0; jaddItem(enableDevice.at(j)); + } } } qDebug() << "[LanPage]Current device:" << m_deviceComboBox->currentText(); @@ -384,7 +403,6 @@ void LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget) m_testLanItem = new LanListItem(itemData, m_deviceName); qDebug() << "[LanPage] addNewItem, connection: " << itemData->m_connectName << "deviceName: " << m_deviceName; listWidget->setItemWidget(m_listWidgetItem, m_testLanItem); - qDebug() << "??????????"; } void LanPage::initList(QString m_deviceName) //程序拉起,初始化显示 @@ -516,12 +534,7 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat } } else{ -// QMap::iterator i; -// for (i = m_deactiveMap.begin(); i != m_deactiveMap.constEnd(); ++i) { -// KyConnectItem *m_item = i.key(); -// if (m_item->m_connectUuid == uuid) { -// } } if (m_activeMap.count() <= 0) { @@ -575,23 +588,25 @@ void LanPage::onLanDataChange(QString uuid) qDebug() << "[LanPage] Connection data changed but type is not Wired"; return; } - else { - qDebug() << "[LanPage] Connection data changed!"; - QMap::iterator iter; - for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.constEnd(); ++iter) { - KyConnectItem *m_item = iter.key(); - if (m_item->m_connectUuid == uuid) { - m_inactivatedLanListWidget->removeItemWidget(iter.value()); - delete iter.value(); - m_deactiveMap.erase(iter); - KyConnectItem *m_itemData = new KyConnectItem(this); - m_itemData = m_connectResourse->getConnectionItemByUuid(uuid, devName); - m_deactiveMap.insert(m_itemData, m_listWidgetItem); - addNewItem(m_itemData, m_inactivatedLanListWidget); - break; - } - } - } + qDebug() << "[LanPage] Connection data changed!"; +// KyConnectItem *m_itemData = new KyConnectItem(this); +// m_itemData = m_connectResourse->getConnectionItemByUuid(uuid, devName); +// qDebug() << "[LanPage] DATA" << m_itemData->m_connectState; + +// QMap::iterator iter; +// for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.constEnd(); ++iter) { +// KyConnectItem *m_item = iter.key(); +// if (m_item->m_connectUuid == uuid) { +// m_inactivatedLanListWidget->removeItemWidget(iter.value()); +// delete iter.value(); +// m_deactiveMap.erase(iter); +// KyConnectItem *m_itemData = new KyConnectItem(this); +// m_itemData = m_connectResourse->getConnectionItemByUuid(uuid, devName); +// m_deactiveMap.insert(m_itemData, m_listWidgetItem); +// addNewItem(m_itemData, m_inactivatedLanListWidget); +// break; +// } +// } } } @@ -599,6 +614,12 @@ void LanPage::setWiredDeviceEnable(const QString& devName, bool enable) { saveDeviceEnableState(devName, enable); initDeviceCombox(); + KyWiredConnectOperation wiredOperation; + if (enable) { + wiredOperation.openWiredNetworkWithDevice(devName); + } else { + wiredOperation.closeWiredNetworkWithDevice(devName); + } } void LanPage::activateWired(const QString& devName, const QString& connUuid) diff --git a/src/frontend/tab-pages/tabpage.cpp b/src/frontend/tab-pages/tabpage.cpp index cb4340af..0273fdb6 100644 --- a/src/frontend/tab-pages/tabpage.cpp +++ b/src/frontend/tab-pages/tabpage.cpp @@ -1,6 +1,7 @@ #include "tabpage.h" #include #include +#include TabPage::TabPage(QWidget *parent) : QWidget(parent) { @@ -39,12 +40,15 @@ void TabPage::initUI() m_deviceLayout->setContentsMargins(DEVICE_LAYOUT_MARGINS); m_deviceFrame->setLayout(m_deviceLayout); m_deviceLabel = new QLabel(m_deviceFrame); + m_deviceLabel->setText(tr("Current Device")); m_deviceComboBox = new QComboBox(m_deviceFrame); m_deviceComboBox->setFixedWidth(DEVICE_COMBOBOX_WIDTH); - m_deviceLabel->setText(tr("Current Device")); + m_tipsLabel = new QLabel(m_deviceFrame); + m_tipsLabel->setText(tr("Devices Closed!")); m_deviceLayout->addWidget(m_deviceLabel); m_deviceLayout->addStretch(); m_deviceLayout->addWidget(m_deviceComboBox); + m_deviceLayout->addWidget(m_tipsLabel); connect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &TabPage::onDeviceComboxIndexChanged); m_activatedNetFrame = new QFrame(this); @@ -167,7 +171,7 @@ void getDeviceEnableState(int type, QMap &map) { map.clear(); if (!QFile::exists(CONFIG_FILE_PATH)) { - return; + qDebug() << "CONFIG_FILE_PATH not exist"; } if (type != WIRED && type != WIRELESS) { qDebug() << "getDeviceEnableState but wrong type"; @@ -186,6 +190,9 @@ void getDeviceEnableState(int type, QMap &map) kdr->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, wiredDevList); if (!wiredDevList.isEmpty()) { for (int i = 0; i < wiredDevList.size(); ++i) { + if (!m_settings->contains(wiredDevList.at(i))) { + saveDeviceEnableState(wiredDevList.at(i),true); + } bool enable = m_settings->value(wiredDevList.at(i), true).toBool(); map.insert(wiredDevList.at(i), enable); } diff --git a/src/frontend/tab-pages/tabpage.h b/src/frontend/tab-pages/tabpage.h index 951611d3..2aee84a8 100644 --- a/src/frontend/tab-pages/tabpage.h +++ b/src/frontend/tab-pages/tabpage.h @@ -91,6 +91,7 @@ protected: QHBoxLayout * m_deviceLayout = nullptr; QLabel * m_deviceLabel = nullptr; QComboBox * m_deviceComboBox = nullptr; + QLabel * m_tipsLabel = nullptr; public slots: virtual void onDeviceComboxIndexChanged(int currentIndex) = 0;