Remove the wired connection using same wired card when connect wired network
This commit is contained in:
parent
acb46b754d
commit
c356a14ef9
|
@ -198,9 +198,15 @@ void BackThread::execDisWifi()
|
||||||
//to connect wired network
|
//to connect wired network
|
||||||
void BackThread::execConnLan(QString connName, QString ifname)
|
void BackThread::execConnLan(QString connName, QString ifname)
|
||||||
{
|
{
|
||||||
//disConnLanOrWifi("ethernet");
|
|
||||||
|
|
||||||
KylinDBus objKyDbus;
|
KylinDBus objKyDbus;
|
||||||
|
|
||||||
|
//先断开当前网卡对应的已连接有线网
|
||||||
|
QString uuid = objKyDbus.getConnLanNameByIfname(ifname);
|
||||||
|
if (!uuid.isEmpty()) {
|
||||||
|
qDebug() << "断开网络:" <<uuid;
|
||||||
|
kylin_network_set_con_down(uuid.toUtf8().data());
|
||||||
|
}
|
||||||
|
|
||||||
bool wiredCableState = objKyDbus.getWiredCableStateByIfname(ifname);
|
bool wiredCableState = objKyDbus.getWiredCableStateByIfname(ifname);
|
||||||
if (wiredCableState) {
|
if (wiredCableState) {
|
||||||
// only if wired cable is plug in, can connect wired network
|
// only if wired cable is plug in, can connect wired network
|
||||||
|
|
|
@ -686,6 +686,66 @@ bool KylinDBus::getWiredCableStateByIfname(QString ifname)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//根据网卡接口的名称获取接口对应网线是否接入
|
||||||
|
QString KylinDBus::getConnLanNameByIfname(QString ifname)
|
||||||
|
{
|
||||||
|
QString uuidName = "--";
|
||||||
|
QDBusInterface interface( "org.freedesktop.NetworkManager",
|
||||||
|
"/org/freedesktop/NetworkManager",
|
||||||
|
"org.freedesktop.DBus.Properties",
|
||||||
|
QDBusConnection::systemBus() );
|
||||||
|
|
||||||
|
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 interfaceDevice( "org.freedesktop.NetworkManager",
|
||||||
|
objPath.path(),
|
||||||
|
"org.freedesktop.DBus.Properties",
|
||||||
|
QDBusConnection::systemBus() );
|
||||||
|
|
||||||
|
QDBusMessage replyDevices = interfaceDevice.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Devices");
|
||||||
|
QList<QVariant> outArgsDevices = replyDevices.arguments();
|
||||||
|
QVariant firstDevices = outArgsDevices.at(0);
|
||||||
|
QDBusVariant dbvFirstDevices = firstDevices.value<QDBusVariant>();
|
||||||
|
QVariant vFirstDevices = dbvFirstDevices.variant();
|
||||||
|
QDBusArgument dbusArgsDevices = vFirstDevices.value<QDBusArgument>();
|
||||||
|
|
||||||
|
QDBusObjectPath objPathDevices;
|
||||||
|
dbusArgsDevices.beginArray();
|
||||||
|
while (!dbusArgsDevices.atEnd()) {
|
||||||
|
dbusArgsDevices >> objPathDevices;
|
||||||
|
QDBusInterface interfaceInterface( "org.freedesktop.NetworkManager",
|
||||||
|
objPathDevices.path(),
|
||||||
|
"org.freedesktop.DBus.Properties",
|
||||||
|
QDBusConnection::systemBus() );
|
||||||
|
|
||||||
|
QDBusReply<QVariant> 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<QVariant> 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)
|
void KylinDBus::onNewConnection(QDBusObjectPath objPath)
|
||||||
{
|
{
|
||||||
|
|
|
@ -95,6 +95,7 @@ public slots:
|
||||||
void onConnectionRemoved(QDBusObjectPath objPath);
|
void onConnectionRemoved(QDBusObjectPath objPath);
|
||||||
void toCreateNewLan();
|
void toCreateNewLan();
|
||||||
bool getWiredCableStateByIfname(QString ifname);
|
bool getWiredCableStateByIfname(QString ifname);
|
||||||
|
QString getConnLanNameByIfname(QString ifname);
|
||||||
void onPropertiesChanged(QVariantMap qvm);
|
void onPropertiesChanged(QVariantMap qvm);
|
||||||
void onLanPropertyChanged(QVariantMap qvm);
|
void onLanPropertyChanged(QVariantMap qvm);
|
||||||
void onIpPropertiesChanged();
|
void onIpPropertiesChanged();
|
||||||
|
|
|
@ -2054,7 +2054,6 @@ void MainWindow::oneTopLanFormSelected(QString lanName, QString uniqueName)
|
||||||
// 顶部所有元素回到原位
|
// 顶部所有元素回到原位
|
||||||
for (int i = topLanList.size() - 1;i >= 0; i --) {
|
for (int i = topLanList.size() - 1;i >= 0; i --) {
|
||||||
OneLancForm *ocf = topLanList.at(i);
|
OneLancForm *ocf = topLanList.at(i);
|
||||||
qDebug() << "网络的名称是"<< ocf->ssidName;
|
|
||||||
ocf->move(L_VERTICAL_LINE_TO_ITEM, (topLanList.size() - 1 - i) * H_NORMAL_ITEM);
|
ocf->move(L_VERTICAL_LINE_TO_ITEM, (topLanList.size() - 1 - i) * H_NORMAL_ITEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue