diff --git a/src/backend/dbus-interface/dbus-interface.pri b/src/backend/dbus-interface/dbus-interface.pri index 70b5b0a8..056901df 100644 --- a/src/backend/dbus-interface/dbus-interface.pri +++ b/src/backend/dbus-interface/dbus-interface.pri @@ -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 \ diff --git a/src/backend/dbus-interface/kylinconnectresource.cpp b/src/backend/dbus-interface/kylinconnectresource.cpp index de7b5243..729bebb2 100644 --- a/src/backend/dbus-interface/kylinconnectresource.cpp +++ b/src/backend/dbus-interface/kylinconnectresource.cpp @@ -1,6 +1,7 @@ #include "kylinconnectresource.h" #include "kywirelessconnectoperation.h" +#include "kylinutil.h" #include #include @@ -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"<settings()->connectionType()) { - return true; - } + QString connectPath = connectPtr->path(); + QString connectionType = getConnectTypeByDbus(connectPath); + if (ETHERNET_TYPE == connectionType) { + return true; } return false; diff --git a/src/backend/dbus-interface/kylinutil.cpp b/src/backend/dbus-interface/kylinutil.cpp new file mode 100644 index 00000000..d90dd510 --- /dev/null +++ b/src/backend/dbus-interface/kylinutil.cpp @@ -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(); + QMap> map; + dbusArg1st >> map; + + if (map.isEmpty()) { + qWarning() << LOG_FLAG <<"get connection settings failed."; + return connectType; + } + + QMap 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; + +} diff --git a/src/backend/dbus-interface/kylinutil.h b/src/backend/dbus-interface/kylinutil.h new file mode 100644 index 00000000..027292bd --- /dev/null +++ b/src/backend/dbus-interface/kylinutil.h @@ -0,0 +1,19 @@ +#ifndef KYLINUTIL_H +#define KYLINUTIL_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#define KEY_CONNECTION "connection" +#define KEY_CONNECT_TYPE "type" +#define ETHERNET_TYPE "802-3-ethernet" + +QString getConnectTypeByDbus(QString &connectPath); + +#endif // KYLINUTIL_H