featrue:add function of Ethernet enable and disable.

This commit is contained in:
renpeijia 2021-08-09 11:09:43 +08:00
parent 9149b54a67
commit b207493157
4 changed files with 79 additions and 2 deletions

View File

@ -5,6 +5,9 @@ KyNetworkDeviceResourse::KyNetworkDeviceResourse()
{ {
m_networkResourceInstance = KyNetworkResourceManager::getInstance(); 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::deviceAdd, this, &KyNetworkDeviceResourse::deviceAdd);
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceRemove, this, &KyNetworkDeviceResourse::deviceRemove); connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceRemove, this, &KyNetworkDeviceResourse::deviceRemove);
@ -141,3 +144,62 @@ void KyNetworkDeviceResourse::DeviceSpeed(QString deviceName, KyConnectItem *wir
} }
#endif #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<<activeConnectUuid;
//TODO:save uuid for system reboot.
}
networkDevicePtr->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;
}

View File

@ -4,6 +4,7 @@
#include <QString> #include <QString>
#include "kylinnetworkresourcemanager.h" #include "kylinnetworkresourcemanager.h"
#include "kylinconnectitem.h" #include "kylinconnectitem.h"
#include "kylinwiredconnectoperation.h"
class KyNetworkDeviceResourse : public QObject class KyNetworkDeviceResourse : public QObject
{ {
@ -29,8 +30,12 @@ public:
bool wiredDeviceCarriered(QString deviceName); bool wiredDeviceCarriered(QString deviceName);
//void DeviceSpeed(QString deviceName, KyWiredConnectItem *wiredItem); //void DeviceSpeed(QString deviceName, KyWiredConnectItem *wiredItem);
void setDeviceRefreshRate(QString deviceName, int ms); void setDeviceRefreshRate(QString deviceName, int ms);
void disconnectDevice();
void setDeviceAutoConnect();
private: private:
KyWiredConnectOperation wiredOperation;
KyNetworkResourceManager *m_networkResourceInstance = nullptr; KyNetworkResourceManager *m_networkResourceInstance = nullptr;
QStringList m_activeConnectUuidList;
}; };
#endif // KYLINNETORKDEVICERESOURCE_H #endif // KYLINNETORKDEVICERESOURCE_H

View File

@ -1412,7 +1412,10 @@ void MainWindow::onBtnLanClicked(int flag)
{ {
switch (flag) { switch (flag) {
case 0: { 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([=]() { QtConcurrent::run([=]() {
QString close_device_cmd = "nmcli device set " + llname + " managed false"; QString close_device_cmd = "nmcli device set " + llname + " managed false";
int res = system(close_device_cmd.toUtf8().data()); int res = system(close_device_cmd.toUtf8().data());
@ -1423,10 +1426,14 @@ void MainWindow::onBtnLanClicked(int flag)
qWarning()<<"Close ethernet device failed!"; qWarning()<<"Close ethernet device failed!";
} }
}); });
#endif
break; break;
} }
case 1: { 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([=]() { QtConcurrent::run([=]() {
QString open_device_cmd = "nmcli device set " + llname + " managed true"; QString open_device_cmd = "nmcli device set " + llname + " managed true";
int res = system(open_device_cmd.toUtf8().data()); int res = system(open_device_cmd.toUtf8().data());
@ -1437,6 +1444,7 @@ void MainWindow::onBtnLanClicked(int flag)
qWarning()<<"Open ethernet device failed!"; qWarning()<<"Open ethernet device failed!";
} }
}); });
#endif
break; break;
} }
case 2: { case 2: {

View File

@ -212,6 +212,8 @@ public:
int m_priHei; int m_priHei;
QStringList m_wifi_list_pwd_changed; //WiFi密码以改变的WiFi列表990/9a0自动回连失败 QStringList m_wifi_list_pwd_changed; //WiFi密码以改变的WiFi列表990/9a0自动回连失败
KyNetworkDeviceResourse m_networkDevice;
public slots: public slots:
void onPhysicalCarrierChanged(bool flag); void onPhysicalCarrierChanged(bool flag);