feature:Remove redundant code and modify inheritance relationship.
This commit is contained in:
parent
b207493157
commit
9b61802ff1
|
@ -70,7 +70,6 @@ SOURCES += \
|
|||
src/kylinconnectoperation.cpp \
|
||||
src/kylinconnectresource.cpp \
|
||||
src/kylinconnectsetting.cpp \
|
||||
src/kylinnetworkconnect.cpp \
|
||||
src/kylinnetworkdeviceresource.cpp \
|
||||
src/kylinnetworkresourcemanager.cpp \
|
||||
src/kywirelessconnectoperation.cpp \
|
||||
|
@ -119,7 +118,6 @@ HEADERS += \
|
|||
src/kylinconnectoperation.h \
|
||||
src/kylinconnectresource.h \
|
||||
src/kylinconnectsetting.h \
|
||||
src/kylinnetworkconnect.h \
|
||||
src/kylinnetworkdeviceresource.h \
|
||||
src/kylinnetworkresourcemanager.h \
|
||||
src/kywirelessconnectoperation.h \
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <NetworkManagerQt/Dhcp4Config>
|
||||
#include <NetworkManagerQt/Dhcp6Config>
|
||||
|
||||
KyActiveConnectResourse::KyActiveConnectResourse()
|
||||
KyActiveConnectResourse::KyActiveConnectResourse(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
m_networkdevice = new KyNetworkDeviceResourse();
|
||||
|
@ -62,7 +62,7 @@ KyConnectItem *KyActiveConnectResourse::getActiveConnectionByUuid(QString connec
|
|||
m_networkResourceInstance->getActiveConnect(connectUuid);
|
||||
|
||||
if (nullptr == activeConnectPtr) {
|
||||
qWarning()<<"it can not find connect "<< connectUuid;
|
||||
qWarning()<< "[KyActiveConnectResourse]" <<"it can not find connect "<< connectUuid;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class KyActiveConnectResourse : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KyActiveConnectResourse();
|
||||
explicit KyActiveConnectResourse(QObject *parent = nullptr);
|
||||
~KyActiveConnectResourse();
|
||||
|
||||
public:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "kylinbluetoothconnectitem.h"
|
||||
|
||||
|
||||
KyBluetoothConnectItem::KyBluetoothConnectItem()
|
||||
KyBluetoothConnectItem::KyBluetoothConnectItem(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_connectName = "";
|
||||
m_connectUuid = "";
|
||||
|
|
|
@ -10,7 +10,7 @@ class KyBluetoothConnectItem : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KyBluetoothConnectItem();
|
||||
explicit KyBluetoothConnectItem(QObject *parent = nullptr);
|
||||
~KyBluetoothConnectItem();
|
||||
|
||||
public:
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <NetworkManagerQt/Ipv6Setting>
|
||||
#include <NetworkManagerQt/WiredSetting>
|
||||
|
||||
KyConnectOperation::KyConnectOperation()
|
||||
KyConnectOperation::KyConnectOperation(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
}
|
||||
|
@ -97,33 +97,7 @@ void KyConnectOperation::connectSettingSet(
|
|||
|
||||
void KyConnectOperation::createConnect(KyConnectSetting &connectSettingsInfo)
|
||||
{
|
||||
qDebug()<<"create connect";
|
||||
connectSettingsInfo.dumpInfo();
|
||||
NetworkManager::ConnectionSettings::Ptr wiredConnectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wired));
|
||||
connectSettingSet(wiredConnectionSettings, connectSettingsInfo);
|
||||
|
||||
NetworkManager::Ipv4Setting::Ptr ipv4Setting = wiredConnectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast<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();
|
||||
});
|
||||
|
||||
qDebug()<<"create connect need to do";
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -149,8 +123,8 @@ void KyConnectOperation::updateConnect(const QString &connectUuid, const KyConne
|
|||
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);
|
||||
// NetworkManager::WiredSetting::Ptr wiredSetting = connectionSettings->setting(NetworkManager::Setting::Wired).dynamicCast<NetworkManager::WiredSetting>();
|
||||
// wiredSetting->setInitialized(true);
|
||||
|
||||
connectPtr->update(connectionSettings->toMap());
|
||||
|
||||
|
@ -192,7 +166,7 @@ void KyConnectOperation::activateConnection(const QString connectUuid)
|
|||
Q_EMIT activateConnectionError(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (NetworkManager::ConnectionSettings::Wired != connectPtr->settings()->connectionType()) {
|
||||
QString errorMessage = tr("the connect type is")
|
||||
+ connectPtr->settings()->connectionType()
|
||||
|
@ -201,7 +175,7 @@ void KyConnectOperation::activateConnection(const QString connectUuid)
|
|||
Q_EMIT activateConnectionError(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
connectPath = connectPtr->path();
|
||||
connectName = connectPtr->name();
|
||||
deviceName = connectPtr->settings()->interfaceName();
|
||||
|
@ -240,7 +214,7 @@ void KyConnectOperation::activateConnection(const QString connectUuid)
|
|||
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();
|
||||
QString errorMessage = tr("activate connection failed: ") + watcher->error().message();
|
||||
qWarning()<<errorMessage;
|
||||
emit this->activateConnectionError(errorMessage);
|
||||
} else {
|
||||
|
|
|
@ -8,7 +8,7 @@ class KyConnectOperation : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KyConnectOperation();
|
||||
explicit KyConnectOperation(QObject *parent = nullptr);
|
||||
~KyConnectOperation();
|
||||
|
||||
public:
|
||||
|
@ -18,7 +18,7 @@ public:
|
|||
void activateConnection(const QString connectUuid);
|
||||
void deactivateConnection(const QString activeConnectName, const QString &activeConnectUuid);
|
||||
|
||||
private:
|
||||
public:
|
||||
void connectSettingSet(
|
||||
NetworkManager::ConnectionSettings::Ptr connectionSettings,
|
||||
const KyConnectSetting &connectSettingsInfo);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <NetworkManagerQt/VpnPlugin>
|
||||
#include <NetworkManagerQt/VpnSetting>
|
||||
|
||||
KyConnectResourse::KyConnectResourse()
|
||||
KyConnectResourse::KyConnectResourse(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
m_networkdevice = new KyNetworkDeviceResourse();
|
||||
|
|
|
@ -13,7 +13,7 @@ class KyConnectResourse : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KyConnectResourse();
|
||||
explicit KyConnectResourse(QObject *parent = nullptr);
|
||||
~KyConnectResourse();
|
||||
|
||||
public:
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "kylinconnectsetting.h"
|
||||
#include <QDebug>
|
||||
|
||||
KyConnectSetting::KyConnectSetting()
|
||||
KyConnectSetting::KyConnectSetting(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_connectName = "";
|
||||
m_ifaceName = "";
|
||||
|
|
|
@ -43,7 +43,7 @@ class KyConnectSetting : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KyConnectSetting();
|
||||
explicit KyConnectSetting(QObject *parent = nullptr);
|
||||
~KyConnectSetting();
|
||||
|
||||
public:
|
||||
|
|
|
@ -1,612 +0,0 @@
|
|||
/*
|
||||
* 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 "kylinnetworkconnect.h"
|
||||
#include "sys/syslog.h"
|
||||
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr assembleWpaXPskSettings(const NetworkManager::AccessPoint::Ptr accessPoint, const QString &psk)
|
||||
{
|
||||
NetworkManager::ConnectionSettings::Ptr settings{new NetworkManager::ConnectionSettings{NetworkManager::ConnectionSettings::Wireless}};
|
||||
settings->setId(accessPoint->ssid());
|
||||
settings->setUuid(NetworkManager::ConnectionSettings::createNewUuid());
|
||||
settings->setAutoconnect(true);
|
||||
//Note: workaround for wrongly (randomly) initialized gateway-ping-timeout
|
||||
settings->setGatewayPingTimeout(0);
|
||||
|
||||
NetworkManager::WirelessSetting::Ptr wifi_sett
|
||||
= settings->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
|
||||
wifi_sett->setInitialized(true);
|
||||
wifi_sett->setSsid(accessPoint->ssid().toUtf8());
|
||||
wifi_sett->setSecurity("802-11-wireless-security");
|
||||
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
security_sett->setInitialized(true);
|
||||
if (NetworkManager::AccessPoint::Adhoc == accessPoint->mode())
|
||||
{
|
||||
wifi_sett->setMode(NetworkManager::WirelessSetting::Adhoc);
|
||||
security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaNone);
|
||||
} else
|
||||
{
|
||||
security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaPsk);
|
||||
}
|
||||
security_sett->setPsk(psk);
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
#include <NetworkManagerQt/AdslDevice>
|
||||
#include <NetworkManagerQt/WiredDevice>
|
||||
#include <NetworkManagerQt/Ipv4Setting>
|
||||
#include <NetworkManagerQt/Ipv6Setting>
|
||||
#include <NetworkManagerQt/WiredSetting>
|
||||
|
||||
KyNetworkConnect::KyNetworkConnect()
|
||||
{
|
||||
qDebug()<<"construct network connect";
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
|
||||
connect(this, &KyNetworkConnect::checkActiveonnection, this, &KyNetworkConnect::onCheckActiveonnection);
|
||||
}
|
||||
|
||||
KyNetworkConnect::~KyNetworkConnect()
|
||||
{
|
||||
m_networkResourceInstance = nullptr;
|
||||
}
|
||||
|
||||
void KyNetworkConnect::ipv4SettingInit(
|
||||
NetworkManager::Ipv4Setting::Ptr &ipv4Setting,
|
||||
const KyConnectSetting &connectInfo)
|
||||
{
|
||||
ipv4Setting->setInitialized(true);
|
||||
|
||||
if (CONFIG_IP_DHCP == connectInfo.m_ipv4ConfigIpType) {
|
||||
ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Automatic);
|
||||
return;
|
||||
} else {
|
||||
ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Manual);
|
||||
}
|
||||
|
||||
if (!connectInfo.m_ipv4Dns.empty()) {
|
||||
ipv4Setting->setDns(connectInfo.m_ipv4Dns);
|
||||
}
|
||||
|
||||
if (!connectInfo.m_ipv4Address.empty()) {
|
||||
ipv4Setting->setAddresses(connectInfo.m_ipv4Address);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
void KyNetworkConnect::ipv6SettingInit(
|
||||
NetworkManager::Ipv6Setting::Ptr &ipv6Setting,
|
||||
const KyConnectSetting &connectInfo)
|
||||
{
|
||||
ipv6Setting->setInitialized(true);
|
||||
|
||||
if (CONFIG_IP_DHCP == connectInfo.m_ipv6ConfigIpType) {
|
||||
ipv6Setting->setMethod(NetworkManager::Ipv6Setting::Automatic);
|
||||
return;
|
||||
}
|
||||
|
||||
ipv6Setting->setMethod(NetworkManager::Ipv6Setting::Manual);
|
||||
if (!connectInfo.m_ipv6Dns.empty()) {
|
||||
ipv6Setting->setDns(connectInfo.m_ipv6Dns);
|
||||
}
|
||||
|
||||
if (!connectInfo.m_ipv6Address.empty()) {
|
||||
ipv6Setting->setAddresses(connectInfo.m_ipv6Address);
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
void KyNetworkConnect::connectSettingInit(
|
||||
NetworkManager::ConnectionSettings::Ptr connectionSettings,
|
||||
const KyConnectSetting &connectInfo)
|
||||
{
|
||||
connectionSettings->setId(connectInfo.m_connectName);
|
||||
connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid());
|
||||
connectionSettings->setAutoconnect(true);
|
||||
connectionSettings->setAutoconnectPriority(0);
|
||||
connectionSettings->setInterfaceName(connectInfo.m_ifaceName);
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkConnect::createWiredConnect(const KyConnectSetting &connectInfo)
|
||||
{
|
||||
NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wired));
|
||||
connectSettingInit(connectionSettings, connectInfo);
|
||||
|
||||
NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast<NetworkManager::Ipv4Setting>();
|
||||
ipv4SettingInit(ipv4Setting, connectInfo);
|
||||
|
||||
NetworkManager::Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast<NetworkManager::Ipv6Setting>();
|
||||
ipv6SettingInit(ipv6Setting, connectInfo);
|
||||
|
||||
NetworkManager::WiredSetting::Ptr wiredSetting = connectionSettings->setting(NetworkManager::Setting::Wired).dynamicCast<NetworkManager::WiredSetting>();
|
||||
wiredSetting->setInitialized(true);
|
||||
|
||||
qDebug()<<"add wired connect"<<connectInfo.m_connectName;
|
||||
|
||||
QDBusPendingCallWatcher * watcher;
|
||||
watcher = new QDBusPendingCallWatcher{NetworkManager::addConnection(connectionSettings->toMap()), this};
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [](QDBusPendingCallWatcher * watcher) {
|
||||
if (watcher->isError() || !watcher->isValid()) {
|
||||
//TODO: in what form should we output the warning messages
|
||||
qWarning() << "create connection failed: " << watcher->error().message();
|
||||
} else {
|
||||
qWarning()<<"success"<<watcher->reply().errorName() <<"error msg"<<watcher->reply().errorMessage();
|
||||
qWarning()<<"error type"<<watcher->error().type();
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkConnect::createConnect(KyConnectType connectType, const KyConnectSetting &connectInfo)
|
||||
{
|
||||
switch (connectType) {
|
||||
case WIRED_CONNECT:
|
||||
qDebug()<<"create wired connect";
|
||||
createWiredConnect(connectInfo);
|
||||
break;
|
||||
default:
|
||||
qWarning()<<"the connect type undefined"<<connectType;
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkConnect::updateConnect(const QString &connectUuid, const KyConnectSetting &connectInfo)
|
||||
{
|
||||
qDebug()<<"update connect"<<connectUuid;
|
||||
NetworkManager::Connection::Ptr connectPtr =
|
||||
NetworkManager::findConnectionByUuid(connectUuid);
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr connectionSettings = connectPtr->settings();
|
||||
connectSettingInit(connectionSettings, connectInfo);
|
||||
|
||||
NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast<NetworkManager::Ipv4Setting>();
|
||||
ipv4SettingInit(ipv4Setting, connectInfo);
|
||||
|
||||
NetworkManager::Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast<NetworkManager::Ipv6Setting>();
|
||||
ipv6SettingInit(ipv6Setting, connectInfo);
|
||||
|
||||
NetworkManager::WiredSetting::Ptr wiredSetting = connectionSettings->setting(NetworkManager::Setting::Wired).dynamicCast<NetworkManager::WiredSetting>();
|
||||
wiredSetting->setInitialized(true);
|
||||
|
||||
connectPtr->update(connectionSettings->toMap());
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
void KyNetworkConnect::deleteConnect(const QString &connectUuid)
|
||||
{
|
||||
|
||||
qWarning()<<"TODO:delete connect ";
|
||||
|
||||
NetworkManager::Connection::Ptr connectPtr =
|
||||
NetworkManager::findConnectionByUuid(connectUuid);
|
||||
|
||||
connectPtr->remove();
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
int KyNetworkConnect::activateConnection(const QString connectUuid)
|
||||
{
|
||||
QString conn_uni;
|
||||
QString dev_uni;
|
||||
QString conn_name;
|
||||
QString dev_name;
|
||||
QString spec_object;
|
||||
|
||||
qDebug()<<"it will activate connect"<<connectUuid;
|
||||
NetworkManager::Connection::Ptr connectPtr = m_networkResourceInstance->getConnect(connectUuid);
|
||||
conn_uni = connectPtr->path();
|
||||
conn_name = connectPtr->name();
|
||||
if (NetworkManager::ConnectionSettings::Vpn == connectPtr->settings()->connectionType()) {
|
||||
spec_object = dev_uni = QStringLiteral("/");
|
||||
/*
|
||||
// find first non-vpn active connection
|
||||
const auto act_i = std::find_if(d->mActiveConns.cbegin(), d->mActiveConns.cend(), [] (NetworkManager::ActiveConnection::Ptr const & conn) -> bool
|
||||
{
|
||||
return nullptr != dynamic_cast<NetworkManager::VpnConnection const *>(conn.data());
|
||||
});
|
||||
if (act_i != d->mActiveConns.cend() && !(*act_i)->devices().empty())
|
||||
{
|
||||
dev_uni = (*act_i)->devices().front();
|
||||
spec_object = (*act_i)->path();
|
||||
}
|
||||
*/
|
||||
|
||||
} else {
|
||||
dev_name = connectPtr->settings()->interfaceName();
|
||||
for (auto const & dev : m_networkResourceInstance->m_devices) {
|
||||
for (auto const & dev_conn : dev->availableConnections()) {
|
||||
if (dev_conn == connectPtr) {
|
||||
dev_uni = dev->uni();
|
||||
dev_name = dev->interfaceName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dev_uni.isEmpty() && !dev_name.isEmpty()) {
|
||||
auto dev = m_networkResourceInstance->findDeviceInterface(dev_name);
|
||||
if (!dev.isNull())
|
||||
dev_uni = dev->uni();
|
||||
}
|
||||
}
|
||||
|
||||
if (dev_uni.isEmpty()) {
|
||||
//TODO: in what form should we output the warning messages
|
||||
qWarning() << QStringLiteral("can't find device '%1' to activate connection '%2' on").arg(dev_name).arg(connectPtr->name());
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
qDebug() << __FUNCTION__ << conn_uni << dev_uni << conn_name << dev_name << spec_object;
|
||||
|
||||
//TODO: check vpn type etc..
|
||||
QDBusPendingCallWatcher * watcher;
|
||||
watcher = new QDBusPendingCallWatcher{NetworkManager::activateConnection(conn_uni, dev_uni, spec_object), this};
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [conn_name, dev_name] (QDBusPendingCallWatcher * watcher) {
|
||||
if (watcher->isError() || !watcher->isValid()) {
|
||||
//TODO: in what form should we output the warning messages
|
||||
qWarning() << "activate connection failed: " << watcher->error().message();
|
||||
} else {
|
||||
qWarning()<<"success"<<watcher->reply().errorName() <<"error msg"<<watcher->reply().errorMessage();
|
||||
qWarning()<<"error type"<<watcher->error().type();
|
||||
}
|
||||
|
||||
watcher->deleteLater();
|
||||
});
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int KyNetworkConnect::deactivateConnection(const QString connectName, const QString &uuid)
|
||||
{
|
||||
int index = 0;
|
||||
NetworkManager::ActiveConnection::Ptr activateConnectPtr = nullptr;
|
||||
|
||||
qDebug()<<"deactivetate connect name"<<connectName<<"uuid"<<uuid;
|
||||
for (index = 0; index < m_networkResourceInstance->m_activeConns.size(); ++index) {
|
||||
activateConnectPtr = m_networkResourceInstance->m_activeConns.at(index);
|
||||
if (activateConnectPtr->uuid() == uuid) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index >= m_networkResourceInstance->m_activeConns.size()) {
|
||||
qWarning()<<"it can not find the activate connect"<<connectName << "uuid"<<uuid;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
qDebug() << __FUNCTION__ <<"dead active connection path:"<< activateConnectPtr->path();
|
||||
|
||||
QDBusPendingReply<> reply = NetworkManager::deactivateConnection(activateConnectPtr->path());
|
||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [activateConnectPtr] (QDBusPendingCallWatcher * watcher) {
|
||||
qDebug() << "finshed";
|
||||
//TODO::it may should send signal deactivateConnectionFinished
|
||||
if (watcher->isError() || !watcher->isValid()) {
|
||||
//TODO: in what form should we output the warning messages
|
||||
qWarning() << QStringLiteral("deactivation of connection '%1' failed: %3").arg(activateConnectPtr->connection()->name())
|
||||
.arg(watcher->error().message());
|
||||
} else {
|
||||
qWarning()<<"deactive connect finished"<<activateConnectPtr->connection()->name();
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void KyNetworkConnect::requestScan(const QString ifaceName)
|
||||
{
|
||||
auto const & dev = m_networkResourceInstance->getNetworkDevice(ifaceName);
|
||||
auto spec_dev = dev->as<NetworkManager::WirelessDevice>();
|
||||
if (nullptr == spec_dev) {
|
||||
//TODO: in what form should we output the warning messages
|
||||
qWarning() << "dropping request for scan on non wireles device " << dev->interfaceName();
|
||||
return;
|
||||
}
|
||||
|
||||
m_networkResourceInstance->requestScan(spec_dev);
|
||||
}
|
||||
|
||||
void KyNetworkConnect::requestAllWifiScan()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void KyNetworkConnect::activateWirelessConnection(NetworkManager::WirelessNetwork::Ptr wirelessNet)
|
||||
{
|
||||
qDebug() << "activateWirelessConnections" ;
|
||||
emit starWaiting();
|
||||
QString conn_uni;
|
||||
QString dev_uni;
|
||||
QString conn_name;
|
||||
QString dev_name;
|
||||
QString spec_object;
|
||||
|
||||
auto access_point = wirelessNet->referenceAccessPoint();
|
||||
Q_ASSERT(!access_point.isNull());
|
||||
dev_uni = wirelessNet->device();
|
||||
syslog(LOG_DEBUG,"dev_uni %s",dev_uni.toUtf8().data());
|
||||
auto dev = m_networkResourceInstance->findDeviceUni(dev_uni);
|
||||
Q_ASSERT(!dev.isNull());
|
||||
auto spec_dev = dev->as<NetworkManager::WirelessDevice>();
|
||||
Q_ASSERT(nullptr != spec_dev);
|
||||
conn_uni = access_point->uni();
|
||||
syslog(LOG_DEBUG,"conn_uni %s",conn_uni.toUtf8().data());
|
||||
conn_name = access_point->ssid();
|
||||
syslog(LOG_DEBUG,"conn_name %s",conn_name.toUtf8().data());
|
||||
//find the device name
|
||||
NetworkManager::Connection::Ptr conn;
|
||||
dev_name = dev->interfaceName();
|
||||
syslog(LOG_DEBUG,"dev_name %s",dev_name.toUtf8().data());
|
||||
for (auto const & dev_conn : dev->availableConnections())
|
||||
{
|
||||
syslog(LOG_DEBUG,"dev_conn->settings()->id() %s",dev_conn->settings()->id().toUtf8().data());
|
||||
if (dev_conn->settings()->id() == conn_name)
|
||||
{
|
||||
conn = dev_conn;
|
||||
}
|
||||
}
|
||||
conn_uni = conn->path();
|
||||
qDebug()<<conn_uni;
|
||||
|
||||
QDBusPendingCallWatcher * watcher;
|
||||
watcher = new QDBusPendingCallWatcher{NetworkManager::activateConnection(conn_uni, dev_uni, spec_object), this};
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) {
|
||||
if (watcher->isError() || !watcher->isValid())
|
||||
{
|
||||
//TODO: in what form should we output the warning messages
|
||||
qWarning() << QStringLiteral("activation of connection failed: %1").arg(watcher->error().message());
|
||||
} else {
|
||||
emit checkActiveonnection((qdbus_cast<QDBusObjectPath>(watcher->reply().arguments().at(0))).path());
|
||||
}
|
||||
qDebug() <<" " << (qdbus_cast<QDBusObjectPath>(watcher->reply().arguments().at(0))).path();
|
||||
|
||||
watcher->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
void KyNetworkConnect::addAndActivateWirelessConnection(NetworkManager::WirelessNetwork::Ptr wirelessNet, const QString &psk)
|
||||
{
|
||||
qDebug() << "addAndActivateWirelessConnection" ;
|
||||
emit starWaiting();
|
||||
QString conn_uni;
|
||||
QString dev_uni;
|
||||
QString conn_name;
|
||||
QString dev_name;
|
||||
QString spec_object;
|
||||
NMVariantMapMap map_settings;
|
||||
|
||||
auto access_point = wirelessNet->referenceAccessPoint();
|
||||
Q_ASSERT(!access_point.isNull());
|
||||
dev_uni = wirelessNet->device();
|
||||
syslog(LOG_DEBUG,"dev_uni %s",dev_uni.toUtf8().data());
|
||||
auto dev = m_networkResourceInstance->findDeviceUni(dev_uni);
|
||||
Q_ASSERT(!dev.isNull());
|
||||
auto spec_dev = dev->as<NetworkManager::WirelessDevice>();
|
||||
Q_ASSERT(nullptr != spec_dev);
|
||||
conn_uni = access_point->uni();
|
||||
syslog(LOG_DEBUG,"conn_uni %s",conn_uni.toUtf8().data());
|
||||
conn_name = access_point->ssid();
|
||||
syslog(LOG_DEBUG,"conn_name %s",conn_name.toUtf8().data());
|
||||
//find the device name
|
||||
NetworkManager::Connection::Ptr conn;
|
||||
dev_name = dev->interfaceName();
|
||||
syslog(LOG_DEBUG,"dev_name %s",dev_name.toUtf8().data());
|
||||
|
||||
//TODO: in what form should we output the warning messages
|
||||
qWarning() << QStringLiteral("can't find connection for '%1' on device '%2', will create new...").arg(conn_name).arg(dev_name);
|
||||
spec_object = conn_uni;
|
||||
NetworkManager::WirelessSecurityType sec_type = NetworkManager::findBestWirelessSecurity(spec_dev->wirelessCapabilities()
|
||||
, true, (spec_dev->mode() == NetworkManager::WirelessDevice::Adhoc)
|
||||
, access_point->capabilities(), access_point->wpaFlags(), access_point->rsnFlags());
|
||||
|
||||
qDebug() << "findBestWirelessSecurity type "<< sec_type;
|
||||
switch (sec_type)
|
||||
{
|
||||
case NetworkManager::UnknownSecurity:
|
||||
qWarning() << QStringLiteral("unknown security to use for '%1'").arg(conn_name);
|
||||
case NetworkManager::NoneSecurity:
|
||||
//nothing to do
|
||||
break;
|
||||
case NetworkManager::WpaPsk:
|
||||
case NetworkManager::Wpa2Psk:
|
||||
if (NetworkManager::ConnectionSettings::Ptr settings = assembleWpaXPskSettings(access_point,psk))
|
||||
{
|
||||
map_settings = settings->toMap();
|
||||
} else
|
||||
{
|
||||
qWarning() << QStringLiteral("connection settings assembly for '%1' failed, abandoning activation...").arg(conn_name);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
//TODO: other types...
|
||||
}
|
||||
|
||||
QDBusPendingCallWatcher * watcher;
|
||||
watcher = new QDBusPendingCallWatcher{NetworkManager::addAndActivateConnection(map_settings, dev_uni, spec_object), this};
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) {
|
||||
if (watcher->isError() || !watcher->isValid())
|
||||
{
|
||||
//TODO: in what form should we output the warning messages
|
||||
qDebug() << "activation of connection failed " << watcher->error().message();
|
||||
}
|
||||
else{
|
||||
emit checkActiveonnection((qdbus_cast<QDBusObjectPath>(watcher->reply().arguments().at(1))).path());
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
void KyNetworkConnect::onActivateWirelessConnection(const QString &connectSsid, const QString &connectUuid)
|
||||
{
|
||||
qDebug() << "onActivateWirelessConnection" << connectSsid;
|
||||
NetworkManager::WirelessNetwork::Ptr wirelessNet = nullptr;
|
||||
for (auto const & net : m_networkResourceInstance->m_wifiNets)
|
||||
{
|
||||
qDebug() << net->ssid() << " " << connectSsid;
|
||||
if (net->ssid() == connectSsid)
|
||||
{
|
||||
wirelessNet = net;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (wirelessNet.isNull())
|
||||
{
|
||||
//TODO:隐藏wifi不会存在与AP中,需要新建connection去连接
|
||||
qDebug() << "hidewifi";emit noConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "非隐藏wifi";
|
||||
NetworkManager::Connection::Ptr connectPtr = m_networkResourceInstance->getConnect(connectUuid);
|
||||
if (connectPtr.isNull())
|
||||
{
|
||||
//无配置文件,前段输入完密码直接调用addAndActivateWirelessConnection
|
||||
qDebug() << "emit noConnection";
|
||||
emit noConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
// //获取安全类型
|
||||
// NetworkManager::ConnectionSettings::Ptr settings = connectPtr->settings();
|
||||
// NetworkManager::WirelessSecuritySetting::Ptr wifiSecurity =
|
||||
// settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
// int key_mgmt = wifiSecurity->keyMgmt();
|
||||
|
||||
//获取密码存储策略 0:所有用户存储 1:当前用户存储 2:每次连接询问
|
||||
NetworkManager::ConnectionSettings::Ptr settings = connectPtr->settings();
|
||||
NetworkManager::WirelessSecuritySetting::Ptr wifiSecurity =
|
||||
settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
int psk_flag = wifiSecurity->pskFlags();
|
||||
|
||||
qDebug() << "psk_flag=" <<psk_flag;
|
||||
|
||||
if(psk_flag == NetworkManager::Setting::SecretFlagType::NotSaved)
|
||||
{
|
||||
//每次都要询问,前端弹出窗口
|
||||
qDebug() << "emit notSavedConnection";
|
||||
emit notSavedConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
activateWirelessConnection(wirelessNet);
|
||||
}
|
||||
|
||||
void KyNetworkConnect::onActivateWirelessConnectionWithPWD(const QString &connectSsid, const QString &psk, bool isNotSaved, const QString &connectUuid)
|
||||
{
|
||||
qDebug() << "onActivateWirelessConnectionWithPWD" << connectSsid;
|
||||
|
||||
if(isNotSaved && !connectUuid.isEmpty())
|
||||
{
|
||||
qDebug() << "每次都要询问";
|
||||
//修改connection psk
|
||||
NetworkManager::Connection::Ptr connectPtr = m_networkResourceInstance->getConnect(connectUuid);
|
||||
if (connectPtr.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr settings = connectPtr->settings();
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
qDebug() << connectPtr->path();
|
||||
security_sett->setPsk(psk);
|
||||
|
||||
//
|
||||
NetworkManager::WirelessNetwork::Ptr wirelessNet = nullptr;
|
||||
for (auto const & net : m_networkResourceInstance->m_wifiNets)
|
||||
{
|
||||
if (net->ssid() == connectSsid)
|
||||
{
|
||||
wirelessNet = net;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
activateWirelessConnection(wirelessNet);
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkManager::WirelessNetwork::Ptr wirelessNet = nullptr;
|
||||
for (auto const & net : m_networkResourceInstance->m_wifiNets)
|
||||
{
|
||||
if (net->ssid() == connectSsid)
|
||||
{
|
||||
wirelessNet = net;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (wirelessNet.isNull())
|
||||
{
|
||||
//TODO:隐藏wifi不会存在与AP中,需要新建connection去连接
|
||||
qDebug() << "hidewifi";
|
||||
return;
|
||||
}
|
||||
|
||||
addAndActivateWirelessConnection(wirelessNet,psk);
|
||||
}
|
||||
|
||||
|
||||
void KyNetworkConnect::onCheckActiveonnection(const QString &activeConnPath)
|
||||
{
|
||||
if (m_networkResourceInstance->m_activeConns.size() == 0)
|
||||
{
|
||||
qDebug() << "不存在activeConnPath";
|
||||
emit connResult(1);
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto const & activeConn : m_networkResourceInstance->m_activeConns)
|
||||
{
|
||||
if (activeConn->path() == activeConnPath)
|
||||
{
|
||||
qDebug() << "存在activeConnPath,且匹配"<<activeConnPath;
|
||||
qDebug() << activeConn->state();
|
||||
connect(activeConn.data(), &NetworkManager::ActiveConnection::stateChangedReason, this, &KyNetworkConnect::onStateChangedReason);
|
||||
return;
|
||||
}
|
||||
}
|
||||
qDebug() << "存在activeConnPath,但不匹配"<<activeConnPath;
|
||||
emit connResult(1);
|
||||
}
|
||||
|
||||
void KyNetworkConnect::onStateChangedReason(NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason)
|
||||
{
|
||||
qDebug() << "onStateChangedReason state:" << state << " reason" << reason;
|
||||
if (state == NetworkManager::ActiveConnection::State::Activated)
|
||||
{
|
||||
emit connResult(0);
|
||||
} else if (state == NetworkManager::ActiveConnection::State::Deactivating || state == NetworkManager::ActiveConnection::State::Deactivated) {
|
||||
emit connResult(1);
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef KYLINNETWORKCONNECT_H
|
||||
#define KYLINNETWORKCONNECT_H
|
||||
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include "kylinconnectsetting.h"
|
||||
|
||||
typedef enum{
|
||||
WIRED_CONNECT,
|
||||
WIFI_CONNECT,
|
||||
}KyConnectType;
|
||||
|
||||
class KyNetworkConnect : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KyNetworkConnect();
|
||||
~KyNetworkConnect();
|
||||
|
||||
public:
|
||||
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);
|
||||
void activateWirelessConnection(NetworkManager::WirelessNetwork::Ptr wirelessNet);
|
||||
void addAndActivateWirelessConnection(NetworkManager::WirelessNetwork::Ptr wirelessNet, const QString &psk);
|
||||
int deactivateConnection(const QString connectName, const QString &uuid);
|
||||
void requestScan(const QString ifaceName);
|
||||
void requestAllWifiScan();
|
||||
|
||||
private:
|
||||
void connectSettingInit(
|
||||
NetworkManager::ConnectionSettings::Ptr connectionSettings,
|
||||
const KyConnectSetting &connectInfo);
|
||||
void ipv4SettingInit(NetworkManager::Ipv4Setting::Ptr &ipv4Setting,
|
||||
const KyConnectSetting &connectInfo);
|
||||
void ipv6SettingInit(NetworkManager::Ipv6Setting::Ptr &ipv6Setting,
|
||||
const KyConnectSetting &connectInfo);
|
||||
|
||||
void createWiredConnect(const KyConnectSetting &connectInfo);
|
||||
|
||||
signals:
|
||||
void activateConnectionFinished(NetworkManager::Connection::Ptr &conn);
|
||||
void deactivateConnectionFinished(NetworkManager::Connection::Ptr &conn);
|
||||
|
||||
void noConnection();
|
||||
void notSavedConnection();
|
||||
|
||||
signals:
|
||||
void checkActiveonnection(const QString &activeConn);
|
||||
void connResult(int);
|
||||
void starWaiting();
|
||||
|
||||
public slots:
|
||||
void onActivateWirelessConnection(const QString &connectSsid, const QString &connectUuid);
|
||||
void onActivateWirelessConnectionWithPWD(const QString &connectSsid, const QString &psk, bool isNotSaved, const QString &connectUuid);
|
||||
void onCheckActiveonnection(const QString &activeConn);
|
||||
void onStateChangedReason(NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason);
|
||||
|
||||
private:
|
||||
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
|
||||
};
|
||||
|
||||
#endif // KYLINNETWORKCONNECT_H
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "kylinnetworkdeviceresource.h"
|
||||
|
||||
KyNetworkDeviceResourse::KyNetworkDeviceResourse()
|
||||
KyNetworkDeviceResourse::KyNetworkDeviceResourse(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
|
||||
|
@ -74,7 +74,7 @@ void KyNetworkDeviceResourse::getHardwareInfo(QString ifaceName, QString &hardAd
|
|||
{
|
||||
hardAddress = "";
|
||||
bandWith = 0;
|
||||
qWarning()<<"the network device type is undefined"<<connectDevice->type();
|
||||
qWarning()<<"[KyNetworkDeviceResourse]" <<"the network device type is undefined"<<connectDevice->type();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ class KyNetworkDeviceResourse : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KyNetworkDeviceResourse();
|
||||
explicit KyNetworkDeviceResourse(QObject *parent = nullptr);
|
||||
~KyNetworkDeviceResourse();
|
||||
|
||||
signals:
|
||||
|
|
|
@ -36,7 +36,7 @@ void KyNetworkResourceManager::Release()
|
|||
}
|
||||
}
|
||||
|
||||
KyNetworkResourceManager::KyNetworkResourceManager()
|
||||
KyNetworkResourceManager::KyNetworkResourceManager(QObject *parent) : QObject(parent)
|
||||
{
|
||||
insertActiveConnections();
|
||||
insertConnections();
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
static void Release();
|
||||
|
||||
public:
|
||||
explicit KyNetworkResourceManager();
|
||||
explicit KyNetworkResourceManager(QObject *parent = nullptr);
|
||||
~KyNetworkResourceManager();
|
||||
|
||||
void removeActiveConnection(int pos);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "kylinvpnconnectitem.h"
|
||||
|
||||
|
||||
KyVpnConnectItem::KyVpnConnectItem()
|
||||
KyVpnConnectItem::KyVpnConnectItem(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_vpnName = "";
|
||||
m_vpnUuid = "";
|
||||
|
|
|
@ -9,7 +9,7 @@ class KyVpnConnectItem : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KyVpnConnectItem();
|
||||
explicit KyVpnConnectItem(QObject *parent = nullptr);
|
||||
~KyVpnConnectItem();
|
||||
|
||||
public:
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
#include <NetworkManagerQt/Ipv6Setting>
|
||||
#include <NetworkManagerQt/WiredSetting>
|
||||
|
||||
KyWiredConnectOperation::KyWiredConnectOperation()
|
||||
KyWiredConnectOperation::KyWiredConnectOperation(QObject *parent) : KyConnectOperation(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
KyWiredConnectOperation::~KyWiredConnectOperation()
|
||||
|
@ -34,10 +35,33 @@ KyWiredConnectOperation::~KyWiredConnectOperation()
|
|||
|
||||
void KyWiredConnectOperation::createWiredConnect(KyConnectSetting &connectSettingsInfo)
|
||||
{
|
||||
qDebug()<<"create wired connect";
|
||||
qDebug()<<"[KyWiredConnectOperation]" << "create connect ";
|
||||
connectSettingsInfo.dumpInfo();
|
||||
|
||||
createConnect(connectSettingsInfo);
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ class KyWiredConnectOperation : public KyConnectOperation
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KyWiredConnectOperation();
|
||||
explicit KyWiredConnectOperation(QObject *parent = nullptr);
|
||||
~KyWiredConnectOperation();
|
||||
|
||||
public:
|
||||
|
|
|
@ -74,7 +74,7 @@ NetworkManager::ConnectionSettings::Ptr assembleWpaXPskHiddenSettings(QString &s
|
|||
return settings;
|
||||
}
|
||||
|
||||
KyWirelessConnectOperation::KyWirelessConnectOperation(QObject *parent) : QObject(parent)
|
||||
KyWirelessConnectOperation::KyWirelessConnectOperation(QObject *parent) : KyConnectOperation(parent)
|
||||
{
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::wifinEnabledChanged, this, &KyWirelessConnectOperation::wifinEnabledChanged);
|
||||
|
@ -87,6 +87,9 @@ KyWirelessConnectOperation::~KyWirelessConnectOperation()
|
|||
|
||||
void KyWirelessConnectOperation::activeWirelessConnect(QString devIfaceName, QString connUuid)
|
||||
{
|
||||
activateConnection(connUuid);
|
||||
return;
|
||||
#if 0
|
||||
NetworkManager::Connection::Ptr conn;
|
||||
conn = m_networkResourceInstance->getConnect(connUuid);
|
||||
if (conn.isNull())
|
||||
|
@ -118,6 +121,13 @@ void KyWirelessConnectOperation::activeWirelessConnect(QString devIfaceName, QSt
|
|||
qDebug() << "5";
|
||||
watcher->deleteLater();
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void KyWirelessConnectOperation::deactivateWirelessConnection(const QString activeConnectName, const QString &activeConnectUuid)
|
||||
{
|
||||
deactivateConnection(activeConnectName, activeConnectUuid);
|
||||
return;
|
||||
}
|
||||
|
||||
//void KyWirelessConnectOperation::activeWirelessConnectWithPwd(QString devIfaceName, QString connUuid, QString psk)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QObject>
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include "kyenterpricesettinginfo.h"
|
||||
//#include "kylinconnectinfo.h"
|
||||
#include "kylinconnectoperation.h"
|
||||
|
||||
enum KySecuType {
|
||||
NONE = 0,
|
||||
|
@ -13,7 +13,7 @@ enum KySecuType {
|
|||
WPA2_AND_WPA3_PERSONAL
|
||||
};
|
||||
|
||||
class KyWirelessConnectOperation : public QObject
|
||||
class KyWirelessConnectOperation : public KyConnectOperation
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -26,6 +26,7 @@ public:
|
|||
bool getConnSecretFlags(QString &, NetworkManager::Setting::SecretFlags &);
|
||||
|
||||
void activeWirelessConnect(QString , QString);
|
||||
void deactivateWirelessConnection(const QString activeConnectName, const QString &activeConnectUuid);
|
||||
//todo:
|
||||
// void activeWirelessConnectWithPwd(QString , QString, QString);
|
||||
void deActiveWirelessConnect(QString &);
|
||||
|
|
|
@ -33,7 +33,7 @@ NmDemo::NmDemo(QWidget *parent) : QDialog(parent)
|
|||
|
||||
//init ptr
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
m_wco = new KyWirelessConnectOperation(this);
|
||||
m_wco = new KyWirelessConnectOperation();
|
||||
m_wnr = new KyWirelessNetResource(this);
|
||||
m_timer = new QTimer(this);
|
||||
|
||||
|
|
|
@ -229,6 +229,7 @@ OneConnForm::OneConnForm(QWidget *parent, MainWindow *mainWindow, ConfForm *conf
|
|||
m_menu = new QMenu();//右键菜单
|
||||
connect(m_menu, &QMenu::triggered, this, &OneConnForm::onMenuTriggered);
|
||||
|
||||
#if 0
|
||||
m_networkConnect = new KyNetworkConnect();
|
||||
connect(this, &OneConnForm::activateWirelessConnection, m_networkConnect, &KyNetworkConnect::onActivateWirelessConnection);
|
||||
connect(this, &OneConnForm::activateWirelessConnectionWithPWD, m_networkConnect, &KyNetworkConnect::onActivateWirelessConnectionWithPWD);
|
||||
|
@ -238,7 +239,7 @@ OneConnForm::OneConnForm(QWidget *parent, MainWindow *mainWindow, ConfForm *conf
|
|||
connect(m_networkConnect, &KyNetworkConnect::starWaiting, [=](){
|
||||
this->startWifiWaiting(true);
|
||||
});
|
||||
|
||||
#endif
|
||||
|
||||
connect(this, SIGNAL(connDone(int)), mw, SLOT(connWifiDone(int)));
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "backthread.h"
|
||||
#include "ksimplenm.h"
|
||||
#include "wpawifidialog.h"
|
||||
#include "kylinnetworkconnect.h"
|
||||
//#include "kylinnetworkconnect.h"
|
||||
|
||||
#define FRAME_SPEED 150
|
||||
#define LIMIT_TIME 90*1000
|
||||
|
@ -168,7 +168,7 @@ private:
|
|||
QString key_mgmt, funcBtnQss;
|
||||
QPushButton *btnProperty = nullptr;
|
||||
QMenu * m_menu = nullptr;
|
||||
KyNetworkConnect *m_networkConnect = nullptr;
|
||||
KyWiredConnectOperation *m_networkConnect = nullptr;
|
||||
|
||||
signals:
|
||||
void selectedOneWifiForm(QString wifiName, int extendLength);
|
||||
|
|
Loading…
Reference in New Issue