From d02b55db6712d811c4f0e6e7c664555e5f2f0104 Mon Sep 17 00:00:00 2001 From: renpeijia Date: Mon, 18 Oct 2021 10:36:08 +0800 Subject: [PATCH 1/5] modify:Optimize code logic for wireless networks. --- .../dbus-interface/kylinconnectresource.cpp | 57 +- .../dbus-interface/kylinconnectresource.h | 3 + .../kylinnetworkresourcemanager.cpp | 16 +- .../kylinnetworkresourcemanager.h | 2 +- .../kywirelessconnectoperation.cpp | 5 +- .../kywirelessconnectoperation.h | 2 +- .../dbus-interface/kywirelessnetresource.cpp | 86 +- .../dbus-interface/kywirelessnetresource.h | 5 +- .../enterprise-wlan/enterprisewlandialog.cpp | 37 +- .../enterprise-wlan/enterprisewlandialog.h | 4 +- src/frontend/list-items/listitem.cpp | 8 +- src/frontend/list-items/listitem.h | 10 + src/frontend/list-items/wlanlistitem.cpp | 406 +++-- src/frontend/list-items/wlanlistitem.h | 40 +- src/frontend/mainwindow.cpp | 12 +- src/frontend/nmdemo.cpp | 2 +- src/frontend/tab-pages/lanpage.cpp | 15 +- src/frontend/tab-pages/lanpage.h | 3 +- src/frontend/tab-pages/wlanpage.cpp | 1597 ++++++++++------- src/frontend/tab-pages/wlanpage.h | 147 +- 20 files changed, 1484 insertions(+), 973 deletions(-) diff --git a/src/backend/dbus-interface/kylinconnectresource.cpp b/src/backend/dbus-interface/kylinconnectresource.cpp index a3b380ed..d8e99518 100644 --- a/src/backend/dbus-interface/kylinconnectresource.cpp +++ b/src/backend/dbus-interface/kylinconnectresource.cpp @@ -541,6 +541,25 @@ KyApConnectItem *KyConnectResourse::getApConnectItem(NetworkManager::Connection: return apConnectItem; } +KyApConnectItem *KyConnectResourse::getApConnectionByUuid(QString connectUuid) +{ + NetworkManager::Connection::Ptr connectPtr = nullptr; + + connectPtr = m_networkResourceInstance->getConnect(connectUuid); + if (nullptr == connectPtr) { + return nullptr; + } + + if (NetworkManager::ConnectionSettings::ConnectionType::Wireless + != connectPtr->settings()->connectionType()) { + return nullptr; + } + + KyApConnectItem *connectItem = getApConnectItem(connectPtr); + + return connectItem; +} + void KyConnectResourse::getApConnections(QList &apConnectItemList) { int index = 0; @@ -581,7 +600,11 @@ void KyConnectResourse::getApConnections(QList &apConnectItem bool KyConnectResourse::isWiredConnection(QString uuid) { NetworkManager::Connection::Ptr connectPtr = - m_networkResourceInstance->getConnect(uuid); + m_networkResourceInstance->getConnect(uuid); + if (connectPtr.isNull()) { + qWarning()<<"[KyConnectResourse]"<<"can not find wired connection"<isValid()) { NetworkManager::ConnectionSettings::Ptr connectSettingPtr = connectPtr->settings(); @@ -603,7 +626,12 @@ bool KyConnectResourse::isWiredConnection(QString uuid) bool KyConnectResourse::isWirelessConnection(QString uuid) { NetworkManager::Connection::Ptr connectPtr = - m_networkResourceInstance->getConnect(uuid); + m_networkResourceInstance->getConnect(uuid); + if (connectPtr.isNull()) { + qWarning()<<"[KyConnectResourse]"<<"can not find wireless connection"<isValid()) { NetworkManager::ConnectionSettings::Ptr connectSettingPtr = connectPtr->settings(); @@ -626,3 +654,28 @@ bool KyConnectResourse::isActivatedConnection(QString uuid) { return m_networkResourceInstance->isActiveConnection(uuid); } + +bool KyConnectResourse::isApConnection(QString uuid) +{ + NetworkManager::Connection::Ptr connectPtr = nullptr; + + connectPtr = m_networkResourceInstance->getConnect(uuid); + if (nullptr == connectPtr) { + return false; + } + + if (NetworkManager::ConnectionSettings::ConnectionType::Wireless + != connectPtr->settings()->connectionType()) { + return false; + } + + NetworkManager::ConnectionSettings::Ptr settingPtr = connectPtr->settings(); + NetworkManager::WirelessSetting::Ptr wirelessSetting + = settingPtr->setting(NetworkManager::Setting::Wireless).dynamicCast(); + if (NetworkManager::WirelessSetting::NetworkMode::Ap + != wirelessSetting->mode()) { + return false; + } + + return true; +} diff --git a/src/backend/dbus-interface/kylinconnectresource.h b/src/backend/dbus-interface/kylinconnectresource.h index 58798bb0..d33ea8f5 100644 --- a/src/backend/dbus-interface/kylinconnectresource.h +++ b/src/backend/dbus-interface/kylinconnectresource.h @@ -27,6 +27,8 @@ public: void getVpnConnections(QList &vpnConnectItemList); void getBluetoothConnections(QList &bluetoothConnectItemList); void getApConnections(QList &apConnectItemList); + KyApConnectItem *getApConnectionByUuid(QString connectUuid); + void getConnectionSetting(QString connectUuid, KyConnectSetting &connectSetting); bool getInterfaceByUuid(QString &deviceName, NetworkManager::ConnectionSettings::ConnectionType &type, const QString connUuid); void getConnectivity(NetworkManager::Connectivity &connectivity); @@ -34,6 +36,7 @@ public: bool isWiredConnection(QString uuid); bool isWirelessConnection(QString uuid); bool isActivatedConnection(QString uuid); + bool isApConnection(QString uuid); private: KyConnectItem *getConnectionItem(NetworkManager::Connection::Ptr connectPtr); diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp index b1156588..2ceeec0d 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp @@ -53,7 +53,7 @@ KyNetworkResourceManager::KyNetworkResourceManager(QObject *parent) : QObject(pa connect(NetworkManager::notifier(), &NetworkManager::Notifier::connectivityChanged, this, &KyNetworkResourceManager::connectivityChanged); //todo wifi开关信号 - connect(NetworkManager::notifier(), &NetworkManager::Notifier::wirelessEnabledChanged, this, &KyNetworkResourceManager::wifinEnabledChanged); + connect(NetworkManager::notifier(), &NetworkManager::Notifier::wirelessEnabledChanged, this, &KyNetworkResourceManager::wifiEnabledChanged); connect(NetworkManager::notifier(), &NetworkManager::Notifier::wirelessHardwareEnabledChanged, [=](){ }); @@ -208,8 +208,13 @@ void KyNetworkResourceManager::addConnection(NetworkManager::Connection::Ptr con void KyNetworkResourceManager::insertConnections() { - for (auto const & conn : NetworkManager::listConnections()) - addConnection(conn); + for (auto const & connectPtr : NetworkManager::listConnections()) { + if (connectPtr->name().isEmpty() || connectPtr->uuid().isEmpty()) { + qWarning() <<"[KyNetworkResourceManager]" << " the name of connection is empty."; + continue; + } + addConnection(connectPtr); + } } void KyNetworkResourceManager::removeDevice(int pos) @@ -771,6 +776,11 @@ void KyNetworkResourceManager::onConnectionAdded(QString const & path) qDebug() <<"[KyNetworkResourceManager]" <<"add connect "<< connectPtr->name() << connectPtr->path(); + if (connectPtr->name().isEmpty() || connectPtr->uuid().isEmpty()) { + qWarning() <<"[KyNetworkResourceManager]" << "the name or uuid of connection is empty"; + return; + } + if (0 > m_connections.indexOf(connectPtr)) { addConnection(connectPtr); emit connectionAdd(connectPtr->uuid()); diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.h b/src/backend/dbus-interface/kylinnetworkresourcemanager.h index 8503a4b4..f71a91b4 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.h +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.h @@ -125,7 +125,7 @@ signals: void wifiNetworkAdded(QString, QString); void wifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net); void wifiNetworkDeviceDisappear(); - void wifinEnabledChanged(bool); + void wifiEnabledChanged(bool); void activeConnectionsReset(); void activeConnectionAdd(QString uuid); diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.cpp b/src/backend/dbus-interface/kywirelessconnectoperation.cpp index 51569465..d96c3d38 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.cpp +++ b/src/backend/dbus-interface/kywirelessconnectoperation.cpp @@ -69,7 +69,8 @@ NetworkManager::ConnectionSettings::Ptr assembleWirelessSettings(const KyWireles KyWirelessConnectOperation::KyWirelessConnectOperation(QObject *parent) : KyConnectOperation(parent) { - connect(m_networkResourceInstance, &KyNetworkResourceManager::wifinEnabledChanged, this, &KyWirelessConnectOperation::wifinEnabledChanged); + connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiEnabledChanged, + this, &KyWirelessConnectOperation::wifiEnabledChanged); } KyWirelessConnectOperation::~KyWirelessConnectOperation() @@ -653,6 +654,7 @@ void KyWirelessConnectOperation::addAndActiveWirelessEnterPriseTtlsConnect(KyEap void KyWirelessConnectOperation::setWirelessEnabled(bool enabled) { NetworkManager::setWirelessEnabled(enabled); +#if 0 if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { QGSettings *gsetting = new QGSettings(GSETTINGS_SCHEMA); if (gsetting->get(WIRELESS_SWITCH).toBool() != enabled) { @@ -661,6 +663,7 @@ void KyWirelessConnectOperation::setWirelessEnabled(bool enabled) } else { qDebug()<<"isSchemaInstalled false"; } +#endif } bool KyWirelessConnectOperation::getWirelessEnabled() diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.h b/src/backend/dbus-interface/kywirelessconnectoperation.h index d160edb9..acbc3299 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.h +++ b/src/backend/dbus-interface/kywirelessconnectoperation.h @@ -116,7 +116,7 @@ private: signals: - void wifinEnabledChanged(bool); + void wifiEnabledChanged(bool); void addAndActivateConnectionError(QString errorMessage); private: diff --git a/src/backend/dbus-interface/kywirelessnetresource.cpp b/src/backend/dbus-interface/kywirelessnetresource.cpp index 6dc0988b..7c3fc631 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.cpp +++ b/src/backend/dbus-interface/kywirelessnetresource.cpp @@ -119,7 +119,7 @@ void KyWirelessNetResource::getWirelessActiveConnection(NetworkManager::ActiveCo qDebug() << "getWirelessActiveConnection " << activeConnectionPtr->uuid(); QString ssid; - QString ifaceName = getDeviceIFace(activeConnectionPtr,ssid); + QString ifaceName = getDeviceIFace(activeConnectionPtr, ssid); if(ifaceName.isEmpty() || ssid.isNull()) { continue; } @@ -134,6 +134,69 @@ void KyWirelessNetResource::getWirelessActiveConnection(NetworkManager::ActiveCo return; } +QString KyWirelessNetResource::getActiveConnectSsidByDevice(QString deviceName) +{ + QString ssid = ""; + + NetworkManager::ActiveConnection::List activeConnectionList; + activeConnectionList.clear(); + activeConnectionList = m_networkResourceInstance->getActiveConnectList(); + if (activeConnectionList.isEmpty()) { + return ssid; + } + + NetworkManager::ActiveConnection::Ptr activeConnectionPtr = nullptr; + for (int index; index < activeConnectionList.size(); index++) { + activeConnectionPtr = activeConnectionList.at(index); + if (activeConnectionPtr.isNull()) { + continue; + } + + if (NetworkManager::ConnectionSettings::ConnectionType::Wireless != activeConnectionPtr->type()) { + continue; + } + + if (NetworkManager::ActiveConnection::State::Activated != activeConnectionPtr->state()) { + continue; + } + + NetworkManager::Connection::Ptr connectPtr = activeConnectionPtr->connection(); + NetworkManager::ConnectionSettings::Ptr settingPtr = connectPtr->settings(); + if (deviceName != settingPtr->interfaceName()) { + continue; + } + + NetworkManager::WirelessSetting::Ptr wirelessSettingPtr = + settingPtr->setting(NetworkManager::Setting::Wireless).dynamicCast(); + ssid = wirelessSettingPtr->ssid(); + } + + return ssid; +} + +bool KyWirelessNetResource::getActiveWirelessNetItem(QString deviceName, KyWirelessNetItem &wirelessNetItem) +{ + if (!m_WifiNetworkList.contains(deviceName)) { + qDebug() << "getWifiNetwork fail,not contain " << deviceName; + return false; + } + + QString ssid = getActiveConnectSsidByDevice(deviceName); + if (ssid.isEmpty()) { + return false; + } + + for (int index = 0; index < m_WifiNetworkList[deviceName].size(); index ++){ + if (m_WifiNetworkList[deviceName].at(index).m_NetSsid == ssid) { + wirelessNetItem = m_WifiNetworkList[deviceName].at(index); + qDebug() << "getWifiNetwork success"; + return true; + } + } + + return false; +} + QString KyWirelessNetResource::getDeviceIFace(NetworkManager::ActiveConnection::Ptr actConn, QString &wirelessNetResourcessid) { @@ -160,23 +223,38 @@ QString KyWirelessNetResource::getDeviceIFace(NetworkManager::ActiveConnection:: return sett->interfaceName(); } -void KyWirelessNetResource::getSsidByUuid(const QString uuid, QString &ssid, QString &devName) +void KyWirelessNetResource::getSsidByUuid(const QString uuid, QString &ssid) { ssid.clear(); - devName.clear(); NetworkManager::Connection::Ptr connectPtr = m_networkResourceInstance->getConnect(uuid); if (connectPtr.isNull()) { return; } + NetworkManager::WirelessSetting::Ptr wireless_sett = connectPtr->settings()->setting(NetworkManager::Setting::Wireless).dynamicCast(); if (wireless_sett.isNull()) { qDebug() << "don't have WirelessSetting connection"; return; } + ssid = wireless_sett->ssid(); - devName = connectPtr->settings()->interfaceName(); qDebug() << "getSsidByUuid success " << ssid; + + return; +} + +void KyWirelessNetResource::getDeviceByUuid(const QString uuid, QString &deviceName) +{ + deviceName.clear(); + + NetworkManager::Connection::Ptr connectPtr = m_networkResourceInstance->getConnect(uuid); + if (connectPtr.isNull()) { + return; + } + + deviceName = connectPtr->settings()->interfaceName(); + return; } diff --git a/src/backend/dbus-interface/kywirelessnetresource.h b/src/backend/dbus-interface/kywirelessnetresource.h index c9ea8104..110bd355 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.h +++ b/src/backend/dbus-interface/kywirelessnetresource.h @@ -28,8 +28,11 @@ public: bool getEnterPriseInfoTtls(QString &uuid, KyEapMethodTtlsInfo &info); void getWirelessActiveConnection(NetworkManager::ActiveConnection::State state, QMap &map); + bool getActiveWirelessNetItem(QString deviceName, KyWirelessNetItem &wirelessNetItem); - void getSsidByUuid(const QString uuid, QString &ssid, QString &devName); + QString getActiveConnectSsidByDevice(QString deviceName); + void getSsidByUuid(const QString uuid, QString &ssid); + void getDeviceByUuid(const QString uuid, QString &deviceName); private: diff --git a/src/frontend/enterprise-wlan/enterprisewlandialog.cpp b/src/frontend/enterprise-wlan/enterprisewlandialog.cpp index bcf3c02b..14cfdad2 100644 --- a/src/frontend/enterprise-wlan/enterprisewlandialog.cpp +++ b/src/frontend/enterprise-wlan/enterprisewlandialog.cpp @@ -5,7 +5,7 @@ #define MAIN_SIZE_EXPAND 400,500 #define MAIN_SIZE_NARROW 400,400 -EnterpriseWlanDialog::EnterpriseWlanDialog(KyWirelessNetItem *data, QString device, QWidget *parent) : QDialog(parent) +EnterpriseWlanDialog::EnterpriseWlanDialog(KyWirelessNetItem &wirelessNetItem, QString device, QWidget *parent) : QDialog(parent) { //设置窗口无边框,阴影 #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) @@ -19,7 +19,7 @@ EnterpriseWlanDialog::EnterpriseWlanDialog(KyWirelessNetItem *data, QString devi #endif this->setAttribute(Qt::WA_DeleteOnClose); - m_data = data; + m_wirelessNetItem = wirelessNetItem; m_deviceName = device; m_connectOperation = new KyWirelessConnectOperation(); m_resource = new KyWirelessNetResource(); @@ -72,11 +72,8 @@ void EnterpriseWlanDialog::initUI() m_ssidTitleLabel = new QLabel(this); m_ssidTitleLabel->setText("SSID"); m_ssidLabel = new QLabel(this); - if (m_data) { - m_ssidLabel->setText(m_data->m_NetSsid); - } else { - qWarning() << "Get SSID failed because of null pointer!" << Q_FUNC_INFO << __LINE__; - } + m_ssidLabel->setText(m_wirelessNetItem.m_NetSsid); + m_ssidLayout->addWidget(m_ssidTitleLabel); m_ssidLayout->addStretch(); m_ssidLayout->addWidget(m_ssidLabel); @@ -130,9 +127,9 @@ void EnterpriseWlanDialog::initConnections() void EnterpriseWlanDialog::initData() { - if (m_data && m_data->m_isConfigured) { + if (m_wirelessNetItem.m_isConfigured) { KyEapMethodType type; - m_connectOperation->getEnterpiseEapMethod(m_data->m_connectUuid, type); + m_connectOperation->getEnterpiseEapMethod(m_wirelessNetItem.m_connectUuid, type); if (type) { onEapTypeChanged(type); } else { @@ -143,20 +140,18 @@ void EnterpriseWlanDialog::initData() void EnterpriseWlanDialog::onBtnConnectClicked() { - if (!m_data) { - qWarning() << "Connect enterprise WLAN failed because of null pointer m_data!" << Q_FUNC_INFO << __LINE__; - } - qDebug() << "Clicked connectBtn, will connect enterprise WLAN, ssid = " << m_data->m_NetSsid << "." << Q_FUNC_INFO << __LINE__; + qDebug() << "Clicked connectBtn, will connect enterprise WLAN, ssid = " + << m_wirelessNetItem.m_NetSsid << "." << Q_FUNC_INFO << __LINE__; KySecuType secuType; KyEapMethodType eapType; m_securityPage->getSecuType(secuType, eapType); KyWirelessConnectSetting connetSetting; - connetSetting.setConnectName(m_data->m_NetSsid); + connetSetting.setConnectName(m_wirelessNetItem.m_NetSsid); connetSetting.setIfaceName(m_deviceName); connetSetting.isAutoConnect = true; //ZJP_TODO 自动连接选项 connetSetting.m_type = KyKeyMgmt::WpaEap; - connetSetting.m_ssid = m_data->m_NetSsid; + connetSetting.m_ssid = m_wirelessNetItem.m_NetSsid; connetSetting.m_secretFlag = 0; connetSetting.dumpInfo(); @@ -179,22 +174,22 @@ void EnterpriseWlanDialog::onEapTypeChanged(const KyEapMethodType &type) { switch (type) { case KyEapMethodType::TLS: - if (m_data && !m_data->m_connectUuid.isEmpty()) { - m_resource->getEnterPriseInfoTls(m_data->m_connectUuid, m_info.tlsInfo); + if (!m_wirelessNetItem.m_connectUuid.isEmpty()) { + m_resource->getEnterPriseInfoTls(m_wirelessNetItem.m_connectUuid, m_info.tlsInfo); m_securityPage->setTlsInfo(m_info.tlsInfo); } this->setFixedSize(MAIN_SIZE_EXPAND); break; case KyEapMethodType::PEAP: - if (m_data && !m_data->m_connectUuid.isEmpty()) { - m_resource->getEnterPriseInfoPeap(m_data->m_connectUuid, m_info.peapInfo); + if (m_wirelessNetItem.m_connectUuid.isEmpty()) { + m_resource->getEnterPriseInfoPeap(m_wirelessNetItem.m_connectUuid, m_info.peapInfo); m_securityPage->setPeapInfo(m_info.peapInfo); } this->setFixedSize(MAIN_SIZE_NARROW); break; case KyEapMethodType::TTLS: - if (m_data && !m_data->m_connectUuid.isEmpty()) { - m_resource->getEnterPriseInfoTtls(m_data->m_connectUuid, m_info.ttlsInfo); + if (!m_wirelessNetItem.m_connectUuid.isEmpty()) { + m_resource->getEnterPriseInfoTtls(m_wirelessNetItem.m_connectUuid, m_info.ttlsInfo); m_securityPage->setTtlsInfo(m_info.ttlsInfo); } this->setFixedSize(MAIN_SIZE_NARROW); diff --git a/src/frontend/enterprise-wlan/enterprisewlandialog.h b/src/frontend/enterprise-wlan/enterprisewlandialog.h index a3260944..43891a11 100644 --- a/src/frontend/enterprise-wlan/enterprisewlandialog.h +++ b/src/frontend/enterprise-wlan/enterprisewlandialog.h @@ -10,7 +10,7 @@ class EnterpriseWlanDialog : public QDialog { Q_OBJECT public: - EnterpriseWlanDialog(KyWirelessNetItem *data, QString device, QWidget *parent = nullptr); + EnterpriseWlanDialog(KyWirelessNetItem &wirelessNetItem, QString device, QWidget *parent = nullptr); ~EnterpriseWlanDialog(); private: @@ -20,7 +20,7 @@ private: void initData(); private: - KyWirelessNetItem *m_data = nullptr; + KyWirelessNetItem m_wirelessNetItem; ConInfo m_info; QString m_deviceName; KyWirelessConnectOperation *m_connectOperation = nullptr; diff --git a/src/frontend/list-items/listitem.cpp b/src/frontend/list-items/listitem.cpp index 021402c0..d3fdc249 100644 --- a/src/frontend/list-items/listitem.cpp +++ b/src/frontend/list-items/listitem.cpp @@ -13,10 +13,10 @@ ListItem::ListItem(QWidget *parent) : QFrame(parent) { + m_connectState = UnknownState; initUI(); initConnection(); connect(qApp, &QApplication::paletteChanged, this, &ListItem::onPaletteChanged); -// m_itemFrame->installEventFilter(this); } ListItem::~ListItem() @@ -45,6 +45,11 @@ void ListItem::setActive(const bool &isActive) m_isActive = isActive; } +void ListItem::setConnectState(ConnectState state) +{ + m_connectState = state; +} + void ListItem::showDesktopNotify(const QString &message) { QDBusInterface iface("org.freedesktop.Notifications", @@ -65,6 +70,7 @@ void ListItem::showDesktopNotify(const QString &message) void ListItem::mousePressEvent(QMouseEvent *event) { + qDebug()<<"[WlanListItem]"<<"mousePressEvent"; if (event->button() == Qt::LeftButton) { onNetButtonClicked(); } else if (event->button() == Qt::RightButton) { diff --git a/src/frontend/list-items/listitem.h b/src/frontend/list-items/listitem.h index 36f04f97..55c72221 100644 --- a/src/frontend/list-items/listitem.h +++ b/src/frontend/list-items/listitem.h @@ -9,6 +9,14 @@ #include "infobutton.h" #include "netdetails/netdetail.h" +typedef enum{ + UnknownState = 0, /**< The active connection is in an unknown state */ + Activating, /**< The connection is activating */ + Activated, /**< The connection is activated */ + Deactivating, /**< The connection is being torn down and cleaned up */ + Deactivated /**< The connection is no longer active */ +}ConnectState; + class ListItem : public QFrame { Q_OBJECT @@ -17,6 +25,7 @@ public: ~ListItem(); void setName(const QString &name); void setActive(const bool &isActive); + void setConnectState(ConnectState state); static void showDesktopNotify(const QString &message); protected: @@ -35,6 +44,7 @@ protected: InfoButton * m_infoButton = nullptr; bool m_isActive = false; + ConnectState m_connectState; public: QVBoxLayout * m_mainLayout = nullptr; diff --git a/src/frontend/list-items/wlanlistitem.cpp b/src/frontend/list-items/wlanlistitem.cpp index 03925255..f2096828 100644 --- a/src/frontend/list-items/wlanlistitem.cpp +++ b/src/frontend/list-items/wlanlistitem.cpp @@ -2,23 +2,32 @@ #include #include "enterprisewlandialog.h" -WlanListItem::WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *data, QString device, QWidget *parent) : ListItem(parent) +#define EMPTY_SSID "EMPTY_SSID" +#define LOG_FLAG "[WlanListItem]" +#define WAIT_US 70*1000 + +WlanListItem::WlanListItem(KyWirelessNetItem &wirelessNetItem, QString device, QWidget *parent) : ListItem(parent) { - m_data = data; - m_resource = resource; m_wlanDevice = device; - m_connoperation = new KyWirelessConnectOperation(this); - m_connectResource = new KyActiveConnectResourse(); + m_wirelessNetItem = wirelessNetItem; + + qDebug()<<"[WlanPage] wlan list item is created." << m_wirelessNetItem.m_NetSsid; + initWlanUI(); setExpanded(false); - initWlanConnection(); + + connect(this->m_infoButton, &InfoButton::clicked, this, &WlanListItem::onInfoButtonClicked); m_menu = new QMenu();//右键菜单 connect(m_menu, &QMenu::triggered, this, &WlanListItem::onMenuTriggered); + + m_wirelessConnectOperation = new KyWirelessConnectOperation(this); } WlanListItem::WlanListItem(QWidget *parent) : ListItem(parent) { + m_wirelessNetItem.m_NetSsid = EMPTY_SSID; + qDebug()<<"[WlanPage] wlan list item is created." << m_wirelessNetItem.m_NetSsid; m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-none-symbolic")); const QString name = tr("Not connected"); setExpanded(false); @@ -29,24 +38,24 @@ WlanListItem::WlanListItem(QWidget *parent) : ListItem(parent) WlanListItem::~WlanListItem() { - disconnect(m_resource, &KyWirelessNetResource::secuTypeChange, this, &WlanListItem::onSecurityChanged); - disconnect(m_resource, &KyWirelessNetResource::connectionAdd, this, &WlanListItem::onConnectionAdd); - disconnect(m_resource, &KyWirelessNetResource::connectionRemove, this, &WlanListItem::onConnectionRemove); - disconnect(this->m_infoButton, &InfoButton::clicked, this, &WlanListItem::onInfoButtonClicked); + qDebug()<<"[WlanPage] wlan list item is deleted." << m_wirelessNetItem.m_NetSsid; +} + +QString WlanListItem::getSsid() +{ + return m_wirelessNetItem.m_NetSsid; } void WlanListItem::setWlanSignal(const int &signal) { - if (!m_data){ - return; - } - m_data->m_signalStrength = signal; + m_wirelessNetItem.m_signalStrength = signal; + refreshIcon(); } void WlanListItem::setWlanState(const int &state) { -// m_data->m_state = state; //ZJP_TODO 后端接口待补全 +// m_wirelessNetItem.m_state = state; //ZJP_TODO 后端接口待补全 refreshIcon(); } @@ -56,81 +65,112 @@ void WlanListItem::setExpanded(const bool &expanded) this->setFixedHeight(NORMAL_HEIGHT); return; } - this->setFixedHeight(expanded ? EXPANDED_HEIGHT : NORMAL_HEIGHT); m_pwdFrame->setVisible(expanded); m_autoConnectFrame->setVisible(expanded); - emit this->itemHeightChanged(m_data->m_NetSsid); - if (!expanded) { + + if (expanded) { + m_pwdLineEdit->setFocus(); + setFixedHeight(EXPANDED_HEIGHT); + } else { + setFixedHeight(NORMAL_HEIGHT); QPalette pal = qApp->palette(); pal.setColor(QPalette::Window, qApp->palette().base().color()); this->setPalette(pal); } -} -QString WlanListItem::getSsid() -{ - if (!m_data) { - return QString(); - } else { - return m_data->m_NetSsid; - } + emit this->itemHeightChanged(expanded, m_wirelessNetItem.m_NetSsid); + + return; } void WlanListItem::resizeEvent(QResizeEvent *event) { this->blockSignals(true); + if (this->height() == EXPANDED_HEIGHT) { this->setExpanded(true); } else { this->setExpanded(false); } + this->blockSignals(false); + return ListItem::resizeEvent(event); } void WlanListItem::onRightButtonClicked() { + qDebug()<< LOG_FLAG <<"onRightButtonClicked"; + if (!m_menu) { return; } + m_menu->clear(); - if (!this->m_data) { + + if (Activated == m_connectState) { + m_menu->addAction(new QAction(tr("Disconnect"), this)); + } else if (Deactivated == m_connectState) { + m_menu->addAction(new QAction(tr("Connect"), this)); + } else { return; } - if (this->m_isActive) { - m_menu->addAction(new QAction(tr("Disconnect"), this)); - } else { - m_menu->addAction(new QAction(tr("Connect"), this)); - } - if (m_data->m_isConfigured) + + if (m_wirelessNetItem.m_isConfigured) { m_menu->addAction(new QAction(tr("Forget"), this)); + } + m_menu->move(cursor().pos()); m_menu->show(); + + return; } void WlanListItem::enterEvent(QEvent *event) { - if (m_data) { - return ListItem::enterEvent(event); - } else { - return QFrame::enterEvent(event); - } + qDebug()<< LOG_FLAG <<"enterEvent" << m_wirelessNetItem.m_NetSsid; + m_mouseIsOut = false; + return ListItem::enterEvent(event); } void WlanListItem::leaveEvent(QEvent *event) { + qDebug()<< LOG_FLAG <<"leaveEvent"<< m_wirelessNetItem.m_NetSsid; + m_mouseIsOut = true; if (m_pwdFrame && m_pwdFrame->isVisible()) { + if (m_focusIsOut) { + setExpanded(false); + } return QFrame::leaveEvent(event); } + return ListItem::leaveEvent(event); } +bool WlanListItem::eventFilter(QObject *watched, QEvent *event) +{ + if (watched == m_pwdLineEdit) { + if (event->type() == QEvent::FocusOut) { + m_focusIsOut = true; + qDebug()<< LOG_FLAG <<"focusOutEvent" << m_wirelessNetItem.m_NetSsid; + if (m_mouseIsOut) { + setExpanded(false); + } + } else if (event->type() == QEvent::FocusIn) { + qDebug()<< LOG_FLAG <<"focusInEvent" << m_wirelessNetItem.m_NetSsid; + m_focusIsOut = false; + } + } + + return QFrame::eventFilter(watched, event); +} + void WlanListItem::initWlanUI() { - m_hasPwd = (m_data->m_secuType.isEmpty() || m_data->m_secuType == "") ? false : true; + m_hasPwd = (m_wirelessNetItem.m_secuType.isEmpty() || m_wirelessNetItem.m_secuType == "") ? false : true; //设置显示的Wlan名称 - this->setName((m_data->m_connName != "") ? m_data->m_connName : m_data->m_NetSsid); + this->setName((m_wirelessNetItem.m_connName != "") ? m_wirelessNetItem.m_connName : m_wirelessNetItem.m_NetSsid); //刷新左侧按钮图标 refreshIcon(); @@ -147,63 +187,60 @@ void WlanListItem::initWlanUI() m_pwdFrameLyt->setContentsMargins(FRAME_CONTENT_MARGINS); m_pwdFrameLyt->setSpacing(FRAME_SPACING); m_pwdFrame->setLayout(m_pwdFrameLyt); - { - m_pwdLineEdit = new QLineEdit(m_pwdFrame); - connect(m_pwdLineEdit, &QLineEdit::textChanged, this, &WlanListItem::onPwdEditorTextChanged); - m_pwdLineEdit->setFixedHeight(PWD_AREA_HEIGHT); - m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Password); - m_pwdLineEdit->setTextMargins(PWD_CONTENT_MARGINS); - m_pwdLineEditLyt = new QHBoxLayout(m_pwdLineEdit); - m_pwdLineEditLyt->setContentsMargins(PWD_LAYOUT_MARGINS); - m_pwdLineEdit->setLayout(m_pwdLineEditLyt); - m_showPwdButton = new QPushButton(m_pwdLineEdit); - m_showPwdButton->setFixedSize(SHOW_PWD_BUTTON_SIZE); - m_showPwdButton->setAutoFillBackground(false); - m_showPwdButton->setIcon(QIcon(":/res/h/hide-pwd.png")); - m_showPwdButton->setCursor(Qt::PointingHandCursor); - connect(m_showPwdButton, &QPushButton::clicked, this, &WlanListItem::onShowPwdButtonClicked); - m_pwdLineEditLyt->addStretch(); - m_pwdLineEditLyt->addWidget(m_showPwdButton); - } + + m_pwdLineEdit = new QLineEdit(m_pwdFrame); + m_pwdLineEdit->installEventFilter(this); + connect(m_pwdLineEdit, &QLineEdit::textChanged, this, &WlanListItem::onPwdEditorTextChanged); + m_pwdLineEdit->setFixedHeight(PWD_AREA_HEIGHT); + m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Password); + m_pwdLineEdit->setTextMargins(PWD_CONTENT_MARGINS); + m_pwdFrameLyt->addWidget(m_pwdLineEdit); + + m_pwdLineEditLyt = new QHBoxLayout(m_pwdLineEdit); + m_pwdLineEditLyt->setContentsMargins(PWD_LAYOUT_MARGINS); + m_pwdLineEdit->setLayout(m_pwdLineEditLyt); + + m_showPwdButton = new QPushButton(m_pwdLineEdit); + m_showPwdButton->setFixedSize(SHOW_PWD_BUTTON_SIZE); + m_showPwdButton->setAutoFillBackground(false); + m_showPwdButton->setIcon(QIcon(":/res/h/hide-pwd.png")); + m_showPwdButton->setCursor(Qt::PointingHandCursor); + connect(m_showPwdButton, &QPushButton::clicked, this, &WlanListItem::onShowPwdButtonClicked); + m_pwdLineEditLyt->addStretch(); + m_pwdLineEditLyt->addWidget(m_showPwdButton); + m_connectButton = new QPushButton(m_pwdFrame); m_connectButton->setFixedSize(CONNECT_BUTTON_WIDTH, PWD_AREA_HEIGHT); m_connectButton->setText(tr("Connect")); m_connectButton->setEnabled(false); connect(m_connectButton, &QPushButton::clicked, this, &WlanListItem::onConnectButtonClicked); - m_pwdFrameLyt->addWidget(m_pwdLineEdit); m_pwdFrameLyt->addWidget(m_connectButton); //自动连接选择区域UI m_autoConnectFrame = new QFrame(this); + m_autoConnectFrameLyt = new QHBoxLayout(m_autoConnectFrame); m_autoConnectFrameLyt->setContentsMargins(FRAME_CONTENT_MARGINS); m_autoConnectFrameLyt->setSpacing(FRAME_SPACING); m_autoConnectFrame->setLayout(m_autoConnectFrameLyt); + m_autoConnectCheckBox = new QCheckBox(m_autoConnectFrame); m_autoConnectCheckBox->setChecked(true); m_autoConnectCheckBox->setFixedSize(SHOW_PWD_BUTTON_SIZE); + m_autoConnectFrameLyt->addWidget(m_autoConnectCheckBox); + m_autoConnectLabel = new QLabel(m_autoConnectFrame); m_autoConnectLabel->setText(tr("Auto Connect")); - m_autoConnectFrameLyt->addWidget(m_autoConnectCheckBox); m_autoConnectFrameLyt->addWidget(m_autoConnectLabel); m_autoConnectFrameLyt->addStretch(); m_mainLayout->addWidget(m_pwdFrame); m_mainLayout->addWidget(m_autoConnectFrame); + m_pwdFrame->hide(); m_autoConnectFrame->hide(); } -void WlanListItem::initWlanConnection() -{ - connect(m_resource, &KyWirelessNetResource::secuTypeChange, this, &WlanListItem::onSecurityChanged); - connect(m_resource, &KyWirelessNetResource::connectionAdd, this, &WlanListItem::onConnectionAdd); - connect(m_resource, &KyWirelessNetResource::connectionRemove, this, &WlanListItem::onConnectionRemove); - connect(this->m_infoButton, &InfoButton::clicked, this, &WlanListItem::onInfoButtonClicked); - connect(m_connectResource, &KyActiveConnectResourse::stateChangeReason, this, &WlanListItem::onWlanStatusChange); - connect(m_netButton, &RadioItemButton::animationStoped, this, &WlanListItem::refreshIcon); -} - void WlanListItem::refreshIcon() { #define FULL_SIGNAL 5 @@ -212,45 +249,54 @@ void WlanListItem::refreshIcon() #define OK_SIGNAL 2 #define LOW_SIGNAL 1 #define STEP 25 -// if (m_data->m_state) //ZJP_TODO 连接中、已连接、未连接的处理,要单独写逻辑,后端接口待补全 if (!m_hasPwd) { //ZJP_TODO 无加密 注意信号格数计算方式,可能需要修改 - switch (m_data->m_signalStrength / STEP + 1) { + switch (m_wirelessNetItem.m_signalStrength / STEP + 1) { case FULL_SIGNAL: case EXCELLENT_SIGNAL: - m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-excellent-symbolic", QIcon(":/res/w/wifi-full.png"))); + m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-excellent-symbolic", + QIcon(":/res/w/wifi-full.png"))); break; case GOOD_SIGNAL: - m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-good-symbolic", QIcon(":/res/w/wifi-high.png"))); + m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-good-symbolic", + QIcon(":/res/w/wifi-high.png"))); break; case OK_SIGNAL: - m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-ok", QIcon(":/res/w/wifi-medium.png"))); + m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-ok", + QIcon(":/res/w/wifi-medium.png"))); break; case LOW_SIGNAL: - m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-low", QIcon(":/res/w/wifi-low.png"))); + m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-low", + QIcon(":/res/w/wifi-low.png"))); break; default: - qDebug() << "Set wlan(without passwd) icon failed, signal = " << m_data->m_signalStrength << Q_FUNC_INFO << __LINE__; + qDebug() << "Set wlan(without passwd) icon failed, signal = " + << m_wirelessNetItem.m_signalStrength << Q_FUNC_INFO << __LINE__; break; } } else { //ZJP_TODO 有加密 - switch (m_data->m_signalStrength / STEP + 1) { + switch (m_wirelessNetItem.m_signalStrength / STEP + 1) { case FULL_SIGNAL: case EXCELLENT_SIGNAL: - m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-excellent-secure-symbolic", QIcon(":/res/w/wifi-full-pwd.png"))); + m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-excellent-secure-symbolic", + QIcon(":/res/w/wifi-full-pwd.png"))); break; case GOOD_SIGNAL: - m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-good-secure-symbolic", QIcon(":/res/w/wifi-high-pwd.png"))); + m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-good-secure-symbolic", + QIcon(":/res/w/wifi-high-pwd.png"))); break; case OK_SIGNAL: - m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-ok-secure-symbolic", QIcon(":/res/w/wifi-medium-pwd.png"))); + m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-ok-secure-symbolic", + QIcon(":/res/w/wifi-medium-pwd.png"))); break; case LOW_SIGNAL: - m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-low-secure-symbolic", QIcon(":/res/w/wifi-low-pwd.png"))); + m_netButton->setButtonIcon(QIcon::fromTheme("network-wireless-signal-low-secure-symbolic", + QIcon(":/res/w/wifi-low-pwd.png"))); break; default: - qDebug() << "Set wlan(with passwd) icon failed, signal = " << m_data->m_signalStrength << Q_FUNC_INFO << __LINE__; + qDebug() << "Set wlan(with passwd) icon failed, signal = " + << m_wirelessNetItem.m_signalStrength << Q_FUNC_INFO << __LINE__; break; } } @@ -258,88 +304,90 @@ void WlanListItem::refreshIcon() void WlanListItem::onInfoButtonClicked() { - //ZJP_TODO 呼出无线详情页 - if(m_data){ - qDebug()<<"Net active or not:"<m_NetSsid, m_data->m_connectUuid, m_isActive, true, !m_data->m_isConfigured, this); - netDetail->show(); - } - else{ - qDebug() << "On wlan info button clicked! But there is no wlan connect " ; + qDebug() << LOG_FLAG << "Net active or not:"<< m_connectState; + qDebug() << LOG_FLAG << "On wlan info button clicked! ssid = " + << m_wirelessNetItem.m_NetSsid << "; name = " + << m_wirelessNetItem.m_connName << "." <show(); } void WlanListItem::onNetButtonClicked() { - if(!m_data){ - qDebug() << "On wlan clicked! But there is no wlan connect!" << Q_FUNC_INFO << __LINE__; + qDebug() << LOG_FLAG << "onNetButtonClicked"; + if (m_wirelessNetItem.m_NetSsid == EMPTY_SSID) { return; } - if ((m_state == NetworkManager::ActiveConnection::State::Activating || m_state == NetworkManager::ActiveConnection::State::Deactivating)) { - qDebug() << "On wlan clicked! But there is nothing to do because it is already activating/deactivating!" << Q_FUNC_INFO << __LINE__; + + if ((Activating == m_connectState || Deactivating == m_connectState)) { + qDebug() << LOG_FLAG << "On wlan clicked! But there is nothing to do because it is already activating/deactivating!" + << Q_FUNC_INFO << __LINE__; return; } //执行连接或断开 - if (m_isActive) { - m_connoperation->deActivateWirelessConnection(m_wlanDevice, m_data->m_connectUuid); - qDebug()<<"Clicked on connected wifi, it will be inactivated. ssid = " << m_data->m_NetSsid << Q_FUNC_INFO << __LINE__; + if (Activated == m_connectState) { + m_wirelessConnectOperation->deActivateWirelessConnection(m_wlanDevice, m_wirelessNetItem.m_connectUuid); + qDebug()<<"[WlanListItem] Clicked on connected wifi, it will be inactivated. ssid = " + << m_wirelessNetItem.m_NetSsid << Q_FUNC_INFO << __LINE__; return; } -//有配置的wifi直接连接 - if (m_data->m_isConfigured) { -// this->onConnectButtonClicked(); - m_connoperation->activeWirelessConnect(m_wlanDevice, m_data->m_connectUuid);//初始化没有uuid只有激活一次才有uuid - qDebug() << "Has configuration, will be activated. ssid = " << m_data->m_NetSsid << m_wlanDevice << m_data->m_connectUuid << Q_FUNC_INFO << __LINE__; + + //有配置或者无密码的wifi直接连接 + if (m_wirelessNetItem.m_isConfigured || m_hasPwd == false) { + m_wirelessConnectOperation->activeWirelessConnect(m_wlanDevice, m_wirelessNetItem.m_connectUuid); + qDebug()<<"[WlanListItem] Has configuration, will be activated. ssid = " + << m_wirelessNetItem.m_NetSsid << Q_FUNC_INFO << __LINE__; return; } - if (!this->m_connectButton->isVisible() && m_data->m_secuType != "") { - if (m_data->m_secuType.contains("802.1x", Qt::CaseInsensitive)) { - EnterpriseWlanDialog *enterpriseWlanDialog = new EnterpriseWlanDialog(m_data, m_wlanDevice, this); + + if (!this->m_connectButton->isVisible() && m_wirelessNetItem.m_secuType != "") { + if (m_wirelessNetItem.m_secuType.contains("802.1x", Qt::CaseInsensitive)) { + EnterpriseWlanDialog *enterpriseWlanDialog = new EnterpriseWlanDialog(m_wirelessNetItem, m_wlanDevice, this); enterpriseWlanDialog->show(); } else { this->setExpanded(true); } - } else { //无密码的情况 + } else { onConnectButtonClicked(); } + + return; } -//void WlanListItem::onNameLableClicked() -//{ -// m_mainLayout = new QVBoxLayout(this); -// m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS); -// m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING); -// this->setLayout(m_mainLayout); - -// m_itemFrame = new QFrame(this); - -// m_hItemLayout = new QHBoxLayout(m_itemFrame); -// m_hItemLayout->setContentsMargins(ITEM_FRAME_MARGINS); -// m_hItemLayout->setSpacing(ITEM_FRAME_SPACING); - -// m_lineEdit = new QLineEdit(m_itemFrame); - -// m_hItemLayout->addWidget(m_lineEdit); -// m_hItemLayout->addStretch(); - -// m_mainLayout->addWidget(m_itemFrame); -//} - -void WlanListItem::onSecurityChanged(QString interface, QString ssid, QString securityType) +void WlanListItem::updateWirelessNetSecurity(QString ssid, QString securityType) { - if (ssid != m_data->m_NetSsid) { + if (ssid != m_wirelessNetItem.m_NetSsid) { return; } - qDebug() << "Security changed! ssid = " << m_data->m_NetSsid << "; security = " << m_data->m_secuType << "." <m_secuType = securityType; - bool newSecu = (m_data->m_secuType.isEmpty() || m_data->m_secuType == "") ? false : true; + + qDebug() << LOG_FLAG << "Security changed! ssid = " << m_wirelessNetItem.m_NetSsid + << "; security = " << m_wirelessNetItem.m_secuType << "." <text().length() < PWD_LENGTH_LIMIT) { m_connectButton->setEnabled(false); } else { m_connectButton->setEnabled(true); } + + return; } void WlanListItem::onShowPwdButtonClicked() { + qDebug()<< LOG_FLAG << "onShowPwdButtonClicked"; if (!m_pwdLineEdit) { return; } + if (m_pwdLineEdit->echoMode() == QLineEdit::EchoMode::Password) { m_showPwdButton->setIcon(QIcon(":/res/h/show-pwd.png")); m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Normal); @@ -366,74 +419,68 @@ void WlanListItem::onShowPwdButtonClicked() m_showPwdButton->setIcon(QIcon(":/res/h/hide-pwd.png")); m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Password); } + + return; } void WlanListItem::onConnectButtonClicked() { - if (m_data->m_secuType.isEmpty() || m_data->m_secuType == "") { - qDebug() << "connect to no password wifi" << Q_FUNC_INFO << __LINE__; - } else if ((!m_connectButton->isEnabled()&&m_connectButton->isVisible()) || !m_data) { + qDebug()<< LOG_FLAG << "onConnectButtonClicked"; + if (!m_connectButton->isEnabled()) { return; } - if ((m_state == NetworkManager::ActiveConnection::State::Activating || m_state == NetworkManager::ActiveConnection::State::Deactivating)) { - qDebug() << "On wlan clicked! But there is nothing to do because it is already activating/deactivating!" << Q_FUNC_INFO << __LINE__; + if ((Activating == m_connectState || Deactivating == m_connectState)) { + qDebug() << LOG_FLAG << "On wlan clicked! But there is nothing to do because it is already activating/deactivating!" + << Q_FUNC_INFO << __LINE__; return; } KyWirelessConnectSetting settings; - settings.m_connectName = m_data->m_NetSsid; - settings.m_ssid = m_data->m_NetSsid; + settings.m_connectName = m_wirelessNetItem.m_NetSsid; + settings.m_ssid = m_wirelessNetItem.m_NetSsid; settings.isAutoConnect = m_autoConnectCheckBox->isChecked(); - settings.m_psk = m_pwdLineEdit->text(); - if (m_data->m_secuType.isEmpty() || m_data->m_secuType == "") { - qDebug() << "connect to no password wifi" << Q_FUNC_INFO << __LINE__; + settings.m_psk = m_pwdLineEdit->text(); + if (m_wirelessNetItem.m_secuType.isEmpty() || m_wirelessNetItem.m_secuType == "") { settings.m_type = WpaNone; - } else if (m_data->m_secuType.contains("WPA1") || m_data->m_secuType.contains("WPA2")) { + } else if (m_wirelessNetItem.m_secuType.contains("WPA1") || m_wirelessNetItem.m_secuType.contains("WPA2")) { settings.m_type = WpaPsk; - } else if (m_data->m_secuType.contains("WPA3")) { + } else if (m_wirelessNetItem.m_secuType.contains("WPA3")) { settings.m_type = SAE; } - qDebug() << "On button connect clicked, will connect wlan. ssid = " << m_data->m_NetSsid << Q_FUNC_INFO <<__LINE__; - emit this->connectButtonClicked(settings, false); + qDebug() << "[WlanListItem] On button connect clicked, will connect wlan. ssid = " + << m_wirelessNetItem.m_NetSsid << Q_FUNC_INFO <<__LINE__; + + m_wirelessConnectOperation->addAndActiveWirelessConnect(m_wlanDevice, settings, false); + setExpanded(false); + return; } -void WlanListItem::onConnectionAdd(QString deviceName, QString ssid) +void WlanListItem::connectStateIsChanging() { - if (!m_data) { - return; - } - if (ssid == m_data->m_NetSsid && deviceName == m_wlanDevice) { - m_resource->getWifiNetwork(deviceName, ssid, *m_data); - } + m_netButton->startLoading(); + + return; } -void WlanListItem::onConnectionRemove(QString deviceName, QString ssid) +void WlanListItem::connectStateChanged() { - if (!m_data) { - return; - } - if (ssid == m_data->m_NetSsid && deviceName == m_wlanDevice) { - m_resource->getWifiNetwork(deviceName, ssid, *m_data); - } + m_netButton->stopLoading(); + + return; } -void WlanListItem::onWlanStatusChange(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason) +void WlanListItem::updateConnectState(ConnectState state) { - QString ssid, devName; - m_resource->getSsidByUuid(uuid, ssid, devName); - //有可能配置被删了,获取不到ssid,所以也可以按uuid判断(解决连接中点忘记网络,图标还在loading的问题) - if (m_data->m_NetSsid == ssid || m_data->m_connectUuid == uuid) { - qDebug() << "[WlanPage] State changed to :" << state << Q_FUNC_INFO <<__LINE__; - m_state = state; - if ((state == NetworkManager::ActiveConnection::State::Activating || state == NetworkManager::ActiveConnection::State::Deactivating) - && devName == m_wlanDevice) { - m_netButton->startLoading(); - } else { - m_netButton->stopLoading(); - } + m_connectState = state; + if (Deactivated == state || Activated == state) { + m_netButton->stopLoading(); + } else { + m_netButton->startLoading(); } + + return; } void WlanListItem::onMenuTriggered(QAction *action) @@ -441,7 +488,14 @@ void WlanListItem::onMenuTriggered(QAction *action) if (action->text() == tr("Disconnect") || action->text() == tr("Connect")) { this->onNetButtonClicked(); } else if (action->text() == tr("Forget")) { - m_connoperation->deleteWirelessConnect(m_data->m_connectUuid); + if (Activated == m_connectState) { + m_wirelessConnectOperation->deActivateWirelessConnection(m_wlanDevice, m_wirelessNetItem.m_connectUuid); + ::usleep(WAIT_US); + } + + m_wirelessConnectOperation->deleteWirelessConnect(m_wirelessNetItem.m_connectUuid); } + + return; } diff --git a/src/frontend/list-items/wlanlistitem.h b/src/frontend/list-items/wlanlistitem.h index 56b554d4..111afc6a 100644 --- a/src/frontend/list-items/wlanlistitem.h +++ b/src/frontend/list-items/wlanlistitem.h @@ -22,36 +22,42 @@ class WlanListItem : public ListItem { Q_OBJECT public: - WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *data, QString device, QWidget *parent = nullptr); + WlanListItem(KyWirelessNetItem &wirelessNetItem, QString device, QWidget *parent = nullptr); WlanListItem(QWidget *parent = nullptr); ~WlanListItem(); public: + QString getSsid(); + void setWlanSignal(const int &signal); void setWlanState(const int &state); void setExpanded(const bool &expanded); - QString getSsid(); - KyWirelessNetItem *m_data = nullptr; + + void connectStateIsChanging(); + void connectStateChanged(); + + void updateConnectState(ConnectState state); + void updateWirelessNetSecurity(QString ssid, QString securityType); + void updateWirelessNetItem(KyWirelessNetItem &wirelessNetItem); + protected: void resizeEvent(QResizeEvent *event); void onRightButtonClicked(); void enterEvent(QEvent *event); void leaveEvent(QEvent *event); + bool eventFilter(QObject *watched, QEvent *event); signals: - void itemHeightChanged(const QString &ssid); - void connectButtonClicked(KyWirelessConnectSetting &connSettingInfo, const bool &isHidden); + void itemHeightChanged(const bool isExpanded, const QString &ssid); private: void initWlanUI(); - void initWlanConnection(); void refreshIcon(); private: - KyWirelessNetResource *m_resource = nullptr; + KyWirelessNetItem m_wirelessNetItem; + KyWirelessConnectOperation *m_wirelessConnectOperation = nullptr; - KyWirelessConnectOperation *m_connoperation = nullptr; - KyActiveConnectResourse *m_connectResource = nullptr; bool m_hasPwd = true; QString m_wlanDevice; @@ -62,7 +68,6 @@ private: QLineEdit * m_pwdLineEdit = nullptr; QHBoxLayout *m_pwdLineEditLyt = nullptr; QPushButton *m_showPwdButton = nullptr; - QPushButton *m_connectButton = nullptr; //自动连接选择区域UI @@ -73,28 +78,17 @@ private: QMenu *m_menu = nullptr; - NetworkManager::ActiveConnection::State m_state; + bool m_focusIsOut = true; + bool m_mouseIsOut = true; -// QVBoxLayout * m_mainLayout = nullptr; -// QFrame * m_itemFrame = nullptr; -// QHBoxLayout * m_hItemLayout = nullptr; -// QLineEdit * m_lineEdit = nullptr; protected slots: void onInfoButtonClicked(); private slots: -// void onInfoButtonClicked(); void onNetButtonClicked(); -// void onNameLableClicked(); - void onSecurityChanged(QString interface, QString ssid, QString securityType); void onPwdEditorTextChanged(); void onShowPwdButtonClicked(); void onConnectButtonClicked(); - void onConnectionAdd(QString deviceName, QString ssid); - void onConnectionRemove(QString deviceName, QString ssid); - void onWlanStatusChange(QString uuid, - NetworkManager::ActiveConnection::State state, - NetworkManager::ActiveConnection::Reason reason); void onMenuTriggered(QAction *action); }; diff --git a/src/frontend/mainwindow.cpp b/src/frontend/mainwindow.cpp index 857e2daf..751d821a 100644 --- a/src/frontend/mainwindow.cpp +++ b/src/frontend/mainwindow.cpp @@ -307,7 +307,7 @@ void MainWindow::resetWindowTheme() void MainWindow::showControlCenter() { QProcess process; - if (m_lanWidget->m_isLanConnected == false && m_wlanWidget->m_wlanIsConnected == true){ + if (!m_lanWidget->lanIsConnected() && m_wlanWidget->wlanIsConnected()){ process.startDetached("ukui-control-center --wlanconnect"); } else { process.startDetached("ukui-control-center --wiredconnect"); @@ -352,11 +352,11 @@ void MainWindow::onThemeChanged(const QString &key) void MainWindow::onRefreshTrayIcon() { //更新托盘图标显示 - if (m_lanWidget->m_isLanConnected == true){ + if (m_lanWidget->lanIsConnected()) { m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic")); - } else if (m_wlanWidget->m_wlanIsConnected == true && m_lanWidget->m_isLanConnected == false){ + } else if (m_wlanWidget->wlanIsConnected()){ m_trayIcon->setIcon(QIcon::fromTheme("network-wireless-signal-excellent-symbolic")); - } else if (m_wlanWidget->m_wlanIsConnected == false && m_lanWidget->m_isLanConnected == false){ + } else { m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic")); } } @@ -497,10 +497,10 @@ void MainWindow::deactivateWired(const QString& devName, const QString& connUuid //无线连接断开 void MainWindow::activateWireless(const QString& devName, const QString& ssid) { - m_wlanWidget->activateWireless(devName, ssid); + m_wlanWidget->activateWirelessConnection(devName, ssid); } void MainWindow::deactivateWireless(const QString& devName, const QString& ssid) { - m_wlanWidget->deactivateWireless(devName, ssid); + m_wlanWidget->deactivateWirelessConnection(devName, ssid); } diff --git a/src/frontend/nmdemo.cpp b/src/frontend/nmdemo.cpp index 9addcce8..3b31412e 100644 --- a/src/frontend/nmdemo.cpp +++ b/src/frontend/nmdemo.cpp @@ -112,7 +112,7 @@ void NmDemo::initUi() void NmDemo::initConnect() { - connect(m_wco, &KyWirelessConnectOperation::wifinEnabledChanged,[=](bool status){ + connect(m_wco, &KyWirelessConnectOperation::wifiEnabledChanged,[=](bool status){ QString temp; temp.sprintf("wifinEnabledChanged %d",status); appendDebugLog(temp); diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 3a77c360..4fd16485 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -473,6 +473,7 @@ void LanPage::addDeviceForCombox(QString deviceName) //2、有多快网卡,但是没有使能 m_deviceFrame->hide(); m_currentDeviceName = deviceName; + setDefaultDevice(WIRED, m_currentDeviceName); } else if (2 == m_enableDeviceList.count()) { //3、现在有且只有一块网卡,并已使能 //4、有多快网卡,且使能了其中一块 @@ -511,7 +512,6 @@ void LanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type devic addDeviceForCombox(deviceName); if (m_currentDeviceName == deviceName) { - setDefaultDevice(WIRED, m_currentDeviceName); initLanArea(); } @@ -1077,3 +1077,16 @@ void LanPage::showDetailPage(QString devName, QString uuid) p_item = nullptr; } +bool LanPage::lanIsConnected() +{ + if (m_activeMap.isEmpty()) { + return false; + } else { + KyConnectItem *p_connectItem = m_activeMap.firstKey(); + if (p_connectItem->m_connectUuid == INVALID_CONNECT_UUID) { + return false; + } + } + + return true; +} diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index 3abb0893..be3c54c1 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -23,7 +23,6 @@ class LanPage : public TabPage public: explicit LanPage(QWidget *parent = nullptr); ~LanPage(); - bool m_isLanConnected = false; //for dbus void getWiredList(QMap > &map); @@ -32,6 +31,8 @@ public: void showDetailPage(QString devName, QString uuid); void setWiredDeviceEnable(const QString& devName, bool enable); + bool lanIsConnected(); + protected: bool eventFilter(QObject *watched, QEvent *event); diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index c624656f..3666bc45 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -6,25 +6,36 @@ #include #include +#define AP_SCAN_INTERVAL (20*1000) +#define ICON_REFRESH_INTERVAL (5*1000) +#define EMPTY_SSID "emptyssid" +#define LOG_FLAG "[WlanPage]" + WlanPage::WlanPage(QWidget *parent) : TabPage(parent) { - m_resource = new KyWirelessNetResource(this); - m_connectResource = new KyActiveConnectResourse(); - m_networkResourceInstance = KyNetworkResourceManager::getInstance(); + m_wirelessNetResource = new KyWirelessNetResource(this); + m_activatedConnectResource = new KyActiveConnectResourse(this); m_netDeviceResource=new KyNetworkDeviceResourse(this); - m_apConnectResource = new KyConnectResourse(this); - m_devList.empty(); - initDevice(); + m_connectResource = new KyConnectResourse(this); m_wirelessConnectOpreation = new KyWirelessConnectOperation(this); - m_connectoperation = new KyConnectOperation(this); - m_settingsLabel->installEventFilter(this); - m_connectResource = new KyActiveConnectResourse(); + + initDevice(); initWlanUI(); - //要在initUI之后调用,保证UI的信号槽顺利绑定 - initConnections(); + initWlanSwitchState(); + initDeviceCombox(); + initWlanArea(); + initTimer(); - getActiveWlan(); - getAllWlan(); + + connect(m_wirelessNetResource, &KyWirelessNetResource::wifiNetworkAdd, this, &WlanPage::onWlanAdded); + connect(m_wirelessNetResource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::onWlanRemoved); + connect(m_wirelessNetResource, &KyWirelessNetResource::signalStrengthChange, this, &WlanPage::signalStrengthChange); + connect(m_wirelessNetResource, &KyWirelessNetResource::secuTypeChange, this, &WlanPage::onSecurityTypeChange); + connect(m_wirelessNetResource, &KyWirelessNetResource::connectionAdd, this, &WlanPage::onConnectionAdd); + connect(m_wirelessNetResource, &KyWirelessNetResource::connectionRemove, this, &WlanPage::onConnectionRemove); + + connect(m_activatedConnectResource, &KyActiveConnectResourse::stateChangeReason, + this, &WlanPage::onConnectionStateChanged); connect(m_netDeviceResource, &KyNetworkDeviceResourse::deviceAdd, this, &WlanPage::onDeviceAdd); connect(m_netDeviceResource, &KyNetworkDeviceResourse::deviceRemove, this, &WlanPage::onDeviceRemove); @@ -32,18 +43,12 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent) connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::activateConnectionError, this, &WlanPage::activateFailed); connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::addAndActivateConnectionError, this, &WlanPage::activateFailed); - connect(this, &WlanPage::activateFailed, this, &WlanPage::onActiveFailed); connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::deactivateConnectionError, this, &WlanPage::deactivateFailed); connect(this, &WlanPage::hiddenWlanClicked, this, &WlanPage::onHiddenWlanClicked); - connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::wifinEnabledChanged, this, &WlanPage::onWifiEnabledChanged); + connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::wifiEnabledChanged, this, &WlanPage::onWifiEnabledChanged); } -//QString WlanPage::getSsidFromUuid(const QString &uuid) -//{ - -//} - bool WlanPage::eventFilter(QObject *w, QEvent *e) { if (e->type() == QEvent::MouseButtonPress) { @@ -68,10 +73,12 @@ void WlanPage::initWlanUI() m_inactivatedWlanListAreaCentralWidget = new QFrame(m_inactivatedNetListArea); m_inactivatedNetListArea->setBackgroundRole(QPalette::Base); m_inactivatedNetListArea->setWidget(m_inactivatedWlanListAreaCentralWidget); + m_inactivatedNetListArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_inactivatedWlanListAreaLayout = new QVBoxLayout(m_inactivatedWlanListAreaCentralWidget); - m_inactivatedWlanListAreaCentralWidget->setLayout(m_inactivatedWlanListAreaLayout); m_inactivatedWlanListAreaLayout->setSpacing(MAIN_LAYOUT_SPACING); m_inactivatedWlanListAreaLayout->setContentsMargins(MAIN_LAYOUT_MARGINS); + m_inactivatedWlanListAreaCentralWidget->setLayout(m_inactivatedWlanListAreaLayout); m_inactivatedNetListWidget = new QListWidget(m_inactivatedWlanListAreaCentralWidget); m_inactivatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS); @@ -79,21 +86,23 @@ void WlanPage::initWlanUI() m_inactivatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame); m_inactivatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_inactivatedNetListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //用了SCrollArea的滚动条 + m_inactivatedWlanListAreaLayout->addWidget(m_inactivatedNetListWidget); - m_hiddenWlanWidget = new QFrame(m_inactivatedWlanListAreaCentralWidget); - m_hiddenWlanLayout = new QHBoxLayout(m_hiddenWlanWidget); - m_hiddenWlanLayout->setContentsMargins(MAIN_LAYOUT_MARGINS); + m_hiddenWlanWidget = new QFrame(m_inactivatedWlanListAreaCentralWidget); m_hiddenWlanLabel = new QLabel(m_hiddenWlanWidget); m_hiddenWlanLabel->setText(tr("More...")); m_hiddenWlanLabel->setContentsMargins(MORE_TEXT_MARGINS); m_hiddenWlanLabel->installEventFilter(this); m_hiddenWlanLabel->setCursor(Qt::PointingHandCursor); + + m_hiddenWlanLayout = new QHBoxLayout(m_hiddenWlanWidget); + m_hiddenWlanLayout->setContentsMargins(MAIN_LAYOUT_MARGINS); m_hiddenWlanLayout->addWidget(m_hiddenWlanLabel); m_hiddenWlanLayout->addStretch(); - m_inactivatedWlanListAreaLayout->addWidget(m_inactivatedNetListWidget); m_inactivatedWlanListAreaLayout->addWidget(m_hiddenWlanLabel); m_inactivatedWlanListAreaLayout->addStretch(); + m_activatedNetListWidget = new QListWidget(m_activatedNetFrame); m_activatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame); m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS); @@ -101,528 +110,22 @@ void WlanPage::initWlanUI() m_activatedNetListWidget->setFixedHeight(NORMAL_HEIGHT); m_activatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_activatedNetLayout->addWidget(m_activatedNetListWidget); -// m_inactivatedNetListArea->setFixedHeight(SCROLLAREA_HEIGHT); - m_inactivatedNetListArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - m_tipsLabel->hide(); //设备关闭的label,要用的话可以放出来 -} - -/** - * @brief WlanPage::initConnections 初始化一些信号槽 - */ -void WlanPage::initConnections() -{ - connect(m_resource, &KyWirelessNetResource::wifiNetworkAdd, this, &WlanPage::onWlanAdded); - connect(m_resource, &KyWirelessNetResource::wifiNetworkAdd, this, [=](QString interface, KyWirelessNetItem &item){ - //for dbus - QStringList info; - info <keys().contains(WIRELESS_SWITCH)) { - 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(); - if (!status) { -// m_deviceFrame->hide(); - m_activatedNetFrame->hide(); - m_inactivatedNetFrame->hide(); - m_activatedNetDivider->hide(); - m_inactivatedNetDivider->hide(); - } else { -// m_deviceFrame->show(); - m_activatedNetFrame->show(); - m_inactivatedNetFrame->show(); - m_activatedNetDivider->show(); - m_inactivatedNetDivider->show(); - } - m_wirelessConnectOpreation->setWirelessEnabled(status); - m_netSwitch->setSwitchStatus(m_switchGsettings->get(WIRELESS_SWITCH).toBool()); - onWlanSwitchStatusChanged(m_switchGsettings->get(WIRELESS_SWITCH).toBool()); - } - }); - return; - } - } - qDebug()<<"isSchemaInstalled false" << Q_FUNC_INFO << __LINE__; - m_netSwitch->setSwitchStatus(m_wirelessConnectOpreation->getWirelessEnabled()); -} - -void WlanPage::initTimer() -{ - m_scanTimer = new QTimer(this); - m_refreshIconTimer = new QTimer(this); - connect(m_scanTimer, &QTimer::timeout, this, &WlanPage::requestScan); - connect(m_refreshIconTimer, &QTimer::timeout, this, &WlanPage::updateByStrength); -} - -/** - * @brief WlanPage::initDevice 初始化默认网卡 - */ -void WlanPage::initDevice() -{ - QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); - m_settings->beginGroup("DEFAULTCARD"); - QString key("wireless"); - QString deviceName; - m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, m_devList); - if (!m_devList.isEmpty()) { - deviceName = m_devList.at(0); - m_settings->setValue(key, deviceName); - } else { - qDebug() << "have no device to use " << Q_FUNC_INFO << __LINE__; - //检测不到无线网卡不再触发click信号 - m_netSwitch->setSwitchStatus(false); - m_netSwitch->setEnabled(false); - } - updateDefaultDevice(deviceName); - qDebug() << "[WlanPage] initDevice defaultDevice = " << deviceName; - m_settings->endGroup(); - m_settings->sync(); - delete m_settings; - m_settings = nullptr; - //获取完m_devList后调用,减少重复获取 - initDeviceCombox(); -} - -void WlanPage::initDeviceCombox() -{ - //TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框 - disconnect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &WlanPage::onDeviceComboxIndexChanged); - if (m_devList.length() <= 1) { - m_deviceFrame->hide(); - foreach (QString device, m_devList) { - m_deviceComboBox->addItem(device, device); - } - } else { - m_deviceFrame->show(); - foreach (QString device, m_devList) { - //空时addItem 会触发currentIndexChanged - m_deviceComboBox->addItem(device, device); - } - int index = m_deviceComboBox->findData(m_defaultDevice); - qDebug() << index; - m_deviceComboBox->setCurrentIndex(index); - } - connect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &WlanPage::onDeviceComboxIndexChanged); - -} - -/** - * @brief WlanPage::getActiveWlan 获取所有已激活连接 - */ -void WlanPage::getActiveWlan() -{ - if (!m_activatedNetListWidget) { - return; - } - QMap actMap; - m_activatedNetListWidget->clear(); - m_resource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap); - QMap::iterator iter = actMap.begin(); - int height = 0; - while (iter != actMap.end()) { - if (iter.key() == m_defaultDevice && !iter.value().isEmpty()) { - QString uuid = iter.value().at(0); - appendActiveWlan(uuid, height); - break; - } - iter ++; - } - if (height > 0) { - m_activatedNetListWidget->setFixedHeight(height); - } else { - //未连接任何WiFi的情况 - m_activatedWlanSSid.clear(); - m_activatedWlanUuid.clear(); - WlanListItem *wlanItemWidget = new WlanListItem(); - qDebug() << "There is no activated wlan." << Q_FUNC_INFO << __LINE__ ; - QListWidgetItem *wlanItem = new QListWidgetItem(); - wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height())); - m_activatedNetListWidget->addItem(wlanItem); -// emit this->wlanConnectChanged(); - m_activatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget); - height += wlanItemWidget->height(); - } -} - -void WlanPage::appendActiveWlan(const QString &uuid, int &height) -{ - qDebug() << "appendActiveWlan" << uuid; - m_activatedWlanUuid = uuid; - m_resource->getSsidByUuid(uuid, m_activatedWlanSSid, m_defaultDevice); - - KyWirelessNetItem data; - if (!m_resource->getWifiNetwork(m_defaultDevice, m_activatedWlanSSid, data)) { - qWarning() << "Get activated wlan failed! ssid = " << m_activatedWlanSSid <<"; device = " << m_defaultDevice << "; uuid = " << m_activatedWlanUuid; - return; - } - KyWirelessNetItem *item_data = new KyWirelessNetItem(data); - WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data, m_defaultDevice); - qDebug() << "Activated wlan: ssid = " << item_data->m_NetSsid; - QListWidgetItem *wlanItem = new QListWidgetItem(); - wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height())); - m_activatedNetListWidget->addItem(wlanItem); - emit this->wlanConnectChanged(); - qDebug() << "[wlanpage]emit wlanConnectChanged()" << Q_FUNC_INFO << __LINE__ ; - m_activatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget); - wlanItemWidget->setActive(true); - - height += wlanItemWidget->height(); -} - -/** - * @brief WlanPage::getAllWlan 获取所有Wlan //ZJP_TODO 需要针对网卡进行筛选 - */ -void WlanPage::getAllWlan() -{ - if (!m_inactivatedNetListWidget) { - return; - } - qDebug() << "Started loading wlan list!" << QDateTime::currentDateTime().toString("hh:mm:ss.zzzz"); - m_inactivatedNetListWidget->clear(); - m_itemsMap.clear(); - m_expandedItem = nullptr; //每次重绘整个列表时要清空扩展项,否则会导致再展开某一项item的时候进程崩溃 - QList wlanList; -// if (!m_resource->getAllDeviceWifiNetwork(map)) - if (!m_resource->getDeviceWifiNetwork(m_defaultDevice, wlanList)) { //ZJP_TODO 获取默认网卡并传入 - return; - } - int height = 0; - foreach (auto itemData, wlanList) { - if (itemData.m_NetSsid == this->m_activatedWlanSSid) { - continue; - } - KyWirelessNetItem *data = new KyWirelessNetItem(itemData); - WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, m_defaultDevice); - QListWidgetItem *wlanItem = new QListWidgetItem(); - qDebug() << itemData.m_NetSsid << itemData.m_isConfigured; - connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); - connect(wlanItemWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked); - QPair pair (wlanItem, wlanItemWidget); - m_itemsMap.insert(data->m_NetSsid, pair); - wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height())); - m_inactivatedNetListWidget->addItem(wlanItem); - m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget); - if (height == 0) { - height += wlanItemWidget->height(); - } - height += wlanItemWidget->height() + NET_LIST_SPACING; - } - m_inactivatedNetListWidget->setFixedHeight(height); - m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); - qDebug() << "Stopped loading wlan list! time=" << QDateTime::currentDateTime().toString("hh:mm:ss.zzzz"); -} - -void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item) -{ - qDebug() << "A Wlan Added! interface = " << interface << "; ssid = " << item.m_NetSsid << "interface" << interface << Q_FUNC_INFO <<__LINE__; - if (interface != m_defaultDevice) { - qDebug() << "wlan add interface not equal defaultdevice,ignore"; - return; - } - KyWirelessNetItem *data = new KyWirelessNetItem(item); - WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, m_defaultDevice); - connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); - connect(wlanItemWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked); - - QListWidgetItem *wlanItem = new QListWidgetItem(); //不要指定父对象,否则insert会出错 - wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height())); - int index = getIndexByStrength(interface, data->m_NetSsid); - - m_inactivatedNetListWidget->insertItem(index, wlanItem); - m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget); - -// m_inactivatedNetListWidget->addItem(wlanItem); //ZJP_TODO 目前会添加到列表尾部 - m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() + wlanItemWidget->height() + NET_LIST_SPACING); - m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); - QPair pair (wlanItem, wlanItemWidget); - m_itemsMap.insert(data->m_NetSsid, pair); -} - -int WlanPage::getIndexByStrength(QString interface, QString ssid) -{ - QList wlanList; - m_resource->getDeviceWifiNetwork(interface, wlanList); - for (int i = 0; i< wlanList.count(); i++) { - if (wlanList.at(i).m_NetSsid == ssid) { - qDebug() << "append" << wlanList.at(i).m_NetSsid << i; - return i; - } - } -} - -void WlanPage::onWlanRemoved(QString interface, QString ssid) -{ - if (!m_itemsMap.contains(ssid)) { return; } - if (m_expandedItem == (m_itemsMap.value(ssid)).first) { m_expandedItem = nullptr; } - qDebug() << "A Wlan Removed! interface = " << interface << "; ssid = " << ssid << Q_FUNC_INFO <<__LINE__; - if (interface != m_defaultDevice) { - qDebug() << "wlan remove interface not equal defaultdevice,ignore"; - } - if (m_itemsMap.value(ssid).second) { - m_inactivatedNetListWidget->takeItem(m_inactivatedNetListWidget->row((m_itemsMap.value(ssid)).first)); - int height = m_itemsMap.value(ssid).second->height(); - m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() - height - NET_LIST_SPACING); - m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); - } - m_itemsMap.remove(ssid); -} - -void WlanPage::onWlanUpdated() -{ - //ZJP_TODO 某些特定情况下不可重绘整个列表,此处代码需要修改 - m_expandedItem = nullptr; - getActiveWlan(); - getAllWlan(); + m_settingsLabel->installEventFilter(this); } -void WlanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType) +void WlanPage::onWlanSwithGsettingsChanged(const QString &key) { - qDebug() << "deviceAdd" << deviceName; - if (deviceType != NetworkManager::Device::Type::Wifi) { - return; - } - m_netSwitch->setEnabled(true); - m_netSwitch->setSwitchStatus(true); - m_devList << deviceName; - if (getDefaultDevice().isEmpty()) - { - m_devList.clear(); - updateDefaultDevice(deviceName); - setDefaultDevice(WIRELESS, deviceName); - + if (key == WIRELESS_SWITCH) { + m_wlanSwitchEnable = m_switchGsettings->get(WIRELESS_SWITCH).toBool(); + qDebug() << LOG_FLAG << "wlan switch state" << m_wlanSwitchEnable; + m_netSwitch->setSwitchStatus(m_wlanSwitchEnable); + initDeviceCombox(); + initWlanArea(); } - //往下拉框添加新的网卡 - if (m_deviceComboBox->findData(deviceName) == -1) { - if (m_devList.length() > 1 && !m_deviceFrame->isVisible()) { - m_deviceFrame->show(); - } - m_deviceComboBox->addItem(deviceName, deviceName); - } - - emit deviceStatusChanged(); -} - -void WlanPage::onDeviceRemove(QString deviceName) -{ - qDebug() << "deviceRemove" << deviceName; - if (getDefaultDevice() == deviceName) - { - QStringList list; - QString newDefaultDevice = ""; - list.empty(); - m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, list); - if (!list.isEmpty()) { - newDefaultDevice = list.at(0); - } else { - m_netSwitch->setSwitchStatus(false); - m_netSwitch->setEnabled(false); - } - updateDefaultDevice(newDefaultDevice); - setDefaultDevice(WIRELESS, newDefaultDevice); - } - - if (m_devList.contains(deviceName)) { - m_devList.removeOne(deviceName); - emit deviceStatusChanged(); - } - - //从下拉框删除已消失的网卡 - if (m_deviceComboBox->findData(deviceName) != -1) { - if (m_devList.length() <= 1 && m_deviceFrame->isVisible()) { - m_deviceFrame->hide(); - } - m_deviceComboBox->removeItem(m_deviceComboBox->findData(deviceName)); - } - -} - -void WlanPage::onDeviceNameUpdate(QString oldName, QString newName) -{ - if (getDefaultDevice() == oldName) { - updateDefaultDevice(newName); - setDefaultDevice(WIRELESS, newName); - } - - if (m_devList.contains(oldName)) { - m_devList.removeOne(oldName); - m_devList.append(newName); - qDebug() << "WlanPage emit deviceNameUpdate " << oldName << newName; - emit deviceNameChanged(oldName, newName); - } - - if (m_deviceComboBox->findData(oldName) != -1) { - m_deviceComboBox->removeItem(m_deviceComboBox->findData(oldName)); - m_deviceComboBox->addItem(newName, newName); - } -} - -void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason) -{ - qDebug()<< "Activated wlan changed, uuid = " << uuid << "; state = " << state << "; reason = " << reason << Q_FUNC_INFO <<__LINE__; - - //wlanpage函数内持续监听连接状态的变化并记录供其他函数调用获取状态 - QString devName,ssid; - NetworkManager::ConnectionSettings::ConnectionType type; - if(m_apConnectResource->getInterfaceByUuid(devName, type, uuid)) { - if (type != NetworkManager::ConnectionSettings::ConnectionType::Wireless) { - return; - } - } - if(NetworkManager::ActiveConnection::State::Activated == state){ - m_wlanIsConnected = true; - qDebug() << "[wlanpage] wlanIsConnected status : " << m_wlanIsConnected << Q_FUNC_INFO << __LINE__ ; - } else { - m_wlanIsConnected = false; - qDebug() << "[wlanpage] wlanIsConnected status : " << m_wlanIsConnected << Q_FUNC_INFO << __LINE__ ; - } - - //弹窗显示wifi连接状况 - qDebug() << "[WlanPage] State changed to :" << state << reason << Q_FUNC_INFO <<__LINE__; - //QString ssid; - QString device = m_defaultDevice; - m_resource->getSsidByUuid(uuid, ssid, device); - if (m_activatedWlanSSid == ssid && state == NetworkManager::ActiveConnection::State::Activated) { - if(m_activedssid != m_activatedWlanSSid){ - m_activedssid = m_activatedWlanSSid; - qDebug() << "[WlanPage] State changed to :" << state << ssid << reason << Q_FUNC_INFO <<__LINE__; - this->showDesktopNotify(tr("WLAN Connected Successfully")); - } - } - if (state == NetworkManager::ActiveConnection::State::Deactivating){ - m_disconnectuuid = uuid; - m_disconnectingflag = true; - } - if (state == NetworkManager::ActiveConnection::State::Deactivated && m_disconnectuuid == uuid){ - if(m_disconnectingflag){ - m_disconnectingflag = false; - this->showDesktopNotify(tr("WLAN Disconnected Successfully")); - qDebug() << "clear the activessid" << Q_FUNC_INFO <<__LINE__; - m_activedssid = ""; - } - } - - //QString ssid,devName; - //NetworkManager::ConnectionSettings::ConnectionType type; - - if(m_apConnectResource->getInterfaceByUuid(devName, type, uuid)) { - if (type != NetworkManager::ConnectionSettings::ConnectionType::Wireless) { - qDebug() << "[WLanPage] updateLanlist but type is not Wireless"; - return; - } - } else { - qDebug() << "[WlanPage] onActivatedWlanChanged but uuid is invalid"; - } - - m_resource->getSsidByUuid(uuid, ssid, devName); - - qDebug() << "emit wlanActiveConnectionStateChanged" << devName << ssid << state; - emit wlanActiveConnectionStateChanged(devName, ssid, state); - - if (state == NetworkManager::ActiveConnection::State::Deactivated) { - QList apConnectItemList; - m_apConnectResource->getApConnections(apConnectItemList); - if (!apConnectItemList.isEmpty()) { - foreach (auto item, apConnectItemList) { - if (item->m_connectUuid == uuid) { - qDebug() << "[WlanPage] hotspot Deactivated"; - emit hotspotDeactivated(item->m_ifaceName, ssid); - break; - } - } - } - } - - if (state == NetworkManager::ActiveConnection::State::Activated) { - QList apConnectItemList; - m_apConnectResource->getApConnections(apConnectItemList); - if (!apConnectItemList.isEmpty()) { - foreach (auto item, apConnectItemList) { - if (item->m_connectUuid == uuid) { - qDebug() << "[WlanPage] hotspot Deactivated"; - emit hotspotActivated(item->m_ifaceName, ssid); - break; - } - } - } - } - - if (state == NetworkManager::ActiveConnection::State::Activated && m_defaultDevice == devName) { - //onWlanRemoved(m_wlanDevice, ssid); - m_activatedNetListWidget->clear(); - int height = 0; - appendActiveWlan(uuid, height); -// emit this->wlanConnectChanged(); - onWlanRemoved(m_defaultDevice, ssid); -// this->showDesktopNotify(tr("Connect WLAN succeed")); - } else if (state == NetworkManager::ActiveConnection::State::Deactivated && (uuid.isEmpty() || (!uuid.isEmpty() && uuid == m_activatedWlanUuid))) { - QString oldActWlanSsid = m_activatedWlanSSid; - getActiveWlan(); - QString newActWlanSsid = m_activatedWlanSSid; - qDebug() << "Refresh active wlan succeed, old ssid = " << oldActWlanSsid << "; new ssid = " << newActWlanSsid << Q_FUNC_INFO << __LINE__; - if (oldActWlanSsid != newActWlanSsid) { - if (!oldActWlanSsid.isEmpty()) { - KyWirelessNetItem item; - if(m_resource->getWifiNetwork(m_defaultDevice, oldActWlanSsid, item)) { - onWlanAdded(m_defaultDevice, item); - } - } - if (!newActWlanSsid.isEmpty()) { - onWlanRemoved(m_defaultDevice, newActWlanSsid); - } - } -// this->showDesktopNotify(tr("Disconnect WLAN succeed")); - } else { - qDebug() << "Unexpected wlan state, will do nothing." << Q_FUNC_INFO << __LINE__; - } -} - -void WlanPage::onItemHeightChanged(const QString &ssid) -{ - if (!m_itemsMap.contains(ssid)) { return; } - QListWidgetItem *item = (m_itemsMap.value(ssid)).first; - - if (m_expandedItem && m_expandedItem != item) { - QSize size(m_inactivatedNetListWidget->itemWidget(m_expandedItem)->size().width(), NORMAL_HEIGHT); - //旧的收起 - m_expandedItem->setSizeHint(size); - m_inactivatedNetListWidget->itemWidget(m_expandedItem)->setFixedHeight(NORMAL_HEIGHT); - //新的展开 - m_expandedItem = item; - item->setSizeHint(m_inactivatedNetListWidget->itemWidget(item)->size()); - } else if (!m_expandedItem) { - m_expandedItem = item; - m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_inactivatedNetListWidget->itemWidget(item)->height() - item->sizeHint().height()); - m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); - item->setSizeHint(m_inactivatedNetListWidget->itemWidget(item)->size()); - } -} - -void WlanPage::onConnectButtonClicked(KyWirelessConnectSetting &connSettingInfo, const bool &isHidden) -{ - qDebug() << "Received signal of connecting wlan, ssid = " << connSettingInfo.m_ssid << "device name = " << m_defaultDevice << Q_FUNC_INFO << __LINE__; - m_wirelessConnectOpreation->addAndActiveWirelessConnect(m_defaultDevice, connSettingInfo, isHidden); + return; } /** @@ -630,23 +133,771 @@ void WlanPage::onConnectButtonClicked(KyWirelessConnectSetting &connSettingInfo, */ void WlanPage::onWlanSwitchClicked() { - qDebug() << "On wlan switch button clicked! old state = " << !m_netSwitch->getSwitchStatus() << Q_FUNC_INFO << __LINE__; - //应该先检测是否有无线网卡可用,才改变开关状态 - m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, m_devList); + qDebug() <<"[WlanPage] On wlan switch button clicked! old state = " + << !m_netSwitch->getSwitchStatus() << Q_FUNC_INFO << __LINE__; + if (m_devList.isEmpty()) { - qDebug() << "have no device to use " << Q_FUNC_INFO << __LINE__; + qDebug() << "[WlanPage] have no device to use " << Q_FUNC_INFO << __LINE__; //检测不到无线网卡不再触发click信号 m_netSwitch->setSwitchStatus(false); - m_netSwitch->setEnabled(false); - }else{ - m_wirelessConnectOpreation->setWirelessEnabled(m_netSwitch->getSwitchStatus()); + //m_netSwitch->setEnabled(false); + } else { + bool switchEnable = m_netSwitch->getSwitchStatus(); + if (m_wlanSwitchEnable != switchEnable) { + qDebug()<< LOG_FLAG << "wlan switch state " << switchEnable; + m_wirelessConnectOpreation->setWirelessEnabled(switchEnable); + m_switchGsettings->set(WIRELESS_SWITCH, switchEnable); + } } + + return; } -void WlanPage::onWlanSwitchStatusChanged(const bool &checked) +void WlanPage::initWlanSwitchState() { - qDebug() << "On wlan switch status changed! new state = " << m_netSwitch->getSwitchStatus() << Q_FUNC_INFO << __LINE__; - onWlanUpdated(); + m_wlanSwitchEnable = m_wirelessConnectOpreation->getWirelessEnabled(); + + if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) { + m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA); + if (m_switchGsettings->keys().contains(WIRELESS_SWITCH)) { + if (m_devList.isEmpty()) { + m_wlanSwitchEnable = false; + } else { + m_wlanSwitchEnable = m_switchGsettings->get(WIRELESS_SWITCH).toBool(); + } + connect(m_switchGsettings, &QGSettings::changed, this, &WlanPage::onWlanSwithGsettingsChanged); + } + } + + m_netSwitch->setSwitchStatus(m_wlanSwitchEnable); + //m_netSwitch->setEnabled(m_wlanSwitchEnable); + + connect(m_netSwitch, &SwitchButton::clicked, this, &WlanPage::onWlanSwitchClicked); + + return; +} + +void WlanPage::initTimer() +{ + m_scanTimer = new QTimer(this); + connect(m_scanTimer, &QTimer::timeout, this, &WlanPage::requestScan); + + m_refreshIconTimer = new QTimer(this); + connect(m_refreshIconTimer, &QTimer::timeout, this, &WlanPage::onRefreshIconTimer); +} + +/** + * @brief WlanPage::initDevice 初始化默认网卡 + */ +void WlanPage::initDevice() +{ + m_devList.clear(); + m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, m_devList); + + m_currentDevice = getDefaultDeviceName(WIRELESS); + + return; +} + +void WlanPage::initDeviceCombox() +{ + //TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框 + disconnect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &WlanPage::onDeviceComboxIndexChanged); + m_deviceComboBox->clear(); + + if (m_wlanSwitchEnable) { + if (0 == m_devList.count()) { + m_deviceFrame->show(); + m_tipsLabel->show(); + m_deviceComboBox->hide(); + m_currentDevice = ""; + setDefaultDevice(WIRELESS, m_currentDevice); + } else if (1 == m_devList.count()) { + m_deviceFrame->hide(); + if (m_currentDevice != m_devList.at(0)) { + m_currentDevice = m_devList.at(0); + setDefaultDevice(WIRELESS, m_currentDevice); + } + } else { + m_deviceFrame->show(); + m_deviceComboBox->show(); + m_tipsLabel->hide(); + for (int index = 0; index < m_devList.count(); ++index) { + m_deviceComboBox->addItem(m_devList.at(index)); + } + + if (m_devList.contains(m_currentDevice)) { + m_deviceComboBox->setCurrentText(m_currentDevice); + } else { + m_currentDevice = m_deviceComboBox->currentText(); + setDefaultDevice(WIRELESS, m_currentDevice); + } + } + } else { + m_deviceFrame->hide(); + m_currentDevice = ""; + setDefaultDevice(WIRELESS, m_currentDevice); + } + + connect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &WlanPage::onDeviceComboxIndexChanged); + return; +} + +QListWidgetItem *WlanPage::addEmptyItem(QListWidget *wirelessListWidget) +{ + WlanListItem *p_wlanItem = new WlanListItem(); + QListWidgetItem *p_listWidgetItem = new QListWidgetItem(wirelessListWidget); + p_listWidgetItem->setSizeHint(QSize(wirelessListWidget->width(), p_wlanItem->height())); + wirelessListWidget->addItem(p_listWidgetItem); + wirelessListWidget->setItemWidget(p_listWidgetItem, p_wlanItem); + + return p_listWidgetItem; +} + +QListWidgetItem *WlanPage::addNewItem(KyWirelessNetItem &wirelessNetItem, + QListWidget *wirelessListWidget) +{ + WlanListItem *p_wlanItem = new WlanListItem(wirelessNetItem, m_currentDevice); + connect(p_wlanItem, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); + + QListWidgetItem *p_listWidgetItem = new QListWidgetItem(wirelessListWidget); + p_listWidgetItem->setSizeHint(QSize(wirelessListWidget->width(), p_wlanItem->height())); + wirelessListWidget->addItem(p_listWidgetItem); + wirelessListWidget->setItemWidget(p_listWidgetItem, p_wlanItem); + + return p_listWidgetItem; +} + +QListWidgetItem *WlanPage::insertNewItem(KyWirelessNetItem &wirelessNetItem, + QListWidget *wirelessListWidget, + int row) +{ + WlanListItem *p_wlanItem = new WlanListItem(wirelessNetItem, m_currentDevice); + connect(p_wlanItem, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); + + QListWidgetItem *p_listWidgetItem = new QListWidgetItem(wirelessListWidget); + p_listWidgetItem->setSizeHint(QSize(wirelessListWidget->width(), p_wlanItem->height())); + wirelessListWidget->insertItem(row, p_listWidgetItem); + wirelessListWidget->setItemWidget(p_listWidgetItem, p_wlanItem); + + return p_listWidgetItem; +} + +void WlanPage::clearWirelessNetItemMap(QMap &wirelessNetItem, + QListWidget *wirelessListWidget) +{ + QMap::iterator iter; + + iter = wirelessNetItem.begin(); + while (iter != wirelessNetItem.end()) { + QListWidgetItem *p_widgetItem = iter.value(); + WlanListItem *p_wlanItem = (WlanListItem *)wirelessListWidget->itemWidget(p_widgetItem); + wirelessListWidget->removeItemWidget(p_widgetItem); + + delete p_wlanItem; + p_wlanItem = nullptr; + + delete p_widgetItem; + p_widgetItem = nullptr; + + iter = wirelessNetItem.erase(iter); + } + + return; +} + +void WlanPage::deleteWirelessItemFormMap(QMap &wirelessNetItemMap, + QListWidget *wirelessListWidget, QString ssid) +{ + QListWidgetItem *p_listWidgetItem = wirelessNetItemMap.value(ssid); + if (nullptr == p_listWidgetItem) { + qWarning()<< LOG_FLAG <<"wireless item is not exsit, it's ssid is " << ssid; + return; + } + + WlanListItem *p_wlanItem = (WlanListItem *)wirelessListWidget->itemWidget(p_listWidgetItem); + int height = p_wlanItem->height(); + + wirelessNetItemMap.remove(ssid); + + wirelessListWidget->takeItem(wirelessListWidget->row(p_listWidgetItem)); + + delete p_wlanItem; + p_wlanItem = nullptr; + + delete p_listWidgetItem; + p_listWidgetItem = nullptr; + + wirelessListWidget->setFixedHeight(wirelessListWidget->height() - height - NET_LIST_SPACING); + + return; +} + +void WlanPage::updateWlanItemState(QListWidget *p_wirelessListWidget, + QListWidgetItem *p_listWidgetItem, + ConnectState state) +{ + WlanListItem *p_wlanItem = nullptr; + p_wlanItem = (WlanListItem *)p_wirelessListWidget->itemWidget(p_listWidgetItem); + if (nullptr != p_wlanItem) { + p_wlanItem->updateConnectState(state); + } + + return; +} + +void WlanPage::constructActivateConnectionArea() +{ + int height = 0; + clearWirelessNetItemMap(m_activateConnectionItemMap, m_activatedNetListWidget); + + if (!m_currentDevice.isEmpty()) { + KyWirelessNetItem wirelessNetItem; + bool ret = m_wirelessNetResource->getActiveWirelessNetItem(m_currentDevice, wirelessNetItem); + if (ret == true) { + QListWidgetItem *p_listWidgetItem = addNewItem(wirelessNetItem, m_activatedNetListWidget); + updateWlanItemState(m_activatedNetListWidget, p_listWidgetItem, Activated); + m_activateConnectionItemMap.insert(wirelessNetItem.m_NetSsid, p_listWidgetItem); + + height += p_listWidgetItem->sizeHint().height(); + } + } + + if (height == 0) { + QListWidgetItem *p_listWidgetItem = addEmptyItem(m_activatedNetListWidget); + m_activateConnectionItemMap.insert(EMPTY_SSID, p_listWidgetItem); + + WlanListItem *p_wlanItem = (WlanListItem *)m_activatedNetListWidget->itemWidget(p_listWidgetItem); + height += p_wlanItem->height(); + } + + m_activatedNetListWidget->setFixedHeight(height); + + return; +} + +void WlanPage::constructWirelessNetArea() +{ + qDebug() << "[WlanPage] Started loading wireless net list!" + << QDateTime::currentDateTime().toString("hh:mm:ss.zzzz"); + + clearWirelessNetItemMap(m_wirelessNetItemMap, m_inactivatedNetListWidget); + m_expandedItem = nullptr; + + QList wirelessNetItemList; + if (!m_wirelessNetResource->getDeviceWifiNetwork(m_currentDevice, wirelessNetItemList)) { + qWarning()<<"[WlanPage] get wireless net item list failed."; + return; + } + + QString activateSsid = m_activateConnectionItemMap.firstKey(); + + int height = 0; + foreach (auto wirelessNetItem, wirelessNetItemList) { + if (wirelessNetItem.m_NetSsid == activateSsid) { + continue; + } + + QListWidgetItem *p_listWidgetItem = addNewItem(wirelessNetItem, m_inactivatedNetListWidget); + updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated); + m_wirelessNetItemMap.insert(wirelessNetItem.m_NetSsid, p_listWidgetItem); + + + if (height == 0) { + height += p_listWidgetItem->sizeHint().height(); + } + height += p_listWidgetItem->sizeHint().height() + NET_LIST_SPACING; + } + + m_inactivatedNetListWidget->setFixedHeight(height); + m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + + m_hiddenWlanLabel->height()); + + qDebug() << "[WlanPage] Stopped loading wireless net list! time=" + << QDateTime::currentDateTime().toString("hh:mm:ss.zzzz"); + + return; +} + +void WlanPage::initWlanArea() +{ + if (m_wlanSwitchEnable) { + m_activatedNetFrame->show(); + m_activatedNetDivider->show(); + constructActivateConnectionArea(); + + m_inactivatedNetFrame->show(); + m_inactivatedNetDivider->show(); + constructWirelessNetArea(); + } else { + m_activatedNetFrame->hide(); + m_activatedNetDivider->hide(); + + m_inactivatedNetFrame->hide(); + m_inactivatedNetDivider->hide(); + } + + return; +} + +void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item) +{ + //for dbus + QStringList info; + info <getWifiNetwork(m_currentDevice, ssid, wirelessNetItem); + if (ret) { + QListWidgetItem *p_listWidgetItem = m_wirelessNetItemMap.value(ssid); + if (p_listWidgetItem) { + WlanListItem *p_wlanItem = (WlanListItem *)m_inactivatedNetListWidget->itemWidget(p_listWidgetItem); + p_wlanItem->updateWirelessNetItem(wirelessNetItem); + } + } + + return; +} + +void WlanPage::onConnectionAdd(QString deviceName, QString ssid) +{ + if (deviceName == m_currentDevice) { + updateWlanListItem(ssid); + } + + return; +} +void WlanPage::onConnectionRemove(QString deviceName, QString ssid) +{ + if (deviceName == m_currentDevice) { + updateWlanListItem(ssid); + } + + return; +} + +void WlanPage::onSecurityTypeChange(QString devName, QString ssid, QString secuType) +{ + QListWidgetItem *p_listWidgetItem = nullptr; + WlanListItem *p_wlanItem = nullptr; + + if (m_wirelessNetItemMap.contains(ssid)) { + p_listWidgetItem = m_wirelessNetItemMap.value(ssid); + p_wlanItem = (WlanListItem*)m_inactivatedNetListWidget->itemWidget(p_listWidgetItem); + } else if (m_activateConnectionItemMap.contains(ssid)) { + p_listWidgetItem = m_activateConnectionItemMap.value(ssid); + p_wlanItem = (WlanListItem*)m_activatedNetListWidget->itemWidget(p_listWidgetItem); + } + + if (nullptr != p_wlanItem) { + p_wlanItem->updateWirelessNetSecurity(ssid, secuType); + } + + emit secuTypeChange(devName, ssid, secuType); + + return; +} + + +void WlanPage::addDeviceToCombox(QString deviceName) +{ + disconnect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &WlanPage::onDeviceComboxIndexChanged); + if (m_wlanSwitchEnable) { + if (m_currentDevice.isEmpty()){ + m_deviceFrame->hide(); + m_currentDevice = deviceName; + setDefaultDevice(WIRELESS, m_currentDevice); + } else if (m_deviceComboBox->count() == 0) { + m_deviceComboBox->addItem(m_currentDevice); + m_deviceComboBox->addItem(deviceName); + m_deviceFrame->show(); + m_deviceComboBox->show(); + m_tipsLabel->hide(); + } else { + m_deviceComboBox->addItem(deviceName); + } + } + + connect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &WlanPage::onDeviceComboxIndexChanged); + return; +} + +void WlanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType) +{ + qDebug() << LOG_FLAG << "deviceAdd" << deviceName; + if (deviceType != NetworkManager::Device::Type::Wifi) { + return; + } + + if (m_devList.contains(deviceName)) { + return; + } + + if (m_devList.isEmpty()) { + m_wlanSwitchEnable = m_switchGsettings->get(WIRELESS_SWITCH).toBool(); + //m_netSwitch->setEnabled(m_wlanSwitchEnable); + m_netSwitch->setSwitchStatus(m_wlanSwitchEnable); + } + + m_devList << deviceName; + addDeviceToCombox(deviceName); + if (m_currentDevice == deviceName) { + initWlanArea(); + } + + emit deviceStatusChanged(); + + return; +} + +void WlanPage::deleteDeviceFromCombox(QString deviceName) +{ + disconnect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &WlanPage::onDeviceComboxIndexChanged); + + if (m_wlanSwitchEnable) { + if (0 == m_devList.count()) { + m_deviceFrame->show(); + m_tipsLabel->show(); + m_deviceComboBox->hide(); + m_currentDevice = ""; + setDefaultDevice(WIRELESS, m_currentDevice); + } else if (1 == m_devList.count()) { + m_deviceFrame->hide(); + m_deviceComboBox->clear(); + m_currentDevice = m_devList.at(0); + setDefaultDevice(WIRELESS, m_currentDevice); + } else { + int index = m_deviceComboBox->findData(deviceName); + if (-1 != index) { + m_deviceComboBox->removeItem(index); + m_currentDevice = m_deviceComboBox->currentText(); + setDefaultDevice(WIRELESS, m_currentDevice); + } + } + } + + connect(m_deviceComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &WlanPage::onDeviceComboxIndexChanged); + return; +} + +void WlanPage::onDeviceRemove(QString deviceName) +{ + if (!m_devList.contains(deviceName)) { + return; + } + + qDebug() << "deviceRemove" << deviceName; + + QString originalDeviceName = m_currentDevice; + + m_devList.removeOne(deviceName); + deleteDeviceFromCombox(deviceName); + + if (m_devList.isEmpty()) { + m_wlanSwitchEnable = false; + //m_netSwitch->setEnabled(m_wlanSwitchEnable); + m_netSwitch->setSwitchStatus(m_wlanSwitchEnable); + } + + if (originalDeviceName == deviceName) { + initWlanArea(); + } + + emit deviceStatusChanged(); +} + +void WlanPage::updateDeviceForCombox(QString oldDeviceName, QString newDeviceName) +{ + if (m_currentDevice == oldDeviceName) { + m_currentDevice = newDeviceName; + setDefaultDevice(WIRELESS, m_currentDevice); + } + + int index = m_deviceComboBox->findText(oldDeviceName); + if (index != -1) { + m_deviceComboBox->setItemText(index, newDeviceName); + } + + return; +} + +void WlanPage::onDeviceNameUpdate(QString oldName, QString newName) +{ + if (!m_devList.contains(oldName)) { + return; + } + + qDebug()<<"[WlanPage] update device name, old name" + << oldName << "new Name" << newName; + + m_devList.removeOne(oldName); + m_devList.append(newName); + + QString originalDeviceName = m_currentDevice; + + updateDeviceForCombox(oldName, newName); + if (originalDeviceName != m_currentDevice) { + initWlanArea(); + } + + emit deviceNameChanged(oldName, newName); +} + +void WlanPage::sendApStateChangeSignal(QString uuid, + QString ssid, + QString deviceName, + NetworkManager::ActiveConnection::State state) +{ + bool ret = false; + ret = m_connectResource->isApConnection(uuid); + if (!ret) { + return; + } + + if (state == NetworkManager::ActiveConnection::State::Deactivated) { + qDebug() << "[WlanPage] hotspot Deactivated"; + emit hotspotDeactivated(deviceName, ssid); + } else if (state == NetworkManager::ActiveConnection::State::Activated) { + qDebug() << "[WlanPage] hotspot activated"; + emit hotspotActivated(deviceName, ssid); + } + + return; +} + +void WlanPage::wlanShowNotify(NetworkManager::ActiveConnection::State state, + NetworkManager::ActiveConnection::Reason reason) +{ + if (state == NetworkManager::ActiveConnection::State::Deactivated) { + showDesktopNotify(tr("WLAN Disconnected Successfully")); + qDebug() << "[WlanPage] wlan disconnected successfully" << Q_FUNC_INFO <<__LINE__; + } else if (state == NetworkManager::ActiveConnection::State::Activated) { + qDebug() << "[WlanPage] wlan connected successfully" << Q_FUNC_INFO <<__LINE__; + this->showDesktopNotify(tr("WLAN Connected Successfully")); + } + + return; +} + +void WlanPage::updateActivatedArea(QString uuid, QString ssid, QString devName) +{ + KyWirelessNetItem wirelessNetItem; + bool ret = m_wirelessNetResource->getWifiNetwork(devName, ssid, wirelessNetItem); + if (!ret) { + qWarning()<<"[WlanPage] get wireless item failed, when update activated connection area."; + return; + } + + if (m_activateConnectionItemMap.contains(wirelessNetItem.m_NetSsid)) { + return; + } + + if (m_expandedItem == m_wirelessNetItemMap.value(ssid)) { + m_expandedItem = nullptr; + } + deleteWirelessItemFormMap(m_wirelessNetItemMap, + m_inactivatedNetListWidget, ssid); + m_inactivatedWlanListAreaCentralWidget->setFixedHeight( + m_inactivatedNetListWidget->height() + + m_hiddenWlanLabel->height()); + + deleteWirelessItemFormMap(m_activateConnectionItemMap, m_activatedNetListWidget, EMPTY_SSID); + QListWidgetItem *p_listWidgetItem = addNewItem(wirelessNetItem, m_activatedNetListWidget); + updateWlanItemState(m_activatedNetListWidget, p_listWidgetItem, Activated); + m_activateConnectionItemMap.insert(wirelessNetItem.m_NetSsid, p_listWidgetItem); + + m_activatedNetListWidget->setFixedHeight(m_activatedNetListWidget->height() + + p_listWidgetItem->sizeHint().height() + NET_LIST_SPACING); + + return; +} + +void WlanPage::updateWirelessNetArea(QString uuid, QString ssid, QString devName) +{ + KyWirelessNetItem wirelessNetItem; + bool ret = m_wirelessNetResource->getWifiNetwork(devName, ssid, wirelessNetItem); + if (!ret) { + qWarning()<<"[WlanPage] get wireless item failed, when update wireless area."; + return; + } + + if(m_wirelessNetItemMap.contains(wirelessNetItem.m_NetSsid)) { + return; + } + + deleteWirelessItemFormMap(m_activateConnectionItemMap, m_activatedNetListWidget, ssid); + QListWidgetItem *p_activeListWidgetItem = addEmptyItem(m_activatedNetListWidget); + m_activateConnectionItemMap.insert(EMPTY_SSID, p_activeListWidgetItem); + m_activatedNetListWidget->setFixedHeight(m_activatedNetListWidget->height() + + p_activeListWidgetItem->sizeHint().height() + NET_LIST_SPACING); + + QListWidgetItem *p_listWidgetItem = addNewItem(wirelessNetItem, m_inactivatedNetListWidget); + updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated); + m_wirelessNetItemMap.insert(wirelessNetItem.m_NetSsid, p_listWidgetItem); + + m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() + + p_listWidgetItem->sizeHint().height() + NET_LIST_SPACING); + m_inactivatedWlanListAreaCentralWidget->setFixedHeight( + m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); + + return; +} + +void WlanPage::onConnectionStateChanged(QString uuid, + NetworkManager::ActiveConnection::State state, + NetworkManager::ActiveConnection::Reason reason) +{ + if (!m_connectResource->isWirelessConnection(uuid)) { + return; + } + + QString devName, ssid; + m_wirelessNetResource->getSsidByUuid(uuid, ssid); + m_wirelessNetResource->getDeviceByUuid(uuid, devName); + if (ssid.isEmpty() || devName.isEmpty()) { + return; + } + + qDebug() << "emit wlanActiveConnectionStateChanged" << devName << ssid << state; + emit wlanActiveConnectionStateChanged(devName, ssid, state); + + sendApStateChangeSignal(uuid, ssid, devName, state); + wlanShowNotify(state, reason); + + if (devName != m_currentDevice) { + return; + } + + qDebug()<< "[WlanPage] wlan state changed, ssid = " << ssid + << "; state = " << state << "; reason = " << reason << Q_FUNC_INFO <<__LINE__; + if (state == NetworkManager::ActiveConnection::State::Activated) { + updateActivatedArea(uuid, ssid, devName); + } else if (state == NetworkManager::ActiveConnection::State::Deactivated) { + updateWirelessNetArea(uuid, ssid, devName); + } else if (state == NetworkManager::ActiveConnection::State::Deactivating){ + if (m_activateConnectionItemMap.contains(ssid)) { + QListWidgetItem *p_listWidgetItem = m_activateConnectionItemMap.value(ssid); + WlanListItem *p_wlanItem = (WlanListItem*)m_activatedNetListWidget->itemWidget(p_listWidgetItem); + p_wlanItem->updateConnectState(Deactivating); + } + } else if (state == NetworkManager::ActiveConnection::State::Activating) { + if (m_wirelessNetItemMap.contains(ssid)) { + QListWidgetItem *p_listWidgetItem = m_wirelessNetItemMap.value(ssid); + WlanListItem *p_wlanItem = (WlanListItem*)m_inactivatedNetListWidget->itemWidget(p_listWidgetItem); + p_wlanItem->updateConnectState(Activating); + } + } + + return; +} + +void WlanPage::onItemHeightChanged(const bool isExpanded, const QString &ssid) +{ + if (!m_wirelessNetItemMap.contains(ssid)) { + return; + } + + QListWidgetItem *p_listWidgetItem = m_wirelessNetItemMap.value(ssid); + + qDebug()<sizeHint().height(); + int width = p_listWidgetItem->sizeHint().width(); + + if (isExpanded) { + if (m_expandedItem != p_listWidgetItem) { + qDebug()<height() - height + EXPANDED_HEIGHT; + m_inactivatedNetListWidget->setFixedHeight(wlanAreaHeight); + m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); + p_listWidgetItem->setSizeHint(expandedSize); + } + + } else { + m_expandedItem = nullptr; + + if (height > NORMAL_HEIGHT) { + qDebug()<setSizeHint(normalSize); + int wlanAreaHeight = m_inactivatedNetListWidget->height() + NORMAL_HEIGHT - height; + m_inactivatedNetListWidget->setFixedHeight(wlanAreaHeight); + m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); + } + } + + return; } void WlanPage::onDeviceComboxIndexChanged(int currentIndex) @@ -654,22 +905,26 @@ void WlanPage::onDeviceComboxIndexChanged(int currentIndex) if (!m_deviceComboBox || currentIndex < 0) { return; } - //TODO 设备变更时更新设备和列表 - QString currentDevice = m_deviceComboBox->itemText(currentIndex); - qDebug() << "Current device changed! device = " << currentDevice << Q_FUNC_INFO << __LINE__; - m_defaultDevice = currentDevice; - getActiveWlan(); - getAllWlan(); + + m_currentDevice = m_deviceComboBox->itemText(currentIndex); + setDefaultDevice(WIRELESS, m_currentDevice); + + initWlanArea(); + + return; } //申请触发扫描,初始化执行&定时执行 void WlanPage::requestScan() { if (!m_wirelessConnectOpreation) { - qWarning() << "Scan failed! m_wirelessConnectOpreation is nullptr!" << Q_FUNC_INFO << __LINE__; + qWarning() << "[WlanPage]Scan failed! m_wirelessConnectOpreation is nullptr!" << Q_FUNC_INFO << __LINE__; return; } + m_wirelessConnectOpreation->requestWirelessScan(); + + return; } void WlanPage::onHiddenWlanClicked() @@ -684,94 +939,105 @@ void WlanPage::showControlCenter() QProcess process; process.startDetached("ukui-control-center --wlanconnect"); } + void WlanPage::onWifiEnabledChanged(bool isWifiOn) { -//监听外部命令导致wifi状态变化,更新界面 + //监听外部命令导致wifi状态变化,更新界面 //应该先检测是否有无线网卡可用,才改变开关状态 - m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, m_devList); if (m_devList.isEmpty()) { - qDebug() << "have no device to use " << Q_FUNC_INFO << __LINE__; + qDebug() << "[WLanPage] have no device to use " << Q_FUNC_INFO << __LINE__; return; } - if (m_netSwitch->getSwitchStatus() == isWifiOn) { + + if (m_wlanSwitchEnable == isWifiOn) { return; } else { - //m_wirelessConnectOpreation->setWirelessEnabled(isWifiOn); - m_netSwitch->setSwitchStatus(isWifiOn); - //外部命令导致连接状态发生变化,通知主界面刷新图标 + //m_netSwitch->setSwitchStatus(isWifiOn); + //m_netSwitch->setEnabled(isWifiOn); + m_switchGsettings->set(WIRELESS_SWITCH, isWifiOn); emit this->wlanConnectChanged(); } + + return; } -void WlanPage::onActiveFailed(QString errorMessage) -{ - qDebug() << "active failed and the message is: " << errorMessage << Q_FUNC_INFO << __LINE__; -} - -void WlanPage::updateByStrength() +void WlanPage::onRefreshIconTimer() { if (m_expandedItem) { - qDebug() << "Has expanded item and forbid refresh wifi strength" << Q_FUNC_INFO << __LINE__; + qDebug()<< LOG_FLAG << "Has expanded item and forbid refresh wifi strength" << Q_FUNC_INFO << __LINE__; return; } - qDebug() << "Will update Wlan list by strength." << Q_FUNC_INFO << __LINE__; + + qDebug()<< LOG_FLAG << "Will update Wlan list by strength." << Q_FUNC_INFO << __LINE__; + QList wlanList; - if (!m_resource->getDeviceWifiNetwork(m_defaultDevice, wlanList)) { + if (!m_wirelessNetResource->getDeviceWifiNetwork(m_currentDevice, wlanList)) { return; } -// int height = 0; - int currentRow = 0; - for (int i = 0; i < wlanList.length(); i ++) { - if (wlanList.at(i).m_NetSsid == this->m_activatedWlanSSid) { //排除已连接WiFi + + QString activateSsid = m_activateConnectionItemMap.firstKey(); + int sortRow = 0; + for (int index = 0; index < wlanList.length(); index++) { + KyWirelessNetItem sortItem = wlanList.at(index); + QString sortSsid = sortItem.m_NetSsid; //应该在第currentRow行的新的WiFi名称 + qDebug()<< LOG_FLAG << "sort ssid"<< sortSsid << "active ssid" << activateSsid << "sort row"<< sortRow; + if (sortSsid == activateSsid) { //排除已连接WiFi continue; } - QString currentSsid = wlanList.at(i).m_NetSsid; //应该在第currentRow行的新的WiFi名称 - QModelIndex currentIndex = m_inactivatedNetListWidget->model()->index(currentRow, 0, QModelIndex()); //当前行的index - WlanListItem * lastWlan = static_cast(m_inactivatedNetListWidget->indexWidget(currentIndex)); //原来在第currentRow行的WlanListItem - if (lastWlan && currentSsid == lastWlan->getSsid()) { //WiFi的排序未改变,不需要修改,继续遍历 - currentRow ++; - continue; - } else if (!lastWlan) { //已经超出原列表长度了,需要new一个放上去 - KyWirelessNetItem *data = new KyWirelessNetItem(wlanList.at(i)); - WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, m_defaultDevice); - QListWidgetItem *wlanItem = new QListWidgetItem(); - connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); - connect(wlanItemWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked); - QPair pair (wlanItem, wlanItemWidget); - m_itemsMap.insert(data->m_NetSsid, pair); - wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height())); - m_inactivatedNetListWidget->addItem(wlanItem); - m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget); - int height = m_inactivatedNetListWidget->height() + wlanItemWidget->height() + NET_LIST_SPACING; - m_inactivatedNetListWidget->setFixedHeight(height); - m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); - } else {//找到了该位置的wifi而且与现在的排序不符,需要调整 - KyWirelessNetItem *data = new KyWirelessNetItem(wlanList.at(i)); - WlanListItem * currentWlan = new WlanListItem(m_resource, data, m_defaultDevice); - connect(currentWlan, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); - connect(currentWlan, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked); - QPair newPair; - newPair.first = m_itemsMap.value(lastWlan->getSsid()).first; - newPair.second = currentWlan; - m_itemsMap[currentSsid] = newPair;//先把map中的当前行wlan替换掉,第currentRow行的ssid->currentRow行的控件 - m_itemsMap[lastWlan->getSsid()] = newPair;//临时使原来指向第currentRow行的的wlan依然指向这个value,防止访问空指针的情况发生,等遍历到该ssid时会赋予其正确的value - m_inactivatedNetListWidget->setIndexWidget(currentIndex, currentWlan); //最后把新的wlan填充到currentRow行 + + QListWidgetItem *p_listWidgetItem = m_inactivatedNetListWidget->item(sortRow); + if (p_listWidgetItem) { + WlanListItem *p_wlanItem = (WlanListItem *)m_inactivatedNetListWidget->itemWidget(p_listWidgetItem); + qDebug()<< LOG_FLAG << "row" << sortRow << "item ssid" << p_wlanItem->getSsid(); + if (sortSsid == p_wlanItem->getSsid()) { + qDebug()<< LOG_FLAG << "sort wlan set signal strength." << Q_FUNC_INFO << __LINE__; + p_wlanItem->setWlanSignal(sortItem.m_signalStrength); + sortRow++; + continue; + } + + QListWidgetItem *p_sortListWidgetItem = m_wirelessNetItemMap.value(sortSsid); + if (p_sortListWidgetItem) { + qDebug()<< LOG_FLAG << "sort wlan update position." << sortSsid << Q_FUNC_INFO << __LINE__; + int takeRow = m_inactivatedNetListWidget->row(p_sortListWidgetItem); + m_inactivatedNetListWidget->takeItem(takeRow); + + WlanListItem *p_sortWlanItem = new WlanListItem(sortItem, m_currentDevice); + connect(p_sortWlanItem, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); + m_inactivatedNetListWidget->insertItem(sortRow, p_sortListWidgetItem); + p_sortWlanItem->updateConnectState(Deactivated); + m_inactivatedNetListWidget->setItemWidget(p_sortListWidgetItem, p_sortWlanItem); + sortRow++; + continue; + } } - currentRow ++; + + qDebug()<< LOG_FLAG << "sort wlan add new item." << Q_FUNC_INFO << __LINE__; + QListWidgetItem *p_newListWidgetItem = insertNewItem(sortItem, m_inactivatedNetListWidget, sortRow); + updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated); + m_wirelessNetItemMap.insert(sortItem.m_NetSsid, p_newListWidgetItem); + + int height = m_inactivatedNetListWidget->height() + + p_newListWidgetItem->sizeHint().height() + NET_LIST_SPACING; + m_inactivatedNetListWidget->setFixedHeight(height); + m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + + m_hiddenWlanLabel->height()); + sortRow++; } + + qDebug()<< LOG_FLAG << "sort wlan finished." << Q_FUNC_INFO << __LINE__; + + return; } - - //for dbus void WlanPage::getWirelessList(QMap > &map) { QMap actMap; - m_resource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap); + m_wirelessNetResource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap); QMap > wlanMap; - if (!m_resource->getAllDeviceWifiNetwork(wlanMap)) - { + if (!m_wirelessNetResource->getAllDeviceWifiNetwork(wlanMap)) { return; } @@ -782,7 +1048,7 @@ void WlanPage::getWirelessList(QMap > &map) //先是已连接 if (actMap.contains(iter.key())) { KyWirelessNetItem data; - if (m_resource->getWifiNetwork(iter.key(), actMap[iter.key()].at(0), data)) { + if (m_wirelessNetResource->getWifiNetwork(iter.key(), actMap[iter.key()].at(0), data)) { vector.append(QStringList()< apConnectItemList; - m_apConnectResource->getApConnections(apConnectItemList); + m_connectResource->getApConnections(apConnectItemList); if (!apConnectItemList.isEmpty()) { uuid = apConnectItemList.at(0)->m_connectUuid; } + m_wirelessConnectOpreation->activeWirelessAp(uuid, apName, apPassword, apDevice); } @@ -822,7 +1089,7 @@ void WlanPage::deactiveWirelessAp(const QString apName, const QString apPassword { QString uuid(""); QList apConnectItemList; - m_apConnectResource->getApConnections(apConnectItemList); + m_connectResource->getApConnections(apConnectItemList); if (!apConnectItemList.isEmpty()) { foreach (auto item, apConnectItemList) { if (apName == item->m_connectName && apPassword == item->m_password && apDevice == item->m_ifaceName) { @@ -832,6 +1099,7 @@ void WlanPage::deactiveWirelessAp(const QString apName, const QString apPassword } } } + if (!uuid.isEmpty()) { m_wirelessConnectOpreation->deactiveWirelessAp(apName, uuid); } else { @@ -844,103 +1112,94 @@ void WlanPage::getStoredApInfo(QStringList &list) { list.clear(); QList apConnectItemList; - m_apConnectResource->getApConnections(apConnectItemList); + m_connectResource->getApConnections(apConnectItemList); if (!apConnectItemList.isEmpty()) { list << apConnectItemList.at(0)->m_connectName; list << apConnectItemList.at(0)->m_password; list << apConnectItemList.at(0)->m_ifaceName; list << (apConnectItemList.at(0)->m_isActivated? "true":"false"); } + + return; } -void WlanPage::activateWireless(const QString& devName, const QString& ssid) +void WlanPage::activateWirelessConnection(const QString& devName, const QString& ssid) { - KyWirelessNetItem data; - if (!m_resource->getWifiNetwork(devName, ssid, data)) { - qDebug() << "no such wifi " << ssid << " in " << devName; + KyWirelessNetItem wirelessNetItem; + if (!m_wirelessNetResource->getWifiNetwork(devName, ssid, wirelessNetItem)) { + qDebug() << "[WlanPage] no such wifi " << ssid << " in " << devName; return; } - if (data.m_isConfigured) { - m_wirelessConnectOpreation->activeWirelessConnect(devName, data.m_connectUuid); + if (wirelessNetItem.m_isConfigured) { + m_wirelessConnectOpreation->activeWirelessConnect(devName, wirelessNetItem.m_connectUuid); } else { //todo: 显示界面输入密码 (无需密码的wifi?) } + + return; } -void WlanPage::deactivateWireless(const QString& devName, const QString& ssid) +void WlanPage::deactivateWirelessConnection(const QString& devName, const QString& ssid) { - KyWirelessNetItem data; - if (!m_resource->getWifiNetwork(devName, ssid, data)) { - qDebug() << "no such wifi " << ssid << " in " << devName; + KyWirelessNetItem wirelessNetItem; + if (!m_wirelessNetResource->getWifiNetwork(devName, ssid, wirelessNetItem)) { + qDebug() << "[WlanPage] no such wifi " << ssid << " in " << devName; return; } - QMap actMap; - m_resource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap); - QMap::iterator iter = actMap.begin(); - if (!actMap.contains(devName)) { - qDebug() << "no such device" << devName; + if (!m_connectResource->isActivatedConnection(wirelessNetItem.m_connectUuid)) { + qDebug()<<"[WlanPage]"<getSsidByUuid(uuid, actSsid, devInterface); + qDebug() << "[WlanPage] deActivate Wireless Connection" << devName << ssid; - if (actSsid != ssid) { - qDebug() << "no such actived wifi" << ssid; - return; - } + m_wirelessConnectOpreation->deActivateWirelessConnection(wirelessNetItem.m_connName, wirelessNetItem.m_connectUuid); - qDebug() << "deActivateWirelessConnection" << devName << ssid; - m_wirelessConnectOpreation->deActivateWirelessConnection(data.m_connName, data.m_connectUuid); + return; } void WlanPage::onMainWindowVisibleChanged(const bool &visible) { - qDebug() << "Received signal of mainwindow visible changed. cur_state = " << visible << Q_FUNC_INFO << __LINE__; + qDebug() << "[WlanPage] Received signal of mainwindow visible changed. cur_state = " << visible << Q_FUNC_INFO << __LINE__; if (visible) { - //打开页面时先触发一次扫描 + //打开页面时先触发一次扫描,然后定时扫描wifi热点和刷新icon requestScan(); - } - - if (!m_scanTimer) { - qWarning() << "No QTimer!" << Q_FUNC_INFO << __LINE__; - return; - } - //若页面打开,开始扫描倒计时,若关闭,停止扫描倒计时 - if (visible) { - qWarning() << "start refresh Timer" << Q_FUNC_INFO << __LINE__; - m_scanTimer->start(20 * 1000); - m_refreshIconTimer->start(5*1000); + m_scanTimer->start(AP_SCAN_INTERVAL); + m_refreshIconTimer->start(ICON_REFRESH_INTERVAL); } else { + //界面关闭的时候,停止wifi扫描和刷新 m_scanTimer->stop(); m_refreshIconTimer->stop(); } + + return; } void WlanPage::showDetailPage(QString devName, QString ssid) { - KyWirelessNetItem data; - if (!m_resource->getWifiNetwork(devName, ssid, data)) { + KyWirelessNetItem wirelessNetItem; + if (!m_wirelessNetResource->getWifiNetwork(devName, ssid, wirelessNetItem)) { 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 = m_connectResource->isActivatedConnection(wirelessNetItem.m_connectUuid); - QString actSsid; - m_resource->getSsidByUuid(actMap[devName].at(0), actSsid, devName); - - bool isActive = !actSsid.compare(ssid); - NetDetail *netDetail = new NetDetail(devName, ssid, data.m_connectUuid, isActive, true, true, this); + NetDetail *netDetail = new NetDetail(devName, ssid, wirelessNetItem.m_connectUuid, isActive, true, false, this); netDetail->show(); + + return; } +bool WlanPage::wlanIsConnected() +{ + if (m_activateConnectionItemMap.isEmpty()) { + return false; + } else if (m_activateConnectionItemMap.contains(EMPTY_SSID)) { + return false; + } + + return true; +} diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index dd3c748f..dca1e9e1 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -26,7 +26,6 @@ class WlanPage : public TabPage public: explicit WlanPage(QWidget *parent = nullptr); ~WlanPage() = default; - bool m_wlanIsConnected = false; //for dbus void getWirelessList(QMap > &map); @@ -36,10 +35,13 @@ public: void deactiveWirelessAp(const QString apName, const QString apPassword, const QString apDevice); //获取热点 void getStoredApInfo(QStringList &list); - void activateWireless(const QString& devName, const QString& ssid); - void deactivateWireless(const QString& devName, const QString& ssid); + void activateWirelessConnection(const QString& devName, const QString& ssid); + void deactivateWirelessConnection(const QString& devName, const QString& ssid); void showDetailPage(QString devName, QString uuid); + + bool wlanIsConnected(); + signals: void oneItemExpanded(const QString &ssid); void wlanAdd(QString devName, QStringList info); @@ -54,81 +56,108 @@ signals: public slots: void onMainWindowVisibleChanged(const bool &visible); - -protected: - bool eventFilter(QObject *watched, QEvent *event); - -private: - void initWlanUI(); - void initConnections(); - int getIndexByStrength(QString interface, QString ssid); - void updateByStrength(); - QString m_activedssid; - QString m_disconnectuuid; - int m_disconnecting; - bool m_disconnectingflag = false; - - //定时触发扫描的定时器 - void initTimer(); - QTimer * m_scanTimer = nullptr; - QTimer * m_refreshIconTimer = nullptr; - - void initDevice();//初始化默认设备 - void initDeviceCombox(); - - void getActiveWlan(); - void appendActiveWlan(const QString &uuid, int &height); - void getAllWlan(); - - QMap> m_itemsMap; - QListWidgetItem *m_expandedItem = nullptr; - QFrame * m_inactivatedWlanListAreaCentralWidget = nullptr; - QVBoxLayout * m_inactivatedWlanListAreaLayout = nullptr; - QFrame * m_hiddenWlanWidget = nullptr; - QHBoxLayout * m_hiddenWlanLayout = nullptr; - QListWidget * m_activatedNetListWidget = nullptr; - QLabel * m_hiddenWlanLabel = nullptr; - - QString m_activatedWlanSSid; - QString m_activatedWlanUuid; - QStringList m_devList; - - KyWirelessNetResource *m_resource = nullptr; - KyActiveConnectResourse *m_connectResource = nullptr; - KyNetworkResourceManager *m_networkResourceInstance = nullptr; - KyNetworkDeviceResourse *m_netDeviceResource = nullptr; - KyWirelessConnectOperation * m_wirelessConnectOpreation = nullptr; - KyConnectOperation *m_connectoperation = nullptr; - KyConnectResourse * m_apConnectResource = nullptr; - QGSettings *m_switchGsettings = nullptr; - + void onSecurityTypeChange(QString devName, QString ssid, QString secuType); private slots: void onWlanAdded(QString interface, KyWirelessNetItem &item); void onWlanRemoved(QString interface, QString ssid); - void onWlanUpdated(); + + void onConnectionAdd(QString deviceName, QString ssid); + void onConnectionRemove(QString deviceName, QString ssid); void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType); void onDeviceRemove(QString deviceName); void onDeviceNameUpdate(QString oldName, QString newName); - void onActivatedWlanChanged(QString uuid, + + void onConnectionStateChanged(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason); - void onItemHeightChanged(const QString &ssid); - void onConnectButtonClicked(KyWirelessConnectSetting &connSettingInfo, const bool &isHidden); + void onItemHeightChanged(const bool isExpanded, const QString &ssid); + void onWlanSwitchClicked(); - void onWlanSwitchStatusChanged(const bool &checked); + void onWlanSwithGsettingsChanged(const QString &key); + void onDeviceComboxIndexChanged(int currentIndex); void requestScan(); void onHiddenWlanClicked(); void showControlCenter(); void onWifiEnabledChanged(bool isWifiOn); - void onActiveFailed(QString errorMessage); + void onRefreshIconTimer(); -// void onRefreshIconTimer(); +protected: + bool eventFilter(QObject *watched, QEvent *event); -// void onsignalStrengthChange(QString, QString, int); +private: + //定时触发扫描的定时器 + void initTimer(); + void initWlanUI(); + void initConnections(); + void initDevice();//初始化默认设备 + void initDeviceCombox(); + void initWlanSwitchState(); + void initWlanArea(); + QListWidgetItem *addEmptyItem(QListWidget *wirelessListWidget); + QListWidgetItem *addNewItem(KyWirelessNetItem &wirelessNetItem, + QListWidget *wirelessListWidget); + QListWidgetItem *insertNewItem(KyWirelessNetItem &wirelessNetItem, + QListWidget *wirelessListWidget, + int row); + + void clearWirelessNetItemMap(QMap &wirelessNetItem, + QListWidget *wirelessListWidget); + void deleteWirelessItemFormMap(QMap &wirelessNetItemMap, + QListWidget *wirelessListWidget, QString ssid); + + void updateWlanItemState(QListWidget *p_wirelessListWidget, + QListWidgetItem *p_listWidgetItem, + ConnectState state); + void updateWlanListItem(QString ssid); + + void constructWirelessNetArea(); + void constructActivateConnectionArea(); + + void updateActivatedArea(QString uuid, QString ssid, QString devName); + void updateWirelessNetArea(QString uuid, QString ssid, QString devName); + + void addDeviceToCombox(QString deviceName); + void deleteDeviceFromCombox(QString deviceName); + void updateDeviceForCombox(QString oldDeviceName, QString newDeviceName); + + void sendApStateChangeSignal(QString uuid, QString ssid, QString deviceName, + NetworkManager::ActiveConnection::State state); + void wlanShowNotify(NetworkManager::ActiveConnection::State state, + NetworkManager::ActiveConnection::Reason reason); + +private: + QMap m_wirelessNetItemMap; + QMap m_activateConnectionItemMap; + + QListWidgetItem *m_expandedItem = nullptr; + + QFrame * m_inactivatedWlanListAreaCentralWidget = nullptr; + QVBoxLayout * m_inactivatedWlanListAreaLayout = nullptr; + + QFrame * m_hiddenWlanWidget = nullptr; + QHBoxLayout * m_hiddenWlanLayout = nullptr; + QLabel * m_hiddenWlanLabel = nullptr; + + QListWidget * m_activatedNetListWidget = nullptr; + + QStringList m_devList; + QString m_currentDevice; + + KyWirelessNetResource *m_wirelessNetResource = nullptr; + KyActiveConnectResourse *m_activatedConnectResource = nullptr; + KyNetworkDeviceResourse *m_netDeviceResource = nullptr; + KyWirelessConnectOperation * m_wirelessConnectOpreation = nullptr; + KyConnectResourse * m_connectResource = nullptr; + + QGSettings *m_switchGsettings = nullptr; + bool m_wlanSwitchEnable = true; + + QTimer *m_scanTimer = nullptr; + QTimer *m_refreshIconTimer = nullptr; }; #endif // WLANPAGE_H From 801b403973d01c0a6e7c4ab4bf51459569eeee67 Mon Sep 17 00:00:00 2001 From: renpeijia Date: Tue, 19 Oct 2021 14:56:50 +0800 Subject: [PATCH 2/5] modify:1)delete invalide files. 2) update wlan item state failed. 3) the ui show failed, when wireless device is empty. --- src/frontend/kylinwiredwidget.cpp | 206 -------- src/frontend/kylinwiredwidget.h | 65 --- src/frontend/list-items/lanlistitem.h | 1 - src/frontend/list-items/wlanlistitem.cpp | 29 +- src/frontend/nmdemo.cpp | 615 ----------------------- src/frontend/nmdemo.h | 93 ---- src/frontend/tab-pages/wlanpage.cpp | 46 +- src/frontend/tab-pages/wlanpage.h | 2 +- 8 files changed, 32 insertions(+), 1025 deletions(-) delete mode 100644 src/frontend/kylinwiredwidget.cpp delete mode 100644 src/frontend/kylinwiredwidget.h delete mode 100644 src/frontend/nmdemo.cpp delete mode 100644 src/frontend/nmdemo.h diff --git a/src/frontend/kylinwiredwidget.cpp b/src/frontend/kylinwiredwidget.cpp deleted file mode 100644 index 3807d792..00000000 --- a/src/frontend/kylinwiredwidget.cpp +++ /dev/null @@ -1,206 +0,0 @@ -#include "kylinwiredwidget.h" - -KyWiredWidget::KyWiredWidget(QWidget *parent):QWidget(parent) -{ - m_activeConnectResource = new KyActiveConnectResourse(); - m_connectResource = new KyConnectResourse(); - m_deviceResource = new KyNetworkDeviceResourse(); - - connect(m_activeConnectResource, &KyActiveConnectResourse::activeConnectRemove, - this, &KyWiredWidget::removeActiveConnection); - connect(m_activeConnectResource, &KyActiveConnectResourse::stateChangeReason, - this, &KyWiredWidget::activeConnectStateChange); - - connect(m_connectResource, &KyConnectResourse::connectionAdd, this, &KyWiredWidget::addConnection); - connect(m_connectResource, &KyConnectResourse::connectionRemove, this, &KyWiredWidget::removeConnection); - connect(m_connectResource, &KyConnectResourse::connectionUpdate, this, &KyWiredWidget::updateConnection); - - connect(m_deviceResource, &KyNetworkDeviceResourse::carrierChanage,this, &KyWiredWidget::wiredDeviceCarrierChange); - - m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), this, SLOT(updateWidgetList())); -} -KyWiredWidget::~KyWiredWidget() -{ - delete m_activeConnectResource; - delete m_connectResource; - delete m_deviceResource; -} - -void KyWiredWidget::constructWiredActiveConnectList() -{ - qDebug()<<"constructWiredActiveConnectList"; - QList wiredActiveConnect; - m_activeConnectResource->getActiveConnectionList("enp2s0", - NetworkManager::ConnectionSettings::ConnectionType::Wired, - wiredActiveConnect); -// if (wiredActiveConnect.isEmpty()) { -// LanListItem *activeWiredForm = new LanListItem(this, nullptr); -// activeWiredForm->constructActiveConnectionEmptyItem(); -// m_wiredActiveFormlist<constructActiveConnectionItem(index); -// m_wiredActiveFormlist< wiredConnections; - m_connectResource->getConnectionList("enp2s0", - NetworkManager::ConnectionSettings::ConnectionType::Wired, - wiredConnections); -// if (!wiredConnections.isEmpty()) { -// for (int index = 0; index < wiredConnections.size(); ++index) { -// resize(W_LIST_WIDGET, height() + H_NORMAL_ITEM); -// OneLancForm *wiredForm = new OneLancForm(this, wiredConnections.at(index)); -// wiredForm->constructConnectionItem(index); -// m_wiredFormlist<stop(); - - if (ACTIVECONNECTION == m_type) { - updateWiredActiveConnection(); - } else { - updateWiredConnection(); - } - - return; -} - -void KyWiredWidget::removeActiveConnection(QString connectUuid) -{ - m_timer->start(300); - return; -} - -void KyWiredWidget::activeConnectStateChange(QString connectUuid, - NetworkManager::ActiveConnection::State state, - NetworkManager::ActiveConnection::Reason reason) -{ - qDebug()<<"active connection"<start(300); - } - - return; -} - -void KyWiredWidget::addConnection(QString connectUuid) -{ - qDebug()<<"add connection "<setDeviceRefreshRate(deviceName, ms); - return; -} - -#if 0 -void KyWiredWidget::updateNetworkSpeed(KyConnectItem *wiredItem) -{ - qulonglong txBytes = wiredItem->m_upSpeed; - qulonglong rxBytes = wiredItem->m_downSpeed; - - m_deviceResource->DeviceSpeed(wiredItem->m_ifaceName, wiredItem); - - if (wiredItem->m_upSpeed > txBytes) { - txBytes = wiredItem->m_upSpeed - txBytes; - } else { - txBytes = 0; - } - - if (wiredItem->m_downSpeed > rxBytes) { - rxBytes = wiredItem->m_downSpeed - rxBytes; - } else { - rxBytes = 0; - } - - emit updateSpeed(rxBytes, txBytes); - - return; -} -#endif diff --git a/src/frontend/kylinwiredwidget.h b/src/frontend/kylinwiredwidget.h deleted file mode 100644 index 360560bd..00000000 --- a/src/frontend/kylinwiredwidget.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef KYLINWIREDWIDGET_H -#define KYLINWIREDWIDGET_H - -#include -#include "backend/dbus-interface/kylinactiveconnectresource.h" -#include "backend/dbus-interface/kylinconnectresource.h" -#include "backend/dbus-interface/kylinnetworkdeviceresource.h" -#include "backend/dbus-interface/kylinconnectitem.h" -#include "lanlistitem.h" -#include "mainwindow.h" - -class LanListItem; - -typedef enum{ - ACTIVECONNECTION, - CONNECTION, -}WIDGETTYPE; - -class KyWiredWidget : public QWidget -{ - Q_OBJECT -public: - explicit KyWiredWidget(QWidget *parent = nullptr); - ~KyWiredWidget(); - - void setType(WIDGETTYPE type); - void constructWiredConnectList(); - void constructWiredActiveConnectList(); - - void updateDeviceRefreshRate(QString deviceName, int ms); - void updateNetworkSpeed(KyConnectItem *wiredItem); - -private: - void updateWiredActiveConnection(); - void updateWiredConnection(); - -signals: - void updateSpeed(qulonglong rx, qulonglong tx); - -public slots: - void removeActiveConnection(QString connectUuid); - void activeConnectStateChange(QString uuid, - NetworkManager::ActiveConnection::State state, - NetworkManager::ActiveConnection::Reason reason); - - void addConnection(QString connectUuid); - void updateConnection(QString connectUuid); - void removeConnection(QString path); - - void wiredDeviceCarrierChange(QString deviceName, bool pluged); - - void updateWidgetList(); -private: - WIDGETTYPE m_type; - QTimer *m_timer; - - KyActiveConnectResourse *m_activeConnectResource = nullptr; - KyConnectResourse *m_connectResource = nullptr; - KyNetworkDeviceResourse *m_deviceResource = nullptr; - - QList m_wiredActiveFormlist; - QList m_wiredFormlist; -}; - -#endif // KYLINWIREDWIDGET_H diff --git a/src/frontend/list-items/lanlistitem.h b/src/frontend/list-items/lanlistitem.h index 50a25997..817dc2bd 100644 --- a/src/frontend/list-items/lanlistitem.h +++ b/src/frontend/list-items/lanlistitem.h @@ -1,7 +1,6 @@ #ifndef LANLISTITEM_H #define LANLISTITEM_H #include "listitem.h" -#include "kylinwiredwidget.h" #include "kylinactiveconnectresource.h" #include diff --git a/src/frontend/list-items/wlanlistitem.cpp b/src/frontend/list-items/wlanlistitem.cpp index 227a0680..a910bd30 100644 --- a/src/frontend/list-items/wlanlistitem.cpp +++ b/src/frontend/list-items/wlanlistitem.cpp @@ -10,7 +10,6 @@ WlanListItem::WlanListItem(KyWirelessNetItem &wirelessNetItem, QString device, Q { m_wlanDevice = device; m_wirelessNetItem = wirelessNetItem; - m_forgetConnection = false; qDebug()<<"[WlanPage] wlan list item is created." << m_wirelessNetItem.m_NetSsid; @@ -132,14 +131,14 @@ void WlanListItem::onRightButtonClicked() void WlanListItem::enterEvent(QEvent *event) { - qDebug()<< LOG_FLAG <<"enterEvent" << m_wirelessNetItem.m_NetSsid; + //qDebug()<< LOG_FLAG <<"enterEvent" << m_wirelessNetItem.m_NetSsid; m_mouseIsOut = false; return ListItem::enterEvent(event); } void WlanListItem::leaveEvent(QEvent *event) { - qDebug()<< LOG_FLAG <<"leaveEvent"<< m_wirelessNetItem.m_NetSsid; + //qDebug()<< LOG_FLAG <<"leaveEvent"<< m_wirelessNetItem.m_NetSsid; m_mouseIsOut = true; if (m_pwdFrame && m_pwdFrame->isVisible()) { if (m_focusIsOut) { @@ -156,12 +155,12 @@ bool WlanListItem::eventFilter(QObject *watched, QEvent *event) if (watched == m_pwdLineEdit) { if (event->type() == QEvent::FocusOut) { m_focusIsOut = true; - qDebug()<< LOG_FLAG <<"focusOutEvent" << m_wirelessNetItem.m_NetSsid; + //qDebug()<< LOG_FLAG <<"focusOutEvent" << m_wirelessNetItem.m_NetSsid; if (m_mouseIsOut) { setExpanded(false); } } else if (event->type() == QEvent::FocusIn) { - qDebug()<< LOG_FLAG <<"focusInEvent" << m_wirelessNetItem.m_NetSsid; + //qDebug()<< LOG_FLAG <<"focusInEvent" << m_wirelessNetItem.m_NetSsid; m_focusIsOut = false; } } @@ -477,16 +476,6 @@ void WlanListItem::updateConnectState(ConnectState state) { m_connectState = state; - if (m_forgetConnection) { - /* - * 如果是要删除链接而导致的状态变化的话,等断开连接后,删除该链接 - */ - if (state == Deactivated) { - m_wirelessConnectOperation->deleteWirelessConnect(m_wirelessNetItem.m_connectUuid); - m_forgetConnection = false; - } - } - if (Deactivated == state || Activated == state) { m_netButton->stopLoading(); } else { @@ -501,15 +490,7 @@ void WlanListItem::onMenuTriggered(QAction *action) if (action->text() == tr("Disconnect") || action->text() == tr("Connect")) { this->onNetButtonClicked(); } else if (action->text() == tr("Forget")) { - /* - *对于激活的链接,忘记密码时,需要先断开连接,然后再删除链接。 - */ - if (Activated == m_connectState) { - m_forgetConnection = true; - m_wirelessConnectOperation->deActivateWirelessConnection(m_wlanDevice, m_wirelessNetItem.m_connectUuid); - } else { - m_wirelessConnectOperation->deleteWirelessConnect(m_wirelessNetItem.m_connectUuid); - } + m_wirelessConnectOperation->deleteWirelessConnect(m_wirelessNetItem.m_connectUuid); } return; diff --git a/src/frontend/nmdemo.cpp b/src/frontend/nmdemo.cpp deleted file mode 100644 index 3b31412e..00000000 --- a/src/frontend/nmdemo.cpp +++ /dev/null @@ -1,615 +0,0 @@ -#include "nmdemo.h" -#include -#include - -QString enumToQstring(NetworkManager::ActiveConnection::State state) -{ - switch (state) { - case NetworkManager::ActiveConnection::State::Unknown: - return "Unknown"; - break; - case NetworkManager::ActiveConnection::State::Activating: - return "Activating"; - break; - case NetworkManager::ActiveConnection::State::Activated: - return "Activated"; - break; - case NetworkManager::ActiveConnection::State::Deactivating: - return "Deactivating"; - break; - case NetworkManager::ActiveConnection::State::Deactivated: - return "Deactivated"; - break; - default: - return ""; - break; - } -} - -NmDemo::NmDemo(QWidget *parent) : QDialog(parent) -{ - this->setFixedSize(510,810); - - //init ptr - m_networkResourceInstance = KyNetworkResourceManager::getInstance(); - m_wco = new KyWirelessConnectOperation(this); - m_wnr = new KyWirelessNetResource(this); - m_acr = new KyActiveConnectResourse(this); - m_cr = new KyConnectResourse(this); - m_timer = new QTimer(this); - - initUi(); - appendDebugLog("init..."); - initConnect(); - initTimer(); - appendDebugLog("init finish..."); - getWifiList(); - - if (m_wco->getWirelessEnabled()) - { - wlansStatus->setText("WLAN:ENABLE"); - } else { - wlansStatus->setText("WLAN:DISABLE"); - } -} - -NmDemo::~NmDemo() -{ - m_networkResourceInstance = nullptr; -} - -void NmDemo::initUi() -{ - refreshButton = new QPushButton(this); - refreshButton->setText("Refresh"); - connectButton = new QPushButton(this); - connectButton->setText("Connect"); - disConnectButton = new QPushButton(this); - disConnectButton->setText("DisConn"); - modifyButton = new QPushButton(this); - modifyButton->setText("Modify"); - enableButton = new QPushButton(this); - enableButton->setText("Enable"); - disableButton = new QPushButton(this); - disableButton->setText("Disable"); - addButton = new QPushButton(this); - addButton->setText("Add"); - wifiList = new QTextEdit(this); - debugLog = new QTextEdit(this); - ssidText = new QLineEdit(this); - ifaceNameText = new QLineEdit(this); - pwdText = new QLineEdit(this); - wlansStatus = new QLabel(this); - ssidLabel = new QLabel(this); - ssidLabel->setText("SSID"); - ifaceLabel = new QLabel(this); - ifaceLabel->setText("IfaceName"); - pwdLabel = new QLabel(this); - pwdLabel->setText("password"); - actConnection = new QLabel(this); - - - refreshButton->setGeometry( 5, 5, 80, 30); - connectButton->setGeometry(105, 5, 80, 30); - disConnectButton->setGeometry(205, 5, 80, 30); - addButton->setGeometry(305, 5 ,80 ,30); - modifyButton->setGeometry(5, 55, 80, 30); - enableButton->setGeometry(105, 55, 80, 30); - disableButton->setGeometry(205, 55, 80, 30); - wlansStatus->setGeometry(305, 55, 180, 30); - ssidLabel->setGeometry(5, 105, 80, 30); - ssidText->setGeometry(100, 105, 100, 30); - pwdLabel->setGeometry(250, 105, 80, 30); - pwdText->setGeometry(345, 105, 150, 30); - actConnection->setGeometry(250, 145, 245, 30); - ifaceLabel->setGeometry(5, 145, 80, 30); - ifaceNameText->setGeometry(100, 145, 100, 30); - wifiList->setGeometry(5, 200, 500,300); - wifiList->setReadOnly(true); - debugLog->setGeometry(5, 510, 500,300); - debugLog->setReadOnly(true); -} - -void NmDemo::initConnect() -{ - connect(m_wco, &KyWirelessConnectOperation::wifiEnabledChanged,[=](bool status){ - QString temp; - temp.sprintf("wifinEnabledChanged %d",status); - appendDebugLog(temp); - if (status) - { - wlansStatus->setText("WLAN:ENABLE"); - } else { - wlansStatus->setText("WLAN:DISABLE"); - } - }); - - //ui button - connect(refreshButton, &QPushButton::clicked, [=](){ -// appendDebugLog("init refreshButton clicked..."); -// m_wco->requestWirelessScan(); - getWifiList(); - }); - - connect(connectButton, &QPushButton::clicked, this, &NmDemo::onConnectClicked); - connect(disConnectButton, &QPushButton::clicked, this, &NmDemo::onDisConnectClicked); - connect(modifyButton, &QPushButton::clicked, this, &NmDemo::onModifyClicked); - connect(enableButton, &QPushButton::clicked, this, &NmDemo::onEnableClick); - connect(disableButton, &QPushButton::clicked, this, &NmDemo::onDisableClick); - connect(addButton, &QPushButton::clicked, this, &NmDemo::onAddClick); - - //连接变化 - - - connect(m_wco, &KyWirelessConnectOperation::createConnectionError, this, &NmDemo::onWcoSignals); - connect(m_wco, &KyWirelessConnectOperation::updateConnectionError, this, &NmDemo::onWcoSignals); - connect(m_wco, &KyWirelessConnectOperation::deleteConnectionError, this, &NmDemo::onWcoSignals); - connect(m_wco, &KyWirelessConnectOperation::activateConnectionError, this, &NmDemo::onWcoSignals); - connect(m_wco, &KyWirelessConnectOperation::deactivateConnectionError, this, &NmDemo::onWcoSignals); - connect(m_wco, &KyWirelessConnectOperation::addAndActivateConnectionError, this, &NmDemo::onWcoSignals); - - //列表变化 - connect(m_wnr, &KyWirelessNetResource::bssidChange, this ,&NmDemo::onBssidChange); - connect(m_wnr, &KyWirelessNetResource::secuTypeChange, this ,&NmDemo::onSecuTypeChange); - connect(m_wnr, &KyWirelessNetResource::signalStrengthChange, this ,&NmDemo::onSignalStrengthChange); - - - - connect(m_wnr, &KyWirelessNetResource::connectionRemove, this ,&NmDemo::onConnectionRemove); - connect(m_wnr, &KyWirelessNetResource::connectionAdd, this ,&NmDemo::onConnectionAdd); - connect(m_wnr, &KyWirelessNetResource::wifiNetworkUpdate, this ,&NmDemo::onWifiNetworkUpdate); - connect(m_wnr, &KyWirelessNetResource::wifiNetworkAdd, this ,&NmDemo::onWifiNetworkAdd); - connect(m_wnr, &KyWirelessNetResource::wifiNetworkRemove, this ,&NmDemo::onWifiNetworkRemove); - - connect(m_acr, &KyActiveConnectResourse::stateChangeReason, this, [this](QString uuid, - NetworkManager::ActiveConnection::State state, - NetworkManager::ActiveConnection::Reason reason){ - appendDebugLog(QString("%1 %2 %3").arg(uuid).arg(state).arg(reason)); - }); -} - -void NmDemo::initTimer() -{ - //30s扫描一次wifi - m_timer->setTimerType(Qt::PreciseTimer); - QObject::connect(m_timer, &QTimer::timeout, [=](){ - m_wco->requestWirelessScan(); - getWifiList(); - }); - m_timer->start(30*1000); -} - - -void NmDemo::onWcoSignals(QString errorMessage) -{ - appendDebugLog(errorMessage); -} - -void NmDemo::onBssidChange(QString devIface, QString ssid, QString bssid) -{ - appendDebugLog(ssid + " belongs to " + devIface + " bssid change to " + bssid); -} - -void NmDemo::onSecuTypeChange(QString devIface, QString ssid, QString secuType) -{ - appendDebugLog(ssid + " belongs to " + devIface + " security change to " + secuType); -} - -void NmDemo::onSignalStrengthChange(QString devIface , QString ssid, int signal) -{ - appendDebugLog(ssid + " belongs to " + devIface + " SignalStrength change to " + QString::number(signal)); -} - -void NmDemo::onConnectionRemove(QString devIface, QString ssid) -{ - appendDebugLog("onConnectionRemove..." + devIface + " " + ssid); - getWifiList(); -} - -void NmDemo::onConnectionAdd(QString devIface, QString ssid) -{ - appendDebugLog("onConnectionAdd..." + devIface + " " + ssid); - getWifiList(); -} - -void NmDemo::onWifiNetworkAdd(QString devIface, KyWirelessNetItem& item) -{ - appendDebugLog("onWifiNetworkAdd..." + devIface + " " + item.m_NetSsid); - getWifiList(); -} - -void NmDemo::onWifiNetworkRemove(QString devIface, QString ssid) -{ - appendDebugLog("onWifiNetworkRemove..." + devIface + " " + ssid); - getWifiList(); -} - -void NmDemo::onWifiNetworkUpdate() -{ - appendDebugLog("onWifiNetworkUpdate..."); - getWifiList(); -} - -void NmDemo::onConnectClicked() -{ - appendDebugLog("onConnectClicked..."); - QString ssid = ssidText->text(); - QString devIface = ifaceNameText->text(); - QString pwd = pwdText->text(); - QString uuid; - bool isNew = true; - bool isHidden = true; - bool isEnterPirse = false; - - appendDebugLog("about to connect " + ssid + " " + devIface + " " + pwd); - QList list; - m_wnr->getDeviceWifiNetwork(devIface, list); - appendDebugLog("agetDeviceWifiNetwork " + devIface + " size: " + QString::number(list.size())); - QList::iterator iter = list.begin(); - while (iter != list.end()) - { - if (iter->m_NetSsid == ssid) - { - isHidden = false; - QString secuType = iter->m_secuType; - qDebug() << secuType; - if (secuType.indexOf("802.1X") >= 0) - { - isEnterPirse = true; - } - - if (iter->m_isConfigured == true) - { - isNew = false; - uuid = iter->m_connectUuid; - } - } - iter++; - } - if (isEnterPirse) - { - if(!isNew) - { - KyEapMethodPeapInfo a; - a.phase2AuthMethod = KyAuthMethodMschapv2; - a.userName = "steve"; - a.userPWD = "testing"; - appendDebugLog("modifyEnterPriseInfoPeap"); - - appendDebugLog("activeWirelessConnect..."); - m_wco->activeWirelessConnect(devIface,uuid); - return; - } else { - KyEapMethodPeapInfo c; - c.m_passwdFlag = NetworkManager::Setting::SecretFlagType::None; - c.phase2AuthMethod = KyAuthMethodMschapv2; - c.userName = "steve"; - c.userPWD = "testing"; - - KyWirelessConnectSetting a; - a.m_connectName = ssid; - a.m_ssid = ssid; - a.isAutoConnect = true; - a.m_type = WpaEap; - - appendDebugLog("addAndActiveWirelessEnterPriseTtlsConnect..."); - qDebug() << "addAndActiveWirelessEnterPriseTtlsConnect"; -// m_wco->addAndActiveWirelessEnterPriseTtlsConnect(c, devIface, isHidden, true, 0); - m_wco->addAndActiveWirelessEnterPrisePeapConnect(c, a, devIface, false); - return; - } - } - if (isNew) - { - appendDebugLog("addAndActiveWirelessConnect..."); - KyWirelessConnectSetting a; - a.m_connectName = ssid; - a.m_ssid = ssid; - a.isAutoConnect = true; - a.m_psk = pwd; - a.m_type = WpaNone; - - - m_wco->addAndActiveWirelessConnect(devIface,a, isHidden); - } else { -// NetworkManager::Setting::SecretFlags c; -// m_wco->getConnSecretFlags(uuid, c); -// appendDebugLog(QString("%1").arg(c)); - appendDebugLog("activeWirelessConnect..."); - m_wco->activeWirelessConnect(devIface,uuid); - } -} - -void NmDemo::onDisConnectClicked() -{ - appendDebugLog("onDisConnectClicked..."); - QString ssid = ssidText->text(); - QString devIface = ifaceNameText->text(); - QString uuid; - bool isFind = false; - QList list; - m_wnr->getDeviceWifiNetwork(devIface, list); - QList::iterator iter = list.begin(); - while (iter != list.end()) - { - if (iter->m_NetSsid == ssid) - { - if (iter->m_isConfigured == true) - { - isFind = true; - uuid = iter->m_connectUuid; - break; - } - } - iter++; - } - if (!isFind) - { - return; - } - appendDebugLog("deActiveWirelessConnect " + ssid); - m_wco->deActivateWirelessConnection(ssid, uuid); -} - -void NmDemo::onModifyClicked() -{ - appendDebugLog("onModifyClicked..."); - QString ssid = ssidText->text(); - QString devIface = ifaceNameText->text(); - QString uuid; - bool isFind = false; - QList list; - m_wnr->getDeviceWifiNetwork(devIface, list); - QList::iterator iter = list.begin(); - while (iter != list.end()) - { - if (iter->m_NetSsid == ssid) - { - if (iter->m_isConfigured == true) - { - isFind = true; - uuid = iter->m_connectUuid; - break; - } - } - iter++; - } - if (!isFind) - { - return; - } - -// KyEapMethodTtlsInfo info; -// m_wco->updateWirelessEnterPriseTtlsConnect(uuid, info); - -// QString psk = m_wco->getPsk(uuid); -// appendDebugLog(ssid +" getPsk is " + psk); -// return; - - appendDebugLog("getConnectKeyMgmt" + QString::number(m_wco->getConnectKeyMgmt(uuid))); - - KyWirelessConnectSetting wcs; - wcs.m_type = WpaPsk; - wcs.m_psk = "123456zsx"; - m_wco->updateWirelessPersonalConnect(uuid, wcs ,true); - appendDebugLog("getConnectKeyMgmt" + QString::number(m_wco->getConnectKeyMgmt(uuid))); - return; - - m_wco->setWirelessAutoConnect(uuid, false); - return; - - KyConnectSetting sett; - showIpv4Ipv6DnsInfo(uuid, sett); - - sett.m_ipv4ConfigIpType = CONFIG_IP_MANUAL; - sett.setIpConfigType(IPADDRESS_V4, CONFIG_IP_MANUAL); - sett.m_ipv4Address.clear(); - QStringList ipv4DnsList; - ipv4DnsList << "1.1.1.1"; - QString a("192.168.1.17"),b("255.255.255.0"),c("192.168.1.0"); - sett.ipv4AddressConstruct(a, b, c, ipv4DnsList); - -// sett.setIpConfigType(IPADDRESS_V6, CONFIG_IP_MANUAL); -// QStringList ipv6DnsList; -// ipv6DnsList << "1.1.1.1"; -// QString d("1.1.1.1"),e("1.1.1.1"),f("1.1.1.1"); -// sett.ipv6AddressConstruct(d, e, f, ipv6DnsList); - - m_wco->updateIpv4AndIpv6SettingInfo(uuid, sett); - - showIpv4Ipv6DnsInfo(uuid, sett); -} - -void NmDemo::showIpv4Ipv6DnsInfo(const QString &uuid, KyConnectSetting &settInfo) -{ - m_cr->getConnectionSetting(uuid, settInfo); - appendDebugLog("connect setting info:"); - appendDebugLog("connect name " + settInfo.m_connectName); - appendDebugLog("iface name " + settInfo.m_ifaceName); - appendDebugLog("ipv4 type " + QString::number(settInfo.m_ipv4ConfigIpType)); - - for (int index = 0 ; index < settInfo.m_ipv4Address.size(); index++) { - appendDebugLog("ipv4 address " + settInfo.m_ipv4Address.at(index).ip().toString()); - appendDebugLog("ipv4 gate way " + settInfo.m_ipv4Address.at(index).gateway().toString()); - appendDebugLog("ipv4 net mask " + settInfo.m_ipv4Address.at(index).netmask().toString()); - } - - for (int index = 0; index < settInfo.m_ipv4Dns.size(); ++index) { - appendDebugLog("ipv4 dns " + settInfo.m_ipv4Dns.at(index).toString()); - } - - appendDebugLog("ipv6 type " + QString::number(settInfo.m_ipv6ConfigIpType)); - - for (int index = 0 ; index < settInfo.m_ipv6Address.size(); index++) { - appendDebugLog("ipv6 address " + settInfo.m_ipv6Address.at(index).ip().toString()); - appendDebugLog("ipv6 gate way " + settInfo.m_ipv6Address.at(index).gateway().toString()); - appendDebugLog("ipv6 net mask " + settInfo.m_ipv6Address.at(index).netmask().toString()); - } - - for (int index = 0; index < settInfo.m_ipv6Dns.size(); ++index) { - appendDebugLog("ipv6 dns " + settInfo.m_ipv6Dns.at(index).toString()); - } - QString ipv4,ipv6; - QList ipv4Dns,ipv6Dns; - ipv4Dns.clear(); - ipv6Dns.clear(); - m_acr->getActiveConnectIpInfo(uuid, ipv4, ipv6); - appendDebugLog("Dynamic ipv4 address " + ipv4); - appendDebugLog("Dynamic ipv6 address " + ipv6); - m_acr->getActiveConnectDnsInfo(uuid, ipv4Dns, ipv6Dns); - appendDebugLog(QString::number(ipv4Dns.size()) + QString::number(ipv6Dns.size())); - for (int index = 0 ; index < ipv4Dns.size(); index++) { - appendDebugLog("Dynamic ipv4 dns " + ipv4Dns.at(index).toString()); - } - for (int index = 0 ; index < ipv6Dns.size(); index++) { - appendDebugLog("Dynamic ipv6 dns " + ipv6Dns.at(index).toString()); - } -} - -void NmDemo::onEnableClick() -{ - appendDebugLog("onEanbleClick..."); - m_wco->setWirelessEnabled(true); -} - -void NmDemo::onDisableClick() -{ - appendDebugLog("onDisableClick..."); - m_wco->setWirelessEnabled(false); -} - -void NmDemo::onAddClick() -{ - appendDebugLog("onAddClick..."); - KyWirelessConnectSetting sett; - sett.m_connectName = "test"; - sett.m_ssid = "test"; - sett.isAutoConnect = false; - sett.m_psk = ""; - sett.m_type = WpaEap; -// //ipv4 - sett.setIpConfigType(IPADDRESS_V4, CONFIG_IP_DHCP); -// QString ipv4Address("192.168.1.17"), ipv4NetMask("255.255.255.0"), ipv4GateWay("192.168.1.0"); -// QStringList list; -// list << "127.17.50.100"; -// sett.ipv4AddressConstruct(ipv4Address, ipv4NetMask, ipv4GateWay, list); -// m_wco->addConnect(sett); - KyEapMethodPeapInfo peap; - peap.phase2AuthMethod = KyAuthMethodMschapv2; - peap.userName = "steve"; - peap.userPWD = "testing"; - m_wco->addPeapConnect(sett,peap); -} - -void NmDemo::appendDebugLog(QString log) -{ - QTimeZone timeZone(QString::fromLatin1(QTimeZone::systemTimeZoneId()).toLatin1()); - QDateTime tzNow = QDateTime::currentDateTime().toTimeZone(timeZone); - QString time= tzNow.toString("hh:mm:ss AP"); - debugLog->append(time + "===="+ log); - qDebug() << log; -} - -void NmDemo::onActiveConnectionAdd(NetworkManager::ActiveConnection::Ptr conn) -{ - if (conn->type() != NetworkManager::ConnectionSettings::ConnectionType::Wireless) - { - return; - } - appendDebugLog(conn->id()+ " " + enumToQstring(conn->state())); - actConnection->setText(conn->id()+ " " + enumToQstring(conn->state())); -} - -void NmDemo::onActiveConnectionUpdate(NetworkManager::ActiveConnection * conn) -{ - if (conn->type() != NetworkManager::ConnectionSettings::ConnectionType::Wireless) - { - return; - } - appendDebugLog(conn->id()+ " " + enumToQstring(conn->state())); - actConnection->setText(conn->id()+ " " + enumToQstring(conn->state())); -} - -void NmDemo::onActiveConnectionRemove(NetworkManager::ActiveConnection * conn) -{ - if (conn->type() != NetworkManager::ConnectionSettings::ConnectionType::Wireless) - { - return; - } - appendDebugLog(conn->id()+ " " + enumToQstring(conn->state())); - actConnection->setText(conn->id()+ " " + enumToQstring(conn->state())); -} - -void NmDemo::onActiveConnectionsReset() -{ - appendDebugLog("onActiveConnectionsReset"); -} - -void NmDemo::getWifiList() -{ - qDebug() << "getWifiList"; - wifiList->clear(); - QMap actMap; - m_wnr->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap); - appendDebugLog("getWirelessActiveConnection Activated " +QString::number(actMap.size())); - - QMap::iterator iter1 = actMap.begin(); - while (iter1 != actMap.end()) - { - wifiList->append(iter1.key()); - for (int i = 0; i < iter1->size(); i++) - { - wifiList->append("Activated" + iter1->at(i)); - } - wifiList->append("===================================="); - iter1++; - } - - m_wnr->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activating, actMap); - appendDebugLog("getWirelessActiveConnection Activating " +QString::number(actMap.size())); - - QMap::iterator iter2 = actMap.begin(); - while (iter2 != actMap.end()) - { - wifiList->append(iter2.key()); - for (int i = 0; i < iter2->size(); i++) - { - wifiList->append("Activating" + iter2->at(i)); - } - wifiList->append("===================================="); - iter2++; - } - - m_wnr->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Deactivating, actMap); - appendDebugLog("getWirelessActiveConnection Deactivating " +QString::number(actMap.size())); - - m_wnr->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Deactivated, actMap); - appendDebugLog("getWirelessActiveConnection Deactivated " +QString::number(actMap.size())); - - QMap > map; - if (!m_wnr->getAllDeviceWifiNetwork(map)) - { - return; - } - QMap >::iterator iter = map.begin(); - while (iter != map.end()) - { - qDebug() << iter.key() << iter.value().size(); - for (int i = 0; i < iter.value().size(); i++) - { - qDebug() << iter.value().at(i).m_NetSsid; - wifiList->append("SSID: " + iter.value().at(i).m_NetSsid + " Configed: " + QString::number(iter.value().at(i).m_isConfigured)); - wifiList->append("frequency: " + QString::number(iter.value().at(i).m_frequency)); - wifiList->append("signalStrength: " + QString::number(iter.value().at(i).m_signalStrength)); - QString security = iter.value().at(i).m_secuType; - if (security.isEmpty()) - { - security = "NONE"; - } - wifiList->append("security: " + security); - wifiList->append("MAC: " + iter.value().at(i).m_bssid); - wifiList->append("===================================="); - } - iter++; - } -} diff --git a/src/frontend/nmdemo.h b/src/frontend/nmdemo.h deleted file mode 100644 index a678e74e..00000000 --- a/src/frontend/nmdemo.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef NMDEMO_H -#define NMDEMO_H - -#include -#include -#include -#include -#include -#include - -#include "backend/dbus-interface/kylinnetworkresourcemanager.h" -#include "backend/dbus-interface/kywirelessconnectoperation.h" -#include "backend/dbus-interface/kywirelessnetresource.h" -#include "backend/dbus-interface/kylinactiveconnectresource.h" -#include "backend/dbus-interface/kylinconnectresource.h" -#include "backend/dbus-interface/kylinactiveconnectresource.h" - -class NmDemo : public QDialog -{ - Q_OBJECT - -public: - QPushButton *refreshButton; - QPushButton *connectButton; - QPushButton *disConnectButton; - QPushButton *modifyButton; - QPushButton *enableButton; - QPushButton *disableButton; - QPushButton *addButton; - QTextEdit *wifiList; - QTextEdit *debugLog; - QLabel *ssidLabel; - QLabel *ifaceLabel; - QLabel *wlansStatus; - QLabel *pwdLabel; - QLabel *actConnection; - QLineEdit *ssidText; - QLineEdit *ifaceNameText; - QLineEdit *pwdText; - - KyNetworkResourceManager *m_networkResourceInstance = nullptr; - KyWirelessConnectOperation *m_wco; - KyWirelessNetResource *m_wnr; - KyActiveConnectResourse *m_acr; - KyConnectResourse *m_cr; - -private: - QTimer *m_timer; - -public: - explicit NmDemo(QWidget *parent = nullptr); - ~NmDemo(); - -private: - void initUi(); - void initConnect(); - void initTimer(); - void appendDebugLog(QString); - void getWifiList(); - - void showIpv4Ipv6DnsInfo(const QString &uuid, KyConnectSetting &sett); - -public slots: - void onWcoSignals(QString); - void onBssidChange(QString, QString, QString); - void onSecuTypeChange(QString, QString, QString); - void onSignalStrengthChange(QString, QString, int); - - void onConnectionRemove(QString, QString); - void onConnectionAdd(QString, QString); - void onWifiNetworkAdd(QString, KyWirelessNetItem&); - void onWifiNetworkRemove(QString, QString); - void onWifiNetworkUpdate(); - - void onConnectClicked(); - void onDisConnectClicked(); - void onModifyClicked(); - void onEnableClick(); - void onDisableClick(); - void onAddClick(); - - void onActiveConnectionAdd(NetworkManager::ActiveConnection::Ptr conn); - void onActiveConnectionUpdate(NetworkManager::ActiveConnection * conn); - void onActiveConnectionRemove(NetworkManager::ActiveConnection * conn); - void onActiveConnectionsReset(); - - - -signals: - -}; - -#endif // NMDEMO_H diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 1b86c99a..b68660a0 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -57,6 +57,7 @@ bool WlanPage::eventFilter(QObject *w, QEvent *e) emit this->hiddenWlanClicked(); } else if (w == m_settingsLabel) { //ZJP_TODO 打开控制面板 + qDebug() << LOG_FLAG <<"recive event show control center"; showControlCenter(); } } @@ -537,6 +538,9 @@ void WlanPage::onConnectionRemove(QString deviceName, QString ssid) { qDebug() << LOG_FLAG << "one connection is removed, it's ssid " << ssid << "device name"<< deviceName; if (deviceName == m_currentDevice) { + if (m_activateConnectionItemMap.contains(ssid)) { + updateWirelessNetArea(nullptr, ssid, deviceName); + } updateWlanListItem(ssid); } @@ -548,6 +552,8 @@ void WlanPage::onSecurityTypeChange(QString devName, QString ssid, QString secuT QListWidgetItem *p_listWidgetItem = nullptr; WlanListItem *p_wlanItem = nullptr; + qDebug()<< LOG_FLAG << "security type is chenged"; + if (m_wirelessNetItemMap.contains(ssid)) { p_listWidgetItem = m_wirelessNetItemMap.value(ssid); p_wlanItem = (WlanListItem*)m_inactivatedNetListWidget->itemWidget(p_listWidgetItem); @@ -626,9 +632,9 @@ void WlanPage::deleteDeviceFromCombox(QString deviceName) if (m_wlanSwitchEnable) { if (0 == m_devList.count()) { - m_deviceFrame->show(); - m_tipsLabel->show(); - m_deviceComboBox->hide(); + m_deviceFrame->hide(); + //m_tipsLabel->show(); + //m_deviceComboBox->hide(); m_currentDevice = ""; setDefaultDevice(WIRELESS, m_currentDevice); } else if (1 == m_devList.count()) { @@ -736,7 +742,7 @@ void WlanPage::sendApStateChangeSignal(QString uuid, return; } -void WlanPage::wlanShowNotify(NetworkManager::ActiveConnection::State state, +void WlanPage::wlanShowNotify(QString ssid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason) { if (state == NetworkManager::ActiveConnection::State::Deactivated) { @@ -775,7 +781,6 @@ void WlanPage::updateActivatedArea(QString uuid, QString ssid, QString devName) deleteWirelessItemFormMap(m_activateConnectionItemMap, m_activatedNetListWidget, EMPTY_SSID); QListWidgetItem *p_listWidgetItem = addNewItem(wirelessNetItem, m_activatedNetListWidget); m_activateConnectionItemMap.insert(wirelessNetItem.m_NetSsid, p_listWidgetItem); - updateWlanItemState(m_activatedNetListWidget, p_listWidgetItem, Activated); m_activatedNetListWidget->setFixedHeight(p_listWidgetItem->sizeHint().height()); @@ -795,14 +800,6 @@ void WlanPage::updateWirelessNetArea(QString uuid, QString ssid, QString devName return; } - /* - *此处更新状态是针对激活的链接忘记密码的操作。 - */ - QListWidgetItem *p_activelistItem = m_activateConnectionItemMap.value(ssid); - if (nullptr != p_activelistItem) { - updateWlanItemState(m_activatedNetListWidget, p_activelistItem, Deactivated); - } - deleteWirelessItemFormMap(m_activateConnectionItemMap, m_activatedNetListWidget, ssid); QListWidgetItem *p_activeListWidgetItem = addEmptyItem(m_activatedNetListWidget); m_activateConnectionItemMap.insert(EMPTY_SSID, p_activeListWidgetItem); @@ -810,7 +807,6 @@ void WlanPage::updateWirelessNetArea(QString uuid, QString ssid, QString devName QListWidgetItem *p_listWidgetItem = addNewItem(wirelessNetItem, m_inactivatedNetListWidget); m_wirelessNetItemMap.insert(wirelessNetItem.m_NetSsid, p_listWidgetItem); - updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated); m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() + p_listWidgetItem->sizeHint().height() + NET_LIST_SPACING); @@ -842,7 +838,7 @@ void WlanPage::onConnectionStateChanged(QString uuid, emit wlanActiveConnectionStateChanged(devName, ssid,uuid, state); sendApStateChangeSignal(uuid, ssid, devName, state); - wlanShowNotify(state, reason); + wlanShowNotify(ssid, state, reason); if (devName != m_currentDevice) { return; @@ -852,19 +848,25 @@ void WlanPage::onConnectionStateChanged(QString uuid, << "; state = " << state << "; reason = " << reason << Q_FUNC_INFO <<__LINE__; if (state == NetworkManager::ActiveConnection::State::Activated) { updateActivatedArea(uuid, ssid, devName); + if (m_activateConnectionItemMap.contains(ssid)) { + QListWidgetItem *p_listWidgetItem = m_activateConnectionItemMap.value(ssid); + updateWlanItemState(m_activatedNetListWidget, p_listWidgetItem, Activated); + } } else if (state == NetworkManager::ActiveConnection::State::Deactivated) { updateWirelessNetArea(uuid, ssid, devName); + if (m_wirelessNetItemMap.contains(ssid)) { + QListWidgetItem *p_listWidgetItem = m_wirelessNetItemMap.value(ssid); + updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated); + } } else if (state == NetworkManager::ActiveConnection::State::Deactivating){ if (m_activateConnectionItemMap.contains(ssid)) { QListWidgetItem *p_listWidgetItem = m_activateConnectionItemMap.value(ssid); - WlanListItem *p_wlanItem = (WlanListItem*)m_activatedNetListWidget->itemWidget(p_listWidgetItem); - p_wlanItem->updateConnectState(Deactivating); + updateWlanItemState(m_activatedNetListWidget, p_listWidgetItem, Deactivating); } } else if (state == NetworkManager::ActiveConnection::State::Activating) { if (m_wirelessNetItemMap.contains(ssid)) { QListWidgetItem *p_listWidgetItem = m_wirelessNetItemMap.value(ssid); - WlanListItem *p_wlanItem = (WlanListItem*)m_inactivatedNetListWidget->itemWidget(p_listWidgetItem); - p_wlanItem->updateConnectState(Activating); + updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Activating); } } @@ -947,8 +949,12 @@ void WlanPage::onHiddenWlanClicked() void WlanPage::showControlCenter() { + qDebug() << LOG_FLAG <<"show control center"; + QProcess process; process.startDetached("ukui-control-center --wlanconnect"); + + return; } void WlanPage::onWifiEnabledChanged(bool isWifiOn) @@ -1022,8 +1028,8 @@ void WlanPage::onRefreshIconTimer() WlanListItem *p_sortWlanItem = new WlanListItem(sortItem, m_currentDevice); connect(p_sortWlanItem, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); m_inactivatedNetListWidget->insertItem(sortRow, p_sortListWidgetItem); - p_sortWlanItem->updateConnectState(Deactivated); m_inactivatedNetListWidget->setItemWidget(p_sortListWidgetItem, p_sortWlanItem); + updateWlanItemState(m_inactivatedNetListWidget, p_sortListWidgetItem, Deactivated); sortRow++; continue; } diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index 6b074c66..6e2dba67 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -132,7 +132,7 @@ private: void sendApStateChangeSignal(QString uuid, QString ssid, QString deviceName, NetworkManager::ActiveConnection::State state); - void wlanShowNotify(NetworkManager::ActiveConnection::State state, + void wlanShowNotify(QString ssid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason); private: From 80ed0ffdf13db3135ee4e7e6483016f71a74704f Mon Sep 17 00:00:00 2001 From: renpeijia Date: Tue, 19 Oct 2021 15:09:35 +0800 Subject: [PATCH 3/5] fix:the control center is core, when get wilreless list --- src/frontend/frontend.pri | 4 ---- src/frontend/tab-pages/wlanpage.cpp | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/frontend/frontend.pri b/src/frontend/frontend.pri index f2d899d7..ec60ca6c 100644 --- a/src/frontend/frontend.pri +++ b/src/frontend/frontend.pri @@ -11,14 +11,10 @@ FORMS += \ HEADERS += \ $$PWD/customstyle.h \ - $$PWD/kylinwiredwidget.h \ $$PWD/mainwindow.h \ - $$PWD/nmdemo.h \ $$PWD/wificonfigdialog.h SOURCES += \ $$PWD/customstyle.cpp \ - $$PWD/kylinwiredwidget.cpp \ $$PWD/mainwindow.cpp \ - $$PWD/nmdemo.cpp \ $$PWD/wificonfigdialog.cpp diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index b68660a0..1100290c 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -1072,7 +1072,9 @@ void WlanPage::getWirelessList(QMap > &map) if (actMap.contains(iter.key())) { qDebug() << "find " <getWifiNetwork(iter.key(), actMap[iter.key()].at(0), data)) { + QString ssid =""; + m_wirelessNetResource->getSsidByUuid(actMap[iter.key()].at(0), ssid); + if (m_wirelessNetResource->getWifiNetwork(iter.key(), ssid, data)) { vector.append(QStringList()< Date: Tue, 19 Oct 2021 19:00:53 +0800 Subject: [PATCH 4/5] fix:control can not start up, when kylin process control center. --- src/frontend/tab-pages/wlanpage.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 1100290c..8dd4669b 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -828,15 +828,16 @@ void WlanPage::onConnectionStateChanged(QString uuid, QString devName, ssid; m_wirelessNetResource->getSsidByUuid(uuid, ssid); m_wirelessNetResource->getDeviceByUuid(uuid, devName); + + qDebug()<< LOG_FLAG << "emit wlanActiveConnectionStateChanged" << devName << ssid << state; + emit wlanActiveConnectionStateChanged(devName, ssid, uuid, state); + if (ssid.isEmpty() || devName.isEmpty()) { qDebug()<< LOG_FLAG << "ssid or devicename is empty" << "devicename"<< devName <<"ssid"< > &map) QString ssid =""; m_wirelessNetResource->getSsidByUuid(actMap[iter.key()].at(0), ssid); if (m_wirelessNetResource->getWifiNetwork(iter.key(), ssid, data)) { - vector.append(QStringList()< Date: Tue, 19 Oct 2021 19:52:05 +0800 Subject: [PATCH 5/5] fix:kylin can not send signal to control center, when connection state change --- src/frontend/tab-pages/wlanpage.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 8dd4669b..c1789dc2 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -820,11 +820,6 @@ void WlanPage::onConnectionStateChanged(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason) { - if (!m_connectResource->isWirelessConnection(uuid)) { - qDebug()<< LOG_FLAG << "it is not wireless connection" << uuid; - return; - } - QString devName, ssid; m_wirelessNetResource->getSsidByUuid(uuid, ssid); m_wirelessNetResource->getDeviceByUuid(uuid, devName); @@ -838,6 +833,11 @@ void WlanPage::onConnectionStateChanged(QString uuid, return; } + if (!m_connectResource->isWirelessConnection(uuid)) { + qDebug()<< LOG_FLAG << "it is not wireless connection" << uuid; + return; + } + sendApStateChangeSignal(uuid, ssid, devName, state); wlanShowNotify(ssid, state, reason);