fix: activating indicator not show when activate a wireless from other place

https://github.com/linuxdeepin/internal-discussion/issues/525

Change-Id: Ifa8b53bf4d6b09a0f04e58e324ca63203a72a842
This commit is contained in:
listenerri 2019-03-08 18:06:55 +08:00
parent 14e2edac28
commit 5f11a0134a
Notes: gerrit 2019-03-12 10:12:10 +08:00
Verified+1: <jenkins@deepin.com>
Code-Review+2: listenerri <listenerri@gmail.com>
Submitted-by: listenerri <listenerri@gmail.com>
Submitted-at: Tue, 12 Mar 2019 10:12:09 +0800
Reviewed-on: https://cr.deepin.io/41927
Project: dde/dde-dock
Branch: refs/heads/master
7 changed files with 118 additions and 42 deletions

31
debian/control vendored
View File

@ -2,17 +2,28 @@ Source: dde-dock
Section: x11
Priority: optional
Maintainer: Deepin Packages Builder <packages@deepin.com>
Build-Depends: debhelper (>= 8.0.0), pkg-config,
Build-Depends: debhelper (>= 8.0.0),
pkg-config,
qt5-qmake,
libxcb-image0-dev, libxcb-composite0-dev,
libxcb-ewmh-dev, libqt5x11extras5-dev,
libxcb-damage0-dev, libqt5svg5-dev,
libxcb-icccm4-dev, libxtst-dev,
libdtkwidget-dev, libdtkcore-dev | libdtkutil-dev,
qttools5-dev-tools, libxcb-icccm4-dev,
qtbase5-private-dev, libdframeworkdbus-dev,
libgsettings-qt-dev, cmake,
libdde-network-utils-dev, libdbusmenu-qt5-dev
libxcb-image0-dev,
libxcb-composite0-dev,
libxcb-ewmh-dev,
libqt5x11extras5-dev,
libxcb-damage0-dev,
libqt5svg5-dev,
libxcb-icccm4-dev,
libxtst-dev,
libdtkwidget-dev,
libdtkcore-dev | libdtkutil-dev,
qttools5-dev-tools,
libxcb-icccm4-dev,
qtbase5-private-dev,
libdframeworkdbus-dev,
libgsettings-qt-dev,
cmake,
libdde-network-utils-dev (>= 0.1.0),
libdde-network-utils-dev (<< 0.1.1),
libdbusmenu-qt5-dev
Standards-Version: 3.9.8
Homepage: http://www.deepin.org/

View File

@ -92,6 +92,11 @@ bool AccessPoint::secured() const
return m_secured;
}
bool AccessPoint::isEmpty() const
{
return m_path.isEmpty();
}
void AccessPoint::loadApInfo(const QJsonObject &apInfo)
{
m_strength = apInfo.value("Strength").toInt();

View File

@ -43,6 +43,8 @@ public:
int strength() const;
bool secured() const;
bool isEmpty() const;
private:
void loadApInfo(const QJsonObject &apInfo);

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: sbw <sbw@sbw.so>
@ -53,8 +53,6 @@ WirelessList::WirelessList(WirelessDevice *deviceIter, QWidget *parent)
{
setFixedHeight(WIDTH);
m_currentClickAPW = nullptr;
const auto ratio = qApp->devicePixelRatio();
QPixmap iconPix = QIcon::fromTheme("notification-network-wireless-full").pixmap(QSize(48, 48) * ratio);
iconPix.setDevicePixelRatio(ratio);
@ -92,14 +90,16 @@ WirelessList::WirelessList(WirelessDevice *deviceIter, QWidget *parent)
connect(m_updateAPTimer, &QTimer::timeout, this, &WirelessList::updateAPList);
connect(m_device, &WirelessDevice::activeWirelessConnectionChanged, this, &WirelessList::onActiveConnectionChanged);
connect(m_device, &WirelessDevice::activeWirelessConnectionInfoChanged, this, &WirelessList::onActiveConnectionInfoChanged);
connect(m_device, static_cast<void (WirelessDevice:: *) (NetworkDevice::DeviceStatus stat) const>(&WirelessDevice::statusChanged), m_updateAPTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
connect(m_device, &WirelessDevice::activeConnectionsChanged, this, &WirelessList::updateIndicatorPos, Qt::QueuedConnection);
connect(this->verticalScrollBar(), &QScrollBar::valueChanged, this, [=] {
if (!m_currentClickAPW) return;
auto apw = accessPointWidgetByAp(m_activatingAP);
if (!apw) return;
const int h = -(m_currentClickAPW->height() - m_indicator->height()) / 2;
m_indicator->move(m_currentClickAPW->mapTo(this, m_currentClickAPW->rect().topRight()) - QPoint(35, h));
const int h = -(apw->height() - m_indicator->height()) / 2;
m_indicator->move(apw->mapTo(this, apw->rect().topRight()) - QPoint(35, h));
});
QMetaObject::invokeMethod(this, "loadAPList", Qt::QueuedConnection);
@ -208,7 +208,6 @@ void WirelessList::updateAPList()
//if (m_networkInter->IsDeviceEnabled(m_device.dbusPath()))
if (m_device->enabled())
{
m_currentClickAPW = nullptr;
// sort ap list by strength
// std::sort(m_apList.begin(), m_apList.end(), std::greater<AccessPoint>());
// const bool wirelessActived = m_device.state() == NetworkDevice::Activated;
@ -224,6 +223,9 @@ void WirelessList::updateAPList()
connect(apw, &AccessPointWidget::requestActiveAP, this, &WirelessList::activateAP);
connect(apw, &AccessPointWidget::requestDeactiveAP, this, &WirelessList::deactiveAP);
connect(apw, &AccessPointWidget::requestActiveAP, this, [=] {
m_clickedAPW = apw;
}, Qt::UniqueConnection);
}
} else if (m_apList.size() < m_apwList.size()) {
if (!m_apwList.isEmpty()) {
@ -232,7 +234,6 @@ void WirelessList::updateAPList()
AccessPointWidget *apw = m_apwList.last();
m_apwList.removeLast();
m_centralLayout->removeWidget(apw);
disconnect(apw, &AccessPointWidget::clicked, this, &WirelessList::updateIndicatorPos);
apw->deleteLater();
}
}
@ -248,10 +249,10 @@ void WirelessList::updateAPList()
return ap1.strength() > ap2.strength();
});
// update the content of AccessPointWidget by the order of ApList
for (int i = 0; i != m_apList.size(); i++) {
m_apwList[i]->updateAP(m_apList[i]);
++avaliableAPCount;
connect(m_apwList[i], &AccessPointWidget::clicked, this, &WirelessList::updateIndicatorPos, Qt::UniqueConnection);
}
// update active AP state
@ -263,10 +264,12 @@ void WirelessList::updateAPList()
}
// If the order of item changes
if (m_apList.contains(m_currentClickAP) && m_indicator->isVisible()) {
m_currentClickAPW = m_apwList.at(m_apList.indexOf(m_currentClickAP));
const int h = -(m_currentClickAPW->height() - m_indicator->height()) / 2;
m_indicator->move(m_currentClickAPW->mapTo(this, m_currentClickAPW->rect().topRight()) - QPoint(35, h));
if (m_indicator->isVisible() && !m_activatingAP.isEmpty() && m_apList.contains(m_activatingAP)) {
AccessPointWidget *apw = accessPointWidgetByAp(m_activatingAP);
if (apw) {
const int h = -(apw->height() - m_indicator->height()) / 2;
m_indicator->move(apw->mapTo(this, apw->rect().topRight()) - QPoint(35, h));
}
}
if (deviceStatus <= NetworkDevice::Disconnected || deviceStatus >= NetworkDevice::Activated) {
@ -308,8 +311,6 @@ void WirelessList::activateAP(const QString &apPath, const QString &ssid)
for (auto item : connections) {
if (item.value("Ssid").toString() != ssid)
continue;
if (item.value("HwAddress").toString() != m_device->usingHwAdr())
continue;
uuid = item.value("Uuid").toString();
if (!uuid.isEmpty())
@ -330,19 +331,36 @@ void WirelessList::deactiveAP()
void WirelessList::updateIndicatorPos()
{
m_currentClickAPW = static_cast<AccessPointWidget*>(sender());
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;
}
if (m_currentClickAPW->active()) return;
// if current is not activating wireless this will make m_activatingAP empty
m_activatingAP = accessPointBySsid(activeSsid);
AccessPointWidget *apw = accessPointWidgetByAp(m_activatingAP);
m_currentClickAP = m_currentClickAPW->ap();
if (activeSsid.isEmpty() || m_activatingAP.isEmpty() || !apw) {
m_indicator->hide();
return;
}
const int h = -(m_currentClickAPW->height() - m_indicator->height()) / 2;
m_indicator->move(m_currentClickAPW->mapTo(this, m_currentClickAPW->rect().topRight()) - QPoint(35, h));
const int h = -(apw->height() - m_indicator->height()) / 2;
m_indicator->move(apw->mapTo(this, apw->rect().topRight()) - QPoint(35, h));
m_indicator->show();
m_indicator->play();
}
void WirelessList::onActiveConnectionChanged()
void WirelessList::onActiveConnectionInfoChanged()
{
if (m_device.isNull()) {
return;
@ -354,7 +372,7 @@ void WirelessList::onActiveConnectionChanged()
// 那么也就无法给m_activeAP正确的值所以在这里使用timer等待一下后端的数据再执行遍历m_apList给m_activeAP赋值的操作
if (m_device->enabled() && m_device->status() == NetworkDevice::Activated
&& m_apList.size() == 0) {
QTimer::singleShot(1000, [=]{onActiveConnectionChanged();});
QTimer::singleShot(1000, [=]{onActiveConnectionInfoChanged();});
return;
}
@ -369,14 +387,20 @@ void WirelessList::onActiveConnectionChanged()
void WirelessList::onActivateApFailed(const QString &apPath, const QString &uuid)
{
if (m_device.isNull()) {
if (m_device.isNull() && !m_clickedAPW) {
return;
}
if (m_currentClickAP.path() == apPath) {
AccessPoint clickedAP = m_clickedAPW->ap();
if (clickedAP.isEmpty()) {
return;
}
if (clickedAP.path() == apPath) {
qDebug() << "wireless connect failed and may require more configuration,"
<< "path:" << m_currentClickAP.path() << "ssid" << m_currentClickAP.ssid()
<< "secret:" << m_currentClickAP.secured() << "strength" << m_currentClickAP.strength();
<< "path:" << clickedAP.path() << "ssid" << clickedAP.ssid()
<< "secret:" << clickedAP.secured() << "strength" << clickedAP.strength();
m_updateAPTimer->start();
m_editConnectionData = {};
@ -397,3 +421,33 @@ void WirelessList::onActivateApFailed(const QString &apPath, const QString &uuid
Q_EMIT requestSetAppletVisible(false);
}
}
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;
}

View File

@ -68,27 +68,31 @@ private slots:
void activateAP(const QString &apPath, const QString &ssid);
void deactiveAP();
void updateIndicatorPos();
void onActiveConnectionChanged();
void onActiveConnectionInfoChanged();
void onActivateApFailed(const QString &apPath, const QString &uuid);
private:
AccessPoint accessPointBySsid(const QString &ssid);
AccessPointWidget *accessPointWidgetByAp(const AccessPoint ap);
private:
QPointer<dde::network::WirelessDevice> m_device;
AccessPoint m_activeAP;
AccessPoint m_activatingAP;
QList<AccessPoint> m_apList;
QList<AccessPointWidget*> m_apwList;
QTimer *m_updateAPTimer;
Dtk::Widget::DPictureSequenceView *m_indicator;
AccessPointWidget *m_currentClickAPW;
AccessPoint m_currentClickAP;
QJsonObject m_editConnectionData;
QVBoxLayout *m_centralLayout;
QWidget *m_centralWidget;
DeviceControlWidget *m_controlPanel;
AccessPointWidget *m_clickedAPW;
};
#endif // WIRELESSAPPLET_H

View File

@ -49,7 +49,7 @@ WiredItem::WiredItem(WiredDevice *device)
connect(m_delayTimer, &QTimer::timeout, this, &WiredItem::reloadIcon);
connect(m_device, static_cast<void (NetworkDevice::*)(NetworkDevice::DeviceStatus) const>(&NetworkDevice::statusChanged), this, &WiredItem::deviceStateChanged);
connect(static_cast<WiredDevice *>(m_device.data()), &WiredDevice::connectionsChanged, this, &WiredItem::deviceStateChanged);
connect(static_cast<WiredDevice *>(m_device.data()), &WiredDevice::activeWiredConnectionChanged, this, &WiredItem::deviceStateChanged);
connect(static_cast<WiredDevice *>(m_device.data()), &WiredDevice::activeWiredConnectionInfoChanged, this, &WiredItem::deviceStateChanged);
QTimer::singleShot(0, this, &WiredItem::refreshTips);
QTimer::singleShot(0, this, &WiredItem::refreshIcon);

View File

@ -51,7 +51,7 @@ WirelessItem::WirelessItem(WirelessDevice *device)
connect(m_refreshTimer, &QTimer::timeout, this, &WirelessItem::onRefreshTimeout);
connect(m_device, static_cast<void (NetworkDevice::*) (const QString &statStr) const>(&NetworkDevice::statusChanged), this, &WirelessItem::deviceStateChanged);
connect(static_cast<WirelessDevice *>(m_device.data()), &WirelessDevice::activeApInfoChanged, m_refreshTimer, static_cast<void (QTimer::*) ()>(&QTimer::start));
connect(static_cast<WirelessDevice *>(m_device.data()), &WirelessDevice::activeWirelessConnectionChanged, m_refreshTimer, static_cast<void (QTimer::*) ()>(&QTimer::start));
connect(static_cast<WirelessDevice *>(m_device.data()), &WirelessDevice::activeWirelessConnectionInfoChanged, m_refreshTimer, static_cast<void (QTimer::*) ()>(&QTimer::start));
//QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection);
QTimer::singleShot(0, this, &WirelessItem::refreshTips);