2019-03-08 18:06:55 +08:00
|
|
|
|
/*
|
2018-06-22 19:07:11 +08:00
|
|
|
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
|
|
|
|
*
|
|
|
|
|
* Author: sbw <sbw@sbw.so>
|
|
|
|
|
*
|
|
|
|
|
* Maintainer: sbw <sbw@sbw.so>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "wirelesslist.h"
|
|
|
|
|
#include "accesspointwidget.h"
|
2020-04-09 21:08:52 +08:00
|
|
|
|
#include "constants.h"
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QScreen>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QGuiApplication>
|
2020-05-23 11:41:09 +08:00
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QScrollBar>
|
|
|
|
|
#include <QTimer>
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
|
|
|
|
#include <dinputdialog.h>
|
2018-09-03 10:43:29 +08:00
|
|
|
|
#include <DDBusSender>
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
|
|
|
|
DWIDGET_USE_NAMESPACE
|
|
|
|
|
|
|
|
|
|
using namespace dde::network;
|
|
|
|
|
|
2020-04-09 21:08:52 +08:00
|
|
|
|
extern const int ItemWidth = 250;
|
2020-04-20 19:37:36 +08:00
|
|
|
|
extern const int ItemMargin = 10;
|
2020-04-09 21:08:52 +08:00
|
|
|
|
extern const int ItemHeight;
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
|
|
|
|
WirelessList::WirelessList(WirelessDevice *deviceIter, QWidget *parent)
|
2020-05-23 11:41:09 +08:00
|
|
|
|
: QScrollArea(parent)
|
|
|
|
|
, m_device(deviceIter)
|
|
|
|
|
, m_activeAP()
|
|
|
|
|
, m_updateAPTimer(new QTimer(this))
|
|
|
|
|
, m_centralLayout(new QVBoxLayout)
|
|
|
|
|
, m_centralWidget(new QWidget)
|
|
|
|
|
, m_controlPanel(new DeviceControlWidget)
|
2018-06-22 19:07:11 +08:00
|
|
|
|
{
|
2020-04-09 21:08:52 +08:00
|
|
|
|
setFixedHeight(ItemHeight);
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
2021-05-19 17:41:06 +09:00
|
|
|
|
//无线网络列表背景色设置为透明
|
2021-05-07 13:14:18 +09:00
|
|
|
|
QPalette backgroud;
|
|
|
|
|
backgroud.setColor(QPalette::Background, Qt::transparent);
|
|
|
|
|
this->setAutoFillBackground(true);
|
|
|
|
|
this->setPalette(backgroud);
|
|
|
|
|
|
2018-06-22 19:07:11 +08:00
|
|
|
|
m_updateAPTimer->setSingleShot(true);
|
|
|
|
|
m_updateAPTimer->setInterval(100);
|
|
|
|
|
|
2021-05-07 13:14:18 +09:00
|
|
|
|
m_centralWidget->setFixedWidth(ItemWidth);
|
2018-06-22 19:07:11 +08:00
|
|
|
|
m_centralWidget->setLayout(m_centralLayout);
|
|
|
|
|
|
2018-07-27 11:16:00 +08:00
|
|
|
|
m_centralLayout->addWidget(m_controlPanel);
|
2018-06-22 19:07:11 +08:00
|
|
|
|
m_centralLayout->setSpacing(0);
|
|
|
|
|
m_centralLayout->setMargin(0);
|
|
|
|
|
|
|
|
|
|
setWidget(m_centralWidget);
|
2019-10-09 16:19:08 +08:00
|
|
|
|
setFrameShape(QFrame::NoFrame);
|
2018-06-22 19:07:11 +08:00
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2020-04-09 21:08:52 +08:00
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2019-10-09 16:19:08 +08:00
|
|
|
|
m_centralWidget->setAutoFillBackground(false);
|
|
|
|
|
viewport()->setAutoFillBackground(false);
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
2020-04-09 21:08:52 +08:00
|
|
|
|
m_loadingStat = new DSpinner(this);
|
|
|
|
|
m_loadingStat->setFixedSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE);
|
|
|
|
|
m_loadingStat->setVisible(false);
|
2019-12-03 09:45:29 +08:00
|
|
|
|
isHotposActive = false;
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
|
|
|
|
connect(m_device, &WirelessDevice::apAdded, this, &WirelessList::APAdded);
|
|
|
|
|
connect(m_device, &WirelessDevice::apRemoved, this, &WirelessList::APRemoved);
|
|
|
|
|
connect(m_device, &WirelessDevice::apInfoChanged, this, &WirelessList::APPropertiesChanged);
|
|
|
|
|
connect(m_device, &WirelessDevice::enableChanged, this, &WirelessList::onDeviceEnableChanged);
|
2018-09-03 10:43:29 +08:00
|
|
|
|
connect(m_device, &WirelessDevice::activateAccessPointFailed, this, &WirelessList::onActivateApFailed);
|
2019-03-20 15:49:41 +08:00
|
|
|
|
connect(m_device, &WirelessDevice::hotspotEnabledChanged, this, &WirelessList::onHotspotEnabledChanged);
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
|
|
|
|
connect(m_controlPanel, &DeviceControlWidget::enableButtonToggled, this, &WirelessList::onEnableButtonToggle);
|
2018-07-31 15:05:03 +08:00
|
|
|
|
connect(m_controlPanel, &DeviceControlWidget::requestRefresh, this, &WirelessList::requestWirelessScan);
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
|
|
|
|
connect(m_updateAPTimer, &QTimer::timeout, this, &WirelessList::updateAPList);
|
|
|
|
|
|
2019-03-08 18:06:55 +08:00
|
|
|
|
connect(m_device, &WirelessDevice::activeWirelessConnectionInfoChanged, this, &WirelessList::onActiveConnectionInfoChanged);
|
2020-05-23 11:41:09 +08:00
|
|
|
|
connect(m_device, static_cast<void (WirelessDevice::*)(NetworkDevice::DeviceStatus stat) const>(&WirelessDevice::statusChanged), m_updateAPTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
2019-03-08 18:06:55 +08:00
|
|
|
|
connect(m_device, &WirelessDevice::activeConnectionsChanged, this, &WirelessList::updateIndicatorPos, Qt::QueuedConnection);
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
2020-05-23 11:41:09 +08:00
|
|
|
|
connect(this->verticalScrollBar(), &QScrollBar::valueChanged, this, [ = ] {
|
2019-03-08 18:06:55 +08:00
|
|
|
|
auto apw = accessPointWidgetByAp(m_activatingAP);
|
2020-05-23 11:41:09 +08:00
|
|
|
|
if (!apw)
|
|
|
|
|
return;
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
2020-04-09 21:08:52 +08:00
|
|
|
|
const int h = -(apw->height() - m_loadingStat->height()) / 2;
|
2020-04-21 11:03:27 +08:00
|
|
|
|
m_loadingStat->move(apw->mapTo(this, apw->rect().topRight()) - QPoint(23, h));
|
2018-06-22 19:07:11 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(this, "loadAPList", Qt::QueuedConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WirelessList::~WirelessList()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *WirelessList::controlPanel()
|
|
|
|
|
{
|
|
|
|
|
return m_controlPanel;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 21:08:52 +08:00
|
|
|
|
int WirelessList::APcount()
|
|
|
|
|
{
|
|
|
|
|
return m_apList.size();
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 19:07:11 +08:00
|
|
|
|
void WirelessList::APAdded(const QJsonObject &apInfo)
|
|
|
|
|
{
|
|
|
|
|
AccessPoint ap(apInfo);
|
2018-06-28 19:06:07 +08:00
|
|
|
|
const auto mIndex = m_apList.indexOf(ap);
|
|
|
|
|
if (mIndex != -1) {
|
2020-08-05 18:27:03 +08:00
|
|
|
|
if(ap.strength() < 5 && ap.path() == m_apList.at(mIndex).path())
|
2020-06-15 17:20:34 +08:00
|
|
|
|
m_apList.removeAt(mIndex);
|
|
|
|
|
else
|
|
|
|
|
m_apList.replace(mIndex, ap);
|
2018-06-28 19:06:07 +08:00
|
|
|
|
} else {
|
2020-08-05 18:27:03 +08:00
|
|
|
|
if(ap.strength() < 5)
|
2020-06-15 17:20:34 +08:00
|
|
|
|
return;
|
2018-06-28 19:06:07 +08:00
|
|
|
|
m_apList.append(ap);
|
|
|
|
|
}
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
|
|
|
|
m_updateAPTimer->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WirelessList::APRemoved(const QJsonObject &apInfo)
|
|
|
|
|
{
|
|
|
|
|
AccessPoint ap(apInfo);
|
2018-06-28 19:06:07 +08:00
|
|
|
|
const auto mIndex = m_apList.indexOf(ap);
|
|
|
|
|
if (mIndex != -1) {
|
|
|
|
|
if (ap.path() == m_apList.at(mIndex).path()) {
|
|
|
|
|
m_apList.removeAt(mIndex);
|
|
|
|
|
m_updateAPTimer->start();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-22 19:07:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WirelessList::setDeviceInfo(const int index)
|
|
|
|
|
{
|
2018-12-25 13:13:26 +08:00
|
|
|
|
if (m_device.isNull()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 19:07:11 +08:00
|
|
|
|
// set device enable state
|
|
|
|
|
m_controlPanel->setDeviceEnabled(m_device->enabled());
|
|
|
|
|
|
|
|
|
|
// set device name
|
|
|
|
|
if (index == -1)
|
|
|
|
|
m_controlPanel->setDeviceName(tr("Wireless Network"));
|
|
|
|
|
else
|
|
|
|
|
m_controlPanel->setDeviceName(tr("Wireless Network %1").arg(index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WirelessList::loadAPList()
|
|
|
|
|
{
|
2018-12-25 13:13:26 +08:00
|
|
|
|
if (m_device.isNull()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 19:07:11 +08:00
|
|
|
|
for (auto item : m_device->apList()) {
|
|
|
|
|
AccessPoint ap(item.toObject());
|
2018-06-28 19:06:07 +08:00
|
|
|
|
const auto mIndex = m_apList.indexOf(ap);
|
|
|
|
|
if (mIndex != -1) {
|
|
|
|
|
// indexOf() will use AccessPoint reimplemented function "operator==" as comparison condition
|
|
|
|
|
// this means that the ssid of the AP is a comparison condition
|
2020-04-22 14:50:55 +08:00
|
|
|
|
m_apList.replace(mIndex, ap);
|
2018-06-28 19:06:07 +08:00
|
|
|
|
} else {
|
2018-06-22 19:07:11 +08:00
|
|
|
|
m_apList.append(ap);
|
2018-06-28 19:06:07 +08:00
|
|
|
|
}
|
2018-06-22 19:07:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_updateAPTimer->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WirelessList::APPropertiesChanged(const QJsonObject &apInfo)
|
|
|
|
|
{
|
2018-06-28 19:06:07 +08:00
|
|
|
|
AccessPoint ap(apInfo);
|
|
|
|
|
const auto mIndex = m_apList.indexOf(ap);
|
2020-08-05 18:27:03 +08:00
|
|
|
|
if(ap.strength() < 5)
|
2020-06-15 17:20:34 +08:00
|
|
|
|
{
|
|
|
|
|
if(mIndex != -1){
|
|
|
|
|
if (ap.path() == m_apList.at(mIndex).path()) {
|
|
|
|
|
m_apList.removeAt(mIndex);
|
|
|
|
|
m_updateAPTimer->start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
if (mIndex != -1) {
|
|
|
|
|
m_apList.replace(mIndex, ap);
|
|
|
|
|
}else {
|
|
|
|
|
m_apList.append(ap);
|
|
|
|
|
}
|
2020-04-22 14:50:55 +08:00
|
|
|
|
m_updateAPTimer->start();
|
2018-06-22 19:07:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WirelessList::updateAPList()
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(sender() == m_updateAPTimer);
|
|
|
|
|
|
2018-12-25 13:13:26 +08:00
|
|
|
|
if (m_device.isNull()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 19:07:11 +08:00
|
|
|
|
int avaliableAPCount = 0;
|
|
|
|
|
|
2020-05-23 11:41:09 +08:00
|
|
|
|
if (m_device->enabled()) {
|
2018-06-22 19:07:11 +08:00
|
|
|
|
// NOTE: Keep the amount consistent
|
2020-05-23 11:41:09 +08:00
|
|
|
|
if (m_apList.size() > m_apwList.size()) {
|
2018-06-22 19:07:11 +08:00
|
|
|
|
int i = m_apList.size() - m_apwList.size();
|
|
|
|
|
for (int index = 0; index != i; index++) {
|
|
|
|
|
AccessPointWidget *apw = new AccessPointWidget;
|
2020-04-09 21:08:52 +08:00
|
|
|
|
apw->setFixedHeight(ItemHeight);
|
2018-06-22 19:07:11 +08:00
|
|
|
|
m_apwList << apw;
|
|
|
|
|
m_centralLayout->addWidget(apw);
|
|
|
|
|
|
|
|
|
|
connect(apw, &AccessPointWidget::requestActiveAP, this, &WirelessList::activateAP);
|
|
|
|
|
connect(apw, &AccessPointWidget::requestDeactiveAP, this, &WirelessList::deactiveAP);
|
2020-05-23 11:41:09 +08:00
|
|
|
|
connect(apw, &AccessPointWidget::requestActiveAP, this, [ = ] {
|
2019-03-08 18:06:55 +08:00
|
|
|
|
m_clickedAPW = apw;
|
|
|
|
|
}, Qt::UniqueConnection);
|
2018-06-22 19:07:11 +08:00
|
|
|
|
}
|
|
|
|
|
} else if (m_apList.size() < m_apwList.size()) {
|
|
|
|
|
if (!m_apwList.isEmpty()) {
|
|
|
|
|
int i = m_apwList.size() - m_apList.size();
|
|
|
|
|
for (int index = 0; index != i; index++) {
|
|
|
|
|
AccessPointWidget *apw = m_apwList.last();
|
|
|
|
|
m_apwList.removeLast();
|
|
|
|
|
m_centralLayout->removeWidget(apw);
|
|
|
|
|
apw->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 11:41:09 +08:00
|
|
|
|
std::sort(m_apList.begin(), m_apList.end(), [&](const AccessPoint & ap1, const AccessPoint & ap2) {
|
2018-06-22 19:07:11 +08:00
|
|
|
|
if (ap1 == m_activeAP)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (ap2 == m_activeAP)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return ap1.strength() > ap2.strength();
|
|
|
|
|
});
|
|
|
|
|
|
2019-03-08 18:06:55 +08:00
|
|
|
|
// update the content of AccessPointWidget by the order of ApList
|
2018-06-22 19:07:11 +08:00
|
|
|
|
for (int i = 0; i != m_apList.size(); i++) {
|
|
|
|
|
m_apwList[i]->updateAP(m_apList[i]);
|
|
|
|
|
++avaliableAPCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update active AP state
|
|
|
|
|
NetworkDevice::DeviceStatus deviceStatus = m_device->status();
|
|
|
|
|
if (!m_apwList.isEmpty()) {
|
|
|
|
|
AccessPointWidget *apw = m_apwList.first();
|
|
|
|
|
|
|
|
|
|
apw->setActiveState(deviceStatus);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 21:08:52 +08:00
|
|
|
|
if (m_loadingStat->isVisible() && !m_activatingAP.isEmpty() && m_apList.contains(m_activatingAP)) {
|
2019-03-08 18:06:55 +08:00
|
|
|
|
AccessPointWidget *apw = accessPointWidgetByAp(m_activatingAP);
|
|
|
|
|
if (apw) {
|
2020-04-09 21:08:52 +08:00
|
|
|
|
const int h = -(apw->height() - m_loadingStat->height()) / 2;
|
2020-04-21 11:03:27 +08:00
|
|
|
|
m_loadingStat->move(apw->mapTo(this, apw->rect().topRight()) - QPoint(23, h));
|
2019-03-08 18:06:55 +08:00
|
|
|
|
}
|
2018-06-22 19:07:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 10:43:29 +08:00
|
|
|
|
if (deviceStatus <= NetworkDevice::Disconnected || deviceStatus >= NetworkDevice::Activated) {
|
2020-04-09 21:08:52 +08:00
|
|
|
|
m_loadingStat->stop();
|
|
|
|
|
m_loadingStat->hide();
|
2018-06-22 19:07:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 21:08:52 +08:00
|
|
|
|
const int contentHeight = avaliableAPCount * ItemHeight;
|
2018-06-22 19:07:11 +08:00
|
|
|
|
m_centralWidget->setFixedHeight(contentHeight);
|
2020-04-09 21:08:52 +08:00
|
|
|
|
setFixedHeight(contentHeight);
|
|
|
|
|
emit requestUpdatePopup();
|
2019-03-12 16:34:40 +08:00
|
|
|
|
|
2019-05-06 16:49:58 +08:00
|
|
|
|
QTimer::singleShot(100, this, &WirelessList::updateIndicatorPos);
|
2018-06-22 19:07:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WirelessList::onEnableButtonToggle(const bool enable)
|
|
|
|
|
{
|
2018-12-25 13:13:26 +08:00
|
|
|
|
if (m_device.isNull()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 19:07:11 +08:00
|
|
|
|
Q_EMIT requestSetDeviceEnable(m_device->path(), enable);
|
|
|
|
|
m_updateAPTimer->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WirelessList::onDeviceEnableChanged(const bool enable)
|
|
|
|
|
{
|
|
|
|
|
m_controlPanel->setDeviceEnabled(enable);
|
|
|
|
|
m_updateAPTimer->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WirelessList::activateAP(const QString &apPath, const QString &ssid)
|
|
|
|
|
{
|
2018-12-25 13:13:26 +08:00
|
|
|
|
if (m_device.isNull()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 19:07:11 +08:00
|
|
|
|
QString uuid;
|
|
|
|
|
|
|
|
|
|
QList<QJsonObject> connections = m_device->connections();
|
|
|
|
|
for (auto item : connections) {
|
|
|
|
|
if (item.value("Ssid").toString() != ssid)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
uuid = item.value("Uuid").toString();
|
|
|
|
|
if (!uuid.isEmpty())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Q_EMIT requestActiveAP(m_device->path(), apPath, uuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WirelessList::deactiveAP()
|
|
|
|
|
{
|
2018-12-25 13:13:26 +08:00
|
|
|
|
if (m_device.isNull()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 19:07:11 +08:00
|
|
|
|
Q_EMIT requestDeactiveAP(m_device->path());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WirelessList::updateIndicatorPos()
|
|
|
|
|
{
|
2019-03-08 18:06:55 +08:00
|
|
|
|
QString activeSsid;
|
|
|
|
|
for (auto activeConnObj : m_device->activeConnections()) {
|
|
|
|
|
if (activeConnObj.value("Vpn").toBool(false)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// the State of Active Connection
|
|
|
|
|
// 0:Unknow, 1:Activating, 2:Activated, 3:Deactivating, 4:Deactivated
|
|
|
|
|
if (activeConnObj.value("State").toInt(0) != 1) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
activeSsid = activeConnObj.value("Id").toString();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
2019-03-08 18:06:55 +08:00
|
|
|
|
// if current is not activating wireless this will make m_activatingAP empty
|
|
|
|
|
m_activatingAP = accessPointBySsid(activeSsid);
|
|
|
|
|
AccessPointWidget *apw = accessPointWidgetByAp(m_activatingAP);
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
2019-03-08 18:06:55 +08:00
|
|
|
|
if (activeSsid.isEmpty() || m_activatingAP.isEmpty() || !apw) {
|
2020-04-09 21:08:52 +08:00
|
|
|
|
m_loadingStat->hide();
|
2019-03-08 18:06:55 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-06-22 19:07:11 +08:00
|
|
|
|
|
2020-04-09 21:08:52 +08:00
|
|
|
|
const int h = -(apw->height() - m_loadingStat->height()) / 2;
|
2020-04-21 11:03:27 +08:00
|
|
|
|
m_loadingStat->move(apw->mapTo(this, apw->rect().topRight()) - QPoint(23, h));
|
2020-04-09 21:08:52 +08:00
|
|
|
|
m_loadingStat->show();
|
|
|
|
|
m_loadingStat->start();
|
2018-06-22 19:07:11 +08:00
|
|
|
|
}
|
2018-06-28 21:27:06 +08:00
|
|
|
|
|
2019-03-08 18:06:55 +08:00
|
|
|
|
void WirelessList::onActiveConnectionInfoChanged()
|
2018-06-28 21:27:06 +08:00
|
|
|
|
{
|
2018-12-25 13:13:26 +08:00
|
|
|
|
if (m_device.isNull()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-11 15:11:28 +08:00
|
|
|
|
// 在这个方法中需要通过m_device->activeApSsid()的信息设置m_activeAP的值
|
2018-06-28 21:27:06 +08:00
|
|
|
|
// m_activeAP的值应该从m_apList中拿到,但在程序第一次启动后,当后端扫描无线网的数据还没有发过来,
|
|
|
|
|
// 这时m_device中的ap list为空,导致本类初始化时调用loadAPList()后m_apList也是空的,
|
|
|
|
|
// 那么也就无法给m_activeAP正确的值,所以在这里使用timer等待一下后端的数据,再执行遍历m_apList给m_activeAP赋值的操作
|
|
|
|
|
if (m_device->enabled() && m_device->status() == NetworkDevice::Activated
|
|
|
|
|
&& m_apList.size() == 0) {
|
2020-05-23 11:41:09 +08:00
|
|
|
|
QTimer::singleShot(1000, [ = ] {onActiveConnectionInfoChanged();});
|
2018-06-28 21:27:06 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_apList.size(); ++i) {
|
2018-10-11 15:11:28 +08:00
|
|
|
|
if (m_apList.at(i).ssid() == m_device->activeApSsid()) {
|
2018-06-28 21:27:06 +08:00
|
|
|
|
m_activeAP = m_apList.at(i);
|
|
|
|
|
m_updateAPTimer->start();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-03 10:43:29 +08:00
|
|
|
|
|
|
|
|
|
void WirelessList::onActivateApFailed(const QString &apPath, const QString &uuid)
|
|
|
|
|
{
|
2019-03-08 18:06:55 +08:00
|
|
|
|
if (m_device.isNull() && !m_clickedAPW) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AccessPoint clickedAP = m_clickedAPW->ap();
|
|
|
|
|
|
|
|
|
|
if (clickedAP.isEmpty()) {
|
2018-12-25 13:13:26 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 18:06:55 +08:00
|
|
|
|
if (clickedAP.path() == apPath) {
|
2018-09-03 10:43:29 +08:00
|
|
|
|
qDebug() << "wireless connect failed and may require more configuration,"
|
2020-05-23 11:41:09 +08:00
|
|
|
|
<< "path:" << clickedAP.path() << "ssid" << clickedAP.ssid()
|
|
|
|
|
<< "secret:" << clickedAP.secured() << "strength" << clickedAP.strength();
|
2018-09-03 10:43:29 +08:00
|
|
|
|
m_updateAPTimer->start();
|
|
|
|
|
|
|
|
|
|
DDBusSender()
|
2020-05-23 11:41:09 +08:00
|
|
|
|
.service("com.deepin.dde.ControlCenter")
|
|
|
|
|
.interface("com.deepin.dde.ControlCenter")
|
|
|
|
|
.path("/com/deepin/dde/ControlCenter")
|
|
|
|
|
.method("ShowPage")
|
|
|
|
|
.arg(QString("network"))
|
|
|
|
|
.arg(QString("%1,%2").arg(m_device->path()).arg(uuid))
|
|
|
|
|
.call();
|
2018-09-03 10:43:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-08 18:06:55 +08:00
|
|
|
|
|
2019-03-20 15:49:41 +08:00
|
|
|
|
void WirelessList::onHotspotEnabledChanged(const bool enabled)
|
|
|
|
|
{
|
|
|
|
|
// Note: the obtained hotspot info is not complete
|
|
|
|
|
m_activeHotspotAP = enabled ? AccessPoint(m_device->activeHotspotInfo().value("Hotspot").toObject())
|
2020-05-23 11:41:09 +08:00
|
|
|
|
: AccessPoint();
|
2019-12-03 09:45:29 +08:00
|
|
|
|
isHotposActive = enabled;
|
2019-03-20 15:49:41 +08:00
|
|
|
|
m_updateAPTimer->start();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 18:06:55 +08:00
|
|
|
|
AccessPoint WirelessList::accessPointBySsid(const QString &ssid)
|
|
|
|
|
{
|
|
|
|
|
if (ssid.isEmpty()) {
|
|
|
|
|
return AccessPoint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto ap : m_apList) {
|
|
|
|
|
if (ap.ssid() == ssid) {
|
|
|
|
|
return ap;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AccessPoint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AccessPointWidget *WirelessList::accessPointWidgetByAp(const AccessPoint ap)
|
|
|
|
|
{
|
|
|
|
|
if (ap.isEmpty()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto apw : m_apwList) {
|
|
|
|
|
if (apw->ap().path() == ap.path()) {
|
|
|
|
|
return apw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|