Fix bug connected items show abnormal if more than one wired network be connected

This commit is contained in:
chenlelin 2021-01-13 21:15:33 +08:00
parent 55db6aecab
commit 0460060a76
4 changed files with 63 additions and 58 deletions

View File

@ -213,7 +213,6 @@ void BackThread::execConnLan(QString connName, QString ifname)
//先断开当前网卡对应的已连接有线网
QString uuid = objKyDbus.getConnLanNameByIfname(ifname);
if (uuid != "--") {
//qDebug() << "断开网络:" <<uuid;
kylin_network_set_con_down(uuid.toUtf8().data());
}

View File

@ -427,7 +427,7 @@ QString KylinDBus::getLanMAC(QString ifname)
}
//获取已经连接的有线网ip
void KylinDBus::getConnectNetIp()
void KylinDBus::getConnectNetIp(QString netUuid)
{
QDBusInterface interface( "org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
@ -452,69 +452,73 @@ void KylinDBus::getConnectNetIp()
"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(),
QDBusReply<QVariant> replyType = interfacePro.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Type");
QDBusReply<QVariant> replyUuid = interfacePro.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Uuid");
if (replyType.value().toString() == "ethernet" || replyType.value().toString() == "802-3-ethernet") {
if (replyUuid.value().toString() == netUuid) {
//ipv4的路径信息和ip信息
QDBusInterface interfaceIp4( "org.freedesktop.NetworkManager",
objPath.path(),
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
QDBusMessage replyIpv4 = interfaceIpv4.call("Get", "org.freedesktop.NetworkManager.IP4Config", "AddressData");
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>();
QList<QVariant> outArgsIpv4 = replyIpv4.arguments();
QVariant firstIpv4 = outArgsIpv4.at(0);
QDBusVariant dbvFirstIpv4 = firstIpv4.value<QDBusVariant>();
QVariant vFirstIpv4 = dbvFirstIpv4.variant();
QDBusInterface interfaceIpv4( "org.freedesktop.NetworkManager",
dbusPathIp4.path(),
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
QDBusMessage replyIpv4 = interfaceIpv4.call("Get", "org.freedesktop.NetworkManager.IP4Config", "AddressData");
const QDBusArgument &dbusArgIpv4 = vFirstIpv4.value<QDBusArgument>();
QList<QVariantMap> mDatasIpv4;
dbusArgIpv4 >> mDatasIpv4;
QList<QVariant> outArgsIpv4 = replyIpv4.arguments();
QVariant firstIpv4 = outArgsIpv4.at(0);
QDBusVariant dbvFirstIpv4 = firstIpv4.value<QDBusVariant>();
QVariant vFirstIpv4 = dbvFirstIpv4.variant();
foreach (QVariantMap mDataIpv4, mDatasIpv4) {
dbusActiveLanIpv4 = mDataIpv4.value("address").toString();
}
const QDBusArgument &dbusArgIpv4 = vFirstIpv4.value<QDBusArgument>();
QList<QVariantMap> mDatasIpv4;
dbusArgIpv4 >> mDatasIpv4;
//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>();
foreach (QVariantMap mDataIpv4, mDatasIpv4) {
dbusActiveLanIpv4 = mDataIpv4.value("address").toString();
}
QDBusInterface interfaceIpv6( "org.freedesktop.NetworkManager",
dbusPathIp6.path(),
//ipv6的路径信息和ip信息
QDBusInterface interfaceIp6( "org.freedesktop.NetworkManager",
objPath.path(),
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
QDBusMessage replyIpv6 = interfaceIpv6.call("Get", "org.freedesktop.NetworkManager.IP6Config", "AddressData");
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>();
QList<QVariant> outArgsIpv6 = replyIpv6.arguments();
QVariant firstIpv6 = outArgsIpv6.at(0);
QDBusVariant dbvFirstIpv6 = firstIpv6.value<QDBusVariant>();
QVariant vFirstIpv6 = dbvFirstIpv6.variant();
QDBusInterface interfaceIpv6( "org.freedesktop.NetworkManager",
dbusPathIp6.path(),
"org.freedesktop.DBus.Properties",
QDBusConnection::systemBus() );
QDBusMessage replyIpv6 = interfaceIpv6.call("Get", "org.freedesktop.NetworkManager.IP6Config", "AddressData");
const QDBusArgument &dbusArgIpv6 = vFirstIpv6.value<QDBusArgument>();
QList<QVariantMap> mDatasIpv6;
dbusArgIpv6 >> mDatasIpv6;
QList<QVariant> outArgsIpv6 = replyIpv6.arguments();
QVariant firstIpv6 = outArgsIpv6.at(0);
QDBusVariant dbvFirstIpv6 = firstIpv6.value<QDBusVariant>();
QVariant vFirstIpv6 = dbvFirstIpv6.variant();
foreach (QVariantMap mDataIpv6, mDatasIpv6) {
dbusActiveLanIpv6 = mDataIpv6.value("address").toString();
const QDBusArgument &dbusArgIpv6 = vFirstIpv6.value<QDBusArgument>();
QList<QVariantMap> mDatasIpv6;
dbusArgIpv6 >> mDatasIpv6;
foreach (QVariantMap mDataIpv6, mDatasIpv6) {
dbusActiveLanIpv6 = mDataIpv6.value("address").toString();
}
}
}
}
dbusArgs.endArray();

View File

@ -52,7 +52,7 @@ public:
void initConnectionInfo();
QList<QString> getConnectNetName();
void connectWiredNet(QString netName);
void getConnectNetIp();
void getConnectNetIp(QString netUuid);
void getLanIpChanged();
void onWiredSettingNumChanged();

View File

@ -1446,7 +1446,7 @@ void MainWindow::getLanListDone(QStringList slist)
isActiveNet = true; //名为nname的网络是已经连接的有线网络
ifLanConnected = true;
objKyDBus->getConnectNetIp();
objKyDBus->getConnectNetIp(nuuid);
if (mwBandWidth == "Unknown!") { getLanBandWidth(); }
//QString strLanName = TranslateLanName(nname); //进行中英文系统环境下有线网络名称的汉化
@ -1483,10 +1483,10 @@ void MainWindow::getLanListDone(QStringList slist)
ccfAct->setLine(false); //最后一个item不显示下划线
}
\
if (!objKyDBus->dbusLanIpv4.isEmpty() && !objKyDBus->dbusActiveLanIpv4.isEmpty()) {
if (objKyDBus->dbusActiveLanIpv4 != objKyDBus->dbusLanIpv4) {
if (!objKyDBus->dbusLanIpv4.isEmpty()) {
if (!objKyDBus->dbusActiveLanIpv4.isEmpty() && objKyDBus->dbusActiveLanIpv4 != objKyDBus->dbusLanIpv4) {
//在第三方nm-connection-editor进行新的IP配置后重新连接网络
objKyDBus->connectWiredNet(nname);
//objKyDBus->connectWiredNet(nname);
} else if ((oldActLanName == actLanSsidName.at(kk)) && (oldDbusActLanDNS != objKyDBus->dbusActLanDNS)) {
//在第三方nm-connection-editor进行新的DNS配置后重新连接网络
objKyDBus->connectWiredNet(nname);
@ -2162,8 +2162,10 @@ void MainWindow::oneLanFormSelected(QString lanName, QString uniqueName)
scrollAreal->move(W_LEFT_AREA, Y_SCROLL_AREA + H_NORMAL_ITEM*(currTopLanItem-1));
lbNoItemTip->move(this->width()/2 - W_NO_ITEM_TIP/2 + W_LEFT_AREA/2, this->height()/2 + H_NORMAL_ITEM*(currTopLanItem-1)/2);
foreach (OneLancForm *ocf, topLanList) {
for (int i = topLanList.size() - 1;i >= 0; i --) {
OneLancForm *ocf = topLanList.at(i);
ocf->setTopItem(false);
ocf->move(L_VERTICAL_LINE_TO_ITEM, (topLanList.size() - 1 - i) * H_NORMAL_ITEM);
}
}
void MainWindow::oneTopLanFormSelected(QString lanName, QString uniqueName)