Merge branch 'kylin-nm-start' into 'dbus-interface'

解决有线网络总开关的问题

See merge request kylin-desktop/kylin-nm!466
This commit is contained in:
赵 世旭 2021-12-13 02:36:46 +00:00
commit 1e6c7f3790
8 changed files with 106 additions and 35 deletions

View File

@ -87,7 +87,13 @@ void KyConnectOperation::connectSettingSet(
void KyConnectOperation::setAutoConnect(NetworkManager::ConnectionSettings::Ptr &connectSetting, void KyConnectOperation::setAutoConnect(NetworkManager::ConnectionSettings::Ptr &connectSetting,
bool bAutoConnect) bool bAutoConnect)
{ {
if (connectSetting.isNull()) {
return;
}
connectSetting->setAutoconnect(bAutoConnect); connectSetting->setAutoconnect(bAutoConnect);
return;
} }
void KyConnectOperation::createConnect(KyConnectSetting &connectSettingsInfo) void KyConnectOperation::createConnect(KyConnectSetting &connectSettingsInfo)

View File

@ -24,8 +24,10 @@ KyNetworkDeviceResourse::KyNetworkDeviceResourse(QObject *parent) : QObject(pare
this, &KyNetworkDeviceResourse::carrierChanage); this, &KyNetworkDeviceResourse::carrierChanage);
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceBitRateChanage, connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceBitRateChanage,
this, &KyNetworkDeviceResourse::deviceBitRateChanage); this, &KyNetworkDeviceResourse::deviceBitRateChanage);
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceMacAddressChanaged, connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceMacAddressChanage,
this, &KyNetworkDeviceResourse::deviceMacAddressChanaged); this, &KyNetworkDeviceResourse::deviceMacAddressChanage);
connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceActiveChanage,
this, &KyNetworkDeviceResourse::deviceActiveChanage);
} }
@ -269,11 +271,8 @@ void KyNetworkDeviceResourse::onDeviceRemove(QString deviceName, QString uni)
return; return;
} }
void KyNetworkDeviceResourse::onDeviceUpdate(NetworkManager::Device * dev) void KyNetworkDeviceResourse::onDeviceUpdate(QString interface, QString dbusPath)
{ {
QString dbusPath = dev->uni();
QString interface = dev->interfaceName();
if (m_deviceMap.contains(dbusPath)) { if (m_deviceMap.contains(dbusPath)) {
if (m_deviceMap[dbusPath] != interface) { if (m_deviceMap[dbusPath] != interface) {
QString oldName = m_deviceMap[dbusPath]; QString oldName = m_deviceMap[dbusPath];

View File

@ -23,12 +23,13 @@ signals:
void carrierChanage(QString deviceName, bool pluged); void carrierChanage(QString deviceName, bool pluged);
void deviceBitRateChanage(QString deviceName, int bitRate); void deviceBitRateChanage(QString deviceName, int bitRate);
void deviceMacAddressChanaged(QString deviceName, const QString &hwAddress); void deviceMacAddressChanage(QString deviceName, const QString &hwAddress);
void deviceActiveChanage(QString deviceName, bool deivceActive);
public slots: public slots:
void onDeviceAdd(QString deviceName, QString uni, NetworkManager::Device::Type deviceType); void onDeviceAdd(QString deviceName, QString uni, NetworkManager::Device::Type deviceType);
void onDeviceRemove(QString deviceName, QString uni); void onDeviceRemove(QString deviceName, QString uni);
void onDeviceUpdate(NetworkManager::Device * dev); void onDeviceUpdate(QString interface, QString dbusPath);
public: public:
void getNetworkDeviceList(NetworkManager::Device::Type deviceType, QStringList &networkDeviceList); void getNetworkDeviceList(NetworkManager::Device::Type deviceType, QStringList &networkDeviceList);

View File

@ -213,9 +213,8 @@ void KyNetworkResourceManager::addDevice(NetworkManager::Device::Ptr device)
connect(device.data(), &NetworkManager::Device::firmwareMissingChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::firmwareMissingChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
connect(device.data(), &NetworkManager::Device::firmwareVersionChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::firmwareVersionChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
#endif #endif
connect(device.data(), &NetworkManager::Device::activeConnectionChanged, this, &KyNetworkResourceManager::onDeviceActiveChanage);
connect(device.data(), &NetworkManager::Device::interfaceNameChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::interfaceNameChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
#if 0 #if 0
connect(device.data(), &NetworkManager::Device::ipV4AddressChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::ipV4AddressChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
connect(device.data(), &NetworkManager::Device::ipV4ConfigChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::ipV4ConfigChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
@ -237,7 +236,7 @@ void KyNetworkResourceManager::addDevice(NetworkManager::Device::Ptr device)
case NetworkManager::Device::Ethernet: case NetworkManager::Device::Ethernet:
connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::bitRateChanged, this, &KyNetworkResourceManager::onDeviceBitRateChanage); connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::bitRateChanged, this, &KyNetworkResourceManager::onDeviceBitRateChanage);
connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::carrierChanged, this, &KyNetworkResourceManager::onDeviceCarrierChanage); connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::carrierChanged, this, &KyNetworkResourceManager::onDeviceCarrierChanage);
connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::hardwareAddressChanged, this, &KyNetworkResourceManager::onDeviceMacAddressChanaged); connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::hardwareAddressChanged, this, &KyNetworkResourceManager::onDeviceMacAddressChanage);
// connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::permanentHardwareAddressChanged, this, &KyNetworkResourceManager::onDeviceUpdated); // connect(qobject_cast<NetworkManager::WiredDevice *>(device.data()), &NetworkManager::WiredDevice::permanentHardwareAddressChanged, this, &KyNetworkResourceManager::onDeviceUpdated);
break; break;
@ -606,9 +605,38 @@ void KyNetworkResourceManager::onVpnActiveConnectChanagedReason(NetworkManager::
return; return;
} }
void KyNetworkResourceManager::onDeviceActiveChanage()
{
NetworkManager::Device *p_device = qobject_cast<NetworkManager::Device *>(sender());
if (nullptr == p_device) {
return;
}
QString deviceName = p_device->interfaceName();
//此处需要取反因为激活连接的网卡状态是false断开连接的网卡状态是true
bool isActive = !p_device->isActive();
qDebug()<< LOG_FLAG << "device active change, device name " << deviceName
<< "active state" << isActive;
emit deviceActiveChanage(deviceName, isActive);
return;
}
void KyNetworkResourceManager::onDeviceUpdated() void KyNetworkResourceManager::onDeviceUpdated()
{ {
emit deviceUpdate(qobject_cast<NetworkManager::Device *>(sender())); NetworkManager::Device *p_device = qobject_cast<NetworkManager::Device *>(sender());
if (nullptr == p_device) {
return;
}
QString deviceName = p_device->interfaceName();
QString deviceUni = p_device->uni();
emit deviceUpdate(deviceName, deviceUni);
return;
} }
void KyNetworkResourceManager::onDeviceCarrierChanage(bool pluged) void KyNetworkResourceManager::onDeviceCarrierChanage(bool pluged)
@ -641,13 +669,13 @@ void KyNetworkResourceManager::onDeviceBitRateChanage(int bitRate)
return; return;
} }
void KyNetworkResourceManager::onDeviceMacAddressChanaged(const QString &hwAddress) void KyNetworkResourceManager::onDeviceMacAddressChanage(const QString &hwAddress)
{ {
NetworkManager::WiredDevice * networkDevice NetworkManager::WiredDevice * networkDevice
= qobject_cast<NetworkManager::WiredDevice *>(sender()); = qobject_cast<NetworkManager::WiredDevice *>(sender());
if (nullptr !=networkDevice && networkDevice->isValid()) { if (nullptr !=networkDevice && networkDevice->isValid()) {
emit deviceMacAddressChanaged(networkDevice->interfaceName(), hwAddress); emit deviceMacAddressChanage(networkDevice->interfaceName(), hwAddress);
} else { } else {
qWarning()<< LOG_FLAG <<"the device is not invalid with mac" << hwAddress; qWarning()<< LOG_FLAG <<"the device is not invalid with mac" << hwAddress;
} }
@ -751,10 +779,14 @@ void KyNetworkResourceManager::onWifiNetworkRemove(NetworkManager::Device * dev,
void KyNetworkResourceManager::onWifiNetworkAppeared(QString const & ssid) void KyNetworkResourceManager::onWifiNetworkAppeared(QString const & ssid)
{ {
NetworkManager::Device * dev = qobject_cast<NetworkManager::Device *>(sender()); NetworkManager::Device * p_device = qobject_cast<NetworkManager::Device *>(sender());
if (nullptr != dev) { if (nullptr != p_device) {
onWifiNetworkAdd(dev, ssid); onWifiNetworkAdd(p_device, ssid);
emit deviceUpdate(dev);
QString deviceName = p_device->interfaceName();
QString deviceUni = p_device->uni();
emit deviceUpdate(deviceName, deviceUni);
} else { } else {
qWarning()<< LOG_FLAG << "onWifiNetworkAppeared failed."; qWarning()<< LOG_FLAG << "onWifiNetworkAppeared failed.";
} }
@ -764,10 +796,14 @@ void KyNetworkResourceManager::onWifiNetworkAppeared(QString const & ssid)
void KyNetworkResourceManager::onWifiNetworkDisappeared(QString const & ssid) void KyNetworkResourceManager::onWifiNetworkDisappeared(QString const & ssid)
{ {
NetworkManager::Device * dev = qobject_cast<NetworkManager::Device *>(sender()); NetworkManager::Device *p_device = qobject_cast<NetworkManager::Device *>(sender());
if (nullptr != dev) { if (nullptr != p_device) {
onWifiNetworkRemove(dev, ssid); onWifiNetworkRemove(p_device, ssid);
emit deviceUpdate(dev);
QString deviceName = p_device->interfaceName();
QString deviceUni = p_device->uni();
emit deviceUpdate(deviceName, deviceUni);
} else { } else {
qWarning()<< LOG_FLAG << "onWifiNetworkDisappeared failed."; qWarning()<< LOG_FLAG << "onWifiNetworkDisappeared failed.";
} }

View File

@ -111,12 +111,13 @@ signals:
void connectionRemove(QString path); void connectionRemove(QString path);
void deviceAdd(QString deviceName, QString uni, NetworkManager::Device::Type deviceType); void deviceAdd(QString deviceName, QString uni, NetworkManager::Device::Type deviceType);
void deviceUpdate(NetworkManager::Device * dev); void deviceUpdate(QString deviceName, QString deviceUni);
void deviceRemove(QString deviceName, QString uni); void deviceRemove(QString deviceName, QString uni);
void deviceActiveChanage(QString deviceName, bool deviceActive);
void deviceCarrierChanage(QString deviceName, bool pluged); void deviceCarrierChanage(QString deviceName, bool pluged);
void deviceBitRateChanage(QString deviceName, int bitRate); void deviceBitRateChanage(QString deviceName, int bitRate);
void deviceMacAddressChanaged(QString deviceName, const QString &hwAddress); void deviceMacAddressChanage(QString deviceName, const QString &hwAddress);
//to KyWirelessNetResource //to KyWirelessNetResource
void wifiNetworkRemoved(QString, QString); void wifiNetworkRemoved(QString, QString);
@ -157,10 +158,13 @@ private slots:
NetworkManager::VpnConnection::StateChangeReason reason); NetworkManager::VpnConnection::StateChangeReason reason);
//device //device
void onDeviceActiveChanage();
void onDeviceUpdated(); void onDeviceUpdated();
void onDeviceCarrierChanage(bool pluged); void onDeviceCarrierChanage(bool pluged);
void onDeviceBitRateChanage(int bitRate); void onDeviceBitRateChanage(int bitRate);
void onDeviceMacAddressChanaged(const QString &hwAddress); void onDeviceMacAddressChanage(const QString &hwAddress);
void onDeviceStateChanged(NetworkManager::Device::State newstate, void onDeviceStateChanged(NetworkManager::Device::State newstate,
NetworkManager::Device::State oldstate, NetworkManager::Device::State oldstate,
NetworkManager::Device::StateChangeReason reason); NetworkManager::Device::StateChangeReason reason);

View File

@ -220,6 +220,7 @@ int KyWiredConnectOperation::closeWiredNetworkWithDevice(QString deviceName)
} }
} }
//wiredDevicePtr->setAutoconnect(false);
wiredDevicePtr->disconnectInterface(); wiredDevicePtr->disconnectInterface();
return 0; return 0;
@ -241,12 +242,17 @@ int KyWiredConnectOperation::openWiredNetworkWithDevice(QString deviceName)
return -EINVAL; return -EINVAL;
} }
QString connectUuid; NetworkManager::WiredDevice *p_wiredDevice =
getActiveConnection(deviceName, connectUuid); qobject_cast<NetworkManager::WiredDevice *>(wiredDevicePtr.data());
if (!connectUuid.isEmpty()) {
qDebug()<<"[KyWiredConnectOperation]" << "open wired network active connection" if (p_wiredDevice->carrier()) {
<< connectUuid <<"device name" << deviceName; QString connectUuid;
activateConnection(connectUuid, deviceName); getActiveConnection(deviceName, connectUuid);
if (!connectUuid.isEmpty()) {
qDebug()<<"[KyWiredConnectOperation]" << "open wired network active connection"
<< connectUuid <<"device name" << deviceName;
activateConnection(connectUuid, deviceName);
}
} }
wiredDevicePtr->setAutoconnect(true); wiredDevicePtr->setAutoconnect(true);

View File

@ -47,6 +47,7 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent)
connect(m_deviceResource, &KyNetworkDeviceResourse::deviceNameUpdate, this, &LanPage::onDeviceNameUpdate); connect(m_deviceResource, &KyNetworkDeviceResourse::deviceNameUpdate, this, &LanPage::onDeviceNameUpdate);
connect(m_deviceResource, &KyNetworkDeviceResourse::carrierChanage, this, &LanPage::onDeviceCarriered); connect(m_deviceResource, &KyNetworkDeviceResourse::carrierChanage, this, &LanPage::onDeviceCarriered);
connect(m_deviceResource, &KyNetworkDeviceResourse::deviceActiveChanage, this, &LanPage::onDeviceActiveChanage);
connect(m_wiredConnectOperation, &KyWiredConnectOperation::activateConnectionError, this, &LanPage::activateFailed); connect(m_wiredConnectOperation, &KyWiredConnectOperation::activateConnectionError, this, &LanPage::activateFailed);
connect(m_wiredConnectOperation, &KyWiredConnectOperation::deactivateConnectionError, this, &LanPage::deactivateFailed); connect(m_wiredConnectOperation, &KyWiredConnectOperation::deactivateConnectionError, this, &LanPage::deactivateFailed);
@ -182,10 +183,10 @@ void LanPage::onLanSwitchClicked()
this->showDesktopNotify(tr("No ethernet device avaliable")); this->showDesktopNotify(tr("No ethernet device avaliable"));
} else { } else {
if (m_netSwitch->getSwitchStatus()) { if (m_netSwitch->getSwitchStatus()) {
qDebug() << "[wiredSwitch]set true after clicked"; //qDebug() << "[wiredSwitch]set true after clicked";
m_switchGsettings->set(WIRED_SWITCH, true); m_switchGsettings->set(WIRED_SWITCH, true);
} else { } else {
qDebug() << "[wiredSwitch]set false after clicked"; //qDebug() << "[wiredSwitch]set false after clicked";
m_switchGsettings->set(WIRED_SWITCH,false); m_switchGsettings->set(WIRED_SWITCH,false);
} }
} }
@ -684,13 +685,30 @@ void LanPage::onDeviceCarriered(QString deviceName, bool pluged)
return; return;
} }
if (!m_wiredSwitch || !m_enableDeviceList.contains(deviceName)) { if (m_enableDeviceList.contains(deviceName)) {
m_wiredConnectOperation->closeWiredNetworkWithDevice(deviceName); m_wiredConnectOperation->openWiredNetworkWithDevice(deviceName);
} }
return; return;
} }
void LanPage::onDeviceActiveChanage(QString deviceName, bool deviceActive)
{
if (!m_devList.contains(deviceName)) {
return;
}
if (deviceActive) {
if (!m_wiredSwitch || !m_enableDeviceList.contains(deviceName)) {
qDebug()<< LOG_FLAG << "close disabled device";
m_wiredConnectOperation->closeWiredNetworkWithDevice(deviceName);
}
}
return;
}
void LanPage::onDeviceComboxIndexChanged(int currentIndex) void LanPage::onDeviceComboxIndexChanged(int currentIndex)
{ {
//TODO 设备变更时更新设备和列表 //TODO 设备变更时更新设备和列表

View File

@ -103,6 +103,7 @@ private slots:
void onDeviceNameUpdate(QString oldName, QString newName); void onDeviceNameUpdate(QString oldName, QString newName);
void onDeviceCarriered(QString deviceName, bool pluged); void onDeviceCarriered(QString deviceName, bool pluged);
void onDeviceActiveChanage(QString deviceName, bool deviceActive);
void onDeviceComboxIndexChanged(int currentIndex); void onDeviceComboxIndexChanged(int currentIndex);