From c44aa9b8d508bdd75fa48dd8843edd08963d43ee Mon Sep 17 00:00:00 2001 From: renpeijia Date: Fri, 6 Aug 2021 08:56:50 +0800 Subject: [PATCH] feature: modify the function of wired according to the design documentation. --- kylin-nm.pro | 6 +- src/kylinactiveconnectresource.cpp | 110 ++++++++++- src/kylinactiveconnectresource.h | 15 +- src/kylinbluetoothconnectitem.h | 1 + src/kylinconnectitem.cpp | 30 +++ src/kylinconnectitem.h | 29 +++ src/kylinconnectoperation.cpp | 288 +++++++++++++++++++++++++++++ src/kylinconnectoperation.h | 42 +++++ src/kylinconnectresource.cpp | 91 ++++++++- src/kylinconnectresource.h | 10 +- src/kylinnetworkdeviceresource.cpp | 60 ++++-- src/kylinnetworkdeviceresource.h | 8 +- src/kylinwiredconnectitem.cpp | 43 ----- src/kylinwiredconnectitem.h | 34 ---- src/kylinwiredconnectoperation.cpp | 210 +++------------------ src/kylinwiredconnectoperation.h | 24 +-- src/kylinwiredwidget.cpp | 16 +- src/kylinwiredwidget.h | 4 +- src/onelancform.cpp | 16 +- src/onelancform.h | 6 +- 20 files changed, 707 insertions(+), 336 deletions(-) create mode 100644 src/kylinconnectitem.cpp create mode 100644 src/kylinconnectitem.h create mode 100644 src/kylinconnectoperation.cpp create mode 100644 src/kylinconnectoperation.h delete mode 100644 src/kylinwiredconnectitem.cpp delete mode 100644 src/kylinwiredconnectitem.h diff --git a/kylin-nm.pro b/kylin-nm.pro index 83ca2eeb..474f7fdf 100644 --- a/kylin-nm.pro +++ b/kylin-nm.pro @@ -66,13 +66,14 @@ SOURCES += \ src/backthread.cpp \ src/kylinactiveconnectresource.cpp \ src/kylinbluetoothconnectitem.cpp \ + src/kylinconnectitem.cpp \ + src/kylinconnectoperation.cpp \ src/kylinconnectresource.cpp \ src/kylinconnectsetting.cpp \ src/kylinnetworkconnect.cpp \ src/kylinnetworkdeviceresource.cpp \ src/kylinnetworkresourcemanager.cpp \ src/kylinvpnconnectitem.cpp \ - src/kylinwiredconnectitem.cpp \ src/kylinwiredconnectoperation.cpp \ src/kylinwiredwidget.cpp \ src/wifi-auth-thread.cpp \ @@ -109,13 +110,14 @@ HEADERS += \ src/backthread.h \ src/kylinactiveconnectresource.h \ src/kylinbluetoothconnectitem.h \ + src/kylinconnectitem.h \ + src/kylinconnectoperation.h \ src/kylinconnectresource.h \ src/kylinconnectsetting.h \ src/kylinnetworkconnect.h \ src/kylinnetworkdeviceresource.h \ src/kylinnetworkresourcemanager.h \ src/kylinvpnconnectitem.h \ - src/kylinwiredconnectitem.h \ src/kylinwiredconnectoperation.h \ src/kylinwiredwidget.h \ src/wifi-auth-thread.h \ diff --git a/src/kylinactiveconnectresource.cpp b/src/kylinactiveconnectresource.cpp index 5dccb09b..49c38f52 100644 --- a/src/kylinactiveconnectresource.cpp +++ b/src/kylinactiveconnectresource.cpp @@ -27,6 +27,84 @@ KyActiveConnectResourse::~KyActiveConnectResourse() } } +KyConnectItem *KyActiveConnectResourse::getActiveConnectionItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr) +{ + qDebug()<<"[KyActiveConnectResourse]"<<"get active connect item"; + + if (nullptr == activeConnectPtr) { + qWarning()<<"[KyActiveConnectResourse]"<<"the active connect is empty"; + return nullptr; + } + + if (NetworkManager::ActiveConnection::State::Activated != activeConnectPtr->state()) { + qWarning()<<"[KyActiveConnectResourse]"<<"the active connect is not activated" + <<"connect name:"<connection()->name() + <<"connect state"<< activeConnectPtr->state(); + return nullptr; + } + + KyConnectItem *activeConnectItem = new KyConnectItem(); + activeConnectItem->m_connectUuid = activeConnectPtr->uuid(); + + NetworkManager::Connection::Ptr connectPtr = activeConnectPtr->connection(); + activeConnectItem->m_connectName = connectPtr->name(); + activeConnectItem->m_connectPath = connectPtr->path(); + + activeConnectItem->m_connectState = NetworkManager::ActiveConnection::State::Activated; + + return activeConnectItem; +} + +void KyActiveConnectResourse::getActiveConnectionList(QString deviceName, + NetworkManager::ConnectionSettings::ConnectionType connectionType, + QList &activeConnectItemList) +{ + qDebug()<<"[KyActiveConnectResourse]"<<"get activate connect for device" + << deviceName <<"connect type:"<getActiveConnectList(); + + if (activeConnectList.empty()) { + qWarning()<<"[KyActiveConnectResourse]"<<"the active connect list is empty"; + return; + } + + NetworkManager::ActiveConnection::Ptr activeConnectPtr = nullptr; + for (int index = 0; index < activeConnectList.size(); index++) { + activeConnectPtr = activeConnectList.at(index); + if (connectionType != activeConnectPtr->type()) { + qDebug()<<"[KyActiveConnectResourse]" <<"the connect type " << activeConnectPtr->type() + <<"connect name" << activeConnectPtr->connection()->name(); + continue; + } + + QStringList interfaces = activeConnectPtr->devices(); + for (int index = 0; index < interfaces.size(); ++index) { + QString ifaceUni = interfaces.at(index); + NetworkManager::Device:: Ptr devicePtr = + m_networkResourceInstance->findDeviceUni(ifaceUni); + if (devicePtr->interfaceName() == deviceName) { + KyConnectItem *activeConnectItem = + getActiveConnectionItem(activeConnectPtr); + if (nullptr != activeConnectItem) { + activeConnectItem->m_ifaceName = deviceName; + activeConnectItem->m_itemType = connectionType; + activeConnectItemList << activeConnectItem; + activeConnectItem->dumpInfo(); + } + + activeConnectPtr = nullptr; + break; + } + } + } + + return; +} + +#if 0 void KyActiveConnectResourse::getWiredActivateConnect(QList &wiredActiveConnectItemList) { int index = 0; @@ -98,6 +176,8 @@ KyWiredConnectItem *KyActiveConnectResourse::getWiredActiveConnectItem(NetworkMa return wiredItem; } +#endif + void KyActiveConnectResourse::getActiveConnectIp( NetworkManager::ActiveConnection::Ptr activeConnectPtr, QString &ipv4Address, @@ -132,6 +212,29 @@ void KyActiveConnectResourse::getActiveConnectIp( return; } +void KyActiveConnectResourse::getActiveConnectDns(NetworkManager::ActiveConnection::Ptr activeConnectPtr, + QList &ipv4Dns, + QList &ipv6Dns) +{ + qDebug()<<"[KyActiveConnectResourse]"<<"get active connect nameservice info"; + + NetworkManager::IpConfig ipv4Config =activeConnectPtr->ipV4Config(); + if (ipv4Config.isValid()) { + ipv4Dns = ipv4Config.nameservers(); + } else { + qWarning()<<"[KyActiveConnectResourse]"<<"ipv4 config is not valid"; + } + + NetworkManager::IpConfig ipv6Config =activeConnectPtr->ipV6Config(); + if (ipv6Config.isValid()) { + ipv6Dns = ipv6Config.nameservers(); + } else { + qWarning()<<"[KyActiveConnectResourse]"<<"ipv6 config is not valid"; + } + + return; +} + KyVpnConnectItem *KyActiveConnectResourse::getVpnActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr) { qDebug()<<"[KyActiveConnectResourse]"<<"get vpn active connect item"; @@ -237,12 +340,17 @@ KyBluetoothConnectItem *KyActiveConnectResourse::getBtActiveConnectItem(NetworkM NetworkManager::BluetoothSetting::Ptr bluetoothSetting = settingPtr->setting(NetworkManager::Setting::Bluetooth).dynamicCast(); bluetoothItem->m_deviceAddress = bluetoothSetting->bluetoothAddress(); + QByteArray btAddrArray = bluetoothSetting->bluetoothAddress(); + for (int index = 0; index < btAddrArray.size(); ++index) { + qDebug("bt address %d %s", index, btAddrArray[index]); + } + qDebug()<<"bluetooth device address"<m_deviceAddress; //wiredItem->m_itemType; return bluetoothItem; } -void KyActiveConnectResourse::getBluetoothConnect(QList &btActiveConnectItemList) +void KyActiveConnectResourse::getBtActivateConnect(QList &btActiveConnectItemList) { int index = 0; NetworkManager::ActiveConnection::List activeConnectList; diff --git a/src/kylinactiveconnectresource.h b/src/kylinactiveconnectresource.h index 15af97e4..d30f16b8 100644 --- a/src/kylinactiveconnectresource.h +++ b/src/kylinactiveconnectresource.h @@ -3,7 +3,7 @@ #include #include "kylinnetworkresourcemanager.h" -#include "kylinwiredconnectitem.h" +#include "kylinconnectitem.h" #include "kylinnetworkdeviceresource.h" #include "kylinvpnconnectitem.h" #include "kylinbluetoothconnectitem.h" @@ -16,15 +16,22 @@ public: ~KyActiveConnectResourse(); public: - void getWiredActivateConnect(QList &wiredActiveConnectItemList); + void getActiveConnectionList(QString DeviceName, + NetworkManager::ConnectionSettings::ConnectionType connectionType, + QList &connectItemList); + //void getWiredActivateConnect(QList &wiredActiveConnectItemList); void getVpnActivateConnect(QList &vpnActiveConnectItemList); - void getBluetoothConnect(QList &btActiveConnectItemList); + void getBtActivateConnect(QList &btActiveConnectItemList); private: + KyConnectItem *getActiveConnectionItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr); void getActiveConnectIp(NetworkManager::ActiveConnection::Ptr activeConnectPtr, QString &ipv4Address, QString &ipv6Address); - KyWiredConnectItem *getWiredActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr); + void getActiveConnectDns(NetworkManager::ActiveConnection::Ptr activeConnectPtr, + QList &ipv4Dns, + QList &ipv6Dns); + // KyWiredConnectItem *getWiredActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr); KyVpnConnectItem *getVpnActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr); KyBluetoothConnectItem *getBtActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr); diff --git a/src/kylinbluetoothconnectitem.h b/src/kylinbluetoothconnectitem.h index 5221a5ec..cbf49210 100644 --- a/src/kylinbluetoothconnectitem.h +++ b/src/kylinbluetoothconnectitem.h @@ -4,6 +4,7 @@ #include #include #include +#include class KyBluetoothConnectItem : public QObject { diff --git a/src/kylinconnectitem.cpp b/src/kylinconnectitem.cpp new file mode 100644 index 00000000..5bc7857b --- /dev/null +++ b/src/kylinconnectitem.cpp @@ -0,0 +1,30 @@ + +#include "kylinconnectitem.h" + +KyConnectItem::KyConnectItem(QObject *parent) : QObject(parent) +{ + m_connectName = ""; + m_connectUuid = ""; + m_connectPath = ""; + + m_ifaceName = ""; + + m_connectState = NetworkManager::ActiveConnection::State::Unknown; //deactive、activing and actived + m_itemType = NetworkManager::ConnectionSettings::ConnectionType::Unknown; +} + +KyConnectItem::~KyConnectItem() +{ + +} + +void KyConnectItem::dumpInfo() +{ + qDebug()<<"wired connection item info:"; + qDebug()<<"connect name:"< +#include "kylinnetworkresourcemanager.h" + +class KyConnectItem : public QObject +{ + Q_OBJECT +public: + explicit KyConnectItem(QObject *parent = nullptr); + ~KyConnectItem(); + +public: + void dumpInfo(); + +public: + QString m_connectName; + QString m_connectUuid; + QString m_connectPath; + + QString m_ifaceName; + + NetworkManager::ActiveConnection::State m_connectState; //deactive、activing and actived + + NetworkManager::ConnectionSettings::ConnectionType m_itemType; //wired or wireless vpn etc +}; + +#endif // KYLINWIREDCONNECTITEM_H diff --git a/src/kylinconnectoperation.cpp b/src/kylinconnectoperation.cpp new file mode 100644 index 00000000..9859b228 --- /dev/null +++ b/src/kylinconnectoperation.cpp @@ -0,0 +1,288 @@ +/* + * Copyright (C) 2020 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see +#include +#include +#include +#include + +KyConnectOperation::KyConnectOperation() +{ + m_networkResourceInstance = KyNetworkResourceManager::getInstance(); +} + +KyConnectOperation::~KyConnectOperation() +{ + m_networkResourceInstance = nullptr; +} + +void KyConnectOperation::ipv4SettingSet( + NetworkManager::Ipv4Setting::Ptr &ipv4Setting, + const KyConnectSetting &connectSettingsInfo) +{ + ipv4Setting->setInitialized(true); + + if (CONFIG_IP_DHCP == connectSettingsInfo.m_ipv4ConfigIpType) { + ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Automatic); + return; + } else { + ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Manual); + } + + if (!connectSettingsInfo.m_ipv4Dns.empty()) { + ipv4Setting->setDns(connectSettingsInfo.m_ipv4Dns); + } + + if (!connectSettingsInfo.m_ipv4Address.empty()) { + ipv4Setting->setAddresses(connectSettingsInfo.m_ipv4Address); + } + + return; +} +void KyConnectOperation::ipv6SettingSet( + NetworkManager::Ipv6Setting::Ptr &ipv6Setting, + const KyConnectSetting &connectSettingsInfo) +{ + ipv6Setting->setInitialized(true); + + if (CONFIG_IP_DHCP == connectSettingsInfo.m_ipv6ConfigIpType) { + ipv6Setting->setMethod(NetworkManager::Ipv6Setting::Automatic); + return; + } + + ipv6Setting->setMethod(NetworkManager::Ipv6Setting::Manual); + if (!connectSettingsInfo.m_ipv6Dns.empty()) { + ipv6Setting->setDns(connectSettingsInfo.m_ipv6Dns); + } + + if (!connectSettingsInfo.m_ipv6Address.empty()) { + ipv6Setting->setAddresses(connectSettingsInfo.m_ipv6Address); + } + + return ; +} + +void KyConnectOperation::connectSettingSet( + NetworkManager::ConnectionSettings::Ptr connectionSettings, + const KyConnectSetting &connectSettingsInfo) +{ + connectionSettings->setId(connectSettingsInfo.m_connectName); + connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); + connectionSettings->setAutoconnect(true); + connectionSettings->setAutoconnectPriority(0); + if (!connectSettingsInfo.m_ifaceName.isEmpty()) { + connectionSettings->setInterfaceName(connectSettingsInfo.m_ifaceName); + } + + return; +} + +void KyConnectOperation::createConnect(KyConnectSetting &connectSettingsInfo) +{ + qDebug()<<"create connect"; + connectSettingsInfo.dumpInfo(); + NetworkManager::ConnectionSettings::Ptr wiredConnectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wired)); + connectSettingSet(wiredConnectionSettings, connectSettingsInfo); + + NetworkManager::Ipv4Setting::Ptr ipv4Setting = wiredConnectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast(); + ipv4SettingSet(ipv4Setting, connectSettingsInfo); + + NetworkManager::Ipv6Setting::Ptr ipv6Setting = wiredConnectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast(); + ipv6SettingSet(ipv6Setting, connectSettingsInfo); + + NetworkManager::WiredSetting::Ptr wiredSetting = wiredConnectionSettings->setting(NetworkManager::Setting::Wired).dynamicCast(); + wiredSetting->setInitialized(true); + + QDBusPendingCallWatcher * watcher; + watcher = new QDBusPendingCallWatcher{NetworkManager::addConnection(wiredConnectionSettings->toMap()), this}; + connect(watcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher * watcher) { + if (watcher->isError() || !watcher->isValid()) { + QString errorMessage = tr("create wired connection failed: ") + watcher->error().message(); + qWarning()<createConnectionError(errorMessage); + } else { + qDebug()<<"create wired connect complete"; + } + watcher->deleteLater(); + }); + + return; +} + +void KyConnectOperation::updateConnect(const QString &connectUuid, const KyConnectSetting &connectSettingsInfo) +{ + qDebug()<<"update connect"<settings(); + connectionSettings->setId(connectSettingsInfo.m_connectName); + connectionSettings->setInterfaceName(connectSettingsInfo.m_ifaceName); + + NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast(); + ipv4SettingSet(ipv4Setting, connectSettingsInfo); + + NetworkManager::Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast(); + ipv6SettingSet(ipv6Setting, connectSettingsInfo); + + NetworkManager::WiredSetting::Ptr wiredSetting = connectionSettings->setting(NetworkManager::Setting::Wired).dynamicCast(); + wiredSetting->setInitialized(true); + + connectPtr->update(connectionSettings->toMap()); + + return ; +} + +void KyConnectOperation::deleteConnect(const QString &connectUuid) +{ + qDebug()<<"delete connect uuid " << connectUuid; + + NetworkManager::Connection::Ptr connectPtr = + NetworkManager::findConnectionByUuid(connectUuid); + if (nullptr == connectPtr) { + QString errorMessage = tr("it can not find connection") + connectUuid; + qWarning()<remove(); + + return ; +} + +void KyConnectOperation::activateConnection(const QString connectUuid) +{ + QString connectPath = ""; + QString deviceIdentifier = ""; + QString connectName = ""; + QString deviceName = ""; + QString specificObject = ""; + NetworkManager::Connection::Ptr connectPtr = nullptr; + + qDebug()<<"it will activate connect"<settings()->connectionType()) { + QString errorMessage = tr("the connect type is") + + connectPtr->settings()->connectionType() + + tr(", but it is not wired"); + qWarning()<path(); + connectName = connectPtr->name(); + deviceName = connectPtr->settings()->interfaceName(); + + for (auto const & dev : m_networkResourceInstance->m_devices) { + for (auto const & dev_conn : dev->availableConnections()) { + if (dev_conn == connectPtr) { + deviceIdentifier = dev->uni(); + deviceName = dev->interfaceName(); + break; + } + } + } + + if (deviceIdentifier.isEmpty() && !deviceName.isEmpty()) { + auto dev = m_networkResourceInstance->findDeviceInterface(deviceName); + if (!dev.isNull()) { + deviceIdentifier = dev->uni(); + } + } + + if (deviceIdentifier.isEmpty()) { + QString errorMessage = tr("device Identifier is empty, its name") + deviceName; + qWarning() << errorMessage; + Q_EMIT activateConnectionError(errorMessage); + return ; + } + + qDebug() <<"active wired connect: path "<< connectPath + << "device identify " << deviceIdentifier + << "connect name " << connectName + << "device name" << deviceName + << "specific parameter"<< specificObject; + + QDBusPendingCallWatcher * watcher; + watcher = new QDBusPendingCallWatcher{NetworkManager::activateConnection(connectPath, deviceIdentifier, specificObject), this}; + connect(watcher, &QDBusPendingCallWatcher::finished, [this, connectName, deviceName] (QDBusPendingCallWatcher * watcher) { + if (watcher->isError() || !watcher->isValid()) { + QString errorMessage = tr("activate connection failed: ") + watcher->error().message(); + qWarning()<activateConnectionError(errorMessage); + } else { + qWarning()<<"active wired connect complete."; + } + + watcher->deleteLater(); + }); + + return ; +} + +void KyConnectOperation::deactivateConnection(const QString activeConnectName, const QString &activeConnectUuid) +{ + NetworkManager::ActiveConnection::Ptr activateConnectPtr = nullptr; + + qDebug()<<"deactivetate connect name"<getActiveConnect(activeConnectUuid); + if (nullptr == activateConnectPtr) { + QString errorMessage = tr("it can not find the activate connect") + + activeConnectName + tr("uuid") + activeConnectUuid; + qWarning()<path(); + QDBusPendingReply<> reply = NetworkManager::deactivateConnection(activateConnectPtr->path()); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, &QDBusPendingCallWatcher::finished, [this, activateConnectPtr] (QDBusPendingCallWatcher * watcher) { + if (watcher->isError() || !watcher->isValid()) { + QString errorMessage = tr("deactivation of connection") + + activateConnectPtr->connection()->name() + tr("failed:") + + watcher->error().message(); + + qWarning()<deactivateConnectionError(errorMessage); + } else { + qWarning() << "deactive connect operation finished" << activateConnectPtr->connection()->name(); + } + watcher->deleteLater(); + }); + + return; +} diff --git a/src/kylinconnectoperation.h b/src/kylinconnectoperation.h new file mode 100644 index 00000000..b2596c3a --- /dev/null +++ b/src/kylinconnectoperation.h @@ -0,0 +1,42 @@ +#ifndef KYLINCONNECTOPERATION_H +#define KYLINCONNECTOPERATION_H + +#include "kylinnetworkresourcemanager.h" +#include "kylinconnectsetting.h" + +class KyConnectOperation : public QObject +{ + Q_OBJECT +public: + explicit KyConnectOperation(); + ~KyConnectOperation(); + +public: + void createConnect(KyConnectSetting &connectSettingsInfo); + void updateConnect(const QString &connectUuid, const KyConnectSetting &connectSettingsInfo); + void deleteConnect(const QString &connectUuid); + void activateConnection(const QString connectUuid); + void deactivateConnection(const QString activeConnectName, const QString &activeConnectUuid); + +private: + void connectSettingSet( + NetworkManager::ConnectionSettings::Ptr connectionSettings, + const KyConnectSetting &connectSettingsInfo); + void ipv4SettingSet(NetworkManager::Ipv4Setting::Ptr &ipv4Setting, + const KyConnectSetting &connectSettingsInfo); + void ipv6SettingSet(NetworkManager::Ipv6Setting::Ptr &ipv6Setting, + const KyConnectSetting &connectSettingsInfo); + inline void errorProcess(QString errorMessage); + +signals: + void createConnectionError(QString errorMessage); + void updateConnectionError(QString errorMessage); + void deleteConnectionError(QString errorMessage); + void activateConnectionError(QString errorMessage); + void deactivateConnectionError(QString errorMessage); + +private: + KyNetworkResourceManager *m_networkResourceInstance = nullptr; +}; + +#endif // KYLINCONNECTOPERATION_H diff --git a/src/kylinconnectresource.cpp b/src/kylinconnectresource.cpp index e4de891f..c6389bf2 100644 --- a/src/kylinconnectresource.cpp +++ b/src/kylinconnectresource.cpp @@ -25,6 +25,79 @@ KyConnectResourse::~KyConnectResourse() } } +KyConnectItem *KyConnectResourse::getConnectionItem(NetworkManager::Connection::Ptr connectPtr) +{ + if (nullptr == connectPtr) { + qWarning()<<"[KyConnectResourse]"<<"the connect is empty"; + return nullptr; + } + + KyConnectItem *connectionItem = new KyConnectItem(); + connectionItem->m_connectName = connectPtr->name(); + connectionItem->m_connectUuid = connectPtr->uuid(); + connectionItem->m_connectPath = connectPtr->path(); + + NetworkManager::ConnectionSettings::Ptr settingPtr = connectPtr->settings(); + connectionItem->m_ifaceName = settingPtr->interfaceName(); + + connectionItem->m_connectState = NetworkManager::ActiveConnection::State::Deactivated; + + return connectionItem; +} + +void KyConnectResourse::getConnectionList(QString DeviceName, + NetworkManager::ConnectionSettings::ConnectionType connectionType, + QList &connectItemList) +{ + NetworkManager::Connection::List connectList; + + qDebug()<<"[KyConnectResourse]"<<"get connections item, device" + <getConnectList(); + + if (connectList.empty()) { + qWarning()<<"[KyConnectResourse]"<<"get connection failed, the connect list is empty"; + return; + } + + NetworkManager::Connection::Ptr connectPtr = nullptr; + for (int index = 0; index < connectList.size(); index++) { + connectPtr = connectList.at(index); + if (connectionType != connectPtr->settings()->connectionType()) { + qDebug()<<"[KyConnectResourse]"<<"connect name:" << connectPtr->name() + <<"connect type:"<settings()->connectionType(); + continue; + } + + QString connectInterface = connectPtr->settings()->interfaceName(); + if (!connectInterface.isEmpty() + && DeviceName != connectInterface) { + qDebug()<<"[KyConnectResourse]" << "connect name:"<< connectPtr->name() + << "connect device name" << connectInterface; + continue; + } + + if (m_networkResourceInstance->isActiveConnection(connectPtr->uuid())) { + qDebug()<<"[KyConnectResourse]"<name()<<"is active connection"; + continue; + } + + KyConnectItem *connectItem = getConnectionItem(connectPtr); + if (nullptr != connectItem) { + connectItem->m_itemType = connectionType; + connectItemList << connectItem; + connectItem->dumpInfo(); + } + + connectPtr = nullptr; + } + + return; +} + +#if 0 void KyConnectResourse::getWiredConnections(QList &wiredConnectItemList) { int index = 0; @@ -93,6 +166,8 @@ KyWiredConnectItem *KyConnectResourse::getWiredConnectItem(NetworkManager::Conne return wiredItem; } +#endif + void KyConnectResourse::getConnectIp( NetworkManager::ConnectionSettings::Ptr settingPtr, QString &ipv4Address, @@ -113,7 +188,8 @@ void KyConnectResourse::getConnectIp( } NetworkManager::Ipv6Setting::Ptr ipv6Setting = settingPtr->setting(NetworkManager::Setting::Ipv6).dynamicCast(); - if (NetworkManager::Ipv4Setting::Manual == ipv6Setting->method()) { + if (nullptr !=ipv6Setting + && NetworkManager::Ipv4Setting::Manual == ipv6Setting->method()) { QList ipv6AddressList = ipv6Setting->addresses(); NetworkManager::IpAddress settingIpv6Address = ipv6AddressList.at(0); if (settingIpv6Address.isValid()) { @@ -166,14 +242,14 @@ void KyConnectResourse::getIpv6ConnectSetting( void KyConnectResourse::getConnectionSetting(QString connectUuid, KyConnectSetting &connectSetting) { - qDebug()<< connectUuid <<"get connect setting info"; + qDebug() <<"[KyConnectResourse]" << connectUuid <<"get connect setting info, connect uuid"; NetworkManager::Connection::Ptr connectPtr = m_networkResourceInstance->getConnect(connectUuid); if (nullptr == connectPtr || !connectPtr->isValid()) { - qWarning() << "it can not find valid connection" << connectUuid; + qWarning() <<"[KyConnectResourse]" << "it can not find valid connection" << connectUuid; return; } @@ -294,7 +370,14 @@ KyBluetoothConnectItem *KyConnectResourse::getBluetoothConnectItem(NetworkManage NetworkManager::BluetoothSetting::Ptr bluetoothSetting = settingPtr->setting(NetworkManager::Setting::Bluetooth).dynamicCast(); bluetoothItem->m_deviceAddress = bluetoothSetting->bluetoothAddress(); - qDebug()<<"bluetooth device address:"<m_deviceAddress; + QByteArray btAddrArray = bluetoothSetting->bluetoothAddress(); + for (int index = 0; index < btAddrArray.size(); ++index) { + qDebug("bt address %d %s", index, btAddrArray[index]); + } + // qDebug()<<"bt address 0:"<< btAddrArray[0]; + // qDebug()<<"bt address 1:"<< btAddrArray[1]; + // qDebug()<<"array size:"<m_deviceAddress.toInt(nullptr, 16); return bluetoothItem; } diff --git a/src/kylinconnectresource.h b/src/kylinconnectresource.h index 521cc9f7..54ef80ef 100644 --- a/src/kylinconnectresource.h +++ b/src/kylinconnectresource.h @@ -3,7 +3,7 @@ #include #include "kylinnetworkresourcemanager.h" -#include "kylinwiredconnectitem.h" +#include "kylinconnectitem.h" #include "kylinvpnconnectitem.h" #include "kylinbluetoothconnectitem.h" #include "kylinnetworkdeviceresource.h" @@ -17,16 +17,20 @@ public: ~KyConnectResourse(); public: - void getWiredConnections(QList &wiredConnectItemList); + void getConnectionList(QString DeviceName, + NetworkManager::ConnectionSettings::ConnectionType connectionType, + QList &connectItemList); + // void getWiredConnections(QList &wiredConnectItemList); void getVpnConnections(QList &vpnConnectItemList); void getBluetoothConnections(QList &bluetoothConnectItemList); void getConnectionSetting(QString connectUuid, KyConnectSetting &connectSetting); private: + KyConnectItem *getConnectionItem(NetworkManager::Connection::Ptr connectPtr); void getConnectIp(NetworkManager::ConnectionSettings::Ptr settingPtr, QString &ipv4Address, QString &ipv6Address); - KyWiredConnectItem *getWiredConnectItem(NetworkManager::Connection::Ptr connectPtr); +// KyWiredConnectItem *getWiredConnectItem(NetworkManager::Connection::Ptr connectPtr); void getVpnConnectData(NetworkManager::ConnectionSettings::Ptr settingPtr, KyVpnConnectItem *vpnItem); diff --git a/src/kylinnetworkdeviceresource.cpp b/src/kylinnetworkdeviceresource.cpp index 7ae89d22..bb25a1d4 100644 --- a/src/kylinnetworkdeviceresource.cpp +++ b/src/kylinnetworkdeviceresource.cpp @@ -19,42 +19,61 @@ KyNetworkDeviceResourse::~KyNetworkDeviceResourse() m_networkResourceInstance = nullptr; } -void KyNetworkDeviceResourse::getWiredDevices(QStringList &wiredDeviceList) +void KyNetworkDeviceResourse::getNetworkDevices(QStringList &networkDeviceList) { qDebug()<<"[KyNetworkDeviceResourse]"<<"get device list"; - NetworkManager::Device::List networkDeviceList + NetworkManager::Device::List deviceList = m_networkResourceInstance->getNetworkDeviceList(); - if (networkDeviceList.isEmpty()) { + if (deviceList.isEmpty()) { qDebug()<<"[KyNetworkDeviceResourse]"<<"network device is not exist."; return; } NetworkManager::Device::Ptr devicePtr = nullptr; - for (int index = 0; index < networkDeviceList.size(); ++index) { - devicePtr = networkDeviceList.at(index); - if (NetworkManager::Device::Type::Ethernet == devicePtr->type()) { - wiredDeviceList<interfaceName(); - } + for (int index = 0; index < deviceList.size(); ++index) { + devicePtr = deviceList.at(index); + networkDeviceList<interfaceName(); } return; } -void KyNetworkDeviceResourse::getWiredHardwareInfo(QString ifaceName, KyWiredConnectItem *wiredItem) +void KyNetworkDeviceResourse::getHardwareInfo(QString ifaceName, QString &hardAddress, int &bandWith) { - qDebug()<<"[KyNetworkDeviceResourse]"<<"get wired hardware info"<getNetworkDevice(ifaceName); - if (nullptr != connectDevice && connectDevice->isValid() - && NetworkManager::Device::Ethernet == connectDevice->type()) { - NetworkManager::WiredDevice *wiredDevicePtr = - qobject_cast(connectDevice.data()); - wiredItem->m_hardAddress = wiredDevicePtr->hardwareAddress(); - wiredItem->m_bandWith = wiredDevicePtr->bitRate(); - } else { - qWarning()<<"[KyNetworkDeviceResourse]"<<"getwiredhardwareinfo failed, the device" << ifaceName << "is not existed"; + if (nullptr == connectDevice || !connectDevice->isValid()) { + qWarning()<<"[KyNetworkDeviceResourse]"<<"get hardware info failed, the device" << ifaceName << "is not existed"; + } + + switch (connectDevice->type()) { + case NetworkManager::Device::Ethernet: + { + NetworkManager::WiredDevice *wiredDevicePtr = + qobject_cast(connectDevice.data()); + hardAddress = wiredDevicePtr->hardwareAddress(); + bandWith = wiredDevicePtr->bitRate(); + break; + } + case NetworkManager::Device::Wifi: + { + NetworkManager::WirelessDevice *wirelessDevicePtr = + qobject_cast(connectDevice.data()); + hardAddress = wirelessDevicePtr->hardwareAddress(); + bandWith = wirelessDevicePtr->bitRate(); + break; + } + default: + { + hardAddress = ""; + bandWith = 0; + qWarning()<<"the network device type is undefined"<type(); + break; + } } return; @@ -105,7 +124,8 @@ void KyNetworkDeviceResourse::setDeviceRefreshRate(QString deviceName, int ms) return; } -void KyNetworkDeviceResourse::DeviceSpeed(QString deviceName, KyWiredConnectItem *wiredItem) +#if 0 +void KyNetworkDeviceResourse::DeviceSpeed(QString deviceName, KyConnectItem *wiredItem) { // qDebug()<<"[KyNetworkDeviceResourse]"< #include "kylinnetworkresourcemanager.h" -#include "kylinwiredconnectitem.h" +#include "kylinconnectitem.h" class KyNetworkDeviceResourse : public QObject { @@ -23,11 +23,11 @@ signals: void deviceMacAddressChanaged(QString deviceName, const QString &hwAddress); public: - void getWiredDevices(QStringList &wiredDeviceList); - void getWiredHardwareInfo(QString ifaceName, KyWiredConnectItem *wiredItem); + void getNetworkDevices(QStringList &networkDeviceList); + void getHardwareInfo(QString ifaceName, QString &hardAddress, int &bandWith); NetworkManager::Device::State getDeviceState(QString deviceName); bool wiredDeviceCarriered(QString deviceName); - void DeviceSpeed(QString deviceName, KyWiredConnectItem *wiredItem); + //void DeviceSpeed(QString deviceName, KyWiredConnectItem *wiredItem); void setDeviceRefreshRate(QString deviceName, int ms); private: diff --git a/src/kylinwiredconnectitem.cpp b/src/kylinwiredconnectitem.cpp deleted file mode 100644 index 60d94d4b..00000000 --- a/src/kylinwiredconnectitem.cpp +++ /dev/null @@ -1,43 +0,0 @@ - -#include "kylinwiredconnectitem.h" - -KyWiredConnectItem::KyWiredConnectItem(QObject *parent):QObject(parent) -{ - m_connectName = ""; - m_connectUuid = ""; - m_ifaceName = ""; - - m_ipv4 = ""; - m_ipv6 = ""; - m_hardAddress = ""; - - m_bandWith = ""; - m_upSpeed = 0; - m_downSpeed = 0; - - m_state = NetworkManager::ActiveConnection::State::Unknown; //deactive、activing and actived - m_itemType = ""; //activeconnect or connect -} - -KyWiredConnectItem::~KyWiredConnectItem() -{ - -} - -void KyWiredConnectItem::dumpInfo() -{ - qDebug()<<"wired connection item info:"; - qDebug()<<"connect name:"< -#include "kylinnetworkresourcemanager.h" - -class KyWiredConnectItem : public QObject -{ - Q_OBJECT -public: - explicit KyWiredConnectItem(QObject *parent = nullptr); - ~KyWiredConnectItem(); - -public: - void dumpInfo(); - -public: - QString m_connectName; - QString m_connectUuid; - QString m_ifaceName; - - QString m_ipv4; - QString m_ipv6; - QString m_hardAddress; - - QString m_bandWith; - qulonglong m_upSpeed; - qulonglong m_downSpeed; - - NetworkManager::ActiveConnection::State m_state; //deactive、activing and actived - QString m_itemType; //activeconnect or connect -}; - -#endif // KYLINWIREDCONNECTITEM_H diff --git a/src/kylinwiredconnectoperation.cpp b/src/kylinwiredconnectoperation.cpp index 80371be6..9d1112fd 100644 --- a/src/kylinwiredconnectoperation.cpp +++ b/src/kylinwiredconnectoperation.cpp @@ -26,100 +26,18 @@ KyWiredConnectOperation::KyWiredConnectOperation() { - m_networkResourceInstance = KyNetworkResourceManager::getInstance(); } KyWiredConnectOperation::~KyWiredConnectOperation() { - m_networkResourceInstance = nullptr; -} - -void KyWiredConnectOperation::ipv4SettingSet( - NetworkManager::Ipv4Setting::Ptr &ipv4Setting, - const KyConnectSetting &connectSettingsInfo) -{ - ipv4Setting->setInitialized(true); - - if (CONFIG_IP_DHCP == connectSettingsInfo.m_ipv4ConfigIpType) { - ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Automatic); - return; - } else { - ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Manual); - } - - if (!connectSettingsInfo.m_ipv4Dns.empty()) { - ipv4Setting->setDns(connectSettingsInfo.m_ipv4Dns); - } - - if (!connectSettingsInfo.m_ipv4Address.empty()) { - ipv4Setting->setAddresses(connectSettingsInfo.m_ipv4Address); - } - - return; -} -void KyWiredConnectOperation::ipv6SettingSet( - NetworkManager::Ipv6Setting::Ptr &ipv6Setting, - const KyConnectSetting &connectSettingsInfo) -{ - ipv6Setting->setInitialized(true); - - if (CONFIG_IP_DHCP == connectSettingsInfo.m_ipv6ConfigIpType) { - ipv6Setting->setMethod(NetworkManager::Ipv6Setting::Automatic); - return; - } - - ipv6Setting->setMethod(NetworkManager::Ipv6Setting::Manual); - if (!connectSettingsInfo.m_ipv6Dns.empty()) { - ipv6Setting->setDns(connectSettingsInfo.m_ipv6Dns); - } - - if (!connectSettingsInfo.m_ipv6Address.empty()) { - ipv6Setting->setAddresses(connectSettingsInfo.m_ipv6Address); - } - - return ; -} - -void KyWiredConnectOperation::connectSettingSet( - NetworkManager::ConnectionSettings::Ptr connectionSettings, - const KyConnectSetting &connectSettingsInfo) -{ - connectionSettings->setId(connectSettingsInfo.m_connectName); - connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); - connectionSettings->setAutoconnect(true); - connectionSettings->setAutoconnectPriority(0); - connectionSettings->setInterfaceName(connectSettingsInfo.m_ifaceName); - return; } void KyWiredConnectOperation::createWiredConnect(KyConnectSetting &connectSettingsInfo) { qDebug()<<"create wired connect"; connectSettingsInfo.dumpInfo(); - NetworkManager::ConnectionSettings::Ptr wiredConnectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wired)); - connectSettingSet(wiredConnectionSettings, connectSettingsInfo); - NetworkManager::Ipv4Setting::Ptr ipv4Setting = wiredConnectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast(); - ipv4SettingSet(ipv4Setting, connectSettingsInfo); - - NetworkManager::Ipv6Setting::Ptr ipv6Setting = wiredConnectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast(); - ipv6SettingSet(ipv6Setting, connectSettingsInfo); - - NetworkManager::WiredSetting::Ptr wiredSetting = wiredConnectionSettings->setting(NetworkManager::Setting::Wired).dynamicCast(); - wiredSetting->setInitialized(true); - - QDBusPendingCallWatcher * watcher; - watcher = new QDBusPendingCallWatcher{NetworkManager::addConnection(wiredConnectionSettings->toMap()), this}; - connect(watcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher * watcher) { - if (watcher->isError() || !watcher->isValid()) { - QString errorMessage = tr("create wired connection failed: ") + watcher->error().message(); - qWarning()<createConnectionError(errorMessage); - } else { - qDebug()<<"create wired connect complete"; - } - watcher->deleteLater(); - }); + createConnect(connectSettingsInfo); return; } @@ -127,29 +45,8 @@ void KyWiredConnectOperation::createWiredConnect(KyConnectSetting &connectSettin void KyWiredConnectOperation::updateWiredConnect(const QString &connectUuid, const KyConnectSetting &connectSettingsInfo) { qDebug()<<"update connect"<settings(); - connectionSettings->setId(connectSettingsInfo.m_connectName); - connectionSettings->setInterfaceName(connectSettingsInfo.m_ifaceName); - - NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast(); - ipv4SettingSet(ipv4Setting, connectSettingsInfo); - - NetworkManager::Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast(); - ipv6SettingSet(ipv6Setting, connectSettingsInfo); - - NetworkManager::WiredSetting::Ptr wiredSetting = connectionSettings->setting(NetworkManager::Setting::Wired).dynamicCast(); - wiredSetting->setInitialized(true); - - connectPtr->update(connectionSettings->toMap()); + updateConnect(connectUuid, connectSettingsInfo); return ; } @@ -158,30 +55,36 @@ void KyWiredConnectOperation::deleteWiredConnect(const QString &connectUuid) { qDebug()<<"delete wired connect uuid " << connectUuid; - NetworkManager::Connection::Ptr connectPtr = - NetworkManager::findConnectionByUuid(connectUuid); - if (nullptr == connectPtr) { - QString errorMessage = tr("it can not find connection") + connectUuid; - qWarning()<remove(); + deleteConnect(connectUuid); return ; } void KyWiredConnectOperation::activateWiredConnection(const QString connectUuid) +{ + activateConnection(connectUuid); + return ; +} + +void KyWiredConnectOperation::deactivateWiredConnection(const QString activeConnectName, const QString &activeConnectUuid) +{ + qDebug()<<"deactivetate connect name"<settings()->connectionType()) { + if (NetworkManager::ConnectionSettings::Vpn != connectPtr->settings()->connectionType()) { QString errorMessage = tr("the connect type is") + connectPtr->settings()->connectionType() - + tr(", but it is not wired"); + + tr(", but it is not vpn"); qWarning()<path(); connectName = connectPtr->name(); - deviceName = connectPtr->settings()->interfaceName(); - - for (auto const & dev : m_networkResourceInstance->m_devices) { - for (auto const & dev_conn : dev->availableConnections()) { - if (dev_conn == connectPtr) { - deviceIdentifier = dev->uni(); - deviceName = dev->interfaceName(); - break; - } - } - } - - if (deviceIdentifier.isEmpty() && !deviceName.isEmpty()) { - auto dev = m_networkResourceInstance->findDeviceInterface(deviceName); - if (!dev.isNull()) { - deviceIdentifier = dev->uni(); - } - } - - if (deviceIdentifier.isEmpty()) { - QString errorMessage = tr("device Identifier is empty, its name") + deviceName; - qWarning() << errorMessage; - Q_EMIT activateConnectionError(errorMessage); - return ; - } + //deviceName = connectPtr->settings()->interfaceName(); + specificObject = deviceIdentifier = QStringLiteral("/"); qDebug() <<"active wired connect: path "<< connectPath << "device identify " << deviceIdentifier << "connect name " << connectName - << "device name" << deviceName + // << "device name" << deviceName << "specific parameter"<< specificObject; QDBusPendingCallWatcher * watcher; watcher = new QDBusPendingCallWatcher{NetworkManager::activateConnection(connectPath, deviceIdentifier, specificObject), this}; - connect(watcher, &QDBusPendingCallWatcher::finished, [this, connectName, deviceName] (QDBusPendingCallWatcher * watcher) { + connect(watcher, &QDBusPendingCallWatcher::finished, [this, connectName] (QDBusPendingCallWatcher * watcher) { if (watcher->isError() || !watcher->isValid()) { - QString errorMessage = tr("activate connection failed: ") + watcher->error().message(); + QString errorMessage = tr("activate vpn connection failed: ") + watcher->error().message(); qWarning()<activateConnectionError(errorMessage); } else { - qWarning()<<"active wired connect complete."; + qWarning()<<"active vpn connect complete."; } watcher->deleteLater(); }); - return ; -} - -void KyWiredConnectOperation::deactivateWiredConnection(const QString activeConnectName, const QString &activeConnectUuid) -{ - NetworkManager::ActiveConnection::Ptr activateConnectPtr = nullptr; - - qDebug()<<"deactivetate connect name"<getActiveConnect(activeConnectUuid); - if (nullptr == activateConnectPtr) { - QString errorMessage = tr("it can not find the activate connect") - + activeConnectName + tr("uuid") + activeConnectUuid; - qWarning()<path(); - QDBusPendingReply<> reply = NetworkManager::deactivateConnection(activateConnectPtr->path()); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); - connect(watcher, &QDBusPendingCallWatcher::finished, [this, activateConnectPtr] (QDBusPendingCallWatcher * watcher) { - if (watcher->isError() || !watcher->isValid()) { - QString errorMessage = tr("deactivation of connection") - + activateConnectPtr->connection()->name() + tr("failed:") - + watcher->error().message(); - - qWarning()<deactivateConnectionError(errorMessage); - } else { - qWarning() << "deactive connect operation finished" << activateConnectPtr->connection()->name(); - } - watcher->deleteLater(); - }); - return; } diff --git a/src/kylinwiredconnectoperation.h b/src/kylinwiredconnectoperation.h index 853a430d..c923ee0c 100644 --- a/src/kylinwiredconnectoperation.h +++ b/src/kylinwiredconnectoperation.h @@ -3,8 +3,9 @@ #include "kylinnetworkresourcemanager.h" #include "kylinconnectsetting.h" +#include "kylinconnectoperation.h" -class KyWiredConnectOperation : public QObject +class KyWiredConnectOperation : public KyConnectOperation { Q_OBJECT public: @@ -16,27 +17,8 @@ public: void updateWiredConnect(const QString &connectUuid, const KyConnectSetting &connectSettingsInfo); void deleteWiredConnect(const QString &connectUuid); void activateWiredConnection(const QString connectUuid); + void activateVpnConnection(const QString connectUuid); void deactivateWiredConnection(const QString activeConnectName, const QString &activeConnectUuid); - -private: - void connectSettingSet( - NetworkManager::ConnectionSettings::Ptr connectionSettings, - const KyConnectSetting &connectSettingsInfo); - void ipv4SettingSet(NetworkManager::Ipv4Setting::Ptr &ipv4Setting, - const KyConnectSetting &connectSettingsInfo); - void ipv6SettingSet(NetworkManager::Ipv6Setting::Ptr &ipv6Setting, - const KyConnectSetting &connectSettingsInfo); - inline void errorProcess(QString errorMessage); - -signals: - void createConnectionError(QString errorMessage); - void updateConnectionError(QString errorMessage); - void deleteConnectionError(QString errorMessage); - void activateConnectionError(QString errorMessage); - void deactivateConnectionError(QString errorMessage); - -private: - KyNetworkResourceManager *m_networkResourceInstance = nullptr; }; #endif // KYLINWIREDCONNECTOPERATION_H diff --git a/src/kylinwiredwidget.cpp b/src/kylinwiredwidget.cpp index 7bf27555..70bc686a 100644 --- a/src/kylinwiredwidget.cpp +++ b/src/kylinwiredwidget.cpp @@ -30,8 +30,10 @@ KyWiredWidget::~KyWiredWidget() void KyWiredWidget::constructWiredActiveConnectList() { qDebug()<<"constructWiredActiveConnectList"; - QList wiredActiveConnect; - m_activeConnectResource->getWiredActivateConnect(wiredActiveConnect); + QList wiredActiveConnect; + m_activeConnectResource->getActiveConnectionList("enp2s0", + NetworkManager::ConnectionSettings::ConnectionType::Wired, + wiredActiveConnect); if (wiredActiveConnect.isEmpty()) { OneLancForm *activeWiredForm = new OneLancForm(this, nullptr); activeWiredForm->constructActiveConnectionEmptyItem(); @@ -56,8 +58,10 @@ void KyWiredWidget::setType(WIDGETTYPE type) void KyWiredWidget::constructWiredConnectList() { qDebug()<<"constructWiredConnectList....."; - QList wiredConnections; - m_connectResource->getWiredConnections(wiredConnections); + QList wiredConnections; + m_connectResource->getConnectionList("enp2s0", + NetworkManager::ConnectionSettings::ConnectionType::Wired, + wiredConnections); if (!wiredConnections.isEmpty()) { for (int index = 0; index < wiredConnections.size(); ++index) { resize(W_LIST_WIDGET, height() + H_NORMAL_ITEM); @@ -176,7 +180,8 @@ void KyWiredWidget::updateDeviceRefreshRate(QString deviceName, int ms) return; } -void KyWiredWidget::updateNetworkSpeed(KyWiredConnectItem *wiredItem) +#if 0 +void KyWiredWidget::updateNetworkSpeed(KyConnectItem *wiredItem) { qulonglong txBytes = wiredItem->m_upSpeed; qulonglong rxBytes = wiredItem->m_downSpeed; @@ -199,3 +204,4 @@ void KyWiredWidget::updateNetworkSpeed(KyWiredConnectItem *wiredItem) return; } +#endif diff --git a/src/kylinwiredwidget.h b/src/kylinwiredwidget.h index b991118f..6f9a3371 100644 --- a/src/kylinwiredwidget.h +++ b/src/kylinwiredwidget.h @@ -5,7 +5,7 @@ #include "kylinactiveconnectresource.h" #include "kylinconnectresource.h" #include "kylinnetworkdeviceresource.h" -#include "kylinwiredconnectitem.h" +#include "kylinconnectitem.h" #include "onelancform.h" #include "mainwindow.h" @@ -26,7 +26,7 @@ public: void constructWiredActiveConnectList(); void updateDeviceRefreshRate(QString deviceName, int ms); - void updateNetworkSpeed(KyWiredConnectItem *wiredItem); + void updateNetworkSpeed(KyConnectItem *wiredItem); private: void updateWiredActiveConnection(); diff --git a/src/onelancform.cpp b/src/onelancform.cpp index 9bae126a..9a61702c 100644 --- a/src/onelancform.cpp +++ b/src/onelancform.cpp @@ -23,7 +23,7 @@ #include -OneLancForm::OneLancForm(QWidget *parent, KyWiredConnectItem *wiredConnectItem) : +OneLancForm::OneLancForm(QWidget *parent, KyConnectItem *wiredConnectItem) : QWidget(parent), ui(new Ui::OneLancForm) { @@ -105,7 +105,7 @@ OneLancForm::OneLancForm(QWidget *parent, KyWiredConnectItem *wiredConnectItem) m_updateSpeedTimer = new QTimer(this); connect(m_updateSpeedTimer, &QTimer::timeout, this, &OneLancForm::updateNetworkSpeed); if (nullptr != m_wiredConnectItem - && NetworkManager::ActiveConnection::State::Activated == m_wiredConnectItem->m_state) { + && NetworkManager::ActiveConnection::State::Activated == m_wiredConnectItem->m_connectState) { m_updateSpeedTimer->start(1000); } @@ -143,8 +143,8 @@ void OneLancForm::constructActiveConnectionItem(int index) tr("Ethernet"), m_wiredConnectItem->m_connectUuid, m_wiredConnectItem->m_ifaceName);//第二个参数本来是strLanName,但目前不需要翻译 setIcon(true); - setLanInfo(m_wiredConnectItem->m_ipv4, m_wiredConnectItem->m_ipv6, - m_wiredConnectItem->m_bandWith, m_wiredConnectItem->m_hardAddress); + //setLanInfo(m_wiredConnectItem->m_ipv4, m_wiredConnectItem->m_ipv6, + // m_wiredConnectItem->m_bandWith, m_wiredConnectItem->m_hardAddress); //setConnedString(true, tr("NetOn,IfName:"), m_wiredConnectItem->m_ifaceName); setConnedString(1, tr("NetOn,"), ""); isConnected = true; @@ -162,8 +162,8 @@ void OneLancForm::constructConnectionItem(int index) m_wiredConnectItem->m_ifaceName); setIcon(true); setLine(true); - setLanInfo(m_wiredConnectItem->m_ipv4, m_wiredConnectItem->m_ipv6, - tr("Disconnected"), m_wiredConnectItem->m_hardAddress); + //setLanInfo(m_wiredConnectItem->m_ipv4, m_wiredConnectItem->m_ipv6, + // tr("Disconnected"), m_wiredConnectItem->m_hardAddress); setConnedString(0, tr("Disconnected"), "");//"未连接" move(L_VERTICAL_LINE_TO_ITEM, index * H_NORMAL_ITEM); setSelected(false, false); @@ -607,8 +607,8 @@ void OneLancForm::stopWaiting() void OneLancForm::updateNetworkSpeed() { KyWiredWidget *wiredWidget = (KyWiredWidget *)parentWidget(); - wiredWidget->updateDeviceRefreshRate(m_wiredConnectItem->m_ifaceName, 1000); - wiredWidget->updateNetworkSpeed(m_wiredConnectItem); + // wiredWidget->updateDeviceRefreshRate(m_wiredConnectItem->m_ifaceName, 1000); + // wiredWidget->updateNetworkSpeed(m_wiredConnectItem); return; } diff --git a/src/onelancform.h b/src/onelancform.h index b3abb663..393a5934 100644 --- a/src/onelancform.h +++ b/src/onelancform.h @@ -29,7 +29,7 @@ #include "kylinwiredconnectoperation.h" #include "backthread.h" #include "ksimplenm.h" -#include "kylinwiredconnectitem.h" +#include "kylinconnectitem.h" #include @@ -63,7 +63,7 @@ class OneLancForm : public QWidget { Q_OBJECT public: - explicit OneLancForm(QWidget *parent = 0, KyWiredConnectItem *wiredConnectItem = 0); + explicit OneLancForm(QWidget *parent = 0, KyConnectItem *wiredConnectItem = 0); ~OneLancForm(); public: @@ -127,7 +127,7 @@ private: KyWiredConnectOperation *m_wiredConnectOperation = nullptr; QString leQssLow, leQssHigh; - KyWiredConnectItem *m_wiredConnectItem = nullptr; + KyConnectItem *m_wiredConnectItem = nullptr; signals: void selectedOneLanForm(QString lanName, QString uniqueName);