From 0231f82a01c389010bf4c5ea031a5f45a5bf27d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cfanpengcheng=5Fcm=E2=80=9D?= Date: Sat, 18 Apr 2020 17:29:45 +0800 Subject: [PATCH] fix(network):Abnormal hot swap of wired network MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 有线网络热插拔异常 bug:20058 (cherry picked from commit 9ddcdfbefbeffa7b8c89a584002451c970b448f7) --- .../network/item/applet/accesspointwidget.cpp | 35 +++-- .../item/applet/devicecontrolwidget.cpp | 4 +- .../network/item/applet/devicecontrolwidget.h | 2 +- plugins/network/item/wireditem.cpp | 92 +++++++----- plugins/network/item/wireditem.h | 14 +- plugins/network/item/wirelessitem.cpp | 26 +--- plugins/network/item/wirelessitem.h | 4 +- plugins/network/networkitem.cpp | 133 +++++++----------- plugins/network/networkitem.h | 6 +- plugins/network/networkplugin.cpp | 26 +++- translations/dde-dock_zh_CN.ts | 8 ++ 11 files changed, 188 insertions(+), 162 deletions(-) diff --git a/plugins/network/item/applet/accesspointwidget.cpp b/plugins/network/item/applet/accesspointwidget.cpp index f32aacb85..72b8174c9 100644 --- a/plugins/network/item/applet/accesspointwidget.cpp +++ b/plugins/network/item/applet/accesspointwidget.cpp @@ -38,6 +38,9 @@ using namespace dde::network; DWIDGET_USE_NAMESPACE DGUI_USE_NAMESPACE +extern const QString DarkType; +extern const QString LightType; + AccessPointWidget::AccessPointWidget() : QFrame(nullptr) , m_activeState(NetworkDevice::Unknow) @@ -52,12 +55,17 @@ AccessPointWidget::AccessPointWidget() m_ssidBtn->setObjectName("Ssid"); // m_disconnectBtn->setVisible(false); - auto iconPix = Utils::renderSVG(":/common/resources/common/list_select@2x.png", - QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); + bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType); + + auto pixpath = QString(":/wireless/resources/wireless/select"); + pixpath = isLight ? pixpath + DarkType : pixpath + LightType; + auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); m_stateButton->setPixmap(iconPix); m_stateButton->setVisible(false); - m_securityPixmap = Utils::renderSVG(":/wireless/resources/wireless/security.svg", QSize(16, 16), devicePixelRatioF()); + pixpath = QString(":/wireless/resources/wireless/security"); + pixpath = isLight ? pixpath + DarkType : pixpath + LightType; + m_securityPixmap = Utils::renderSVG(pixpath, QSize(16, 16), devicePixelRatioF()); m_securityIconSize = m_securityPixmap.size(); m_securityLabel->setPixmap(m_securityPixmap); m_securityLabel->setFixedSize(m_securityIconSize / devicePixelRatioF()); @@ -188,9 +196,12 @@ void AccessPointWidget::setStrengthIcon(const int strength) m_securityPixmap.setDevicePixelRatio(devicePixelRatioF()); m_securityLabel->setPixmap(m_securityPixmap); -// m_disconnectBtn->setNormalPic(isLight ? ":/wireless/resources/wireless/select_dark.svg" : ":/wireless/resources/wireless/select.svg"); -// m_disconnectBtn->setHoverPic(isLight ? ":/wireless/resources/wireless/disconnect_dark.svg" : ":/wireless/resources/wireless/disconnect.svg"); -// m_disconnectBtn->setPressPic(isLight ? ":/wireless/resources/wireless/disconnect_dark.svg" : ":/wireless/resources/wireless/disconnect.svg"); + if (NetworkDevice::Activated == m_activeState) { + auto pixpath = QString(":/wireless/resources/wireless/select"); + pixpath = isLight ? pixpath + DarkType : pixpath + LightType; + auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); + m_stateButton->setPixmap(iconPix); + } } void AccessPointWidget::ssidClicked() @@ -210,18 +221,22 @@ void AccessPointWidget::disconnectBtnClicked() void AccessPointWidget::buttonEnter() { + bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType); if (NetworkDevice::Activated == m_activeState) { - auto iconPix = Utils::renderSVG(":/common/resources/common/notify_close_press@2x.png", - QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); + auto pixpath = QString(":/wireless/resources/wireless/disconnect"); + pixpath = isLight ? pixpath + DarkType : pixpath + LightType; + auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); m_stateButton->setPixmap(iconPix); } } void AccessPointWidget::buttonLeave() { + bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType); if (NetworkDevice::Activated == m_activeState) { - auto iconPix = Utils::renderSVG(":/common/resources/common/list_select@2x.png", - QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); + auto pixpath = QString(":/wireless/resources/wireless/select"); + pixpath = isLight ? pixpath + DarkType : pixpath + LightType; + auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); m_stateButton->setPixmap(iconPix); } } diff --git a/plugins/network/item/applet/devicecontrolwidget.cpp b/plugins/network/item/applet/devicecontrolwidget.cpp index deae204fd..3fcefd82e 100644 --- a/plugins/network/item/applet/devicecontrolwidget.cpp +++ b/plugins/network/item/applet/devicecontrolwidget.cpp @@ -38,7 +38,7 @@ extern const int ItemHeight = 30; DeviceControlWidget::DeviceControlWidget(QWidget *parent) : QWidget(parent) { - m_deviceName = new TipsWidget; + m_deviceName = new QLabel(this); m_deviceName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); m_switchBtn = new DSwitchButton; @@ -116,7 +116,7 @@ void DeviceControlWidget::refreshNetwork() m_loadingIndicator->setLoading(true); - QTimer::singleShot(1000, this, [=] { + QTimer::singleShot(1000, this, [ = ] { m_loadingIndicator->setLoading(false); }); } diff --git a/plugins/network/item/applet/devicecontrolwidget.h b/plugins/network/item/applet/devicecontrolwidget.h index 61ba316bf..0a0a0411e 100644 --- a/plugins/network/item/applet/devicecontrolwidget.h +++ b/plugins/network/item/applet/devicecontrolwidget.h @@ -54,7 +54,7 @@ private slots: void refreshNetwork(); private: - TipsWidget *m_deviceName; + QLabel *m_deviceName; Dtk::Widget::DSwitchButton *m_switchBtn; // HorizontalSeperator *m_seperator; DLoadingIndicator *m_loadingIndicator; diff --git a/plugins/network/item/wireditem.cpp b/plugins/network/item/wireditem.cpp index 0e11cd5c1..b0ba7150f 100644 --- a/plugins/network/item/wireditem.cpp +++ b/plugins/network/item/wireditem.cpp @@ -31,9 +31,12 @@ DGUI_USE_NAMESPACE const int ItemHeight = 30; +extern const QString DarkType = "_dark.svg"; +extern const QString LightType = ".svg"; -WiredItem::WiredItem(WiredDevice *device, QWidget *parent) +WiredItem::WiredItem(WiredDevice *device, const QString &deviceName, QWidget *parent) : DeviceItem(device, parent) + , m_deviceName(deviceName) , m_connectedName(new QLabel(this)) , m_wiredIcon(new QLabel(this)) , m_stateButton(new StateLabel(this)) @@ -43,12 +46,16 @@ WiredItem::WiredItem(WiredDevice *device, QWidget *parent) setFixedHeight(ItemHeight); // m_connectedName->setVisible(false); - auto iconPix = Utils::renderSVG(":/wired/resources/wired/network-wired-symbolic-dark.svg", - QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); + bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType); + + auto pixpath = QString(":/wired/resources/wired/network-wired-symbolic"); + pixpath = isLight ? pixpath + "-dark.svg" : pixpath + LightType; + auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); m_wiredIcon->setPixmap(iconPix); m_wiredIcon->setVisible(false); - iconPix = Utils::renderSVG(":/common/resources/common/list_select@2x.png", - QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); + pixpath = QString(":/wireless/resources/wireless/select"); + pixpath = isLight ? pixpath + DarkType : pixpath + LightType; + iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); m_stateButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); m_stateButton->setPixmap(iconPix); m_stateButton->setVisible(false); @@ -56,6 +63,8 @@ WiredItem::WiredItem(WiredDevice *device, QWidget *parent) m_loadingStat->setVisible(false); // m_line->setVisible(false); + m_connectedName->setText(m_deviceName); + auto connectionLayout = new QVBoxLayout(this); connectionLayout->setMargin(0); connectionLayout->setSpacing(0); @@ -73,6 +82,8 @@ WiredItem::WiredItem(WiredDevice *device, QWidget *parent) connectionLayout->addLayout(itemLayout); setLayout(connectionLayout); + connect(m_device, static_cast(&NetworkDevice::enableChanged), + this, &WiredItem::enableChanged); connect(m_device, static_cast(&NetworkDevice::statusChanged), this, &WiredItem::deviceStateChanged); @@ -89,30 +100,16 @@ WiredItem::WiredItem(WiredDevice *device, QWidget *parent) deviceStateChanged(m_device->status()); } -bool WiredItem::deviceActivated() +void WiredItem::setTitle(const QString &name) { - switch (m_device->status()) { - case NetworkDevice::Unknow: - case NetworkDevice::Unmanaged: - case NetworkDevice::Unavailable: { - return false; - } - case NetworkDevice::Disconnected: - case NetworkDevice::Deactivation: - case NetworkDevice::Failed: - case NetworkDevice::Prepare: - case NetworkDevice::Config: - case NetworkDevice::NeedAuth: - case NetworkDevice::IpConfig: - case NetworkDevice::IpCheck: - case NetworkDevice::Secondaries: - case NetworkDevice::Activated: { - if (m_device->enabled()) - return true; - else - return false; - } - } + if (m_device->status() != NetworkDevice::Activated) + m_connectedName->setText(name); + m_deviceName = name; +} + +bool WiredItem::deviceEabled() +{ + return m_device->enabled(); } void WiredItem::setDeviceEnabled(bool enabled) @@ -155,9 +152,27 @@ QJsonObject WiredItem::getActiveWiredConnectionInfo() return static_cast(m_device.data())->activeWiredConnectionInfo(); } +void WiredItem::setThemeType(DGuiApplicationHelper::ColorType themeType) +{ + bool isLight = (themeType == DGuiApplicationHelper::LightType); + + auto pixpath = QString(":/wired/resources/wired/network-wired-symbolic"); + pixpath = isLight ? pixpath + "-dark.svg" : pixpath + LightType; + auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); + m_wiredIcon->setPixmap(iconPix); + + if (m_device) { + if (NetworkDevice::Activated == m_device->status()) { + pixpath = QString(":/wireless/resources/wireless/select"); + pixpath = isLight ? pixpath + DarkType : pixpath + LightType; + auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); + m_stateButton->setPixmap(iconPix); + } + } +} + void WiredItem::deviceStateChanged(NetworkDevice::DeviceStatus state) { - emit wiredState(state); QPixmap iconPix; switch (state) { case NetworkDevice::Unknow: @@ -169,6 +184,8 @@ void WiredItem::deviceStateChanged(NetworkDevice::DeviceStatus state) m_loadingStat->stop(); m_loadingStat->hide(); m_loadingStat->setVisible(false); + if (!m_device->enabled()) + m_stateButton->setVisible(false); } break; case NetworkDevice::Prepare: @@ -197,6 +214,9 @@ void WiredItem::deviceStateChanged(NetworkDevice::DeviceStatus state) void WiredItem::changedActiveWiredConnectionInfo(const QJsonObject &connInfo) { + if (connInfo.isEmpty()) + m_stateButton->setVisible(false); + auto strTitle = connInfo.value("ConnectionName").toString(); m_connectedName->setText(strTitle); QFontMetrics fontMetrics(m_connectedName->font()); @@ -205,7 +225,7 @@ void WiredItem::changedActiveWiredConnectionInfo(const QJsonObject &connInfo) } if (strTitle.isEmpty()) - m_connectedName->setText(m_device->usingHwAdr()); + m_connectedName->setText(m_deviceName); else m_connectedName->setText(strTitle); } @@ -213,9 +233,11 @@ void WiredItem::changedActiveWiredConnectionInfo(const QJsonObject &connInfo) void WiredItem::buttonEnter() { if (m_device) { + bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType); if (NetworkDevice::Activated == m_device->status()) { - auto iconPix = Utils::renderSVG(":/common/resources/common/notify_close_press@2x.png", - QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); + auto pixpath = QString(":/wireless/resources/wireless/disconnect"); + pixpath = isLight ? pixpath + DarkType : pixpath + LightType; + auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); m_stateButton->setPixmap(iconPix); } } @@ -224,9 +246,11 @@ void WiredItem::buttonEnter() void WiredItem::buttonLeave() { if (m_device) { + bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType); if (NetworkDevice::Activated == m_device->status()) { - auto iconPix = Utils::renderSVG(":/common/resources/common/list_select@2x.png", - QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); + auto pixpath = QString(":/wireless/resources/wireless/select"); + pixpath = isLight ? pixpath + DarkType : pixpath + LightType; + auto iconPix = Utils::renderSVG(pixpath, QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); m_stateButton->setPixmap(iconPix); } } diff --git a/plugins/network/item/wireditem.h b/plugins/network/item/wireditem.h index 6390fdd2f..3af0fe396 100644 --- a/plugins/network/item/wireditem.h +++ b/plugins/network/item/wireditem.h @@ -25,12 +25,14 @@ #include "deviceitem.h" #include +#include #include #include #include using namespace dde::network; +DGUI_USE_NAMESPACE DWIDGET_USE_NAMESPACE class TipsWidget; @@ -59,17 +61,19 @@ public: Q_ENUM(WiredStatus) public: - explicit WiredItem(dde::network::WiredDevice *device, QWidget *parent = nullptr); - inline void setTitle(const QString &name) { m_connectedName->setText(name); } - bool deviceActivated(); + explicit WiredItem(dde::network::WiredDevice *device, const QString &deviceName, QWidget *parent = nullptr); + void setTitle(const QString &name); + bool deviceEabled(); void setDeviceEnabled(bool enabled); WiredStatus getDeviceState(); QJsonObject getActiveWiredConnectionInfo(); + inline QString &deviceName() { return m_deviceName; } + void setThemeType(DGuiApplicationHelper::ColorType themeType); signals: void requestActiveConnection(const QString &devPath, const QString &uuid); - void wiredState(NetworkDevice::DeviceStatus state); void wiredStateChanged(); + void enableChanged(); private slots: void deviceStateChanged(NetworkDevice::DeviceStatus state); @@ -78,10 +82,12 @@ private slots: void buttonLeave(); private: + QString m_deviceName; QLabel *m_connectedName; QLabel *m_wiredIcon; StateLabel *m_stateButton; DSpinner *m_loadingStat; + // HorizontalSeperator *m_line; }; diff --git a/plugins/network/item/wirelessitem.cpp b/plugins/network/item/wirelessitem.cpp index c6488ebc2..75267a71e 100644 --- a/plugins/network/item/wirelessitem.cpp +++ b/plugins/network/item/wirelessitem.cpp @@ -89,30 +89,9 @@ int WirelessItem::APcount() return m_APList->APcount(); } -bool WirelessItem::deviceActivated() +bool WirelessItem::deviceEanbled() { - switch (m_device->status()) { - case NetworkDevice::Unknow: - case NetworkDevice::Unmanaged: - case NetworkDevice::Unavailable: { - return false; - } - case NetworkDevice::Disconnected: - case NetworkDevice::Deactivation: - case NetworkDevice::Failed: - case NetworkDevice::Prepare: - case NetworkDevice::Config: - case NetworkDevice::NeedAuth: - case NetworkDevice::IpConfig: - case NetworkDevice::IpCheck: - case NetworkDevice::Secondaries: - case NetworkDevice::Activated: { - if (m_device->enabled()) - return true; - else - return false; - } - } + return m_device->enabled(); } void WirelessItem::setDeviceEnabled(bool enable) @@ -163,6 +142,7 @@ QJsonObject WirelessItem::getActiveWirelessConnectionInfo() void WirelessItem::setDeviceInfo(const int index) { m_APList->setDeviceInfo(index); + m_index = index; } bool WirelessItem::eventFilter(QObject *o, QEvent *e) diff --git a/plugins/network/item/wirelessitem.h b/plugins/network/item/wirelessitem.h index 6d712c495..f8b36caa2 100644 --- a/plugins/network/item/wirelessitem.h +++ b/plugins/network/item/wirelessitem.h @@ -60,11 +60,12 @@ public: QWidget *itemApplet(); int APcount(); - bool deviceActivated(); + bool deviceEanbled(); void setDeviceEnabled(bool enable); WirelessStatus getDeviceState(); QJsonObject &getConnectedApInfo(); QJsonObject getActiveWirelessConnectionInfo(); + inline int deviceInfo() { return m_index; } public Q_SLOTS: // set the device name displayed @@ -90,6 +91,7 @@ private slots: void adjustHeight(); private: + int m_index; QTimer *m_refreshTimer; QWidget *m_wirelessApplet; WirelessList *m_APList; diff --git a/plugins/network/networkitem.cpp b/plugins/network/networkitem.cpp index 4ead1d68c..26c52e9f0 100644 --- a/plugins/network/networkitem.cpp +++ b/plugins/network/networkitem.cpp @@ -4,14 +4,11 @@ #include "../../widgets/tipswidget.h" #include "../frame/util/imageutil.h" -#include #include #include #include -DGUI_USE_NAMESPACE - extern const int ItemWidth; extern const int ItemHeight; const int ControlItemHeight = 35; @@ -25,7 +22,6 @@ NetworkItem::NetworkItem(QWidget *parent) : QWidget(parent) , m_tipsWidget(new TipsWidget(this)) , m_applet(new QScrollArea(this)) - , m_line(new HorizontalSeperator(this)) , m_switchWire(true) , m_timer(new QTimer(this)) , m_switchWireTimer(new QTimer(this)) @@ -74,7 +70,7 @@ NetworkItem::NetworkItem(QWidget *parent) auto centralWidget = new QWidget(m_applet); auto centralLayout = new QVBoxLayout; - centralLayout->setMargin(0); + centralLayout->setContentsMargins(QMargins(10, 0, 10, 0)); centralLayout->setSpacing(0); centralLayout->addWidget(m_wirelessControlPanel); centralLayout->addLayout(m_wirelessLayout); @@ -93,12 +89,13 @@ NetworkItem::NetworkItem(QWidget *parent) m_applet->viewport()->setAutoFillBackground(false); m_applet->setVisible(false); - connect(m_switchWireTimer, &QTimer::timeout, [=]{ + connect(m_switchWireTimer, &QTimer::timeout, [ = ] { m_switchWire = !m_switchWire; }); connect(m_timer, &QTimer::timeout, this, &NetworkItem::refreshIcon); - connect(m_switchWiredBtn, &DSwitchButton::checkedChanged, this, &NetworkItem::wiredsEnable); - connect(m_switchWirelessBtn, &DSwitchButton::checkedChanged, this, &NetworkItem::wirelessEnable); + connect(m_switchWiredBtn, &DSwitchButton::toggled, this, &NetworkItem::wiredsEnable); + connect(m_switchWirelessBtn, &DSwitchButton::toggled, this, &NetworkItem::wirelessEnable); + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &NetworkItem::onThemeTypeChanged); } QWidget *NetworkItem::itemApplet() @@ -114,19 +111,19 @@ QWidget *NetworkItem::itemTips() void NetworkItem::updateDeviceItems(QMap &wiredItems, QMap &wirelessItems) { + // 已有设备不重复进行增删操作 auto tempWiredItems = m_wiredItems; auto tempWirelessItems = m_wirelessItems; - int wirelessItemCount = m_wirelessItems.size(); - int index = 0; for (auto wirelessItem : wirelessItems) { if (wirelessItem) { auto path = wirelessItem->path(); - if (m_wiredItems.contains(path)) { + if (m_wirelessItems.contains(path)) { + m_wirelessItems.value(path)->setDeviceInfo(wirelessItem->deviceInfo()); tempWirelessItems.remove(path); + delete wirelessItem; } else { wirelessItem->setParent(this); - wirelessItem->setDeviceInfo(wirelessItemCount == 1 ? -1 : ++index); m_wirelessItems.insert(path, wirelessItem); } } @@ -136,10 +133,14 @@ void NetworkItem::updateDeviceItems(QMap &wiredItems, QMap if (wiredItem) { auto path = wiredItem->path(); if (m_wiredItems.contains(path)) { + m_wiredItems.value(path)->setTitle(wiredItem->deviceName()); tempWiredItems.remove(path); + delete wiredItem; } else { wiredItem->setParent(this); m_wiredItems.insert(path, wiredItem); + wiredItem->setVisible(true); + m_wiredLayout->addWidget(wiredItem); } } } @@ -149,6 +150,7 @@ void NetworkItem::updateDeviceItems(QMap &wiredItems, QMap auto path = wirelessItem->device()->path(); m_wirelessItems.remove(path); m_connectedWirelessDevice.remove(path); + wirelessItem->itemApplet()->setVisible(false); m_wirelessLayout->removeWidget(wirelessItem->itemApplet()); delete wirelessItem; } @@ -158,6 +160,7 @@ void NetworkItem::updateDeviceItems(QMap &wiredItems, QMap auto path = wiredItem->device()->path(); m_wiredItems.remove(path); m_connectedWiredDevice.remove(path); + wiredItem->setVisible(false); m_wiredLayout->removeWidget(wiredItem); delete wiredItem; } @@ -172,7 +175,6 @@ const QString NetworkItem::contextMenu() const if (m_wirelessItems.size() && m_wiredItems.size()) { items.reserve(3); - // 待文案 QMap wireEnable; wireEnable["itemId"] = MenueWiredEnable; if (m_switchWiredBtnState) @@ -229,12 +231,12 @@ void NetworkItem::invokeMenuItem(const QString &menuId, const bool checked) wirelessEnable(!m_switchWirelessBtnState); else if (menuId == MenueSettings) DDBusSender() - .service("com.deepin.dde.ControlCenter") - .interface("com.deepin.dde.ControlCenter") - .path("/com/deepin/dde/ControlCenter") - .method(QString("ShowModule")) - .arg(QString("network")) - .call(); + .service("com.deepin.dde.ControlCenter") + .interface("com.deepin.dde.ControlCenter") + .path("/com/deepin/dde/ControlCenter") + .method(QString("ShowModule")) + .arg(QString("network")) + .call(); } void NetworkItem::refreshIcon() @@ -312,7 +314,7 @@ void NetworkItem::refreshIcon() return; } } - case Aconnecting:{ + case Aconnecting: { m_timer->start(); strength = QTime::currentTime().msec() / 10 % 100; if (strength == 100) { @@ -372,30 +374,6 @@ void NetworkItem::refreshIcon() update(); } -void NetworkItem::deviceDel() -{ - auto wiredDevice = qobject_cast(sender()); - if (!wiredDevice) - return; - auto path = wiredDevice->path(); - - auto wirelessItem = m_wirelessItems.value(path); - if (wirelessItem) { - m_wirelessItems.remove(path); - m_wirelessLayout->removeWidget(wirelessItem->itemApplet()); - delete wirelessItem; - } - - auto wiredItem = m_wiredItems.value(path); - if (wiredItem) { - m_wiredItems.remove(path); - m_wiredLayout->removeWidget(wiredItem); - delete wiredItem; - } - - updateSelf(); -} - void NetworkItem::resizeEvent(QResizeEvent *e) { QWidget::resizeEvent(e); @@ -429,12 +407,9 @@ void NetworkItem::wiredsEnable(bool enable) for (auto wiredItem : m_wiredItems) { if (wiredItem) { wiredItem->setDeviceEnabled(enable); - enable ? m_wiredLayout->addWidget(wiredItem) - : m_wiredLayout->removeWidget(wiredItem); - wiredItem->setVisible(enable); } } - updateSelf(); +// updateSelf(); } void NetworkItem::wirelessEnable(bool enable) @@ -443,13 +418,20 @@ void NetworkItem::wirelessEnable(bool enable) if (wirelessItem) { wirelessItem->setDeviceEnabled(enable); enable ? m_wirelessLayout->addWidget(wirelessItem->itemApplet()) - : m_wirelessLayout->removeWidget(wirelessItem->itemApplet()); + : m_wirelessLayout->removeWidget(wirelessItem->itemApplet()); wirelessItem->itemApplet()->setVisible(enable); } } updateSelf(); } +void NetworkItem::onThemeTypeChanged(DGuiApplicationHelper::ColorType themeType) +{ + for (auto wiredItem : m_wiredItems) { + wiredItem->setThemeType(themeType); + } +} + void NetworkItem::getPluginState() { int wiredState = 0; @@ -962,7 +944,8 @@ void NetworkItem::updateView() if (m_switchWirelessBtnState) { for (auto wirelessItem : m_wirelessItems) { if (wirelessItem) { - itemCount += wirelessItem->APcount(); + if (wirelessItem->device()->enabled()) + itemCount += wirelessItem->APcount(); // 单个设备开关控制项 itemCount++; } @@ -974,30 +957,26 @@ void NetworkItem::updateView() contentHeight += m_wirelessControlPanel->height(); m_wirelessControlPanel->setVisible(wirelessDeviceCnt); - int wiredItemsCount = 0; - if (m_switchWiredBtnState) { - wiredItemsCount = m_wiredItems.size(); - } auto wiredDeviceCnt = m_wiredItems.size(); if (wiredDeviceCnt) contentHeight += m_wiredControlPanel->height(); m_wiredControlPanel->setVisible(wiredDeviceCnt); - itemCount += wiredItemsCount; + itemCount += wiredDeviceCnt; // 分割线 都有设备时才有 - auto hasDevice = wirelessDeviceCnt && wiredDeviceCnt; - m_line->setVisible(hasDevice); +// auto hasDevice = wirelessDeviceCnt && wiredDeviceCnt; +// m_line->setVisible(hasDevice); auto centralWidget = m_applet->widget(); if (itemCount <= constDisplayItemCnt) { - contentHeight += (itemCount - wiredItemsCount) * ItemHeight; - contentHeight += wiredItemsCount * ItemHeight; + contentHeight += (itemCount - wiredDeviceCnt) * ItemHeight; + contentHeight += wiredDeviceCnt * ItemHeight; centralWidget->setFixedHeight(contentHeight); m_applet->setFixedHeight(contentHeight); } else { - contentHeight += (itemCount - wiredItemsCount) * ItemHeight; - contentHeight += wiredItemsCount * ItemHeight; + contentHeight += (itemCount - wiredDeviceCnt) * ItemHeight; + contentHeight += wiredDeviceCnt * ItemHeight; centralWidget->setFixedHeight(contentHeight); m_applet->setFixedHeight(constDisplayItemCnt * ItemHeight); m_applet->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); @@ -1032,7 +1011,10 @@ void NetworkItem::updateMasterControlSwitch() bool deviceState = false; for (auto wirelessItem : m_wirelessItems) { if (wirelessItem) - deviceState |= wirelessItem->deviceActivated(); + if (wirelessItem->deviceEanbled()) { + deviceState = true; + break; + } } m_switchWirelessBtn->blockSignals(true); m_switchWirelessBtn->setChecked(deviceState); @@ -1057,27 +1039,14 @@ void NetworkItem::updateMasterControlSwitch() deviceState = false; for (auto wiredItem : m_wiredItems) { if (wiredItem) - deviceState |= wiredItem->deviceActivated(); + if (wiredItem->deviceEabled()) { + deviceState = true; + break; + } } m_switchWiredBtn->blockSignals(true); m_switchWiredBtn->setChecked(deviceState); m_switchWiredBtn->blockSignals(false); - if (deviceState) { - for (auto wiredItem : m_wiredItems) { - if (wiredItem) { - wiredItem->setVisible(true); - m_wiredLayout->addWidget(wiredItem); - } - - } - } else { - for (auto wiredItem : m_wiredItems) { - if (wiredItem) { - wiredItem->setVisible(false); - m_wiredLayout->removeWidget(wiredItem); - } - } - } m_switchWiredBtnState = deviceState; } @@ -1116,7 +1085,7 @@ void NetworkItem::refreshTips() strTips.chop(1); m_tipsWidget->setText(strTips); } - break; + break; case Aconnected: { QString strTips; for (auto wirelessItem : m_connectedWirelessDevice) { @@ -1133,7 +1102,7 @@ void NetworkItem::refreshTips() strTips.chop(1); m_tipsWidget->setText(strTips); } - break; + break; case Bconnected: { QString strTips; for (auto wiredItem : m_connectedWiredDevice) { @@ -1150,7 +1119,7 @@ void NetworkItem::refreshTips() strTips.chop(1); m_tipsWidget->setText(strTips); } - break; + break; case Disconnected: case Adisconnected: case Bdisconnected: diff --git a/plugins/network/networkitem.h b/plugins/network/networkitem.h index 81356a40f..46252894d 100644 --- a/plugins/network/networkitem.h +++ b/plugins/network/networkitem.h @@ -1,6 +1,7 @@ #ifndef NETWORKITEM_H #define NETWORKITEM_H +#include #include #include @@ -8,6 +9,7 @@ #include #include +DGUI_USE_NAMESPACE DWIDGET_USE_NAMESPACE class PluginState; @@ -58,7 +60,6 @@ public: void refreshTips(); public slots: - void deviceDel(); void updateSelf(); void refreshIcon(); @@ -69,6 +70,7 @@ protected: private slots: void wiredsEnable(bool enable); void wirelessEnable(bool enable); + void onThemeTypeChanged(DGuiApplicationHelper::ColorType themeType); private: void getPluginState(); @@ -86,7 +88,7 @@ private: QWidget *m_wiredControlPanel; bool m_switchWiredBtnState; - HorizontalSeperator *m_line; +// HorizontalSeperator *m_line; QLabel *m_wirelessTitle; DSwitchButton *m_switchWirelessBtn; diff --git a/plugins/network/networkplugin.cpp b/plugins/network/networkplugin.cpp index 2d497fddd..731eb7986 100644 --- a/plugins/network/networkplugin.cpp +++ b/plugins/network/networkplugin.cpp @@ -164,20 +164,42 @@ void NetworkPlugin::onDeviceListChanged(const QList devices) QMap wirelessItems; QMap wiredItems; + int wiredDeviceCnt = 0; + int wirelessDeviceCnt = 0; + for (auto device : devices) { + if (device && device->type() == NetworkDevice::Wired) + wiredDeviceCnt++; + else + wirelessDeviceCnt++; + } + + // 编号 (与控制中心有线设备保持一致命名) + int wiredNum = 0; + int wirelessNum = 0; + QString text; + for (auto device : devices) { const QString &path = device->path(); // new device DeviceItem *item = nullptr; switch (device->type()) { case NetworkDevice::Wired: - item = new WiredItem(static_cast(device)); + wiredNum++; + if (wiredDeviceCnt == 1) + text = tr("Wired Network"); + else + text = tr("Wired Network %1").arg(wiredNum); + item = new WiredItem(static_cast(device), text); wiredItems.insert(path, static_cast(item)); connect(static_cast(item), &WiredItem::wiredStateChanged, m_networkItem, &NetworkItem::updateSelf); + connect(static_cast(item), &WiredItem::enableChanged, + m_networkItem, &NetworkItem::updateSelf); break; case NetworkDevice::Wireless: item = new WirelessItem(static_cast(device)); + static_cast(item)->setDeviceInfo(wirelessDeviceCnt == 1 ? -1 : ++wirelessNum); wirelessItems.insert(path, static_cast(item)); connect(static_cast(item), &WirelessItem::queryActiveConnInfo, @@ -207,8 +229,6 @@ void NetworkPlugin::onDeviceListChanged(const QList devices) Q_UNREACHABLE(); } - connect(device, &dde::network::NetworkDevice::removed, - m_networkItem, &NetworkItem::deviceDel); connect(item, &DeviceItem::requestSetDeviceEnable, m_networkWorker, &NetworkWorker::setDeviceEnable); connect(m_networkModel, &NetworkModel::connectivityChanged, m_networkItem, &NetworkItem::updateSelf); } diff --git a/translations/dde-dock_zh_CN.ts b/translations/dde-dock_zh_CN.ts index a96860c58..ebcd00c42 100644 --- a/translations/dde-dock_zh_CN.ts +++ b/translations/dde-dock_zh_CN.ts @@ -171,6 +171,14 @@ Network 网络 + + Wired Network + 有线网络 + + + Wired Network %1 + 有线网络%1 + OnboardPlugin