From f6bdf25c7faa0d47b6badca238207ceb17316770 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Fri, 17 Sep 2021 10:47:54 +0800 Subject: [PATCH 1/2] dns set --- .../dbus-interface/kylinconnectoperation.cpp | 21 ++++--------------- src/frontend/netdetails/ipv4page.cpp | 7 +++++++ src/frontend/netdetails/ipv6page.cpp | 6 ++++++ src/frontend/tab-pages/lanpage.cpp | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/backend/dbus-interface/kylinconnectoperation.cpp b/src/backend/dbus-interface/kylinconnectoperation.cpp index 3c3af528..4701df6b 100644 --- a/src/backend/dbus-interface/kylinconnectoperation.cpp +++ b/src/backend/dbus-interface/kylinconnectoperation.cpp @@ -39,6 +39,7 @@ void KyConnectOperation::ipv4SettingSet( const KyConnectSetting &connectSettingsInfo) { ipv4Setting->setInitialized(true); + ipv4Setting->setDns(connectSettingsInfo.m_ipv4Dns); if (CONFIG_IP_DHCP == connectSettingsInfo.m_ipv4ConfigIpType) { ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Automatic); @@ -46,14 +47,7 @@ void KyConnectOperation::ipv4SettingSet( } else { ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Manual); } - - if (!connectSettingsInfo.m_ipv4Dns.empty()) { - ipv4Setting->setDns(connectSettingsInfo.m_ipv4Dns); - } - - if (!connectSettingsInfo.m_ipv4Address.empty()) { - ipv4Setting->setAddresses(connectSettingsInfo.m_ipv4Address); - } + ipv4Setting->setAddresses(connectSettingsInfo.m_ipv4Address); return; } @@ -62,6 +56,7 @@ void KyConnectOperation::ipv6SettingSet( const KyConnectSetting &connectSettingsInfo) { ipv6Setting->setInitialized(true); + ipv6Setting->setDns(connectSettingsInfo.m_ipv6Dns); if (CONFIG_IP_DHCP == connectSettingsInfo.m_ipv6ConfigIpType) { ipv6Setting->setMethod(NetworkManager::Ipv6Setting::Automatic); @@ -70,15 +65,7 @@ void KyConnectOperation::ipv6SettingSet( } ipv6Setting->setMethod(NetworkManager::Ipv6Setting::Manual); - if (!connectSettingsInfo.m_ipv6Dns.empty()) { - ipv6Setting->setDns(connectSettingsInfo.m_ipv6Dns); - } - - if (!connectSettingsInfo.m_ipv6Address.empty()) { - ipv6Setting->setAddresses(connectSettingsInfo.m_ipv6Address); - } - - + ipv6Setting->setAddresses(connectSettingsInfo.m_ipv6Address); return ; } diff --git a/src/frontend/netdetails/ipv4page.cpp b/src/frontend/netdetails/ipv4page.cpp index 43af26a1..16dcc1a4 100644 --- a/src/frontend/netdetails/ipv4page.cpp +++ b/src/frontend/netdetails/ipv4page.cpp @@ -114,6 +114,13 @@ bool Ipv4Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting) if (info.ipv4ConfigType != CONFIG_IP_DHCP) { qDebug() << "ipv4ConfigType change to Auto"; setting.setIpConfigType(IPADDRESS_V4, CONFIG_IP_DHCP); + QString ipv4address(""); + QString netMask(""); + QString gateWay(""); + QStringList dnsList; + dnsList.empty(); + qDebug() << ipv4address << netMask << gateWay; + setting.ipv4AddressConstruct(ipv4address, netMask, gateWay, dnsList); isChanged = true; } } else { diff --git a/src/frontend/netdetails/ipv6page.cpp b/src/frontend/netdetails/ipv6page.cpp index 4bef6e2f..05ed0593 100644 --- a/src/frontend/netdetails/ipv6page.cpp +++ b/src/frontend/netdetails/ipv6page.cpp @@ -43,6 +43,12 @@ bool Ipv6Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting) if (info.ipv6ConfigType != CONFIG_IP_DHCP) { qDebug() << "ipv6ConfigType change to Auto"; setting.setIpConfigType(IPADDRESS_V6, CONFIG_IP_DHCP); + QString ipv6address(""); + QString prefix(""); + QString gateWay(""); + QStringList dnsList; + dnsList.empty(); + setting.ipv6AddressConstruct(ipv6address, prefix, gateWay, dnsList); isChanged = true; } } else { diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 363d4b2e..f46b17a6 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -558,7 +558,7 @@ void LanPage::getWiredList(QMap > &map) m_connectResourse->getConnectionList(deviceName, NetworkManager::ConnectionSettings::Wired, deactivedList); //未激活列表的显示 if (!deactivedList.isEmpty()) { for (int i = 0; i < deactivedList.size(); i++) { - vector.append(QStringList()<m_connectName<m_connectUuid); + vector.append(QStringList()<m_connectName<m_connectUuid << deactivedList.at(i)->m_connectPath); } } map.insert(deviceName, vector); From 6ac510db84ff88c9404caca9ae595e0128007e44 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Fri, 17 Sep 2021 17:53:50 +0800 Subject: [PATCH 2/2] dbus interface --- .../dbus-interface/kylinconnectsetting.cpp | 1 + .../kylinnetworkdeviceresource.cpp | 3 ++ src/backend/dbusadaptor.cpp | 11 ++++- src/frontend/netdetails/creatnetpage.cpp | 4 +- src/frontend/netdetails/netdetail.cpp | 10 ++-- src/frontend/new-mainwindow.cpp | 2 + src/frontend/tab-pages/lanpage.cpp | 48 +++++++++---------- src/frontend/tab-pages/lanpage.h | 1 + 8 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/backend/dbus-interface/kylinconnectsetting.cpp b/src/backend/dbus-interface/kylinconnectsetting.cpp index a8c5ede5..79a009ed 100644 --- a/src/backend/dbus-interface/kylinconnectsetting.cpp +++ b/src/backend/dbus-interface/kylinconnectsetting.cpp @@ -109,6 +109,7 @@ void KyConnectSetting::dumpInfo() qDebug()<<"connect setting info:"; qDebug()<<"connect name"<< m_connectName; qDebug()<<"iface name" << m_ifaceName; + qDebug()<<"ipv4 method" <isValid()) { qWarning()<<"[KyNetworkDeviceResourse]"<<"get hardware info failed, the device" << ifaceName << "is not existed"; + hardAddress.clear(); + bandWith = 0; + return; } switch (connectDevice->type()) { diff --git a/src/backend/dbusadaptor.cpp b/src/backend/dbusadaptor.cpp index 52639148..66e306e5 100644 --- a/src/backend/dbusadaptor.cpp +++ b/src/backend/dbusadaptor.cpp @@ -63,7 +63,11 @@ void DbusAdaptor::setWiredSwitchEnable(bool enable) //todo mainwindow调用backend 对开关 打开/关闭 if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_KYLIN_NM)) { QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA_KYLIN_NM); - gsetting->set(KEY_WIRED_SWITCH, enable); + if (gsetting->get(KEY_WIRED_SWITCH).toBool() != enable) { + gsetting->set(KEY_WIRED_SWITCH, enable); + } + delete gsetting; + gsetting = nullptr; } else { qDebug()<<"isSchemaInstalled false"; } @@ -75,7 +79,9 @@ void DbusAdaptor::setWirelessSwitchEnable(bool enable) //todo mainwindow调用backend 对开关 打开/关闭 if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_KYLIN_NM)) { QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA_KYLIN_NM); - gsetting->set(KEY_WIRELESS_SWITCH, enable); + if (gsetting->get(KEY_WIRELESS_SWITCH).toBool() != enable) { + gsetting->set(KEY_WIRELESS_SWITCH, enable); + } delete gsetting; gsetting = nullptr; } else { @@ -151,6 +157,7 @@ void DbusAdaptor::activateConnect(int type, QString devName, QString ssid) void DbusAdaptor::deActivateConnect(int type, QString devName, QString ssid) { if (type == WIRED) { + qDebug() << "deactivateWired"; parent()->deactivateWired(devName,ssid); } else if (type == WIRELESS) { parent()->deactivateWireless(devName,ssid); diff --git a/src/frontend/netdetails/creatnetpage.cpp b/src/frontend/netdetails/creatnetpage.cpp index ff4bd30e..bffae482 100644 --- a/src/frontend/netdetails/creatnetpage.cpp +++ b/src/frontend/netdetails/creatnetpage.cpp @@ -43,8 +43,8 @@ void CreatNetPage::initUI() m_detailLayout->addRow(m_dnsLabel,firstDnsEdit); m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit); - ipv4ConfigCombox->addItem(tr("Auto(DHCP)")); //"自动(DHCP)" - ipv4ConfigCombox->addItem(tr("Manual")); //"手动" + ipv4ConfigCombox->addItem(tr("Auto(DHCP)"), AUTO_CONFIG); //"自动(DHCP)" + ipv4ConfigCombox->addItem(tr("Manual"), MANUAL_CONFIG); //"手动" // IP的正则格式限制 diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index 41ed6251..329116db 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -656,10 +656,12 @@ bool NetDetail::createWiredConnect() KyWirelessConnectSetting connetSetting; connetSetting.setIfaceName(m_deviceName); createNetPage->constructIpv4Info(connetSetting); - if (checkIpv4Conflict(connetSetting.m_ipv4Address.at(0).ip().toString())) { - qDebug() << "ipv4 conflict"; - //todo desktop notify - return false; + if (connetSetting.m_ipv4ConfigIpType != CONFIG_IP_DHCP) { + if (checkIpv4Conflict(connetSetting.m_ipv4Address.at(0).ip().toString())) { + qDebug() << "ipv4 conflict"; + //todo desktop notify + return false; + } } m_wiredConnOperation->createWiredConnect(connetSetting); return true; diff --git a/src/frontend/new-mainwindow.cpp b/src/frontend/new-mainwindow.cpp index f1d94536..ec646167 100644 --- a/src/frontend/new-mainwindow.cpp +++ b/src/frontend/new-mainwindow.cpp @@ -152,6 +152,8 @@ void MainWindow::initDbusConnnect() connect(m_wlanWidget, &WlanPage::activateFailed, this, &MainWindow::activateFailed); connect(m_wlanWidget, &WlanPage::deactivateFailed, this, &MainWindow::deactivateFailed); + connect(m_lanWidget, &LanPage::activateFailed, this, &MainWindow::activateFailed); + connect(m_lanWidget, &LanPage::deactivateFailed, this, &MainWindow::deactivateFailed); connect(m_lanWidget, &LanPage::lanAdd, this, &MainWindow::lanAdd); connect(m_lanWidget, &LanPage::lanRemove, this, &MainWindow::lanRemove); diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index f46b17a6..097b8d9f 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -20,9 +20,10 @@ const QString WIRED_SWITCH = "wiredswitch"; LanPage::LanPage(QWidget *parent) : TabPage(parent) { //释放问题 - m_activeResourse = new KyActiveConnectResourse; - m_connectResourse = new KyConnectResourse; - m_device = new KyNetworkDeviceResourse; + m_activeResourse = new KyActiveConnectResourse(this); + m_connectResourse = new KyConnectResourse(this); + m_device = new KyNetworkDeviceResourse(this); + m_wiredConnectOperation = new KyWiredConnectOperation(this); devList.empty(); m_nullLanItem = new LanListItem(); initUI(); @@ -42,6 +43,11 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent) connect(m_device, &KyNetworkDeviceResourse::deviceAdd, this, &LanPage::onDeviceAdd); connect(m_device, &KyNetworkDeviceResourse::deviceRemove, this, &LanPage::onDeviceRemove); connect(m_device, &KyNetworkDeviceResourse::deviceNameUpdate, this, &LanPage::onDeviceNameUpdate); + + connect(m_wiredConnectOperation, &KyWiredConnectOperation::activateConnectionError, this, &LanPage::activateFailed); + connect(m_wiredConnectOperation, &KyWiredConnectOperation::deactivateConnectionError, this, &LanPage::deactivateFailed); + + //为什么同一个类中要用信号槽 connect(this, &LanPage::deviceStatusChanged, this, &LanPage::onDeviceChanged); } @@ -262,15 +268,6 @@ void LanPage::initDeviceCombox() saveDeviceEnableState(iter.key(), true); } } - if (m_deviceComboBox->currentText().isEmpty()) { - if (m_switchGsettings->get(WIRED_SWITCH).toBool()) { - m_switchGsettings->set(WIRED_SWITCH,false); - } - } else { - if (!m_switchGsettings->get(WIRED_SWITCH).toBool()) { - m_switchGsettings->set(WIRED_SWITCH,true); - } - } qDebug() << "[LanPage]current:" << m_deviceComboBox->currentText(); } @@ -575,23 +572,26 @@ void LanPage::setWiredDeviceEnable(const QString& devName, bool enable) void LanPage::activateWired(const QString& devName, const QString& connUuid) { qDebug() << "activateWired" << devName << connUuid; - KyWiredConnectOperation a; - a.activateConnection(connUuid, devName); + m_wiredConnectOperation->activateConnection(connUuid, devName); } void LanPage::deactivateWired(const QString& devName, const QString& connUuid) { qDebug() << "deactivateWired" << devName << connUuid; - KyConnectItem *item = nullptr; - item = m_activeResourse->getActiveConnectionByUuid(connUuid, devName); - if (nullptr == item) { - //todo: 通知桌面 - qDebug() << "not ActiveConnection"; - return; - } - - KyWiredConnectOperation a; - a.deactivateWiredConnection(item->m_connectName, connUuid); +// KyConnectItem *item = nullptr; +// item = m_activeResourse->getActiveConnectionByUuid(connUuid, devName); +// if (nullptr == item) { +// qDebug() << "not ActiveConnection"; +// item = m_connectResourse->getConnectionItemByUuid(connUuid, devName); +// if (nullptr == item) { +// QString errorMessage = tr("it can not find the activate connect" + tr("uuid") + connUuid; +// qWarning()<deactivateWiredConnection(name, connUuid); } void LanPage::showDetailPage(QString devName, QString uuid) diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index a370366c..af8c031b 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -52,6 +52,7 @@ private: QListWidgetItem *m_listWidgetItem = nullptr; KyNetworkDeviceResourse *m_device = nullptr; + KyWiredConnectOperation *m_wiredConnectOperation = nullptr; KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接 KyConnectResourse *m_connectResourse = nullptr; //未激活的连接