diff --git a/src/kylin-dbus-interface.cpp b/src/kylin-dbus-interface.cpp index 2e069af7..a39e4c6a 100644 --- a/src/kylin-dbus-interface.cpp +++ b/src/kylin-dbus-interface.cpp @@ -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 outArgs = result.arguments(); + QVariant first = outArgs.at(0); + QDBusVariant dbvFirst = first.value(); + QVariant vFirst = dbvFirst.variant(); + QDBusArgument dbusArgs = vFirst.value(); + + QDBusObjectPath objPath; + dbusArgs.beginArray(); + while (!dbusArgs.atEnd()) { + dbusArgs >> objPath; + + QDBusInterface interfacePro( "org.freedesktop.NetworkManager", + objPath.path(), + "org.freedesktop.DBus.Properties", + QDBusConnection::systemBus() ); + + QDBusReply 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 outArgsIp4 = replyIp4.arguments(); + 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"); + + QList outArgsIpv4 = replyIpv4.arguments(); + 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(); + } + + //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 outArgsIp6 = replyIp6.arguments(); + QVariant firstIp6 = outArgsIp6.at(0); + QDBusVariant dbvFirstIp6 = firstIp6.value(); + QVariant vFirstIp6 = dbvFirstIp6.variant(); + QDBusObjectPath dbusPathIp6 = vFirstIp6.value(); + + QDBusInterface interfaceIpv6( "org.freedesktop.NetworkManager", + dbusPathIp6.path(), + "org.freedesktop.DBus.Properties", + QDBusConnection::systemBus() ); + QDBusMessage replyIpv6 = interfaceIpv6.call("Get", "org.freedesktop.NetworkManager.IP6Config", "AddressData"); + + QList outArgsIpv6 = replyIpv6.arguments(); + QVariant firstIpv6 = outArgsIpv6.at(0); + QDBusVariant dbvFirstIpv6 = firstIpv6.value(); + QVariant vFirstIpv6 = dbvFirstIpv6.variant(); + + const QDBusArgument &dbusArgIpv6 = vFirstIpv6.value(); + QList mDatasIpv6; + dbusArgIpv6 >> mDatasIpv6; + + foreach (QVariantMap mDataIpv6, mDatasIpv6) { + dbusActiveLanIpv6 = mDataIpv6.value("address").toString(); + } + } + } + dbusArgs.endArray(); +} + //获取wifi的mac地址 void KylinDBus::getWifiMac(QString netName) { diff --git a/src/kylin-dbus-interface.h b/src/kylin-dbus-interface.h index 990aef44..99df7e37 100644 --- a/src/kylin-dbus-interface.h +++ b/src/kylin-dbus-interface.h @@ -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 = ""; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7752eca3..2fcb56d8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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); diff --git a/src/onelancform.ui b/src/onelancform.ui index 984bd572..1d09d67d 100644 --- a/src/onelancform.ui +++ b/src/onelancform.ui @@ -115,7 +115,7 @@ 63 86 - 238 + 246 20