diff --git a/src/backthread.cpp b/src/backthread.cpp index a4d35e3c..8f877e14 100644 --- a/src/backthread.cpp +++ b/src/backthread.cpp @@ -198,9 +198,15 @@ void BackThread::execDisWifi() //to connect wired network void BackThread::execConnLan(QString connName, QString ifname) { - //disConnLanOrWifi("ethernet"); - KylinDBus objKyDbus; + + //先断开当前网卡对应的已连接有线网 + QString uuid = objKyDbus.getConnLanNameByIfname(ifname); + if (!uuid.isEmpty()) { + qDebug() << "断开网络:" < 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 interfaceDevice( "org.freedesktop.NetworkManager", + objPath.path(), + "org.freedesktop.DBus.Properties", + QDBusConnection::systemBus() ); + + QDBusMessage replyDevices = interfaceDevice.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Devices"); + QList outArgsDevices = replyDevices.arguments(); + QVariant firstDevices = outArgsDevices.at(0); + QDBusVariant dbvFirstDevices = firstDevices.value(); + QVariant vFirstDevices = dbvFirstDevices.variant(); + QDBusArgument dbusArgsDevices = vFirstDevices.value(); + + QDBusObjectPath objPathDevices; + dbusArgsDevices.beginArray(); + while (!dbusArgsDevices.atEnd()) { + dbusArgsDevices >> objPathDevices; + QDBusInterface interfaceInterface( "org.freedesktop.NetworkManager", + objPathDevices.path(), + "org.freedesktop.DBus.Properties", + QDBusConnection::systemBus() ); + + QDBusReply replyInterface = interfaceInterface.call("Get", "org.freedesktop.NetworkManager.Device", "Interface"); + if (replyInterface.value().toString() == ifname) { + QDBusInterface interfaceUuid( "org.freedesktop.NetworkManager", + objPath.path(), + "org.freedesktop.DBus.Properties", + QDBusConnection::systemBus() ); + + QDBusReply replyDevices = interfaceUuid.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Uuid"); + uuidName = replyDevices.value().toString(); + } + } + dbusArgsDevices.endArray(); + } + dbusArgs.endArray(); + + return uuidName; +} + //新增了一个网络,伴随着多了一个网络配置文件 void KylinDBus::onNewConnection(QDBusObjectPath objPath) { diff --git a/src/kylin-dbus-interface.h b/src/kylin-dbus-interface.h index 2153cbc3..e0ea87ed 100644 --- a/src/kylin-dbus-interface.h +++ b/src/kylin-dbus-interface.h @@ -95,6 +95,7 @@ public slots: void onConnectionRemoved(QDBusObjectPath objPath); void toCreateNewLan(); bool getWiredCableStateByIfname(QString ifname); + QString getConnLanNameByIfname(QString ifname); void onPropertiesChanged(QVariantMap qvm); void onLanPropertyChanged(QVariantMap qvm); void onIpPropertiesChanged(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a6b71634..0f1bec61 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2054,7 +2054,6 @@ void MainWindow::oneTopLanFormSelected(QString lanName, QString uniqueName) // 顶部所有元素回到原位 for (int i = topLanList.size() - 1;i >= 0; i --) { OneLancForm *ocf = topLanList.at(i); - qDebug() << "网络的名称是"<< ocf->ssidName; ocf->move(L_VERTICAL_LINE_TO_ITEM, (topLanList.size() - 1 - i) * H_NORMAL_ITEM); }