diff --git a/src/kylinnetworkdeviceresource.cpp b/src/kylinnetworkdeviceresource.cpp index 820100ba..464915bd 100644 --- a/src/kylinnetworkdeviceresource.cpp +++ b/src/kylinnetworkdeviceresource.cpp @@ -5,6 +5,9 @@ KyNetworkDeviceResourse::KyNetworkDeviceResourse() { m_networkResourceInstance = KyNetworkResourceManager::getInstance(); + m_activeConnectUuidList.clear(); + //TODO::get uuid from settings for system reboot; + connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceAdd, this, &KyNetworkDeviceResourse::deviceAdd); connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceRemove, this, &KyNetworkDeviceResourse::deviceRemove); @@ -141,3 +144,62 @@ void KyNetworkDeviceResourse::DeviceSpeed(QString deviceName, KyConnectItem *wir } #endif + +void KyNetworkDeviceResourse::disconnectDevice() +{ + NetworkManager::Device::List networkDeviceList = + m_networkResourceInstance->getNetworkDeviceList(); + + if (networkDeviceList.isEmpty()) { + qDebug()<<"[KyNetworkDeviceResourse]"<<"the network device is empty, no need disconnect."; + return; + } + + m_activeConnectUuidList.clear(); + + for (int index = 0; index < networkDeviceList.size(); ++index) { + NetworkManager::Device::Ptr networkDevicePtr = networkDeviceList.at(index); + if (networkDevicePtr->isValid() && + NetworkManager::Device::Type::Ethernet == networkDevicePtr->type()) { + NetworkManager::ActiveConnection::Ptr activeConnectPtr = networkDevicePtr->activeConnection(); + QString activeConnectUuid = activeConnectPtr->uuid(); + if (!activeConnectUuid.isEmpty()) { + m_activeConnectUuidList<disconnectInterface(); + } + networkDevicePtr = nullptr; + } + + return; +} + +void KyNetworkDeviceResourse::setDeviceAutoConnect() +{ + NetworkManager::Device::List networkDeviceList = + m_networkResourceInstance->getNetworkDeviceList(); + + if (networkDeviceList.isEmpty()) { + qDebug()<<"[KyNetworkDeviceResourse]" << "the network device is empty,so no need set auto connect."; + return; + } + + for (int index = 0; index < m_activeConnectUuidList.size(); ++index) { + QString connectUuid = m_activeConnectUuidList.at(index); + wiredOperation.activateConnection(connectUuid); + qDebug()<<"[KyNetworkDeviceResourse]" << "active connect uuid"<< connectUuid; + } + + for (int index = 0; index < networkDeviceList.size(); ++index) { + NetworkManager::Device::Ptr networkDevicePtr = networkDeviceList.at(index); + if (networkDevicePtr->isValid() + && NetworkManager::Device::Type::Ethernet == networkDevicePtr->type()) { + networkDevicePtr->setAutoconnect(true); + } + networkDevicePtr = nullptr; + } + + return; +} + diff --git a/src/kylinnetworkdeviceresource.h b/src/kylinnetworkdeviceresource.h index 710e6838..33a76035 100644 --- a/src/kylinnetworkdeviceresource.h +++ b/src/kylinnetworkdeviceresource.h @@ -4,6 +4,7 @@ #include #include "kylinnetworkresourcemanager.h" #include "kylinconnectitem.h" +#include "kylinwiredconnectoperation.h" class KyNetworkDeviceResourse : public QObject { @@ -29,8 +30,12 @@ public: bool wiredDeviceCarriered(QString deviceName); //void DeviceSpeed(QString deviceName, KyWiredConnectItem *wiredItem); void setDeviceRefreshRate(QString deviceName, int ms); + void disconnectDevice(); + void setDeviceAutoConnect(); private: + KyWiredConnectOperation wiredOperation; KyNetworkResourceManager *m_networkResourceInstance = nullptr; + QStringList m_activeConnectUuidList; }; #endif // KYLINNETORKDEVICERESOURCE_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fd9b42d8..09d9bb42 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1412,7 +1412,10 @@ void MainWindow::onBtnLanClicked(int flag) { switch (flag) { case 0: { - qDebug()<<"On btnWired clicked! will close switch button"; + qDebug()<<"On btnWired clicked! will close switch button----------------------------"; + m_networkDevice.disconnectDevice(); + emit this->onWiredDeviceChanged(false); +#if 0 QtConcurrent::run([=]() { QString close_device_cmd = "nmcli device set " + llname + " managed false"; int res = system(close_device_cmd.toUtf8().data()); @@ -1423,10 +1426,14 @@ void MainWindow::onBtnLanClicked(int flag) qWarning()<<"Close ethernet device failed!"; } }); +#endif break; } case 1: { - qDebug()<<"On btnWired clicked! will open switch button"; + qDebug()<<"On btnWired clicked! will open switch button++++++++++++++++++++++++++++"; + m_networkDevice.setDeviceAutoConnect(); + emit this->onWiredDeviceChanged(true); +#if 0 QtConcurrent::run([=]() { QString open_device_cmd = "nmcli device set " + llname + " managed true"; int res = system(open_device_cmd.toUtf8().data()); @@ -1437,6 +1444,7 @@ void MainWindow::onBtnLanClicked(int flag) qWarning()<<"Open ethernet device failed!"; } }); +#endif break; } case 2: { diff --git a/src/mainwindow.h b/src/mainwindow.h index d22fc96a..5f8cb0ab 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -212,6 +212,8 @@ public: int m_priHei; QStringList m_wifi_list_pwd_changed; //WiFi密码以改变的WiFi列表(990/9a0自动回连失败) + KyNetworkDeviceResourse m_networkDevice; + public slots: void onPhysicalCarrierChanged(bool flag);