Merge branch 'kylin-nm-dbus-renpj' into 'dbus-interface'

feature:1、add create connect、update connect and delete connect function with wired。

See merge request kylin-desktop/kylin-nm!99
This commit is contained in:
ren peijia 2021-07-09 02:42:09 +00:00
commit c41e070e53
11 changed files with 524 additions and 178 deletions

2
debian/control vendored
View File

@ -15,6 +15,8 @@ Build-Depends: debhelper (>=9),
libkf5windowsystem-dev, libkf5windowsystem-dev,
libx11-dev, libx11-dev,
libqt5svg5-dev, libqt5svg5-dev,
libkf5networkmanagerqt-dev (>= 5.36.0),
libnm-dev,
Standards-Version: 4.5.0 Standards-Version: 4.5.0
Rules-Requires-Root: no Rules-Requires-Root: no
Homepage: https://github.com/ukui/kylin-nm Homepage: https://github.com/ukui/kylin-nm

4
debian/files vendored
View File

@ -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

View File

@ -64,6 +64,7 @@ include(src/singleapplication/qt-single-application.pri)
SOURCES += \ SOURCES += \
src/backthread.cpp \ src/backthread.cpp \
src/kylinconnectinfo.cpp \
src/kylinnetworkconnect.cpp \ src/kylinnetworkconnect.cpp \
src/kylinnetworkresourcemanager.cpp \ src/kylinnetworkresourcemanager.cpp \
src/wifi-auth-thread.cpp \ src/wifi-auth-thread.cpp \
@ -98,6 +99,7 @@ SOURCES += \
HEADERS += \ HEADERS += \
src/backthread.h \ src/backthread.h \
src/kylinconnectinfo.h \
src/kylinnetworkconnect.h \ src/kylinnetworkconnect.h \
src/kylinnetworkresourcemanager.h \ src/kylinnetworkresourcemanager.h \
src/wifi-auth-thread.h \ src/wifi-auth-thread.h \

View File

@ -181,7 +181,7 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt
lastIpv6 = v6addr; lastIpv6 = v6addr;
lastTypeIndex = ui->cbType->currentIndex(); lastTypeIndex = ui->cbType->currentIndex();
netUuid = uuidName; netUuid = uuidName;
//qDebug() << Q_FUNC_INFO << __LINE__ << connName << uuidName; qDebug() << Q_FUNC_INFO << connName << uuidName;
isActWifi = false; isActWifi = false;
if (isWiFi) { if (isWiFi) {
@ -230,27 +230,43 @@ void ConfForm::setProp(QString connName, QString uuidName, QString v4method, QSt
ui->btnSave->setEnabled(false); 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<<ui->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() void ConfForm::on_btnCreate_clicked()
{ {
KylinDBus kylindbus; KylinDBus kylindbus;
kylindbus.getWiredCardName(); 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) { if (kylindbus.multiWiredIfName.size() == 0) {
QString tip(tr("Can not create new wired network for without wired card")); QString tip(tr("Can not create new wired network for without wired card"));
@ -258,64 +274,28 @@ void ConfForm::on_btnCreate_clicked()
onConfformHide(); onConfformHide();
return; return;
} else { } 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冲突 //在手动配置网络的情况下以及当前的IP参数有更改的情况下检测IP冲突
if (!ui->leAddr->text().isEmpty()|| !ui->leAddr_ipv6->text().isEmpty()) { if (!ui->leAddr->text().isEmpty()|| !ui->leAddr_ipv6->text().isEmpty()) {
if (check_ip_conflict(mIfname)) { if (check_ip_conflict(m_ifaceName)) {
return; 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) { KyConnectInfo newConnectInfo;
//选择手动配置Ipv4、掩码、网关 connectInfoConstruct(newConnectInfo);
this->isCreateNewNet = true; m_networkConnect.createConnect(WIRED_CONNECT, newConnectInfo);
newUuid = "--";
this->saveNetworkConfiguration(); if (DHCP_IP == ui->cbType->currentIndex()) {
} else {
//选择自动,则配置完成并发出桌面通知 //选择自动,则配置完成并发出桌面通知
QString txt(tr("New network already created")); QString txt(tr("New network already created"));
kylindbus.showDesktopNotify(txt); 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(); onConfformHide();
} }
@ -326,10 +306,10 @@ void ConfForm::on_btnSave_clicked()
if (isActWifi) { if (isActWifi) {
kylindbus.getWirelessCardName(); kylindbus.getWirelessCardName();
QString mWifiIfname = kylindbus.dbusWiFiCardName; m_ifaceName = kylindbus.dbusWiFiCardName;
this->isCreateNewNet = false; this->isCreateNewNet = false;
if (mWifiIfname.isEmpty()) { if (m_ifaceName.isEmpty()) {
QString notifyTxt(tr("Wireless card not exist")); QString notifyTxt(tr("Wireless card not exist"));
kylindbus.showDesktopNotify(notifyTxt); kylindbus.showDesktopNotify(notifyTxt);
return; return;
@ -337,7 +317,7 @@ void ConfForm::on_btnSave_clicked()
if (ui->cbType->currentIndex() == 1) { if (ui->cbType->currentIndex() == 1) {
//在手动配置网络的情况下以及当前的IP参数有更改的情况下检测IP冲突 //在手动配置网络的情况下以及当前的IP参数有更改的情况下检测IP冲突
if ((!ui->leAddr->text().isEmpty() && (ui->leAddr->text() != lastIpv4)) || (!ui->leAddr_ipv6->text().isEmpty() && (ui->leAddr_ipv6->text() != lastIpv6))) { 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; return;
} }
} }
@ -346,8 +326,6 @@ void ConfForm::on_btnSave_clicked()
this->saveNetworkConfiguration(); this->saveNetworkConfiguration();
} else { } else {
kylindbus.getWiredCardName(); kylindbus.getWiredCardName();
QString mIfname;
if (kylindbus.multiWiredIfName.size() == 0) { if (kylindbus.multiWiredIfName.size() == 0) {
QString tip(tr("Can not save wired network for without wired card")); QString tip(tr("Can not save wired network for without wired card"));
kylindbus.showDesktopNotify(tip); kylindbus.showDesktopNotify(tip);
@ -355,64 +333,22 @@ void ConfForm::on_btnSave_clicked()
onConfformHide(); onConfformHide();
return; return;
} else { } else {
mIfname = kylindbus.multiWiredIfName.at(0); m_ifaceName = kylindbus.multiWiredIfName.at(0);
} }
//如果网络的名称已经修改,则删掉当前网络,新建一个网络 this->isCreateNewNet = false;
//修改为 直接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="<<cmd<<". res="<<status;
// this->isCreateNewNet = true; if (ui->cbType->currentIndex() == 1) {
// newUuid = "--"; //在手动配置网络的情况下以及当前的IP参数有更改的情况下检测IP冲突
if ((!ui->leAddr->text().isEmpty() && (ui->leAddr->text() != lastIpv4)) || (!ui->leAddr_ipv6->text().isEmpty() && (ui->leAddr_ipv6->text() != lastIpv6))) {
// QProcess * processAdd = new QProcess; if (check_ip_conflict(m_ifaceName)) {
// QString cmdAdd = "nmcli connection add con-name '" + name + "' ifname '" + mIfname + "' type ethernet"; return;
// QStringList options;
// options << "-c" << cmdAdd;
// processAdd->start("/bin/bash",options);
// connect(processAdd, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&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;
}
} }
} }
this->saveNetworkConfiguration();
} }
this->saveNetworkConfiguration();
} }
QString txt(tr("New network settings already finished")); QString txt(tr("New network settings already finished"));
kylindbus.showDesktopNotify(txt); kylindbus.showDesktopNotify(txt);
@ -420,67 +356,19 @@ void ConfForm::on_btnSave_clicked()
void ConfForm::saveNetworkConfiguration() void ConfForm::saveNetworkConfiguration()
{ {
//获取对应掩码的参数 KylinDBus kylindbus;
QString mask = "";
if (ui->cbMask->currentIndex() == 0) { KyConnectInfo newConnectInfo;
mask = "24"; connectInfoConstruct(newConnectInfo);
} else if(ui->cbMask->currentIndex() == 1) { m_networkConnect.updateConnect(netUuid, newConnectInfo);
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";
}
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) { if (ui->cbType->currentIndex() == DHCP_IP) {
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 (this->isActConf && lastTypeIndex == 1 && ui->cbType->currentIndex() == 0) { if (this->isActConf && lastTypeIndex == 1 && ui->cbType->currentIndex() == 0) {
//对于已经连接的网络,若由手动改为自动,则进行重连以保证配置生效 //对于已经连接的网络,若由手动改为自动,则进行重连以保证配置生效
KylinDBus kylindbus;
kylindbus.reConnectWiredNet(netUuid.toUtf8().data()); 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(); onConfformHide();
} }

View File

@ -28,11 +28,18 @@
#include <QDialog> #include <QDialog>
#include <QListView> #include <QListView>
#include "kylin-dbus-interface.h" #include "kylin-dbus-interface.h"
#include "kylinnetworkconnect.h"
#include "kylinconnectinfo.h"
namespace Ui { namespace Ui {
class ConfForm; class ConfForm;
} }
enum{
DHCP_IP = 0,
MANUAL_IP = 1,
};
class ConfForm : public QDialog class ConfForm : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -90,6 +97,7 @@ private:
bool check_ip_conflict(QString ifname); bool check_ip_conflict(QString ifname);
void onConfformHide(); void onConfformHide();
bool isEditingAlready(); //连接按钮是否可被按 bool isEditingAlready(); //连接按钮是否可被按
void connectInfoConstruct(KyConnectInfo &connectInfo);
bool isPress; bool isPress;
QPoint winPos; QPoint winPos;
@ -105,6 +113,9 @@ private:
QString labelQss, cbxQss, leQss, lineQss, btnOnQss, btnOffQss; QString labelQss, cbxQss, leQss, lineQss, btnOnQss, btnOffQss;
KyNetworkConnect m_networkConnect;
QString m_ifaceName;
signals: signals:
void requestRefreshLanList(int updateType); void requestRefreshLanList(int updateType);
}; };

99
src/kylinconnectinfo.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "kylinconnectinfo.h"
#include <QDebug>
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"<<ipType;
return -EINVAL;
}
if (CONFIG_IP_DHCP != ipConfigType && CONFIG_IP_MANUAL != ipConfigType) {
qWarning()<<"set config ip type failed, the config ip type undefined"<<ipConfigType;
return -EINVAL;
}
if (IPADDRESS_V4 == ipType) {
m_ipv4ConfigIpType = ipConfigType;
} else {
m_ipv6ConfigIpType = ipConfigType;
}
return 0;
}
void KyConnectInfo::ipv4AddressConstruct(QString &ipv4Address, QString &ipv4NetMask, QString &ipv4GateWay, QStringList &ipv4Dns)
{
qDebug()<<"ipv4 address"<<ipv4Address << ipv4NetMask << ipv4GateWay;
NetworkManager::IpAddress nmIpv4Address;
nmIpv4Address.setIp(QHostAddress(ipv4Address));
nmIpv4Address.setGateway(QHostAddress(ipv4GateWay));
nmIpv4Address.setNetmask(QHostAddress(ipv4NetMask));
m_ipv4Address << nmIpv4Address;
for (int index = 0; index < ipv4Dns.size(); ++index) {
qDebug()<<"dns"<<ipv4Dns[index];
m_ipv4Dns << QHostAddress(ipv4Dns[index]);
}
return ;
}
void KyConnectInfo::ipv6AddressConstruct(QString &ipv6Address, QString &ipv6NetMask, QString &ipv6GateWay, QStringList &ipv6Dns)
{
NetworkManager::IpAddress nmIpv6Address;
nmIpv6Address.setIp(QHostAddress(ipv6Address));
nmIpv6Address.setGateway(QHostAddress(ipv6GateWay));
nmIpv6Address.setPrefixLength(ipv6NetMask.toInt());
m_ipv6Address << nmIpv6Address;
for (int index = 0; index < ipv6Dns.size(); index++) {
m_ipv6Dns << QHostAddress(ipv6Dns[index]);
}
return ;
}

69
src/kylinconnectinfo.h Normal file
View File

@ -0,0 +1,69 @@
/*
* 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/&gt;.
*
*/
#ifndef KYLINCONNECTINFO_H
#define KYLINCONNECTINFO_H
#include <QStringList>
#include <QString>
#include <QObject>
#include <NetworkManagerQt/AdslDevice>
#include <NetworkManagerQt/WiredDevice>
#include <NetworkManagerQt/Ipv4Setting>
#include <NetworkManagerQt/Ipv6Setting>
#include <NetworkManagerQt/WiredSetting>
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<NetworkManager::IpAddress> m_ipv4Address;
QList<QHostAddress> m_ipv4Dns;
KyIpConfigType m_ipv6ConfigIpType;
QList<NetworkManager::IpAddress> m_ipv6Address;
QList<QHostAddress> m_ipv6Dns;
};
#endif // KYLINCONNECTINFO_H

View File

@ -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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "kylinnetworkconnect.h" #include "kylinnetworkconnect.h"
#include "sys/syslog.h" #include "sys/syslog.h"
@ -33,8 +51,15 @@ NetworkManager::ConnectionSettings::Ptr assembleWpaXPskSettings(const NetworkMan
} }
#include <NetworkManagerQt/AdslDevice>
#include <NetworkManagerQt/WiredDevice>
#include <NetworkManagerQt/Ipv4Setting>
#include <NetworkManagerQt/Ipv6Setting>
#include <NetworkManagerQt/WiredSetting>
KyNetworkConnect::KyNetworkConnect() KyNetworkConnect::KyNetworkConnect()
{ {
qDebug()<<"construct network connect";
m_networkResourceInstance = KyNetworkResourceManager::getInstance(); m_networkResourceInstance = KyNetworkResourceManager::getInstance();
connect(this, &KyNetworkConnect::checkActiveonnection, this, &KyNetworkConnect::onCheckActiveonnection); connect(this, &KyNetworkConnect::checkActiveonnection, this, &KyNetworkConnect::onCheckActiveonnection);
@ -45,6 +70,147 @@ KyNetworkConnect::~KyNetworkConnect()
m_networkResourceInstance = nullptr; 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<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 KyConnectInfo &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 KyConnectInfo &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) int KyNetworkConnect::activateConnection(const QString connectUuid)
{ {
QString conn_uni; QString conn_uni;
@ -105,9 +271,12 @@ int KyNetworkConnect::activateConnection(const QString connectUuid)
connect(watcher, &QDBusPendingCallWatcher::finished, [conn_name, dev_name] (QDBusPendingCallWatcher * watcher) { connect(watcher, &QDBusPendingCallWatcher::finished, [conn_name, dev_name] (QDBusPendingCallWatcher * watcher) {
if (watcher->isError() || !watcher->isValid()) { if (watcher->isError() || !watcher->isValid()) {
//TODO: in what form should we output the warning messages //TODO: in what form should we output the warning messages
qWarning() << QStringLiteral("activation of connection '%1' on interface '%2' failed: %3").arg(conn_name) qWarning() << "activate connection failed: " << watcher->error().message();
.arg(dev_name).arg(watcher->error().message()); } else {
qWarning()<<"success"<<watcher->reply().errorName() <<"error msg"<<watcher->reply().errorMessage();
qWarning()<<"error type"<<watcher->error().type();
} }
watcher->deleteLater(); watcher->deleteLater();
}); });

View File

@ -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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef KYLINNETWORKCONNECT_H #ifndef KYLINNETWORKCONNECT_H
#define KYLINNETWORKCONNECT_H #define KYLINNETWORKCONNECT_H
#include "kylinnetworkresourcemanager.h" #include "kylinnetworkresourcemanager.h"
#include "kylinconnectinfo.h"
typedef enum{
WIRED_CONNECT,
WIFI_CONNECT,
}KyConnectType;
class KyNetworkConnect : public QObject class KyNetworkConnect : public QObject
{ {
@ -11,6 +35,9 @@ public:
~KyNetworkConnect(); ~KyNetworkConnect();
public: public:
void createConnect(KyConnectType connectType, const KyConnectInfo &connectInfo);
void updateConnect(const QString &connectUuid, const KyConnectInfo &connectInfo);
void deleteConnect(const QString &connectUuid);
int addAndActivateConnect(const QString ); int addAndActivateConnect(const QString );
int activateConnection(const QString connectUuid); int activateConnection(const QString connectUuid);
void activateWirelessConnection(NetworkManager::WirelessNetwork::Ptr wirelessNet); void activateWirelessConnection(NetworkManager::WirelessNetwork::Ptr wirelessNet);
@ -19,9 +46,20 @@ public:
void requestScan(const QString ifaceName); void requestScan(const QString ifaceName);
void requestAllWifiScan(); void requestAllWifiScan();
private:
void connectSettingInit(
NetworkManager::ConnectionSettings::Ptr connectionSettings,
const KyConnectInfo &connectInfo);
void ipv4SettingInit(NetworkManager::Ipv4Setting::Ptr &ipv4Setting,
const KyConnectInfo &connectInfo);
void ipv6SettingInit(NetworkManager::Ipv6Setting::Ptr &ipv6Setting,
const KyConnectInfo &connectInfo);
void createWiredConnect(const KyConnectInfo &connectInfo);
signals: signals:
void activateConnectionFinished(NetworkManager::Connection::Ptr conn); void activateConnectionFinished(NetworkManager::Connection::Ptr &conn);
void deactivateConnectionFinished(NetworkManager::Connection::Ptr conn); void deactivateConnectionFinished(NetworkManager::Connection::Ptr &conn);
void noConnection(); void noConnection();
void notSavedConnection(); void notSavedConnection();

View File

@ -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 <http://www.gnu.org/licenses/&gt;.
*
*/
#include "kylinnetworkresourcemanager.h" #include "kylinnetworkresourcemanager.h"
KyNetworkResourceManager* KyNetworkResourceManager::m_pInstance = nullptr; KyNetworkResourceManager* KyNetworkResourceManager::m_pInstance = nullptr;
@ -72,6 +90,7 @@ void KyNetworkResourceManager::addActiveConnection(NetworkManager::ActiveConnect
connect(conn.data(), &NetworkManager::ActiveConnection::typeChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated); connect(conn.data(), &NetworkManager::ActiveConnection::typeChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
connect(conn.data(), &NetworkManager::ActiveConnection::masterChanged, 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::specificObjectChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
connect(conn.data(), &NetworkManager::ActiveConnection::stateChangedReason, this, &KyNetworkResourceManager::onActiveConnectionChangedReason);
connect(conn.data(), &NetworkManager::ActiveConnection::stateChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated); connect(conn.data(), &NetworkManager::ActiveConnection::stateChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
connect(conn.data(), &NetworkManager::ActiveConnection::vpnChanged, 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::uuidChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
@ -133,7 +152,7 @@ void KyNetworkResourceManager::addDevice(NetworkManager::Device::Ptr device)
{ {
m_devices.push_back(device); m_devices.push_back(device);
//device signals //device signals
connect(device.data(), &NetworkManager::Device::stateChanged, this, &KyNetworkResourceManager::onDeviceUpdated); //connect(device.data(), &NetworkManager::Device::stateChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
connect(device.data(), &NetworkManager::Device::activeConnectionChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::activeConnectionChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
connect(device.data(), &NetworkManager::Device::autoconnectChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::autoconnectChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
connect(device.data(), &NetworkManager::Device::availableConnectionChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::availableConnectionChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
@ -158,6 +177,7 @@ void KyNetworkResourceManager::addDevice(NetworkManager::Device::Ptr device)
connect(device.data(), &NetworkManager::Device::meteredChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::meteredChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
connect(device.data(), &NetworkManager::Device::connectionStateChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::connectionStateChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
connect(device.data(), &NetworkManager::Device::stateReasonChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::stateReasonChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
connect(device.data(), &NetworkManager::Device::stateChanged, this, &KyNetworkResourceManager::onDeviceStateChanged);
connect(device.data(), &NetworkManager::Device::udiChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::udiChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
switch (device->type()) switch (device->type())
{ {
@ -348,11 +368,34 @@ void KyNetworkResourceManager::onActiveConnectionUpdated()
emit activeConnectionUpdate(qobject_cast<NetworkManager::ActiveConnection *>(sender())); emit activeConnectionUpdate(qobject_cast<NetworkManager::ActiveConnection *>(sender()));
} }
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;
return;
}
void KyNetworkResourceManager::onDeviceUpdated() void KyNetworkResourceManager::onDeviceUpdated()
{ {
emit deviceUpdate(qobject_cast<NetworkManager::Device *>(sender())); emit deviceUpdate(qobject_cast<NetworkManager::Device *>(sender()));
} }
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;
}
void KyNetworkResourceManager::onWifiNetworkAppeared(QString const & ssid) void KyNetworkResourceManager::onWifiNetworkAppeared(QString const & ssid)
{ {
NetworkManager::Device * dev = qobject_cast<NetworkManager::Device *>(sender()); NetworkManager::Device * dev = qobject_cast<NetworkManager::Device *>(sender());

View File

@ -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 <http://www.gnu.org/licenses/&gt;.
*
*/
#ifndef KYLINNETWORKRESOURCEMANAGER_H #ifndef KYLINNETWORKRESOURCEMANAGER_H
#define KYLINNETWORKRESOURCEMANAGER_H #define KYLINNETWORKRESOURCEMANAGER_H
@ -97,9 +115,14 @@ private slots:
//active connection //active connection
void onActiveConnectionUpdated(); void onActiveConnectionUpdated();
void onActiveConnectionChangedReason(NetworkManager::ActiveConnection::State state,
NetworkManager::ActiveConnection::Reason reason);
//device //device
void onDeviceUpdated(); void onDeviceUpdated();
void onDeviceStateChanged(NetworkManager::Device::State newstate,
NetworkManager::Device::State oldstate,
NetworkManager::Device::StateChangeReason reason);
void onWifiNetworkAppeared(QString const & ssid); void onWifiNetworkAppeared(QString const & ssid);
void onWifiNetworkDisappeared(QString const & ssid); void onWifiNetworkDisappeared(QString const & ssid);