featrue:add function of Ethernet enable and disable.
This commit is contained in:
parent
9149b54a67
commit
b207493157
|
@ -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<<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;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QString>
|
||||
#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
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue