From 1eef4e2e7236ca9b3feeda20f285a86f221c267e Mon Sep 17 00:00:00 2001 From: renpeijia Date: Fri, 9 Jul 2021 09:10:26 +0800 Subject: [PATCH] =?UTF-8?q?=20=20=20=20feature:1=E3=80=81add=20create=20co?= =?UTF-8?q?nnect=E3=80=81update=20connect=20and=20delete=20connect=20funct?= =?UTF-8?q?ion=20with=20wired=E3=80=82=20=20=20=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?=202=E3=80=81add=20library=20in=20control=20file=20of=20debian?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debian/control | 2 + debian/files | 4 +- kylin-nm.pro | 2 + src/confform.cpp | 232 +++++++--------------------- src/confform.h | 11 ++ src/kylinconnectinfo.cpp | 99 ++++++++++++ src/kylinconnectinfo.h | 69 +++++++++ src/kylinnetworkconnect.cpp | 173 ++++++++++++++++++++- src/kylinnetworkconnect.h | 42 ++++- src/kylinnetworkresourcemanager.cpp | 45 +++++- src/kylinnetworkresourcemanager.h | 23 +++ 11 files changed, 524 insertions(+), 178 deletions(-) create mode 100644 src/kylinconnectinfo.cpp create mode 100644 src/kylinconnectinfo.h diff --git a/debian/control b/debian/control index 407e9ee3..444ec3e9 100644 --- a/debian/control +++ b/debian/control @@ -15,6 +15,8 @@ Build-Depends: debhelper (>=9), libkf5windowsystem-dev, libx11-dev, libqt5svg5-dev, + libkf5networkmanagerqt-dev (>= 5.36.0), + libnm-dev, Standards-Version: 4.5.0 Rules-Requires-Root: no Homepage: https://github.com/ukui/kylin-nm diff --git a/debian/files b/debian/files index a92036ad..1587e6bf 100644 --- a/debian/files +++ b/debian/files @@ -1 +1,3 @@ -kylin-nm_3.0.1-1kylin54_source.buildinfo utils optional +kylin-nm-dbgsym_3.0.1-1kylin54_amd64.ddeb debug optional automatic=yes +kylin-nm_3.0.1-1kylin54_amd64.buildinfo utils optional +kylin-nm_3.0.1-1kylin54_amd64.deb utils optional diff --git a/kylin-nm.pro b/kylin-nm.pro index 473a213c..ebafc26d 100644 --- a/kylin-nm.pro +++ b/kylin-nm.pro @@ -64,6 +64,7 @@ include(src/singleapplication/qt-single-application.pri) SOURCES += \ src/backthread.cpp \ + src/kylinconnectinfo.cpp \ src/kylinnetworkconnect.cpp \ src/kylinnetworkresourcemanager.cpp \ src/wifi-auth-thread.cpp \ @@ -98,6 +99,7 @@ SOURCES += \ HEADERS += \ src/backthread.h \ + src/kylinconnectinfo.h \ src/kylinnetworkconnect.h \ src/kylinnetworkresourcemanager.h \ src/wifi-auth-thread.h \ diff --git a/src/confform.cpp b/src/confform.cpp index 840e18ab..8d118e12 100644 --- a/src/confform.cpp +++ b/src/confform.cpp @@ -181,7 +181,7 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt lastIpv6 = v6addr; lastTypeIndex = ui->cbType->currentIndex(); netUuid = uuidName; - //qDebug() << Q_FUNC_INFO << __LINE__ << connName << uuidName; + qDebug() << Q_FUNC_INFO << connName << uuidName; isActWifi = false; if (isWiFi) { @@ -230,27 +230,43 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt ui->btnSave->setEnabled(false); } +void ConfForm::connectInfoConstruct(KyConnectInfo &connectInfo) +{ + QString connectName = ui->leName->text(); + + connectInfo.setConnectName(connectName); + connectInfo.setIfaceName(m_ifaceName); + if (MANUAL_IP == ui->cbType->currentIndex()) { + if (!ui->leAddr->text().isEmpty()) { + QString ipv4Address = ui->leAddr->text(); + QString ipv4NetMask = ui->cbMask->currentText(); + QString ipv4GateWay = ui->leGateway->text(); + + QStringList ipv4DnsList; + ipv4DnsList.clear(); + ipv4DnsList<leDns->text(); + if (ui->leDns2->text() != "") { + ipv4DnsList << ui->leDns2->text(); + } + + connectInfo.setIpConfigType(IPADDRESS_V4, CONFIG_IP_MANUAL); + connectInfo.ipv4AddressConstruct(ipv4Address, ipv4NetMask, + ipv4GateWay, ipv4DnsList); + } + + if (!ui->leAddr_ipv6->text().isEmpty()) { + qWarning()<<"ipv6 function need todo"; + } + } + + return; +} + //点击了创建新的网络的按钮 void ConfForm::on_btnCreate_clicked() { KylinDBus kylindbus; kylindbus.getWiredCardName(); - QString mIfname; - - QString mask = ""; - if (ui->cbMask->currentIndex() == 0) { - mask = "24"; - } else if(ui->cbMask->currentIndex() == 1) { - mask = "23"; - } else if(ui->cbMask->currentIndex() == 2) { - mask = "22"; - } else if(ui->cbMask->currentIndex() == 3) { - mask = "16"; - } else if(ui->cbMask->currentIndex() == 4) { - mask = "8"; - } else { - mask = "24"; - } if (kylindbus.multiWiredIfName.size() == 0) { QString tip(tr("Can not create new wired network for without wired card")); @@ -258,64 +274,28 @@ void ConfForm::on_btnCreate_clicked() onConfformHide(); return; } else { - mIfname = kylindbus.multiWiredIfName.at(0); + m_ifaceName = kylindbus.multiWiredIfName.at(0); } - if (ui->cbType->currentIndex() == 1) { + if (ui->cbType->currentIndex() == MANUAL_IP) { //在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突 if (!ui->leAddr->text().isEmpty()|| !ui->leAddr_ipv6->text().isEmpty()) { - if (check_ip_conflict(mIfname)) { + if (check_ip_conflict(m_ifaceName)) { return; } } } - QString name = ui->leName->text(); - QString cmdStr; - if(ui->cbType->currentIndex() == 0){ - cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet"; - }else{ - if (ui->leAddr->text().isEmpty()) { //只配置了ipv6地址 - cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet ipv4.method auto ipv6.method manual ipv6.address " - + ui->leAddr_ipv6->text(); - } else if (ui->leAddr_ipv6->text().isEmpty()) { //只配置了ipv4地址 - cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet ipv6.method auto ipv4.method manual ipv4.address " - + ui->leAddr->text() + "/" + mask.toUtf8().data(); - } else { - cmdStr = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet ipv6.method manual ipv6.address " + ui->leAddr_ipv6->text() - + " ipv4.method manual ipv4.address " + ui->leAddr->text() + "/" + mask.toUtf8().data(); - } - if(!ui->leGateway->text().isEmpty()){ - cmdStr += " ipv4.gateway " + ui->leGateway->text(); - } - if(!ui->leDns->text().isEmpty()){ - cmdStr += " ipv4.dns " + ui->leDns->text(); - if(!ui->leDns2->text().isEmpty()){ - cmdStr += "," + ui->leDns2->text(); - } - } - } - cmdStr += " connection.autoconnect yes connection.autoconnect-priority 0"; - Utils::m_system(cmdStr.toUtf8().data()); - if (ui->cbType->currentIndex() == 1) { - //选择手动,配置Ipv4、掩码、网关 - this->isCreateNewNet = true; - newUuid = "--"; - this->saveNetworkConfiguration(); - } else { + KyConnectInfo newConnectInfo; + connectInfoConstruct(newConnectInfo); + m_networkConnect.createConnect(WIRED_CONNECT, newConnectInfo); + + if (DHCP_IP == ui->cbType->currentIndex()) { //选择自动,则配置完成并发出桌面通知 QString txt(tr("New network already created")); kylindbus.showDesktopNotify(txt); } -// if (!ui->leAddr_ipv6->text().isEmpty()) { -// QString cmdStr = "nmcli connection modify '" + name + "' ipv6.method manual ipv6.addresses " + ui->leAddr_ipv6->text(); -// Utils::m_system(cmdStr.toUtf8().data()); -// } else { -// QString cmdStr = "nmcli connection modify '" + name + "' ipv6.method auto"; -// Utils::m_system(cmdStr.toUtf8().data()); -// } - onConfformHide(); } @@ -326,10 +306,10 @@ void ConfForm::on_btnSave_clicked() if (isActWifi) { kylindbus.getWirelessCardName(); - QString mWifiIfname = kylindbus.dbusWiFiCardName; + m_ifaceName = kylindbus.dbusWiFiCardName; this->isCreateNewNet = false; - if (mWifiIfname.isEmpty()) { + if (m_ifaceName.isEmpty()) { QString notifyTxt(tr("Wireless card not exist")); kylindbus.showDesktopNotify(notifyTxt); return; @@ -337,7 +317,7 @@ void ConfForm::on_btnSave_clicked() if (ui->cbType->currentIndex() == 1) { //在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突 if ((!ui->leAddr->text().isEmpty() && (ui->leAddr->text() != lastIpv4)) || (!ui->leAddr_ipv6->text().isEmpty() && (ui->leAddr_ipv6->text() != lastIpv6))) { - if (check_ip_conflict(mWifiIfname)) { + if (check_ip_conflict(m_ifaceName)) { return; } } @@ -346,8 +326,6 @@ void ConfForm::on_btnSave_clicked() this->saveNetworkConfiguration(); } else { kylindbus.getWiredCardName(); - QString mIfname; - if (kylindbus.multiWiredIfName.size() == 0) { QString tip(tr("Can not save wired network for without wired card")); kylindbus.showDesktopNotify(tip); @@ -355,64 +333,22 @@ void ConfForm::on_btnSave_clicked() onConfformHide(); return; } else { - mIfname = kylindbus.multiWiredIfName.at(0); + m_ifaceName = kylindbus.multiWiredIfName.at(0); } - //如果网络的名称已经修改,则删掉当前网络,新建一个网络 - //修改为 直接modify 不删除不新建 - QString name = ui->leName->text(); - if (name != lastConnName) { - // QString cmd = "nmcli connection delete '" + netUuid + "'"; - QString cmd = "nmcli connection modify '" + lastConnName + "' con-name '"+name+"'"; - int status = system(cmd.toUtf8().data()); - qDebug()<<"executed 'nmcli connection modify'. cmd="<start("/bin/bash",options); - // connect(processAdd, static_cast(&QProcess::finished), this, [ = ]() { - // processAdd->deleteLater(); - // }); - // connect(processAdd, &QProcess::channelReadyRead, this, [ = ]() { - // QString str = processAdd->readAll(); - // QString regExpPattern("[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}"); - // QRegExp regExpTest(regExpPattern); - // int pos = str.indexOf(regExpTest); - // newUuid = str.mid(pos,36); //36是uuid的长度 - - if (ui->cbType->currentIndex() == 1) { - //在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突 - if ((!ui->leAddr->text().isEmpty() && (ui->leAddr->text() != lastIpv4)) || (!ui->leAddr_ipv6->text().isEmpty() && (ui->leAddr_ipv6->text() != lastIpv6))) { - if (check_ip_conflict(mIfname)) { - return; - } - } - } - - this->saveNetworkConfiguration(); - return; - // }); - // processAdd->waitForFinished(); - } else { - this->isCreateNewNet = false; - newUuid = "--"; - - if (ui->cbType->currentIndex() == 1) { - //在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突 - if ((!ui->leAddr->text().isEmpty() && (ui->leAddr->text() != lastIpv4)) || (!ui->leAddr_ipv6->text().isEmpty() && (ui->leAddr_ipv6->text() != lastIpv6))) { - if (check_ip_conflict(mIfname)) { - return; - } + if (ui->cbType->currentIndex() == 1) { + //在手动配置网络的情况下以及当前的IP参数有更改的情况下,检测IP冲突 + if ((!ui->leAddr->text().isEmpty() && (ui->leAddr->text() != lastIpv4)) || (!ui->leAddr_ipv6->text().isEmpty() && (ui->leAddr_ipv6->text() != lastIpv6))) { + if (check_ip_conflict(m_ifaceName)) { + return; } } - - this->saveNetworkConfiguration(); } + + this->saveNetworkConfiguration(); + } QString txt(tr("New network settings already finished")); kylindbus.showDesktopNotify(txt); @@ -420,67 +356,19 @@ void ConfForm::on_btnSave_clicked() void ConfForm::saveNetworkConfiguration() { - //获取对应掩码的参数 - QString mask = ""; - if (ui->cbMask->currentIndex() == 0) { - mask = "24"; - } else if(ui->cbMask->currentIndex() == 1) { - mask = "23"; - } else if(ui->cbMask->currentIndex() == 2) { - mask = "22"; - } else if(ui->cbMask->currentIndex() == 3) { - mask = "16"; - } else if(ui->cbMask->currentIndex() == 4) { - mask = "8"; - } else { - mask = "24"; - } + KylinDBus kylindbus; + + KyConnectInfo newConnectInfo; + connectInfoConstruct(newConnectInfo); + m_networkConnect.updateConnect(netUuid, newConnectInfo); - QString name = ui->leName->text(); - QString dnss = ui->leDns->text(); - if (ui->leDns2->text() != "") { - dnss.append(","); - dnss.append(ui->leDns2->text()); - } //是选择的自动还是手动配置网络 - if (ui->cbType->currentIndex() == 0) { - qDebug() << Q_FUNC_INFO << __LINE__ << name << newUuid << ui->leAddr->text() << mask << ui->leGateway->text(); - //kylin_network_set_automethod(name.toUtf8().data()); - kylin_network_set_automethod(netUuid.toUtf8().data()); - kylin_network_set_ipv6_automethod(netUuid.toUtf8().data()); + if (ui->cbType->currentIndex() == DHCP_IP) { if (this->isActConf && lastTypeIndex == 1 && ui->cbType->currentIndex() == 0) { //对于已经连接的网络,若由手动改为自动,则进行重连以保证配置生效 - KylinDBus kylindbus; kylindbus.reConnectWiredNet(netUuid.toUtf8().data()); } } - else { - if (newUuid != "--" && newUuid != "" && !newUuid.isEmpty()) { - qDebug() << Q_FUNC_INFO << __LINE__ << name << newUuid << ui->leAddr->text() << mask << ui->leGateway->text() << dnss; - if (!ui->leAddr->text().isEmpty()) { - kylin_network_set_manualall(newUuid.toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data()); - } else { - kylin_network_set_automethod(newUuid.toUtf8().data()); - } - if (!ui->leAddr_ipv6->text().isEmpty()) { - kylin_network_set_ipv6_manualmethod(newUuid.toUtf8().data(), ui->leAddr_ipv6->text().toUtf8().data()); - } else { - kylin_network_set_ipv6_automethod(newUuid.toUtf8().data()); - } - } else { - qDebug() << Q_FUNC_INFO << __LINE__ << name << netUuid << ui->leAddr->text() << mask << ui->leGateway->text() << dnss; - if (!ui->leAddr->text().isEmpty()) { - kylin_network_set_manualall(netUuid.toUtf8().data(), ui->leAddr->text().toUtf8().data(), mask.toUtf8().data(), ui->leGateway->text().toUtf8().data(), dnss.toUtf8().data()); - } else { - kylin_network_set_automethod(netUuid.toUtf8().data()); - } - if (!ui->leAddr_ipv6->text().isEmpty()) { - kylin_network_set_ipv6_manualmethod(netUuid.toUtf8().data(), ui->leAddr_ipv6->text().toUtf8().data()); - } else { - kylin_network_set_ipv6_automethod(netUuid.toUtf8().data()); - } - } - } onConfformHide(); } diff --git a/src/confform.h b/src/confform.h index ee10a93a..702ebf97 100644 --- a/src/confform.h +++ b/src/confform.h @@ -28,11 +28,18 @@ #include #include #include "kylin-dbus-interface.h" +#include "kylinnetworkconnect.h" +#include "kylinconnectinfo.h" namespace Ui { class ConfForm; } +enum{ + DHCP_IP = 0, + MANUAL_IP = 1, +}; + class ConfForm : public QDialog { Q_OBJECT @@ -90,6 +97,7 @@ private: bool check_ip_conflict(QString ifname); void onConfformHide(); bool isEditingAlready(); //连接按钮是否可被按 + void connectInfoConstruct(KyConnectInfo &connectInfo); bool isPress; QPoint winPos; @@ -105,6 +113,9 @@ private: QString labelQss, cbxQss, leQss, lineQss, btnOnQss, btnOffQss; + KyNetworkConnect m_networkConnect; + QString m_ifaceName; + signals: void requestRefreshLanList(int updateType); }; diff --git a/src/kylinconnectinfo.cpp b/src/kylinconnectinfo.cpp new file mode 100644 index 00000000..7059bce2 --- /dev/null +++ b/src/kylinconnectinfo.cpp @@ -0,0 +1,99 @@ +/* + * 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 + +KyConnectInfo::KyConnectInfo() +{ + m_connectName = ""; + m_ifaceName = ""; + + m_ipv4ConfigIpType = CONFIG_IP_DHCP; + m_ipv4Address.clear(); + m_ipv4Dns.clear(); + + m_ipv6ConfigIpType = CONFIG_IP_DHCP; + m_ipv6Address.clear(); + m_ipv6Dns.clear(); +} + +KyConnectInfo::~KyConnectInfo() +{ + +} + +void KyConnectInfo::setIfaceName(QString &ifaceName) +{ + m_ifaceName = ifaceName; +} + +void KyConnectInfo::setConnectName(QString &connectName) +{ + m_connectName = connectName; +} + +int KyConnectInfo::setIpConfigType(KyIpAddressType ipType, KyIpConfigType ipConfigType) +{ + if (ipType != IPADDRESS_V4 && ipType != IPADDRESS_V6) { + qWarning()<<"set config ip type failed, the ip address type undefined"< +#include +#include + +#include +#include +#include +#include +#include + +typedef enum { + CONFIG_IP_MANUAL, + CONFIG_IP_DHCP, +}KyIpConfigType; + +typedef enum { + IPADDRESS_V4, + IPADDRESS_V6, +}KyIpAddressType; + +class KyConnectInfo : public QObject +{ + Q_OBJECT +public: + KyConnectInfo(); + ~KyConnectInfo(); + +public: + void setIfaceName(QString &ifaceName); + void setConnectName(QString &connectName); + 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); + +public: + QString m_connectName; + QString m_ifaceName; + + KyIpConfigType m_ipv4ConfigIpType; + QList m_ipv4Address; + QList m_ipv4Dns; + + KyIpConfigType m_ipv6ConfigIpType; + QList m_ipv6Address; + QList m_ipv6Dns; +}; + +#endif // KYLINCONNECTINFO_H diff --git a/src/kylinnetworkconnect.cpp b/src/kylinnetworkconnect.cpp index 17e2ca53..9327e9b9 100644 --- a/src/kylinnetworkconnect.cpp +++ b/src/kylinnetworkconnect.cpp @@ -1,7 +1,32 @@ +/* + * Copyright (C) 2020 Tianjin KYLIN Information Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see +#include +#include +#include +#include + KyNetworkConnect::KyNetworkConnect() { + qDebug()<<"construct network connect"; m_networkResourceInstance = KyNetworkResourceManager::getInstance(); } @@ -10,6 +35,147 @@ KyNetworkConnect::~KyNetworkConnect() m_networkResourceInstance = nullptr; } +void KyNetworkConnect::ipv4SettingInit( + NetworkManager::Ipv4Setting::Ptr &ipv4Setting, + const KyConnectInfo &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 KyConnectInfo &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 KyConnectInfo &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 KyConnectInfo &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(); + ipv4SettingInit(ipv4Setting, connectInfo); + + NetworkManager::Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast(); + ipv6SettingInit(ipv6Setting, connectInfo); + + NetworkManager::WiredSetting::Ptr wiredSetting = connectionSettings->setting(NetworkManager::Setting::Wired).dynamicCast(); + wiredSetting->setInitialized(true); + + qDebug()<<"add wired connect"<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"<reply().errorName() <<"error msg"<reply().errorMessage(); + qWarning()<<"error type"<error().type(); + } + watcher->deleteLater(); + }); + + return; +} + +void KyNetworkConnect::createConnect(KyConnectType connectType, const KyConnectInfo &connectInfo) +{ + switch (connectType) { + case WIRED_CONNECT: + qDebug()<<"create wired connect"; + createWiredConnect(connectInfo); + break; + default: + qWarning()<<"the connect type undefined"<settings(); + connectSettingInit(connectionSettings, connectInfo); + + NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast(); + ipv4SettingInit(ipv4Setting, connectInfo); + + NetworkManager::Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast(); + ipv6SettingInit(ipv6Setting, connectInfo); + + NetworkManager::WiredSetting::Ptr wiredSetting = connectionSettings->setting(NetworkManager::Setting::Wired).dynamicCast(); + 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; @@ -70,9 +236,12 @@ int KyNetworkConnect::activateConnection(const QString connectUuid) 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() << QStringLiteral("activation of connection '%1' on interface '%2' failed: %3").arg(conn_name) - .arg(dev_name).arg(watcher->error().message()); + qWarning() << "activate connection failed: " << watcher->error().message(); + } else { + qWarning()<<"success"<reply().errorName() <<"error msg"<reply().errorMessage(); + qWarning()<<"error type"<error().type(); } + watcher->deleteLater(); }); diff --git a/src/kylinnetworkconnect.h b/src/kylinnetworkconnect.h index ed5cd553..26d2be4b 100644 --- a/src/kylinnetworkconnect.h +++ b/src/kylinnetworkconnect.h @@ -1,7 +1,31 @@ +/* + * 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 type()) { @@ -344,11 +364,34 @@ void KyNetworkResourceManager::onActiveConnectionUpdated() emit activeConnectionUpdate(qobject_cast(sender())); } +void KyNetworkResourceManager::onActiveConnectionChangedReason(NetworkManager::ActiveConnection::State state, + NetworkManager::ActiveConnection::Reason reason) +{ + qWarning()<<"the active connect state"<(sender())); } +void KyNetworkResourceManager::onDeviceStateChanged( + NetworkManager::Device::State newstate, + NetworkManager::Device::State oldstate, + NetworkManager::Device::StateChangeReason reason) +{ + NetworkManager::WiredDevice *wiredDevice = qobject_cast(sender()); + if (wiredDevice->carrier()) { + qWarning()<<"the device carrier true"; + } else { + qWarning()<<"the device carrier false"; + } + + qWarning()<<"the device state "<(sender()); diff --git a/src/kylinnetworkresourcemanager.h b/src/kylinnetworkresourcemanager.h index 7001811e..f256bdcd 100644 --- a/src/kylinnetworkresourcemanager.h +++ b/src/kylinnetworkresourcemanager.h @@ -1,3 +1,21 @@ +/* + * 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