Fix bug can not show ipv4 and ipv6 of connected network which configuration is DHCP

This commit is contained in:
chenlelin 2020-07-24 15:09:15 +08:00
parent d2dd5ea94a
commit 175326fb23
4 changed files with 104 additions and 4 deletions

View File

@ -216,7 +216,7 @@ void KylinDBus::getWirelessCardName()
}
}
//获取有线网ip
//获取没有连接的有线网ip
void KylinDBus::getLanIp(QString netName)
{
QDBusInterface m_interface("org.freedesktop.NetworkManager",
@ -296,6 +296,100 @@ void KylinDBus::getLanIp(QString netName)
} //end foreach (QDBusObjectPath objNet, m_objNets)
}
//获取已经连接的有线网ip
void KylinDBus::getConnectNetIp()
{
QDBusInterface interface( "org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
//获取已经连接了那些网络,及这些网络对应的网络类型(ethernet or wifi)
QDBusMessage result = interface.call("Get", "org.freedesktop.NetworkManager", "ActiveConnections");
QList<QVariant> outArgs = result.arguments();
QVariant first = outArgs.at(0);
QDBusVariant dbvFirst = first.value<QDBusVariant>();
QVariant vFirst = dbvFirst.variant();
QDBusArgument dbusArgs = vFirst.value<QDBusArgument>();
QDBusObjectPath objPath;
dbusArgs.beginArray();
while (!dbusArgs.atEnd()) {
dbusArgs >> objPath;
QDBusInterface interfacePro( "org.freedesktop.NetworkManager",
objPath.path(),
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
QDBusReply<QVariant> reply = interfacePro.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Type");
if (reply.value().toString() == "ethernet" || reply.value().toString() == "802-3-ethernet") {
//ipv4的路径信息和ip信息
QDBusInterface interfaceIp4( "org.freedesktop.NetworkManager",
objPath.path(),
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
QDBusMessage replyIp4 = interfaceIp4.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Ip4Config");
QList<QVariant> outArgsIp4 = replyIp4.arguments();
QVariant firstIp4 = outArgsIp4.at(0);
QDBusVariant dbvFirstIp4 = firstIp4.value<QDBusVariant>();
QVariant vFirstIp4 = dbvFirstIp4.variant();
QDBusObjectPath dbusPathIp4 = vFirstIp4.value<QDBusObjectPath>();
QDBusInterface interfaceIpv4( "org.freedesktop.NetworkManager",
dbusPathIp4.path(),
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
QDBusMessage replyIpv4 = interfaceIpv4.call("Get", "org.freedesktop.NetworkManager.IP4Config", "AddressData");
QList<QVariant> outArgsIpv4 = replyIpv4.arguments();
QVariant firstIpv4 = outArgsIpv4.at(0);
QDBusVariant dbvFirstIpv4 = firstIpv4.value<QDBusVariant>();
QVariant vFirstIpv4 = dbvFirstIpv4.variant();
const QDBusArgument &dbusArgIpv4 = vFirstIpv4.value<QDBusArgument>();
QList<QVariantMap> mDatasIpv4;
dbusArgIpv4 >> mDatasIpv4;
foreach (QVariantMap mDataIpv4, mDatasIpv4) {
dbusActiveLanIpv4 = mDataIpv4.value("address").toString();
}
//ipv6的路径信息和ip信息
QDBusInterface interfaceIp6( "org.freedesktop.NetworkManager",
objPath.path(),
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
QDBusMessage replyIp6 = interfaceIp6.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Ip6Config");
QList<QVariant> outArgsIp6 = replyIp6.arguments();
QVariant firstIp6 = outArgsIp6.at(0);
QDBusVariant dbvFirstIp6 = firstIp6.value<QDBusVariant>();
QVariant vFirstIp6 = dbvFirstIp6.variant();
QDBusObjectPath dbusPathIp6 = vFirstIp6.value<QDBusObjectPath>();
QDBusInterface interfaceIpv6( "org.freedesktop.NetworkManager",
dbusPathIp6.path(),
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
QDBusMessage replyIpv6 = interfaceIpv6.call("Get", "org.freedesktop.NetworkManager.IP6Config", "AddressData");
QList<QVariant> outArgsIpv6 = replyIpv6.arguments();
QVariant firstIpv6 = outArgsIpv6.at(0);
QDBusVariant dbvFirstIpv6 = firstIpv6.value<QDBusVariant>();
QVariant vFirstIpv6 = dbvFirstIpv6.variant();
const QDBusArgument &dbusArgIpv6 = vFirstIpv6.value<QDBusArgument>();
QList<QVariantMap> mDatasIpv6;
dbusArgIpv6 >> mDatasIpv6;
foreach (QVariantMap mDataIpv6, mDatasIpv6) {
dbusActiveLanIpv6 = mDataIpv6.value("address").toString();
}
}
}
dbusArgs.endArray();
}
//获取wifi的mac地址
void KylinDBus::getWifiMac(QString netName)
{

View File

@ -47,6 +47,7 @@ public:
void showDesktopNotify(QString message);
void initConnectionInfo();
void connectWiredNet(QString netName);
void getConnectNetIp();
int getTaskBarPos(QString str);
int getTaskBarHeight(QString str);
@ -71,6 +72,8 @@ public:
QString dbusLanCardName = "";
QString dbusLanIpv4 = "";
QString dbusLanIpv6 = "";
QString dbusActiveLanIpv4 = "";
QString dbusActiveLanIpv6 = "";
QString dbusLanGateway = "";
QString dbusLanMac = "";
QString dbusWiFiCardName = "";

View File

@ -1382,8 +1382,8 @@ void MainWindow::getLanListDone(QStringList slist)
if (ltype != "802-11-wireless" && ltype != "wifi" && ltype != "" && ltype != "--") {
// 当前连接的lan
objKyDBus->getLanIp(nname);
if (nname == actLanName) {
objKyDBus->getConnectNetIp();
actLanName = "--";
if (mwBandWidth == "Unknown!") { getLanBandWidth(); }
@ -1391,7 +1391,7 @@ void MainWindow::getLanListDone(QStringList slist)
connect(ccf, SIGNAL(disconnActiveLan()), this, SLOT(activeLanDisconn()));
ccf->setName(nname, nname + order);
ccf->setIcon(true);
ccf->setLanInfo(objKyDBus->dbusLanIpv4, objKyDBus->dbusLanIpv6, mwBandWidth, objKyDBus->dbusLanMac);
ccf->setLanInfo(objKyDBus->dbusActiveLanIpv4, objKyDBus->dbusActiveLanIpv6, mwBandWidth, objKyDBus->dbusLanMac);
ccf->setConnedString(1, tr("NetOn,"));//"已连接"
ccf->isConnected = true;
ifLanConnected = true;
@ -1401,8 +1401,11 @@ void MainWindow::getLanListDone(QStringList slist)
lbLoadUpImg->show();
ccf->setTopItem(false);
currSelNetName = "";
objKyDBus->dbusActiveLanIpv4 = "";
objKyDBus->dbusActiveLanIpv6 = "";
syslog(LOG_DEBUG, "already insert an active lannet in the top of lan list");
} else {
objKyDBus->getLanIp(nname);
lanListWidget->resize(W_LIST_WIDGET, lanListWidget->height() + H_NORMAL_ITEM);
OneLancForm *ocf = new OneLancForm(lanListWidget, this, confForm, ksnm);

View File

@ -115,7 +115,7 @@
<rect>
<x>63</x>
<y>86</y>
<width>238</width>
<width>246</width>
<height>20</height>
</rect>
</property>