feature:develop wired 、pptp and bluetooth function.
This commit is contained in:
parent
c41e070e53
commit
48b297b1c8
20
kylin-nm.pro
20
kylin-nm.pro
|
@ -64,9 +64,17 @@ include(src/singleapplication/qt-single-application.pri)
|
|||
|
||||
SOURCES += \
|
||||
src/backthread.cpp \
|
||||
src/kylinconnectinfo.cpp \
|
||||
src/kylinactiveconnectresource.cpp \
|
||||
src/kylinbluetoothconnectitem.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 \
|
||||
src/confform.cpp \
|
||||
src/dbusadaptor.cpp \
|
||||
|
@ -99,9 +107,17 @@ SOURCES += \
|
|||
|
||||
HEADERS += \
|
||||
src/backthread.h \
|
||||
src/kylinconnectinfo.h \
|
||||
src/kylinactiveconnectresource.h \
|
||||
src/kylinbluetoothconnectitem.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 \
|
||||
src/confform.h \
|
||||
src/dbusadaptor.h \
|
||||
|
|
|
@ -230,7 +230,7 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt
|
|||
ui->btnSave->setEnabled(false);
|
||||
}
|
||||
|
||||
void ConfForm::connectInfoConstruct(KyConnectInfo &connectInfo)
|
||||
void ConfForm::connectInfoConstruct(KyConnectSetting &connectInfo)
|
||||
{
|
||||
QString connectName = ui->leName->text();
|
||||
|
||||
|
@ -286,9 +286,9 @@ void ConfForm::on_btnCreate_clicked()
|
|||
}
|
||||
}
|
||||
|
||||
KyConnectInfo newConnectInfo;
|
||||
KyConnectSetting newConnectInfo;
|
||||
connectInfoConstruct(newConnectInfo);
|
||||
m_networkConnect.createConnect(WIRED_CONNECT, newConnectInfo);
|
||||
m_networkConnect.createWiredConnect(newConnectInfo);
|
||||
|
||||
if (DHCP_IP == ui->cbType->currentIndex()) {
|
||||
//选择自动,则配置完成并发出桌面通知
|
||||
|
@ -358,9 +358,9 @@ void ConfForm::saveNetworkConfiguration()
|
|||
{
|
||||
KylinDBus kylindbus;
|
||||
|
||||
KyConnectInfo newConnectInfo;
|
||||
KyConnectSetting newConnectInfo;
|
||||
connectInfoConstruct(newConnectInfo);
|
||||
m_networkConnect.updateConnect(netUuid, newConnectInfo);
|
||||
m_networkConnect.updateWiredConnect(netUuid, newConnectInfo);
|
||||
|
||||
//是选择的自动还是手动配置网络
|
||||
if (ui->cbType->currentIndex() == DHCP_IP) {
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
#include <QDialog>
|
||||
#include <QListView>
|
||||
#include "kylin-dbus-interface.h"
|
||||
#include "kylinnetworkconnect.h"
|
||||
#include "kylinconnectinfo.h"
|
||||
#include "kylinwiredconnectoperation.h"
|
||||
#include "kylinconnectsetting.h"
|
||||
|
||||
namespace Ui {
|
||||
class ConfForm;
|
||||
|
@ -97,7 +97,7 @@ private:
|
|||
bool check_ip_conflict(QString ifname);
|
||||
void onConfformHide();
|
||||
bool isEditingAlready(); //连接按钮是否可被按
|
||||
void connectInfoConstruct(KyConnectInfo &connectInfo);
|
||||
void connectInfoConstruct(KyConnectSetting &connectInfo);
|
||||
|
||||
bool isPress;
|
||||
QPoint winPos;
|
||||
|
@ -113,7 +113,7 @@ private:
|
|||
|
||||
QString labelQss, cbxQss, leQss, lineQss, btnOnQss, btnOffQss;
|
||||
|
||||
KyNetworkConnect m_networkConnect;
|
||||
KyWiredConnectOperation m_networkConnect;
|
||||
QString m_ifaceName;
|
||||
|
||||
signals:
|
||||
|
|
|
@ -0,0 +1,276 @@
|
|||
|
||||
#include "kylinactiveconnectresource.h"
|
||||
|
||||
#include <NetworkManagerQt/IpConfig>
|
||||
#include <NetworkManagerQt/Dhcp4Config>
|
||||
#include <NetworkManagerQt/Dhcp6Config>
|
||||
|
||||
KyActiveConnectResourse::KyActiveConnectResourse()
|
||||
{
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
m_networkdevice = new KyNetworkDeviceResourse();
|
||||
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::activeConnectionRemove,
|
||||
this, &KyActiveConnectResourse::activeConnectRemove);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::activeConnectStateChangeReason,
|
||||
this, &KyActiveConnectResourse::stateChangeReason);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::vpnActiveConnectStateChangeReason,
|
||||
this, &KyActiveConnectResourse::vpnConnectChangeReason);
|
||||
}
|
||||
|
||||
KyActiveConnectResourse::~KyActiveConnectResourse()
|
||||
{
|
||||
m_networkResourceInstance = nullptr;
|
||||
if (nullptr == m_networkdevice) {
|
||||
delete m_networkdevice;
|
||||
m_networkdevice = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void KyActiveConnectResourse::getWiredActivateConnect(QList<KyWiredConnectItem *> &wiredActiveConnectItemList)
|
||||
{
|
||||
int index = 0;
|
||||
NetworkManager::ActiveConnection::List activeConnectList;
|
||||
qDebug()<<"[KyActiveConnectResourse]"<<"get wired activate connect";
|
||||
|
||||
activeConnectList.clear();
|
||||
activeConnectList = m_networkResourceInstance->getActiveConnectList();
|
||||
|
||||
if (activeConnectList.empty()) {
|
||||
qWarning()<<"[KyActiveConnectResourse]"<<"the active connect list is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkManager::ActiveConnection::Ptr activeConnectPtr = nullptr;
|
||||
for (index = 0; index < activeConnectList.size(); index++) {
|
||||
activeConnectPtr = activeConnectList.at(index);
|
||||
if (NetworkManager::ConnectionSettings::ConnectionType::Wired
|
||||
!= activeConnectPtr->type()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
KyWiredConnectItem *activeConnectItem =
|
||||
getWiredActiveConnectItem(activeConnectPtr);
|
||||
if (nullptr != activeConnectItem) {
|
||||
wiredActiveConnectItemList << activeConnectItem;
|
||||
activeConnectItem->dumpInfo();
|
||||
}
|
||||
|
||||
activeConnectPtr = nullptr;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
KyWiredConnectItem *KyActiveConnectResourse::getWiredActiveConnectItem(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"
|
||||
<<activeConnectPtr->connection()->name() << activeConnectPtr->state();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
KyWiredConnectItem *wiredItem = new KyWiredConnectItem();
|
||||
NetworkManager::Connection::Ptr connectPtr = activeConnectPtr->connection();
|
||||
NetworkManager::ConnectionSettings::Ptr settingPtr = connectPtr->settings();
|
||||
|
||||
wiredItem->m_connectName = connectPtr->name();
|
||||
qDebug() <<"[KyActiveConnectResourse]"<< "connect uuid" << connectPtr->uuid()
|
||||
<< "active connect uuid" << activeConnectPtr->uuid();
|
||||
wiredItem->m_connectUuid = activeConnectPtr->uuid();
|
||||
wiredItem->m_ifaceName = settingPtr->interfaceName();
|
||||
|
||||
|
||||
getActiveConnectIp(activeConnectPtr, wiredItem->m_ipv4, wiredItem->m_ipv6);
|
||||
|
||||
m_networkdevice->getWiredHardwareInfo(settingPtr->interfaceName(), wiredItem);
|
||||
|
||||
wiredItem->m_state = NetworkManager::ActiveConnection::State::Activated;
|
||||
//wiredItem->m_itemType;
|
||||
|
||||
return wiredItem;
|
||||
}
|
||||
|
||||
void KyActiveConnectResourse::getActiveConnectIp(
|
||||
NetworkManager::ActiveConnection::Ptr activeConnectPtr,
|
||||
QString &ipv4Address,
|
||||
QString &ipv6Address)
|
||||
{
|
||||
qDebug()<<"[KyActiveConnectResourse]"<<"get active connect ip info";
|
||||
|
||||
NetworkManager::IpConfig ipv4Config =activeConnectPtr->ipV4Config();
|
||||
if (ipv4Config.isValid()) {
|
||||
if (!ipv4Config.addresses().isEmpty()) {
|
||||
NetworkManager::IpAddress address = ipv4Config.addresses().at(0);
|
||||
ipv4Address = address.ip().toString();
|
||||
} else {
|
||||
qWarning()<<"[KyActiveConnectResourse]"<<"the ipv4 address is empty.";
|
||||
}
|
||||
} else {
|
||||
qWarning()<<"[KyActiveConnectResourse]"<<"ipv4 config is not valid";
|
||||
}
|
||||
|
||||
NetworkManager::IpConfig ipv6Config =activeConnectPtr->ipV6Config();
|
||||
if (ipv6Config.isValid()) {
|
||||
if (!ipv6Config.addresses().isEmpty()) {
|
||||
NetworkManager::IpAddress address = ipv6Config.addresses().at(0);
|
||||
ipv6Address = address.ip().toString();
|
||||
} else {
|
||||
qWarning()<<"[KyActiveConnectResourse]"<<"ipv6 address is empty";
|
||||
}
|
||||
} else {
|
||||
qWarning()<<"[KyActiveConnectResourse]"<<"ipv6 config is not valid";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
KyVpnConnectItem *KyActiveConnectResourse::getVpnActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr)
|
||||
{
|
||||
qDebug()<<"[KyActiveConnectResourse]"<<"get vpn active connect item";
|
||||
|
||||
if (nullptr == activeConnectPtr) {
|
||||
qWarning()<<"[KyActiveConnectResourse]"<<"get vpn active connect failed, the active connect is empty";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (NetworkManager::ActiveConnection::State::Activated != activeConnectPtr->state()) {
|
||||
qWarning()<<"[KyActiveConnectResourse]"<<"the active connect is not activated"
|
||||
<<activeConnectPtr->connection()->name() << activeConnectPtr->state();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
KyVpnConnectItem *vpnItem = new KyVpnConnectItem();
|
||||
NetworkManager::Connection::Ptr connectPtr = activeConnectPtr->connection();
|
||||
vpnItem->m_vpnName = connectPtr->name();
|
||||
|
||||
vpnItem->m_vpnUuid = activeConnectPtr->uuid();
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr settingsPtr = connectPtr->settings();
|
||||
NetworkManager::VpnSetting::Ptr vpnSetting = settingsPtr->setting(NetworkManager::Setting::Vpn).dynamicCast<NetworkManager::VpnSetting>();
|
||||
NMStringMap vpnDataMap = vpnSetting->data();
|
||||
if (vpnDataMap.isEmpty()) {
|
||||
qWarning()<<"[KyActiveConnectResourse]"<<"get vpn connection Data failed, the data is empty";
|
||||
} else {
|
||||
vpnItem->m_vpnGateWay = vpnDataMap["gateway"];
|
||||
vpnItem->m_vpnUser = vpnDataMap["user"];
|
||||
if ( "yes" == vpnDataMap["require-mppe"]) {
|
||||
vpnItem->m_vpnMppe = true;
|
||||
} else {
|
||||
vpnItem->m_vpnMppe = false;
|
||||
qDebug()<<"[KyActiveConnectResourse]"<<"vpn mppe required:"<< vpnDataMap["require-mppe"];
|
||||
}
|
||||
}
|
||||
|
||||
getActiveConnectIp(activeConnectPtr, vpnItem->m_vpnIpv4Address, vpnItem->m_vpnIpv6Address);
|
||||
|
||||
NetworkManager::VpnConnection *p_vpnConnect = qobject_cast<NetworkManager::VpnConnection *>(activeConnectPtr.data());
|
||||
vpnItem->m_vpnState = p_vpnConnect->state();
|
||||
|
||||
return vpnItem;
|
||||
}
|
||||
|
||||
void KyActiveConnectResourse::getVpnActivateConnect(QList<KyVpnConnectItem *> &vpnActiveConnectItemList)
|
||||
{
|
||||
int index = 0;
|
||||
NetworkManager::ActiveConnection::List activeConnectList;
|
||||
|
||||
activeConnectList.clear();
|
||||
activeConnectList = m_networkResourceInstance->getActiveConnectList();
|
||||
|
||||
if (activeConnectList.empty()) {
|
||||
qWarning()<<"[KyActiveConnectResourse]"<<"get vpn active connect failed, the active connect list is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkManager::ActiveConnection::Ptr activeConnectPtr = nullptr;
|
||||
for (index = 0; index < activeConnectList.size(); index++) {
|
||||
activeConnectPtr = activeConnectList.at(index);
|
||||
if (!activeConnectPtr->vpn()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
KyVpnConnectItem *activeConnectItem =
|
||||
getVpnActiveConnectItem(activeConnectPtr);
|
||||
if (nullptr != activeConnectItem) {
|
||||
vpnActiveConnectItemList << activeConnectItem;
|
||||
}
|
||||
|
||||
activeConnectPtr = nullptr;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
KyBluetoothConnectItem *KyActiveConnectResourse::getBtActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr)
|
||||
{
|
||||
qDebug()<<"[KyActiveConnectResourse]"<<"get bluetooth active connect item";
|
||||
|
||||
if (nullptr == activeConnectPtr) {
|
||||
qWarning()<<"[KyActiveConnectResourse]"<<"get bluetooth item failed, the active connect is empty";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (NetworkManager::ActiveConnection::State::Activated != activeConnectPtr->state()) {
|
||||
qWarning()<<"[KyActiveConnectResourse]"<<"get bluetooth item failed, the active connect is not activated"
|
||||
<<activeConnectPtr->connection()->name() << activeConnectPtr->state();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
KyBluetoothConnectItem *bluetoothItem = new KyBluetoothConnectItem();
|
||||
NetworkManager::Connection::Ptr connectPtr = activeConnectPtr->connection();
|
||||
|
||||
bluetoothItem->m_connectName = connectPtr->name();
|
||||
bluetoothItem->m_connectUuid = activeConnectPtr->uuid();
|
||||
bluetoothItem->m_state = NetworkManager::ActiveConnection::State::Activated;
|
||||
|
||||
getActiveConnectIp(activeConnectPtr, bluetoothItem->m_ipv4Address, bluetoothItem->m_ipv6Address);
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr settingPtr = connectPtr->settings();
|
||||
NetworkManager::BluetoothSetting::Ptr bluetoothSetting =
|
||||
settingPtr->setting(NetworkManager::Setting::Bluetooth).dynamicCast<NetworkManager::BluetoothSetting>();
|
||||
bluetoothItem->m_deviceAddress = bluetoothSetting->bluetoothAddress();
|
||||
//wiredItem->m_itemType;
|
||||
|
||||
return bluetoothItem;
|
||||
}
|
||||
|
||||
void KyActiveConnectResourse::getBluetoothConnect(QList<KyBluetoothConnectItem *> &btActiveConnectItemList)
|
||||
{
|
||||
int index = 0;
|
||||
NetworkManager::ActiveConnection::List activeConnectList;
|
||||
|
||||
activeConnectList.clear();
|
||||
activeConnectList = m_networkResourceInstance->getActiveConnectList();
|
||||
|
||||
if (activeConnectList.empty()) {
|
||||
qWarning()<<"[KyActiveConnectResourse]"<<"get bluetooth active connect failed, the active connect list is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkManager::ActiveConnection::Ptr activeConnectPtr = nullptr;
|
||||
for (index = 0; index < activeConnectList.size(); index++) {
|
||||
activeConnectPtr = activeConnectList.at(index);
|
||||
if (NetworkManager::ConnectionSettings::ConnectionType::Bluetooth
|
||||
!= activeConnectPtr->type()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
KyBluetoothConnectItem *activeConnectItem = getBtActiveConnectItem(activeConnectPtr);
|
||||
if (nullptr != activeConnectItem) {
|
||||
btActiveConnectItemList << activeConnectItem;
|
||||
}
|
||||
|
||||
activeConnectPtr = nullptr;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef KYLINACTIVECONNECTRESOURCE_H
|
||||
#define KYLINACTIVECONNECTRESOURCE_H
|
||||
|
||||
#include <QString>
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include "kylinwiredconnectitem.h"
|
||||
#include "kylinnetworkdeviceresource.h"
|
||||
#include "kylinvpnconnectitem.h"
|
||||
#include "kylinbluetoothconnectitem.h"
|
||||
|
||||
class KyActiveConnectResourse : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KyActiveConnectResourse();
|
||||
~KyActiveConnectResourse();
|
||||
|
||||
public:
|
||||
void getWiredActivateConnect(QList<KyWiredConnectItem *> &wiredActiveConnectItemList);
|
||||
void getVpnActivateConnect(QList<KyVpnConnectItem *> &vpnActiveConnectItemList);
|
||||
void getBluetoothConnect(QList<KyBluetoothConnectItem *> &btActiveConnectItemList);
|
||||
|
||||
private:
|
||||
void getActiveConnectIp(NetworkManager::ActiveConnection::Ptr activeConnectPtr,
|
||||
QString &ipv4Address,
|
||||
QString &ipv6Address);
|
||||
KyWiredConnectItem *getWiredActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr);
|
||||
KyVpnConnectItem *getVpnActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr);
|
||||
KyBluetoothConnectItem *getBtActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr);
|
||||
|
||||
signals:
|
||||
void activeConnectAdd(QString activeConnectUuid);
|
||||
void updateActiveConnect(QString activeConnectUuid);
|
||||
void activeConnectRemove(QString activeConnectUuid);
|
||||
void stateChangeReason(QString uuid,
|
||||
NetworkManager::ActiveConnection::State state,
|
||||
NetworkManager::ActiveConnection::Reason reason);
|
||||
void vpnConnectChangeReason(QString uuid,
|
||||
NetworkManager::VpnConnection::State state,
|
||||
NetworkManager::VpnConnection::StateChangeReason reason);
|
||||
|
||||
private:
|
||||
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
|
||||
KyNetworkDeviceResourse *m_networkdevice = nullptr;
|
||||
};
|
||||
#endif // KYLINACTIVECONNECTRESOURCE_H
|
|
@ -0,0 +1,29 @@
|
|||
#include "kylinbluetoothconnectitem.h"
|
||||
|
||||
|
||||
KyBluetoothConnectItem::KyBluetoothConnectItem()
|
||||
{
|
||||
m_connectName = "";
|
||||
m_connectUuid = "";
|
||||
|
||||
m_deviceAddress = "";
|
||||
|
||||
m_ipv4Address = "";
|
||||
m_ipv6Address = "";
|
||||
|
||||
m_state = NetworkManager::ActiveConnection::State::Deactivated;
|
||||
}
|
||||
|
||||
KyBluetoothConnectItem::~KyBluetoothConnectItem()
|
||||
{
|
||||
m_connectName = "";
|
||||
m_connectUuid = "";
|
||||
|
||||
m_deviceAddress = "";
|
||||
|
||||
m_ipv4Address = "";
|
||||
m_ipv6Address = "";
|
||||
|
||||
m_state = NetworkManager::ActiveConnection::State::Deactivated;
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef KYLINBLUETOOTHCONNECTITEM_H
|
||||
#define KYLINBLUETOOTHCONNECTITEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <NetworkManagerQt/BluetoothDevice>
|
||||
#include <NetworkManagerQt/BluetoothSetting>
|
||||
|
||||
class KyBluetoothConnectItem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KyBluetoothConnectItem();
|
||||
~KyBluetoothConnectItem();
|
||||
|
||||
public:
|
||||
void dumpInfo();
|
||||
|
||||
public:
|
||||
QString m_connectName;
|
||||
QString m_connectUuid;
|
||||
|
||||
QString m_deviceAddress;
|
||||
|
||||
QString m_ipv4Address;
|
||||
QString m_ipv6Address;
|
||||
|
||||
NetworkManager::ActiveConnection::State m_state; //deactive、activing and actived
|
||||
//QString m_itemType; //activeconnect or connect
|
||||
|
||||
};
|
||||
|
||||
#endif // KYLINBLUETOOTHCONNECTITEM_H
|
|
@ -0,0 +1,342 @@
|
|||
|
||||
#include "kylinconnectresource.h"
|
||||
#include <NetworkManagerQt/Ipv4Setting>
|
||||
#include <NetworkManagerQt/Ipv6Setting>
|
||||
#include <NetworkManagerQt/VpnConnection>
|
||||
#include <NetworkManagerQt/VpnPlugin>
|
||||
#include <NetworkManagerQt/VpnSetting>
|
||||
|
||||
KyConnectResourse::KyConnectResourse()
|
||||
{
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
m_networkdevice = new KyNetworkDeviceResourse();
|
||||
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionAdd, this, &KyConnectResourse::connectionAdd);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionRemove, this, &KyConnectResourse::connectionRemove);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionUpdate, this, &KyConnectResourse::connectionUpdate);
|
||||
}
|
||||
|
||||
KyConnectResourse::~KyConnectResourse()
|
||||
{
|
||||
m_networkResourceInstance = nullptr;
|
||||
if (nullptr != m_networkdevice) {
|
||||
delete m_networkdevice;
|
||||
m_networkdevice = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void KyConnectResourse::getWiredConnections(QList<KyWiredConnectItem *> &wiredConnectItemList)
|
||||
{
|
||||
int index = 0;
|
||||
NetworkManager::Connection::List connectList;
|
||||
|
||||
qDebug()<<"[KyConnectResourse]"<<"get wired connections";
|
||||
|
||||
connectList.clear();
|
||||
connectList = m_networkResourceInstance->getConnectList();
|
||||
|
||||
if (connectList.empty()) {
|
||||
qWarning()<<"[KyConnectResourse]"<<"get wired connection failed, the connect list is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkManager::Connection::Ptr connectPtr = nullptr;
|
||||
for (index = 0; index < connectList.size(); index++) {
|
||||
connectPtr = connectList.at(index);
|
||||
if (NetworkManager::ConnectionSettings::ConnectionType::Wired
|
||||
!= connectPtr->settings()->connectionType()) {
|
||||
qDebug()<<"[KyConnectResourse]"<<"connect name:" << connectPtr->name()
|
||||
<<"connect type:"<<connectPtr->settings()->connectionType();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_networkResourceInstance->isActiveConnection(connectPtr->uuid())) {
|
||||
qDebug()<<"[KyConnectResourse]"<<connectPtr->name()<<"is active connection";
|
||||
continue;
|
||||
}
|
||||
|
||||
KyWiredConnectItem *connectItem = getWiredConnectItem(connectPtr);
|
||||
if (nullptr != connectItem) {
|
||||
wiredConnectItemList << connectItem;
|
||||
connectItem->dumpInfo();
|
||||
}
|
||||
|
||||
connectPtr = nullptr;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
KyWiredConnectItem *KyConnectResourse::getWiredConnectItem(NetworkManager::Connection::Ptr connectPtr)
|
||||
{
|
||||
qDebug()<<"[KyConnectResourse]"<<"get connect item";
|
||||
|
||||
if (nullptr == connectPtr) {
|
||||
qWarning()<<"[KyConnectResourse]"<<"the connect is empty";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
KyWiredConnectItem *wiredItem = new KyWiredConnectItem();
|
||||
NetworkManager::ConnectionSettings::Ptr settingPtr = connectPtr->settings();
|
||||
|
||||
wiredItem->m_connectName = connectPtr->name();
|
||||
wiredItem->m_connectUuid = connectPtr->uuid();
|
||||
wiredItem->m_ifaceName = settingPtr->interfaceName();
|
||||
|
||||
getConnectIp(settingPtr, wiredItem->m_ipv4, wiredItem->m_ipv6);
|
||||
|
||||
m_networkdevice->getWiredHardwareInfo(settingPtr->interfaceName(), wiredItem);
|
||||
|
||||
wiredItem->m_state = NetworkManager::ActiveConnection::State::Deactivated;
|
||||
//wiredItem->m_itemType;
|
||||
|
||||
return wiredItem;
|
||||
}
|
||||
|
||||
void KyConnectResourse::getConnectIp(
|
||||
NetworkManager::ConnectionSettings::Ptr settingPtr,
|
||||
QString &ipv4Address,
|
||||
QString &ipv6Address)
|
||||
{
|
||||
NetworkManager::Ipv4Setting::Ptr ipv4Setting =
|
||||
settingPtr->setting(NetworkManager::Setting::Ipv4).dynamicCast<NetworkManager::Ipv4Setting>();
|
||||
if (NetworkManager::Ipv4Setting::Manual == ipv4Setting->method()) {
|
||||
QList<NetworkManager::IpAddress> ipv4AddressList = ipv4Setting->addresses();
|
||||
NetworkManager::IpAddress settingIpv4Address = ipv4AddressList.at(0);
|
||||
if (settingIpv4Address.isValid()) {
|
||||
ipv4Address = settingIpv4Address.ip().toString();
|
||||
} else {
|
||||
qWarning()<<"[KyConnectResourse]"<<"get connect ipv4 failed, ipv4Address is not valid";
|
||||
}
|
||||
} else {
|
||||
qWarning()<<"[KyConnectResourse]"<<"get connect ipv4 failed, ipv4 config with dhcp";
|
||||
}
|
||||
|
||||
NetworkManager::Ipv6Setting::Ptr ipv6Setting = settingPtr->setting(NetworkManager::Setting::Ipv6).dynamicCast<NetworkManager::Ipv6Setting>();
|
||||
if (NetworkManager::Ipv4Setting::Manual == ipv6Setting->method()) {
|
||||
QList<NetworkManager::IpAddress> ipv6AddressList = ipv6Setting->addresses();
|
||||
NetworkManager::IpAddress settingIpv6Address = ipv6AddressList.at(0);
|
||||
if (settingIpv6Address.isValid()) {
|
||||
ipv6Address = settingIpv6Address.ip().toString();
|
||||
} else {
|
||||
qWarning()<<"[KyConnectResourse]"<<"get connect ipv6 failed, ipv6Address is not valid";
|
||||
}
|
||||
} else {
|
||||
qWarning()<<"[KyConnectResourse]"<<"get connect ipv6 failed, ipv6 config with dhcp";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void KyConnectResourse::getIpv4ConnectSetting(
|
||||
NetworkManager::Ipv4Setting::Ptr &ipv4Setting,
|
||||
KyConnectSetting &connectSetting)
|
||||
{
|
||||
if (NetworkManager::Ipv4Setting::Automatic == ipv4Setting->method()) {
|
||||
connectSetting.m_ipv4ConfigIpType = CONFIG_IP_DHCP;
|
||||
return;
|
||||
}
|
||||
|
||||
connectSetting.m_ipv4ConfigIpType = CONFIG_IP_MANUAL;
|
||||
|
||||
connectSetting.m_ipv4Address = ipv4Setting->addresses();
|
||||
connectSetting.m_ipv4Dns = ipv4Setting->dns();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyConnectResourse::getIpv6ConnectSetting(
|
||||
NetworkManager::Ipv6Setting::Ptr &ipv6Setting,
|
||||
KyConnectSetting &connectSetting)
|
||||
{
|
||||
|
||||
if (NetworkManager::Ipv6Setting::Automatic == ipv6Setting->method()) {
|
||||
connectSetting.m_ipv6ConfigIpType = CONFIG_IP_DHCP;
|
||||
return;
|
||||
}
|
||||
|
||||
connectSetting.m_ipv6ConfigIpType = CONFIG_IP_MANUAL;
|
||||
|
||||
connectSetting.m_ipv6Address = ipv6Setting->addresses();
|
||||
connectSetting.m_ipv6Dns = ipv6Setting->dns();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyConnectResourse::getConnectionSetting(QString connectUuid, KyConnectSetting &connectSetting)
|
||||
{
|
||||
qDebug()<< connectUuid <<"get connect setting info";
|
||||
|
||||
NetworkManager::Connection::Ptr connectPtr =
|
||||
m_networkResourceInstance->getConnect(connectUuid);
|
||||
|
||||
if (nullptr == connectPtr
|
||||
|| !connectPtr->isValid()) {
|
||||
qWarning() << "it can not find valid connection" << connectUuid;
|
||||
return;
|
||||
}
|
||||
|
||||
connectSetting.m_connectName = connectPtr->name();
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr connectionSettings = connectPtr->settings();
|
||||
connectSetting.m_ifaceName = connectionSettings->interfaceName();
|
||||
|
||||
NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast<NetworkManager::Ipv4Setting>();
|
||||
getIpv4ConnectSetting(ipv4Setting, connectSetting);
|
||||
|
||||
NetworkManager::Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast<NetworkManager::Ipv6Setting>();
|
||||
getIpv6ConnectSetting(ipv6Setting, connectSetting);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyConnectResourse::getVpnConnectData(NetworkManager::ConnectionSettings::Ptr settingsPtr,
|
||||
KyVpnConnectItem *vpnItem)
|
||||
{
|
||||
NetworkManager::VpnSetting::Ptr vpnSetting = settingsPtr->setting(NetworkManager::Setting::Vpn).dynamicCast<NetworkManager::VpnSetting>();
|
||||
NMStringMap vpnDataMap = vpnSetting->data();
|
||||
if (vpnDataMap.isEmpty()) {
|
||||
qWarning()<<"get vpn connection Data failed, the data is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
vpnItem->m_vpnGateWay = vpnDataMap["gateway"];
|
||||
vpnItem->m_vpnUser = vpnDataMap["user"];
|
||||
if ( "yes" == vpnDataMap["require-mppe"]) {
|
||||
vpnItem->m_vpnMppe = true;
|
||||
} else {
|
||||
vpnItem->m_vpnMppe = false;
|
||||
qDebug()<<"vpn mppe required:"<< vpnDataMap["require-mppe"];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
KyVpnConnectItem *KyConnectResourse::getVpnConnectItem(NetworkManager::Connection::Ptr connectPtr)
|
||||
{
|
||||
if (nullptr == connectPtr) {
|
||||
qWarning()<<"[KyConnectResourse]"<<"get vpn connection item failed, the connect is empty";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
KyVpnConnectItem *vpnItem = new KyVpnConnectItem();
|
||||
NetworkManager::ConnectionSettings::Ptr settingPtr = connectPtr->settings();
|
||||
|
||||
vpnItem->m_vpnName = connectPtr->name();
|
||||
vpnItem->m_vpnUuid = connectPtr->uuid();
|
||||
vpnItem->m_vpnState = NetworkManager::VpnConnection::State::Disconnected;
|
||||
|
||||
getConnectIp(settingPtr, vpnItem->m_vpnIpv4Address, vpnItem->m_vpnIpv6Address);
|
||||
getVpnConnectData(settingPtr, vpnItem);
|
||||
|
||||
return vpnItem;
|
||||
}
|
||||
|
||||
void KyConnectResourse::getVpnConnections(QList<KyVpnConnectItem *> &vpnConnectItemList)
|
||||
{
|
||||
int index = 0;
|
||||
NetworkManager::Connection::List connectList;
|
||||
|
||||
qDebug()<<"[KyConnectResourse]"<<"get vpn connections";
|
||||
|
||||
connectList.clear();
|
||||
connectList = m_networkResourceInstance->getConnectList();
|
||||
|
||||
if (connectList.empty()) {
|
||||
qWarning()<<"[KyConnectResourse]"<<"get vpn connections failed, the connect list is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkManager::Connection::Ptr connectPtr = nullptr;
|
||||
for (index = 0; index < connectList.size(); index++) {
|
||||
connectPtr = connectList.at(index);
|
||||
if (NetworkManager::ConnectionSettings::ConnectionType::Vpn
|
||||
!= connectPtr->settings()->connectionType()) {
|
||||
qDebug()<<"[KyConnectResourse]"<<"connect name:" << connectPtr->name()
|
||||
<<"connect type:"<<connectPtr->settings()->connectionType();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_networkResourceInstance->isActiveConnection(connectPtr->uuid())) {
|
||||
qDebug()<<"[KyConnectResourse]"<<connectPtr->name()<<"is active connection";
|
||||
continue;
|
||||
}
|
||||
|
||||
KyVpnConnectItem *connectItem = getVpnConnectItem(connectPtr);
|
||||
if (nullptr != connectItem) {
|
||||
vpnConnectItemList << connectItem;
|
||||
//connectItem->dumpInfo();
|
||||
}
|
||||
|
||||
connectPtr = nullptr;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
KyBluetoothConnectItem *KyConnectResourse::getBluetoothConnectItem(NetworkManager::Connection::Ptr connectPtr)
|
||||
{
|
||||
if (nullptr == connectPtr) {
|
||||
qWarning()<<"[KyConnectResourse]"<<"get bluetooth connection item failed, the connect is empty";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
KyBluetoothConnectItem *bluetoothItem = new KyBluetoothConnectItem();
|
||||
bluetoothItem->m_connectName = connectPtr->name();
|
||||
bluetoothItem->m_connectUuid = connectPtr->uuid();
|
||||
bluetoothItem->m_state = NetworkManager::ActiveConnection::State::Deactivated;
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr settingPtr = connectPtr->settings();
|
||||
getConnectIp(settingPtr, bluetoothItem->m_ipv4Address, bluetoothItem->m_ipv6Address);
|
||||
|
||||
NetworkManager::BluetoothSetting::Ptr bluetoothSetting =
|
||||
settingPtr->setting(NetworkManager::Setting::Bluetooth).dynamicCast<NetworkManager::BluetoothSetting>();
|
||||
bluetoothItem->m_deviceAddress = bluetoothSetting->bluetoothAddress();
|
||||
qDebug()<<"bluetooth device address:"<<bluetoothItem->m_deviceAddress;
|
||||
|
||||
return bluetoothItem;
|
||||
}
|
||||
|
||||
void KyConnectResourse::getBluetoothConnections(QList<KyBluetoothConnectItem *> &bluetoothConnectItemList)
|
||||
{
|
||||
int index = 0;
|
||||
NetworkManager::Connection::List connectList;
|
||||
|
||||
qDebug()<<"[KyConnectResourse]"<<"get bluetooth connections";
|
||||
|
||||
connectList.clear();
|
||||
connectList = m_networkResourceInstance->getConnectList();
|
||||
|
||||
if (connectList.empty()) {
|
||||
qWarning()<<"[KyConnectResourse]"<<"get bluetooth connections failed, the connect list is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkManager::Connection::Ptr connectPtr = nullptr;
|
||||
for (index = 0; index < connectList.size(); index++) {
|
||||
connectPtr = connectList.at(index);
|
||||
if (NetworkManager::ConnectionSettings::ConnectionType::Bluetooth
|
||||
!= connectPtr->settings()->connectionType()) {
|
||||
qDebug()<<"[KyConnectResourse]"<<"connect name:" << connectPtr->name()
|
||||
<<"connect type:"<<connectPtr->settings()->connectionType();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_networkResourceInstance->isActiveConnection(connectPtr->uuid())) {
|
||||
qDebug()<<"[KyConnectResourse]"<<connectPtr->name()<<"is active connection";
|
||||
continue;
|
||||
}
|
||||
|
||||
KyBluetoothConnectItem *connectItem = getBluetoothConnectItem(connectPtr);
|
||||
if (nullptr != connectItem) {
|
||||
bluetoothConnectItemList << connectItem;
|
||||
//connectItem->dumpInfo();
|
||||
}
|
||||
|
||||
connectPtr = nullptr;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
#ifndef KYLINCONNECTRESOURCE_H
|
||||
#define KYLINCONNECTRESOURCE_H
|
||||
|
||||
#include <QString>
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include "kylinwiredconnectitem.h"
|
||||
#include "kylinvpnconnectitem.h"
|
||||
#include "kylinbluetoothconnectitem.h"
|
||||
#include "kylinnetworkdeviceresource.h"
|
||||
#include "kylinconnectsetting.h"
|
||||
|
||||
class KyConnectResourse : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KyConnectResourse();
|
||||
~KyConnectResourse();
|
||||
|
||||
public:
|
||||
void getWiredConnections(QList<KyWiredConnectItem *> &wiredConnectItemList);
|
||||
void getVpnConnections(QList<KyVpnConnectItem *> &vpnConnectItemList);
|
||||
void getBluetoothConnections(QList<KyBluetoothConnectItem *> &bluetoothConnectItemList);
|
||||
void getConnectionSetting(QString connectUuid, KyConnectSetting &connectSetting);
|
||||
|
||||
private:
|
||||
void getConnectIp(NetworkManager::ConnectionSettings::Ptr settingPtr,
|
||||
QString &ipv4Address,
|
||||
QString &ipv6Address);
|
||||
KyWiredConnectItem *getWiredConnectItem(NetworkManager::Connection::Ptr connectPtr);
|
||||
|
||||
void getVpnConnectData(NetworkManager::ConnectionSettings::Ptr settingPtr,
|
||||
KyVpnConnectItem *vpnItem);
|
||||
KyVpnConnectItem *getVpnConnectItem(NetworkManager::Connection::Ptr connectPtr);
|
||||
|
||||
KyBluetoothConnectItem *getBluetoothConnectItem(NetworkManager::Connection::Ptr connectPtr);
|
||||
|
||||
void getIpv4ConnectSetting(NetworkManager::Ipv4Setting::Ptr &ipv4Setting,
|
||||
KyConnectSetting &connectSetting);
|
||||
void getIpv6ConnectSetting(NetworkManager::Ipv6Setting::Ptr &ipv6Setting,
|
||||
KyConnectSetting &connectSetting);
|
||||
|
||||
signals:
|
||||
void connectionAdd(QString uuid);
|
||||
void connectionUpdate(QString uuid);
|
||||
void connectionRemove(QString path);
|
||||
|
||||
private:
|
||||
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
|
||||
KyNetworkDeviceResourse *m_networkdevice = nullptr;
|
||||
};
|
||||
#endif // KYLINCONNECTRESOURCE_H
|
|
@ -15,10 +15,10 @@
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#include "kylinconnectinfo.h"
|
||||
#include "kylinconnectsetting.h"
|
||||
#include <QDebug>
|
||||
|
||||
KyConnectInfo::KyConnectInfo()
|
||||
KyConnectSetting::KyConnectSetting()
|
||||
{
|
||||
m_connectName = "";
|
||||
m_ifaceName = "";
|
||||
|
@ -32,22 +32,22 @@ KyConnectInfo::KyConnectInfo()
|
|||
m_ipv6Dns.clear();
|
||||
}
|
||||
|
||||
KyConnectInfo::~KyConnectInfo()
|
||||
KyConnectSetting::~KyConnectSetting()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void KyConnectInfo::setIfaceName(QString &ifaceName)
|
||||
void KyConnectSetting::setIfaceName(QString &ifaceName)
|
||||
{
|
||||
m_ifaceName = ifaceName;
|
||||
}
|
||||
|
||||
void KyConnectInfo::setConnectName(QString &connectName)
|
||||
void KyConnectSetting::setConnectName(QString &connectName)
|
||||
{
|
||||
m_connectName = connectName;
|
||||
}
|
||||
|
||||
int KyConnectInfo::setIpConfigType(KyIpAddressType ipType, KyIpConfigType ipConfigType)
|
||||
int KyConnectSetting::setIpConfigType(KyIpAddressType ipType, KyIpConfigType ipConfigType)
|
||||
{
|
||||
if (ipType != IPADDRESS_V4 && ipType != IPADDRESS_V6) {
|
||||
qWarning()<<"set config ip type failed, the ip address type undefined"<<ipType;
|
||||
|
@ -67,7 +67,7 @@ int KyConnectInfo::setIpConfigType(KyIpAddressType ipType, KyIpConfigType ipConf
|
|||
|
||||
return 0;
|
||||
}
|
||||
void KyConnectInfo::ipv4AddressConstruct(QString &ipv4Address, QString &ipv4NetMask, QString &ipv4GateWay, QStringList &ipv4Dns)
|
||||
void KyConnectSetting::ipv4AddressConstruct(QString &ipv4Address, QString &ipv4NetMask, QString &ipv4GateWay, QStringList &ipv4Dns)
|
||||
{
|
||||
qDebug()<<"ipv4 address"<<ipv4Address << ipv4NetMask << ipv4GateWay;
|
||||
NetworkManager::IpAddress nmIpv4Address;
|
||||
|
@ -83,7 +83,7 @@ void KyConnectInfo::ipv4AddressConstruct(QString &ipv4Address, QString &ipv4NetM
|
|||
|
||||
return ;
|
||||
}
|
||||
void KyConnectInfo::ipv6AddressConstruct(QString &ipv6Address, QString &ipv6NetMask, QString &ipv6GateWay, QStringList &ipv6Dns)
|
||||
void KyConnectSetting::ipv6AddressConstruct(QString &ipv6Address, QString &ipv6NetMask, QString &ipv6GateWay, QStringList &ipv6Dns)
|
||||
{
|
||||
NetworkManager::IpAddress nmIpv6Address;
|
||||
nmIpv6Address.setIp(QHostAddress(ipv6Address));
|
||||
|
@ -97,3 +97,32 @@ void KyConnectInfo::ipv6AddressConstruct(QString &ipv6Address, QString &ipv6NetM
|
|||
|
||||
return ;
|
||||
}
|
||||
|
||||
void KyConnectSetting::dumpInfo()
|
||||
{
|
||||
qDebug()<<"connect setting info:";
|
||||
qDebug()<<"connect name"<< m_connectName;
|
||||
qDebug()<<"iface name" << m_ifaceName;
|
||||
|
||||
for (int index = 0 ; index << m_ipv4Address.size(); index++) {
|
||||
qDebug()<<"ipv4 address" << m_ipv4Address.at(index).ip().toString();
|
||||
qDebug()<<"ipv4 gate way" << m_ipv4Address.at(index).gateway().toString();
|
||||
qDebug()<<"ipv4 net mask" << m_ipv4Address.at(index).netmask().toString();
|
||||
}
|
||||
|
||||
for (int index = 0; index < m_ipv4Dns.size(); ++index) {
|
||||
qDebug()<<"ipv4 dns" << m_ipv4Dns.at(index).toString();
|
||||
}
|
||||
|
||||
/*
|
||||
for (int index = 0 ; index << m_ipv6Address.size(); index++) {
|
||||
qDebug()<<"ipv6 address" << m_ipv6Address.at(index).ip().toString();
|
||||
qDebug()<<"ipv6 gate way" << m_ipv6Address.at(index).gateway().toString();
|
||||
qDebug()<<"ipv6 net mask" << m_ipv6Address.at(index).netmask().toString();
|
||||
}
|
||||
|
||||
for (int index = 0; index < m_ipv6Dns.size(); ++index) {
|
||||
qDebug()<<"ipv6 dns" << m_ipv6Dns.at(index).toString();
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -16,8 +16,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef KYLINCONNECTINFO_H
|
||||
#define KYLINCONNECTINFO_H
|
||||
#ifndef KYLINCONNECTSETTING_H
|
||||
#define KYLINCONNECTSETTING_H
|
||||
|
||||
#include <QStringList>
|
||||
#include <QString>
|
||||
|
@ -39,12 +39,12 @@ typedef enum {
|
|||
IPADDRESS_V6,
|
||||
}KyIpAddressType;
|
||||
|
||||
class KyConnectInfo : public QObject
|
||||
class KyConnectSetting : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KyConnectInfo();
|
||||
~KyConnectInfo();
|
||||
KyConnectSetting();
|
||||
~KyConnectSetting();
|
||||
|
||||
public:
|
||||
void setIfaceName(QString &ifaceName);
|
||||
|
@ -52,6 +52,7 @@ public:
|
|||
int setIpConfigType(KyIpAddressType ipType, KyIpConfigType configType);
|
||||
void ipv4AddressConstruct(QString &ipv4Address, QString &ipv4NetMask, QString &ipv4GateWay, QStringList &ipv4Dns);
|
||||
void ipv6AddressConstruct(QString &ipv6Address, QString &ipv6NetMask, QString &ipv6GateWay, QStringList &ipv6Dns);
|
||||
void dumpInfo();
|
||||
|
||||
public:
|
||||
QString m_connectName;
|
||||
|
@ -66,4 +67,4 @@ public:
|
|||
QList<QHostAddress> m_ipv6Dns;
|
||||
};
|
||||
|
||||
#endif // KYLINCONNECTINFO_H
|
||||
#endif // KYLINCONNECTSETTING_H
|
|
@ -72,7 +72,7 @@ KyNetworkConnect::~KyNetworkConnect()
|
|||
|
||||
void KyNetworkConnect::ipv4SettingInit(
|
||||
NetworkManager::Ipv4Setting::Ptr &ipv4Setting,
|
||||
const KyConnectInfo &connectInfo)
|
||||
const KyConnectSetting &connectInfo)
|
||||
{
|
||||
ipv4Setting->setInitialized(true);
|
||||
|
||||
|
@ -95,7 +95,7 @@ void KyNetworkConnect::ipv4SettingInit(
|
|||
}
|
||||
void KyNetworkConnect::ipv6SettingInit(
|
||||
NetworkManager::Ipv6Setting::Ptr &ipv6Setting,
|
||||
const KyConnectInfo &connectInfo)
|
||||
const KyConnectSetting &connectInfo)
|
||||
{
|
||||
ipv6Setting->setInitialized(true);
|
||||
|
||||
|
@ -118,7 +118,7 @@ void KyNetworkConnect::ipv6SettingInit(
|
|||
|
||||
void KyNetworkConnect::connectSettingInit(
|
||||
NetworkManager::ConnectionSettings::Ptr connectionSettings,
|
||||
const KyConnectInfo &connectInfo)
|
||||
const KyConnectSetting &connectInfo)
|
||||
{
|
||||
connectionSettings->setId(connectInfo.m_connectName);
|
||||
connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid());
|
||||
|
@ -128,7 +128,7 @@ void KyNetworkConnect::connectSettingInit(
|
|||
return;
|
||||
}
|
||||
|
||||
void KyNetworkConnect::createWiredConnect(const KyConnectInfo &connectInfo)
|
||||
void KyNetworkConnect::createWiredConnect(const KyConnectSetting &connectInfo)
|
||||
{
|
||||
NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wired));
|
||||
connectSettingInit(connectionSettings, connectInfo);
|
||||
|
@ -160,7 +160,7 @@ void KyNetworkConnect::createWiredConnect(const KyConnectInfo &connectInfo)
|
|||
return;
|
||||
}
|
||||
|
||||
void KyNetworkConnect::createConnect(KyConnectType connectType, const KyConnectInfo &connectInfo)
|
||||
void KyNetworkConnect::createConnect(KyConnectType connectType, const KyConnectSetting &connectInfo)
|
||||
{
|
||||
switch (connectType) {
|
||||
case WIRED_CONNECT:
|
||||
|
@ -175,7 +175,7 @@ void KyNetworkConnect::createConnect(KyConnectType connectType, const KyConnectI
|
|||
return;
|
||||
}
|
||||
|
||||
void KyNetworkConnect::updateConnect(const QString &connectUuid, const KyConnectInfo &connectInfo)
|
||||
void KyNetworkConnect::updateConnect(const QString &connectUuid, const KyConnectSetting &connectInfo)
|
||||
{
|
||||
qDebug()<<"update connect"<<connectUuid;
|
||||
NetworkManager::Connection::Ptr connectPtr =
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#define KYLINNETWORKCONNECT_H
|
||||
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include "kylinconnectinfo.h"
|
||||
#include "kylinconnectsetting.h"
|
||||
|
||||
typedef enum{
|
||||
WIRED_CONNECT,
|
||||
|
@ -35,8 +35,8 @@ public:
|
|||
~KyNetworkConnect();
|
||||
|
||||
public:
|
||||
void createConnect(KyConnectType connectType, const KyConnectInfo &connectInfo);
|
||||
void updateConnect(const QString &connectUuid, const KyConnectInfo &connectInfo);
|
||||
void createConnect(KyConnectType connectType, const KyConnectSetting &connectInfo);
|
||||
void updateConnect(const QString &connectUuid, const KyConnectSetting &connectInfo);
|
||||
void deleteConnect(const QString &connectUuid);
|
||||
int addAndActivateConnect(const QString );
|
||||
int activateConnection(const QString connectUuid);
|
||||
|
@ -49,13 +49,13 @@ public:
|
|||
private:
|
||||
void connectSettingInit(
|
||||
NetworkManager::ConnectionSettings::Ptr connectionSettings,
|
||||
const KyConnectInfo &connectInfo);
|
||||
const KyConnectSetting &connectInfo);
|
||||
void ipv4SettingInit(NetworkManager::Ipv4Setting::Ptr &ipv4Setting,
|
||||
const KyConnectInfo &connectInfo);
|
||||
const KyConnectSetting &connectInfo);
|
||||
void ipv6SettingInit(NetworkManager::Ipv6Setting::Ptr &ipv6Setting,
|
||||
const KyConnectInfo &connectInfo);
|
||||
const KyConnectSetting &connectInfo);
|
||||
|
||||
void createWiredConnect(const KyConnectInfo &connectInfo);
|
||||
void createWiredConnect(const KyConnectSetting &connectInfo);
|
||||
|
||||
signals:
|
||||
void activateConnectionFinished(NetworkManager::Connection::Ptr &conn);
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
|
||||
#include "kylinnetworkdeviceresource.h"
|
||||
|
||||
KyNetworkDeviceResourse::KyNetworkDeviceResourse()
|
||||
{
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceAdd, this, &KyNetworkDeviceResourse::deviceAdd);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceRemove, this, &KyNetworkDeviceResourse::deviceRemove);
|
||||
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceCarrierChanage, this, &KyNetworkDeviceResourse::carrierChanage);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceBitRateChanage, this, &KyNetworkDeviceResourse::deviceBitRateChanage);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceMacAddressChanaged, this, &KyNetworkDeviceResourse::deviceMacAddressChanaged);
|
||||
|
||||
}
|
||||
|
||||
KyNetworkDeviceResourse::~KyNetworkDeviceResourse()
|
||||
{
|
||||
m_networkResourceInstance = nullptr;
|
||||
}
|
||||
|
||||
void KyNetworkDeviceResourse::getWiredDevices(QStringList &wiredDeviceList)
|
||||
{
|
||||
qDebug()<<"[KyNetworkDeviceResourse]"<<"get device list";
|
||||
NetworkManager::Device::List networkDeviceList
|
||||
= m_networkResourceInstance->getNetworkDeviceList();
|
||||
|
||||
if (networkDeviceList.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<<devicePtr->interfaceName();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkDeviceResourse::getWiredHardwareInfo(QString ifaceName, KyWiredConnectItem *wiredItem)
|
||||
{
|
||||
qDebug()<<"[KyNetworkDeviceResourse]"<<"get wired hardware info"<<ifaceName;
|
||||
NetworkManager::Device::Ptr connectDevice =
|
||||
m_networkResourceInstance->getNetworkDevice(ifaceName);
|
||||
|
||||
if (nullptr != connectDevice && connectDevice->isValid()
|
||||
&& NetworkManager::Device::Ethernet == connectDevice->type()) {
|
||||
NetworkManager::WiredDevice *wiredDevicePtr =
|
||||
qobject_cast<NetworkManager::WiredDevice *>(connectDevice.data());
|
||||
wiredItem->m_hardAddress = wiredDevicePtr->hardwareAddress();
|
||||
wiredItem->m_bandWith = wiredDevicePtr->bitRate();
|
||||
} else {
|
||||
qWarning()<<"[KyNetworkDeviceResourse]"<<"getwiredhardwareinfo failed, the device" << ifaceName << "is not existed";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkManager::Device::State KyNetworkDeviceResourse::getDeviceState(QString deviceName)
|
||||
{
|
||||
qDebug()<<"[KyNetworkDeviceResourse]"<<deviceName<<"get device state";
|
||||
|
||||
NetworkManager::Device::Ptr connectDevice =
|
||||
m_networkResourceInstance->findDeviceInterface(deviceName);
|
||||
if (connectDevice->isValid()) {
|
||||
return connectDevice->state();
|
||||
}
|
||||
|
||||
qWarning()<<"[KyNetworkDeviceResourse]"<<"the device is not valid.";
|
||||
return NetworkManager::Device::State::UnknownState;
|
||||
}
|
||||
|
||||
bool KyNetworkDeviceResourse::wiredDeviceCarriered(QString deviceName)
|
||||
{
|
||||
qDebug()<<"[KyNetworkDeviceResourse]"<<deviceName<<"wired device is carriered";
|
||||
|
||||
NetworkManager::Device::Ptr connectDevice =
|
||||
m_networkResourceInstance->findDeviceInterface(deviceName);
|
||||
if (connectDevice->isValid()
|
||||
&& NetworkManager::Ethernet == connectDevice->type()) {
|
||||
NetworkManager::WiredDevice *wiredDevicePtr =
|
||||
qobject_cast<NetworkManager::WiredDevice *>(connectDevice.data());
|
||||
return wiredDevicePtr->carrier();
|
||||
}
|
||||
|
||||
qWarning()<<"[KyNetworkDeviceResourse]"<< deviceName <<" can not get carrier state.";
|
||||
return false;
|
||||
}
|
||||
|
||||
void KyNetworkDeviceResourse::setDeviceRefreshRate(QString deviceName, int ms)
|
||||
{
|
||||
qDebug()<<"[KyNetworkDeviceResourse]"<<deviceName<<"set device refresh rate"<<ms;
|
||||
|
||||
NetworkManager::Device::Ptr connectDevice =
|
||||
m_networkResourceInstance->findDeviceInterface(deviceName);
|
||||
if (connectDevice->isValid()) {
|
||||
NetworkManager::DeviceStatistics::Ptr deviceStatistics = connectDevice->deviceStatistics();
|
||||
deviceStatistics->setRefreshRateMs(ms);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkDeviceResourse::DeviceSpeed(QString deviceName, KyWiredConnectItem *wiredItem)
|
||||
{
|
||||
// qDebug()<<"[KyNetworkDeviceResourse]"<<deviceName<<"get deivce up and down speed.";
|
||||
|
||||
NetworkManager::Device::Ptr connectDevice =
|
||||
m_networkResourceInstance->findDeviceInterface(deviceName);
|
||||
if (connectDevice->isValid()) {
|
||||
NetworkManager::DeviceStatistics::Ptr deviceStatistics = connectDevice->deviceStatistics();
|
||||
wiredItem->m_upSpeed = deviceStatistics->txBytes();
|
||||
wiredItem->m_downSpeed = deviceStatistics->rxBytes();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
#ifndef KYLINNETORKDEVICERESOURCE_H
|
||||
#define KYLINNETORKDEVICERESOURCE_H
|
||||
|
||||
#include <QString>
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include "kylinwiredconnectitem.h"
|
||||
|
||||
class KyNetworkDeviceResourse : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KyNetworkDeviceResourse();
|
||||
~KyNetworkDeviceResourse();
|
||||
|
||||
signals:
|
||||
void deviceAdd(QString deviceName);
|
||||
void deviceUpdate(QString deviceName);
|
||||
void deviceRemove(QString deviceName);
|
||||
|
||||
void stateChange(QString deviceName, int state);
|
||||
void carrierChanage(QString deviceName, bool pluged);
|
||||
void deviceBitRateChanage(QString deviceName, int bitRate);
|
||||
void deviceMacAddressChanaged(QString deviceName, const QString &hwAddress);
|
||||
|
||||
public:
|
||||
void getWiredDevices(QStringList &wiredDeviceList);
|
||||
void getWiredHardwareInfo(QString ifaceName, KyWiredConnectItem *wiredItem);
|
||||
NetworkManager::Device::State getDeviceState(QString deviceName);
|
||||
bool wiredDeviceCarriered(QString deviceName);
|
||||
void DeviceSpeed(QString deviceName, KyWiredConnectItem *wiredItem);
|
||||
void setDeviceRefreshRate(QString deviceName, int ms);
|
||||
|
||||
private:
|
||||
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
|
||||
};
|
||||
#endif // KYLINNETORKDEVICERESOURCE_H
|
|
@ -55,7 +55,10 @@ KyNetworkResourceManager::KyNetworkResourceManager()
|
|||
// we need remove the connections manually.
|
||||
connect(NetworkManager::notifier(), &NetworkManager::Notifier::serviceDisappeared, this, &KyNetworkResourceManager::clearConnections);
|
||||
|
||||
qDebug() << m_activeConns.size() << m_connections.size() << m_devices.size();
|
||||
qDebug() <<"[KyNetworkResourceManager]"
|
||||
<< "active connections:" << m_activeConns.size()
|
||||
<< "connections:" << m_connections.size()
|
||||
<< "network device:" << m_devices.size();
|
||||
}
|
||||
|
||||
KyNetworkResourceManager::~KyNetworkResourceManager()
|
||||
|
@ -90,15 +93,14 @@ void KyNetworkResourceManager::addActiveConnection(NetworkManager::ActiveConnect
|
|||
connect(conn.data(), &NetworkManager::ActiveConnection::typeChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::masterChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::specificObjectChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::stateChangedReason, this, &KyNetworkResourceManager::onActiveConnectionChangedReason);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::stateChangedReason, this, &KyNetworkResourceManager::onActiveConnectionChangedReason);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::stateChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::vpnChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::uuidChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::devicesChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
if (conn->vpn())
|
||||
{
|
||||
if (conn->vpn()) {
|
||||
connect(qobject_cast<NetworkManager::VpnConnection *>(conn.data()), &NetworkManager::VpnConnection::bannerChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(qobject_cast<NetworkManager::VpnConnection *>(conn.data()), &NetworkManager::VpnConnection::stateChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(qobject_cast<NetworkManager::VpnConnection *>(conn.data()), &NetworkManager::VpnConnection::stateChanged, this, &KyNetworkResourceManager::onVpnActiveConnectChanagedReason);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,16 +119,18 @@ void KyNetworkResourceManager::removeConnection(int pos)
|
|||
|
||||
void KyNetworkResourceManager::clearConnections()
|
||||
{
|
||||
while (0 < m_connections.size())
|
||||
while (0 < m_connections.size()) {
|
||||
removeConnection(0);
|
||||
}
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::addConnection(NetworkManager::Connection::Ptr conn)
|
||||
{
|
||||
m_connections.push_back(conn);
|
||||
|
||||
//connections signals
|
||||
connect(conn.data(), &NetworkManager::Connection::updated, this, &KyNetworkResourceManager::onConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::Connection::removed, this, static_cast<void (KyNetworkResourceManager::*)()>(&KyNetworkResourceManager::onConnectionRemoved));
|
||||
connect(conn.data(), &NetworkManager::Connection::removed, this, &KyNetworkResourceManager::onConnectionRemoved);
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::insertConnections()
|
||||
|
@ -182,9 +186,9 @@ void KyNetworkResourceManager::addDevice(NetworkManager::Device::Ptr device)
|
|||
switch (device->type())
|
||||
{
|
||||
case NetworkManager::Ethernet:
|
||||
connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::bitRateChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
|
||||
connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::carrierChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
|
||||
connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::hardwareAddressChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
|
||||
connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::bitRateChanged, this, &KyNetworkResourceManager::onDeviceBitRateChanage);
|
||||
connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::carrierChanged, this, &KyNetworkResourceManager::onDeviceCarrierChanage);
|
||||
connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::hardwareAddressChanged, this, &KyNetworkResourceManager::onDeviceMacAddressChanaged);
|
||||
connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::permanentHardwareAddressChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
|
||||
break;
|
||||
|
||||
|
@ -237,15 +241,11 @@ void KyNetworkResourceManager::addWifiNetwork(NetworkManager::WirelessNetwork::P
|
|||
|
||||
void KyNetworkResourceManager::insertWifiNetworks()
|
||||
{
|
||||
for (auto const & device : m_devices)
|
||||
{
|
||||
if (NetworkManager::Device::Wifi == device->type())
|
||||
{
|
||||
for (auto const & device : m_devices) {
|
||||
if (NetworkManager::Device::Wifi == device->type()) {
|
||||
NetworkManager::WirelessDevice::Ptr w_dev = device.objectCast<NetworkManager::WirelessDevice>();
|
||||
for (auto const & net : w_dev->networks())
|
||||
{
|
||||
if (!net.isNull())
|
||||
{
|
||||
for (auto const & net : w_dev->networks()) {
|
||||
if (!net.isNull()) {
|
||||
addWifiNetwork(net);
|
||||
}
|
||||
}
|
||||
|
@ -288,37 +288,52 @@ NetworkManager::WirelessNetwork::Ptr KyNetworkResourceManager::findWifiNetwork(Q
|
|||
|
||||
NetworkManager::Device::Ptr KyNetworkResourceManager::getNetworkDevice(const QString ifaceName)
|
||||
{
|
||||
NetworkManager::Device::Ptr devicePtr = nullptr;
|
||||
if (ifaceName.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (int index = 0; index < m_devices.size(); ++index) {
|
||||
devicePtr = m_devices.at(index);
|
||||
if (ifaceName == devicePtr->interfaceName()) {
|
||||
return devicePtr;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NetworkManager::ActiveConnection::Ptr KyNetworkResourceManager::getActiveConnect(const QString connectUuid)
|
||||
NetworkManager::ActiveConnection::Ptr KyNetworkResourceManager::getActiveConnect(const QString activeConnectUuid)
|
||||
{
|
||||
int index = 0;
|
||||
NetworkManager::ActiveConnection::Ptr activateConnectPtr = nullptr;
|
||||
|
||||
qDebug()<<"get activetate connect with uuid"<<connectUuid;
|
||||
qDebug()<<"[KyNetworkResourceManager]"<<"get activetate connect with uuid"<< activeConnectUuid;
|
||||
if (activeConnectUuid.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (index = 0; index < m_activeConns.size(); ++index) {
|
||||
activateConnectPtr = m_activeConns.at(index);
|
||||
if (activateConnectPtr->uuid() == connectUuid) {
|
||||
if (activateConnectPtr->uuid() == activeConnectUuid) {
|
||||
return activateConnectPtr;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning()<<"it can not find the activate connect with uuid" <<connectUuid;
|
||||
qWarning()<<"[KyNetworkResourceManager]"<<"it can not find the activate connect with uuid" <<activeConnectUuid;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NetworkManager::Connection::Ptr KyNetworkResourceManager::getConnect(const QString connectUuid)
|
||||
{
|
||||
if(connectUuid.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
NetworkManager::Connection::Ptr connectPtr = nullptr;
|
||||
|
||||
qDebug()<<"get connect with uuid"<<connectUuid;
|
||||
qDebug()<<"[KyNetworkResourceManager]"<<"get connect with uuid"<<connectUuid;
|
||||
if (connectUuid.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (index = 0; index < m_connections.size(); ++index) {
|
||||
connectPtr = m_connections.at(index);
|
||||
|
@ -327,7 +342,7 @@ NetworkManager::Connection::Ptr KyNetworkResourceManager::getConnect(const QStri
|
|||
}
|
||||
}
|
||||
|
||||
qWarning()<<"it can not find connect with uuid"<<connectUuid;
|
||||
qWarning()<<"[KyNetworkResourceManager]"<<"it can not find connect with uuid"<<connectUuid;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -337,9 +352,44 @@ NetworkManager::WirelessNetwork::Ptr KyNetworkResourceManager::getWifiNetwork(co
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
NetworkManager::ActiveConnection::List KyNetworkResourceManager::getActiveConnectList()
|
||||
{
|
||||
return m_activeConns;
|
||||
}
|
||||
|
||||
NetworkManager::Connection::List KyNetworkResourceManager::getConnectList()
|
||||
{
|
||||
return m_connections;
|
||||
}
|
||||
|
||||
NetworkManager::Device::List KyNetworkResourceManager::getNetworkDeviceList()
|
||||
{
|
||||
return m_devices;
|
||||
}
|
||||
|
||||
bool KyNetworkResourceManager::isActiveConnection(QString uuid)
|
||||
{
|
||||
int index = 0;
|
||||
NetworkManager::ActiveConnection::Ptr activateConnectPtr = nullptr;
|
||||
|
||||
if (uuid.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (index = 0; index < m_activeConns.size(); ++index) {
|
||||
activateConnectPtr = m_activeConns.at(index);
|
||||
if (activateConnectPtr->uuid() == uuid
|
||||
&& NetworkManager::ActiveConnection::State::Activated == activateConnectPtr->state()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::requestScan(NetworkManager::WirelessDevice * dev)
|
||||
{
|
||||
qDebug() << __FUNCTION__ << dev->interfaceName();
|
||||
qDebug() <<"[KyNetworkResourceManager]"<< dev->interfaceName()<<"start scan wifi ap";
|
||||
QDBusPendingReply<> reply = dev->requestScan();
|
||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, dev);
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [dev] (QDBusPendingCallWatcher * watcher) {
|
||||
|
@ -355,24 +405,62 @@ void KyNetworkResourceManager::requestScan(NetworkManager::WirelessDevice * dev)
|
|||
|
||||
void KyNetworkResourceManager::onConnectionUpdated()
|
||||
{
|
||||
emit connectionUpdate(qobject_cast<NetworkManager::Connection *>(sender()));
|
||||
}
|
||||
NetworkManager::Connection *connectPtr =
|
||||
qobject_cast<NetworkManager::Connection *>(sender());
|
||||
|
||||
void KyNetworkResourceManager::onConnectionRemoved()
|
||||
{
|
||||
emit connectionRemove(qobject_cast<NetworkManager::Connection *>(sender()));
|
||||
qDebug()<<"[KyNetworkResourceManager]"<<"onConnectionUpdate "<<connectPtr->name()<<connectPtr->uuid();
|
||||
|
||||
if (connectPtr->isValid()) {
|
||||
emit connectionUpdate(connectPtr->uuid());
|
||||
} else {
|
||||
qWarning()<< "[KyNetworkResourceManager]"
|
||||
<<"connect update failed, the connect is invalid"
|
||||
<<connectPtr->name()
|
||||
<<connectPtr->uuid()
|
||||
<<connectPtr->path();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onActiveConnectionUpdated()
|
||||
{
|
||||
emit activeConnectionUpdate(qobject_cast<NetworkManager::ActiveConnection *>(sender()));
|
||||
//emit activeConnectionUpdate(qobject_cast<NetworkManager::ActiveConnection *>(sender()));
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onActiveConnectionChangedReason(NetworkManager::ActiveConnection::State state,
|
||||
void KyNetworkResourceManager::onActiveConnectionChangedReason(
|
||||
NetworkManager::ActiveConnection::State state,
|
||||
NetworkManager::ActiveConnection::Reason reason)
|
||||
{
|
||||
qWarning()<<"the active connect state"<<state;
|
||||
qWarning()<<"the active connect state chanager reason:"<<reason;
|
||||
NetworkManager::ActiveConnection * activeConnect =
|
||||
qobject_cast<NetworkManager::ActiveConnection *>(sender());
|
||||
if (activeConnect->isValid()) {
|
||||
qDebug()<<"state change activate connect"<<activeConnect->uuid();
|
||||
qDebug()<<"the active connect state"<<state;
|
||||
qDebug()<<"the active connect state chanager reason:"<<reason;
|
||||
emit activeConnectStateChangeReason(activeConnect->uuid(), state, reason);
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onVpnActiveConnectChanagedReason(NetworkManager::VpnConnection::State state,
|
||||
NetworkManager::VpnConnection::StateChangeReason reason)
|
||||
{
|
||||
NetworkManager::ActiveConnection *activeConnect =
|
||||
qobject_cast<NetworkManager::ActiveConnection *>(sender());
|
||||
|
||||
if (activeConnect->isValid()) {
|
||||
qDebug()<<"state change activate connect"<<activeConnect->uuid();
|
||||
qDebug()<<"the active connect state"<<state;
|
||||
qDebug()<<"the active connect state chanager reason:"<<reason;
|
||||
emit vpnActiveConnectStateChangeReason(activeConnect->uuid(), state, reason);
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -381,19 +469,56 @@ void KyNetworkResourceManager::onDeviceUpdated()
|
|||
emit deviceUpdate(qobject_cast<NetworkManager::Device *>(sender()));
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onDeviceCarrierChanage(bool pluged)
|
||||
{
|
||||
NetworkManager::WiredDevice * networkDevice
|
||||
= qobject_cast<NetworkManager::WiredDevice *>(sender());
|
||||
|
||||
qDebug()<<"device carrier chanage"<< pluged;
|
||||
if (networkDevice->isValid()) {
|
||||
emit deviceCarrierChanage(networkDevice->interfaceName(), pluged);
|
||||
} else {
|
||||
qWarning()<<"the device is not invalid";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onDeviceBitRateChanage(int bitRate)
|
||||
{
|
||||
NetworkManager::WiredDevice * networkDevice
|
||||
= qobject_cast<NetworkManager::WiredDevice *>(sender());
|
||||
|
||||
if (networkDevice->isValid()) {
|
||||
emit deviceBitRateChanage(networkDevice->interfaceName(), bitRate);
|
||||
} else {
|
||||
qWarning()<<"the device is not invalid";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onDeviceMacAddressChanaged(const QString &hwAddress)
|
||||
{
|
||||
NetworkManager::WiredDevice * networkDevice
|
||||
= qobject_cast<NetworkManager::WiredDevice *>(sender());
|
||||
|
||||
if (networkDevice->isValid()) {
|
||||
emit deviceMacAddressChanaged(networkDevice->interfaceName(), hwAddress);
|
||||
} else {
|
||||
qWarning()<<"the device is not invalid";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onDeviceStateChanged(
|
||||
NetworkManager::Device::State newstate,
|
||||
NetworkManager::Device::State oldstate,
|
||||
NetworkManager::Device::StateChangeReason reason)
|
||||
{
|
||||
NetworkManager::WiredDevice *wiredDevice = qobject_cast<NetworkManager::WiredDevice *>(sender());
|
||||
if (wiredDevice->carrier()) {
|
||||
qWarning()<<"the device carrier true";
|
||||
} else {
|
||||
qWarning()<<"the device carrier false";
|
||||
}
|
||||
|
||||
qWarning()<<"the device state "<<oldstate << "to" <<newstate << "reason"<< reason;
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onWifiNetworkAppeared(QString const & ssid)
|
||||
|
@ -417,113 +542,144 @@ void KyNetworkResourceManager::onWifiNetworkUpdated()
|
|||
|
||||
void KyNetworkResourceManager::onDeviceAdded(QString const & uni)
|
||||
{
|
||||
qDebug()<<Q_FUNC_INFO<<"onDeviceAdded"<<uni;
|
||||
qDebug()<< "onDeviceAdded"<<uni;
|
||||
|
||||
NetworkManager::Device::Ptr dev = NetworkManager::findNetworkInterface(uni);
|
||||
if (!dev.isNull()) {
|
||||
if (dev->isValid())
|
||||
qWarning() << Q_FUNC_INFO << uni << " is currently invalid...";
|
||||
|
||||
if (0 > m_devices.indexOf(dev)) {
|
||||
addDevice(dev);
|
||||
}
|
||||
|
||||
emit deviceAdd(dev);
|
||||
NetworkManager::Device::Ptr networkDevice = NetworkManager::findNetworkInterface(uni);
|
||||
if (networkDevice.isNull()) {
|
||||
qWarning()<<"the device is not exist in networkmanager."<< uni;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!networkDevice->isValid()) {
|
||||
qWarning() << uni << " is currently not invalid";
|
||||
return;
|
||||
}
|
||||
|
||||
if (0 > m_devices.indexOf(networkDevice)) {
|
||||
addDevice(networkDevice);
|
||||
emit deviceAdd(networkDevice->interfaceName());
|
||||
} else {
|
||||
qWarning() << networkDevice->interfaceName() <<"the device is exist in network device list.";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onDeviceRemoved(QString const & uni)
|
||||
{
|
||||
qDebug()<<Q_FUNC_INFO<<"onDeviceRemoved"<<uni;
|
||||
NetworkManager::Device::Ptr dev = findDeviceUni(uni);
|
||||
if (!dev.isNull())
|
||||
{
|
||||
if (dev->isValid())
|
||||
qWarning() << Q_FUNC_INFO << uni << " is currently invalid...";
|
||||
|
||||
auto index = std::find(m_devices.cbegin(), m_devices.cend(), dev);
|
||||
if (m_devices.cend() != index) {
|
||||
const int pos = index - m_devices.cbegin();
|
||||
removeDevice(pos);
|
||||
}
|
||||
|
||||
emit deviceRemove(dev.data());
|
||||
NetworkManager::Device::Ptr networkDevice = findDeviceUni(uni);
|
||||
if (networkDevice.isNull()) {
|
||||
qWarning()<<"the device is not exist in network device list ."<< uni;
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug()<<"remove network device"<< uni;
|
||||
|
||||
auto index = std::find(m_devices.cbegin(), m_devices.cend(), networkDevice);
|
||||
if (m_devices.cend() != index) {
|
||||
const int pos = index - m_devices.cbegin();
|
||||
removeDevice(pos);
|
||||
emit deviceRemove(networkDevice->interfaceName());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onActiveConnectionAdded(QString const & path)
|
||||
{
|
||||
NetworkManager::ActiveConnection::Ptr conn = NetworkManager::findActiveConnection(path);//XXX: const QString &uni
|
||||
if (!conn.isNull()) {
|
||||
if (conn->isValid())
|
||||
qWarning() << Q_FUNC_INFO << path << " is currently invalid...";
|
||||
|
||||
if (0 > m_activeConns.indexOf(conn)) {
|
||||
addActiveConnection(conn);
|
||||
} else {
|
||||
//TODO: onActiveConnectionUpdate
|
||||
qWarning() << Q_FUNC_INFO << "update active connection tp do";
|
||||
}
|
||||
|
||||
emit activeConnectionAdd(conn);
|
||||
NetworkManager::ActiveConnection::Ptr activeConnectPtr = NetworkManager::findActiveConnection(path);//XXX: const QString &uni
|
||||
if (activeConnectPtr.isNull()) {
|
||||
qWarning() << "[KyNetworkResourceManager]" << "the active connect is null, so do not add it."<<path;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!activeConnectPtr->isValid()) {
|
||||
qWarning() << "[KyNetworkResourceManager]" << path << " connect is currently not valid";
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug()<<"add active connect"<<activeConnectPtr->connection()->name();
|
||||
|
||||
if (0 > m_activeConns.indexOf(activeConnectPtr)) {
|
||||
addActiveConnection(activeConnectPtr);
|
||||
emit activeConnectionAdd(activeConnectPtr->uuid());
|
||||
} else {
|
||||
//TODO: onActiveConnectionUpdate
|
||||
qWarning() << "[KyNetworkResourceManager]" << "update active connection to do";
|
||||
//emit activeConnectionUpdate(conn->uuid());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onActiveConnectionRemoved(QString const & path)
|
||||
{
|
||||
NetworkManager::ActiveConnection::Ptr conn = findActiveConnection(path);//XXX: const QString &uni
|
||||
if (!conn.isNull()) {
|
||||
if (conn->isValid())
|
||||
qWarning() << Q_FUNC_INFO << path << " is currently invalid...";
|
||||
|
||||
auto index = std::find(m_activeConns.cbegin(), m_activeConns.cend(), conn);
|
||||
if (m_activeConns.cend() != index) {
|
||||
const int pos = index - m_activeConns.cbegin();
|
||||
removeActiveConnection(pos);
|
||||
}
|
||||
|
||||
emit activeConnectionRemove(conn.data());
|
||||
NetworkManager::ActiveConnection::Ptr activeConnectPtr = findActiveConnection(path);//XXX: const QString &uni
|
||||
if (activeConnectPtr.isNull()) {
|
||||
qWarning() <<"[KyNetworkResourceManager]"
|
||||
<<"the active connect is null, so do not remove it. "<< path;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onActiveConnectionsChanged()
|
||||
{
|
||||
emit activeConnectionsReset();
|
||||
qDebug() <<"[KyNetworkResourceManager]"<<"remove active connect"<<activeConnectPtr->uuid();
|
||||
|
||||
auto index = std::find(m_activeConns.cbegin(), m_activeConns.cend(), activeConnectPtr);
|
||||
if (m_activeConns.cend() != index) {
|
||||
const int pos = index - m_activeConns.cbegin();
|
||||
removeActiveConnection(pos);
|
||||
emit activeConnectionRemove(activeConnectPtr->uuid());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onConnectionAdded(QString const & path)
|
||||
{
|
||||
NetworkManager::Connection::Ptr conn = NetworkManager::findConnection(path);
|
||||
if (!conn.isNull())
|
||||
{
|
||||
if (conn->isValid())
|
||||
qWarning() << Q_FUNC_INFO << path << " is currently invalid...";
|
||||
|
||||
if (0 > m_connections.indexOf(conn)) {
|
||||
addConnection(conn);
|
||||
} else {
|
||||
//TODO: onConnectionUpdate
|
||||
}
|
||||
|
||||
emit connectionAdd(conn);
|
||||
NetworkManager::Connection::Ptr connectPtr = NetworkManager::findConnection(path);
|
||||
if (connectPtr.isNull()) {
|
||||
qWarning() <<"[KyNetworkResourceManager]" <<"it can not find in networkmanager."<<path;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!connectPtr->isValid()) {
|
||||
qWarning() <<"[KyNetworkResourceManager]" << path << " is currently not invalid";
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() <<"[KyNetworkResourceManager]" <<"add connect "<< connectPtr->name() << connectPtr->path();
|
||||
|
||||
if (0 > m_connections.indexOf(connectPtr)) {
|
||||
addConnection(connectPtr);
|
||||
emit connectionAdd(connectPtr->uuid());
|
||||
} else {
|
||||
//TODO::updateconnect
|
||||
qWarning() << "[KyNetworkResourceManager]" << connectPtr->uuid() <<" connect is exist in connect list.";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onConnectionRemoved(QString const & path)
|
||||
{
|
||||
NetworkManager::Connection::Ptr conn = NetworkManager::findConnection(path);
|
||||
if (!conn.isNull()) {
|
||||
if (conn->isValid())
|
||||
qWarning() << Q_FUNC_INFO << path << " is currently invalid...";
|
||||
|
||||
auto index = std::find(m_connections.cbegin(), m_connections.cend(), conn);
|
||||
if (m_connections.cend() != index) {
|
||||
const int pos = index - m_connections.cbegin();
|
||||
removeConnection(pos);
|
||||
}
|
||||
|
||||
emit connectionRemove(conn.data());
|
||||
if (path.isEmpty()) {
|
||||
qDebug() <<"[KyNetworkResourceManager]" <<"the connect path is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() <<"[KyNetworkResourceManager]" << "remove connection path" << path;
|
||||
NetworkManager::Connection::Ptr connectionPtr = nullptr;
|
||||
for (int index = 0; index < m_connections.size(); ++index) {
|
||||
connectionPtr = m_connections.at(index);
|
||||
if (connectionPtr->path() == path) {
|
||||
removeConnection(index);
|
||||
emit connectionRemove(path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() <<"[KyNetworkResourceManager]" << path <<" connect is no exist in connect list";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::removeConnection(QString const & uuid)
|
||||
|
@ -535,3 +691,16 @@ void KyNetworkResourceManager::removeConnection(QString const & uuid)
|
|||
conn->remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KyNetworkResourceManager::connectionDump()
|
||||
{
|
||||
NetworkManager::Connection::Ptr connectionPtr = nullptr;
|
||||
for (int index = 0; index < m_connections.size(); ++index) {
|
||||
connectionPtr = m_connections.at(index);
|
||||
qDebug()<<"connection info**********************";
|
||||
qDebug()<<"connection name"<< connectionPtr->name();
|
||||
qDebug()<<"connection uuid"<< connectionPtr->uuid();
|
||||
qDebug()<<"connection uuid"<< connectionPtr->path();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,40 +86,63 @@ public:
|
|||
|
||||
void removeConnection(QString const & uuid);
|
||||
|
||||
void connectionDump();
|
||||
|
||||
public:
|
||||
NetworkManager::Device::Ptr getNetworkDevice(const QString ifaceName);
|
||||
NetworkManager::ActiveConnection::Ptr getActiveConnect(const QString uuid);
|
||||
NetworkManager::ActiveConnection::Ptr getActiveConnect(const QString activeConnectUuid);
|
||||
NetworkManager::Connection::Ptr getConnect(const QString uuid);
|
||||
NetworkManager::WirelessNetwork::Ptr getWifiNetwork(const QString apName);
|
||||
|
||||
NetworkManager::ActiveConnection::List getActiveConnectList();
|
||||
NetworkManager::Connection::List getConnectList();
|
||||
NetworkManager::Device::List getNetworkDeviceList();
|
||||
bool isActiveConnection(QString uuid);
|
||||
|
||||
signals:
|
||||
void connectionAdd(NetworkManager::Connection::Ptr conn);
|
||||
void connectionUpdate(NetworkManager::Connection * conn);
|
||||
void connectionRemove(NetworkManager::Connection * conn);
|
||||
void activeConnectionAdd(NetworkManager::ActiveConnection::Ptr conn);
|
||||
void activeConnectionUpdate(NetworkManager::ActiveConnection * conn);
|
||||
void activeConnectionRemove(NetworkManager::ActiveConnection * conn);
|
||||
void activeConnectionsReset();
|
||||
void deviceAdd(NetworkManager::Device::Ptr dev);
|
||||
void connectionAdd(QString uuid);
|
||||
void connectionUpdate(QString uuid);
|
||||
void connectionRemove(QString path);
|
||||
|
||||
void deviceAdd(QString deviceName);
|
||||
void deviceUpdate(NetworkManager::Device * dev);
|
||||
void deviceRemove(NetworkManager::Device * dev);
|
||||
void deviceRemove(QString deviceName);
|
||||
|
||||
void deviceCarrierChanage(QString deviceName, bool pluged);
|
||||
void deviceBitRateChanage(QString deviceName, int bitRate);
|
||||
void deviceMacAddressChanaged(QString deviceName, const QString &hwAddress);
|
||||
|
||||
void wifiNetworkAdd(NetworkManager::Device * dev, QString const & ssid);
|
||||
void wifiNetworkUpdate(NetworkManager::WirelessNetwork * net);
|
||||
void wifiNetworkRemove(NetworkManager::Device * dev, QString const & ssid);
|
||||
|
||||
void activeConnectionAdd(QString uuid);
|
||||
void activeConnectionUpdate(QString uuid);
|
||||
void activeConnectionRemove(QString uuid);
|
||||
void activeConnectStateChangeReason(QString uuid,
|
||||
NetworkManager::ActiveConnection::State state,
|
||||
NetworkManager::ActiveConnection::Reason reason);
|
||||
void vpnActiveConnectStateChangeReason(QString uuid,
|
||||
NetworkManager::VpnConnection::State state,
|
||||
NetworkManager::VpnConnection::StateChangeReason reason);
|
||||
|
||||
private slots:
|
||||
//connection
|
||||
void onConnectionUpdated();
|
||||
void onConnectionRemoved();
|
||||
//void onConnectionRemoved();
|
||||
|
||||
//active connection
|
||||
void onActiveConnectionUpdated();
|
||||
void onActiveConnectionChangedReason(NetworkManager::ActiveConnection::State state,
|
||||
NetworkManager::ActiveConnection::Reason reason);
|
||||
void onVpnActiveConnectChanagedReason(NetworkManager::VpnConnection::State state,
|
||||
NetworkManager::VpnConnection::StateChangeReason reason);
|
||||
|
||||
//device
|
||||
void onDeviceUpdated();
|
||||
void onDeviceCarrierChanage(bool pluged);
|
||||
void onDeviceBitRateChanage(int bitRate);
|
||||
void onDeviceMacAddressChanaged(const QString &hwAddress);
|
||||
void onDeviceStateChanged(NetworkManager::Device::State newstate,
|
||||
NetworkManager::Device::State oldstate,
|
||||
NetworkManager::Device::StateChangeReason reason);
|
||||
|
@ -134,7 +157,6 @@ private slots:
|
|||
void onDeviceRemoved(QString const & uni);
|
||||
void onActiveConnectionAdded(QString const & path);
|
||||
void onActiveConnectionRemoved(QString const & path);
|
||||
void onActiveConnectionsChanged();
|
||||
|
||||
//settings notifier
|
||||
void onConnectionAdded(QString const & path);
|
||||
|
@ -147,7 +169,6 @@ public:
|
|||
NetworkManager::Connection::List m_connections;
|
||||
NetworkManager::Device::List m_devices;
|
||||
NetworkManager::WirelessNetwork::List m_wifiNets;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
#include "kylinvpnconnectitem.h"
|
||||
|
||||
|
||||
KyVpnConnectItem::KyVpnConnectItem()
|
||||
{
|
||||
m_vpnName = "";
|
||||
m_vpnUuid = "";
|
||||
|
||||
m_vpnUser = "";
|
||||
m_vpnGateWay = "";
|
||||
|
||||
m_vpnIpv4Address = "";
|
||||
m_vpnIpv6Address = "";
|
||||
|
||||
m_vpnMppe = false;
|
||||
m_vpnState = NetworkManager::VpnConnection::State::Disconnected;
|
||||
}
|
||||
|
||||
KyVpnConnectItem::~KyVpnConnectItem()
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef KYLINVPNCONNECTITEM_H
|
||||
#define KYLINVPNCONNECTITEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <NetworkManagerQt/VpnConnection>
|
||||
#include <NetworkManagerQt/VpnSetting>
|
||||
|
||||
class KyVpnConnectItem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KyVpnConnectItem();
|
||||
~KyVpnConnectItem();
|
||||
|
||||
public:
|
||||
QString m_vpnName;
|
||||
QString m_vpnUuid;
|
||||
|
||||
QString m_vpnUser;
|
||||
QString m_vpnGateWay;
|
||||
|
||||
QString m_vpnIpv4Address;
|
||||
QString m_vpnIpv6Address;
|
||||
|
||||
bool m_vpnMppe;
|
||||
NetworkManager::VpnConnection::State m_vpnState;
|
||||
};
|
||||
|
||||
|
||||
#endif // KYLINVPNCONNECTITEM_H
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
#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:"<<m_connectName;
|
||||
qDebug()<<"connect uuid:"<<m_connectUuid;
|
||||
qDebug()<<"iface name:"<<m_ifaceName;
|
||||
|
||||
qDebug()<<"ipv4 address:"<<m_ipv4;
|
||||
qDebug()<<"ipv6 address:"<<m_ipv6;
|
||||
qDebug()<<"hard address:"<<m_hardAddress;
|
||||
|
||||
qDebug()<<"band width:"<< m_bandWith;
|
||||
qDebug()<<"up speed:"<<m_upSpeed;
|
||||
qDebug()<<"down speed:"<<m_downSpeed;
|
||||
|
||||
qDebug()<<"state:"<<m_state;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef KYLINWIREDCONNECTITEM_H
|
||||
#define KYLINWIREDCONNECTITEM_H
|
||||
|
||||
#include <QString>
|
||||
#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
|
|
@ -0,0 +1,285 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "kylinwiredconnectoperation.h"
|
||||
|
||||
#include <NetworkManagerQt/AdslDevice>
|
||||
#include <NetworkManagerQt/WiredDevice>
|
||||
#include <NetworkManagerQt/Ipv4Setting>
|
||||
#include <NetworkManagerQt/Ipv6Setting>
|
||||
#include <NetworkManagerQt/WiredSetting>
|
||||
|
||||
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<NetworkManager::Ipv4Setting>();
|
||||
ipv4SettingSet(ipv4Setting, connectSettingsInfo);
|
||||
|
||||
NetworkManager::Ipv6Setting::Ptr ipv6Setting = wiredConnectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast<NetworkManager::Ipv6Setting>();
|
||||
ipv6SettingSet(ipv6Setting, connectSettingsInfo);
|
||||
|
||||
NetworkManager::WiredSetting::Ptr wiredSetting = wiredConnectionSettings->setting(NetworkManager::Setting::Wired).dynamicCast<NetworkManager::WiredSetting>();
|
||||
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()<<errorMessage;
|
||||
emit this->createConnectionError(errorMessage);
|
||||
} else {
|
||||
qDebug()<<"create wired connect complete";
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredConnectOperation::updateWiredConnect(const QString &connectUuid, const KyConnectSetting &connectSettingsInfo)
|
||||
{
|
||||
qDebug()<<"update connect"<<connectUuid;
|
||||
NetworkManager::Connection::Ptr connectPtr =
|
||||
NetworkManager::findConnectionByUuid(connectUuid);
|
||||
if (nullptr == connectPtr) {
|
||||
QString errorMessage = tr("it can not find connection") + connectUuid;
|
||||
qWarning()<<errorMessage;
|
||||
Q_EMIT updateConnectionError(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr connectionSettings = connectPtr->settings();
|
||||
connectionSettings->setId(connectSettingsInfo.m_connectName);
|
||||
connectionSettings->setInterfaceName(connectSettingsInfo.m_ifaceName);
|
||||
|
||||
NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast<NetworkManager::Ipv4Setting>();
|
||||
ipv4SettingSet(ipv4Setting, connectSettingsInfo);
|
||||
|
||||
NetworkManager::Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast<NetworkManager::Ipv6Setting>();
|
||||
ipv6SettingSet(ipv6Setting, connectSettingsInfo);
|
||||
|
||||
NetworkManager::WiredSetting::Ptr wiredSetting = connectionSettings->setting(NetworkManager::Setting::Wired).dynamicCast<NetworkManager::WiredSetting>();
|
||||
wiredSetting->setInitialized(true);
|
||||
|
||||
connectPtr->update(connectionSettings->toMap());
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
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()<<errorMessage;
|
||||
Q_EMIT deleteConnectionError(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
connectPtr->remove();
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
void KyWiredConnectOperation::activateWiredConnection(const QString connectUuid)
|
||||
{
|
||||
QString connectPath = "";
|
||||
QString deviceIdentifier = "";
|
||||
QString connectName = "";
|
||||
QString deviceName = "";
|
||||
QString specificObject = "";
|
||||
NetworkManager::Connection::Ptr connectPtr = nullptr;
|
||||
|
||||
qDebug()<<"it will activate connect"<<connectUuid;
|
||||
connectPtr = NetworkManager::findConnectionByUuid(connectUuid);
|
||||
if (nullptr == connectPtr) {
|
||||
QString errorMessage = "the connect uuid " + connectUuid + "is not exsit";
|
||||
qWarning()<<errorMessage;
|
||||
Q_EMIT activateConnectionError(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (NetworkManager::ConnectionSettings::Wired != connectPtr->settings()->connectionType()) {
|
||||
QString errorMessage = tr("the connect type is")
|
||||
+ connectPtr->settings()->connectionType()
|
||||
+ tr(", but it is not wired");
|
||||
qWarning()<<errorMessage;
|
||||
Q_EMIT activateConnectionError(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
connectPath = connectPtr->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()<<errorMessage;
|
||||
emit this->activateConnectionError(errorMessage);
|
||||
} else {
|
||||
qWarning()<<"active wired connect complete.";
|
||||
}
|
||||
|
||||
watcher->deleteLater();
|
||||
});
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
void KyWiredConnectOperation::deactivateWiredConnection(const QString activeConnectName, const QString &activeConnectUuid)
|
||||
{
|
||||
NetworkManager::ActiveConnection::Ptr activateConnectPtr = nullptr;
|
||||
|
||||
qDebug()<<"deactivetate connect name"<<activeConnectName<<"uuid"<<activeConnectUuid;
|
||||
activateConnectPtr = m_networkResourceInstance->getActiveConnect(activeConnectUuid);
|
||||
if (nullptr == activateConnectPtr) {
|
||||
QString errorMessage = tr("it can not find the activate connect")
|
||||
+ activeConnectName + tr("uuid") + activeConnectUuid;
|
||||
qWarning()<<errorMessage;
|
||||
Q_EMIT deactivateConnectionError(errorMessage);
|
||||
return ;
|
||||
}
|
||||
|
||||
qDebug() <<"dead active connection path:"<< activateConnectPtr->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()<<errorMessage;
|
||||
emit this->deactivateConnectionError(errorMessage);
|
||||
} else {
|
||||
qWarning() << "deactive connect operation finished" << activateConnectPtr->connection()->name();
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef KYLINWIREDCONNECTOPERATION_H
|
||||
#define KYLINWIREDCONNECTOPERATION_H
|
||||
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include "kylinconnectsetting.h"
|
||||
|
||||
class KyWiredConnectOperation : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KyWiredConnectOperation();
|
||||
~KyWiredConnectOperation();
|
||||
|
||||
public:
|
||||
void createWiredConnect(KyConnectSetting &connectSettingsInfo);
|
||||
void updateWiredConnect(const QString &connectUuid, const KyConnectSetting &connectSettingsInfo);
|
||||
void deleteWiredConnect(const QString &connectUuid);
|
||||
void activateWiredConnection(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
|
|
@ -0,0 +1,201 @@
|
|||
#include "kylinwiredwidget.h"
|
||||
|
||||
KyWiredWidget::KyWiredWidget(QWidget *parent):QWidget(parent)
|
||||
{
|
||||
m_activeConnectResource = new KyActiveConnectResourse();
|
||||
m_connectResource = new KyConnectResourse();
|
||||
m_deviceResource = new KyNetworkDeviceResourse();
|
||||
|
||||
connect(m_activeConnectResource, &KyActiveConnectResourse::activeConnectRemove,
|
||||
this, &KyWiredWidget::removeActiveConnection);
|
||||
connect(m_activeConnectResource, &KyActiveConnectResourse::stateChangeReason,
|
||||
this, &KyWiredWidget::activeConnectStateChange);
|
||||
|
||||
connect(m_connectResource, &KyConnectResourse::connectionAdd, this, &KyWiredWidget::addConnection);
|
||||
connect(m_connectResource, &KyConnectResourse::connectionRemove, this, &KyWiredWidget::removeConnection);
|
||||
connect(m_connectResource, &KyConnectResourse::connectionUpdate, this, &KyWiredWidget::updateConnection);
|
||||
|
||||
connect(m_deviceResource, &KyNetworkDeviceResourse::carrierChanage,this, &KyWiredWidget::wiredDeviceCarrierChange);
|
||||
|
||||
m_timer = new QTimer(this);
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(updateWidgetList()));
|
||||
}
|
||||
KyWiredWidget::~KyWiredWidget()
|
||||
{
|
||||
delete m_activeConnectResource;
|
||||
delete m_connectResource;
|
||||
delete m_deviceResource;
|
||||
}
|
||||
|
||||
void KyWiredWidget::constructWiredActiveConnectList()
|
||||
{
|
||||
qDebug()<<"constructWiredActiveConnectList";
|
||||
QList<KyWiredConnectItem *> wiredActiveConnect;
|
||||
m_activeConnectResource->getWiredActivateConnect(wiredActiveConnect);
|
||||
if (wiredActiveConnect.isEmpty()) {
|
||||
OneLancForm *activeWiredForm = new OneLancForm(this, nullptr);
|
||||
activeWiredForm->constructActiveConnectionEmptyItem();
|
||||
m_wiredActiveFormlist<<activeWiredForm;
|
||||
} else {
|
||||
for (int index = 0; index < wiredActiveConnect.size(); ++index) {
|
||||
resize(width(), height() + H_NORMAL_ITEM * index);
|
||||
OneLancForm *activeWiredForm = new OneLancForm(this, wiredActiveConnect.at(index));
|
||||
activeWiredForm->constructActiveConnectionItem(index);
|
||||
m_wiredActiveFormlist<<activeWiredForm;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredWidget::setType(WIDGETTYPE type)
|
||||
{
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
void KyWiredWidget::constructWiredConnectList()
|
||||
{
|
||||
qDebug()<<"constructWiredConnectList.....";
|
||||
QList<KyWiredConnectItem *> wiredConnections;
|
||||
m_connectResource->getWiredConnections(wiredConnections);
|
||||
if (!wiredConnections.isEmpty()) {
|
||||
for (int index = 0; index < wiredConnections.size(); ++index) {
|
||||
resize(W_LIST_WIDGET, height() + H_NORMAL_ITEM);
|
||||
OneLancForm *wiredForm = new OneLancForm(this, wiredConnections.at(index));
|
||||
wiredForm->constructConnectionItem(index);
|
||||
m_wiredFormlist<<wiredForm;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredWidget::updateWiredActiveConnection()
|
||||
{
|
||||
qDebug()<<"updateWiredActiveConnection......";
|
||||
while (!m_wiredActiveFormlist.empty()) {
|
||||
OneLancForm *wiredActiveForm = m_wiredActiveFormlist.at(0);
|
||||
m_wiredActiveFormlist.removeAt(0);
|
||||
delete wiredActiveForm;
|
||||
wiredActiveForm = nullptr;
|
||||
}
|
||||
|
||||
constructWiredActiveConnectList();
|
||||
}
|
||||
|
||||
void KyWiredWidget::updateWiredConnection()
|
||||
{
|
||||
qDebug()<<"updateWiredConnection........";
|
||||
while (!m_wiredFormlist.empty()) {
|
||||
OneLancForm *wiredForm = m_wiredFormlist.at(0);
|
||||
m_wiredFormlist.removeAt(0);
|
||||
qDebug()<<"delete item"<< wiredForm->uuidName;
|
||||
delete wiredForm;
|
||||
wiredForm = nullptr;
|
||||
}
|
||||
|
||||
constructWiredConnectList();
|
||||
}
|
||||
|
||||
void KyWiredWidget::updateWidgetList()
|
||||
{
|
||||
m_timer->stop();
|
||||
|
||||
if (ACTIVECONNECTION == m_type) {
|
||||
updateWiredActiveConnection();
|
||||
} else {
|
||||
updateWiredConnection();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredWidget::removeActiveConnection(QString connectUuid)
|
||||
{
|
||||
m_timer->start(300);
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredWidget::activeConnectStateChange(QString connectUuid,
|
||||
NetworkManager::ActiveConnection::State state,
|
||||
NetworkManager::ActiveConnection::Reason reason)
|
||||
{
|
||||
qDebug()<<"active connection"<<connectUuid
|
||||
<<"state"<<state <<"change reason"<<reason;
|
||||
if (NetworkManager::ActiveConnection::State::Activated == state) {
|
||||
m_timer->start(300);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredWidget::addConnection(QString connectUuid)
|
||||
{
|
||||
qDebug()<<"add connection "<<connectUuid;
|
||||
|
||||
if (CONNECTION == m_type) {
|
||||
updateWiredConnection();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredWidget::updateConnection(QString connectUuid)
|
||||
{
|
||||
qDebug() << "update connection" << connectUuid;
|
||||
|
||||
if (CONNECTION == m_type) {
|
||||
updateWiredConnection();
|
||||
} else {
|
||||
updateWiredActiveConnection();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredWidget::removeConnection(QString path)
|
||||
{
|
||||
qDebug()<<"remove connection"<< path;
|
||||
|
||||
if (CONNECTION == m_type) {
|
||||
updateWiredConnection();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredWidget::wiredDeviceCarrierChange(QString deviceName, bool pluged)
|
||||
{
|
||||
qDebug()<<"device"<< deviceName << "carrier state"<< pluged;
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredWidget::updateDeviceRefreshRate(QString deviceName, int ms)
|
||||
{
|
||||
m_deviceResource->setDeviceRefreshRate(deviceName, ms);
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredWidget::updateNetworkSpeed(KyWiredConnectItem *wiredItem)
|
||||
{
|
||||
qulonglong txBytes = wiredItem->m_upSpeed;
|
||||
qulonglong rxBytes = wiredItem->m_downSpeed;
|
||||
|
||||
m_deviceResource->DeviceSpeed(wiredItem->m_ifaceName, wiredItem);
|
||||
|
||||
if (wiredItem->m_upSpeed > txBytes) {
|
||||
txBytes = wiredItem->m_upSpeed - txBytes;
|
||||
} else {
|
||||
txBytes = 0;
|
||||
}
|
||||
|
||||
if (wiredItem->m_downSpeed > rxBytes) {
|
||||
rxBytes = wiredItem->m_downSpeed - rxBytes;
|
||||
} else {
|
||||
rxBytes = 0;
|
||||
}
|
||||
|
||||
emit updateSpeed(rxBytes, txBytes);
|
||||
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef KYLINWIREDWIDGET_H
|
||||
#define KYLINWIREDWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "kylinactiveconnectresource.h"
|
||||
#include "kylinconnectresource.h"
|
||||
#include "kylinnetworkdeviceresource.h"
|
||||
#include "kylinwiredconnectitem.h"
|
||||
#include "onelancform.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
typedef enum{
|
||||
ACTIVECONNECTION,
|
||||
CONNECTION,
|
||||
}WIDGETTYPE;
|
||||
|
||||
class KyWiredWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KyWiredWidget(QWidget *parent = nullptr);
|
||||
~KyWiredWidget();
|
||||
|
||||
void setType(WIDGETTYPE type);
|
||||
void constructWiredConnectList();
|
||||
void constructWiredActiveConnectList();
|
||||
|
||||
void updateDeviceRefreshRate(QString deviceName, int ms);
|
||||
void updateNetworkSpeed(KyWiredConnectItem *wiredItem);
|
||||
|
||||
private:
|
||||
void updateWiredActiveConnection();
|
||||
void updateWiredConnection();
|
||||
|
||||
signals:
|
||||
void updateSpeed(qulonglong rx, qulonglong tx);
|
||||
|
||||
public slots:
|
||||
void removeActiveConnection(QString connectUuid);
|
||||
void activeConnectStateChange(QString uuid,
|
||||
NetworkManager::ActiveConnection::State state,
|
||||
NetworkManager::ActiveConnection::Reason reason);
|
||||
|
||||
void addConnection(QString connectUuid);
|
||||
void updateConnection(QString connectUuid);
|
||||
void removeConnection(QString path);
|
||||
|
||||
void wiredDeviceCarrierChange(QString deviceName, bool pluged);
|
||||
|
||||
void updateWidgetList();
|
||||
private:
|
||||
WIDGETTYPE m_type;
|
||||
QTimer *m_timer;
|
||||
|
||||
KyActiveConnectResourse *m_activeConnectResource = nullptr;
|
||||
KyConnectResourse *m_connectResource = nullptr;
|
||||
KyNetworkDeviceResourse *m_deviceResource = nullptr;
|
||||
|
||||
QList<OneLancForm*> m_wiredActiveFormlist;
|
||||
QList<OneLancForm*> m_wiredFormlist;
|
||||
};
|
||||
|
||||
#endif // KYLINWIREDWIDGET_H
|
|
@ -24,6 +24,7 @@
|
|||
#include "hot-spot/dlghotspotcreate.h"
|
||||
#include "wireless-security/dlghidewifi.h"
|
||||
#include "sysdbusregister.h"
|
||||
#include "kylinwiredwidget.h"
|
||||
|
||||
#include <algorithm>//sort函数包含的头文件
|
||||
|
||||
|
@ -138,25 +139,26 @@ void MainWindow::secondaryStart()
|
|||
|
||||
qDebug()<<"Init ksnm...";
|
||||
this->ksnm = new KSimpleNM();
|
||||
#if 0
|
||||
connect(ksnm, SIGNAL(getLanListFinished(QStringList)), this, SLOT(getLanListDone(QStringList)));
|
||||
connect(ksnm, SIGNAL(getWifiListFinished(QStringList)), this, SLOT(getWifiListDone(QStringList)));
|
||||
connect(ksnm, SIGNAL(getConnListFinished(QStringList)), this, SLOT(getConnListDone(QStringList)));
|
||||
connect(ksnm, SIGNAL(requestRevalueUpdateWifi()), this, SLOT(onRequestRevalueUpdateWifi()));
|
||||
|
||||
#endif
|
||||
qDebug()<<"Init LoadingDiv...";
|
||||
loading = new LoadingDiv(this);
|
||||
loading->move(40,0);
|
||||
connect(loading, SIGNAL(toStopLoading() ), this, SLOT(on_checkOverTime() ));
|
||||
|
||||
checkIsWirelessDevicePluggedIn(); //检测无线网卡是否插入
|
||||
initLanSlistAndGetReconnectNetList(); //初始化有线网列表
|
||||
//initLanSlistAndGetReconnectNetList(); //初始化有线网列表
|
||||
initNetwork(); //初始化网络
|
||||
initTimer(); //初始化定时器
|
||||
initActNetDNS();//初始化已连接网络的DNS
|
||||
getSystemFontFamily();//建立GSetting监听系统字体
|
||||
|
||||
qDebug()<<"Init button connections...";
|
||||
connect(ui->btnNetList, &QPushButton::clicked, this, &MainWindow::onBtnNetListClicked);
|
||||
connect(ui->btnNetList, &QPushButton::clicked, this, &MainWindow::onBtnNetListClickeds);
|
||||
connect(btnWireless, &SwitchButton::clicked,this, &MainWindow::onBtnWifiClicked);
|
||||
connect(btnWired, &SwitchButton::clicked, this, &MainWindow::onBtnLanClicked);
|
||||
connect(this, &MainWindow::onWiredDeviceChanged, this, &MainWindow::setLanSwitchStatus);
|
||||
|
@ -289,9 +291,13 @@ void MainWindow::editQssString()
|
|||
void MainWindow::createTopLanUI()
|
||||
{
|
||||
qDebug()<<"Creating Top Lan UI...";
|
||||
topLanListWidget = new QWidget(ui->centralWidget);
|
||||
topLanListWidget = new KyWiredWidget(ui->centralWidget);
|
||||
topLanListWidget->setType(ACTIVECONNECTION);
|
||||
topLanListWidget->move(W_LEFT_AREA, Y_TOP_ITEM);
|
||||
topLanListWidget->resize(W_TOP_LIST_WIDGET, H_NORMAL_ITEM + H_GAP_UP + X_ITEM);
|
||||
|
||||
connect(topLanListWidget, &KyWiredWidget::updateSpeed, this, &MainWindow::on_setNetSpeeds);
|
||||
|
||||
/*顶部的一个item*/
|
||||
lbTopLanList = new QLabel(topLanListWidget);
|
||||
lbTopLanList->setText(tr("Ethernet Networks"));//"可用网络列表"
|
||||
|
@ -381,7 +387,8 @@ void MainWindow::createListAreaUI()
|
|||
scrollAreaw->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
scrollAreaw->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
|
||||
lanListWidget = new QWidget(scrollAreal);
|
||||
lanListWidget = new KyWiredWidget(scrollAreal);
|
||||
lanListWidget->setType(CONNECTION);
|
||||
wifiListWidget = new QWidget(scrollAreaw);
|
||||
lbLanList = new QLabel(lanListWidget);
|
||||
lbWifiList = new QLabel(wifiListWidget);
|
||||
|
@ -592,7 +599,7 @@ void MainWindow::initNetwork()
|
|||
if (iface->lstate == 0) {
|
||||
connLanDone(3);
|
||||
}
|
||||
onBtnNetListClicked();
|
||||
onBtnNetListClickeds();
|
||||
|
||||
ui->btnNetList->setStyleSheet("QPushButton{border:0px solid rgba(255,255,255,0);background-color:rgba(255,255,255,0);}");
|
||||
ui->btnWifiList->setStyleSheet("QPushButton{border:none;}");
|
||||
|
@ -618,7 +625,7 @@ void MainWindow::initNetwork()
|
|||
char *chr = "nmcli networking on";
|
||||
Utils::m_system(chr);
|
||||
|
||||
onBtnNetListClicked();
|
||||
onBtnNetListClickeds();
|
||||
|
||||
ui->btnNetList->setStyleSheet("QPushButton{border:0px solid rgba(255,255,255,0);background-color:rgba(255,255,255,0);}");
|
||||
ui->btnWifiList->setStyleSheet("QPushButton{border:none;}");
|
||||
|
@ -652,24 +659,24 @@ void MainWindow::initTimer()
|
|||
//网线插入时定时执行
|
||||
wiredCableUpTimer = new QTimer(this);
|
||||
wiredCableUpTimer->setTimerType(Qt::PreciseTimer);
|
||||
QObject::connect(wiredCableUpTimer, SIGNAL(timeout()), this, SLOT(onCarrierUpHandle()));
|
||||
// QObject::connect(wiredCableUpTimer, SIGNAL(timeout()), this, SLOT(onCarrierUpHandle()));
|
||||
|
||||
//网线拔出时定时执行
|
||||
// wiredCableDownTimer = new QTimer(this);
|
||||
// wiredCableDownTimer->setTimerType(Qt::PreciseTimer);
|
||||
// QObject::connect(wiredCableDownTimer, SIGNAL(timeout()), this, SLOT(onCarrierDownHandle()));
|
||||
connect(this, SIGNAL(carrierDownHandle()), this, SLOT(onCarrierDownHandle()));
|
||||
//connect(this, SIGNAL(carrierDownHandle()), this, SLOT(onCarrierDownHandle()));
|
||||
|
||||
//定时处理异常网络,即当点击Lan列表按钮时,若lstate=2,但任然有有线网连接的情况
|
||||
deleteLanTimer = new QTimer(this);
|
||||
deleteLanTimer->setTimerType(Qt::PreciseTimer);
|
||||
QObject::connect(deleteLanTimer, SIGNAL(timeout()), this, SLOT(onDeleteLan()));
|
||||
// QObject::connect(deleteLanTimer, SIGNAL(timeout()), this, SLOT(onDeleteLan()));
|
||||
|
||||
//定时获取网速
|
||||
setNetSpeed = new QTimer(this);
|
||||
setNetSpeed->setTimerType(Qt::PreciseTimer);
|
||||
QObject::connect(setNetSpeed, SIGNAL(timeout()), this, SLOT(on_setNetSpeed()));
|
||||
setNetSpeed->start(1000);
|
||||
// QObject::connect(setNetSpeed, SIGNAL(timeout()), this, SLOT(on_setNetSpeed()));
|
||||
// setNetSpeed->start(1000);
|
||||
}
|
||||
|
||||
//初始化已经连接网络的DNS
|
||||
|
@ -1073,6 +1080,7 @@ void MainWindow::getActiveInfoAndSetTrayIcon()
|
|||
//网线插拔处理,由kylin-dbus-interface.cpp调用
|
||||
void MainWindow::onPhysicalCarrierChanged(bool flag)
|
||||
{
|
||||
#if 0
|
||||
this->startLoading();
|
||||
if (flag) {
|
||||
isHandlingWiredCableOn = true;
|
||||
|
@ -1104,10 +1112,12 @@ void MainWindow::onPhysicalCarrierChanged(bool flag)
|
|||
}
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::onCarrierUpHandle()
|
||||
{
|
||||
#if 0
|
||||
wiredCableUpTimer->stop();
|
||||
|
||||
//检查有线网络的个数是否为0,如果是0,则新建一个有线网络
|
||||
|
@ -1118,12 +1128,13 @@ void MainWindow::onCarrierUpHandle()
|
|||
is_stop_check_net_state = 0;
|
||||
isHandlingWiredCableOn = false;
|
||||
emit btnWired->clicked(4);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::onCarrierDownHandle()
|
||||
{
|
||||
//syslog(LOG_DEBUG, "Wired net is disconnected");
|
||||
|
||||
#if 0
|
||||
QString txt(tr("Wired net is disconnected"));
|
||||
objKyDBus->showDesktopNotify(txt);
|
||||
currSelNetName = "";
|
||||
|
@ -1136,6 +1147,7 @@ void MainWindow::onCarrierDownHandle()
|
|||
this->stopLoading();
|
||||
onBtnNetListClicked(0);
|
||||
is_stop_check_net_state = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::onDeleteLan()
|
||||
|
@ -1468,8 +1480,23 @@ void MainWindow::setLanSwitchStatus(bool is_opened)
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::onBtnNetListClickeds(int flag)
|
||||
{
|
||||
this->scrollAreal->show();
|
||||
topLanListWidget->constructWiredActiveConnectList();
|
||||
lanListWidget->constructWiredConnectList();
|
||||
this->scrollAreaw->hide();
|
||||
this->topWifiListWidget->hide();
|
||||
|
||||
lbLoadDown->show();
|
||||
lbLoadUp->show();
|
||||
lbLoadDownImg->show();
|
||||
lbLoadUpImg->show();
|
||||
}
|
||||
|
||||
void MainWindow::onBtnNetListClicked(int flag)
|
||||
{
|
||||
#if 0
|
||||
this->is_btnLanList_clicked = 1;
|
||||
this->is_btnWifiList_clicked = 0;
|
||||
end_rcv_rates = 0;
|
||||
|
@ -1523,6 +1550,7 @@ void MainWindow::onBtnNetListClicked(int flag)
|
|||
|
||||
delete iface;
|
||||
bt->deleteLater();
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::on_btnWifiList_clicked()
|
||||
|
@ -1692,6 +1720,7 @@ void MainWindow::onNewConnAdded(int type) {
|
|||
// 获取lan列表回调
|
||||
void MainWindow::getLanListDone(QStringList slist)
|
||||
{
|
||||
#if 0
|
||||
if (this->is_btnWifiList_clicked == 1) {
|
||||
return;
|
||||
}
|
||||
|
@ -1948,6 +1977,7 @@ void MainWindow::getLanListDone(QStringList slist)
|
|||
if (btnWired->isEnabled() && !btnWired->getSwitchStatus() && BackThread::execGetIface()->lstate != 2) {
|
||||
btnWired->setSwitchStatus(true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// 获取wifi列表回调
|
||||
|
@ -3363,6 +3393,7 @@ void MainWindow::oneLanFormSelected(QString lanName, QString uniqueName)
|
|||
if (currSelNetName == uniqueName) {
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
QList<OneLancForm *> topLanList = topLanListWidget->findChildren<OneLancForm *>();
|
||||
QList<OneLancForm *> lanList = lanListWidget->findChildren<OneLancForm *>();
|
||||
|
||||
|
@ -3442,9 +3473,12 @@ void MainWindow::oneLanFormSelected(QString lanName, QString uniqueName)
|
|||
ocf->setTopItem(false);
|
||||
ocf->move(L_VERTICAL_LINE_TO_ITEM, (topLanList.size() - 1 - i) * H_NORMAL_ITEM);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::oneTopLanFormSelected(QString lanName, QString uniqueName)
|
||||
{
|
||||
#if 0
|
||||
//应设计要求,选中同一选项卡不再缩小
|
||||
if (currSelNetName == uniqueName) return;
|
||||
QList<OneLancForm *> topLanList = topLanListWidget->findChildren<OneLancForm *>();
|
||||
|
@ -3515,6 +3549,8 @@ void MainWindow::oneTopLanFormSelected(QString lanName, QString uniqueName)
|
|||
|
||||
currSelNetName = uniqueName;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::oneWifiFormSelected(QString wifibssid, int extendLength)
|
||||
|
@ -3734,12 +3770,14 @@ void MainWindow::disNetDone()
|
|||
delete topLanListWidget; // 清空top列表
|
||||
createTopLanUI(); //创建顶部有线网item
|
||||
|
||||
#if 0
|
||||
// 清空lan列表
|
||||
lanListWidget = new QWidget(scrollAreal);
|
||||
lanListWidget->resize(W_LIST_WIDGET, H_NORMAL_ITEM + H_LAN_ITEM_EXTEND);
|
||||
scrollAreal->setWidget(lanListWidget);
|
||||
scrollAreal->move(W_LEFT_AREA, Y_SCROLL_AREA);
|
||||
|
||||
|
||||
// 当前连接的lan
|
||||
OneLancForm *ccf = new OneLancForm(topLanListWidget, this, confForm, ksnm);
|
||||
ccf->setLanName(tr("Not connected"), tr("Not connected"), "--", "--");//"当前未连接任何 以太网"
|
||||
|
@ -3750,7 +3788,7 @@ void MainWindow::disNetDone()
|
|||
ccf->setAct(true);
|
||||
ccf->move(L_VERTICAL_LINE_TO_ITEM, 0);
|
||||
ccf->show();
|
||||
|
||||
#endif
|
||||
btnWireless->setSwitchStatus(false);
|
||||
|
||||
this->lanListWidget->show();
|
||||
|
@ -4140,6 +4178,56 @@ void MainWindow::onRequestReconnecWifi()
|
|||
toReconnectWifi();
|
||||
}
|
||||
|
||||
void MainWindow::on_setNetSpeeds(qulonglong rx, qulonglong tx)
|
||||
{
|
||||
long int delta_rcv = rx/1024;
|
||||
long int delta_tx = tx/1024;
|
||||
|
||||
//简易滤波
|
||||
if (delta_rcv < 0 || delta_tx < 0) {
|
||||
delta_rcv = 0;
|
||||
delta_tx = 0;
|
||||
}
|
||||
|
||||
int rcv_num = delta_rcv;
|
||||
int tx_num = delta_tx;
|
||||
|
||||
QString str_rcv;
|
||||
QString str_tx;
|
||||
|
||||
if (rcv_num < 1024) {
|
||||
str_rcv = QString::number(rcv_num) + "KB/s.";
|
||||
} else {
|
||||
int remainder;
|
||||
if (rcv_num%1024 < 100) {
|
||||
remainder = 0;
|
||||
} else {
|
||||
remainder = (rcv_num%1024)/100;
|
||||
}
|
||||
str_rcv = QString::number(rcv_num/1024) + "." + QString::number(remainder) + "MB/s.";
|
||||
}
|
||||
|
||||
if (tx_num < 1024) {
|
||||
str_tx = QString::number(tx_num) + "KB/s";
|
||||
} else {
|
||||
int remainder;
|
||||
if (tx_num%1024 < 100) {
|
||||
remainder = 0;
|
||||
} else {
|
||||
remainder = (tx_num%1024)/100;
|
||||
}
|
||||
str_tx = QString::number(tx_num/1024) + "." + QString::number(remainder) + "MB/s";
|
||||
}
|
||||
|
||||
lbLoadDown->setText(str_rcv);
|
||||
lbLoadUp->setText(str_tx);
|
||||
|
||||
int offset = str_rcv.length() * 7;
|
||||
lbLoadUp->move(X_ITEM + offset + 145, Y_TOP_ITEM + 32);
|
||||
lbLoadUpImg->move(X_ITEM + offset + 128, Y_TOP_ITEM + 35);
|
||||
return;
|
||||
}
|
||||
|
||||
void MainWindow::on_setNetSpeed()
|
||||
{
|
||||
if (this->isVisible() && is_stop_check_net_state==0) {
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "utils.h"
|
||||
#include "switchbutton.h"
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include "kylinwiredwidget.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -116,6 +117,7 @@
|
|||
|
||||
class OneConnForm;
|
||||
class ConfForm;
|
||||
class KyWiredWidget;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
@ -292,9 +294,9 @@ private:
|
|||
QDesktopWidget desktop;
|
||||
KSimpleNM *ksnm = nullptr;
|
||||
ConfForm *confForm = nullptr;
|
||||
QWidget *topLanListWidget = nullptr;
|
||||
KyWiredWidget *topLanListWidget = nullptr;
|
||||
QWidget *topWifiListWidget = nullptr;
|
||||
QWidget *lanListWidget = nullptr;
|
||||
KyWiredWidget *lanListWidget = nullptr;
|
||||
QWidget *wifiListWidget = nullptr;
|
||||
QWidget *optWifiWidget = nullptr;
|
||||
|
||||
|
@ -385,6 +387,7 @@ private slots:
|
|||
void onBtnNetClicked();
|
||||
// void on_btnWifiList_clicked();
|
||||
void onBtnNetListClicked(int flag=0);
|
||||
void onBtnNetListClickeds(int flag=0);
|
||||
void onNewConnAdded(int type);
|
||||
|
||||
void onRequestRevalueUpdateWifi();
|
||||
|
@ -403,6 +406,7 @@ private slots:
|
|||
void handleWifiDisconnLoading();
|
||||
void onRequestScanAccesspoint();
|
||||
void toScanWifi(bool isShow);
|
||||
void on_setNetSpeeds(qulonglong rx, qulonglong tx);
|
||||
void on_setNetSpeed();
|
||||
void on_checkOverTime();
|
||||
|
||||
|
|
|
@ -19,10 +19,11 @@
|
|||
#include "onelancform.h"
|
||||
#include "ui_onelancform.h"
|
||||
#include "mainwindow.h"
|
||||
#include "kylinwiredwidget.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
OneLancForm::OneLancForm(QWidget *parent, MainWindow *mainWindow, ConfForm *confForm, KSimpleNM *ksnm) :
|
||||
OneLancForm::OneLancForm(QWidget *parent, KyWiredConnectItem *wiredConnectItem) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::OneLancForm)
|
||||
{
|
||||
|
@ -78,9 +79,8 @@ OneLancForm::OneLancForm(QWidget *parent, MainWindow *mainWindow, ConfForm *conf
|
|||
ui->lbWaiting->hide();
|
||||
ui->lbWaitingIcon->hide();
|
||||
|
||||
this->mw = mainWindow;
|
||||
this->cf = confForm;
|
||||
this->ks = ksnm;
|
||||
|
||||
m_wiredConnectItem = wiredConnectItem;
|
||||
|
||||
this->isSelected = false;
|
||||
this->isActive = false;
|
||||
|
@ -90,7 +90,9 @@ OneLancForm::OneLancForm(QWidget *parent, MainWindow *mainWindow, ConfForm *conf
|
|||
ui->btnInfo->setAttribute(Qt::WA_Hover,true);
|
||||
ui->btnInfo->installEventFilter(this);
|
||||
|
||||
|
||||
this->waitTimer = new QTimer(this);
|
||||
#if 0
|
||||
connect(waitTimer, SIGNAL(timeout()), this, SLOT(waitAnimStep()));
|
||||
|
||||
connect(mw, SIGNAL(waitLanStop()), this, SLOT(stopWaiting()));
|
||||
|
@ -99,21 +101,75 @@ OneLancForm::OneLancForm(QWidget *parent, MainWindow *mainWindow, ConfForm *conf
|
|||
on_btnConn_clicked();
|
||||
}
|
||||
});
|
||||
#endif
|
||||
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) {
|
||||
m_updateSpeedTimer->start(1000);
|
||||
}
|
||||
|
||||
ui->btnConn->setShortcut(Qt::Key_Return);//将字母区回车键与连接按钮绑定在一起
|
||||
ui->btnConnSub->setShortcut(Qt::Key_Return);//点击连接按钮触发回车键
|
||||
|
||||
m_networkConnect = new KyNetworkConnect();
|
||||
m_wiredConnectOperation = new KyWiredConnectOperation();
|
||||
|
||||
srand((unsigned)time(NULL));
|
||||
}
|
||||
|
||||
OneLancForm::~OneLancForm()
|
||||
{
|
||||
delete m_networkConnect;
|
||||
delete m_wiredConnectItem;
|
||||
delete m_wiredConnectOperation;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void OneLancForm::constructActiveConnectionEmptyItem()
|
||||
{
|
||||
setLanName(tr("Not connected"), tr("Not connected"), "--", "--");//"当前未连接任何 以太网"
|
||||
setIcon(false);
|
||||
setConnedString(1, tr("Disconnected"), "");//"未连接"
|
||||
isConnected = false;
|
||||
setTopItem(false);//"当前未连接任何 以太网"
|
||||
setAct(true);
|
||||
move(L_VERTICAL_LINE_TO_ITEM, 0);
|
||||
show();
|
||||
setLine(false);
|
||||
}
|
||||
|
||||
void OneLancForm::constructActiveConnectionItem(int index)
|
||||
{
|
||||
setLanName(m_wiredConnectItem->m_connectName,
|
||||
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);
|
||||
//setConnedString(true, tr("NetOn,IfName:"), m_wiredConnectItem->m_ifaceName);
|
||||
setConnedString(1, tr("NetOn,"), "");
|
||||
isConnected = true;
|
||||
setTopItem(false);
|
||||
setLine(true);
|
||||
setAct(true);
|
||||
move(L_VERTICAL_LINE_TO_ITEM, index*H_NORMAL_ITEM);
|
||||
show();
|
||||
}
|
||||
|
||||
void OneLancForm::constructConnectionItem(int index)
|
||||
{
|
||||
setLanName(m_wiredConnectItem->m_connectName,
|
||||
tr("Ethernet"), m_wiredConnectItem->m_connectUuid,
|
||||
m_wiredConnectItem->m_ifaceName);
|
||||
setIcon(true);
|
||||
setLine(true);
|
||||
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);
|
||||
show();
|
||||
}
|
||||
|
||||
void OneLancForm::mousePressEvent(QMouseEvent *)
|
||||
{
|
||||
emit selectedOneLanForm(ssidName, uuidName);//避免重名情况
|
||||
|
@ -328,7 +384,9 @@ void OneLancForm::slotConnLan()
|
|||
void OneLancForm::on_btnDisConn_clicked()
|
||||
{
|
||||
qDebug()<<"DisConnect button about lan net is clicked, current wired net name is "<<ui->lbName->text();
|
||||
m_wiredConnectOperation->deactivateWiredConnection(ssidName, uuidName);
|
||||
|
||||
#if 0
|
||||
this->startWaiting(false);
|
||||
mw->is_stop_check_net_state = 1;
|
||||
|
||||
|
@ -343,6 +401,7 @@ void OneLancForm::on_btnDisConn_clicked()
|
|||
disconnect(this, SIGNAL(selectedOneLanForm(QString, QString)), mw, SLOT(oneTopLanFormSelected(QString, QString)));
|
||||
|
||||
emit requestHandleLanDisconn();
|
||||
#endif
|
||||
}
|
||||
|
||||
void OneLancForm::toDisConnWiredNetwork(QString netUuid)
|
||||
|
@ -401,12 +460,13 @@ void OneLancForm::on_btnConnSub_clicked()
|
|||
|
||||
void OneLancForm::toConnectWiredNetwork()
|
||||
{
|
||||
/*
|
||||
if (mw->is_stop_check_net_state == 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
mw->is_stop_check_net_state = 1;
|
||||
/*
|
||||
|
||||
QThread *t = new QThread();
|
||||
BackThread *bt = new BackThread();
|
||||
bt->moveToThread(t);
|
||||
|
@ -418,7 +478,7 @@ void OneLancForm::toConnectWiredNetwork()
|
|||
t->start();
|
||||
*/
|
||||
|
||||
m_networkConnect->activateConnection(uuidName);
|
||||
m_wiredConnectOperation->activateWiredConnection(uuidName);
|
||||
}
|
||||
|
||||
//点击列表中item扩展后显示信息的位置时,执行该函数,用于显示网络配置界面
|
||||
|
@ -544,6 +604,15 @@ void OneLancForm::stopWaiting()
|
|||
mw->getActiveInfoAndSetTrayIcon();
|
||||
}
|
||||
|
||||
void OneLancForm::updateNetworkSpeed()
|
||||
{
|
||||
KyWiredWidget *wiredWidget = (KyWiredWidget *)parentWidget();
|
||||
wiredWidget->updateDeviceRefreshRate(m_wiredConnectItem->m_ifaceName, 1000);
|
||||
wiredWidget->updateNetworkSpeed(m_wiredConnectItem);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void OneLancForm::on_btnCancel_clicked()
|
||||
{
|
||||
QString cmd = "kill -9 $(pidof nmcli)"; //杀掉当前正在进行的有关nmcli命令的进程
|
||||
|
|
|
@ -26,9 +26,11 @@
|
|||
|
||||
#include "confform.h"
|
||||
#include "kylin-network-interface.h"
|
||||
#include "kylinnetworkconnect.h"
|
||||
#include "kylinwiredconnectoperation.h"
|
||||
#include "backthread.h"
|
||||
#include "ksimplenm.h"
|
||||
#include "kylinwiredconnectitem.h"
|
||||
|
||||
|
||||
#include <QtDBus/QDBusConnection>
|
||||
#include <QtDBus/QDBusMessage>
|
||||
|
@ -60,10 +62,14 @@ class OneLancForm;
|
|||
class OneLancForm : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OneLancForm(QWidget *parent = 0, KyWiredConnectItem *wiredConnectItem = 0);
|
||||
~OneLancForm();
|
||||
|
||||
public:
|
||||
explicit OneLancForm(QWidget *parent = 0, MainWindow *mw = 0, ConfForm *confForm = 0, KSimpleNM *ksnm = 0);
|
||||
~OneLancForm();
|
||||
void constructConnectionItem(int index);
|
||||
void constructActiveConnectionItem(int index);
|
||||
void constructActiveConnectionEmptyItem();
|
||||
|
||||
void setLanName(QString ssid, QString transSsid, QString uuid, QString interface);
|
||||
void setIcon(bool isOn);
|
||||
|
@ -89,6 +95,7 @@ public slots:
|
|||
void waitAnimStep();
|
||||
void startWaiting(bool isToConnect);
|
||||
void stopWaiting();
|
||||
void updateNetworkSpeed();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
|
@ -109,6 +116,7 @@ private slots:
|
|||
|
||||
private:
|
||||
QTimer *waitTimer = nullptr;
|
||||
QTimer *m_updateSpeedTimer = nullptr;
|
||||
int waitPage;
|
||||
int countCurrentTime;
|
||||
|
||||
|
@ -116,9 +124,10 @@ private:
|
|||
MainWindow *mw = nullptr;
|
||||
ConfForm *cf = nullptr;
|
||||
KSimpleNM *ks = nullptr;
|
||||
KyNetworkConnect *m_networkConnect = nullptr;
|
||||
KyWiredConnectOperation *m_wiredConnectOperation = nullptr;
|
||||
|
||||
QString leQssLow, leQssHigh;
|
||||
KyWiredConnectItem *m_wiredConnectItem = nullptr;
|
||||
|
||||
signals:
|
||||
void selectedOneLanForm(QString lanName, QString uniqueName);
|
||||
|
|
Loading…
Reference in New Issue