From f1dbe5bda31a559a5df53e3e27e3166c76a0f08d Mon Sep 17 00:00:00 2001 From: huanchuang <260832833@qq.com> Date: Tue, 27 Apr 2021 15:01:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=87=A0=E5=A4=84Qlist?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=B8=8D=E8=A7=84=E8=8C=83=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=AE=B5=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kylin-dbus-interface.cpp | 114 ++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 41 deletions(-) diff --git a/src/kylin-dbus-interface.cpp b/src/kylin-dbus-interface.cpp index 994f1b30..d402e96d 100644 --- a/src/kylin-dbus-interface.cpp +++ b/src/kylin-dbus-interface.cpp @@ -558,29 +558,37 @@ void KylinDBus::getConnectNetIp(QString netUuid) QDBusConnection::systemBus() ); QDBusMessage replyIp4 = interfaceIp4.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Ip4Config"); QList outArgsIp4 = replyIp4.arguments(); - QVariant firstIp4 = outArgsIp4.at(0); - QDBusVariant dbvFirstIp4 = firstIp4.value(); - QVariant vFirstIp4 = dbvFirstIp4.variant(); - QDBusObjectPath dbusPathIp4 = vFirstIp4.value(); + if(false == outArgsIp4.isEmpty()) + { + QVariant firstIp4 = outArgsIp4.at(0); + QDBusVariant dbvFirstIp4 = firstIp4.value(); + QVariant vFirstIp4 = dbvFirstIp4.variant(); + QDBusObjectPath dbusPathIp4 = vFirstIp4.value(); - QDBusInterface interfaceIpv4( "org.freedesktop.NetworkManager", - dbusPathIp4.path(), - "org.freedesktop.DBus.Properties", - QDBusConnection::systemBus() ); - QDBusMessage replyIpv4 = interfaceIpv4.call("Get", "org.freedesktop.NetworkManager.IP4Config", "AddressData"); + QDBusInterface interfaceIpv4( "org.freedesktop.NetworkManager", + dbusPathIp4.path(), + "org.freedesktop.DBus.Properties", + QDBusConnection::systemBus() ); + QDBusMessage replyIpv4 = interfaceIpv4.call("Get", "org.freedesktop.NetworkManager.IP4Config", "AddressData"); - QList outArgsIpv4 = replyIpv4.arguments(); - QVariant firstIpv4 = outArgsIpv4.at(0); - QDBusVariant dbvFirstIpv4 = firstIpv4.value(); - QVariant vFirstIpv4 = dbvFirstIpv4.variant(); + QList outArgsIpv4 = replyIpv4.arguments(); + if(false == outArgsIpv4.isEmpty()) + { + QVariant firstIpv4 = outArgsIpv4.at(0); + QDBusVariant dbvFirstIpv4 = firstIpv4.value(); + QVariant vFirstIpv4 = dbvFirstIpv4.variant(); - const QDBusArgument &dbusArgIpv4 = vFirstIpv4.value(); - QList mDatasIpv4; - dbusArgIpv4 >> mDatasIpv4; - - foreach (QVariantMap mDataIpv4, mDatasIpv4) { - dbusActiveLanIpv4 = mDataIpv4.value("address").toString(); - break; + const QDBusArgument &dbusArgIpv4 = vFirstIpv4.value(); + QList mDatasIpv4; + dbusArgIpv4 >> mDatasIpv4; + if(false == mDatasIpv4.isEmpty()) + { + foreach (QVariantMap mDataIpv4, mDatasIpv4) { + dbusActiveLanIpv4 = mDataIpv4.value("address").toString(); + break; + } + } + } } //ipv6的路径信息和ip信息 @@ -590,6 +598,9 @@ void KylinDBus::getConnectNetIp(QString netUuid) QDBusConnection::systemBus() ); QDBusMessage replyIp6 = interfaceIp6.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Ip6Config"); QList outArgsIp6 = replyIp6.arguments(); + if(outArgsIp6.isEmpty()) + continue; + QVariant firstIp6 = outArgsIp6.at(0); QDBusVariant dbvFirstIp6 = firstIp6.value(); QVariant vFirstIp6 = dbvFirstIp6.variant(); @@ -602,6 +613,9 @@ void KylinDBus::getConnectNetIp(QString netUuid) QDBusMessage replyIpv6 = interfaceIpv6.call("Get", "org.freedesktop.NetworkManager.IP6Config", "AddressData"); QList outArgsIpv6 = replyIpv6.arguments(); + if(outArgsIpv6.isEmpty()) + continue; + QVariant firstIpv6 = outArgsIpv6.at(0); QDBusVariant dbvFirstIpv6 = firstIpv6.value(); QVariant vFirstIpv6 = dbvFirstIpv6.variant(); @@ -609,6 +623,8 @@ void KylinDBus::getConnectNetIp(QString netUuid) const QDBusArgument &dbusArgIpv6 = vFirstIpv6.value(); QList mDatasIpv6; dbusArgIpv6 >> mDatasIpv6; + if(mDatasIpv6.isEmpty()) + continue; foreach (QVariantMap mDataIpv6, mDatasIpv6) { dbusActiveLanIpv6 = mDataIpv6.value("address").toString(); @@ -625,28 +641,36 @@ void KylinDBus::getConnectNetIp(QString netUuid) QDBusConnection::systemBus() ); QDBusMessage replyIp4 = interfaceIp4.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Ip4Config"); QList outArgsIp4 = replyIp4.arguments(); - QVariant firstIp4 = outArgsIp4.at(0); - QDBusVariant dbvFirstIp4 = firstIp4.value(); - QVariant vFirstIp4 = dbvFirstIp4.variant(); - QDBusObjectPath dbusPathIp4 = vFirstIp4.value(); + if(false == outArgsIp4.isEmpty()) + { + QVariant firstIp4 = outArgsIp4.at(0); + QDBusVariant dbvFirstIp4 = firstIp4.value(); + QVariant vFirstIp4 = dbvFirstIp4.variant(); + QDBusObjectPath dbusPathIp4 = vFirstIp4.value(); - QDBusInterface interfaceIpv4( "org.freedesktop.NetworkManager", - dbusPathIp4.path(), - "org.freedesktop.DBus.Properties", - QDBusConnection::systemBus() ); - QDBusMessage replyIpv4 = interfaceIpv4.call("Get", "org.freedesktop.NetworkManager.IP4Config", "AddressData"); + QDBusInterface interfaceIpv4( "org.freedesktop.NetworkManager", + dbusPathIp4.path(), + "org.freedesktop.DBus.Properties", + QDBusConnection::systemBus() ); + QDBusMessage replyIpv4 = interfaceIpv4.call("Get", "org.freedesktop.NetworkManager.IP4Config", "AddressData"); - QList outArgsIpv4 = replyIpv4.arguments(); - QVariant firstIpv4 = outArgsIpv4.at(0); - QDBusVariant dbvFirstIpv4 = firstIpv4.value(); - QVariant vFirstIpv4 = dbvFirstIpv4.variant(); + QList outArgsIpv4 = replyIpv4.arguments(); + if(false == outArgsIpv4.isEmpty()) + { + QVariant firstIpv4 = outArgsIpv4.at(0); + QDBusVariant dbvFirstIpv4 = firstIpv4.value(); + QVariant vFirstIpv4 = dbvFirstIpv4.variant(); - const QDBusArgument &dbusArgIpv4 = vFirstIpv4.value(); - QList mDatasIpv4; - dbusArgIpv4 >> mDatasIpv4; - - foreach (QVariantMap mDataIpv4, mDatasIpv4) { - dbusActiveWifiIpv4 = mDataIpv4.value("address").toString(); + const QDBusArgument &dbusArgIpv4 = vFirstIpv4.value(); + QList mDatasIpv4; + dbusArgIpv4 >> mDatasIpv4; + if(false == mDatasIpv4.isEmpty()) + { + foreach (QVariantMap mDataIpv4, mDatasIpv4) { + dbusActiveWifiIpv4 = mDataIpv4.value("address").toString(); + } + } + } } //ipv6的路径信息和ip信息 @@ -656,6 +680,8 @@ void KylinDBus::getConnectNetIp(QString netUuid) QDBusConnection::systemBus() ); QDBusMessage replyIp6 = interfaceIp6.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Ip6Config"); QList outArgsIp6 = replyIp6.arguments(); + if(outArgsIp6.isEmpty()) + continue; QVariant firstIp6 = outArgsIp6.at(0); QDBusVariant dbvFirstIp6 = firstIp6.value(); QVariant vFirstIp6 = dbvFirstIp6.variant(); @@ -668,6 +694,8 @@ void KylinDBus::getConnectNetIp(QString netUuid) QDBusMessage replyIpv6 = interfaceIpv6.call("Get", "org.freedesktop.NetworkManager.IP6Config", "AddressData"); QList outArgsIpv6 = replyIpv6.arguments(); + if(outArgsIpv6.isEmpty()) + continue; QVariant firstIpv6 = outArgsIpv6.at(0); QDBusVariant dbvFirstIpv6 = firstIpv6.value(); QVariant vFirstIpv6 = dbvFirstIpv6.variant(); @@ -675,7 +703,8 @@ void KylinDBus::getConnectNetIp(QString netUuid) const QDBusArgument &dbusArgIpv6 = vFirstIpv6.value(); QList mDatasIpv6; dbusArgIpv6 >> mDatasIpv6; - + if(mDatasIpv6.isEmpty()) + continue; foreach (QVariantMap mDataIpv6, mDatasIpv6) { dbusActiveWifiIpv6 = mDataIpv6.value("address").toString(); } @@ -1422,6 +1451,8 @@ QList KylinDBus::getAtiveWifiBSsidUuid(QStringList wifilist) QDBusMessage resultConnection = interfaceInfo.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Connection"); QList outArgsConnection = resultConnection.arguments(); + if(outArgsConnection.isEmpty()) + continue; QVariant firstConnection = outArgsConnection.at(0); QDBusVariant dbvFirstConnection = firstConnection.value(); QVariant vFirstConnection = dbvFirstConnection.variant(); @@ -1432,7 +1463,8 @@ QList KylinDBus::getAtiveWifiBSsidUuid(QStringList wifilist) "org.freedesktop.NetworkManager.Settings.Connection", QDBusConnection::systemBus()); QDBusMessage resultSet = interfaceSet.call("GetSettings"); - + if(resultSet.arguments().isEmpty()) + continue; const QDBusArgument &dbusArg1stSet = resultSet.arguments().at( 0 ).value(); QMap> mapSet; dbusArg1stSet >> mapSet;