mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
activate ap when clicked
Change-Id: I05aac5d527c467379a4c0d08bf6f9232cfb38097
This commit is contained in:
parent
553c666770
commit
53e8f61ab5
@ -56,6 +56,11 @@ const QString AccessPoint::ssid() const
|
||||
return m_ssid;
|
||||
}
|
||||
|
||||
const QString AccessPoint::path() const
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
int AccessPoint::strength() const
|
||||
{
|
||||
return m_strength;
|
||||
|
@ -18,6 +18,7 @@ public:
|
||||
AccessPoint &operator=(const AccessPoint &ap);
|
||||
|
||||
const QString ssid() const;
|
||||
const QString path() const;
|
||||
int strength() const;
|
||||
bool secured() const;
|
||||
|
||||
|
@ -6,16 +6,15 @@
|
||||
AccessPointWidget::AccessPointWidget(const AccessPoint &ap)
|
||||
: QWidget(nullptr),
|
||||
|
||||
m_active(false),
|
||||
m_ap(ap),
|
||||
m_ssid(new QLabel),
|
||||
m_ssidBtn(new QPushButton(this)),
|
||||
m_securityIcon(new QLabel),
|
||||
m_strengthIcon(new QLabel)
|
||||
{
|
||||
|
||||
m_ssid->setText(ap.ssid());
|
||||
m_ssid->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
m_ssid->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
|
||||
m_ssid->setStyleSheet("color:white;");
|
||||
m_ssidBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
m_ssidBtn->setText(ap.ssid());
|
||||
m_ssidBtn->setObjectName("Ssid");
|
||||
|
||||
if (ap.secured())
|
||||
m_securityIcon->setPixmap(QPixmap(":/wireless/resources/wireless/security.svg"));
|
||||
@ -27,12 +26,26 @@ AccessPointWidget::AccessPointWidget(const AccessPoint &ap)
|
||||
centeralLayout->addSpacing(5);
|
||||
centeralLayout->addWidget(m_strengthIcon);
|
||||
centeralLayout->addSpacing(10);
|
||||
centeralLayout->addWidget(m_ssid);
|
||||
centeralLayout->addWidget(m_ssidBtn);
|
||||
centeralLayout->setSpacing(0);
|
||||
centeralLayout->setMargin(0);
|
||||
|
||||
setStrengthIcon(ap.strength());
|
||||
setLayout(centeralLayout);
|
||||
setStyleSheet("AccessPointWidget #Ssid {"
|
||||
"color:white;"
|
||||
"text-align:left;"
|
||||
"}"
|
||||
"AccessPointWidget[active=true] #Ssid {"
|
||||
"color:#2ca7f8;"
|
||||
"}");
|
||||
|
||||
connect(m_ssidBtn, &QPushButton::clicked, this, &AccessPointWidget::ssidClicked);
|
||||
}
|
||||
|
||||
bool AccessPointWidget::active() const
|
||||
{
|
||||
return m_active;
|
||||
}
|
||||
|
||||
void AccessPointWidget::setActive(const bool active)
|
||||
@ -41,11 +54,7 @@ void AccessPointWidget::setActive(const bool active)
|
||||
return;
|
||||
|
||||
m_active = active;
|
||||
|
||||
if (m_active)
|
||||
m_ssid->setStyleSheet("color:#2c8cde;");
|
||||
else
|
||||
m_ssid->setStyleSheet("color:white;");
|
||||
setStyleSheet(styleSheet());
|
||||
}
|
||||
|
||||
void AccessPointWidget::setStrengthIcon(const int strength)
|
||||
@ -55,3 +64,8 @@ void AccessPointWidget::setStrengthIcon(const int strength)
|
||||
|
||||
m_strengthIcon->setPixmap(QPixmap(QString(":/wireless/resources/wireless/wireless-%1-symbolic.svg").arg(strength / 10 & ~0x1)));
|
||||
}
|
||||
|
||||
void AccessPointWidget::ssidClicked()
|
||||
{
|
||||
emit requestActiveAP(QDBusObjectPath(m_ap.path()), m_ap.ssid());
|
||||
}
|
||||
|
@ -5,24 +5,34 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QDBusObjectPath>
|
||||
|
||||
class AccessPointWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool active READ active WRITE setActive DESIGNABLE true)
|
||||
|
||||
public:
|
||||
explicit AccessPointWidget(const AccessPoint &ap);
|
||||
|
||||
bool active() const;
|
||||
void setActive(const bool active);
|
||||
|
||||
signals:
|
||||
void requestActiveAP(const QDBusObjectPath &apPath, const QString &ssid) const;
|
||||
|
||||
private:
|
||||
void setStrengthIcon(const int strength);
|
||||
|
||||
private slots:
|
||||
void ssidClicked();
|
||||
|
||||
private:
|
||||
bool m_active;
|
||||
|
||||
AccessPoint m_ap;
|
||||
QLabel *m_ssid;
|
||||
QPushButton *m_ssidBtn;
|
||||
QLabel *m_securityIcon;
|
||||
QLabel *m_strengthIcon;
|
||||
};
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <QJsonDocument>
|
||||
|
||||
#define WIDTH 300
|
||||
#define MAX_HEIGHT 200
|
||||
#define MAX_HEIGHT 300
|
||||
#define ITEM_HEIGHT 30
|
||||
|
||||
WirelessApplet::WirelessApplet(const QSet<NetworkDevice>::const_iterator &deviceIter, QWidget *parent)
|
||||
@ -49,6 +49,8 @@ WirelessApplet::WirelessApplet(const QSet<NetworkDevice>::const_iterator &device
|
||||
connect(m_controlPanel, &DeviceControlWidget::deviceEnableChanged, this, &WirelessApplet::deviceEnableChanged);
|
||||
|
||||
connect(m_updateAPTimer, &QTimer::timeout, this, &WirelessApplet::updateAPList);
|
||||
|
||||
connect(this, &WirelessApplet::activeAPChanged, m_updateAPTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
||||
}
|
||||
|
||||
NetworkDevice::NetworkState WirelessApplet::wirelessState() const
|
||||
@ -170,6 +172,9 @@ void WirelessApplet::updateAPList()
|
||||
AccessPointWidget *apw = new AccessPointWidget(ap);
|
||||
if (ap == m_activeAP)
|
||||
apw->setActive(true);
|
||||
|
||||
connect(apw, &AccessPointWidget::requestActiveAP, this, &WirelessApplet::activateAP);
|
||||
|
||||
m_centeralLayout->addWidget(apw);
|
||||
|
||||
++avaliableAPCount;
|
||||
@ -239,3 +244,29 @@ void WirelessApplet::onActiveAPChanged()
|
||||
|
||||
emit activeAPChanged();
|
||||
}
|
||||
|
||||
void WirelessApplet::activateAP(const QDBusObjectPath &apPath, const QString &ssid)
|
||||
{
|
||||
QString uuid;
|
||||
|
||||
const QJsonDocument doc = QJsonDocument::fromJson(m_networkInter->connections().toUtf8());
|
||||
for (auto it : doc.object().value("wireless").toArray())
|
||||
{
|
||||
const QJsonObject obj = it.toObject();
|
||||
if (obj.value("Ssid").toString() != ssid)
|
||||
continue;
|
||||
if (obj.value("HwAddress").toString() != m_device.hwAddress())
|
||||
continue;
|
||||
|
||||
uuid = obj.value("Uuid").toString();
|
||||
if (!uuid.isEmpty())
|
||||
break;
|
||||
}
|
||||
|
||||
m_networkInter->ActivateAccessPoint(uuid, apPath, m_device.dbusPath());
|
||||
}
|
||||
|
||||
void WirelessApplet::needSecrets(const QString &S1, const QString &s2, const QString &s3, const bool defaultAutoConnect)
|
||||
{
|
||||
qDebug() << S1 << s2 << s3 << defaultAutoConnect;
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ private slots:
|
||||
void deviceEnableChanged(const bool enable);
|
||||
void deviceStateChanegd();
|
||||
void onActiveAPChanged();
|
||||
void activateAP(const QDBusObjectPath &apPath, const QString &ssid);
|
||||
void needSecrets(const QString &S1, const QString &s2, const QString &s3, const bool defaultAutoConnect);
|
||||
|
||||
private:
|
||||
NetworkDevice m_device;
|
||||
|
Loading…
x
Reference in New Issue
Block a user