From 80ba5945fe6a32940dbfa1997153e0aae389ed28 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Mon, 13 Sep 2021 09:26:53 +0800 Subject: [PATCH 1/9] netdetail page --- .../kyenterpricesettinginfo.cpp | 28 +- .../dbus-interface/kyenterpricesettinginfo.h | 60 ++ .../dbus-interface/kylinconnectresource.cpp | 1 + .../dbus-interface/kylinconnectsetting.cpp | 8 +- .../dbus-interface/kylinconnectsetting.h | 2 + .../kywirelessconnectoperation.cpp | 95 ++- .../kywirelessconnectoperation.h | 13 +- .../dbus-interface/kywirelessnetresource.cpp | 14 +- .../dbus-interface/kywirelessnetresource.h | 2 + src/backend/dbusadaptor.cpp | 66 +- src/backend/dbusadaptor.h | 8 +- src/frontend/list-items/lanlistitem.cpp | 2 +- src/frontend/list-items/lanlistitem.h | 2 +- src/frontend/list-items/wlanlistitem.cpp | 10 +- src/frontend/netdetails.pri | 1 + src/frontend/netdetails/coninfo.h | 61 ++ src/frontend/netdetails/creatnetpage.cpp | 181 ++++- src/frontend/netdetails/creatnetpage.h | 47 +- src/frontend/netdetails/detailpage.cpp | 48 +- src/frontend/netdetails/detailpage.h | 19 +- src/frontend/netdetails/ipv4page.cpp | 207 +++-- src/frontend/netdetails/ipv4page.h | 38 +- src/frontend/netdetails/ipv6page.cpp | 141 +++- src/frontend/netdetails/ipv6page.h | 22 +- src/frontend/netdetails/netdetail.cpp | 729 ++++++++++++----- src/frontend/netdetails/netdetail.h | 85 +- src/frontend/netdetails/securitypage.cpp | 731 ++++++++++++++++++ src/frontend/netdetails/securitypage.h | 85 +- src/frontend/new-mainwindow.cpp | 42 + src/frontend/new-mainwindow.h | 8 + src/frontend/tab-pages/lanpage.cpp | 28 +- src/frontend/tab-pages/lanpage.h | 3 +- src/frontend/tab-pages/tabpage.cpp | 57 ++ src/frontend/tab-pages/tabpage.h | 2 + src/frontend/tab-pages/wlanpage.cpp | 29 + src/frontend/tab-pages/wlanpage.h | 1 + 36 files changed, 2388 insertions(+), 488 deletions(-) create mode 100644 src/frontend/netdetails/coninfo.h diff --git a/src/backend/dbus-interface/kyenterpricesettinginfo.cpp b/src/backend/dbus-interface/kyenterpricesettinginfo.cpp index cb741bc9..8bff2062 100644 --- a/src/backend/dbus-interface/kyenterpricesettinginfo.cpp +++ b/src/backend/dbus-interface/kyenterpricesettinginfo.cpp @@ -13,11 +13,16 @@ void assembleEapMethodTlsSettings(NetworkManager::ConnectionSettings::Ptr connSe if (!info.domain.isEmpty()){ wifi_8021x_sett->setDomainSuffixMatch(info.domain); } - QByteArray caCerEndWithNull(info.caCertPath.toUtf8() + '\0'); - wifi_8021x_sett->setCaCertificate(caCerEndWithNull); - QByteArray cliCertEndWithNull(info.clientCertPath.toUtf8() + '\0'); + if (info.bNeedCa) { + QByteArray caCerEndWithNull("file://" + info.caCertPath.toUtf8() + '\0'); + wifi_8021x_sett->setCaCertificate(caCerEndWithNull); + } else { + QByteArray caCerEndWithNull(""); + wifi_8021x_sett->setCaCertificate(caCerEndWithNull); + } + QByteArray cliCertEndWithNull("file://" + info.clientCertPath.toUtf8() + '\0'); wifi_8021x_sett->setClientCertificate(cliCertEndWithNull); - QByteArray cliPriKeyEndWithNull(info.clientPrivateKey.toUtf8() + '\0'); + QByteArray cliPriKeyEndWithNull("file://" + info.clientPrivateKey.toUtf8() + '\0'); wifi_8021x_sett->setPrivateKey(cliPriKeyEndWithNull); wifi_8021x_sett->setPrivateKeyPassword(info.clientPrivateKeyPWD); wifi_8021x_sett->setPrivateKeyPasswordFlags(info.m_privateKeyPWDFlag); @@ -98,13 +103,16 @@ void modifyEapMethodTlsSettings(NetworkManager::ConnectionSettings::Ptr connSett } if (tlsInfo.bNeedCa) { - QByteArray caCerEndWithNull(tlsInfo.caCertPath.toUtf8() + '\0'); + QByteArray caCerEndWithNull("file://" + tlsInfo.caCertPath.toUtf8() + '\0'); + setting->setCaCertificate(caCerEndWithNull); + } else { + QByteArray caCerEndWithNull(""); setting->setCaCertificate(caCerEndWithNull); } - QByteArray cliCertEndWithNull(tlsInfo.clientCertPath.toUtf8() + '\0'); + QByteArray cliCertEndWithNull("file://" + tlsInfo.clientCertPath.toUtf8() + '\0'); setting->setClientCertificate(cliCertEndWithNull); - QByteArray cliPriKeyEndWithNull(tlsInfo.clientPrivateKey.toUtf8() + '\0'); + QByteArray cliPriKeyEndWithNull("file://" + tlsInfo.clientPrivateKey.toUtf8() + '\0'); setting->setPrivateKey(cliPriKeyEndWithNull); setting->setPrivateKeyPasswordFlags(tlsInfo.m_privateKeyPWDFlag); if(tlsInfo.bChanged) @@ -133,6 +141,9 @@ void modifyEapMethodPeapSettings(NetworkManager::ConnectionSettings::Ptr connSet } wifi_8021x_sett->setPasswordFlags(peapInfo.m_passwdFlag); + QByteArray caCerEndWithNull(""); + wifi_8021x_sett->setCaCertificate(caCerEndWithNull); + return; } @@ -158,5 +169,8 @@ void modifyEapMethodTtlsSettings(NetworkManager::ConnectionSettings::Ptr connSet wifi_8021x_sett->setPassword(ttlsInfo.userPWD); } wifi_8021x_sett->setPasswordFlags(ttlsInfo.m_passwdFlag); + + QByteArray caCerEndWithNull(""); + wifi_8021x_sett->setCaCertificate(caCerEndWithNull); return; } diff --git a/src/backend/dbus-interface/kyenterpricesettinginfo.h b/src/backend/dbus-interface/kyenterpricesettinginfo.h index 093dcd06..c2427671 100644 --- a/src/backend/dbus-interface/kyenterpricesettinginfo.h +++ b/src/backend/dbus-interface/kyenterpricesettinginfo.h @@ -7,6 +7,12 @@ #include "kylinnetworkresourcemanager.h" #include +enum KyEapMethodType { + TLS = 0, + PEAP, + TTLS, +}; + class KyEapMethodTlsInfo { public: @@ -21,6 +27,23 @@ public: NetworkManager::Setting::SecretFlags m_privateKeyPWDFlag; // only valid when update bool bChanged; + + inline bool operator == (const KyEapMethodTlsInfo& info) const + { + if (this->identity == info.identity + && this->domain == info.domain +// && this->devIfaceName == info.devIfaceName + && this->caCertPath == info.caCertPath + && this->bNeedCa == info.bNeedCa + && this->clientCertPath == info.clientCertPath + && this->clientPrivateKey == info.clientPrivateKey + && this->clientPrivateKeyPWD == info.clientPrivateKeyPWD + /*&& this->m_privateKeyPWDFlag == info.m_privateKeyPWDFlag*/) { + return true; + } else { + return false; + } + } }; typedef enum { @@ -54,6 +77,18 @@ public: NetworkManager::Setting::SecretFlags m_passwdFlag; // only valid when update bool bChanged; + + inline bool operator == (const KyEapMethodPeapInfo& info) const + { + if (this->phase2AuthMethod == info.phase2AuthMethod + && this->userName == info.userName + && this->userPWD == info.userPWD + /*&& this->m_passwdFlag == info.m_passwdFlag*/) { + return true; + } else { + return false; + } + } }; enum KyTtlsAuthMethod @@ -73,6 +108,31 @@ public: NetworkManager::Setting::SecretFlags m_passwdFlag; // only valid when update bool bChanged; + + inline bool operator == (const KyEapMethodTtlsInfo& info) const + { + if (this->authType == info.authType) { + if (authType == AUTH_EAP) { + if (this->authEapMethod == info.authEapMethod + && this ->userName == info.userName + && this->userPWD == info.userPWD + /*&& this->m_passwdFlag == info.m_passwdFlag*/) { + return true; + } + } else { + if (authType == AUTH_EAP) { + if (this->authNoEapMethod == info.authNoEapMethod + && this ->userName == info.userName + && this->userPWD == info.userPWD + /*&& this->m_passwdFlag == info.m_passwdFlag*/) { + return true; + } + } + } + + } + return false; + } }; void assembleEapMethodTlsSettings(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyEapMethodTlsInfo &tlsInfo); diff --git a/src/backend/dbus-interface/kylinconnectresource.cpp b/src/backend/dbus-interface/kylinconnectresource.cpp index af84c696..10165584 100644 --- a/src/backend/dbus-interface/kylinconnectresource.cpp +++ b/src/backend/dbus-interface/kylinconnectresource.cpp @@ -295,6 +295,7 @@ void KyConnectResourse::getConnectionSetting(QString connectUuid, KyConnectSetti NetworkManager::ConnectionSettings::Ptr connectionSettings = connectPtr->settings(); connectSetting.m_ifaceName = connectionSettings->interfaceName(); + connectSetting.m_isAutoConnect = connectionSettings->autoconnect(); NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast(); getIpv4ConnectSetting(ipv4Setting, connectSetting); diff --git a/src/backend/dbus-interface/kylinconnectsetting.cpp b/src/backend/dbus-interface/kylinconnectsetting.cpp index 84d29ef8..a8c5ede5 100644 --- a/src/backend/dbus-interface/kylinconnectsetting.cpp +++ b/src/backend/dbus-interface/kylinconnectsetting.cpp @@ -30,6 +30,8 @@ KyConnectSetting::KyConnectSetting(/*QObject *parent) : QObject(parent*/) m_ipv6ConfigIpType = CONFIG_IP_DHCP; m_ipv6Address.clear(); m_ipv6Dns.clear(); + + m_isAutoConnect = true; } KyConnectSetting::~KyConnectSetting() @@ -74,8 +76,10 @@ void KyConnectSetting::ipv4AddressConstruct(QString &ipv4Address, QString &ipv4N nmIpv4Address.setIp(QHostAddress(ipv4Address)); nmIpv4Address.setGateway(QHostAddress(ipv4GateWay)); nmIpv4Address.setNetmask(QHostAddress(ipv4NetMask)); + m_ipv4Address.clear(); m_ipv4Address << nmIpv4Address; + m_ipv4Dns.clear(); for (int index = 0; index < ipv4Dns.size(); ++index) { qDebug()<<"dns"< m_ipv6Address; QList m_ipv6Dns; + + bool m_isAutoConnect; }; #endif // KYLINCONNECTSETTING_H diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.cpp b/src/backend/dbus-interface/kywirelessconnectoperation.cpp index cd973a60..e9dd5668 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.cpp +++ b/src/backend/dbus-interface/kywirelessconnectoperation.cpp @@ -43,6 +43,7 @@ NetworkManager::ConnectionSettings::Ptr assembleWirelessSettings(const KyWireles settings->setAutoconnect(connSettingInfo.isAutoConnect); //Note: workaround for wrongly (randomly) initialized gateway-ping-timeout settings->setGatewayPingTimeout(0); + settings->setInterfaceName(connSettingInfo.m_ifaceName); NetworkManager::WirelessSetting::Ptr wifi_sett = settings->setting(NetworkManager::Setting::Wireless).dynamicCast(); @@ -236,6 +237,7 @@ void KyWirelessConnectOperation::deleteWirelessConnect(const QString &connectUui QString KyWirelessConnectOperation::getPsk(const QString &connectUuid) { + qDebug() << "getPsk" << connectUuid; NetworkManager::Connection::Ptr connectPtr = NetworkManager::findConnectionByUuid(connectUuid); if (connectPtr.isNull()) { @@ -244,9 +246,6 @@ QString KyWirelessConnectOperation::getPsk(const QString &connectUuid) return ""; } QDBusPendingReply reply = connectPtr->secrets(PSK_SETTING_NAME); - if(!reply.isValid()) { - return ""; - } QMap map(reply.value()); if (map.contains("802-11-wireless-security") && map.value("802-11-wireless-security").contains("psk")) { @@ -256,6 +255,46 @@ QString KyWirelessConnectOperation::getPsk(const QString &connectUuid) return ""; } +QString KyWirelessConnectOperation::getPrivateKeyPassword(const QString &connectUuid) +{ + qDebug() << "getPsk" << connectUuid; + NetworkManager::Connection::Ptr connectPtr = + NetworkManager::findConnectionByUuid(connectUuid); + if (connectPtr.isNull()) { + QString errorMessage = tr("it can not find connection") + connectUuid; + qWarning()< reply = connectPtr->secrets(PSK_SETTING_NAME); + QMap map(reply.value()); + if (map.contains("802-1x") && map.value("802-1x").contains("private-key-password")) + { + QString psk = map.value("802-1x").value("private-key-password").toString(); + return psk; + } + return ""; +} + +QString KyWirelessConnectOperation::get8021xPassword(const QString &connectUuid) +{ + qDebug() << "getPsk" << connectUuid; + NetworkManager::Connection::Ptr connectPtr = + NetworkManager::findConnectionByUuid(connectUuid); + if (connectPtr.isNull()) { + QString errorMessage = tr("it can not find connection") + connectUuid; + qWarning()< reply = connectPtr->secrets(PSK_SETTING_NAME); + QMap map(reply.value()); + if (map.contains("802-1x") && map.value("802-1x").contains("password")) + { + QString psk = map.value("802-1x").value("password").toString(); + return psk; + } + return ""; +} + void KyWirelessConnectOperation::updateIpv4AndIpv6SettingInfo(const QString &uuid, const KyConnectSetting &connectSettingsInfo) { qDebug()<<"updateIpv4AndIpv6SettingInfo wireless connect uuid " << uuid; @@ -617,7 +656,9 @@ void KyWirelessConnectOperation::setWirelessEnabled(bool enabled) NetworkManager::setWirelessEnabled(enabled); if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA); - gsetting->set(WIRELESS_SWITCH, enabled); + if (gsetting->get(WIRELESS_SWITCH).toBool() != enabled) { + gsetting->set(WIRELESS_SWITCH, enabled); + } } else { qDebug()<<"isSchemaInstalled false"; } @@ -777,14 +818,17 @@ KyKeyMgmt KyWirelessConnectOperation::getConnectKeyMgmt(const QString &uuid) { NetworkManager::Connection::Ptr connectPtr = NetworkManager::findConnectionByUuid(uuid); + if (connectPtr.isNull()) { + return KyKeyMgmt::Unknown; + } NetworkManager::WirelessSecuritySetting::Ptr security_sett = connectPtr->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); -// if(security_sett.isNull()) -// { -// return KyKeyMgmt::Unknown; -// } + if(security_sett.isNull()) + { + return KyKeyMgmt::Unknown; + } return (KyKeyMgmt)security_sett->keyMgmt(); } @@ -804,7 +848,7 @@ void KyWirelessConnectOperation::updateWirelessSecu(NetworkManager::ConnectionSe } security_sett->setKeyMgmt((NetworkManager::WirelessSecuritySetting::KeyMgmt)type); if (bPwdChange) { - qDebug() << "get psk " << security_sett->psk(); + qDebug() << "set psk " << connSettingInfo.m_psk; security_sett->setPsk(connSettingInfo.m_psk); } return; @@ -877,3 +921,36 @@ void KyWirelessConnectOperation::activateApConnectionByUuid(const QString apUuid return ; } + +bool KyWirelessConnectOperation::getEnterpiseEapMethod(const QString &uuid, KyEapMethodType &type) +{ + NetworkManager::Connection::Ptr connectPtr = + NetworkManager::findConnectionByUuid(uuid); + if (connectPtr.isNull()) { + qDebug() << "getEnterpiseEapMethod faild.Can't find uuid = " << uuid; + return false; + } + + KyKeyMgmt keyMgmt = getConnectKeyMgmt(uuid); + if (keyMgmt != WpaEap) { + qDebug() << "getEnterpiseEapMethod but not WpaEap.it's " << keyMgmt; + return false; + } + + NetworkManager::ConnectionSettings::Ptr connectionSettings = connectPtr->settings(); + + NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett + = connectionSettings->setting(NetworkManager::Setting::Security8021x).dynamicCast(); + + QList list = wifi_8021x_sett->eapMethods(); + + if (list.contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodTls)) { + type = TLS; + } else if (list.contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodPeap)) { + type = PEAP; + } else if (list.contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodTtls)) { + type = TTLS; + } + + return true; +} diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.h b/src/backend/dbus-interface/kywirelessconnectoperation.h index df3c1f3a..6a5a761d 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.h +++ b/src/backend/dbus-interface/kywirelessconnectoperation.h @@ -15,7 +15,7 @@ enum KySecuType { NONE = 0, WPA_AND_WPA2_PERSONAL, WPA_AND_WPA2_ENTERPRISE, - WPA2_AND_WPA3_PERSONAL + WPA3_PERSONAL, }; enum KyKeyMgmt { @@ -27,12 +27,6 @@ enum KyKeyMgmt { SAE }; -enum KyEapMethodType { - TLS, - PEAP, - TTLS, -}; - class KyWirelessConnectSetting : public KyConnectSetting { // Q_OBJECT @@ -65,6 +59,9 @@ public: //获取KeyMgmt KyKeyMgmt getConnectKeyMgmt(const QString &uuid); + //获取企业网类型 + bool getEnterpiseEapMethod(const QString &uuid, KyEapMethodType &type); + //激活连接 void activeWirelessConnect(QString , QString); //断开连接 @@ -102,6 +99,8 @@ public: void deleteWirelessConnect(const QString &connectUuid); //获取密码 QString getPsk(const QString &connectUuid); + QString getPrivateKeyPassword(const QString &connectUuid); + QString get8021xPassword(const QString &connectUuid); //申请扫描 void requestWirelessScan(); diff --git a/src/backend/dbus-interface/kywirelessnetresource.cpp b/src/backend/dbus-interface/kywirelessnetresource.cpp index 783f34c8..7a3d3041 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.cpp +++ b/src/backend/dbus-interface/kywirelessnetresource.cpp @@ -19,6 +19,7 @@ KyWirelessNetResource::KyWirelessNetResource(QObject *parent) qDebug()<<"KyWirelessNetResource"; m_networkResourceInstance = KyNetworkResourceManager::getInstance(); m_connectResource = new KyConnectResourse(this); + m_operation = new KyWirelessConnectOperation(this); kyWirelessNetItemListInit(); @@ -74,16 +75,18 @@ bool KyWirelessNetResource::getWifiNetwork(const QString &devIfaceName, const QS // onWifiNetworkDeviceDisappear(); if (!m_WifiNetworkList.contains(devIfaceName)) { + qDebug() << "getWifiNetwork fail,not contain " << devIfaceName; return false; } else { for (int index = 0; index < m_WifiNetworkList[devIfaceName].size(); index ++){ if (m_WifiNetworkList[devIfaceName].at(index).m_NetSsid == ssid) { wirelessNetResource = m_WifiNetworkList[devIfaceName].at(index); + qDebug() << "getWifiNetwork success"; return true; } } } - + qDebug() << "getWifiNetwork fail,not contain " << ssid; return false; } @@ -346,13 +349,13 @@ bool KyWirelessNetResource::getEnterPriseInfoTls(QString &uuid, KyEapMethodTlsIn return false; } + info.identity = setting->identity(); info.domain = setting->domainSuffixMatch(); - info.caCertPath = setting->caPath(); info.clientCertPath = setting->clientCertificate(); info.clientPrivateKey = QString(setting->privateKey()); - info.clientPrivateKeyPWD = setting->privateKeyPassword(); + info.clientPrivateKeyPWD = m_operation->getPrivateKeyPassword(conn->uuid()); return true; } @@ -382,7 +385,7 @@ bool KyWirelessNetResource::getEnterPriseInfoPeap(QString &uuid, KyEapMethodPeap info.phase2AuthMethod = (KyNoEapMethodAuth)setting->phase2AuthMethod(); info.userName = setting->identity(); - info.userPWD = setting->password(); + info.userPWD = m_operation->get8021xPassword(conn->uuid()); return true; } @@ -422,7 +425,8 @@ bool KyWirelessNetResource::getEnterPriseInfoTtls(QString &uuid, KyEapMethodTtls info.authType = KyTtlsAuthMethod::AUTH_NO_EAP; } info.userName = setting->identity(); - info.userPWD = setting->password(); + info.userPWD = m_operation->get8021xPassword(conn->uuid()); + return true; } diff --git a/src/backend/dbus-interface/kywirelessnetresource.h b/src/backend/dbus-interface/kywirelessnetresource.h index 3249fe90..b5725f9a 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.h +++ b/src/backend/dbus-interface/kywirelessnetresource.h @@ -6,6 +6,7 @@ #include "kylinnetworkresourcemanager.h" #include "kyenterpricesettinginfo.h" #include "kylinconnectresource.h" +#include "kywirelessconnectoperation.h" //class KyWirelessNetItem; @@ -59,6 +60,7 @@ signals: private: KyNetworkResourceManager *m_networkResourceInstance = nullptr; KyConnectResourse *m_connectResource = nullptr; + KyWirelessConnectOperation *m_operation = nullptr; QMap > m_WifiNetworkList; }; diff --git a/src/backend/dbusadaptor.cpp b/src/backend/dbusadaptor.cpp index 8bb61cf6..52639148 100644 --- a/src/backend/dbusadaptor.cpp +++ b/src/backend/dbusadaptor.cpp @@ -21,63 +21,6 @@ const QByteArray GSETTINGS_SCHEMA_KYLIN_NM = "org.ukui.kylin-nm.switch"; const QString KEY_WIRELESS_SWITCH = "wirelessswitch"; const QString KEY_WIRED_SWITCH = "wiredswitch"; -void saveDeviceEnableState(QString deviceName, bool enable) -{ - QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); - m_settings->beginGroup("CARDEABLE"); - m_settings->setValue(deviceName, enable); - m_settings->endGroup(); - m_settings->sync(); - delete m_settings; - m_settings = nullptr; - return; -} - -void getDeviceEnableState(int type, QMap &map) -{ - map.clear(); - if (!QFile::exists(CONFIG_FILE_PATH)) { - return; - } - if (type != WIRED && type != WIRELESS) { - qDebug() << "getDeviceEnableState but wrong type"; - return; - } - - KyNetworkDeviceResourse * kdr = new KyNetworkDeviceResourse(); - QStringList wiredDevList,wirelessDevList; - wiredDevList.clear(); - wirelessDevList.clear(); - - QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); - m_settings->beginGroup("CARDEABLE"); - - if (type == WIRED) { - kdr->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, wiredDevList); - if (!wiredDevList.isEmpty()) { - for (int i = 0; i < wiredDevList.size(); ++i) { - bool enable = m_settings->value(wiredDevList.at(i), true).toBool(); - map.insert(wiredDevList.at(i), enable); - } - } - } else if (type == WIRELESS) { - kdr->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, wirelessDevList); - if (!wirelessDevList.isEmpty()) { - for (int i = 0; i < wirelessDevList.size(); ++i) { - bool enable = m_settings->value(wirelessDevList.at(i), true).toBool(); - map.insert(wirelessDevList.at(i), enable); - } - } - } - - m_settings->endGroup(); - delete m_settings; - m_settings = nullptr; - delete kdr; - kdr = nullptr; - return; -} - /* * Implementation of adaptor class DbusAdaptor */ @@ -143,6 +86,7 @@ void DbusAdaptor::setWirelessSwitchEnable(bool enable) //启用/禁用网卡 void DbusAdaptor::setDeviceEnable(QString devName, bool enable) { + parent()->setWiredDeviceEnable(devName, enable); saveDeviceEnableState(devName, enable); } @@ -227,15 +171,13 @@ QMap DbusAdaptor::getDeviceListAndEnabled(int devType) //唤起属性页 根据网卡类型 参数2 为ssid/uuid void DbusAdaptor::showPropertyWidget(QString devName, QString ssid) { - //todo - //parent()->showPropertyWidget(devName,ssid); + parent()->showPropertyWidget(devName,ssid); } //唤起新建有线连接界面 -void DbusAdaptor::showCreateWiredConnectWidget(QString devName, QString connectionName) +void DbusAdaptor::showCreateWiredConnectWidget(QString devName) { - //todo - //parent()->showCreateWiredConnectWidget(devName,connectionName); + parent()->showCreateWiredConnectWidget(devName); } //开启热点 diff --git a/src/backend/dbusadaptor.h b/src/backend/dbusadaptor.h index c369dc02..f15d6a26 100644 --- a/src/backend/dbusadaptor.h +++ b/src/backend/dbusadaptor.h @@ -51,11 +51,11 @@ public Q_SLOTS: // METHODS QMap > getWirelessList(); //有线列表 QMap> getWiredList(); - //有线开关 + //有线总开关 Q_NOREPLY void setWiredSwitchEnable(bool enable); - //无线开关 + //无线总开关 Q_NOREPLY void setWirelessSwitchEnable(bool enable); - //启用/禁用网卡 + //有线网卡开关 Q_NOREPLY void setDeviceEnable(QString devName, bool enable); //设置默认网卡 Q_NOREPLY void setDefaultWiredDevice(QString deviceName); @@ -71,7 +71,7 @@ public Q_SLOTS: // METHODS //唤起属性页 根据网卡类型 参数2 为ssid/uuid Q_NOREPLY void showPropertyWidget(QString devName, QString ssid); //唤起新建有线连接界面 - Q_NOREPLY void showCreateWiredConnectWidget(QString devName, QString connectionName); + Q_NOREPLY void showCreateWiredConnectWidget(QString devName); //开启热点 void activeWirelessAp(const QString apName, const QString apPassword, const QString apDevice); //断开热点 diff --git a/src/frontend/list-items/lanlistitem.cpp b/src/frontend/list-items/lanlistitem.cpp index 21dcd4d4..e9d04dde 100644 --- a/src/frontend/list-items/lanlistitem.cpp +++ b/src/frontend/list-items/lanlistitem.cpp @@ -54,7 +54,7 @@ void LanListItem::onInfoButtonClicked() if(m_data){ qDebug()<<"Net active or not:"<m_connectName, m_data->m_connectUuid, m_isActive,false, false); + NetDetail *netDetail = new NetDetail(deviceName, m_data->m_connectName, m_data->m_connectUuid, m_isActive,false, false, this); netDetail->show(); } else{ diff --git a/src/frontend/list-items/lanlistitem.h b/src/frontend/list-items/lanlistitem.h index 0c5c200e..92d52bdd 100644 --- a/src/frontend/list-items/lanlistitem.h +++ b/src/frontend/list-items/lanlistitem.h @@ -22,7 +22,7 @@ private: KyConnectItem *m_data = nullptr; KyWiredConnectOperation *m_connectOperation = nullptr; - QString deviceName = nullptr; + QString deviceName = ""; private slots: void onInfoButtonClicked(); diff --git a/src/frontend/list-items/wlanlistitem.cpp b/src/frontend/list-items/wlanlistitem.cpp index a3776760..ab465baf 100644 --- a/src/frontend/list-items/wlanlistitem.cpp +++ b/src/frontend/list-items/wlanlistitem.cpp @@ -197,7 +197,7 @@ void WlanListItem::onInfoButtonClicked() if(m_data){ qDebug()<<"Net active or not:"<m_NetSsid, m_data->m_connectUuid,m_isActive, true, false); + NetDetail *netDetail = new NetDetail(m_wlanDevice, m_data->m_NetSsid, m_data->m_connectUuid, m_isActive, true, !m_data->m_isConfigured, this); netDetail->show(); } else{ @@ -322,8 +322,8 @@ void WlanListItem::onConnectionAdd(QString deviceName, QString ssid) if (!m_data) { return; } - if (ssid == m_data->m_NetSsid) { - m_data->m_isConfigured = true; + if (ssid == m_data->m_NetSsid && deviceName == m_wlanDevice) { + m_resource->getWifiNetwork(deviceName, ssid, *m_data); } } @@ -332,8 +332,8 @@ void WlanListItem::onConnectionRemove(QString deviceName, QString ssid) if (!m_data) { return; } - if (ssid == m_data->m_NetSsid) { - m_data->m_isConfigured = false; + if (ssid == m_data->m_NetSsid && deviceName == m_wlanDevice) { + m_resource->getWifiNetwork(deviceName, ssid, *m_data); } } diff --git a/src/frontend/netdetails.pri b/src/frontend/netdetails.pri index a75c2147..10b5c1e7 100644 --- a/src/frontend/netdetails.pri +++ b/src/frontend/netdetails.pri @@ -1,4 +1,5 @@ HEADERS += \ + $$PWD/netdetails/coninfo.h \ $$PWD/netdetails/creatnetpage.h \ $$PWD/netdetails/customtabstyle.h \ $$PWD/netdetails/detailpage.h \ diff --git a/src/frontend/netdetails/coninfo.h b/src/frontend/netdetails/coninfo.h new file mode 100644 index 00000000..b2e144f5 --- /dev/null +++ b/src/frontend/netdetails/coninfo.h @@ -0,0 +1,61 @@ +#ifndef CONINFO_H +#define CONINFO_H + +#include +#include "kywirelessnetitem.h" +#include "kylinconnectresource.h" +#include "kylinactiveconnectresource.h" +#include "kywirelessconnectoperation.h" +#include "kywirelessnetresource.h" +#include "kyenterpricesettinginfo.h" + +#define AUTO_CONFIG 0 +#define MANUAL_CONFIG 1 + +enum TtlsInnerType +{ + PAP = 0, + MSCHAP, + MSCHAPV2_EAP, + MSCHAPV2, + CHAP, + MD5_EAP, + GTC_EAP +}; + +class ConInfo { +public: + QString strConName; + QString strConType; + QString strSecType; + KySecuType secType = WPA_AND_WPA2_PERSONAL; + QString strPassword; + QString strChan; + QString strMac; + QString strHz; + QString strBandWidth; + QString strDynamicIpv4; + QString strDynamicIpv6; + QString strDynamicIpv4Dns; + bool isAutoConnect = false; + + KyIpConfigType ipv4ConfigType = CONFIG_IP_DHCP; + QString strIPV4Address; + QString strIPV4NetMask; + QString strIPV4FirDns; + QString strIPV4SecDns; + QString strIPV4GateWay; + + KyIpConfigType ipv6ConfigType = CONFIG_IP_DHCP; + QString strIPV6Address; + QString strIPV6Prefix; + QString strIPV6FirDns; + QString strIPV6SecDns; + QString strIPV6GateWay; + + KyEapMethodType enterpriseType; + KyEapMethodTlsInfo tlsInfo; + KyEapMethodPeapInfo peapInfo; + KyEapMethodTtlsInfo ttlsInfo; +}; +#endif // CONINFO_H diff --git a/src/frontend/netdetails/creatnetpage.cpp b/src/frontend/netdetails/creatnetpage.cpp index 40461471..ea672c6a 100644 --- a/src/frontend/netdetails/creatnetpage.cpp +++ b/src/frontend/netdetails/creatnetpage.cpp @@ -1,6 +1,185 @@ #include "creatnetpage.h" -CreatNetPage::CreatNetPage(QWidget *parent) : QFrame(parent) + + +CreatNetPage::CreatNetPage(QWidget *parent):QFrame(parent) { + initUI(); + initComponent(); +} + +void CreatNetPage::initUI() +{ + connNameEdit = new QLineEdit(this); + ipv4ConfigCombox = new QComboBox(this); + ipv4addressEdit = new QLineEdit(this); + netMaskEdit = new QLineEdit(this); + gateWayEdit = new QLineEdit(this); + firstDnsEdit = new QLineEdit(this); + secondDnsEdit = new QLineEdit(this); + + m_connNameLabel = new QLabel(this); + m_configLabel = new QLabel(this); + m_addressLabel = new QLabel(this); + m_maskLabel = new QLabel(this); + m_gateWayLabel = new QLabel(this); + m_dnsLabel = new QLabel(this); + m_secDnsLabel = new QLabel(this); + + m_connNameLabel->setText(tr("Connection Name")); + m_configLabel->setText(tr("Ipv4Config")); + m_addressLabel->setText(tr("Address")); + m_maskLabel->setText(tr("Netmask")); + m_gateWayLabel->setText(tr("Default Gateway")); + m_dnsLabel->setText(tr("Prefs DNS")); + m_secDnsLabel->setText(tr("Alternative DNS")); + + m_detailLayout = new QFormLayout(this); + m_detailLayout->addRow(m_connNameLabel,connNameEdit); + m_detailLayout->addRow(m_configLabel,ipv4ConfigCombox); + m_detailLayout->addRow(m_addressLabel,ipv4addressEdit); + m_detailLayout->addRow(m_maskLabel,netMaskEdit); + m_detailLayout->addRow(m_gateWayLabel,gateWayEdit); + m_detailLayout->addRow(m_dnsLabel,firstDnsEdit); + m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit); + + ipv4ConfigCombox->addItem(tr("Auto(DHCP)")); //"自动(DHCP)" + ipv4ConfigCombox->addItem(tr("Manual")); //"手动" + + + // IP的正则格式限制 + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + + ipv4addressEdit->setValidator(new QRegExpValidator(rx, this)); + gateWayEdit->setValidator(new QRegExpValidator(rx, this)); + netMaskEdit->setValidator(new QRegExpValidator(rx, this)); + firstDnsEdit->setValidator(new QRegExpValidator(rx, this)); + secondDnsEdit->setValidator(new QRegExpValidator(rx, this)); +} + +void CreatNetPage::initComponent() { + if (ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { + setLineEnabled(false); + } else if (ipv4ConfigCombox->currentIndex() == MANUAL_CONFIG) { + setLineEnabled(true); + } + connect(ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(configChanged(int))); + + connect(connNameEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfSaveBtn())); + connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); +} + +bool CreatNetPage::checkConnectBtnIsEnabled() +{ + if (connNameEdit->text().isEmpty()) { + qDebug() << "create connName empty or invalid"; + return false; + } + qDebug() << "checkConnectBtnIsEnabled currentIndex" << ipv4ConfigCombox->currentIndex(); + if (ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { + return true; + } else { + if (ipv4addressEdit->text().isEmpty() || !getTextEditState(ipv4addressEdit->text())) { + qDebug() << "create ipv4address empty or invalid"; + return false; + } + + if (netMaskEdit->text().isEmpty() || !getTextEditState(netMaskEdit->text())) { + qDebug() << "create ipv4 netMask empty or invalid"; + return false; + } + + if (gateWayEdit->text().isEmpty() || !getTextEditState(gateWayEdit->text())) { + qDebug() << "create ipv4 gateway empty or invalid"; + return false; + } + + if (firstDnsEdit->text().isEmpty() && !secondDnsEdit->text().isEmpty()) { + qDebug() << "create ipv4 dns sort invalid"; + return false; + } + + if (!getTextEditState(firstDnsEdit->text())) { + qDebug() << "create ipv4 first dns invalid"; + return false; + } + + if (!getTextEditState(secondDnsEdit->text())) { + qDebug() << "create ipv4 second dns invalid"; + return false; + } + } + return true; +} + +void CreatNetPage::configChanged(int index) { + if (index == AUTO_CONFIG) { + setLineEnabled(false); + } + if (index == MANUAL_CONFIG) { + setLineEnabled(true); + } +} + +void CreatNetPage::setLineEnabled(bool check) { + + ipv4addressEdit->setEnabled(check); + netMaskEdit->setEnabled(check); + gateWayEdit->setEnabled(check); + firstDnsEdit->setEnabled(check); + secondDnsEdit->setEnabled(check); + + if (!check) { + ipv4addressEdit->clear(); + netMaskEdit->clear(); + gateWayEdit->clear(); + firstDnsEdit->clear(); + secondDnsEdit->clear(); + } +} + +void CreatNetPage::setEnableOfSaveBtn() { + emit setCreatePageState(checkConnectBtnIsEnabled()); +} + +bool CreatNetPage::getTextEditState(QString text) +{ + if (text.isEmpty()) { + return true; + } + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + + bool match = false; + match = rx.exactMatch(text); + + return match; +} + +void CreatNetPage::constructIpv4Info(KyConnectSetting &setting) +{ + setting.m_connectName = connNameEdit->text(); + QString ipv4address =ipv4addressEdit->text(); + QString netMask = netMaskEdit->text(); + QString gateWay = gateWayEdit->text(); + qDebug() << ipv4address << netMask << gateWay; + + QStringList dnsList; + dnsList.empty(); + if (!firstDnsEdit->text().isEmpty()) { + dnsList << firstDnsEdit->text(); + if (!secondDnsEdit->text().isEmpty()) { + dnsList << secondDnsEdit->text(); + } + } + if (ipv4ConfigCombox->currentData() == AUTO_CONFIG) { + setting.setIpConfigType(IPADDRESS_V4, CONFIG_IP_DHCP); + } else { + setting.setIpConfigType(IPADDRESS_V4, CONFIG_IP_MANUAL); + setting.ipv4AddressConstruct(ipv4address, netMask, gateWay, dnsList); + } } diff --git a/src/frontend/netdetails/creatnetpage.h b/src/frontend/netdetails/creatnetpage.h index 35d61528..d27cc7c1 100644 --- a/src/frontend/netdetails/creatnetpage.h +++ b/src/frontend/netdetails/creatnetpage.h @@ -2,13 +2,58 @@ #define CREATNETPAGE_H #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "coninfo.h" class CreatNetPage : public QFrame { Q_OBJECT public: CreatNetPage(QWidget *parent = nullptr); + + void constructIpv4Info(KyConnectSetting &setting); +private: + QLineEdit *connNameEdit; + QComboBox *ipv4ConfigCombox; + QLineEdit *ipv4addressEdit; + QLineEdit *netMaskEdit; + QLineEdit *gateWayEdit; + QLineEdit *firstDnsEdit; + QLineEdit *secondDnsEdit; + +private: + QFormLayout *m_detailLayout; + QVBoxLayout *mvBoxLayout; + QLabel *m_connNameLabel; + QLabel *m_configLabel; + QLabel *m_addressLabel; + QLabel *m_maskLabel; + QLabel *m_gateWayLabel; + QLabel *m_dnsLabel; + QLabel *m_secDnsLabel; +private: + void initUI(); + void initComponent(); + void setLineEnabled(bool check); + void configSave(); + bool getTextEditState(QString text); + bool checkConnectBtnIsEnabled(); + +private slots: + void setEnableOfSaveBtn(); + void configChanged(int index); +Q_SIGNALS: + void setCreatePageState(bool); + }; #endif // CREATNETPAGE_H diff --git a/src/frontend/netdetails/detailpage.cpp b/src/frontend/netdetails/detailpage.cpp index 04355f81..70aa28f7 100644 --- a/src/frontend/netdetails/detailpage.cpp +++ b/src/frontend/netdetails/detailpage.cpp @@ -2,13 +2,15 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); -DetailPage::DetailPage(bool isWlan, QWidget *parent) - : mIsWlan(isWlan), QFrame(parent) +DetailPage::DetailPage(bool isWlan, bool isCreate, QWidget *parent) + : mIsWlan(isWlan), isCreate(isCreate), QFrame(parent) { this->setFrameShape(QFrame::Shape::StyledPanel); this->setMaximumWidth(960); initUI(); - initComponent(); + if (isCreate) { + connect(mSSID, &QLineEdit::textEdited, this, &DetailPage::setEnableOfSaveBtn); + } } void DetailPage::setSSID(const QString &ssid) { @@ -51,16 +53,39 @@ void DetailPage::setMac(const QString &mac) { this->mMac->setText(mac); } +void DetailPage::setAutoConnect(bool flag) +{ + this->forgetNetBox->setChecked(flag); +} + +void DetailPage::getSsid(QString &ssid) +{ + ssid = mSSID->text(); +} + +bool DetailPage::checkIsChanged(const ConInfo info) +{ + if (info.isAutoConnect != forgetNetBox->isChecked()) { + return true; + } else { + return false; + } +} + void DetailPage::initUI() { forgetNetBox = new QCheckBox(this); layout = new QVBoxLayout(this); mDetailLayout = new QFormLayout(this); - mSSID = new QLabel(this); - QHBoxLayout *mSSIDLayout = new QHBoxLayout(this); - mSSIDLayout->addStretch(); - mSSIDLayout->addWidget(mSSID); + mSSID = new QLineEdit(this); + mSSID->setAlignment(Qt::AlignRight); + if (!isCreate) { + mSSID->setStyleSheet("background:transparent;border-width:0;border-style:outset"); + mSSID->setFocusPolicy(Qt::NoFocus); + } else { + mSSID->setStyleSheet("border-width:0;border-style:outset"); + } mProtocol = new QLabel(this); QHBoxLayout *mProtocolLayout = new QHBoxLayout(this); @@ -118,7 +143,7 @@ void DetailPage::initUI() { mAutoLayout->addWidget(autoConnect); mAutoLayout->addSpacerItem(horizontalSpacer); - mDetailLayout->addRow(tr("SSID:"), mSSIDLayout); + mDetailLayout->addRow(tr("SSID:"), mSSID); mDetailLayout->addRow(tr("Protocol:"), mProtocolLayout); if (mIsWlan) { mDetailLayout->addRow(tr("Security Type:"), mSecTypeLayout); @@ -136,10 +161,7 @@ void DetailPage::initUI() { layout->addLayout(mAutoLayout); } -void DetailPage::initComponent() { - connect(forgetNetBox, SIGNAL(toggled(bool)), this, SLOT(setNetStatus(bool))); -} - -void DetailPage::setNetStatus(bool checked) { +void DetailPage::setEnableOfSaveBtn() { + emit setDetailPageState(!mSSID->text().isEmpty()); } diff --git a/src/frontend/netdetails/detailpage.h b/src/frontend/netdetails/detailpage.h index a6fc33f7..719e33ce 100644 --- a/src/frontend/netdetails/detailpage.h +++ b/src/frontend/netdetails/detailpage.h @@ -7,11 +7,14 @@ #include #include #include + +#include "coninfo.h" + class DetailPage : public QFrame { Q_OBJECT public: - DetailPage(bool isWlan, QWidget *parent = nullptr); + DetailPage(bool isWlan, bool isCreate = false, QWidget *parent = nullptr); void setSSID(const QString &ssid); void setProtocol(const QString &protocol); @@ -23,13 +26,17 @@ public: void setIpv4Dns(const QString &ipv4Dns); void setIpv6(const QString &ipv6); void setMac(const QString &mac); + void setAutoConnect(bool flag); + + bool checkIsChanged(const ConInfo info); + + void getSsid(QString &ssid); private: void initUI(); - void initComponent(); public: - QLabel *mSSID; + QLineEdit *mSSID; QLabel *mProtocol; QLabel *mSecType; QLabel *mHz; @@ -48,8 +55,12 @@ private: QHBoxLayout *mAutoLayout; QCheckBox *forgetNetBox; bool mIsWlan; + bool isCreate; private slots: - void setNetStatus(bool checked); + void setEnableOfSaveBtn(); + +signals: + void setDetailPageState(bool); }; diff --git a/src/frontend/netdetails/ipv4page.cpp b/src/frontend/netdetails/ipv4page.cpp index 75292d34..43af26a1 100644 --- a/src/frontend/netdetails/ipv4page.cpp +++ b/src/frontend/netdetails/ipv4page.cpp @@ -1,7 +1,7 @@ #include "ipv4page.h" #include "netdetail.h" -Ipv4Page::Ipv4Page(bool isWlan, QWidget *parent) - : isWlan(isWlan), QFrame(parent) + +Ipv4Page::Ipv4Page(QWidget *parent):QFrame(parent) { initUI(); initComponent(); @@ -10,10 +10,10 @@ Ipv4Page::Ipv4Page(bool isWlan, QWidget *parent) void Ipv4Page::initUI() { ipv4ConfigCombox = new QComboBox(this); ipv4addressEdit = new QLineEdit(this); - netMaskCombox = new QComboBox(this); + netMaskEdit = new QLineEdit(this); gateWayEdit = new QLineEdit(this); - firstDnsEidt = new QLineEdit(this); - secondDnsEidt = new QLineEdit(this); + firstDnsEdit = new QLineEdit(this); + secondDnsEdit = new QLineEdit(this); m_configLabel = new QLabel(this); m_addressLabel = new QLabel(this); @@ -32,27 +32,30 @@ void Ipv4Page::initUI() { m_detailLayout = new QFormLayout(this); m_detailLayout->addRow(m_configLabel,ipv4ConfigCombox); m_detailLayout->addRow(m_addressLabel,ipv4addressEdit); - m_detailLayout->addRow(m_maskLabel,netMaskCombox); + m_detailLayout->addRow(m_maskLabel,netMaskEdit); m_detailLayout->addRow(m_gateWayLabel,gateWayEdit); - m_detailLayout->addRow(m_dnsLabel,firstDnsEidt); - m_detailLayout->addRow(m_secDnsLabel,secondDnsEidt); + m_detailLayout->addRow(m_dnsLabel,firstDnsEdit); + m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit); ipv4ConfigCombox->addItem(tr("Auto(DHCP)")); //"自动(DHCP)" ipv4ConfigCombox->addItem(tr("Manual")); //"手动" - netMaskCombox->addItem("255.255.255.0"); //24 - netMaskCombox->addItem("255.255.254.0"); //23 - netMaskCombox->addItem("255.255.252.0"); //22 - netMaskCombox->addItem("255.255.0.0"); //16 - netMaskCombox->addItem("255.0.0.0"); //8 +// netMaskCombox->addItem(""); +// netMaskCombox->addItem("255.255.255.0"); //24 +// netMaskCombox->addItem("255.255.254.0"); //23 +// netMaskCombox->addItem("255.255.252.0"); //22 +// netMaskCombox->addItem("255.255.0.0"); //16 +// netMaskCombox->addItem("255.0.0.0"); //8 + // IP的正则格式限制 QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + ipv4addressEdit->setValidator(new QRegExpValidator(rx, this)); gateWayEdit->setValidator(new QRegExpValidator(rx, this)); - firstDnsEidt->setValidator(new QRegExpValidator(rx, this)); - secondDnsEidt->setValidator(new QRegExpValidator(rx, this)); - setEnableOfSaveBtn(); + netMaskEdit->setValidator(new QRegExpValidator(rx, this)); + firstDnsEdit->setValidator(new QRegExpValidator(rx, this)); + secondDnsEdit->setValidator(new QRegExpValidator(rx, this)); } void Ipv4Page::initComponent() { @@ -62,12 +65,17 @@ void Ipv4Page::initComponent() { setLineEnabled(true); } connect(ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(configChanged(int))); -// connect(mNetMask, SIGNAL(currentIndexChanged(int)), this, SLOT(cbMaskChanged(int))); + + connect(ipv4ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfSaveBtn())); + connect(netMaskEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); } -void Ipv4Page::setIpv4Config(const QString &ipv4Config) +void Ipv4Page::setIpv4Config(KyIpConfigType ipv4Config) { - if (ipv4Config.toInt() == AUTO_CONFIG) { + if (ipv4Config == CONFIG_IP_MANUAL) { ipv4ConfigCombox->setCurrentIndex(MANUAL_CONFIG); } else { ipv4ConfigCombox->setCurrentIndex(AUTO_CONFIG); @@ -79,14 +87,19 @@ void Ipv4Page::setIpv4(const QString &ipv4) ipv4addressEdit->setText(ipv4); } +void Ipv4Page::setNetMask(const QString &netMask) +{ + netMaskEdit->setText(netMask); +} + void Ipv4Page::setIpv4FirDns(const QString &ipv4FirDns) { - firstDnsEidt->setText(ipv4FirDns); + firstDnsEdit->setText(ipv4FirDns); } void Ipv4Page::setIpv4SecDns(const QString &ipv4SecDns) { - secondDnsEidt->setText(ipv4SecDns); + secondDnsEdit->setText(ipv4SecDns); } void Ipv4Page::setGateWay(const QString &gateWay) @@ -94,6 +107,88 @@ void Ipv4Page::setGateWay(const QString &gateWay) gateWayEdit->setText(gateWay); } +bool Ipv4Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting) +{ + bool isChanged = false; + if (ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { + if (info.ipv4ConfigType != CONFIG_IP_DHCP) { + qDebug() << "ipv4ConfigType change to Auto"; + setting.setIpConfigType(IPADDRESS_V4, CONFIG_IP_DHCP); + isChanged = true; + } + } else { + if (info.ipv4ConfigType != CONFIG_IP_MANUAL) { + qDebug() << "ipv4ConfigType change to Manual"; + setting.setIpConfigType(IPADDRESS_V4, CONFIG_IP_MANUAL); + isChanged = true; + } + if(info.strIPV4Address != ipv4addressEdit->text() + || info.strIPV4NetMask != netMaskEdit->text() + || info.strIPV4GateWay != gateWayEdit->text() + || info.strIPV4FirDns != firstDnsEdit->text() + || info.strIPV4SecDns != secondDnsEdit->text()) { + + qDebug() << "ipv4 info changed"; + QStringList dnsList; + dnsList.empty(); + if (!firstDnsEdit->text().isEmpty()) { + dnsList << firstDnsEdit->text(); + if (!secondDnsEdit->text().isEmpty()) { + dnsList << secondDnsEdit->text(); + } + } + + QString ipv4address =ipv4addressEdit->text(); + QString netMask = netMaskEdit->text(); + QString gateWay = gateWayEdit->text(); + qDebug() << ipv4address << netMask << gateWay; + setting.ipv4AddressConstruct(ipv4address, netMask, gateWay, dnsList); + setting.dumpInfo(); + isChanged = true; + } + } + return isChanged; +} + +bool Ipv4Page::checkConnectBtnIsEnabled() +{ + qDebug() << "checkConnectBtnIsEnabled currentIndex" << ipv4ConfigCombox->currentIndex(); + if (ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) { + return true; + } else { + if (ipv4addressEdit->text().isEmpty() || !getTextEditState(ipv4addressEdit->text())) { + qDebug() << "ipv4address empty or invalid"; + return false; + } + + if (netMaskEdit->text().isEmpty() || !getTextEditState(netMaskEdit->text())) { + qDebug() << "ipv4 netMask empty or invalid"; + return false; + } + + if (gateWayEdit->text().isEmpty() || !getTextEditState(gateWayEdit->text())) { + qDebug() << "ipv4 gateway empty or invalid"; + return false; + } + + if (firstDnsEdit->text().isEmpty() && !secondDnsEdit->text().isEmpty()) { + qDebug() << "ipv4 dns sort invalid"; + return false; + } + + if (!getTextEditState(firstDnsEdit->text())) { + qDebug() << "ipv4 first dns invalid"; + return false; + } + + if (!getTextEditState(secondDnsEdit->text())) { + qDebug() << "ipv4 second dns invalid"; + return false; + } + } + return true; +} + void Ipv4Page::configChanged(int index) { if (index == AUTO_CONFIG) { setLineEnabled(false); @@ -104,54 +199,36 @@ void Ipv4Page::configChanged(int index) { } void Ipv4Page::setLineEnabled(bool check) { - m_addressLabel->setEnabled(check); - m_maskLabel->setEnabled(check); - m_gateWayLabel->setEnabled(check); - m_dnsLabel->setEnabled(check); - m_secDnsLabel->setEnabled(check); ipv4addressEdit->setEnabled(check); - netMaskCombox->setEnabled(check); + netMaskEdit->setEnabled(check); gateWayEdit->setEnabled(check); - firstDnsEidt->setEnabled(check); - secondDnsEidt->setEnabled(check); -} + firstDnsEdit->setEnabled(check); + secondDnsEdit->setEnabled(check); -void Ipv4Page::setEnableOfSaveBtn() { - if (ipv4ConfigCombox->currentIndex() == 1) { -// if (mIpv4address->text().isEmpty()) { -// //当ipv4和ipv6地址均未设置时,禁止保存 -// emit setBtnEnableFalse(); -// return; -// } - -// if (!ui->leAddr->text().isEmpty() && !this->getTextEditState(ui->leAddr->text()) ) { -// emit setBtnEnableFalse(); -// return; -// } - -// if (!ui->leGateway->text().isEmpty() && !this->getTextEditState(ui->leGateway->text()) ) { -// emit setBtnEnableFalse(); -// return; -// } - -// if (!ui->leDns->text().isEmpty() && !this->getTextEditState(ui->leDns->text()) ) { -// emit setBtnEnableFalse(); -// return; -// } - -// if (!ui->leAddr_ipv6->text().isEmpty() && ! this->getIpv6EditState(ui->leAddr_ipv6->text())) { -// emit setBtnEnableFalse(); -// return; -// } -// if(ui->leDns2->text().isEmpty()){ - -// }else{ -// if(!this->getTextEditState(ui->leDns2->text())){ -// emit setBtnEnableFalse(); -// return ; -// } -// } + if (!check) { + ipv4addressEdit->clear(); + netMaskEdit->clear(); + gateWayEdit->clear(); + firstDnsEdit->clear(); + secondDnsEdit->clear(); } } +void Ipv4Page::setEnableOfSaveBtn() { + emit setIpv4PageState(checkConnectBtnIsEnabled()); +} + +bool Ipv4Page::getTextEditState(QString text) +{ + if (text.isEmpty()) { + return true; + } + QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); + + bool match = false; + match = rx.exactMatch(text); + + return match; +} + diff --git a/src/frontend/netdetails/ipv4page.h b/src/frontend/netdetails/ipv4page.h index c53181ba..827f4e1b 100644 --- a/src/frontend/netdetails/ipv4page.h +++ b/src/frontend/netdetails/ipv4page.h @@ -12,35 +12,29 @@ #include #include -struct ConnProperties -{ - QString uuidName; //uuid - QString v4method; // - QString v4addr; //ipv4地址 - QString mask; // - QString gateway; //网关 - QString dns; //DNS - bool isActConf; // - QString type; //网络类型 -}; +//#include "kylinconnectsetting.h" +#include "coninfo.h" class Ipv4Page : public QFrame { Q_OBJECT public: - Ipv4Page(bool isWlan, QWidget *parent = nullptr); - void setIpv4Config(const QString &ipv4Config); + Ipv4Page(QWidget *parent = nullptr); + void setIpv4Config(KyIpConfigType ipv4Config); void setIpv4(const QString &ipv4); + void setNetMask(const QString &netMask); void setIpv4FirDns(const QString &ipv4FirDns); void setIpv4SecDns(const QString &ipv4SecDns); void setGateWay(const QString &gateWay); -public: + + bool checkIsChanged(const ConInfo info, KyConnectSetting &setting); +private: QComboBox *ipv4ConfigCombox; QLineEdit *ipv4addressEdit; - QComboBox *netMaskCombox; + QLineEdit *netMaskEdit; QLineEdit *gateWayEdit; - QLineEdit *firstDnsEidt; - QLineEdit *secondDnsEidt; + QLineEdit *firstDnsEdit; + QLineEdit *secondDnsEdit; private: QFormLayout *m_detailLayout; @@ -51,19 +45,19 @@ private: QLabel *m_gateWayLabel; QLabel *m_dnsLabel; QLabel *m_secDnsLabel; - bool isWlan; private: void initUI(); void initComponent(); - void setEnableOfSaveBtn(); void setLineEnabled(bool check); void configSave(); + bool getTextEditState(QString text); + bool checkConnectBtnIsEnabled(); - -public slots: +private slots: + void setEnableOfSaveBtn(); void configChanged(int index); Q_SIGNALS: -// void setBtnEnableFalse(); + void setIpv4PageState(bool); }; diff --git a/src/frontend/netdetails/ipv6page.cpp b/src/frontend/netdetails/ipv6page.cpp index 6b600d52..4bef6e2f 100644 --- a/src/frontend/netdetails/ipv6page.cpp +++ b/src/frontend/netdetails/ipv6page.cpp @@ -1,15 +1,15 @@ #include "ipv6page.h" #include "netdetail.h" -Ipv6Page::Ipv6Page(bool isWlan, QWidget *parent) - :isWlan(isWlan), QFrame(parent) + +Ipv6Page::Ipv6Page(QWidget *parent):QFrame(parent) { initUI(); initComponent(); } -void Ipv6Page::setIpv6Config(const QString &ipv6Config) +void Ipv6Page::setIpv6Config(KyIpConfigType ipv6Config) { - if (ipv6Config.toInt() == AUTO_CONFIG) { + if (ipv6Config == CONFIG_IP_MANUAL) { ipv6ConfigCombox->setCurrentIndex(MANUAL_CONFIG); } else { ipv6ConfigCombox->setCurrentIndex(AUTO_CONFIG); @@ -36,6 +36,48 @@ void Ipv6Page::setGateWay(const QString &gateWay) gateWayEdit->setText(gateWay); } +bool Ipv6Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting) +{ + bool isChanged = false; + if (ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) { + if (info.ipv6ConfigType != CONFIG_IP_DHCP) { + qDebug() << "ipv6ConfigType change to Auto"; + setting.setIpConfigType(IPADDRESS_V6, CONFIG_IP_DHCP); + isChanged = true; + } + } else { + if (info.ipv6ConfigType != CONFIG_IP_MANUAL) { + qDebug() << "ipv6ConfigType change to Manual"; + setting.setIpConfigType(IPADDRESS_V6, CONFIG_IP_MANUAL); + isChanged = true; + } + if(info.strIPV6Address != ipv6AddressEdit->text() + || info.strIPV6Prefix != lengthEdit->text() + || info.strIPV6GateWay != gateWayEdit->text() + || info.strIPV6FirDns != firstDnsEdit->text() + || info.strIPV6SecDns != secondDnsEdit->text()) { + + qDebug() << "ipv6 info changed"; + QStringList dnsList; + dnsList.empty(); + if (!firstDnsEdit->text().isEmpty()) { + dnsList << firstDnsEdit->text(); + if (!secondDnsEdit->text().isEmpty()) { + dnsList << secondDnsEdit->text(); + } + } + + QString ipv6address =ipv6AddressEdit->text(); + QString prefix = lengthEdit->text(); + QString gateWay = gateWayEdit->text(); + setting.ipv6AddressConstruct(ipv6address, prefix, gateWay, dnsList); + setting.dumpInfo(); + isChanged = true; + } + } + return isChanged; +} + void Ipv6Page::initUI() { ipv6ConfigCombox = new QComboBox(this); ipv6AddressEdit = new QLineEdit(this); @@ -73,15 +115,27 @@ void Ipv6Page::initUI() { QRegExp ipv6_rx("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"); ipv6AddressEdit->setValidator(new QRegExpValidator(ipv6_rx, this)); + gateWayEdit->setValidator(new QRegExpValidator(ipv6_rx, this)); + firstDnsEdit->setValidator(new QRegExpValidator(ipv6_rx, this)); + secondDnsEdit->setValidator(new QRegExpValidator(ipv6_rx, this)); + + QRegExp prefix_rx("\\b(?:(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\.){3}(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\b"); + lengthEdit->setValidator(new QRegExpValidator(prefix_rx,this)); } void Ipv6Page::initComponent() { - if (ipv6ConfigCombox->currentIndex() == MANUAL_CONFIG) { + if (ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) { setControlEnabled(false); } else if (ipv6ConfigCombox->currentIndex() == MANUAL_CONFIG) { setControlEnabled(true); } connect(ipv6ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(configChanged(int))); + + connect(ipv6ConfigCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfSaveBtn())); + connect(lengthEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(gateWayEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(firstDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(secondDnsEdit, SIGNAL(textChanged(QString)), this, SLOT(setEnableOfSaveBtn())); } void Ipv6Page::configChanged(int index) { @@ -93,17 +147,76 @@ void Ipv6Page::configChanged(int index) { } } -void Ipv6Page::setControlEnabled(bool check) { - m_addressLabel->setEnabled(check); - m_subnetLabel->setEnabled(check); - lengthEdit->setEnabled(check); - m_gateWayLabel->setEnabled(check); - m_dnsLabel->setEnabled(check); - m_secDnsLabel->setEnabled(check); - +void Ipv6Page::setControlEnabled(bool check) +{ ipv6AddressEdit->setEnabled(check); - m_subnetLabel->setEnabled(check); + lengthEdit->setEnabled(check); gateWayEdit->setEnabled(check); firstDnsEdit->setEnabled(check); secondDnsEdit->setEnabled(check); + + if (!check) { + ipv6AddressEdit->clear(); + lengthEdit->clear(); + gateWayEdit->clear(); + firstDnsEdit->clear(); + secondDnsEdit->clear(); + } } + +void Ipv6Page::setEnableOfSaveBtn() +{ + emit setIpv6PageState(checkConnectBtnIsEnabled()); +} + +bool Ipv6Page::checkConnectBtnIsEnabled() +{ + if (ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) { + return true; + } else { + if (ipv6AddressEdit->text().isEmpty() || !getIpv6EditState(ipv6AddressEdit->text())) { + qDebug() << "ipv6address empty or invalid"; + return false; + } + + if (lengthEdit->text().isEmpty()) { + qDebug() << "ipv6 prefix length empty"; + return false; + } + + if (gateWayEdit->text().isEmpty() || !getIpv6EditState(gateWayEdit->text())) { + qDebug() << "ipv6 gateway empty or invalid"; + return false; + } + + if (firstDnsEdit->text().isEmpty() && !secondDnsEdit->text().isEmpty()) { + qDebug() << "ipv6 dns sort invalid"; + return false; + } + + if (!getIpv6EditState(firstDnsEdit->text())) { + qDebug() << "ipv6 first dns invalid"; + return false; + } + + if (!getIpv6EditState(secondDnsEdit->text())) { + qDebug() << "ipv6 second dns invalid"; + return false; + } + } + return true; +} + +bool Ipv6Page::getIpv6EditState(QString text) +{ + if (text.isEmpty()) { + return true; + } + QRegExp rx("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"); + + bool match = false; + match = rx.exactMatch(text); + + return match; +} + diff --git a/src/frontend/netdetails/ipv6page.h b/src/frontend/netdetails/ipv6page.h index f2887eee..d312394c 100644 --- a/src/frontend/netdetails/ipv6page.h +++ b/src/frontend/netdetails/ipv6page.h @@ -12,17 +12,22 @@ #include #include +//#include "kylinconnectsetting.h" +#include "coninfo.h" + class Ipv6Page : public QFrame { Q_OBJECT public: - Ipv6Page(bool isWlan, QWidget *parent = nullptr); - void setIpv6Config(const QString &ipv6Config); + Ipv6Page(QWidget *parent = nullptr); + void setIpv6Config(KyIpConfigType ipv6Config); void setIpv6(const QString &ipv4); void setIpv6FirDns(const QString &ipv6FirDns); void setIpv6SecDns(const QString &ipv6SecDns); void setGateWay(const QString &gateWay); + bool checkIsChanged(const ConInfo info, KyConnectSetting &setting); + public: QComboBox *ipv6ConfigCombox; QLineEdit *ipv6AddressEdit; @@ -38,15 +43,22 @@ private: QLabel *m_gateWayLabel; QLabel *m_dnsLabel; QLabel *m_secDnsLabel; -private: - bool isWlan; private: void initUI(); void initComponent(); void setControlEnabled(bool check); -public slots: + bool getIpv6EditState(QString text); + + bool checkConnectBtnIsEnabled(); + + +private slots: void configChanged(int index); + void setEnableOfSaveBtn(); + +signals: + void setIpv6PageState(bool); }; #endif // IPV6PAGE_H diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index 57abc24e..f5e61946 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -1,4 +1,6 @@ #include "netdetail.h" +#include "backend/kylinipv4arping.h" +#include "backend/kylinipv6arping.h" #define WINDOW_WIDTH 540 #define WINDOW_HEIGHT 574 @@ -17,29 +19,49 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); -NetDetail::NetDetail(QString name, QString uuid, bool isActive, bool isWlan, bool isCreateNet, QWidget *parent) - :m_name(name), m_uuid(uuid), isActive(isActive), isWlan(isWlan), isCreateNet(isCreateNet), QDialog(parent) +NetDetail::NetDetail(QString interface, QString name, QString uuid, bool isActive, bool isWlan, bool isCreateNet, QWidget *parent) + :m_deviceName(interface), + m_name(name), + m_uuid(uuid), + isActive(isActive), + isWlan(isWlan), + isCreateNet(isCreateNet), + QDialog(parent) { - setWindowFlags(Qt::FramelessWindowHint | Qt::Tool); + setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint ); setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_DeleteOnClose); setFixedSize(WINDOW_WIDTH,WINDOW_HEIGHT); centerToScreen(); m_netDeviceResource = new KyNetworkDeviceResourse(this); - initWifiDevice(); - initLanDevice(); + m_wirelessConnOpration = new KyWirelessConnectOperation(this); + m_resource = new KyWirelessNetResource(this); + m_connectOperation = new KyConnectOperation(this); + m_wiredConnOperation = new KyWiredConnectOperation(this); initUI(); loadPage(); initComponent(); - getConInfo(mInfo); + getConInfo(m_info); pagePadding(name,isWlan); + + + isCreateOk = !(isCreateNet && !isWlan); + isDetailOk = !(m_name.isEmpty()); + isIpv4Ok = true; + isIpv6Ok = true; + isSecuOk = true; + + qDebug() << interface << name << uuid << "isWlan" << isWlan << "isCreateNet" <setContentsMargins(9,9,14,24); - detailPage = new DetailPage(isWlan,this); - ipv4Page = new Ipv4Page(isWlan,this); - ipv6Page = new Ipv6Page(isWlan,this); - securityWidget = new SecurityPage(this); + detailPage = new DetailPage(isWlan, isCreateNet, this); + ipv4Page = new Ipv4Page(this); + ipv6Page = new Ipv6Page(this); + securityPage = new SecurityPage(this); createNetPage = new CreatNetPage(this); -// addLanWidget = new AddLanWidget; titleWidget = new QWidget(this); centerWidget = new QWidget(this); @@ -71,7 +92,7 @@ void NetDetail::initUI() stackWidget->addWidget(detailPage); stackWidget->addWidget(ipv4Page); stackWidget->addWidget(ipv6Page); - stackWidget->addWidget(securityWidget); + stackWidget->addWidget(securityPage); stackWidget->addWidget(createNetPage); mainLayout->addWidget(titleWidget); @@ -150,19 +171,19 @@ void NetDetail::initUI() void NetDetail::loadPage() { - //判断是否创建网络 - if (isCreateNet) { + //判断是否创建网络页面 + if (isCreateNet && !isWlan) { pageFrame->hide(); stackWidget->setCurrentIndex(CREATE_NET_PAGE_NUM); - titleLabel->setText(tr("Add Connect")); + titleLabel->setText(tr("Add Lan Connect")); } else { stackWidget->setCurrentIndex(DETAIL_PAGE_NUM); titleLabel->setText(m_name); - } - if (!isWlan) { - securityBtn->hide(); - } else { - securityBtn->show(); + if (!isWlan) { + securityBtn->hide(); + } else { + securityBtn->show(); + } } } @@ -187,243 +208,395 @@ void NetDetail::initComponent() stackWidget->setCurrentIndex(SECURITY_PAGE_NUM); }); connect(confimBtn, SIGNAL(clicked()), this, SLOT(on_btnConfirm_clicked())); + if (!m_uuid.isEmpty()) { + forgetBtn->show(); + connect(forgetBtn, SIGNAL(clicked()), this, SLOT(on_btnForget_clicked())); + } else { + forgetBtn->hide(); + } + + connect(createNetPage, &CreatNetPage::setCreatePageState, this, [=](bool status) { + isCreateOk = status; + setConfirmEnable(); + }); + + connect(detailPage, &DetailPage::setDetailPageState, this, [=](bool status) { + isDetailOk = status; + setConfirmEnable(); + }); + + connect(ipv4Page, &Ipv4Page::setIpv4PageState, this, [=](bool status) { + isIpv4Ok = status; + setConfirmEnable(); + }); + + connect(ipv6Page, &Ipv6Page::setIpv6PageState, this, [=](bool status) { + isIpv6Ok = status; + setConfirmEnable(); + }); + + connect(securityPage, &SecurityPage::setSecuPageState, this, [=](bool status) { + isSecuOk = status; + setConfirmEnable(); + }); } void NetDetail::pagePadding(QString netName, bool isWlan) { - foreach (ConInfo netInfo, mInfo) { - //网络详情页填充 - if (isWlan) { - if (!netInfo.strConName.compare(netName, Qt::CaseInsensitive)) { - detailPage->setSSID(netName); - detailPage->setProtocol(netInfo.strConType); - detailPage->setSecType(netInfo.strSecType); - detailPage->setHz(netInfo.strHz); - detailPage->setChan(netInfo.strChan); - detailPage->setIpv4(netInfo.strIPV4Address); - detailPage->setIpv4Dns(netInfo.strIPV4FirDns); - detailPage->setIpv6(netInfo.strIPV6Address); - detailPage->setMac(netInfo.strMac); - detailPage->setBandWidth(netInfo.strBandWidth); - } - } else { - if (!netInfo.strConName.compare(netName, Qt::CaseInsensitive)) { - detailPage->setSSID(netName); - detailPage->setProtocol(netInfo.strConType); - detailPage->setIpv4(netInfo.strIPV4Address); - detailPage->setIpv4Dns(netInfo.strIPV4FirDns); - detailPage->setIpv6(netInfo.strIPV6Address); - detailPage->setMac(netInfo.strMac); - detailPage->setBandWidth(netInfo.strBandWidth); - } - } - //ipv4页面填充 - if (!netInfo.strConName.compare(netName, Qt::CaseInsensitive)) { - if (netInfo.strIPV4ConfigType.toInt() == AUTO_CONFIG) { - ipv4Page->setIpv4Config(netInfo.strIPV4ConfigType); - ipv4Page->setIpv4(netInfo.strIPV4Address); - ipv4Page->setIpv4FirDns(netInfo.strIPV4FirDns); - ipv4Page->setIpv4SecDns(netInfo.strIPV4SecDns); - ipv4Page->setGateWay(netInfo.strIPV4GateWay); - } else { - ipv4Page->setIpv4Config(netInfo.strIPV4ConfigType); - } - } - //ipv6页面填充 - if (!netInfo.strConName.compare(netName, Qt::CaseInsensitive)) { - if (netInfo.strIPV4ConfigType.toInt() == AUTO_CONFIG) { - ipv6Page->setIpv6Config(netInfo.strIPV6ConfigType); - ipv6Page->setIpv6(netInfo.strIPV4Address); - ipv6Page->setIpv6FirDns(netInfo.strIPV6FirDns); - ipv6Page->setIpv6SecDns(netInfo.strIPV4SecDns); - ipv6Page->setGateWay(netInfo.strIPV4GateWay); - } else { - ipv6Page->setIpv6Config(netInfo.strIPV6ConfigType); - } - } + //网络详情页填充 + if(isCreateNet && !isWlan) { + return; } -} -void NetDetail::initLanDevice() -{ - QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); - m_settings->beginGroup("DEFAULTCARD"); - QString key("wired"); - m_deviceName = m_settings->value(key, "").toString(); - if (m_deviceName.isEmpty()) { - qDebug() << "initDevice but defalut wired card is null"; - QStringList list; - list.empty(); - m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, list); - if (!list.isEmpty()) { - m_deviceName = list.at(0); - m_settings->setValue(key, m_deviceName); - } - } - qDebug() << "[LanPage] initDevice defaultDevice = " << m_deviceName; - m_settings->endGroup(); - m_settings->sync(); - delete m_settings; - m_settings = nullptr; -} + detailPage->setSSID(netName); + detailPage->setProtocol(m_info.strConType); + detailPage->setSecType(m_info.strSecType); + detailPage->setHz(m_info.strHz); + detailPage->setChan(m_info.strChan); + detailPage->setIpv4(m_info.strDynamicIpv4); + detailPage->setIpv4Dns(m_info.strDynamicIpv4Dns); + detailPage->setIpv6(m_info.strDynamicIpv6); + detailPage->setMac(m_info.strMac); + detailPage->setBandWidth(m_info.strBandWidth); + detailPage->setAutoConnect(m_info.isAutoConnect); -void NetDetail::initWifiDevice() -{ - QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); - m_settings->beginGroup("DEFAULTCARD"); - QString key("wireless"); - QString deviceName = m_settings->value(key, "").toString(); - m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, m_devList); - if (deviceName.isEmpty()) { - qDebug() << "initDevice but defalut wireless card is null"; - if (!m_devList.isEmpty()) { - deviceName = m_devList.at(0); - m_settings->setValue(key, deviceName); + //ipv4页面填充 + if (m_info.ipv4ConfigType == CONFIG_IP_MANUAL) { + ipv4Page->setIpv4Config(m_info.ipv4ConfigType); + ipv4Page->setIpv4(m_info.strIPV4Address); + ipv4Page->setNetMask(m_info.strIPV4NetMask); + ipv4Page->setIpv4FirDns(m_info.strIPV4FirDns); + ipv4Page->setIpv4SecDns(m_info.strIPV4SecDns); + ipv4Page->setGateWay(m_info.strIPV4GateWay); + } else { + ipv4Page->setIpv4Config(m_info.ipv4ConfigType); + } + //ipv6页面填充 + if (m_info.ipv6ConfigType == CONFIG_IP_MANUAL) { + ipv6Page->setIpv6Config(m_info.ipv6ConfigType); + ipv6Page->setIpv6(m_info.strIPV4Address); + ipv6Page->setIpv6FirDns(m_info.strIPV6FirDns); + ipv6Page->setIpv6SecDns(m_info.strIPV4SecDns); + ipv6Page->setGateWay(m_info.strIPV4GateWay); + } else { + ipv6Page->setIpv6Config(m_info.ipv6ConfigType); + } + + //安全页面 + if (isWlan) { + securityPage->setSecurity(m_info.secType); + qDebug() << "setSecurity" << m_info.secType; + if (m_info.secType == WPA_AND_WPA2_ENTERPRISE) { + if (m_info.enterpriseType == TLS) { + securityPage->setTlsInfo(m_info.tlsInfo); + } else if (m_info.enterpriseType == PEAP) { + securityPage->setPeapInfo(m_info.peapInfo); + } else if (m_info.enterpriseType == TTLS) { + securityPage->setTtlsInfo(m_info.ttlsInfo); + } } } - qDebug() << "[WlanPage] initDevice defaultDevice = " << deviceName; - m_settings->endGroup(); - m_settings->sync(); - delete m_settings; - m_settings = nullptr; } //获取网路详情信息 -void NetDetail::getConInfo(QList& qlConInfo) +void NetDetail::getConInfo(ConInfo &conInfo) { - ConInfo conInfo; - KyConnectSetting connetSetting; - KyWirelessNetItem kyWirelessNetItem; - KyWirelessNetResource *m_resource = new KyWirelessNetResource(this); - KyConnectResourse *kyConnectResourse = new KyConnectResourse(this); + if (isCreateNet && !isWlan) { + return; + } + getBaseInfo(conInfo); + getDynamicIpInfo(conInfo, isActive); + getStaticIpInfo(conInfo,isActive); +} + + +//详情ssid 带宽 物理地址 无线额外(安全性 频带 通道) +void NetDetail::getBaseInfo(ConInfo &conInfo) +{ + //有线无线公有 + conInfo.strConName = m_name; - QString deviceName; QString hardAddress; int bandWith; + m_netDeviceResource->getHardwareInfo(m_deviceName, hardAddress, bandWith); - if (!m_devList.isEmpty()) { - deviceName = m_devList.at(0); + if (!hardAddress.isEmpty()) { + conInfo.strBandWidth = QString("%1").arg(bandWith/1000) + "Mbps"; } - if(isWlan) { - if (!m_resource->getWifiNetwork(deviceName, m_name, kyWirelessNetItem)) { - return; + + if (!isWlan) { + conInfo.strConType = "802-3-ethernet"; + if (!hardAddress.isEmpty()) { + conInfo.strMac = hardAddress; } + } else { + conInfo.strConType = "802-11-wireless"; + KyWirelessNetItem item; + if (!m_resource->getWifiNetwork(m_deviceName, m_name, item)) { + qDebug() << "getWifiNetWork failed device:" << m_deviceName << " name:" << m_name; + return; + } else { + conInfo.strMac = item.m_bssid; + } + + //无线特有 + conInfo.strSecType = item.m_secuType; + qDebug() << conInfo.strSecType; + + KyKeyMgmt type = m_wirelessConnOpration->getConnectKeyMgmt(m_uuid); + if (type == WpaNone || type == Unknown) { + conInfo.secType = NONE; + } else if (type == WpaPsk) { + conInfo.secType = WPA_AND_WPA2_PERSONAL; + } else if (type == SAE) { + conInfo.secType = WPA3_PERSONAL; + } else if (type == WpaEap) { + conInfo.secType = WPA_AND_WPA2_ENTERPRISE; + } else { + qDebug() << "KeyMgmt not support now " << type; + } + conInfo.strHz = QString::number(item.m_frequency); + if (item.m_isConfigured) { + conInfo.strChan = QString::number(item.m_channel); + } + + initSecuData(); } +} + +//详情ipv4 ipv6 ipv4Dns +void NetDetail::getDynamicIpInfo(ConInfo &conInfo, bool bActived) +{ + if (!bActived) { + return; + } + //已激活的网络 详情页显示动态ipv4 ipv6 dns + QString ipv4,ipv6; + QList ipv4Dns,ipv6Dns; + KyActiveConnectResourse *activeResourse = new KyActiveConnectResourse(this); + activeResourse->getActiveConnectIpInfo(m_uuid,ipv4,ipv6); + activeResourse->getActiveConnectDnsInfo(m_uuid,ipv4Dns,ipv6Dns); + + //Ipv6 + if (!ipv6.isEmpty()) { + conInfo.strDynamicIpv6 = ipv6; + } + + //IPv4 + if (!ipv4.isEmpty()) { + conInfo.strDynamicIpv4 = ipv4; + } + + if (!ipv4Dns.isEmpty()) { + conInfo.strDynamicIpv4Dns = ipv4Dns.at(0).toString(); + } +} + +//ipv4+ipv6页面 +void NetDetail::getStaticIpInfo(ConInfo &conInfo, bool bActived) +{ + KyConnectResourse *kyConnectResourse = new KyConnectResourse(this); + KyConnectSetting connetSetting; kyConnectResourse->getConnectionSetting(m_uuid,connetSetting); - conInfo.strConUUID = m_uuid; - conInfo.strIPV4ConfigType = QString("%1").arg(connetSetting.m_ipv4ConfigIpType); - conInfo.strIPV6ConfigType = QString("%1").arg(connetSetting.m_ipv6ConfigIpType); - qDebug()<<"conInfo.strConUUID:"< 0) { - conInfo.strIPV4Address = connetSetting.m_ipv4Address.at(0).ip().toString(); - conInfo.strIPV4GateWay = connetSetting.m_ipv4Address.at(0).gateway().toString(); - } else { - conInfo.strIPV4Address = "--"; - conInfo.strIPV4GateWay = "--"; - qDebug()<<"m_ipv4Address length is 0"; - } - if (connetSetting.m_ipv6Address.length() > 0) { - conInfo.strIPV6Address = connetSetting.m_ipv6Address.at(0).ip().toString(); - conInfo.strIPV6GateWay = connetSetting.m_ipv6Address.at(0).gateway().toString(); - } else { - conInfo.strIPV6Address = "--"; - conInfo.strIPV6GateWay = "--"; - qDebug()<<"m_ipv4Address length is 0"; - } + conInfo.ipv4ConfigType = connetSetting.m_ipv4ConfigIpType; + conInfo.ipv6ConfigType = connetSetting.m_ipv6ConfigIpType; + conInfo.isAutoConnect = connetSetting.m_isAutoConnect; - if (isWlan && isActive) { - conInfo.strConType = "802-11-wireless"; - KyActiveConnectResourse *activeResourse = new KyActiveConnectResourse(this); - QString ipv4,ipv6; - QList ipv4Dns,ipv6Dns; - activeResourse->getActiveConnectIpInfo(m_uuid,ipv4,ipv6); - activeResourse->getActiveConnectDnsInfo(m_uuid,ipv4Dns,ipv6Dns); - m_netDeviceResource->getHardwareInfo(deviceName, hardAddress, bandWith); - - qDebug()<<"802-11-wireless : "<<"deviceName:"< 0) { + conInfo.strIPV4Address = connetSetting.m_ipv4Address.at(0).ip().toString(); + conInfo.strIPV4NetMask = connetSetting.m_ipv4Address.at(0).netmask().toString(); + conInfo.strIPV4GateWay = connetSetting.m_ipv4Address.at(0).gateway().toString(); } - if (ipv6Dns.length() == 1) { - conInfo.strIPV6FirDns = ipv6Dns.at(0).toString(); - conInfo.strIPV6SecDns = "--"; - } else if (ipv4Dns.length() == 2){ - conInfo.strIPV6FirDns = ipv6Dns.at(0).toString(); - conInfo.strIPV6SecDns = ipv6Dns.at(1).toString(); - } else { - conInfo.strIPV6FirDns = "--"; - conInfo.strIPV6SecDns = "--"; - qDebug()<<"ipv6Dns length is 0"; - } - - conInfo.strSecType = kyWirelessNetItem.m_secuType; - conInfo.strMac = kyWirelessNetItem.m_bssid; - conInfo.strHz = QString("%1").arg(kyWirelessNetItem.m_frequency) +" MHz"; - conInfo.strConName = kyWirelessNetItem.m_NetSsid; - conInfo.strIPV4Address = ipv4; - conInfo.strIPV6Address = ipv6; - conInfo.strBandWidth = QString("%1").arg(bandWith/1000) + "Mbps"; - } else if (isWlan && !isActive) { - conInfo.strConType = "802-11-wireless"; - } else { - conInfo.strConType = "802-3-ethernet"; - qDebug()<<"802-11-ethernet : "<<"deviceName:"<getHardwareInfo(m_deviceName, hardAddress, bandWith); - if (connetSetting.m_ipv4Dns.length() == 1) { + if (connetSetting.m_ipv4Dns.size() == 1) { conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString(); - conInfo.strIPV4SecDns = "--"; - } else if (connetSetting.m_ipv4Dns.length() == 2) { + } else if (connetSetting.m_ipv4Dns.size() > 1) { conInfo.strIPV4FirDns = connetSetting.m_ipv4Dns.at(0).toString(); conInfo.strIPV4SecDns = connetSetting.m_ipv4Dns.at(1).toString(); - } else { - conInfo.strIPV4FirDns = "--"; - conInfo.strIPV4SecDns = "--"; - qDebug()<<"m_ipv4DNS length is 0"; } - if (connetSetting.m_ipv6Dns.length() == 1) { + } + + if (connetSetting.m_ipv6ConfigIpType == CONFIG_IP_MANUAL) { + if (connetSetting.m_ipv6Address.size() > 0) { + conInfo.strIPV6Address = connetSetting.m_ipv6Address.at(0).ip().toString(); + conInfo.strIPV6Prefix = connetSetting.m_ipv6Address.at(0).netmask().toString(); + conInfo.strIPV6GateWay = connetSetting.m_ipv6Address.at(0).gateway().toString(); + } + + if (connetSetting.m_ipv6Dns.size() == 1) { conInfo.strIPV6FirDns = connetSetting.m_ipv6Dns.at(0).toString(); - conInfo.strIPV6SecDns = "--"; - } else if (connetSetting.m_ipv6Dns.length() == 2) { + } else if (connetSetting.m_ipv4Dns.size() > 1) { conInfo.strIPV6FirDns = connetSetting.m_ipv6Dns.at(0).toString(); conInfo.strIPV6SecDns = connetSetting.m_ipv6Dns.at(1).toString(); - } else { - conInfo.strIPV6FirDns = "--"; - conInfo.strIPV6SecDns = "--"; - qDebug()<<"m_ipv6DNS length is 0"; } - conInfo.strBandWidth = QString("%1").arg(bandWith/1000) + "Mbps"; - conInfo.strMac = hardAddress; } - qlConInfo.append(conInfo); + + if (!bActived) { + conInfo.strDynamicIpv4 = conInfo.strIPV4Address.isEmpty() ? tr("Auto") : conInfo.strIPV4Address; + conInfo.strDynamicIpv6 = conInfo.strIPV6Address.isEmpty() ? tr("Auto") : conInfo.strIPV6Address; + conInfo.strDynamicIpv4Dns = conInfo.strIPV4FirDns.isEmpty() ? tr("Auto") : conInfo.strIPV4FirDns; + } +} + +void NetDetail::initSecuData() +{ + QString password; + int type = m_info.secType; + switch (type) { + case NONE: + break; + case WPA_AND_WPA2_PERSONAL: + case WPA3_PERSONAL: + password = m_wirelessConnOpration->getPsk(m_uuid); + m_info.strPassword = password; + securityPage->setPsk(password); + break; + case WPA_AND_WPA2_ENTERPRISE: + if (!m_wirelessConnOpration->getEnterpiseEapMethod(m_uuid, m_info.enterpriseType)) { + qDebug() << m_name << "not enterprise wifi"; + } else if (m_info.enterpriseType == TLS){ + initTlsInfo(m_info); + } else if (m_info.enterpriseType == PEAP){ + initPeapInfo(m_info); + } else { + initTtlsInfo(m_info); + } + break; + default: + break; + } +} + +void NetDetail::initTlsInfo(ConInfo &conInfo) +{ + m_resource->getEnterPriseInfoTls(m_uuid, conInfo.tlsInfo); +} + +void NetDetail::initPeapInfo(ConInfo &conInfo) +{ + m_resource->getEnterPriseInfoPeap(m_uuid, conInfo.peapInfo); +} + +void NetDetail::initTtlsInfo(ConInfo &conInfo) +{ + m_resource->getEnterPriseInfoTtls(m_uuid, conInfo.ttlsInfo); } //点击了保存更改网络设置的按钮 void NetDetail::on_btnConfirm_clicked() { - if (checkConfig()) { - + if (isCreateNet) { + if (!isWlan) { + //新建有线连接 + qDebug() << "Confirm create wired connect"; + if (!createWiredConnect()) { + return; + } + } else { + //新建无线连接 + qDebug() << "Confirm create wireless connect"; + if (!createWirelessConnect()) { + return; + } + } } else { + //更新连接 + qDebug() << "Confirm update connect"; + if (!updateConnect()) { + return; + } + } + close(); +} +//点击忘记网络 +void NetDetail::on_btnForget_clicked() +{ + qDebug() << "user choose forget connection uuid = " << m_uuid; + m_connectOperation->deleteConnect(m_uuid); + close(); +} + +void NetDetail::setConfirmEnable() +{ + qDebug() << isCreateNet << isWlan; + if (isCreateNet && !isWlan) { + isConfirmBtnEnable = isCreateOk; + } else { + qDebug() << isDetailOk << isIpv4Ok << isIpv6Ok << isSecuOk; + if (isDetailOk && isIpv4Ok && isIpv6Ok) { + if (isWlan && !isSecuOk) { + isConfirmBtnEnable = false; + } else { + isConfirmBtnEnable = true; + } + } else { + isConfirmBtnEnable = false; + } + } + qDebug() << "setConfirmEnable "<< isConfirmBtnEnable; + confimBtn->setEnabled(isConfirmBtnEnable); +} + +bool NetDetail::checkIpv4Conflict(QString ipv4Address) +{ + bool isConflict = false; + KyIpv4Arping* ipv4Arping = new KyIpv4Arping(m_deviceName, ipv4Address); + + if (ipv4Arping->ipv4ConflictCheck() >= 0) { + isConflict = ipv4Arping->ipv4IsConflict(); + } else { + qDebug() << "checkIpv4Conflict internal error"; + } + + delete ipv4Arping; + ipv4Arping = nullptr; + return isConflict; +} + +bool NetDetail::checkIpv6Conflict(QString ipv6address) +{ + bool isConflict = false; + KyIpv6Arping* ipv46rping = new KyIpv6Arping(m_deviceName, ipv6address); + + if (ipv46rping->ipv6ConflictCheck() >= 0) { + isConflict = ipv46rping->ipv6IsConflict(); + } else { + qDebug() << "checkIpv6Conflict internal error"; + } + + delete ipv46rping; + ipv46rping = nullptr; + return isConflict; +} + +void NetDetail::updateWirelessPersonalConnect() +{ + KyWirelessConnectSetting setting; + securityPage->updateSecurityChange(setting); + bool isPwdChanged = !(m_info.strPassword == setting.m_psk); + qDebug() << setting.m_psk << isPwdChanged; + m_wirelessConnOpration->updateWirelessPersonalConnect(m_uuid, setting, isPwdChanged); +} + +void NetDetail::updateWirelessEnterPriseConnect(KyEapMethodType enterpriseType) +{ + if (enterpriseType == TLS) { + m_info.tlsInfo.devIfaceName = m_deviceName; + securityPage->updateTlsChange(m_info.tlsInfo); + m_wirelessConnOpration->updateWirelessEnterPriseTlsConnect(m_uuid, m_info.tlsInfo); + } else if (enterpriseType == PEAP) { + securityPage->updatePeapChange(m_info.peapInfo); + m_wirelessConnOpration->updateWirelessEnterPrisePeapConnect(m_uuid, m_info.peapInfo); + } else if (enterpriseType == TTLS) { + securityPage->updateTtlsChange(m_info.ttlsInfo); + m_wirelessConnOpration->updateWirelessEnterPriseTtlsConnect(m_uuid, m_info.ttlsInfo); } } -//检测网络配置信息是否改变 -bool NetDetail::checkConfig() { - return false; -} + void NetDetail::paintEvent(QPaintEvent *event) { @@ -466,3 +639,133 @@ void NetDetail::paintEvent(QPaintEvent *event) p.fillPath(rectPath, palette().color(QPalette::Base)); p.restore(); } + +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; + } + m_wiredConnOperation->createWiredConnect(connetSetting); + return true; +} + +bool NetDetail::createWirelessConnect() +{ + KyWirelessConnectSetting connetSetting; + //基本信息 + QString ssid; + detailPage->getSsid(ssid); + connetSetting.setConnectName(ssid); + connetSetting.setIfaceName(m_deviceName); + if (detailPage->checkIsChanged(m_info)) { + connetSetting.isAutoConnect = !m_info.isAutoConnect; + } else { + connetSetting.isAutoConnect = m_info.isAutoConnect; + } + qDebug() << "isAutoConnect" << connetSetting.isAutoConnect; + connetSetting.m_ssid = ssid; + connetSetting.m_secretFlag = NetworkManager::Setting::None; + + //ipv4 & ipv6 + bool ipv4Change = ipv4Page->checkIsChanged(m_info, connetSetting); + bool ipv6Change = ipv6Page->checkIsChanged(m_info, connetSetting); + + connetSetting.dumpInfo(); + + qDebug() << "ipv4Changed" << ipv4Change << "ipv6Change" << ipv6Change; + if (ipv4Change && connetSetting.m_ipv4ConfigIpType == CONFIG_IP_MANUAL) { + if (checkIpv4Conflict(connetSetting.m_ipv4Address.at(0).ip().toString())) { + qDebug() << "ipv4 conflict"; + //todo desktop notify + return false; + } + } + + if (ipv6Change && connetSetting.m_ipv6ConfigIpType == CONFIG_IP_MANUAL) { + if (checkIpv6Conflict(connetSetting.m_ipv6Address.at(0).ip().toString())) { + qDebug() << "ipv6 conflict"; + //todo desktop notify + return false; + } + } + //wifi安全性 + KySecuType secuType; + KyEapMethodType enterpriseType; + securityPage->getSecuType(secuType, enterpriseType); + if (secuType == WPA_AND_WPA2_ENTERPRISE) { + connetSetting.m_type = SAE; + if (enterpriseType == TLS) { + qDebug() << "add new TLS connect"; + m_info.tlsInfo.devIfaceName = m_deviceName; + securityPage->updateTlsChange(m_info.tlsInfo); + m_wirelessConnOpration->addTlsConnect(connetSetting, m_info.tlsInfo); + } else if (enterpriseType == PEAP) { + qDebug() << "add new PEAP connect"; + securityPage->updatePeapChange(m_info.peapInfo); + m_wirelessConnOpration->addPeapConnect(connetSetting, m_info.peapInfo); + } else if (enterpriseType == TTLS) { + qDebug() << "add new TTLS connect"; + securityPage->updateTtlsChange(m_info.ttlsInfo); + m_wirelessConnOpration->addTtlsConnect(connetSetting, m_info.ttlsInfo); + } + } else { + qDebug() << "add new personal connect"; + securityPage->updateSecurityChange(connetSetting); + m_wirelessConnOpration->addConnect(connetSetting); + } + return true; +} + +bool NetDetail::updateConnect() +{ + KyConnectResourse *kyConnectResourse = new KyConnectResourse(this); + KyConnectSetting connetSetting; + kyConnectResourse->getConnectionSetting(m_uuid,connetSetting); + + if(!m_uuid.isEmpty() && detailPage->checkIsChanged(m_info)) { + m_wirelessConnOpration->setWirelessAutoConnect(m_uuid, !m_info.isAutoConnect); + } + + bool ipv4Change = ipv4Page->checkIsChanged(m_info, connetSetting); + bool ipv6Change = ipv6Page->checkIsChanged(m_info, connetSetting); + + qDebug() << "ipv4Changed" << ipv4Change << "ipv6Change" << ipv6Change; + + if (ipv4Change && connetSetting.m_ipv4ConfigIpType == CONFIG_IP_MANUAL) { + if (checkIpv4Conflict(connetSetting.m_ipv4Address.at(0).ip().toString())) { + qDebug() << "ipv4 conflict"; + //todo desktop notify + return false; + } + } + + if (ipv6Change && connetSetting.m_ipv6ConfigIpType == CONFIG_IP_MANUAL) { + if (checkIpv6Conflict(connetSetting.m_ipv6Address.at(0).ip().toString())) { + qDebug() << "ipv6 conflict"; + //todo desktop notify + return false; + } + } + + if (ipv4Change || ipv6Change) { + connetSetting.dumpInfo(); + m_wiredConnOperation->updateWiredConnect(m_uuid, connetSetting); + } + + if (isWlan && securityPage->checkIsChanged(m_info)) { + KySecuType secuType; + KyEapMethodType enterpriseType; + securityPage->getSecuType(secuType, enterpriseType); + if (secuType == WPA_AND_WPA2_ENTERPRISE) { + updateWirelessEnterPriseConnect(enterpriseType); + } else { + updateWirelessPersonalConnect(); + } + } + return true; +} diff --git a/src/frontend/netdetails/netdetail.h b/src/frontend/netdetails/netdetail.h index 3645e345..7c139818 100644 --- a/src/frontend/netdetails/netdetail.h +++ b/src/frontend/netdetails/netdetail.h @@ -24,73 +24,64 @@ #include "ipv6page.h" #include "securitypage.h" #include "creatnetpage.h" -#include "kywirelessnetitem.h" -#include "kylinconnectresource.h" -#include "kylinactiveconnectresource.h" -#include "kywirelessnetresource.h" +#include "coninfo.h" #include "tab-pages/tabpage.h" -static int AUTO_CONFIG = 0; -static int MANUAL_CONFIG = 1; - -typedef struct ConInfo_s { - QString strConName; - QString strConUUID; - QString strConType; - QString strSecType; - QString strChan; - QString strMac; - QString strHz; - QString strBandWidth; - - QString strIPV4ConfigType; - QString strIPV4Address; - QString strIPV4Prefix; - QString strIPV4FirDns; - QString strIPV4SecDns; - QString strIPV4GateWay; - - QString strIPV6ConfigType; - QString strIPV6Address; - QString strIPV6FirDns; - QString strIPV6SecDns; - QString strIPV6GateWay; - QString strIPV6Prefix; -}ConInfo; - - class NetDetail : public QDialog { Q_OBJECT public: - NetDetail(QString name, QString uuid, bool isActive, bool isWlan, bool isCreateNet, QWidget *parent = nullptr); + NetDetail(QString interface, QString name, QString uuid, bool isActive, bool isWlan, bool isCreateNet, QWidget *parent = nullptr); ~NetDetail(); protected: void paintEvent(QPaintEvent *event); private: void initUI(); - void initWifiDevice();//初始化无线默认设备 - void initLanDevice();//初始化有线默认设备 void centerToScreen(); void initComponent(); - void getConInfo(QList& qlConInfo); - bool checkConfig(); + void getConInfo(ConInfo &conInfo); void loadPage(); void pagePadding(QString netName, bool isWlan); + void initSecuData(); + void initTlsInfo(ConInfo &conInfo); + void initPeapInfo(ConInfo &conInfo); + void initTtlsInfo(ConInfo &conInfo); + + void updateWirelessPersonalConnect(); + void updateWirelessEnterPriseConnect(KyEapMethodType enterpriseType); + + //详情ssid 带宽 物理地址 无线额外(安全性 频带 通道) + void getBaseInfo(ConInfo &conInfo); + //详情ipv4 ipv6 ipv4Dns + void getDynamicIpInfo(ConInfo &conInfo, bool bActived); + //ipv4+ipv6页面 + void getStaticIpInfo(ConInfo &conInfo, bool bActived); + + void setConfirmEnable(); + + bool checkIpv4Conflict(QString ipv4Address); + bool checkIpv6Conflict(QString ipv6Address); + + bool createWiredConnect(); + bool createWirelessConnect(); + bool updateConnect(); private: KyNetworkDeviceResourse *m_netDeviceResource = nullptr; + KyConnectOperation* m_connectOperation = nullptr; + KyWirelessConnectOperation *m_wirelessConnOpration = nullptr; + KyWiredConnectOperation *m_wiredConnOperation = nullptr; + KyWirelessNetResource *m_resource = nullptr; QStackedWidget * stackWidget; DetailPage * detailPage; Ipv4Page * ipv4Page; Ipv6Page * ipv6Page; - SecurityPage * securityWidget; + SecurityPage * securityPage; CreatNetPage * createNetPage; -// AddLanWidget * addLanWidget; QWidget * titleWidget; QWidget * centerWidget; @@ -112,18 +103,24 @@ private: QString m_name; QString m_uuid; - QString m_ssid; - QStringList m_devList; QString m_deviceName; bool isWlan; bool isCreateNet; bool isActive; + bool isHideWlan; - QList mInfo; + bool isCreateOk; + bool isDetailOk; + bool isIpv4Ok; + bool isIpv6Ok; + bool isSecuOk; + bool isConfirmBtnEnable; + + ConInfo m_info; private slots: void on_btnConfirm_clicked(); - + void on_btnForget_clicked(); }; #endif // NETDETAIL_H diff --git a/src/frontend/netdetails/securitypage.cpp b/src/frontend/netdetails/securitypage.cpp index cb089993..6d509a25 100644 --- a/src/frontend/netdetails/securitypage.cpp +++ b/src/frontend/netdetails/securitypage.cpp @@ -1,11 +1,742 @@ #include "securitypage.h" +#include "netdetail.h" + +#include SecurityPage::SecurityPage(QWidget *parent) : QFrame(parent) { initUI(); + initConnect(); } void SecurityPage::initUI() { + secuTypeLabel = new QLabel(this); + pwdLabel = new QLabel(this); + secuTypeLabel = new QLabel(this); + pwdLabel = new QLabel(this); + //企业wifi共有 + eapTypeLabel = new QLabel(this); + //TLS + identityLable = new QLabel(this); + domainLable = new QLabel(this); + caCertPathLabel = new QLabel(this); + caNeedFlagLabel = new QLabel(this); + clientCertPathLabel = new QLabel(this); + clientPrivateKeyLabel = new QLabel(this); + clientPrivateKeyPwdLabel = new QLabel(this); + + //PEAP TTLS共有 + eapMethodLabel = new QLabel(this); + userNameLabel = new QLabel(this); + userPwdLabel = new QLabel(this); + userPwdFlagLabel = new QLabel(this); + + secuTypeCombox = new QComboBox(this); + pwdEdit = new QLineEdit(this); + eapTypeCombox = new QComboBox(this); + //TLS + identityEdit = new QLineEdit(this); + domainEdit = new QLineEdit(this); + caCertPathCombox = new QComboBox(this); + caNeedBox = new QCheckBox(this); + clientCertPathCombox = new QComboBox(this); + clientPrivateKeyCombox = new QComboBox(this); + clientPrivateKeyPwdEdit = new QLineEdit(this); + + //PEAP && TTLS + eapMethodCombox = new QComboBox(this); + userNameEdit = new QLineEdit(this); + userPwdEdit = new QLineEdit(this); + userPwdFlagBox = new QCheckBox(this); + + + mSecuLayout = new QFormLayout(this); + mSecuLayout->addRow(secuTypeLabel, secuTypeCombox); + mSecuLayout->addRow(pwdLabel, pwdEdit); + mSecuLayout->addRow(eapTypeLabel, eapTypeCombox); + mSecuLayout->addRow(identityLable, identityEdit); + mSecuLayout->addRow(domainLable, domainEdit); + mSecuLayout->addRow(caCertPathLabel, caCertPathCombox); + mSecuLayout->addRow(caNeedBox, caNeedFlagLabel); + mSecuLayout->addRow(clientCertPathLabel, clientCertPathCombox); + mSecuLayout->addRow(clientPrivateKeyLabel, clientPrivateKeyCombox); + mSecuLayout->addRow(clientPrivateKeyPwdLabel,clientPrivateKeyPwdEdit); + mSecuLayout->addRow(eapMethodLabel, eapMethodCombox); + mSecuLayout->addRow(userNameLabel, userNameEdit); + mSecuLayout->addRow(userPwdLabel, userPwdEdit); + mSecuLayout->addRow(userPwdFlagBox, userPwdFlagLabel); + + + secuTypeLabel->setText(tr("Security")); + pwdLabel->setText(tr("Password")); + //企业wifi共有 + eapTypeLabel->setText(tr("EAP type")); + //TLS + identityLable->setText(tr("Identity")); + domainLable->setText(tr("Domain")); + caCertPathLabel->setText(tr("CA certficate")); + caNeedFlagLabel->setText(tr("no need for CA certificate")); + clientCertPathLabel->setText(tr("User certificate")); + clientPrivateKeyLabel->setText(tr("User private key")); + clientPrivateKeyPwdLabel->setText(tr("User key password")); + + //PEAP TTLS共有 + eapMethodLabel->setText(tr("Ineer authentication")); + userNameLabel->setText(tr("Usename")); + userPwdLabel->setText(tr("Password")); + userPwdFlagLabel->setText(tr("Ask pwd each query")); + + secuTypeCombox->addItem(tr("None"),NONE); + secuTypeCombox->addItem(tr("WPA&WPA2 Personal"),WPA_AND_WPA2_PERSONAL); + secuTypeCombox->addItem(tr("WPA&WPA2 Enterprise"), WPA_AND_WPA2_ENTERPRISE); + secuTypeCombox->addItem(tr("WPA3 Personal"), WPA3_PERSONAL); + + eapTypeCombox->addItem("TLS", TLS); + eapTypeCombox->addItem("PEAP", PEAP); + eapTypeCombox->addItem("TTLS", TTLS); + eapTypeCombox->setCurrentIndex(TLS); + //TLS + caCertPathCombox->addItem(tr("None"), QString(tr("None"))); //无 + caCertPathCombox->addItem(tr("Choose from file..."), QString(tr("Choose from file..."))); //从文件中选择... + + clientCertPathCombox->addItem(tr("None"), QString(tr("None"))); //无 + clientCertPathCombox->addItem(tr("Choose from file..."), QString(tr("Choose from file..."))); //从文件中选择... + + clientPrivateKeyCombox->addItem(tr("None"), QString(tr("None"))); //无 + clientPrivateKeyCombox->addItem(tr("Choose from file..."), QString(tr("Choose from file..."))); //从文件中选择... + + pwdBox = new QCheckBox(this); + pwdBox->setStyleSheet("QCheckBox::indicator {width: 18px; height: 9px;}" + "QCheckBox::indicator:checked {image: url(:/res/h/show-pwd.png);}" + "QCheckBox::indicator:unchecked {image: url(:/res/h/hide-pwd.png);}"); + pwdBox->setCursor(Qt::PointingHandCursor); + pwdBox->setFixedSize(30, pwdEdit->height()); + //防止文本框输入内容位于按钮之下 + QMargins margins = pwdEdit->textMargins(); + pwdEdit->setTextMargins(margins.left(), margins.top(), pwdBox->width(), margins.bottom()); + QHBoxLayout *pPwdLayout = new QHBoxLayout(); + pPwdLayout->addStretch(); + pPwdLayout->addWidget(pwdBox); + pPwdLayout->setSpacing(0); + pPwdLayout->setContentsMargins(0, 0, 0, 0); + pwdEdit->setLayout(pPwdLayout); + pwdEdit->setEchoMode(QLineEdit::Password); + + userPwdBox = new QCheckBox(this); + userPwdBox->setStyleSheet("QCheckBox::indicator {width: 18px; height: 9px;}" + "QCheckBox::indicator:checked {image: url(:/res/h/show-pwd.png);}" + "QCheckBox::indicator:unchecked {image: url(:/res/h/hide-pwd.png);}"); + userPwdBox->setCursor(Qt::PointingHandCursor); + userPwdBox->setFixedSize(30, userPwdEdit->height()); + //防止文本框输入内容位于按钮之下 + userPwdEdit->setTextMargins(margins.left(), margins.top(), userPwdBox->width(), margins.bottom()); + QHBoxLayout *puserPwdLayout = new QHBoxLayout(); + puserPwdLayout->addStretch(); + puserPwdLayout->addWidget(userPwdBox); + puserPwdLayout->setSpacing(0); + puserPwdLayout->setContentsMargins(0, 0, 0, 0); + userPwdEdit->setLayout(puserPwdLayout); + userPwdEdit->setEchoMode(QLineEdit::Password); + + privateKeyBox = new QCheckBox(this); + privateKeyBox->setStyleSheet("QCheckBox::indicator {width: 18px; height: 9px;}" + "QCheckBox::indicator:checked {image: url(:/res/h/show-pwd.png);}" + "QCheckBox::indicator:unchecked {image: url(:/res/h/hide-pwd.png);}"); + privateKeyBox->setCursor(Qt::PointingHandCursor); + privateKeyBox->setFixedSize(30, clientPrivateKeyPwdEdit->height()); + //防止文本框输入内容位于按钮之下 + clientPrivateKeyPwdEdit->setTextMargins(margins.left(), margins.top(), privateKeyBox->width(), margins.bottom()); + QHBoxLayout *pPrivateKeyPwdLayout = new QHBoxLayout(); + pPrivateKeyPwdLayout->addStretch(); + pPrivateKeyPwdLayout->addWidget(privateKeyBox); + pPrivateKeyPwdLayout->setSpacing(0); + pPrivateKeyPwdLayout->setContentsMargins(0, 0, 0, 0); + clientPrivateKeyPwdEdit->setLayout(pPrivateKeyPwdLayout); + clientPrivateKeyPwdEdit->setEchoMode(QLineEdit::Password); + + showNone(); +} + +void SecurityPage::initConnect() +{ + //安全类型变化 + connect(secuTypeCombox, &QComboBox::currentTextChanged, this, &SecurityPage::onSecuTypeComboxIndexChanged); + //EAP方式变化 + connect(eapTypeCombox, &QComboBox::currentTextChanged, this, &SecurityPage::onEapTypeComboxIndexChanged); + + connect(caNeedBox, &QCheckBox::clicked, this, [&](){ + if (caNeedBox->isChecked()) { + caCertPathCombox->setEnabled(false); + } else { + caCertPathCombox->setEnabled(true); + } + }); + + connect(pwdBox, &QCheckBox::clicked, this, [&]() { + if (pwdEdit->echoMode() == QLineEdit::Password) { + pwdBox->setChecked(true); + pwdEdit->setEchoMode(QLineEdit::Normal); + } else { + pwdBox->setChecked(false); + pwdEdit->setEchoMode(QLineEdit::Password); + } + + }); + + connect(userPwdBox, &QCheckBox::clicked, this, [&]() { + if (userPwdEdit->echoMode() == QLineEdit::Password) { + userPwdBox->setChecked(true); + userPwdEdit->setEchoMode(QLineEdit::Normal); + } else { + userPwdBox->setChecked(false); + userPwdEdit->setEchoMode(QLineEdit::Password); + } + + }); + + connect(privateKeyBox, &QCheckBox::clicked, this, [&]() { + if (clientPrivateKeyPwdEdit->echoMode() == QLineEdit::Password) { + privateKeyBox->setChecked(true); + clientPrivateKeyPwdEdit->setEchoMode(QLineEdit::Normal); + } else { + privateKeyBox->setChecked(false); + clientPrivateKeyPwdEdit->setEchoMode(QLineEdit::Password); + } + + }); + + connect(caCertPathCombox, static_cast(&QComboBox::currentIndexChanged), this, [=] (const QString &str) { + if (str.contains("Choose from file...") || str.contains("从文件选择...")) + { + QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a CA certificate"), "recent:///", + tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); + if (!fileName.isNull()) { + QStringList nameList = fileName.split("/"); + caCertPathCombox->blockSignals(true); + caCertPathCombox->setItemText(0, fileName); + caCertPathCombox->setCurrentIndex(0); + caCertPathCombox->blockSignals(false); + } else { + caCertPathCombox->blockSignals(true); + caCertPathCombox->setItemText(0, tr("None")); + caCertPathCombox->setCurrentIndex(0); + caCertPathCombox->blockSignals(false); + } + } else { + qWarning() << "Choose file is null or unvalible"; + } + }); + + connect(clientCertPathCombox, static_cast(&QComboBox::currentIndexChanged), this, [=] (const QString &str) { + if (str.contains("Choose from file...") || str.contains("从文件选择...")) + { + QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a CA certificate"), "recent:///", + tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); + if (!fileName.isNull()) { +// QStringList nameList = fileName.split("/"); + clientCertPathCombox->blockSignals(true); + clientCertPathCombox->setItemText(0, fileName); + clientCertPathCombox->setCurrentIndex(0); + clientCertPathCombox->blockSignals(false); + } else { + clientCertPathCombox->blockSignals(true); + clientCertPathCombox->setItemText(0, tr("None")); + clientCertPathCombox->setCurrentIndex(0); + clientCertPathCombox->blockSignals(false); + } + } else { + qWarning() << "Choose file is null or unvalible"; + } + }); + + connect(clientPrivateKeyCombox, static_cast(&QComboBox::currentIndexChanged), this, [=] (const QString &str) { + if (str.contains("Choose from file...") || str.contains("从文件选择...")) + { + QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a CA certificate"), "recent:///", + tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); + if (!fileName.isNull()) { + QStringList nameList = fileName.split("/"); + clientPrivateKeyCombox->blockSignals(true); + clientPrivateKeyCombox->setItemText(0, fileName); + clientPrivateKeyCombox->setCurrentIndex(0); + clientPrivateKeyCombox->blockSignals(false); + } else { + clientPrivateKeyCombox->blockSignals(true); + clientPrivateKeyCombox->setItemText(0, tr("None")); + clientPrivateKeyCombox->setCurrentIndex(0); + clientPrivateKeyCombox->blockSignals(false); + } + } else { + qWarning() << "Choose file is null or unvalible"; + } + }); + + connect(secuTypeCombox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(pwdEdit, &QLineEdit::textChanged, this, &SecurityPage::setEnableOfSaveBtn); + connect(eapTypeCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfSaveBtn())); + connect(identityEdit, &QLineEdit::textChanged, this, &SecurityPage::setEnableOfSaveBtn); + connect(caCertPathCombox, SIGNAL(currentTextChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(caNeedBox, &QCheckBox::stateChanged, this, &SecurityPage::setEnableOfSaveBtn); + connect(clientCertPathCombox, SIGNAL(currentTextChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(clientPrivateKeyCombox, SIGNAL(currentTextChanged(QString)), this, SLOT(setEnableOfSaveBtn())); + connect(clientPrivateKeyPwdEdit, &QLineEdit::textChanged, this, &SecurityPage::setEnableOfSaveBtn); + connect(eapMethodCombox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnableOfSaveBtn())); + connect(userNameEdit, &QLineEdit::textChanged, this, &SecurityPage::setEnableOfSaveBtn); + connect(userPwdEdit, &QLineEdit::textChanged, this, &SecurityPage::setEnableOfSaveBtn); } + +void SecurityPage::setSecurity(KySecuType index) +{ + secuTypeCombox->setCurrentIndex(index); + onSecuTypeComboxIndexChanged(); +} + +void SecurityPage::setPsk(const QString &psk) +{ + pwdEdit->setText(psk); +} + +void SecurityPage::setTlsInfo(KyEapMethodTlsInfo &info) +{ + showTls(); + identityEdit->setText(info.identity); + domainEdit->setText(info.domain); + if (info.caCertPath.isEmpty()) { + caCertPathCombox->setItemText(0, ""); + caNeedBox->setChecked(true); + } else { + caCertPathCombox->setItemText(0, info.caCertPath); + caNeedBox->setChecked(false); + } + + if (info.clientCertPath.isEmpty()) { + clientCertPathCombox->setItemText(0, ""); + } else { + clientCertPathCombox->setItemText(0, info.clientCertPath); + } + + if (info.clientPrivateKey.isEmpty()) { + clientPrivateKeyCombox->setItemText(0, ""); + } else { + clientPrivateKeyCombox->setItemText(0, info.clientPrivateKey); + } + + clientPrivateKeyPwdEdit->setText(info.clientPrivateKeyPWD); + +} + +void SecurityPage::setPeapInfo(KyEapMethodPeapInfo &info) +{ + showPeapOrTtls(); + eapTypeCombox->setCurrentIndex(PEAP); + onEapTypeComboxIndexChanged(); + eapMethodCombox->setCurrentIndex(info.phase2AuthMethod); + userNameEdit->setText(info.userName); + userPwdEdit->setText(info.userPWD); + if (info.m_passwdFlag & NetworkManager::Setting::NotSaved) { + userPwdFlagBox->setChecked(true); + } else { + userPwdFlagBox->setChecked(false); + } +} + +void SecurityPage::setTtlsInfo(KyEapMethodTtlsInfo &info) +{ + showPeapOrTtls(); + eapTypeCombox->setCurrentIndex(TTLS); + onEapTypeComboxIndexChanged(); + + if (info.authType == AUTH_EAP) { + if (info.authEapMethod = KyAuthEapMethodMschapv2) { + eapMethodCombox->setCurrentIndex(MSCHAPV2_EAP); + } else if (info.authEapMethod = KyAuthEapMethodMd5) { + eapMethodCombox->setCurrentIndex(MD5_EAP); + } else if (info.authEapMethod = KyAuthEapMethodMd5) { + eapMethodCombox->setCurrentIndex(MD5_EAP); + } else { + qDebug() << "not support yet. AUTH_EAP method" << info.authEapMethod; + } + } else { + if (info.authNoEapMethod == KyAuthMethodPap) { + eapMethodCombox->setCurrentIndex(PAP); + } else if (info.authNoEapMethod == KyAuthMethodMschap) { + eapMethodCombox->setCurrentIndex(MSCHAP); + } else if (info.authNoEapMethod == KyAuthMethodMschapv2) { + eapMethodCombox->setCurrentIndex(MSCHAPV2); + } else if (info.authNoEapMethod == KyAuthMethodChap) { + eapMethodCombox->setCurrentIndex(CHAP); + } else { + qDebug() << "not support yet. AUTH_NO_EAP method" << info.authNoEapMethod; + } + } + userNameEdit->setText(info.userName); + userPwdEdit->setText(info.userPWD); + if (info.m_passwdFlag & NetworkManager::Setting::NotSaved) { + userPwdFlagBox->setChecked(true); + } else { + userPwdFlagBox->setChecked(false); + } +} + +void SecurityPage::updateTlsChange(KyEapMethodTlsInfo &info) +{ + KyEapMethodTlsInfo tlsInfo = assembleTlsInfo(); +// if (tlsInfo.clientPrivateKeyPWD != info.clientPrivateKeyPWD) { + tlsInfo.bChanged = true; +// } + tlsInfo.devIfaceName = info.devIfaceName; + info = tlsInfo; +} + +void SecurityPage::updatePeapChange(KyEapMethodPeapInfo &info) +{ + KyEapMethodPeapInfo peapInfo = assemblePeapInfo(); +// if (peapInfo.userPWD != info.userPWD) { + peapInfo.bChanged = true; +// } + info = peapInfo; +} + +void SecurityPage::updateTtlsChange(KyEapMethodTtlsInfo &info) +{ + KyEapMethodTtlsInfo ttlsInfo = assembleTtlsInfo(); +// if (ttlsInfo.userPWD != info.userPWD) { + ttlsInfo.bChanged = true; +// } + info = ttlsInfo; +} + +void SecurityPage::getSecuType(KySecuType &secuType, KyEapMethodType &enterpriseType) +{ + secuType = (KySecuType)secuTypeCombox->currentData().toInt(); + enterpriseType = (KyEapMethodType)eapTypeCombox->currentData().toInt(); +} + +bool SecurityPage::checkIsChanged(const ConInfo info) +{ + qDebug() << "SecurityPage checkIsChanged"; + if (info.secType != secuTypeCombox->currentData().toInt()) { + return true; + } else { + if (info.secType == NONE) { + return false; + } else if (info.secType == WPA_AND_WPA2_PERSONAL || info.secType == WPA3_PERSONAL) { + return !(info.strPassword == pwdEdit->text()); + } else { + if (info.enterpriseType != eapTypeCombox->currentData().toInt()) { + return true; + } else { + if (info.enterpriseType == TLS) { + return !(info.tlsInfo == assembleTlsInfo()); + } else if (info.enterpriseType == PEAP) { + return !(info.peapInfo == assemblePeapInfo()); + } else if (info.enterpriseType == TTLS) { + return !(info.ttlsInfo == assembleTtlsInfo()); + } + } + } + } +} + +void SecurityPage::showNone() +{ + pwdEdit->hide(); + eapTypeCombox->hide(); + + identityEdit->hide(); + domainEdit->hide(); + caCertPathCombox->hide(); + caNeedBox->hide(); + clientCertPathCombox->hide(); + clientPrivateKeyCombox->hide(); + clientPrivateKeyPwdEdit->hide(); + + eapMethodCombox->hide(); + userNameEdit->hide(); + userPwdEdit->hide(); + userPwdFlagBox->hide(); + + pwdLabel->hide(); + //企业wifi共有 + eapTypeLabel->hide(); + //TLS + identityLable->hide(); + domainLable->hide(); + caCertPathLabel->hide(); + caNeedFlagLabel->hide(); + clientCertPathLabel->hide(); + clientPrivateKeyLabel->hide(); + clientPrivateKeyPwdLabel->hide(); + + //PEAP TTLS共有 + eapMethodLabel->hide(); + userNameLabel->hide(); + userPwdLabel->hide(); + userPwdFlagLabel->hide(); +} + +void SecurityPage::showPsk() +{ + pwdEdit->show(); + eapTypeCombox->hide(); + + identityEdit->hide(); + domainEdit->hide(); + caCertPathCombox->hide(); + caNeedBox->hide(); + clientCertPathCombox->hide(); + clientPrivateKeyCombox->hide(); + clientPrivateKeyPwdEdit->hide(); + + eapMethodCombox->hide(); + userNameEdit->hide(); + userPwdEdit->hide(); + userPwdFlagBox->hide(); + + pwdLabel->show(); + //企业wifi共有 + eapTypeLabel->hide(); + //TLS + identityLable->hide(); + domainLable->hide(); + caCertPathLabel->hide(); + caNeedFlagLabel->hide(); + clientCertPathLabel->hide(); + clientPrivateKeyLabel->hide(); + clientPrivateKeyPwdLabel->hide(); + + //PEAP TTLS共有 + eapMethodLabel->hide(); + userNameLabel->hide(); + userPwdLabel->hide(); + userPwdFlagLabel->hide(); +} + +void SecurityPage::showTls() +{ + pwdEdit->hide(); + eapTypeCombox->show(); + + identityEdit->show(); + domainEdit->show(); + caCertPathCombox->show(); + caNeedBox->show(); + clientCertPathCombox->show(); + clientPrivateKeyCombox->show(); + clientPrivateKeyPwdEdit->show(); + + eapMethodCombox->hide(); + userNameEdit->hide(); + userPwdEdit->hide(); + userPwdFlagBox->hide(); + + pwdLabel->hide(); + //企业wifi共有 + eapTypeLabel->show(); + //TLS + identityLable->show(); + domainLable->show(); + caCertPathLabel->show(); + caNeedFlagLabel->show(); + clientCertPathLabel->show(); + clientPrivateKeyLabel->show(); + clientPrivateKeyPwdLabel->show(); + + //PEAP TTLS共有 + eapMethodLabel->hide(); + userNameLabel->hide(); + userPwdLabel->hide(); + userPwdFlagLabel->hide(); +} + +void SecurityPage::showPeapOrTtls() +{ + pwdEdit->hide(); + eapTypeCombox->show(); + + identityEdit->hide(); + domainEdit->hide(); + caCertPathCombox->hide(); + caNeedBox->hide(); + clientCertPathCombox->hide(); + clientPrivateKeyCombox->hide(); + clientPrivateKeyPwdEdit->hide(); + + eapMethodCombox->show(); + userNameEdit->show(); + userPwdEdit->show(); + userPwdFlagBox->show(); + + pwdLabel->hide(); + //企业wifi共有 + eapTypeLabel->show(); + //TLS + identityLable->hide(); + domainLable->hide(); + caCertPathLabel->hide(); + caNeedFlagLabel->hide(); + clientCertPathLabel->hide(); + clientPrivateKeyLabel->hide(); + clientPrivateKeyPwdLabel->hide(); + + //PEAP TTLS共有 + eapMethodLabel->show(); + userNameLabel->show(); + userPwdLabel->show(); + userPwdFlagLabel->show(); +} + +KyEapMethodTlsInfo SecurityPage::assembleTlsInfo() +{ + KyEapMethodTlsInfo info; + info.identity = identityEdit->text(); + info.domain = domainEdit->text(); + info.caCertPath = caCertPathCombox->currentText(); + info.bNeedCa = !caNeedBox->isChecked(); + info.clientCertPath = clientCertPathCombox->currentText(); + info.clientPrivateKey = clientPrivateKeyCombox->currentText(); + info.clientPrivateKeyPWD = clientPrivateKeyPwdEdit->text(); + info.m_privateKeyPWDFlag = (privateKeyBox->isChecked() ? NetworkManager::Setting::NotSaved : NetworkManager::Setting::None); + + return info; +} + +KyEapMethodPeapInfo SecurityPage::assemblePeapInfo() +{ + KyEapMethodPeapInfo info; + info.phase2AuthMethod = (KyNoEapMethodAuth)eapMethodCombox->currentData().toInt(); + info.userName = userNameEdit->text(); + info.userPWD = userPwdEdit->text(); + info.m_passwdFlag = (userPwdBox->isChecked() ? NetworkManager::Setting::NotSaved : NetworkManager::Setting::None); + + return info; +} +KyEapMethodTtlsInfo SecurityPage::assembleTtlsInfo() +{ + KyEapMethodTtlsInfo info; + if (eapMethodCombox->currentData().toInt() == PAP + || eapMethodCombox->currentData().toInt() == MSCHAP + || eapMethodCombox->currentData().toInt() == MSCHAPV2 + || eapMethodCombox->currentData().toInt() == CHAP) { + info.authType = AUTH_NO_EAP; + info.authEapMethod = (KyEapMethodAuth)eapMethodCombox->currentData().toInt(); + } else { + info.authType = AUTH_EAP; + info.authNoEapMethod = (KyNoEapMethodAuth)eapMethodCombox->currentData().toInt(); + } + info.userName = userNameEdit->text(); + info.userPWD = userPwdEdit->text(); + info.m_passwdFlag = (userPwdBox->isChecked() ? NetworkManager::Setting::NotSaved : NetworkManager::Setting::None); + return info; +} + +void SecurityPage::updateSecurityChange(KyWirelessConnectSetting &setting) +{ + qDebug() << "secuTypeCombox->currentData()" << secuTypeCombox->currentData().toInt() << pwdEdit->text(); + if (secuTypeCombox->currentData().toInt() == NONE) { + setting.m_psk = ""; + } else { + setting.m_psk = pwdEdit->text(); + } + + if (secuTypeCombox->currentData().toInt() == NONE) { + setting.m_type = WpaNone; + } else if (secuTypeCombox->currentData().toInt() == WPA_AND_WPA2_PERSONAL) { + setting.m_type = WpaPsk; + } else if (secuTypeCombox->currentData().toInt() == WPA3_PERSONAL) { + setting.m_type = SAE; + } +} + +bool SecurityPage::checkConnectBtnIsEnabled() +{ + int index = secuTypeCombox->currentData().toInt(); + if (index == NONE) { + + } else if (index == WPA_AND_WPA2_PERSONAL || index == WPA3_PERSONAL) { + if (pwdEdit->text().isEmpty() || pwdEdit->text().length() < 8 ) { + qDebug() << "password is empty or length < 8"; + return false; + } + } else if (index == WPA_AND_WPA2_ENTERPRISE) { + int type = eapTypeCombox->currentData().toInt(); + if (type == TLS) { + if (identityEdit->text().isEmpty()) { + qDebug() << "tls identity is empty"; + return false; + } + QFile cafile(caCertPathCombox->currentText()); + if(!caNeedBox->isChecked() && !cafile.exists()) { + qDebug() << "ca cert filepath " << caCertPathCombox->currentText() << " is invalid"; + return false; + } + + QFile cliCafile(clientCertPathCombox->currentText()); + if(!cliCafile.exists()) { + qDebug() << "client cert filepath " << clientCertPathCombox->currentText() << " is invalid"; + return false; + } + + QFile cliKeyfile(clientPrivateKeyCombox->currentText()); + if(!cliKeyfile.exists()) { + qDebug() << "client private key filepath " << clientPrivateKeyCombox->currentText() << " is invalid"; + return false; + } + + if(clientPrivateKeyPwdEdit->text().isEmpty()) { + qDebug() << "client Private Key password is empty"; + return false; + } + } else if (type == PEAP || type == TTLS) { + if(userNameEdit->text().isEmpty() || userPwdEdit->text().isEmpty()) { + qDebug() << "user name or user password is empty"; + return false; + } + } + } + return true; +} + +void SecurityPage::setEnableOfSaveBtn() +{ + emit setSecuPageState(checkConnectBtnIsEnabled()); +} + +void SecurityPage::onSecuTypeComboxIndexChanged() +{ + int index = secuTypeCombox->currentData().toInt(); + qDebug() << "onSecuTypeComboxIndexChanged" << index; + if (index == WPA_AND_WPA2_PERSONAL || index == WPA3_PERSONAL) { + showPsk(); + } else if (index == WPA_AND_WPA2_ENTERPRISE) { + onEapTypeComboxIndexChanged(); + } else if (index == NONE) { + showNone(); + } +} + +void SecurityPage::onEapTypeComboxIndexChanged() +{ + int index = eapTypeCombox->currentData().toInt(); + if (index == TLS) { + showTls(); + } else if (index == PEAP) { + showPeapOrTtls(); + eapMethodCombox->clear(); + eapMethodCombox->addItem("MSCHAPv2", KyAuthMethodMschapv2); + eapMethodCombox->addItem("MD5", KyAuthMethodMd5); + eapMethodCombox->addItem("GTC", KyAuthMethodGtc); + } else if (index == TTLS) { + showPeapOrTtls(); + eapMethodCombox->clear(); + eapMethodCombox->addItem("pap", PAP); + eapMethodCombox->addItem("mschap", MSCHAP); + eapMethodCombox->addItem("mschapv2(eap)", MSCHAPV2_EAP); + eapMethodCombox->addItem("mschapv2", MSCHAPV2); + eapMethodCombox->addItem("chap", CHAP); + eapMethodCombox->addItem("md5(eap)", MD5_EAP); + eapMethodCombox->addItem("gtc(eap)", GTC_EAP); + } +} diff --git a/src/frontend/netdetails/securitypage.h b/src/frontend/netdetails/securitypage.h index 2789341c..153c04c2 100644 --- a/src/frontend/netdetails/securitypage.h +++ b/src/frontend/netdetails/securitypage.h @@ -6,17 +6,98 @@ #include #include #include +#include + +#include "coninfo.h" + class SecurityPage : public QFrame { + Q_OBJECT public: SecurityPage(QWidget *parent = nullptr); -private: - QFormLayout *mDetailLayout; + + void setSecurity(KySecuType index); + void setPsk(const QString &psk); + void setTlsInfo(KyEapMethodTlsInfo &info); + void setPeapInfo(KyEapMethodPeapInfo &info); + void setTtlsInfo(KyEapMethodTtlsInfo &info); + + bool checkIsChanged(const ConInfo info); + void updateSecurityChange(KyWirelessConnectSetting &setting); + void updateTlsChange(KyEapMethodTlsInfo &info); + void updatePeapChange(KyEapMethodPeapInfo &info); + void updateTtlsChange(KyEapMethodTtlsInfo &info); + + void getSecuType(KySecuType &secuType, KyEapMethodType &enterpriseType); private: + QFormLayout *mSecuLayout; + +private: + + QLabel *secuTypeLabel; + QLabel *pwdLabel; + //企业wifi共有 + QLabel *eapTypeLabel; + //TLS + QLabel *identityLable; + QLabel *domainLable; + QLabel *caCertPathLabel; + QLabel *caNeedFlagLabel; + QLabel *clientCertPathLabel; + QLabel *clientPrivateKeyLabel; + QLabel *clientPrivateKeyPwdLabel; + + //PEAP TTLS共有 + QLabel *eapMethodLabel; + QLabel *userNameLabel; + QLabel *userPwdLabel; + QLabel *userPwdFlagLabel; + + QComboBox *secuTypeCombox; + QLineEdit *pwdEdit; + QComboBox *eapTypeCombox; + //TLS + QLineEdit *identityEdit; + QLineEdit *domainEdit; + QComboBox *caCertPathCombox; + QCheckBox *caNeedBox; + QComboBox *clientCertPathCombox; + QComboBox *clientPrivateKeyCombox; + QLineEdit *clientPrivateKeyPwdEdit; + + //PEAP && TTLS + QComboBox *eapMethodCombox; + QLineEdit *userNameEdit; + QLineEdit *userPwdEdit; + QCheckBox *userPwdFlagBox; + + QCheckBox *pwdBox; + QCheckBox *userPwdBox; + QCheckBox *privateKeyBox; + + void showNone(); + void showPsk(); + void showTls(); + void showPeapOrTtls(); void initUI(); + void initConnect(); + KyEapMethodTlsInfo assembleTlsInfo(); + KyEapMethodPeapInfo assemblePeapInfo(); + KyEapMethodTtlsInfo assembleTtlsInfo(); + + bool checkConnectBtnIsEnabled(); + + +private slots: + void onSecuTypeComboxIndexChanged(); + void onEapTypeComboxIndexChanged(); + void setEnableOfSaveBtn(); + +signals: + void setSecuPageState(bool); }; #endif // SECURITYWIDGET_H diff --git a/src/frontend/new-mainwindow.cpp b/src/frontend/new-mainwindow.cpp index 81d003b2..137af403 100644 --- a/src/frontend/new-mainwindow.cpp +++ b/src/frontend/new-mainwindow.cpp @@ -7,6 +7,8 @@ #include #include +#include "kylinnetworkdeviceresource.h" + #define MAINWINDOW_WIDTH 420 #define MAINWINDOW_HEIGHT 456 #define THEME_SCHAME "org.ukui.style" @@ -397,6 +399,46 @@ void MainWindow::getStoredApInfo(QStringList &list) m_wlanWidget->getStoredApInfo(list); } + +void MainWindow::setWiredDeviceEnable(const QString& devName, bool enable) +{ + m_lanWidget->setWiredDeviceEnable(devName, enable); +} +void MainWindow::showPropertyWidget(QString devName, QString ssid) +{ + KyNetworkDeviceResourse *devResourse = new KyNetworkDeviceResourse(); + QStringList wiredDeviceList; + wiredDeviceList.clear(); + devResourse->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, wiredDeviceList); + if (wiredDeviceList.contains(devName)) { + qDebug() << "showPropertyWidget device type wired device name " << devName << " uuid " << ssid; + m_lanWidget->showDetailPage(devName, ssid); + delete devResourse; + devResourse = nullptr; + return; + } + + QStringList wirelessDeviceList; + wirelessDeviceList.clear(); + devResourse->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, wirelessDeviceList); + if (wirelessDeviceList.contains(devName)) { + qDebug() << "showPropertyWidget device type wireless device name " << devName << " ssid " << ssid; + m_wlanWidget->showDetailPage(devName, ssid); + delete devResourse; + devResourse = nullptr; + return; + } + + qDebug() << "showPropertyWidget no such device " << devName; +} + +void MainWindow::showCreateWiredConnectWidget(const QString devName) +{ + qDebug() << "showCreateWiredConnectWidget! devName = " << devName; + NetDetail *netDetail = new NetDetail(devName, "", "", false, false, true, this); + netDetail->show(); +} + //有线连接断开 void MainWindow::activateWired(const QString& devName, const QString& connName) { diff --git a/src/frontend/new-mainwindow.h b/src/frontend/new-mainwindow.h index b052bee4..671972ad 100644 --- a/src/frontend/new-mainwindow.h +++ b/src/frontend/new-mainwindow.h @@ -11,6 +11,7 @@ #include #include "lanpage.h" #include "wlanpage.h" +#include "netdetails/netdetail.h" class MainWindow : public QMainWindow { @@ -39,6 +40,13 @@ public: void activateWireless(const QString& devName, const QString& ssid); void deactivateWireless(const QString& devName, const QString& ssid); + void setWiredDeviceEnable(const QString& devName, bool enable); + + //唤起属性页 根据网卡类型 参数2 为ssid/uuid + void showPropertyWidget(QString devName, QString ssid); + //唤起新建有线连接界面 + void showCreateWiredConnectWidget(const QString devName); + signals: //设备插拔 void deviceStatusChanged(); diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index f9fc6519..10211e47 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -15,7 +15,7 @@ #define ITEM_HEIGHT 48 const QString WIRED_SWITCH = "wiredswitch"; -const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.switch"; +//const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.switch"; LanPage::LanPage(QWidget *parent) : TabPage(parent) { @@ -407,6 +407,11 @@ void LanPage::getWiredList(QMap > &map) return; } +void LanPage::setWiredDeviceEnable(const QString& devName, bool enable) +{ + //todo: +} + void LanPage::activateWired(const QString& devName, const QString& connUuid) { //todo: @@ -416,3 +421,24 @@ void LanPage::deactivateWired(const QString& devName, const QString& connUuid) { //todo: } + +void LanPage::showDetailPage(QString devName, QString uuid) +{ + KyConnectItem *item = nullptr; + bool isActive = true; + item = m_activeResourse->getActiveConnectionByUuid(uuid, devName); + if (nullptr == item) { + item = m_connectResourse->getConnectionItemByUuid(uuid, devName); + isActive= false; + } + + if (nullptr == item) { + qDebug()<<"[LanPage] GetConnectionItemByUuid is empty when showDetailPage"; + return; + } + + NetDetail *netDetail = new NetDetail(devName, item->m_connectName, uuid, isActive, false, false, this); + netDetail->show(); + delete item; + item = nullptr; +} diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index 933e250c..f8692672 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -26,7 +26,8 @@ public: void getWiredList(QMap > &map); void activateWired(const QString& devName, const QString& connUuid); void deactivateWired(const QString& devName, const QString& connUuid); - + void showDetailPage(QString devName, QString uuid); + void setWiredDeviceEnable(const QString& devName, bool enable); signals: void wiredActivating(QString devName, QString ssid); diff --git a/src/frontend/tab-pages/tabpage.cpp b/src/frontend/tab-pages/tabpage.cpp index efb7304a..eb08515a 100644 --- a/src/frontend/tab-pages/tabpage.cpp +++ b/src/frontend/tab-pages/tabpage.cpp @@ -148,3 +148,60 @@ bool checkDeviceExist(KyDeviceType deviceType, QString deviceName) delete kdr; return devList.contains(deviceName); } + +void saveDeviceEnableState(QString deviceName, bool enable) +{ + QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); + m_settings->beginGroup("CARDEABLE"); + m_settings->setValue(deviceName, enable); + m_settings->endGroup(); + m_settings->sync(); + delete m_settings; + m_settings = nullptr; + return; +} + +void getDeviceEnableState(int type, QMap &map) +{ + map.clear(); + if (!QFile::exists(CONFIG_FILE_PATH)) { + return; + } + if (type != WIRED && type != WIRELESS) { + qDebug() << "getDeviceEnableState but wrong type"; + return; + } + + KyNetworkDeviceResourse * kdr = new KyNetworkDeviceResourse(); + QStringList wiredDevList,wirelessDevList; + wiredDevList.clear(); + wirelessDevList.clear(); + + QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); + m_settings->beginGroup("CARDEABLE"); + + if (type == WIRED) { + kdr->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, wiredDevList); + if (!wiredDevList.isEmpty()) { + for (int i = 0; i < wiredDevList.size(); ++i) { + bool enable = m_settings->value(wiredDevList.at(i), true).toBool(); + map.insert(wiredDevList.at(i), enable); + } + } + } else if (type == WIRELESS) { + kdr->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, wirelessDevList); + if (!wirelessDevList.isEmpty()) { + for (int i = 0; i < wirelessDevList.size(); ++i) { + bool enable = m_settings->value(wirelessDevList.at(i), true).toBool(); + map.insert(wirelessDevList.at(i), enable); + } + } + } + + m_settings->endGroup(); + delete m_settings; + m_settings = nullptr; + delete kdr; + kdr = nullptr; + return; +} diff --git a/src/frontend/tab-pages/tabpage.h b/src/frontend/tab-pages/tabpage.h index f4a06d1f..1cee2a08 100644 --- a/src/frontend/tab-pages/tabpage.h +++ b/src/frontend/tab-pages/tabpage.h @@ -38,6 +38,8 @@ enum KyDeviceType const QString CONFIG_FILE_PATH = QDir::homePath() + "/.config/ukui/kylin-nm.conf"; bool checkDeviceExist(KyDeviceType deviceType, QString deviceName); void setDefaultDevice(KyDeviceType deviceType, QString deviceName); +void saveDeviceEnableState(QString deviceName, bool enable); +void getDeviceEnableState(int type, QMap &map); class TabPage : public QWidget { diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 17a85d49..71fe23d4 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -112,6 +112,8 @@ void WlanPage::initConnections() m_netSwitch->setSwitchStatus(m_switchGsettings->get(WIRELESS_SWITCH).toBool()); connect(m_switchGsettings, &QGSettings::changed, this, [ = ](const QString &key) { if (key == WIRELESS_SWITCH) { + bool status = m_switchGsettings->get(WIRELESS_SWITCH).toBool(); + m_wirelessConnectOpreation->setWirelessEnabled(status); onWlanSwitchStatusChanged(m_switchGsettings->get(WIRELESS_SWITCH).toBool()); } }); @@ -159,14 +161,21 @@ void WlanPage::initDevice() void WlanPage::initDeviceCombox() { //TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框 + disconnect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &WlanPage::onDeviceComboxIndexChanged); if (m_devList.length() <= 1) { m_deviceFrame->hide(); } else { m_deviceFrame->show(); foreach (QString device, m_devList) { + //空时addItem 会触发currentIndexChanged m_deviceComboBox->addItem(device, device); } + int index = m_deviceComboBox->findData(defaultDevice); + qDebug() << index; + m_deviceComboBox->setCurrentIndex(index); } + connect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &WlanPage::onDeviceComboxIndexChanged); + } /** @@ -251,6 +260,7 @@ void WlanPage::getAllWlan() KyWirelessNetItem *data = new KyWirelessNetItem(itemData); WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, defaultDevice); QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget); + qDebug() << itemData.m_NetSsid << itemData.m_isConfigured; connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); connect(wlanItemWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked); m_itemsMap.insert(data->m_NetSsid, wlanItem); @@ -635,3 +645,22 @@ void WlanPage::onMainWindowVisibleChanged(const bool &visible) m_scanTimer->stop(); } } +void WlanPage::showDetailPage(QString devName, QString ssid) +{ + KyWirelessNetItem data; + if (!m_resource->getWifiNetwork(devName, ssid, data)) { + qDebug()<<"[WlanPage] " << ssid << " is missing when showDetailPage"; + return; + } + + QMap actMap; + m_resource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap); + if (!actMap.contains(devName)) { + qDebug()<<"[WlanPage] " << devName << " is missing when showDetailPage"; + return; + } + + bool isActive = actMap[devName].contains(ssid); + NetDetail *netDetail = new NetDetail(devName, ssid, data.m_connectUuid, isActive, true, false, this); + netDetail->show(); +} diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index 4339f27c..cb95ce02 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -31,6 +31,7 @@ public: void activateWireless(const QString& devName, const QString& ssid); void deactivateWireless(const QString& devName, const QString& ssid); + void showDetailPage(QString devName, QString uuid); signals: void oneItemExpanded(const QString &ssid); void wirelessActivating(QString devName, QString ssid); From 325f9dd634129973988bf95365920416e858c973 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Mon, 13 Sep 2021 15:56:15 +0800 Subject: [PATCH 2/9] netdetail connect method --- src/backend/dbusadaptor.h | 5 +++ src/frontend/netdetails/netdetail.cpp | 39 +++++++++++++++++----- src/frontend/new-mainwindow.cpp | 2 ++ src/frontend/new-mainwindow.h | 4 +++ src/frontend/tab-pages/lanpage.cpp | 47 +++++++++++++++++++++++---- src/frontend/tab-pages/wlanpage.cpp | 14 ++++++-- src/frontend/tab-pages/wlanpage.h | 2 ++ 7 files changed, 97 insertions(+), 16 deletions(-) diff --git a/src/backend/dbusadaptor.h b/src/backend/dbusadaptor.h index f15d6a26..0b35e6c0 100644 --- a/src/backend/dbusadaptor.h +++ b/src/backend/dbusadaptor.h @@ -92,6 +92,11 @@ Q_SIGNALS: // SIGNALS void hotspotDeactivated(QString devName, QString ssid); //热点连接 void hotspotActivated(QString devName, QString ssid); + + //信号强度变化 + void signalStrengthChange(QString devName, QString ssid, int strength); + //安全性变化 + void secuTypeChange(QString devName, QString ssid, QString secuType); }; #endif diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index f5e61946..b2188fcd 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -183,6 +183,9 @@ void NetDetail::loadPage() securityBtn->hide(); } else { securityBtn->show(); + if (m_name.isEmpty()) { + titleLabel->setText(tr("connect hiddin wlan")); + } } } } @@ -700,23 +703,43 @@ bool NetDetail::createWirelessConnect() if (secuType == WPA_AND_WPA2_ENTERPRISE) { connetSetting.m_type = SAE; if (enterpriseType == TLS) { - qDebug() << "add new TLS connect"; m_info.tlsInfo.devIfaceName = m_deviceName; securityPage->updateTlsChange(m_info.tlsInfo); - m_wirelessConnOpration->addTlsConnect(connetSetting, m_info.tlsInfo); + if (!m_name.isEmpty()) { + qDebug() << "add new TLS connect"; + m_wirelessConnOpration->addTlsConnect(connetSetting, m_info.tlsInfo); + } else { + qDebug() << "addAndConnect TLS connect"; + m_wirelessConnOpration->addAndActiveWirelessEnterPriseTlsConnect(m_info.tlsInfo, connetSetting, m_deviceName, true); + } } else if (enterpriseType == PEAP) { - qDebug() << "add new PEAP connect"; securityPage->updatePeapChange(m_info.peapInfo); - m_wirelessConnOpration->addPeapConnect(connetSetting, m_info.peapInfo); + if (!m_name.isEmpty()) { + qDebug() << "add new PEAP connect"; + m_wirelessConnOpration->addPeapConnect(connetSetting, m_info.peapInfo); + } else { + qDebug() << "addAndConnect PEAP connect"; + m_wirelessConnOpration->addAndActiveWirelessEnterPrisePeapConnect(m_info.peapInfo, connetSetting, m_deviceName, true); + } } else if (enterpriseType == TTLS) { - qDebug() << "add new TTLS connect"; securityPage->updateTtlsChange(m_info.ttlsInfo); - m_wirelessConnOpration->addTtlsConnect(connetSetting, m_info.ttlsInfo); + if (!m_name.isEmpty()) { + qDebug() << "add new TTLS connect"; + m_wirelessConnOpration->addTtlsConnect(connetSetting, m_info.ttlsInfo); + } else { + qDebug() << "addAndConnect TTLS connect"; + m_wirelessConnOpration->addAndActiveWirelessEnterPriseTtlsConnect(m_info.ttlsInfo, connetSetting, m_deviceName, true); + } } } else { - qDebug() << "add new personal connect"; securityPage->updateSecurityChange(connetSetting); - m_wirelessConnOpration->addConnect(connetSetting); + if (!m_name.isEmpty()) { + qDebug() << "add new personal connect"; + m_wirelessConnOpration->addConnect(connetSetting); + } else { + qDebug() << "addAndConnect personal connect"; + m_wirelessConnOpration->addAndActiveWirelessConnect(m_deviceName, connetSetting, true); + } } return true; } diff --git a/src/frontend/new-mainwindow.cpp b/src/frontend/new-mainwindow.cpp index 137af403..2b38e747 100644 --- a/src/frontend/new-mainwindow.cpp +++ b/src/frontend/new-mainwindow.cpp @@ -161,6 +161,8 @@ void MainWindow::initDbusConnnect() connect(m_wlanWidget, &WlanPage::hotspotDeactivated, this, &MainWindow::hotspotDeactivated); connect(m_wlanWidget, &WlanPage::hotspotActivated, this, &MainWindow::hotspotActivated); + connect(m_wlanWidget, &WlanPage::secuTypeChange, this, &MainWindow::secuTypeChange); + connect(m_wlanWidget, &WlanPage::signalStrengthChange, this, &MainWindow::signalStrengthChange); } /** diff --git a/src/frontend/new-mainwindow.h b/src/frontend/new-mainwindow.h index 671972ad..5bc46255 100644 --- a/src/frontend/new-mainwindow.h +++ b/src/frontend/new-mainwindow.h @@ -62,6 +62,10 @@ signals: //热点断开 void hotspotDeactivated(QString devName, QString ssid); void hotspotActivated(QString devName, QString ssid); + //信号强度变化 + void signalStrengthChange(QString devName, QString ssid, int strength); + //安全性变化 + void secuTypeChange(QString devName, QString ssid, QString secuType); void mainWindowVisibleChanged(const bool &visible); public slots: diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 898cd666..3b6605b1 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -19,6 +19,7 @@ const QString WIRED_SWITCH = "wiredswitch"; LanPage::LanPage(QWidget *parent) : TabPage(parent) { + //释放问题 m_activeResourse = new KyActiveConnectResourse; m_connectResourse = new KyConnectResourse; m_device = new KyNetworkDeviceResourse; @@ -41,6 +42,7 @@ 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(this, &LanPage::deviceStatusChanged, this, &LanPage::onDeviceChanged); } @@ -121,6 +123,7 @@ void LanPage::onLanSwitchClicked() void LanPage::removeConnectionSlot(QString path) //删除时后端会自动断开激活,将其从未激活列表中删除 { qDebug()<<"[LanPage] Removing a connection, path:"<removeItemWidget(iters.value()); delete(iters.value()); m_deactiveMap.erase(iters); - + isLan = true; //for dbus qDebug() << "[LanPage] because removeConnectionSlot " << item->m_ifaceName; emit listUpdate(item->m_ifaceName); @@ -140,10 +143,34 @@ void LanPage::removeConnectionSlot(QString path) //删除时后端会 break; } } + if (!isLan) { + //removeConnection不是当前设备的,可能是其他有线设备或无线设备,保险起见发送信号更新 + for (int index = 0; index < devList.size(); ++index) { + if (devList.at(index) == m_deviceName) { + continue; + } + emit listUpdate(devList.at(index)); + } + } } void LanPage::addConnectionSlot(QString uuid) //新增一个有线连接,将其加入到激活列表 { + QString devName; + NetworkManager::ConnectionSettings::ConnectionType type; + if(m_connectResourse->getInterfaceByUuid(devName, type, uuid)) { + if (type != NetworkManager::ConnectionSettings::ConnectionType::Wired) { + qDebug() << "[LanPage] addConnectionSlot but type is not Wired"; + return; + } + } else { + qDebug() << "[LanPage] addConnectionSlot but uuid is invalid"; + } + + //for dbus + qDebug() << "[LanPage] emit listUpdate because addConnection " << devName; + emit listUpdate(devName); + KyConnectItem * newItem = m_connectResourse->getConnectionItemByUuid(uuid, m_deviceName); if (newItem != nullptr) { if (newItem->m_itemType == NetworkManager::ConnectionSettings::ConnectionType::Wired) { @@ -151,9 +178,7 @@ void LanPage::addConnectionSlot(QString uuid) //新增一个有线 addNewItem(newItem, m_inactivatedLanListWidget); m_deactiveMap.insert(newItem, m_listWidgetItem); } - //for dbus - qDebug() << "[LanPage] because addConnectionSlot " << newItem->m_ifaceName; - emit listUpdate(newItem->m_ifaceName); + } else { qDebug()<<"[LanPage] GetConnectionItemByUuid is empty when add a new!"; } @@ -266,7 +291,7 @@ void LanPage::onDeviceNameUpdate(QString oldName, QString newName) if (devList.contains(oldName)) { devList.removeOne(oldName); devList.append(newName); - qDebug() << "LanPage emit deviceNameUpdate " << oldName << newName; + qDebug() << "[LanPage] emit deviceNameUpdate " << oldName << newName; emit deviceNameChanged(oldName, newName); } } @@ -363,8 +388,18 @@ void LanPage::initList(QString m_deviceName) //程序拉起,初始化显 void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason) { qDebug()<<"[LanPage] State change slot:"<getInterfaceByUuid(devName, type, uuid)) { + if (type != NetworkManager::ConnectionSettings::ConnectionType::Wired) { + qDebug() << "[LanPage] updateLanlist but type is not Wired"; + return; + } + } else { + qDebug() << "[LanPage] updateLanlist but uuid is invalid"; + } + if (state == NetworkManager::ActiveConnection::State::Activating) { qDebug() << "[LanPage] wiredActivating " << devName; emit wiredActivating(devName,uuid); diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index fb9dd73b..780fdd76 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -108,6 +108,9 @@ void WlanPage::initConnections() connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::onWlanRemoved); connect(m_resource, &KyWirelessNetResource::wifiNetworkAdd, this, &WlanPage::listUpdate); connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::listUpdate); + connect(m_resource, &KyWirelessNetResource::signalStrengthChange, this, &WlanPage::signalStrengthChange); + connect(m_resource, &KyWirelessNetResource::secuTypeChange, this, &WlanPage::secuTypeChange); + // connect(m_resource, &KyWirelessNetResource::wifiNetworkUpdate, this, &WlanPage::onWlanUpdated); connect(m_connectResource, &KyActiveConnectResourse::stateChangeReason, this, &WlanPage::onActivatedWlanChanged); // connect(m_connectoperation, &KyConnectOperation::activateConnectionError, this, &WlanPage::showDesktopNotify); @@ -288,8 +291,11 @@ void WlanPage::getAllWlan() void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item) { + emit listUpdate(interface); qDebug() << "A Wlan Added! interface = " << interface << "; ssid = " << item.m_NetSsid << Q_FUNC_INFO <<__LINE__; - + if (interface != defaultDevice) { + qDebug() << "wlan add interface not equal defaultdevice,ignore"; + } KyWirelessNetItem *data = new KyWirelessNetItem(item); WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, defaultDevice); connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); @@ -306,9 +312,13 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item) void WlanPage::onWlanRemoved(QString interface, QString ssid) { + emit listUpdate(interface); if (!m_itemsMap.contains(ssid)) { return; } if (m_expandedItem == m_itemsMap.value(ssid)) { m_expandedItem = nullptr; } qDebug() << "A Wlan Removed! interface = " << interface << "; ssid = " << ssid << Q_FUNC_INFO <<__LINE__; + if (interface != defaultDevice) { + qDebug() << "wlan remove interface not equal defaultdevice,ignore"; + } int height = m_inactivatedNetListWidget->itemWidget(m_itemsMap.value(ssid))->height(); m_inactivatedNetListWidget->takeItem(m_inactivatedNetListWidget->row(m_itemsMap.value(ssid))); m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() - height - NET_LIST_SPACING); @@ -541,7 +551,7 @@ void WlanPage::requestScan() void WlanPage::onHiddenWlanClicked() { qDebug() << "[wlanPage] AddHideWifi Clicked! " << Q_FUNC_INFO << __LINE__ ; - NetDetail *netDetail = new NetDetail("", "", false, true, false); + NetDetail *netDetail = new NetDetail(defaultDevice, "", "", false, true, true, this); netDetail->show(); } diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index e2b15271..0b37cead 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -39,6 +39,8 @@ signals: void wirelessActivating(QString devName, QString ssid); void hotspotDeactivated(QString devName, QString ssid); void hotspotActivated(QString devName, QString ssid); + void signalStrengthChange(QString devName, QString ssid, int strength); + void secuTypeChange(QString devName, QString ssid, QString secuType); void hiddenWlanClicked(); public slots: From 6d7e7219723a870b238fdcf1c17f012e8d4d35c6 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Tue, 14 Sep 2021 10:40:38 +0800 Subject: [PATCH 3/9] dbus - active && deactive --- src/frontend/new-mainwindow.cpp | 12 +++---- src/frontend/new-mainwindow.h | 4 +-- src/frontend/tab-pages/lanpage.cpp | 56 +++++++++++++++++++++-------- src/frontend/tab-pages/wlanpage.cpp | 37 ++++++++++++++++--- 4 files changed, 82 insertions(+), 27 deletions(-) diff --git a/src/frontend/new-mainwindow.cpp b/src/frontend/new-mainwindow.cpp index 2b38e747..1ea1d72e 100644 --- a/src/frontend/new-mainwindow.cpp +++ b/src/frontend/new-mainwindow.cpp @@ -442,23 +442,23 @@ void MainWindow::showCreateWiredConnectWidget(const QString devName) } //有线连接断开 -void MainWindow::activateWired(const QString& devName, const QString& connName) +void MainWindow::activateWired(const QString& devName, const QString& connUuid) { - + m_lanWidget->activateWired(devName, connUuid); } -void MainWindow::deactivateWired(const QString& devName, const QString& connName) +void MainWindow::deactivateWired(const QString& devName, const QString& connUuid) { - + m_lanWidget->deactivateWired(devName, connUuid); } //无线连接断开 void MainWindow::activateWireless(const QString& devName, const QString& ssid) { - + m_wlanWidget->activateWireless(devName, ssid); } void MainWindow::deactivateWireless(const QString& devName, const QString& ssid) { - + m_wlanWidget->deactivateWireless(devName, ssid); } diff --git a/src/frontend/new-mainwindow.h b/src/frontend/new-mainwindow.h index 5bc46255..fcf35509 100644 --- a/src/frontend/new-mainwindow.h +++ b/src/frontend/new-mainwindow.h @@ -34,8 +34,8 @@ public: //获取热点 void getStoredApInfo(QStringList &list); //有线连接断开 - void activateWired(const QString& devName, const QString& connName); - void deactivateWired(const QString& devName, const QString& connName); + void activateWired(const QString& devName, const QString& connUuid); + void deactivateWired(const QString& devName, const QString& connUuid); //无线连接断开 void activateWireless(const QString& devName, const QString& ssid); void deactivateWireless(const QString& devName, const QString& ssid); diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 3b6605b1..e09ed664 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -25,16 +25,15 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent) m_device = new KyNetworkDeviceResourse; devList.empty(); m_nullLanItem = new LanListItem(); - - initDevice(); initUI(); - initDeviceCombox(); if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); initNetSwitch(); - } else { + } else { qDebug()<<"[LanPage] org.ukui.kylin-nm.switch is not installed!"; - } + } + initDevice(); + initDeviceCombox(); initList(m_deviceName); connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist); connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &LanPage::addConnectionSlot); @@ -212,18 +211,32 @@ void LanPage::initDevice() void LanPage::initDeviceCombox() { //TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框 + QMap enableMap; + getDeviceEnableState(0,enableMap); m_deviceComboBox->clear(); m_deviceMap.clear(); getWiredList(m_deviceMap); -// if (m_deactiveMap.count() <= 1) { -// m_deviceFrame->hide(); -// } else{ - m_deviceFrame->show(); - QMap >::iterator iter; - for (iter = m_deviceMap.begin(); iter != m_deviceMap.constEnd(); ++iter) { + m_deviceFrame->show(); + QMap >::iterator iter; + for (iter = m_deviceMap.begin(); iter != m_deviceMap.constEnd(); ++iter) { + if (enableMap.contains(iter.key())) { + if (enableMap[iter.key()]) { + m_deviceComboBox->addItem(iter.key()); + } + } else { m_deviceComboBox->addItem(iter.key()); + 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(); } @@ -514,17 +527,30 @@ void LanPage::getWiredList(QMap > &map) void LanPage::setWiredDeviceEnable(const QString& devName, bool enable) { - //todo: + saveDeviceEnableState(devName, enable); + initDeviceCombox(); } void LanPage::activateWired(const QString& devName, const QString& connUuid) { - //todo: + qDebug() << "activateWired" << devName << connUuid; + KyWiredConnectOperation a; + a.activateConnection(connUuid, devName); } void LanPage::deactivateWired(const QString& devName, const QString& connUuid) { - //todo: + 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); } void LanPage::showDetailPage(QString devName, QString uuid) diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 780fdd76..94c34a20 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -140,7 +140,6 @@ void WlanPage::initTimer() { m_scanTimer = new QTimer(this); connect(m_scanTimer, &QTimer::timeout, this, &WlanPage::requestScan); -// m_scanTimer->start(10 * 1000); } /** @@ -648,12 +647,42 @@ void WlanPage::getStoredApInfo(QStringList &list) void WlanPage::activateWireless(const QString& devName, const QString& ssid) { - //todo + KyWirelessNetItem data; + if (!m_resource->getWifiNetwork(devName, ssid, data)) { + qDebug() << "no such wifi " << ssid << " in " << devName; + return; + } + + if (data.m_isConfigured) { + m_wirelessConnectOpreation->activeWirelessConnect(devName, data.m_connectUuid); + } else { + //todo: 显示界面输入密码 (无需密码的wifi?) + } } void WlanPage::deactivateWireless(const QString& devName, const QString& ssid) { - //todo + KyWirelessNetItem data; + if (!m_resource->getWifiNetwork(devName, ssid, data)) { + qDebug() << "no such wifi " << ssid << " in " << devName; + return; + } + + QMap actMap; + m_resource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap); + QMap::iterator iter = actMap.begin(); + if (!actMap.contains(devName)) { + qDebug() << "no such device" << devName; + return; + } + + if (!actMap[devName].contains(ssid)) { + qDebug() << "no such actived wifi" << ssid; + return; + } + + qDebug() << "deActivateWirelessConnection" << devName << ssid; + m_wirelessConnectOpreation->deActivateWirelessConnection(data.m_connName, data.m_connectUuid); } void WlanPage::onMainWindowVisibleChanged(const bool &visible) @@ -670,7 +699,7 @@ void WlanPage::onMainWindowVisibleChanged(const bool &visible) } //若页面打开,开始扫描倒计时,若关闭,停止扫描倒计时 if (visible) { - m_scanTimer->start(10 * 1000); + m_scanTimer->start(20 * 1000); } else { m_scanTimer->stop(); } From 84429a703bf617ff1eab86b1bc06706a1eda671f Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Wed, 15 Sep 2021 11:42:06 +0800 Subject: [PATCH 4/9] add method and dbus signal --- .../kylinactiveconnectresource.cpp | 21 ++ .../kylinactiveconnectresource.h | 2 + .../dbus-interface/kylinconnectresource.cpp | 6 + .../dbus-interface/kylinconnectresource.h | 2 + .../kylinnetworkresourcemanager.cpp | 6 + .../kylinnetworkresourcemanager.h | 4 + .../kywirelessconnectoperation.cpp | 16 +- src/backend/dbusadaptor.h | 12 +- src/frontend/netdetails/creatnetpage.cpp | 4 +- src/frontend/netdetails/netdetail.cpp | 7 +- src/frontend/netdetails/securitypage.cpp | 223 ++++++++++-------- src/frontend/netdetails/securitypage.h | 9 + src/frontend/new-mainwindow.cpp | 15 +- src/frontend/new-mainwindow.h | 13 +- src/frontend/tab-pages/lanpage.cpp | 96 +++++--- src/frontend/tab-pages/lanpage.h | 7 +- src/frontend/tab-pages/tabpage.h | 1 - src/frontend/tab-pages/wlanpage.cpp | 23 +- src/frontend/tab-pages/wlanpage.h | 4 +- 19 files changed, 295 insertions(+), 176 deletions(-) diff --git a/src/backend/dbus-interface/kylinactiveconnectresource.cpp b/src/backend/dbus-interface/kylinactiveconnectresource.cpp index b33510d8..cfc5d55d 100644 --- a/src/backend/dbus-interface/kylinactiveconnectresource.cpp +++ b/src/backend/dbus-interface/kylinactiveconnectresource.cpp @@ -511,3 +511,24 @@ void KyActiveConnectResourse::getApActivateConnect(QList &apC return; } + +bool KyActiveConnectResourse::isActiveConnection(QString uuid, QStringList &devName) +{ + if (!m_networkResourceInstance->isActiveConnection(uuid)) { + return false; + } else { + NetworkManager::ActiveConnection::Ptr actPtr = m_networkResourceInstance->getActiveConnect(uuid); + if (actPtr.isNull()) { + return false; + } else { + QStringList interfaces = actPtr->devices(); + for (int index = 0; index < interfaces.size(); ++index) { + QString ifaceUni = interfaces.at(index); + NetworkManager::Device:: Ptr devicePtr = + m_networkResourceInstance->findDeviceUni(ifaceUni); + devName <interfaceName(); + } + return true; + } + } +} diff --git a/src/backend/dbus-interface/kylinactiveconnectresource.h b/src/backend/dbus-interface/kylinactiveconnectresource.h index 388d85e9..b5d02054 100644 --- a/src/backend/dbus-interface/kylinactiveconnectresource.h +++ b/src/backend/dbus-interface/kylinactiveconnectresource.h @@ -34,6 +34,8 @@ public: void getApActivateConnect(QList &apConnectItemList); + bool isActiveConnection(QString uuid, QStringList &devName); + private: void getActiveConnectIp(NetworkManager::ActiveConnection::Ptr activeConnectPtr, QString &ipv4Address, diff --git a/src/backend/dbus-interface/kylinconnectresource.cpp b/src/backend/dbus-interface/kylinconnectresource.cpp index 10165584..ac491f0f 100644 --- a/src/backend/dbus-interface/kylinconnectresource.cpp +++ b/src/backend/dbus-interface/kylinconnectresource.cpp @@ -16,6 +16,7 @@ KyConnectResourse::KyConnectResourse(QObject *parent) : QObject(parent) connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionAdd, this, &KyConnectResourse::connectionAdd); connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionRemove, this, &KyConnectResourse::connectionRemove); connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionUpdate, this, &KyConnectResourse::connectionUpdate); + connect(m_networkResourceInstance, &KyNetworkResourceManager::connectivityChanged, this, &KyConnectResourse::connectivityChanged); } KyConnectResourse::~KyConnectResourse() @@ -278,6 +279,11 @@ void KyConnectResourse::getIpv6ConnectSetting( return; } +void KyConnectResourse::getConnectivity(NetworkManager::Connectivity &connectivity) +{ + m_networkResourceInstance->getConnectivity(connectivity); +} + void KyConnectResourse::getConnectionSetting(QString connectUuid, KyConnectSetting &connectSetting) { qDebug() <<"[KyConnectResourse]" << connectUuid <<"get connect setting info, connect uuid"; diff --git a/src/backend/dbus-interface/kylinconnectresource.h b/src/backend/dbus-interface/kylinconnectresource.h index aa8f9c26..39dfa82c 100644 --- a/src/backend/dbus-interface/kylinconnectresource.h +++ b/src/backend/dbus-interface/kylinconnectresource.h @@ -28,6 +28,7 @@ public: void getApConnections(QList &apConnectItemList); void getConnectionSetting(QString connectUuid, KyConnectSetting &connectSetting); bool getInterfaceByUuid(QString &deviceName, NetworkManager::ConnectionSettings::ConnectionType &type, const QString connUuid); + void getConnectivity(NetworkManager::Connectivity &connectivity); private: KyConnectItem *getConnectionItem(NetworkManager::Connection::Ptr connectPtr); @@ -51,6 +52,7 @@ signals: void connectionAdd(QString uuid); void connectionUpdate(QString uuid); void connectionRemove(QString path); + void connectivityChanged(NetworkManager::Connectivity connectivity); private: KyNetworkResourceManager *m_networkResourceInstance = nullptr; diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp index ab6529a0..76d7a71e 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp @@ -51,6 +51,7 @@ KyNetworkResourceManager::KyNetworkResourceManager(QObject *parent) : QObject(pa connect(NetworkManager::settingsNotifier(), &NetworkManager::SettingsNotifier::connectionAdded, this, &KyNetworkResourceManager::onConnectionAdded); connect(NetworkManager::settingsNotifier(), &NetworkManager::SettingsNotifier::connectionRemoved, this, static_cast(&KyNetworkResourceManager::onConnectionRemoved)); + connect(NetworkManager::notifier(), &NetworkManager::Notifier::connectivityChanged, this, &KyNetworkResourceManager::connectivityChanged); //todo wifi开关信号 connect(NetworkManager::notifier(), &NetworkManager::Notifier::wirelessEnabledChanged, this, &KyNetworkResourceManager::wifinEnabledChanged); connect(NetworkManager::notifier(), &NetworkManager::Notifier::wirelessHardwareEnabledChanged, [=](){ @@ -483,6 +484,11 @@ bool KyNetworkResourceManager::isActivatingConnection(QString uuid) return false; } +void KyNetworkResourceManager::getConnectivity(NetworkManager::Connectivity &connectivity) +{ + connectivity = NetworkManager::connectivity(); +} + void KyNetworkResourceManager::requestScan(NetworkManager::WirelessDevice * dev) { qDebug() <<"[KyNetworkResourceManager]"<< dev->interfaceName()<<"start scan wifi ap"; diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.h b/src/backend/dbus-interface/kylinnetworkresourcemanager.h index cb558a57..8503a4b4 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.h +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.h @@ -101,6 +101,8 @@ public: bool isActiveConnection(QString uuid); bool isActivatingConnection(QString uuid); + void getConnectivity(NetworkManager::Connectivity &connectivity); + signals: void connectionAdd(QString uuid); void connectionUpdate(QString uuid); @@ -136,6 +138,8 @@ signals: NetworkManager::VpnConnection::State state, NetworkManager::VpnConnection::StateChangeReason reason); + void connectivityChanged(NetworkManager::Connectivity connectivity); + private slots: //connection void onConnectionUpdated(); diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.cpp b/src/backend/dbus-interface/kywirelessconnectoperation.cpp index e9dd5668..cf182d8a 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.cpp +++ b/src/backend/dbus-interface/kywirelessconnectoperation.cpp @@ -247,8 +247,8 @@ QString KyWirelessConnectOperation::getPsk(const QString &connectUuid) } QDBusPendingReply reply = connectPtr->secrets(PSK_SETTING_NAME); QMap map(reply.value()); - if (map.contains("802-11-wireless-security") && map.value("802-11-wireless-security").contains("psk")) - { + if (map.contains("802-11-wireless-security") + && map.value("802-11-wireless-security").contains("psk")) { QString psk = map.value("802-11-wireless-security").value("psk").toString(); return psk; } @@ -267,8 +267,8 @@ QString KyWirelessConnectOperation::getPrivateKeyPassword(const QString &connect } QDBusPendingReply reply = connectPtr->secrets(PSK_SETTING_NAME); QMap map(reply.value()); - if (map.contains("802-1x") && map.value("802-1x").contains("private-key-password")) - { + if (map.contains("802-1x") + && map.value("802-1x").contains("private-key-password")) { QString psk = map.value("802-1x").value("private-key-password").toString(); return psk; } @@ -825,8 +825,7 @@ KyKeyMgmt KyWirelessConnectOperation::getConnectKeyMgmt(const QString &uuid) NetworkManager::WirelessSecuritySetting::Ptr security_sett = connectPtr->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); - if(security_sett.isNull()) - { + if(security_sett.isNull()) { return KyKeyMgmt::Unknown; } return (KyKeyMgmt)security_sett->keyMgmt(); @@ -848,7 +847,6 @@ void KyWirelessConnectOperation::updateWirelessSecu(NetworkManager::ConnectionSe } security_sett->setKeyMgmt((NetworkManager::WirelessSecuritySetting::KeyMgmt)type); if (bPwdChange) { - qDebug() << "set psk " << connSettingInfo.m_psk; security_sett->setPsk(connSettingInfo.m_psk); } return; @@ -927,13 +925,13 @@ bool KyWirelessConnectOperation::getEnterpiseEapMethod(const QString &uuid, KyEa NetworkManager::Connection::Ptr connectPtr = NetworkManager::findConnectionByUuid(uuid); if (connectPtr.isNull()) { - qDebug() << "getEnterpiseEapMethod faild.Can't find uuid = " << uuid; + qWarning() << "getEnterpiseEapMethod faild.Can't find uuid = " << uuid; return false; } KyKeyMgmt keyMgmt = getConnectKeyMgmt(uuid); if (keyMgmt != WpaEap) { - qDebug() << "getEnterpiseEapMethod but not WpaEap.it's " << keyMgmt; + qWarning() << "getEnterpiseEapMethod but not WpaEap.it's " << keyMgmt; return false; } diff --git a/src/backend/dbusadaptor.h b/src/backend/dbusadaptor.h index 0b35e6c0..0c290333 100644 --- a/src/backend/dbusadaptor.h +++ b/src/backend/dbusadaptor.h @@ -79,9 +79,15 @@ public Q_SLOTS: // METHODS //获取热点 QStringList getStoredApInfo(); Q_SIGNALS: // SIGNALS - void wirelessActivating(QString devName, QString ssid); - void wiredActivating(QString devName, QString ssid); - void listUpdate(QString devName); +// void wirelessActivating(QString devName, QString ssid); +// void wiredActivating(QString devName, QString ssid); + void lanAdd(QString devName, QStringList info); + void lanRemove(QString dbusPath); + void lanUpdate(QString devName, QStringList info); + void wlanAdd(QString devName, QStringList info); + void wlanRemove(QString devName,QString ssid); + void wlanactiveConnectionStateChanged(QString devName, QString ssid, int status); + void lanActiveConnectionStateChanged(QString devName, QString uuid, int status); //仅失败,若成功直接发listUpdate void activateFailed(QString errorMessage); void deactivateFailed(QString errorMessage); diff --git a/src/frontend/netdetails/creatnetpage.cpp b/src/frontend/netdetails/creatnetpage.cpp index ea672c6a..ff4bd30e 100644 --- a/src/frontend/netdetails/creatnetpage.cpp +++ b/src/frontend/netdetails/creatnetpage.cpp @@ -165,7 +165,9 @@ void CreatNetPage::constructIpv4Info(KyConnectSetting &setting) QString ipv4address =ipv4addressEdit->text(); QString netMask = netMaskEdit->text(); QString gateWay = gateWayEdit->text(); - qDebug() << ipv4address << netMask << gateWay; + qDebug() << "constructIpv4Info: " << "ipv4address " << ipv4address + << " netMask " << netMask + << " gateWay " << gateWay; QStringList dnsList; dnsList.empty(); diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index b2188fcd..d352f838 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -524,11 +524,9 @@ void NetDetail::on_btnForget_clicked() void NetDetail::setConfirmEnable() { - qDebug() << isCreateNet << isWlan; if (isCreateNet && !isWlan) { isConfirmBtnEnable = isCreateOk; } else { - qDebug() << isDetailOk << isIpv4Ok << isIpv6Ok << isSecuOk; if (isDetailOk && isIpv4Ok && isIpv6Ok) { if (isWlan && !isSecuOk) { isConfirmBtnEnable = false; @@ -551,7 +549,7 @@ bool NetDetail::checkIpv4Conflict(QString ipv4Address) if (ipv4Arping->ipv4ConflictCheck() >= 0) { isConflict = ipv4Arping->ipv4IsConflict(); } else { - qDebug() << "checkIpv4Conflict internal error"; + qWarning() << "checkIpv4Conflict internal error"; } delete ipv4Arping; @@ -567,7 +565,7 @@ bool NetDetail::checkIpv6Conflict(QString ipv6address) if (ipv46rping->ipv6ConflictCheck() >= 0) { isConflict = ipv46rping->ipv6IsConflict(); } else { - qDebug() << "checkIpv6Conflict internal error"; + qWarning() << "checkIpv6Conflict internal error"; } delete ipv46rping; @@ -580,7 +578,6 @@ void NetDetail::updateWirelessPersonalConnect() KyWirelessConnectSetting setting; securityPage->updateSecurityChange(setting); bool isPwdChanged = !(m_info.strPassword == setting.m_psk); - qDebug() << setting.m_psk << isPwdChanged; m_wirelessConnOpration->updateWirelessPersonalConnect(m_uuid, setting, isPwdChanged); } diff --git a/src/frontend/netdetails/securitypage.cpp b/src/frontend/netdetails/securitypage.cpp index 6d509a25..f6447b3a 100644 --- a/src/frontend/netdetails/securitypage.cpp +++ b/src/frontend/netdetails/securitypage.cpp @@ -165,112 +165,20 @@ void SecurityPage::initConnect() //EAP方式变化 connect(eapTypeCombox, &QComboBox::currentTextChanged, this, &SecurityPage::onEapTypeComboxIndexChanged); - connect(caNeedBox, &QCheckBox::clicked, this, [&](){ - if (caNeedBox->isChecked()) { - caCertPathCombox->setEnabled(false); - } else { - caCertPathCombox->setEnabled(true); - } - }); + connect(caNeedBox, &QCheckBox::clicked, this, &SecurityPage::onCaNeedBoxClicked); - connect(pwdBox, &QCheckBox::clicked, this, [&]() { - if (pwdEdit->echoMode() == QLineEdit::Password) { - pwdBox->setChecked(true); - pwdEdit->setEchoMode(QLineEdit::Normal); - } else { - pwdBox->setChecked(false); - pwdEdit->setEchoMode(QLineEdit::Password); - } + connect(pwdBox, &QCheckBox::clicked, this, &SecurityPage::onPwdBoxClicked); + connect(userPwdBox, &QCheckBox::clicked, this, &SecurityPage::onUserPwdBox); + connect(privateKeyBox, &QCheckBox::clicked, this, &SecurityPage::onPrivateKeyBoxClicked); - }); + connect(caCertPathCombox, static_cast(&QComboBox::currentIndexChanged), + this, &SecurityPage::onCaCertPathComboxIndexChanged); - connect(userPwdBox, &QCheckBox::clicked, this, [&]() { - if (userPwdEdit->echoMode() == QLineEdit::Password) { - userPwdBox->setChecked(true); - userPwdEdit->setEchoMode(QLineEdit::Normal); - } else { - userPwdBox->setChecked(false); - userPwdEdit->setEchoMode(QLineEdit::Password); - } + connect(clientCertPathCombox, static_cast(&QComboBox::currentIndexChanged), + this, &SecurityPage::onClientCertPathComboxIndexChanged); - }); - - connect(privateKeyBox, &QCheckBox::clicked, this, [&]() { - if (clientPrivateKeyPwdEdit->echoMode() == QLineEdit::Password) { - privateKeyBox->setChecked(true); - clientPrivateKeyPwdEdit->setEchoMode(QLineEdit::Normal); - } else { - privateKeyBox->setChecked(false); - clientPrivateKeyPwdEdit->setEchoMode(QLineEdit::Password); - } - - }); - - connect(caCertPathCombox, static_cast(&QComboBox::currentIndexChanged), this, [=] (const QString &str) { - if (str.contains("Choose from file...") || str.contains("从文件选择...")) - { - QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a CA certificate"), "recent:///", - tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); - if (!fileName.isNull()) { - QStringList nameList = fileName.split("/"); - caCertPathCombox->blockSignals(true); - caCertPathCombox->setItemText(0, fileName); - caCertPathCombox->setCurrentIndex(0); - caCertPathCombox->blockSignals(false); - } else { - caCertPathCombox->blockSignals(true); - caCertPathCombox->setItemText(0, tr("None")); - caCertPathCombox->setCurrentIndex(0); - caCertPathCombox->blockSignals(false); - } - } else { - qWarning() << "Choose file is null or unvalible"; - } - }); - - connect(clientCertPathCombox, static_cast(&QComboBox::currentIndexChanged), this, [=] (const QString &str) { - if (str.contains("Choose from file...") || str.contains("从文件选择...")) - { - QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a CA certificate"), "recent:///", - tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); - if (!fileName.isNull()) { -// QStringList nameList = fileName.split("/"); - clientCertPathCombox->blockSignals(true); - clientCertPathCombox->setItemText(0, fileName); - clientCertPathCombox->setCurrentIndex(0); - clientCertPathCombox->blockSignals(false); - } else { - clientCertPathCombox->blockSignals(true); - clientCertPathCombox->setItemText(0, tr("None")); - clientCertPathCombox->setCurrentIndex(0); - clientCertPathCombox->blockSignals(false); - } - } else { - qWarning() << "Choose file is null or unvalible"; - } - }); - - connect(clientPrivateKeyCombox, static_cast(&QComboBox::currentIndexChanged), this, [=] (const QString &str) { - if (str.contains("Choose from file...") || str.contains("从文件选择...")) - { - QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a CA certificate"), "recent:///", - tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); - if (!fileName.isNull()) { - QStringList nameList = fileName.split("/"); - clientPrivateKeyCombox->blockSignals(true); - clientPrivateKeyCombox->setItemText(0, fileName); - clientPrivateKeyCombox->setCurrentIndex(0); - clientPrivateKeyCombox->blockSignals(false); - } else { - clientPrivateKeyCombox->blockSignals(true); - clientPrivateKeyCombox->setItemText(0, tr("None")); - clientPrivateKeyCombox->setCurrentIndex(0); - clientPrivateKeyCombox->blockSignals(false); - } - } else { - qWarning() << "Choose file is null or unvalible"; - } - }); + connect(clientPrivateKeyCombox, static_cast(&QComboBox::currentIndexChanged), + this, &SecurityPage::onClientPrivateKeyComboxIndexChanged); connect(secuTypeCombox, SIGNAL(currentIndexChanged(QString)), this, SLOT(setEnableOfSaveBtn())); connect(pwdEdit, &QLineEdit::textChanged, this, &SecurityPage::setEnableOfSaveBtn); @@ -740,3 +648,114 @@ void SecurityPage::onEapTypeComboxIndexChanged() eapMethodCombox->addItem("gtc(eap)", GTC_EAP); } } + +void SecurityPage::onCaNeedBoxClicked() +{ + if (caNeedBox->isChecked()) { + caCertPathCombox->setEnabled(false); + } else { + caCertPathCombox->setEnabled(true); + } +} + +void SecurityPage::onPwdBoxClicked() +{ + if (pwdEdit->echoMode() == QLineEdit::Password) { + pwdBox->setChecked(true); + pwdEdit->setEchoMode(QLineEdit::Normal); + } else { + pwdBox->setChecked(false); + pwdEdit->setEchoMode(QLineEdit::Password); + } +} + +void SecurityPage::onUserPwdBox() +{ + if (userPwdEdit->echoMode() == QLineEdit::Password) { + userPwdBox->setChecked(true); + userPwdEdit->setEchoMode(QLineEdit::Normal); + } else { + userPwdBox->setChecked(false); + userPwdEdit->setEchoMode(QLineEdit::Password); + } + +} + +void SecurityPage::onPrivateKeyBoxClicked() +{ + if (clientPrivateKeyPwdEdit->echoMode() == QLineEdit::Password) { + privateKeyBox->setChecked(true); + clientPrivateKeyPwdEdit->setEchoMode(QLineEdit::Normal); + } else { + privateKeyBox->setChecked(false); + clientPrivateKeyPwdEdit->setEchoMode(QLineEdit::Password); + } +} + +void SecurityPage::onCaCertPathComboxIndexChanged(QString str) +{ + if (str.contains("Choose from file...") || str.contains("从文件选择...")) + { + QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a CA certificate"), "recent:///", + tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); + if (!fileName.isNull()) { + QStringList nameList = fileName.split("/"); + caCertPathCombox->blockSignals(true); + caCertPathCombox->setItemText(0, fileName); + caCertPathCombox->setCurrentIndex(0); + caCertPathCombox->blockSignals(false); + } else { + caCertPathCombox->blockSignals(true); + caCertPathCombox->setItemText(0, tr("None")); + caCertPathCombox->setCurrentIndex(0); + caCertPathCombox->blockSignals(false); + } + } else { + qWarning() << "Choose file is null or unvalible"; + } +} + +void SecurityPage::onClientCertPathComboxIndexChanged(QString str) +{ + if (str.contains("Choose from file...") || str.contains("从文件选择...")) + { + QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a CA certificate"), "recent:///", + tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); + if (!fileName.isNull()) { + clientCertPathCombox->blockSignals(true); + clientCertPathCombox->setItemText(0, fileName); + clientCertPathCombox->setCurrentIndex(0); + clientCertPathCombox->blockSignals(false); + } else { + clientCertPathCombox->blockSignals(true); + clientCertPathCombox->setItemText(0, tr("None")); + clientCertPathCombox->setCurrentIndex(0); + clientCertPathCombox->blockSignals(false); + } + } else { + qWarning() << "Choose file is null or unvalible"; + } +} + +void SecurityPage::onClientPrivateKeyComboxIndexChanged(QString str) +{ + if (str.contains("Choose from file...") || str.contains("从文件选择...")) + { + QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a CA certificate"), "recent:///", + tr("CA Files (*.pem *.der *.p12 *.crt *.cer *.pfx)")); + if (!fileName.isNull()) { + QStringList nameList = fileName.split("/"); + clientPrivateKeyCombox->blockSignals(true); + clientPrivateKeyCombox->setItemText(0, fileName); + clientPrivateKeyCombox->setCurrentIndex(0); + clientPrivateKeyCombox->blockSignals(false); + } else { + clientPrivateKeyCombox->blockSignals(true); + clientPrivateKeyCombox->setItemText(0, tr("None")); + clientPrivateKeyCombox->setCurrentIndex(0); + clientPrivateKeyCombox->blockSignals(false); + } + } else { + qWarning() << "Choose file is null or unvalible"; + } +} diff --git a/src/frontend/netdetails/securitypage.h b/src/frontend/netdetails/securitypage.h index 153c04c2..34669022 100644 --- a/src/frontend/netdetails/securitypage.h +++ b/src/frontend/netdetails/securitypage.h @@ -96,6 +96,15 @@ private slots: void onEapTypeComboxIndexChanged(); void setEnableOfSaveBtn(); + void onCaNeedBoxClicked(); + void onPwdBoxClicked(); + void onUserPwdBox(); + void onPrivateKeyBoxClicked(); + + void onCaCertPathComboxIndexChanged(QString str); + void onClientCertPathComboxIndexChanged(QString str); + void onClientPrivateKeyComboxIndexChanged(QString str); + signals: void setSecuPageState(bool); }; diff --git a/src/frontend/new-mainwindow.cpp b/src/frontend/new-mainwindow.cpp index 1ea1d72e..61178d4e 100644 --- a/src/frontend/new-mainwindow.cpp +++ b/src/frontend/new-mainwindow.cpp @@ -153,12 +153,15 @@ void MainWindow::initDbusConnnect() connect(m_wlanWidget, &WlanPage::activateFailed, this, &MainWindow::activateFailed); connect(m_wlanWidget, &WlanPage::deactivateFailed, this, &MainWindow::deactivateFailed); - connect(m_lanWidget, &LanPage::listUpdate, this, &MainWindow::listUpdate); - connect(m_wlanWidget, &WlanPage::listUpdate, this, &MainWindow::listUpdate); + connect(m_lanWidget, &LanPage::lanAdd, this, &MainWindow::lanAdd); + connect(m_lanWidget, &LanPage::lanRemove, this, &MainWindow::lanRemove); + connect(m_lanWidget, &LanPage::lanUpdate, this, &MainWindow::lanUpdate); + connect(m_lanWidget, &LanPage::lanActiveConnectionStateChanged, this, &MainWindow::lanActiveConnectionStateChanged); - connect(m_lanWidget, &LanPage::wiredActivating, this, &MainWindow::wiredActivating); - connect(m_wlanWidget, &WlanPage::wirelessActivating, this, &MainWindow::wirelessActivating); + connect(m_wlanWidget, &WlanPage::wlanAdd, this, &MainWindow::wlanAdd); + connect(m_wlanWidget, &WlanPage::wlanRemove, this, &MainWindow::wlanRemove); + connect(m_wlanWidget, &WlanPage::wlanActiveConnectionStateChanged, this, &MainWindow::wlanactiveConnectionStateChanged); connect(m_wlanWidget, &WlanPage::hotspotDeactivated, this, &MainWindow::hotspotDeactivated); connect(m_wlanWidget, &WlanPage::hotspotActivated, this, &MainWindow::hotspotActivated); connect(m_wlanWidget, &WlanPage::secuTypeChange, this, &MainWindow::secuTypeChange); @@ -431,7 +434,9 @@ void MainWindow::showPropertyWidget(QString devName, QString ssid) return; } - qDebug() << "showPropertyWidget no such device " << devName; + qWarning() << "showPropertyWidget no such device " << devName; + delete devResourse; + devResourse = nullptr; } void MainWindow::showCreateWiredConnectWidget(const QString devName) diff --git a/src/frontend/new-mainwindow.h b/src/frontend/new-mainwindow.h index fcf35509..49a113ba 100644 --- a/src/frontend/new-mainwindow.h +++ b/src/frontend/new-mainwindow.h @@ -52,11 +52,14 @@ signals: void deviceStatusChanged(); //设备名称变化 void deviceNameChanged(QString oldName, QString newName); - //设备有线无线列表更新(有线增删、无线增加减少) - void listUpdate(QString devName); - //控制面板连接中 - void wiredActivating(QString devName, QString ssid); - void wirelessActivating(QString devName, QString ssid); + //有线无线列表更新(有线增删、无线增加减少) + void lanAdd(QString devName, QStringList info); + void lanRemove(QString dbusPath); + void lanUpdate(QString devName, QStringList info); + void wlanAdd(QString devName, QStringList info); + void wlanRemove(QString devName,QString ssid); + void wlanactiveConnectionStateChanged(QString devName, QString ssid, int status); + void lanActiveConnectionStateChanged(QString devName, QString uuid, int status); void activateFailed(QString errorMessage); void deactivateFailed(QString errorMessage); //热点断开 diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index e09ed664..363d4b2e 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -38,6 +38,7 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent) connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist); connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &LanPage::addConnectionSlot); connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &LanPage::removeConnectionSlot); + connect(m_connectResourse, &KyConnectResourse::connectionUpdate, this, &LanPage::connectionUpdateSlot); connect(m_device, &KyNetworkDeviceResourse::deviceAdd, this, &LanPage::onDeviceAdd); connect(m_device, &KyNetworkDeviceResourse::deviceRemove, this, &LanPage::onDeviceRemove); connect(m_device, &KyNetworkDeviceResourse::deviceNameUpdate, this, &LanPage::onDeviceNameUpdate); @@ -121,6 +122,10 @@ void LanPage::onLanSwitchClicked() void LanPage::removeConnectionSlot(QString path) //删除时后端会自动断开激活,将其从未激活列表中删除 { + //for dbus + qDebug() << "[LanPage] emit lanRemove because removeConnectionSlot " << path; + emit lanRemove(path); + qDebug()<<"[LanPage] Removing a connection, path:"<m_ifaceName; - emit listUpdate(item->m_ifaceName); break; } } - if (!isLan) { - //removeConnection不是当前设备的,可能是其他有线设备或无线设备,保险起见发送信号更新 - for (int index = 0; index < devList.size(); ++index) { - if (devList.at(index) == m_deviceName) { - continue; - } - emit listUpdate(devList.at(index)); - } - } } void LanPage::addConnectionSlot(QString uuid) //新增一个有线连接,将其加入到激活列表 @@ -167,8 +160,14 @@ void LanPage::addConnectionSlot(QString uuid) //新增一个有线 } //for dbus - qDebug() << "[LanPage] emit listUpdate because addConnection " << devName; - emit listUpdate(devName); + KyConnectItem *item = nullptr; + item = m_connectResourse->getConnectionItemByUuid(uuid, devName); + if (nullptr != item) { + QStringList info; + info << item->m_connectName << uuid << item->m_connectPath; + qDebug() << "[LanPage] emit lanAdd because addConnection " << devName; + emit lanAdd(devName, info); + } KyConnectItem * newItem = m_connectResourse->getConnectionItemByUuid(uuid, m_deviceName); if (newItem != nullptr) { @@ -182,6 +181,41 @@ void LanPage::addConnectionSlot(QString uuid) //新增一个有线 qDebug()<<"[LanPage] GetConnectionItemByUuid is empty when add a new!"; } } +void LanPage::connectionUpdateSlot(QString uuid) +{ + //for dbus + QStringList devNameList; + if (m_activeResourse->isActiveConnection(uuid, devNameList)) { + for (int i = 0; i < devNameList.size(); ++i) { + KyConnectItem *item = nullptr; + item = m_activeResourse->getActiveConnectionByUuid(uuid, devNameList.at(i)); + if (nullptr != item) { + if (item->m_itemType != NetworkManager::ConnectionSettings::ConnectionType::Wired) { + return; + } + QStringList info; + info << item->m_connectName << uuid << item->m_connectPath; + emit lanUpdate(devNameList.at(i), info); + } + } + } else { + QString devName; + NetworkManager::ConnectionSettings::ConnectionType type; + if (!m_connectResourse->getInterfaceByUuid(devName, type, uuid)) { + return; + } + if (type != NetworkManager::ConnectionSettings::ConnectionType::Wired) { + return; + } + KyConnectItem *item = nullptr; + item = m_connectResourse->getConnectionItemByUuid(uuid, devName); + if (nullptr != item) { + QStringList info; + info << item->m_connectName << uuid << item->m_connectPath; + emit lanUpdate(devName, info); + } + } +} void LanPage::initDevice() { @@ -413,16 +447,23 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat qDebug() << "[LanPage] updateLanlist but uuid is invalid"; } - if (state == NetworkManager::ActiveConnection::State::Activating) { - qDebug() << "[LanPage] wiredActivating " << devName; - emit wiredActivating(devName,uuid); + QStringList devNameList; + if (m_activeResourse->isActiveConnection(uuid, devNameList)) { + for (int i = 0; i < devNameList.size(); ++i) { + KyConnectItem *item = nullptr; + item = m_activeResourse->getActiveConnectionByUuid(uuid, devNameList.at(i)); + if (nullptr != item) { + QStringList info; + info << item->m_connectName << uuid << item->m_connectPath; + emit lanActiveConnectionStateChanged(devNameList.at(i), uuid, state); + } + } + } else { + qDebug() << "emit lanActiveConnectionStateChanged" << devName << uuid << state; + emit lanActiveConnectionStateChanged(devName, uuid, state); } - if (state == NetworkManager::ActiveConnection::State::Activated || state == NetworkManager::ActiveConnection::State::Deactivated) - { - qDebug() << "[LanPage] because updateLanlist " < > &map) QVector vector; m_activeResourse->getActiveConnectionList(deviceName,NetworkManager::ConnectionSettings::Wired,activedList); if (!activedList.isEmpty()) { - vector.append(QStringList()<m_connectName<m_connectUuid); + vector.append(QStringList() << activedList.at(0)->m_connectName << activedList.at(0)->m_connectUuid << activedList.at(0)->m_connectPath); } else { vector.append(QStringList()<<("--")); } @@ -560,14 +601,13 @@ void LanPage::showDetailPage(QString devName, QString uuid) item = m_activeResourse->getActiveConnectionByUuid(uuid, devName); if (nullptr == item) { item = m_connectResourse->getConnectionItemByUuid(uuid, devName); + if (nullptr == item) { + qWarning()<<"[LanPage] GetConnectionItemByUuid is empty when showDetailPage"; + return; + } isActive= false; } - if (nullptr == item) { - qDebug()<<"[LanPage] GetConnectionItemByUuid is empty when showDetailPage"; - return; - } - NetDetail *netDetail = new NetDetail(devName, item->m_connectName, uuid, isActive, false, false, this); netDetail->show(); delete item; diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index c01fe7f6..a370366c 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -29,8 +29,10 @@ public: void showDetailPage(QString devName, QString uuid); void setWiredDeviceEnable(const QString& devName, bool enable); signals: - void wiredActivating(QString devName, QString ssid); - + void lanAdd(QString devName, QStringList info); + void lanRemove(QString dbusPath); + void lanUpdate(QString devName, QStringList info); + void lanActiveConnectionStateChanged(QString interface, QString uuid, int status); private: void initDevice();//初始化默认设备 void initDeviceCombox(); @@ -72,6 +74,7 @@ private slots: void updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason); void addConnectionSlot(QString uuid); void removeConnectionSlot(QString path); + void connectionUpdateSlot(QString uuid); void onSwithGsettingsChanged(const QString &key); void onLanSwitchClicked(); void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType); diff --git a/src/frontend/tab-pages/tabpage.h b/src/frontend/tab-pages/tabpage.h index 1cee2a08..7810a382 100644 --- a/src/frontend/tab-pages/tabpage.h +++ b/src/frontend/tab-pages/tabpage.h @@ -56,7 +56,6 @@ signals: void deviceNameChanged(QString oldName, QString newName); void activateFailed(QString errorMessage); void deactivateFailed(QString errorMessage); - void listUpdate(QString devName); protected: void initUI(); diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 94c34a20..4a7c1191 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -106,8 +106,6 @@ void WlanPage::initConnections() { connect(m_resource, &KyWirelessNetResource::wifiNetworkAdd, this, &WlanPage::onWlanAdded); connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::onWlanRemoved); - connect(m_resource, &KyWirelessNetResource::wifiNetworkAdd, this, &WlanPage::listUpdate); - connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::listUpdate); connect(m_resource, &KyWirelessNetResource::signalStrengthChange, this, &WlanPage::signalStrengthChange); connect(m_resource, &KyWirelessNetResource::secuTypeChange, this, &WlanPage::secuTypeChange); @@ -290,7 +288,12 @@ void WlanPage::getAllWlan() void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item) { - emit listUpdate(interface); + //for dbus + QStringList info; + info < apConnectItemList; diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index 0b37cead..351c9565 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -36,7 +36,9 @@ public: void showDetailPage(QString devName, QString uuid); signals: void oneItemExpanded(const QString &ssid); - void wirelessActivating(QString devName, QString ssid); + void wlanAdd(QString devName, QStringList info); + void wlanRemove(QString devName,QString ssid); + void wlanActiveConnectionStateChanged(QString interface, QString ssid, int status); void hotspotDeactivated(QString devName, QString ssid); void hotspotActivated(QString devName, QString ssid); void signalStrengthChange(QString devName, QString ssid, int strength); From 6697722d4a9b25c8ed3c9838d99a0babf282e00f Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Wed, 15 Sep 2021 11:46:12 +0800 Subject: [PATCH 5/9] fix fault --- src/backend/dbus-interface/kylinactiveconnectresource.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backend/dbus-interface/kylinactiveconnectresource.cpp b/src/backend/dbus-interface/kylinactiveconnectresource.cpp index cfc5d55d..7f1c604d 100644 --- a/src/backend/dbus-interface/kylinactiveconnectresource.cpp +++ b/src/backend/dbus-interface/kylinactiveconnectresource.cpp @@ -75,6 +75,9 @@ KyConnectItem *KyActiveConnectResourse::getActiveConnectionByUuid(QString connec if (devicePtr->interfaceName() == deviceName) { KyConnectItem *activeConnectItem = getActiveConnectionItem(activeConnectPtr); + if (nullptr == activeConnectItem) { + return nullptr; + } activeConnectItem->m_ifaceName = deviceName; activeConnectItem->m_itemType = activeConnectPtr->type(); return activeConnectItem; From 2a2d2fbf2984f9b2facb459e7fcdcdfac7df86d8 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Thu, 16 Sep 2021 11:24:48 +0800 Subject: [PATCH 6/9] modify get channel method --- .../dbus-interface/kywirelessnetitem.cpp | 2 +- src/frontend/netdetails/netdetail.cpp | 17 ++++++++++++++--- src/frontend/netdetails/netdetail.h | 3 +++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/backend/dbus-interface/kywirelessnetitem.cpp b/src/backend/dbus-interface/kywirelessnetitem.cpp index 44252ca0..db3ed6fc 100644 --- a/src/backend/dbus-interface/kywirelessnetitem.cpp +++ b/src/backend/dbus-interface/kywirelessnetitem.cpp @@ -54,6 +54,7 @@ void KyWirelessNetItem::init(NetworkManager::WirelessNetwork::Ptr net) m_NetSsid = net->ssid(); m_signalStrength = net->signalStrength(); m_frequency = net->referenceAccessPoint()->frequency(); + m_channel = NetworkManager::findChannel(m_frequency); NetworkManager::AccessPoint::Capabilities cap = net->referenceAccessPoint()->capabilities(); NetworkManager::AccessPoint::WpaFlags wpaFlag = net->referenceAccessPoint()->wpaFlags(); NetworkManager::AccessPoint::WpaFlags rsnFlag = net->referenceAccessPoint()->rsnFlags(); @@ -81,7 +82,6 @@ void KyWirelessNetItem::initInfoBySsid() m_connName = conn->name(); m_connDbusPath = conn->path(); m_isConfigured = true; - m_channel = wifi_sett->channel(); return; } } diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index d352f838..3c87f9fc 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -111,15 +111,28 @@ void NetDetail::initUI() detailBtn = new QPushButton(this); detailBtn->setText(tr("Detail")); + detailBtn->setCheckable(true); + detailBtn->setChecked(true); ipv4Btn = new QPushButton(this); ipv4Btn->setText(tr("Ipv4")); + ipv4Btn->setCheckable(true); ipv6Btn = new QPushButton(this); ipv6Btn->setText(tr("Ipv6")); + ipv6Btn->setCheckable(true); securityBtn = new QPushButton(this); securityBtn->setText(tr("Security")); + securityBtn->setCheckable(true); + + group = new QButtonGroup(this); + group->addButton(detailBtn); + group->addButton(ipv4Btn); + group->addButton(ipv6Btn); + if (isWlan) { + group->addButton(securityBtn); + } pageLayout->addStretch(); pageLayout->addWidget(detailBtn); @@ -360,9 +373,7 @@ void NetDetail::getBaseInfo(ConInfo &conInfo) qDebug() << "KeyMgmt not support now " << type; } conInfo.strHz = QString::number(item.m_frequency); - if (item.m_isConfigured) { - conInfo.strChan = QString::number(item.m_channel); - } + conInfo.strChan = QString::number(item.m_channel); initSecuData(); } diff --git a/src/frontend/netdetails/netdetail.h b/src/frontend/netdetails/netdetail.h index 7c139818..bc353213 100644 --- a/src/frontend/netdetails/netdetail.h +++ b/src/frontend/netdetails/netdetail.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -119,6 +120,8 @@ private: ConInfo m_info; + QButtonGroup *group; + private slots: void on_btnConfirm_clicked(); void on_btnForget_clicked(); From 4936fa953ec6e18f554841bee9f5c532e89670d3 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Thu, 16 Sep 2021 14:13:49 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E9=9C=80=E8=A6=81=E8=AE=BE=E5=A4=87=E5=8C=B9?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/dbus-interface/kywirelessnetresource.cpp | 4 +++- src/backend/dbus-interface/kywirelessnetresource.h | 2 +- src/frontend/list-items/wlanlistitem.cpp | 9 +++++---- src/frontend/tab-pages/wlanpage.cpp | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/backend/dbus-interface/kywirelessnetresource.cpp b/src/backend/dbus-interface/kywirelessnetresource.cpp index 7a3d3041..ab17ab71 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.cpp +++ b/src/backend/dbus-interface/kywirelessnetresource.cpp @@ -159,9 +159,10 @@ QString KyWirelessNetResource::getDeviceIFace(NetworkManager::ActiveConnection:: return sett->interfaceName(); } -void KyWirelessNetResource::getSsidByUuid(const QString uuid, QString &ssid) +void KyWirelessNetResource::getSsidByUuid(const QString uuid, QString &ssid, QString &devName) { ssid.clear(); + devName.clear(); NetworkManager::Connection::Ptr connectPtr = m_networkResourceInstance->getConnect(uuid); if (connectPtr.isNull()) { return; @@ -173,6 +174,7 @@ void KyWirelessNetResource::getSsidByUuid(const QString uuid, QString &ssid) return; } ssid = wireless_sett->ssid(); + devName = connectPtr->settings()->interfaceName(); qDebug() << "getSsidByUuid success " << ssid; return; } diff --git a/src/backend/dbus-interface/kywirelessnetresource.h b/src/backend/dbus-interface/kywirelessnetresource.h index b5725f9a..c9ea8104 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.h +++ b/src/backend/dbus-interface/kywirelessnetresource.h @@ -29,7 +29,7 @@ public: void getWirelessActiveConnection(NetworkManager::ActiveConnection::State state, QMap &map); - void getSsidByUuid(const QString uuid, QString &ssid); + void getSsidByUuid(const QString uuid, QString &ssid, QString &devName); private: diff --git a/src/frontend/list-items/wlanlistitem.cpp b/src/frontend/list-items/wlanlistitem.cpp index d3b3d5c1..489d97b4 100644 --- a/src/frontend/list-items/wlanlistitem.cpp +++ b/src/frontend/list-items/wlanlistitem.cpp @@ -382,13 +382,14 @@ void WlanListItem::onConnectionRemove(QString deviceName, QString ssid) void WlanListItem::onWlanStatusChange(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason) { - QString ssid; - m_resource->getSsidByUuid(uuid,ssid); + QString ssid, devName; + m_resource->getSsidByUuid(uuid, ssid, devName); if (m_data->m_NetSsid == ssid) { qDebug() << "[WlanPage] State changed to :" << state << Q_FUNC_INFO <<__LINE__; - if (state == NetworkManager::ActiveConnection::State::Activating) { + if ((state == NetworkManager::ActiveConnection::State::Activating || state == NetworkManager::ActiveConnection::State::Deactivating) + && devName == m_wlanDevice) { m_netButton->startLoading(); - } else { + } else if (){ m_netButton->stopLoading(); } } diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 7d4a9202..07f589e1 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -430,7 +430,7 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec qDebug() << "[WlanPage] onActivatedWlanChanged but uuid is invalid"; } - m_resource->getSsidByUuid(uuid, ssid); + m_resource->getSsidByUuid(uuid, ssid, devName); qDebug() << "emit wlanActiveConnectionStateChanged" << devName << ssid << state; emit wlanActiveConnectionStateChanged(devName, ssid, state); @@ -463,7 +463,7 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec } } - if (state == NetworkManager::ActiveConnection::State::Activated) { + if (state == NetworkManager::ActiveConnection::State::Activated && defaultDevice == devName) { //onWlanRemoved(m_wlanDevice, ssid); m_activatedNetListWidget->clear(); int height = 0; From 0e00edd7689f082b8e1cfd2a81e5f08b6689a0fd Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Thu, 16 Sep 2021 14:22:09 +0800 Subject: [PATCH 8/9] fix code --- src/frontend/list-items/wlanlistitem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/list-items/wlanlistitem.cpp b/src/frontend/list-items/wlanlistitem.cpp index 489d97b4..077908cd 100644 --- a/src/frontend/list-items/wlanlistitem.cpp +++ b/src/frontend/list-items/wlanlistitem.cpp @@ -389,7 +389,7 @@ void WlanListItem::onWlanStatusChange(QString uuid, NetworkManager::ActiveConnec if ((state == NetworkManager::ActiveConnection::State::Activating || state == NetworkManager::ActiveConnection::State::Deactivating) && devName == m_wlanDevice) { m_netButton->startLoading(); - } else if (){ + } else { m_netButton->stopLoading(); } } From 184366de8f7317902cd62a1cdc134691168e0374 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Fri, 17 Sep 2021 10:03:17 +0800 Subject: [PATCH 9/9] modify --- src/frontend/netdetails/netdetail.cpp | 10 +++++----- src/frontend/netdetails/netdetail.h | 2 +- src/frontend/tab-pages/tabpage.cpp | 6 +++--- src/frontend/tab-pages/tabpage.h | 2 +- src/frontend/tab-pages/wlanpage.cpp | 28 +++++++++++++-------------- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index 3c87f9fc..41ed6251 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -126,12 +126,12 @@ void NetDetail::initUI() securityBtn->setText(tr("Security")); securityBtn->setCheckable(true); - group = new QButtonGroup(this); - group->addButton(detailBtn); - group->addButton(ipv4Btn); - group->addButton(ipv6Btn); + m_group = new QButtonGroup(this); + m_group->addButton(detailBtn); + m_group->addButton(ipv4Btn); + m_group->addButton(ipv6Btn); if (isWlan) { - group->addButton(securityBtn); + m_group->addButton(securityBtn); } pageLayout->addStretch(); diff --git a/src/frontend/netdetails/netdetail.h b/src/frontend/netdetails/netdetail.h index bc353213..990a783d 100644 --- a/src/frontend/netdetails/netdetail.h +++ b/src/frontend/netdetails/netdetail.h @@ -120,7 +120,7 @@ private: ConInfo m_info; - QButtonGroup *group; + QButtonGroup *m_group; private slots: void on_btnConfirm_clicked(); diff --git a/src/frontend/tab-pages/tabpage.cpp b/src/frontend/tab-pages/tabpage.cpp index b235099c..ec70785e 100644 --- a/src/frontend/tab-pages/tabpage.cpp +++ b/src/frontend/tab-pages/tabpage.cpp @@ -93,13 +93,13 @@ void TabPage::initUI() void TabPage::updateDefaultDevice(QString &deviceName) { qDebug() << "updateDefaultDevice" << deviceName; - defaultDevice = deviceName; + m_defaultDevice = deviceName; } QString TabPage::getDefaultDevice() { - qDebug() << "getDefaultDevice" << defaultDevice; - return defaultDevice; + qDebug() << "getDefaultDevice" << m_defaultDevice; + return m_defaultDevice; } void setDefaultDevice(KyDeviceType deviceType, QString deviceName) diff --git a/src/frontend/tab-pages/tabpage.h b/src/frontend/tab-pages/tabpage.h index 7810a382..403f8a44 100644 --- a/src/frontend/tab-pages/tabpage.h +++ b/src/frontend/tab-pages/tabpage.h @@ -84,7 +84,7 @@ protected: QHBoxLayout * m_settingsLayout = nullptr; QLabel * m_settingsLabel = nullptr; - QString defaultDevice = ""; + QString m_defaultDevice = ""; //临时增加的下拉框选择网卡区域 QFrame * m_deviceFrame = nullptr; diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 07f589e1..ed1f145e 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -180,7 +180,7 @@ void WlanPage::initDeviceCombox() //空时addItem 会触发currentIndexChanged m_deviceComboBox->addItem(device, device); } - int index = m_deviceComboBox->findData(defaultDevice); + int index = m_deviceComboBox->findData(m_defaultDevice); qDebug() << index; m_deviceComboBox->setCurrentIndex(index); } @@ -202,7 +202,7 @@ void WlanPage::getActiveWlan() QMap::iterator iter = actMap.begin(); int height = 0; while (iter != actMap.end()) { - if (iter.key() == defaultDevice && !iter.value().isEmpty()) { + if (iter.key() == m_defaultDevice && !iter.value().isEmpty()) { QString ssid = iter.value().at(0); appendActiveWlan(ssid, height); break; @@ -229,11 +229,11 @@ void WlanPage::appendActiveWlan(const QString &ssid, int &height) m_activatedWlanSSid = ssid; KyWirelessNetItem data; - if (!m_resource->getWifiNetwork(defaultDevice, ssid, data)) { + if (!m_resource->getWifiNetwork(m_defaultDevice, ssid, data)) { return; } KyWirelessNetItem *item_data = new KyWirelessNetItem(data); - WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data, defaultDevice); + WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data, m_defaultDevice); qDebug() << "Activated wlan: ssid = " << item_data->m_NetSsid; QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget); wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height())); @@ -257,7 +257,7 @@ void WlanPage::getAllWlan() m_itemsMap.clear(); QList wlanList; // if (!m_resource->getAllDeviceWifiNetwork(map)) - if (!m_resource->getDeviceWifiNetwork(defaultDevice, wlanList)) //ZJP_TODO 获取默认网卡并传入 + if (!m_resource->getDeviceWifiNetwork(m_defaultDevice, wlanList)) //ZJP_TODO 获取默认网卡并传入 { return; } @@ -268,7 +268,7 @@ void WlanPage::getAllWlan() } KyWirelessNetItem *data = new KyWirelessNetItem(itemData); - WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, defaultDevice); + WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, m_defaultDevice); QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget); qDebug() << itemData.m_NetSsid << itemData.m_isConfigured; connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); @@ -296,11 +296,11 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item) qDebug() << "A Wlan Added! interface = " << interface << "; ssid = " << item.m_NetSsid << Q_FUNC_INFO <<__LINE__; - if (interface != defaultDevice) { + if (interface != m_defaultDevice) { qDebug() << "wlan add interface not equal defaultdevice,ignore"; } KyWirelessNetItem *data = new KyWirelessNetItem(item); - WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, defaultDevice); + WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, m_defaultDevice); connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget); wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height())); @@ -319,7 +319,7 @@ void WlanPage::onWlanRemoved(QString interface, QString ssid) if (!m_itemsMap.contains(ssid)) { return; } if (m_expandedItem == m_itemsMap.value(ssid)) { m_expandedItem = nullptr; } qDebug() << "A Wlan Removed! interface = " << interface << "; ssid = " << ssid << Q_FUNC_INFO <<__LINE__; - if (interface != defaultDevice) { + if (interface != m_defaultDevice) { qDebug() << "wlan remove interface not equal defaultdevice,ignore"; } int height = m_inactivatedNetListWidget->itemWidget(m_itemsMap.value(ssid))->height(); @@ -463,12 +463,12 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec } } - if (state == NetworkManager::ActiveConnection::State::Activated && defaultDevice == devName) { + if (state == NetworkManager::ActiveConnection::State::Activated && m_defaultDevice == devName) { //onWlanRemoved(m_wlanDevice, ssid); m_activatedNetListWidget->clear(); int height = 0; appendActiveWlan(ssid, height); - onWlanRemoved(defaultDevice, ssid); + onWlanRemoved(m_defaultDevice, ssid); // this->showDesktopNotify(tr("Connect WLAN succeed")); } else if (state == NetworkManager::ActiveConnection::State::Deactivated) { onWlanUpdated(); @@ -502,7 +502,7 @@ void WlanPage::onItemHeightChanged(const QString &ssid) void WlanPage::onConnectButtonClicked(KyWirelessConnectSetting &connSettingInfo, const bool &isHidden) { qDebug() << "Received signal of connecting wlan, ssid = " << connSettingInfo.m_ssid << Q_FUNC_INFO << __LINE__; - m_wirelessConnectOpreation->addAndActiveWirelessConnect(defaultDevice, connSettingInfo, isHidden); + m_wirelessConnectOpreation->addAndActiveWirelessConnect(m_defaultDevice, connSettingInfo, isHidden); } /** @@ -529,7 +529,7 @@ void WlanPage::onDeviceComboxIndexChanged(int currentIndex) //TODO 设备变更时更新设备和列表 QString currentDevice = m_deviceComboBox->itemText(currentIndex); qDebug() << "Current device changed! device = " << currentDevice << Q_FUNC_INFO << __LINE__; - defaultDevice = currentDevice; + m_defaultDevice = currentDevice; getActiveWlan(); getAllWlan(); } @@ -546,7 +546,7 @@ void WlanPage::requestScan() void WlanPage::onHiddenWlanClicked() { qDebug() << "[wlanPage] AddHideWifi Clicked! " << Q_FUNC_INFO << __LINE__ ; - NetDetail *netDetail = new NetDetail(defaultDevice, "", "", false, true, true, this); + NetDetail *netDetail = new NetDetail(m_defaultDevice, "", "", false, true, true, this); netDetail->show(); }