diff --git a/debian/control b/debian/control index 95855f96f..8f504da0b 100644 --- a/debian/control +++ b/debian/control @@ -2,17 +2,28 @@ Source: dde-dock Section: x11 Priority: optional Maintainer: Deepin Packages Builder -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/ diff --git a/plugins/network/item/applet/accesspoint.cpp b/plugins/network/item/applet/accesspoint.cpp index a82affde3..35bef37bd 100644 --- a/plugins/network/item/applet/accesspoint.cpp +++ b/plugins/network/item/applet/accesspoint.cpp @@ -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(); diff --git a/plugins/network/item/applet/accesspoint.h b/plugins/network/item/applet/accesspoint.h index 051227ac4..2645e0fbe 100644 --- a/plugins/network/item/applet/accesspoint.h +++ b/plugins/network/item/applet/accesspoint.h @@ -43,6 +43,8 @@ public: int strength() const; bool secured() const; + bool isEmpty() const; + private: void loadApInfo(const QJsonObject &apInfo); diff --git a/plugins/network/item/applet/wirelesslist.cpp b/plugins/network/item/applet/wirelesslist.cpp index d4889402e..00e34d1f7 100644 --- a/plugins/network/item/applet/wirelesslist.cpp +++ b/plugins/network/item/applet/wirelesslist.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd. * * Author: sbw @@ -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(&WirelessDevice::statusChanged), m_updateAPTimer, static_cast(&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()); // 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(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; +} diff --git a/plugins/network/item/applet/wirelesslist.h b/plugins/network/item/applet/wirelesslist.h index 9247580f6..7f8d3820f 100644 --- a/plugins/network/item/applet/wirelesslist.h +++ b/plugins/network/item/applet/wirelesslist.h @@ -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 m_device; AccessPoint m_activeAP; + AccessPoint m_activatingAP; QList m_apList; QList 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 diff --git a/plugins/network/item/wireditem.cpp b/plugins/network/item/wireditem.cpp index 3e0413bae..3097cf58a 100644 --- a/plugins/network/item/wireditem.cpp +++ b/plugins/network/item/wireditem.cpp @@ -49,7 +49,7 @@ WiredItem::WiredItem(WiredDevice *device) connect(m_delayTimer, &QTimer::timeout, this, &WiredItem::reloadIcon); connect(m_device, static_cast(&NetworkDevice::statusChanged), this, &WiredItem::deviceStateChanged); connect(static_cast(m_device.data()), &WiredDevice::connectionsChanged, this, &WiredItem::deviceStateChanged); - connect(static_cast(m_device.data()), &WiredDevice::activeWiredConnectionChanged, this, &WiredItem::deviceStateChanged); + connect(static_cast(m_device.data()), &WiredDevice::activeWiredConnectionInfoChanged, this, &WiredItem::deviceStateChanged); QTimer::singleShot(0, this, &WiredItem::refreshTips); QTimer::singleShot(0, this, &WiredItem::refreshIcon); diff --git a/plugins/network/item/wirelessitem.cpp b/plugins/network/item/wirelessitem.cpp index dcad67337..61282a97b 100644 --- a/plugins/network/item/wirelessitem.cpp +++ b/plugins/network/item/wirelessitem.cpp @@ -51,7 +51,7 @@ WirelessItem::WirelessItem(WirelessDevice *device) connect(m_refreshTimer, &QTimer::timeout, this, &WirelessItem::onRefreshTimeout); connect(m_device, static_cast(&NetworkDevice::statusChanged), this, &WirelessItem::deviceStateChanged); connect(static_cast(m_device.data()), &WirelessDevice::activeApInfoChanged, m_refreshTimer, static_cast(&QTimer::start)); - connect(static_cast(m_device.data()), &WirelessDevice::activeWirelessConnectionChanged, m_refreshTimer, static_cast(&QTimer::start)); + connect(static_cast(m_device.data()), &WirelessDevice::activeWirelessConnectionInfoChanged, m_refreshTimer, static_cast(&QTimer::start)); //QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection); QTimer::singleShot(0, this, &WirelessItem::refreshTips);