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);