2017-09-18 14:33:44 +08:00
|
|
|
/*
|
2018-02-07 11:52:47 +08:00
|
|
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
2017-09-18 14:33:44 +08:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-07-26 16:59:44 +08:00
|
|
|
#include "accesspointwidget.h"
|
2016-08-03 10:01:28 +08:00
|
|
|
#include "horizontalseperator.h"
|
2016-07-26 16:59:44 +08:00
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QDebug>
|
|
|
|
|
2017-11-20 11:25:06 +08:00
|
|
|
#include <DSvgRenderer>
|
|
|
|
|
2016-08-11 20:43:34 +08:00
|
|
|
DWIDGET_USE_NAMESPACE
|
|
|
|
|
2016-07-26 16:59:44 +08:00
|
|
|
AccessPointWidget::AccessPointWidget(const AccessPoint &ap)
|
2016-08-29 16:10:33 +08:00
|
|
|
: QFrame(nullptr),
|
2016-07-26 16:59:44 +08:00
|
|
|
|
2016-08-29 16:10:33 +08:00
|
|
|
m_activeState(NetworkDevice::Unknow),
|
2016-07-28 10:46:00 +08:00
|
|
|
m_ap(ap),
|
2016-07-28 16:57:05 +08:00
|
|
|
m_ssidBtn(new QPushButton(this)),
|
2016-08-29 16:10:33 +08:00
|
|
|
m_indicator(new DPictureSequenceView(this)),
|
2016-08-11 20:43:34 +08:00
|
|
|
m_disconnectBtn(new DImageButton(this)),
|
2016-07-27 10:06:14 +08:00
|
|
|
m_securityIcon(new QLabel),
|
|
|
|
m_strengthIcon(new QLabel)
|
2016-07-26 16:59:44 +08:00
|
|
|
{
|
2017-11-20 11:25:06 +08:00
|
|
|
const auto ratio = devicePixelRatioF();
|
2016-07-28 16:57:05 +08:00
|
|
|
m_ssidBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
|
|
m_ssidBtn->setText(ap.ssid());
|
|
|
|
m_ssidBtn->setObjectName("Ssid");
|
2016-07-26 16:59:44 +08:00
|
|
|
|
2016-08-11 20:43:34 +08:00
|
|
|
m_disconnectBtn->setVisible(false);
|
2017-11-20 11:25:06 +08:00
|
|
|
m_disconnectBtn->setNormalPic(":/wireless/resources/wireless/select.svg");
|
|
|
|
m_disconnectBtn->setHoverPic(":/wireless/resources/wireless/disconnect_hover.svg");
|
|
|
|
m_disconnectBtn->setPressPic(":/wireless/resources/wireless/disconnect_press.svg");
|
|
|
|
|
2017-11-30 09:24:12 +08:00
|
|
|
m_indicator->setPictureSequence(":/wireless/indicator/resources/wireless/spinner14/Spinner%1.png", QPair<int, int>(1, 91), 2);
|
2017-11-20 11:25:06 +08:00
|
|
|
m_indicator->setFixedSize(QSize(14, 14) * ratio);
|
2016-08-29 16:10:33 +08:00
|
|
|
m_indicator->setVisible(false);
|
|
|
|
|
2016-07-27 10:06:14 +08:00
|
|
|
if (ap.secured())
|
2017-11-20 11:25:06 +08:00
|
|
|
{
|
|
|
|
QPixmap iconPix = DSvgRenderer::render(":/wireless/resources/wireless/security.svg", QSize(16, 16) * ratio);
|
|
|
|
iconPix.setDevicePixelRatio(ratio);
|
|
|
|
m_securityIcon->setPixmap(iconPix);
|
|
|
|
}
|
2016-07-27 10:06:14 +08:00
|
|
|
else
|
2016-08-08 15:29:27 +08:00
|
|
|
{
|
2017-11-20 11:25:06 +08:00
|
|
|
QPixmap pixmap(QSize(16, 16));
|
2016-08-08 15:29:27 +08:00
|
|
|
pixmap.fill(Qt::transparent);
|
|
|
|
m_securityIcon->setPixmap(pixmap);
|
|
|
|
}
|
2016-07-27 10:06:14 +08:00
|
|
|
|
2016-08-03 10:01:28 +08:00
|
|
|
QHBoxLayout *infoLayout = new QHBoxLayout;
|
|
|
|
infoLayout->addWidget(m_securityIcon);
|
|
|
|
infoLayout->addSpacing(5);
|
|
|
|
infoLayout->addWidget(m_strengthIcon);
|
|
|
|
infoLayout->addSpacing(10);
|
|
|
|
infoLayout->addWidget(m_ssidBtn);
|
2016-08-29 16:10:33 +08:00
|
|
|
infoLayout->addWidget(m_indicator);
|
2016-08-11 20:43:34 +08:00
|
|
|
infoLayout->addWidget(m_disconnectBtn);
|
|
|
|
infoLayout->addSpacing(20);
|
2016-08-03 10:01:28 +08:00
|
|
|
infoLayout->setSpacing(0);
|
|
|
|
infoLayout->setContentsMargins(15, 0, 0, 0);
|
|
|
|
|
2017-02-06 22:25:47 +08:00
|
|
|
QVBoxLayout *centralLayout = new QVBoxLayout;
|
|
|
|
centralLayout->addLayout(infoLayout);
|
|
|
|
centralLayout->setSpacing(0);
|
|
|
|
centralLayout->setMargin(0);
|
2016-07-26 16:59:44 +08:00
|
|
|
|
2016-07-27 10:06:14 +08:00
|
|
|
setStrengthIcon(ap.strength());
|
2017-02-06 22:25:47 +08:00
|
|
|
setLayout(centralLayout);
|
2016-07-28 16:57:05 +08:00
|
|
|
setStyleSheet("AccessPointWidget #Ssid {"
|
|
|
|
"color:white;"
|
2016-08-02 17:56:09 +08:00
|
|
|
"background-color:transparent;"
|
|
|
|
"border:none;"
|
2016-07-28 16:57:05 +08:00
|
|
|
"text-align:left;"
|
|
|
|
"}"
|
2016-08-29 16:10:33 +08:00
|
|
|
"AccessPointWidget {"
|
2016-09-01 17:25:01 +08:00
|
|
|
"border-radius:4px;"
|
|
|
|
"margin:0 2px;"
|
|
|
|
"border-top:1px solid rgba(255, 255, 255, .05);"
|
2016-08-29 16:10:33 +08:00
|
|
|
"}"
|
|
|
|
"AccessPointWidget:hover {"
|
|
|
|
"border:none;"
|
2016-09-01 17:25:01 +08:00
|
|
|
"margin:0;"
|
2016-08-29 16:10:33 +08:00
|
|
|
"background-color:rgba(255, 255, 255, .1);"
|
|
|
|
"}"
|
2016-07-28 16:57:05 +08:00
|
|
|
"AccessPointWidget[active=true] #Ssid {"
|
2016-08-11 20:43:34 +08:00
|
|
|
// "color:#2ca7f8;"
|
2016-07-28 16:57:05 +08:00
|
|
|
"}");
|
|
|
|
|
|
|
|
connect(m_ssidBtn, &QPushButton::clicked, this, &AccessPointWidget::ssidClicked);
|
2016-08-11 20:43:34 +08:00
|
|
|
connect(m_disconnectBtn, &DImageButton::clicked, this, &AccessPointWidget::disconnectBtnClicked);
|
2016-07-28 16:57:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AccessPointWidget::active() const
|
|
|
|
{
|
2016-08-29 16:10:33 +08:00
|
|
|
return m_activeState == NetworkDevice::Activated;
|
2016-07-26 16:59:44 +08:00
|
|
|
}
|
2016-07-27 10:06:14 +08:00
|
|
|
|
2016-08-29 16:10:33 +08:00
|
|
|
void AccessPointWidget::setActiveState(const NetworkDevice::NetworkState state)
|
2016-07-28 10:46:00 +08:00
|
|
|
{
|
2016-08-29 16:10:33 +08:00
|
|
|
if (m_activeState == state)
|
2016-07-28 10:46:00 +08:00
|
|
|
return;
|
|
|
|
|
2016-08-29 16:10:33 +08:00
|
|
|
m_activeState = state;
|
2016-07-28 16:57:05 +08:00
|
|
|
setStyleSheet(styleSheet());
|
2016-08-29 16:10:33 +08:00
|
|
|
|
|
|
|
const bool isActive = active();
|
|
|
|
m_disconnectBtn->setVisible(isActive);
|
2016-08-30 17:18:31 +08:00
|
|
|
|
|
|
|
if (!isActive && state > NetworkDevice::Disconnected)
|
|
|
|
{
|
|
|
|
m_indicator->play();
|
|
|
|
m_indicator->setVisible(true);
|
|
|
|
} else {
|
|
|
|
m_indicator->setVisible(false);
|
|
|
|
}
|
2016-08-29 16:10:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AccessPointWidget::enterEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
QWidget::enterEvent(e);
|
2017-11-20 11:25:06 +08:00
|
|
|
m_disconnectBtn->setNormalPic(":/wireless/resources/wireless/disconnect.svg");
|
2016-08-29 16:10:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AccessPointWidget::leaveEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
QWidget::leaveEvent(e);
|
2017-11-20 11:25:06 +08:00
|
|
|
m_disconnectBtn->setNormalPic(":/wireless/resources/wireless/select.svg");
|
2016-07-28 10:46:00 +08:00
|
|
|
}
|
|
|
|
|
2016-07-27 10:06:14 +08:00
|
|
|
void AccessPointWidget::setStrengthIcon(const int strength)
|
|
|
|
{
|
2017-11-20 11:25:06 +08:00
|
|
|
QPixmap iconPix;
|
|
|
|
const auto ratio = devicePixelRatioF();
|
|
|
|
const QSize s = QSize(16, 16) * ratio;
|
|
|
|
|
2017-12-01 15:41:05 +08:00
|
|
|
QString type;
|
2016-07-27 10:06:14 +08:00
|
|
|
if (strength == 100)
|
2017-12-01 15:41:05 +08:00
|
|
|
type = "80";
|
|
|
|
else if (strength < 20)
|
|
|
|
type = "0";
|
2017-11-20 11:25:06 +08:00
|
|
|
else
|
2017-12-01 15:41:05 +08:00
|
|
|
type = QString::number(strength / 10 & ~0x1) + "0";
|
|
|
|
|
|
|
|
iconPix = DSvgRenderer::render(QString(":/wireless/resources/wireless/wireless-%1-symbolic.svg").arg(type), s);
|
2017-11-20 11:25:06 +08:00
|
|
|
iconPix.setDevicePixelRatio(ratio);
|
2016-07-27 10:06:14 +08:00
|
|
|
|
2017-11-20 11:25:06 +08:00
|
|
|
m_strengthIcon->setPixmap(iconPix);
|
2016-07-27 10:06:14 +08:00
|
|
|
}
|
2016-07-28 16:57:05 +08:00
|
|
|
|
|
|
|
void AccessPointWidget::ssidClicked()
|
|
|
|
{
|
2016-09-06 10:54:42 +08:00
|
|
|
if (m_activeState == NetworkDevice::Activated)
|
|
|
|
return;
|
|
|
|
|
2016-08-29 16:10:33 +08:00
|
|
|
setActiveState(NetworkDevice::Prepare);
|
2016-07-28 16:57:05 +08:00
|
|
|
emit requestActiveAP(QDBusObjectPath(m_ap.path()), m_ap.ssid());
|
|
|
|
}
|
2016-08-11 20:43:34 +08:00
|
|
|
|
|
|
|
void AccessPointWidget::disconnectBtnClicked()
|
|
|
|
{
|
2016-08-29 16:10:33 +08:00
|
|
|
setActiveState(NetworkDevice::Unknow);
|
2016-08-11 20:43:34 +08:00
|
|
|
emit requestDeactiveAP(m_ap);
|
|
|
|
}
|