Merge branch 'dbus-interface' of http://gitlab2.kylin.com/kylin-desktop/kylin-nm into 1209

This commit is contained in:
kangshuning 2021-12-10 17:39:16 +08:00
commit 9691a5eca9
4 changed files with 72 additions and 11 deletions

View File

@ -14,6 +14,7 @@ HEADERS += \
$$PWD/kylinconnectsetting.h \
$$PWD/kylinnetworkdeviceresource.h \
$$PWD/kylinnetworkresourcemanager.h \
$$PWD/kylinutil.h \
$$PWD/kylinvpnconnectitem.h \
$$PWD/kylinvpnrequest.h \
$$PWD/kylinwiredconnectoperation.h \
@ -35,6 +36,7 @@ SOURCES += \
$$PWD/kylinconnectsetting.cpp \
$$PWD/kylinnetworkdeviceresource.cpp \
$$PWD/kylinnetworkresourcemanager.cpp \
$$PWD/kylinutil.cpp \
$$PWD/kylinvpnconnectitem.cpp \
$$PWD/kylinvpnrequest.c \
$$PWD/kylinwiredconnectoperation.cpp \

View File

@ -1,6 +1,7 @@
#include "kylinconnectresource.h"
#include "kywirelessconnectoperation.h"
#include "kylinutil.h"
#include <NetworkManagerQt/Ipv4Setting>
#include <NetworkManagerQt/Ipv6Setting>
@ -702,18 +703,16 @@ bool KyConnectResourse::isWiredConnection(QString uuid)
return false;
}
if (!connectPtr.isNull()) {
NetworkManager::ConnectionSettings::Ptr connectSettingPtr = connectPtr->settings();
/*
* NetworkManager库获取的连接类型线
* 线wifi-p2p的投屏
* networkmanager的dbus接口获取
*/
if (connectSettingPtr.isNull()) {
qWarning()<<"[KyConnectResourse]"<<"get connect setting failed, connect uuid"<<uuid;
return false;
}
if (NetworkManager::ConnectionSettings::ConnectionType::Wired ==
connectPtr->settings()->connectionType()) {
return true;
}
QString connectPath = connectPtr->path();
QString connectionType = getConnectTypeByDbus(connectPath);
if (ETHERNET_TYPE == connectionType) {
return true;
}
return false;

View File

@ -0,0 +1,41 @@
#include "kylinutil.h"
#define LOG_FLAG "kylin-util"
QString getConnectTypeByDbus(QString &connectPath)
{
QString connectType = "";
if (connectPath.isEmpty()) {
qWarning()<< LOG_FLAG << "connect path is empty, so can not get connect type";
return connectType;
}
QDBusInterface dbusInterface("org.freedesktop.NetworkManager",
connectPath,
"org.freedesktop.NetworkManager.Settings.Connection",
QDBusConnection::systemBus());
QDBusMessage result = dbusInterface.call("GetSettings");
const QDBusArgument &dbusArg1st = result.arguments().at( 0 ).value<QDBusArgument>();
QMap<QString, QMap<QString, QVariant>> map;
dbusArg1st >> map;
if (map.isEmpty()) {
qWarning() << LOG_FLAG <<"get connection settings failed.";
return connectType;
}
QMap<QString,QVariant> connectMap = map.value(KEY_CONNECTION);
if (connectMap.isEmpty()) {
qWarning() << LOG_FLAG <<"threre is not connection settings";
return connectType;
}
connectType = connectMap.value(KEY_CONNECT_TYPE).toString();
qDebug() << LOG_FLAG << "connection type" << connectType;
return connectType;
}

View File

@ -0,0 +1,19 @@
#ifndef KYLINUTIL_H
#define KYLINUTIL_H
#include <QObject>
#include <QDebug>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusObjectPath>
#include <QDBusReply>
#include <QDBusObjectPath>
#define KEY_CONNECTION "connection"
#define KEY_CONNECT_TYPE "type"
#define ETHERNET_TYPE "802-3-ethernet"
QString getConnectTypeByDbus(QString &connectPath);
#endif // KYLINUTIL_H