fix(network):Abnormal hot swap of wired network

有线网络热插拔异常 bug:20058

(cherry picked from commit 9ddcdfbefbeffa7b8c89a584002451c970b448f7)
This commit is contained in:
“fanpengcheng_cm” 2020-04-18 17:29:45 +08:00 committed by fpc_diesel
parent 068b3e028b
commit 0231f82a01
11 changed files with 188 additions and 162 deletions

View File

@ -38,6 +38,9 @@ using namespace dde::network;
DWIDGET_USE_NAMESPACE DWIDGET_USE_NAMESPACE
DGUI_USE_NAMESPACE DGUI_USE_NAMESPACE
extern const QString DarkType;
extern const QString LightType;
AccessPointWidget::AccessPointWidget() AccessPointWidget::AccessPointWidget()
: QFrame(nullptr) : QFrame(nullptr)
, m_activeState(NetworkDevice::Unknow) , m_activeState(NetworkDevice::Unknow)
@ -52,12 +55,17 @@ AccessPointWidget::AccessPointWidget()
m_ssidBtn->setObjectName("Ssid"); m_ssidBtn->setObjectName("Ssid");
// m_disconnectBtn->setVisible(false); // m_disconnectBtn->setVisible(false);
auto iconPix = Utils::renderSVG(":/common/resources/common/list_select@2x.png", bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType);
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); m_stateButton->setPixmap(iconPix);
m_stateButton->setVisible(false); 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_securityIconSize = m_securityPixmap.size();
m_securityLabel->setPixmap(m_securityPixmap); m_securityLabel->setPixmap(m_securityPixmap);
m_securityLabel->setFixedSize(m_securityIconSize / devicePixelRatioF()); m_securityLabel->setFixedSize(m_securityIconSize / devicePixelRatioF());
@ -188,9 +196,12 @@ void AccessPointWidget::setStrengthIcon(const int strength)
m_securityPixmap.setDevicePixelRatio(devicePixelRatioF()); m_securityPixmap.setDevicePixelRatio(devicePixelRatioF());
m_securityLabel->setPixmap(m_securityPixmap); m_securityLabel->setPixmap(m_securityPixmap);
// m_disconnectBtn->setNormalPic(isLight ? ":/wireless/resources/wireless/select_dark.svg" : ":/wireless/resources/wireless/select.svg"); if (NetworkDevice::Activated == m_activeState) {
// m_disconnectBtn->setHoverPic(isLight ? ":/wireless/resources/wireless/disconnect_dark.svg" : ":/wireless/resources/wireless/disconnect.svg"); auto pixpath = QString(":/wireless/resources/wireless/select");
// m_disconnectBtn->setPressPic(isLight ? ":/wireless/resources/wireless/disconnect_dark.svg" : ":/wireless/resources/wireless/disconnect.svg"); 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() void AccessPointWidget::ssidClicked()
@ -210,18 +221,22 @@ void AccessPointWidget::disconnectBtnClicked()
void AccessPointWidget::buttonEnter() void AccessPointWidget::buttonEnter()
{ {
bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType);
if (NetworkDevice::Activated == m_activeState) { if (NetworkDevice::Activated == m_activeState) {
auto iconPix = Utils::renderSVG(":/common/resources/common/notify_close_press@2x.png", auto pixpath = QString(":/wireless/resources/wireless/disconnect");
QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); 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->setPixmap(iconPix);
} }
} }
void AccessPointWidget::buttonLeave() void AccessPointWidget::buttonLeave()
{ {
bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType);
if (NetworkDevice::Activated == m_activeState) { if (NetworkDevice::Activated == m_activeState) {
auto iconPix = Utils::renderSVG(":/common/resources/common/list_select@2x.png", auto pixpath = QString(":/wireless/resources/wireless/select");
QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); 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->setPixmap(iconPix);
} }
} }

View File

@ -38,7 +38,7 @@ extern const int ItemHeight = 30;
DeviceControlWidget::DeviceControlWidget(QWidget *parent) DeviceControlWidget::DeviceControlWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
m_deviceName = new TipsWidget; m_deviceName = new QLabel(this);
m_deviceName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); m_deviceName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_switchBtn = new DSwitchButton; m_switchBtn = new DSwitchButton;
@ -116,7 +116,7 @@ void DeviceControlWidget::refreshNetwork()
m_loadingIndicator->setLoading(true); m_loadingIndicator->setLoading(true);
QTimer::singleShot(1000, this, [=] { QTimer::singleShot(1000, this, [ = ] {
m_loadingIndicator->setLoading(false); m_loadingIndicator->setLoading(false);
}); });
} }

View File

@ -54,7 +54,7 @@ private slots:
void refreshNetwork(); void refreshNetwork();
private: private:
TipsWidget *m_deviceName; QLabel *m_deviceName;
Dtk::Widget::DSwitchButton *m_switchBtn; Dtk::Widget::DSwitchButton *m_switchBtn;
// HorizontalSeperator *m_seperator; // HorizontalSeperator *m_seperator;
DLoadingIndicator *m_loadingIndicator; DLoadingIndicator *m_loadingIndicator;

View File

@ -31,9 +31,12 @@
DGUI_USE_NAMESPACE DGUI_USE_NAMESPACE
const int ItemHeight = 30; 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) : DeviceItem(device, parent)
, m_deviceName(deviceName)
, m_connectedName(new QLabel(this)) , m_connectedName(new QLabel(this))
, m_wiredIcon(new QLabel(this)) , m_wiredIcon(new QLabel(this))
, m_stateButton(new StateLabel(this)) , m_stateButton(new StateLabel(this))
@ -43,12 +46,16 @@ WiredItem::WiredItem(WiredDevice *device, QWidget *parent)
setFixedHeight(ItemHeight); setFixedHeight(ItemHeight);
// m_connectedName->setVisible(false); // m_connectedName->setVisible(false);
auto iconPix = Utils::renderSVG(":/wired/resources/wired/network-wired-symbolic-dark.svg", bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType);
QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF());
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->setPixmap(iconPix);
m_wiredIcon->setVisible(false); m_wiredIcon->setVisible(false);
iconPix = Utils::renderSVG(":/common/resources/common/list_select@2x.png", pixpath = QString(":/wireless/resources/wireless/select");
QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); 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->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
m_stateButton->setPixmap(iconPix); m_stateButton->setPixmap(iconPix);
m_stateButton->setVisible(false); m_stateButton->setVisible(false);
@ -56,6 +63,8 @@ WiredItem::WiredItem(WiredDevice *device, QWidget *parent)
m_loadingStat->setVisible(false); m_loadingStat->setVisible(false);
// m_line->setVisible(false); // m_line->setVisible(false);
m_connectedName->setText(m_deviceName);
auto connectionLayout = new QVBoxLayout(this); auto connectionLayout = new QVBoxLayout(this);
connectionLayout->setMargin(0); connectionLayout->setMargin(0);
connectionLayout->setSpacing(0); connectionLayout->setSpacing(0);
@ -73,6 +82,8 @@ WiredItem::WiredItem(WiredDevice *device, QWidget *parent)
connectionLayout->addLayout(itemLayout); connectionLayout->addLayout(itemLayout);
setLayout(connectionLayout); setLayout(connectionLayout);
connect(m_device, static_cast<void (NetworkDevice::*)(const bool) const>(&NetworkDevice::enableChanged),
this, &WiredItem::enableChanged);
connect(m_device, static_cast<void (NetworkDevice::*)(NetworkDevice::DeviceStatus) const>(&NetworkDevice::statusChanged), connect(m_device, static_cast<void (NetworkDevice::*)(NetworkDevice::DeviceStatus) const>(&NetworkDevice::statusChanged),
this, &WiredItem::deviceStateChanged); this, &WiredItem::deviceStateChanged);
@ -89,30 +100,16 @@ WiredItem::WiredItem(WiredDevice *device, QWidget *parent)
deviceStateChanged(m_device->status()); deviceStateChanged(m_device->status());
} }
bool WiredItem::deviceActivated() void WiredItem::setTitle(const QString &name)
{ {
switch (m_device->status()) { if (m_device->status() != NetworkDevice::Activated)
case NetworkDevice::Unknow: m_connectedName->setText(name);
case NetworkDevice::Unmanaged: m_deviceName = name;
case NetworkDevice::Unavailable: { }
return false;
} bool WiredItem::deviceEabled()
case NetworkDevice::Disconnected: {
case NetworkDevice::Deactivation: return m_device->enabled();
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;
}
}
} }
void WiredItem::setDeviceEnabled(bool enabled) void WiredItem::setDeviceEnabled(bool enabled)
@ -155,9 +152,27 @@ QJsonObject WiredItem::getActiveWiredConnectionInfo()
return static_cast<WiredDevice *>(m_device.data())->activeWiredConnectionInfo(); return static_cast<WiredDevice *>(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) void WiredItem::deviceStateChanged(NetworkDevice::DeviceStatus state)
{ {
emit wiredState(state);
QPixmap iconPix; QPixmap iconPix;
switch (state) { switch (state) {
case NetworkDevice::Unknow: case NetworkDevice::Unknow:
@ -169,6 +184,8 @@ void WiredItem::deviceStateChanged(NetworkDevice::DeviceStatus state)
m_loadingStat->stop(); m_loadingStat->stop();
m_loadingStat->hide(); m_loadingStat->hide();
m_loadingStat->setVisible(false); m_loadingStat->setVisible(false);
if (!m_device->enabled())
m_stateButton->setVisible(false);
} }
break; break;
case NetworkDevice::Prepare: case NetworkDevice::Prepare:
@ -197,6 +214,9 @@ void WiredItem::deviceStateChanged(NetworkDevice::DeviceStatus state)
void WiredItem::changedActiveWiredConnectionInfo(const QJsonObject &connInfo) void WiredItem::changedActiveWiredConnectionInfo(const QJsonObject &connInfo)
{ {
if (connInfo.isEmpty())
m_stateButton->setVisible(false);
auto strTitle = connInfo.value("ConnectionName").toString(); auto strTitle = connInfo.value("ConnectionName").toString();
m_connectedName->setText(strTitle); m_connectedName->setText(strTitle);
QFontMetrics fontMetrics(m_connectedName->font()); QFontMetrics fontMetrics(m_connectedName->font());
@ -205,7 +225,7 @@ void WiredItem::changedActiveWiredConnectionInfo(const QJsonObject &connInfo)
} }
if (strTitle.isEmpty()) if (strTitle.isEmpty())
m_connectedName->setText(m_device->usingHwAdr()); m_connectedName->setText(m_deviceName);
else else
m_connectedName->setText(strTitle); m_connectedName->setText(strTitle);
} }
@ -213,9 +233,11 @@ void WiredItem::changedActiveWiredConnectionInfo(const QJsonObject &connInfo)
void WiredItem::buttonEnter() void WiredItem::buttonEnter()
{ {
if (m_device) { if (m_device) {
bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType);
if (NetworkDevice::Activated == m_device->status()) { if (NetworkDevice::Activated == m_device->status()) {
auto iconPix = Utils::renderSVG(":/common/resources/common/notify_close_press@2x.png", auto pixpath = QString(":/wireless/resources/wireless/disconnect");
QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); 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->setPixmap(iconPix);
} }
} }
@ -224,9 +246,11 @@ void WiredItem::buttonEnter()
void WiredItem::buttonLeave() void WiredItem::buttonLeave()
{ {
if (m_device) { if (m_device) {
bool isLight = (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType);
if (NetworkDevice::Activated == m_device->status()) { if (NetworkDevice::Activated == m_device->status()) {
auto iconPix = Utils::renderSVG(":/common/resources/common/list_select@2x.png", auto pixpath = QString(":/wireless/resources/wireless/select");
QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), devicePixelRatioF()); 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->setPixmap(iconPix);
} }
} }

View File

@ -25,12 +25,14 @@
#include "deviceitem.h" #include "deviceitem.h"
#include <WiredDevice> #include <WiredDevice>
#include <DGuiApplicationHelper>
#include <DSpinner> #include <DSpinner>
#include <QLabel> #include <QLabel>
#include <QVBoxLayout> #include <QVBoxLayout>
using namespace dde::network; using namespace dde::network;
DGUI_USE_NAMESPACE
DWIDGET_USE_NAMESPACE DWIDGET_USE_NAMESPACE
class TipsWidget; class TipsWidget;
@ -59,17 +61,19 @@ public:
Q_ENUM(WiredStatus) Q_ENUM(WiredStatus)
public: public:
explicit WiredItem(dde::network::WiredDevice *device, QWidget *parent = nullptr); explicit WiredItem(dde::network::WiredDevice *device, const QString &deviceName, QWidget *parent = nullptr);
inline void setTitle(const QString &name) { m_connectedName->setText(name); } void setTitle(const QString &name);
bool deviceActivated(); bool deviceEabled();
void setDeviceEnabled(bool enabled); void setDeviceEnabled(bool enabled);
WiredStatus getDeviceState(); WiredStatus getDeviceState();
QJsonObject getActiveWiredConnectionInfo(); QJsonObject getActiveWiredConnectionInfo();
inline QString &deviceName() { return m_deviceName; }
void setThemeType(DGuiApplicationHelper::ColorType themeType);
signals: signals:
void requestActiveConnection(const QString &devPath, const QString &uuid); void requestActiveConnection(const QString &devPath, const QString &uuid);
void wiredState(NetworkDevice::DeviceStatus state);
void wiredStateChanged(); void wiredStateChanged();
void enableChanged();
private slots: private slots:
void deviceStateChanged(NetworkDevice::DeviceStatus state); void deviceStateChanged(NetworkDevice::DeviceStatus state);
@ -78,10 +82,12 @@ private slots:
void buttonLeave(); void buttonLeave();
private: private:
QString m_deviceName;
QLabel *m_connectedName; QLabel *m_connectedName;
QLabel *m_wiredIcon; QLabel *m_wiredIcon;
StateLabel *m_stateButton; StateLabel *m_stateButton;
DSpinner *m_loadingStat; DSpinner *m_loadingStat;
// HorizontalSeperator *m_line; // HorizontalSeperator *m_line;
}; };

View File

@ -89,30 +89,9 @@ int WirelessItem::APcount()
return m_APList->APcount(); return m_APList->APcount();
} }
bool WirelessItem::deviceActivated() bool WirelessItem::deviceEanbled()
{ {
switch (m_device->status()) { return m_device->enabled();
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;
}
}
} }
void WirelessItem::setDeviceEnabled(bool enable) void WirelessItem::setDeviceEnabled(bool enable)
@ -163,6 +142,7 @@ QJsonObject WirelessItem::getActiveWirelessConnectionInfo()
void WirelessItem::setDeviceInfo(const int index) void WirelessItem::setDeviceInfo(const int index)
{ {
m_APList->setDeviceInfo(index); m_APList->setDeviceInfo(index);
m_index = index;
} }
bool WirelessItem::eventFilter(QObject *o, QEvent *e) bool WirelessItem::eventFilter(QObject *o, QEvent *e)

View File

@ -60,11 +60,12 @@ public:
QWidget *itemApplet(); QWidget *itemApplet();
int APcount(); int APcount();
bool deviceActivated(); bool deviceEanbled();
void setDeviceEnabled(bool enable); void setDeviceEnabled(bool enable);
WirelessStatus getDeviceState(); WirelessStatus getDeviceState();
QJsonObject &getConnectedApInfo(); QJsonObject &getConnectedApInfo();
QJsonObject getActiveWirelessConnectionInfo(); QJsonObject getActiveWirelessConnectionInfo();
inline int deviceInfo() { return m_index; }
public Q_SLOTS: public Q_SLOTS:
// set the device name displayed // set the device name displayed
@ -90,6 +91,7 @@ private slots:
void adjustHeight(); void adjustHeight();
private: private:
int m_index;
QTimer *m_refreshTimer; QTimer *m_refreshTimer;
QWidget *m_wirelessApplet; QWidget *m_wirelessApplet;
WirelessList *m_APList; WirelessList *m_APList;

View File

@ -4,14 +4,11 @@
#include "../../widgets/tipswidget.h" #include "../../widgets/tipswidget.h"
#include "../frame/util/imageutil.h" #include "../frame/util/imageutil.h"
#include <DGuiApplicationHelper>
#include <DDBusSender> #include <DDBusSender>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QJsonDocument> #include <QJsonDocument>
DGUI_USE_NAMESPACE
extern const int ItemWidth; extern const int ItemWidth;
extern const int ItemHeight; extern const int ItemHeight;
const int ControlItemHeight = 35; const int ControlItemHeight = 35;
@ -25,7 +22,6 @@ NetworkItem::NetworkItem(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, m_tipsWidget(new TipsWidget(this)) , m_tipsWidget(new TipsWidget(this))
, m_applet(new QScrollArea(this)) , m_applet(new QScrollArea(this))
, m_line(new HorizontalSeperator(this))
, m_switchWire(true) , m_switchWire(true)
, m_timer(new QTimer(this)) , m_timer(new QTimer(this))
, m_switchWireTimer(new QTimer(this)) , m_switchWireTimer(new QTimer(this))
@ -74,7 +70,7 @@ NetworkItem::NetworkItem(QWidget *parent)
auto centralWidget = new QWidget(m_applet); auto centralWidget = new QWidget(m_applet);
auto centralLayout = new QVBoxLayout; auto centralLayout = new QVBoxLayout;
centralLayout->setMargin(0); centralLayout->setContentsMargins(QMargins(10, 0, 10, 0));
centralLayout->setSpacing(0); centralLayout->setSpacing(0);
centralLayout->addWidget(m_wirelessControlPanel); centralLayout->addWidget(m_wirelessControlPanel);
centralLayout->addLayout(m_wirelessLayout); centralLayout->addLayout(m_wirelessLayout);
@ -93,12 +89,13 @@ NetworkItem::NetworkItem(QWidget *parent)
m_applet->viewport()->setAutoFillBackground(false); m_applet->viewport()->setAutoFillBackground(false);
m_applet->setVisible(false); m_applet->setVisible(false);
connect(m_switchWireTimer, &QTimer::timeout, [=]{ connect(m_switchWireTimer, &QTimer::timeout, [ = ] {
m_switchWire = !m_switchWire; m_switchWire = !m_switchWire;
}); });
connect(m_timer, &QTimer::timeout, this, &NetworkItem::refreshIcon); connect(m_timer, &QTimer::timeout, this, &NetworkItem::refreshIcon);
connect(m_switchWiredBtn, &DSwitchButton::checkedChanged, this, &NetworkItem::wiredsEnable); connect(m_switchWiredBtn, &DSwitchButton::toggled, this, &NetworkItem::wiredsEnable);
connect(m_switchWirelessBtn, &DSwitchButton::checkedChanged, this, &NetworkItem::wirelessEnable); connect(m_switchWirelessBtn, &DSwitchButton::toggled, this, &NetworkItem::wirelessEnable);
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &NetworkItem::onThemeTypeChanged);
} }
QWidget *NetworkItem::itemApplet() QWidget *NetworkItem::itemApplet()
@ -114,19 +111,19 @@ QWidget *NetworkItem::itemTips()
void NetworkItem::updateDeviceItems(QMap<QString, WiredItem *> &wiredItems, QMap<QString, WirelessItem *> &wirelessItems) void NetworkItem::updateDeviceItems(QMap<QString, WiredItem *> &wiredItems, QMap<QString, WirelessItem *> &wirelessItems)
{ {
// 已有设备不重复进行增删操作
auto tempWiredItems = m_wiredItems; auto tempWiredItems = m_wiredItems;
auto tempWirelessItems = m_wirelessItems; auto tempWirelessItems = m_wirelessItems;
int wirelessItemCount = m_wirelessItems.size();
int index = 0;
for (auto wirelessItem : wirelessItems) { for (auto wirelessItem : wirelessItems) {
if (wirelessItem) { if (wirelessItem) {
auto path = wirelessItem->path(); auto path = wirelessItem->path();
if (m_wiredItems.contains(path)) { if (m_wirelessItems.contains(path)) {
m_wirelessItems.value(path)->setDeviceInfo(wirelessItem->deviceInfo());
tempWirelessItems.remove(path); tempWirelessItems.remove(path);
delete wirelessItem;
} else { } else {
wirelessItem->setParent(this); wirelessItem->setParent(this);
wirelessItem->setDeviceInfo(wirelessItemCount == 1 ? -1 : ++index);
m_wirelessItems.insert(path, wirelessItem); m_wirelessItems.insert(path, wirelessItem);
} }
} }
@ -136,10 +133,14 @@ void NetworkItem::updateDeviceItems(QMap<QString, WiredItem *> &wiredItems, QMap
if (wiredItem) { if (wiredItem) {
auto path = wiredItem->path(); auto path = wiredItem->path();
if (m_wiredItems.contains(path)) { if (m_wiredItems.contains(path)) {
m_wiredItems.value(path)->setTitle(wiredItem->deviceName());
tempWiredItems.remove(path); tempWiredItems.remove(path);
delete wiredItem;
} else { } else {
wiredItem->setParent(this); wiredItem->setParent(this);
m_wiredItems.insert(path, wiredItem); m_wiredItems.insert(path, wiredItem);
wiredItem->setVisible(true);
m_wiredLayout->addWidget(wiredItem);
} }
} }
} }
@ -149,6 +150,7 @@ void NetworkItem::updateDeviceItems(QMap<QString, WiredItem *> &wiredItems, QMap
auto path = wirelessItem->device()->path(); auto path = wirelessItem->device()->path();
m_wirelessItems.remove(path); m_wirelessItems.remove(path);
m_connectedWirelessDevice.remove(path); m_connectedWirelessDevice.remove(path);
wirelessItem->itemApplet()->setVisible(false);
m_wirelessLayout->removeWidget(wirelessItem->itemApplet()); m_wirelessLayout->removeWidget(wirelessItem->itemApplet());
delete wirelessItem; delete wirelessItem;
} }
@ -158,6 +160,7 @@ void NetworkItem::updateDeviceItems(QMap<QString, WiredItem *> &wiredItems, QMap
auto path = wiredItem->device()->path(); auto path = wiredItem->device()->path();
m_wiredItems.remove(path); m_wiredItems.remove(path);
m_connectedWiredDevice.remove(path); m_connectedWiredDevice.remove(path);
wiredItem->setVisible(false);
m_wiredLayout->removeWidget(wiredItem); m_wiredLayout->removeWidget(wiredItem);
delete wiredItem; delete wiredItem;
} }
@ -172,7 +175,6 @@ const QString NetworkItem::contextMenu() const
if (m_wirelessItems.size() && m_wiredItems.size()) { if (m_wirelessItems.size() && m_wiredItems.size()) {
items.reserve(3); items.reserve(3);
// 待文案
QMap<QString, QVariant> wireEnable; QMap<QString, QVariant> wireEnable;
wireEnable["itemId"] = MenueWiredEnable; wireEnable["itemId"] = MenueWiredEnable;
if (m_switchWiredBtnState) if (m_switchWiredBtnState)
@ -229,12 +231,12 @@ void NetworkItem::invokeMenuItem(const QString &menuId, const bool checked)
wirelessEnable(!m_switchWirelessBtnState); wirelessEnable(!m_switchWirelessBtnState);
else if (menuId == MenueSettings) else if (menuId == MenueSettings)
DDBusSender() DDBusSender()
.service("com.deepin.dde.ControlCenter") .service("com.deepin.dde.ControlCenter")
.interface("com.deepin.dde.ControlCenter") .interface("com.deepin.dde.ControlCenter")
.path("/com/deepin/dde/ControlCenter") .path("/com/deepin/dde/ControlCenter")
.method(QString("ShowModule")) .method(QString("ShowModule"))
.arg(QString("network")) .arg(QString("network"))
.call(); .call();
} }
void NetworkItem::refreshIcon() void NetworkItem::refreshIcon()
@ -312,7 +314,7 @@ void NetworkItem::refreshIcon()
return; return;
} }
} }
case Aconnecting:{ case Aconnecting: {
m_timer->start(); m_timer->start();
strength = QTime::currentTime().msec() / 10 % 100; strength = QTime::currentTime().msec() / 10 % 100;
if (strength == 100) { if (strength == 100) {
@ -372,30 +374,6 @@ void NetworkItem::refreshIcon()
update(); update();
} }
void NetworkItem::deviceDel()
{
auto wiredDevice = qobject_cast<WiredDevice *>(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) void NetworkItem::resizeEvent(QResizeEvent *e)
{ {
QWidget::resizeEvent(e); QWidget::resizeEvent(e);
@ -429,12 +407,9 @@ void NetworkItem::wiredsEnable(bool enable)
for (auto wiredItem : m_wiredItems) { for (auto wiredItem : m_wiredItems) {
if (wiredItem) { if (wiredItem) {
wiredItem->setDeviceEnabled(enable); wiredItem->setDeviceEnabled(enable);
enable ? m_wiredLayout->addWidget(wiredItem)
: m_wiredLayout->removeWidget(wiredItem);
wiredItem->setVisible(enable);
} }
} }
updateSelf(); // updateSelf();
} }
void NetworkItem::wirelessEnable(bool enable) void NetworkItem::wirelessEnable(bool enable)
@ -443,13 +418,20 @@ void NetworkItem::wirelessEnable(bool enable)
if (wirelessItem) { if (wirelessItem) {
wirelessItem->setDeviceEnabled(enable); wirelessItem->setDeviceEnabled(enable);
enable ? m_wirelessLayout->addWidget(wirelessItem->itemApplet()) enable ? m_wirelessLayout->addWidget(wirelessItem->itemApplet())
: m_wirelessLayout->removeWidget(wirelessItem->itemApplet()); : m_wirelessLayout->removeWidget(wirelessItem->itemApplet());
wirelessItem->itemApplet()->setVisible(enable); wirelessItem->itemApplet()->setVisible(enable);
} }
} }
updateSelf(); updateSelf();
} }
void NetworkItem::onThemeTypeChanged(DGuiApplicationHelper::ColorType themeType)
{
for (auto wiredItem : m_wiredItems) {
wiredItem->setThemeType(themeType);
}
}
void NetworkItem::getPluginState() void NetworkItem::getPluginState()
{ {
int wiredState = 0; int wiredState = 0;
@ -962,7 +944,8 @@ void NetworkItem::updateView()
if (m_switchWirelessBtnState) { if (m_switchWirelessBtnState) {
for (auto wirelessItem : m_wirelessItems) { for (auto wirelessItem : m_wirelessItems) {
if (wirelessItem) { if (wirelessItem) {
itemCount += wirelessItem->APcount(); if (wirelessItem->device()->enabled())
itemCount += wirelessItem->APcount();
// 单个设备开关控制项 // 单个设备开关控制项
itemCount++; itemCount++;
} }
@ -974,30 +957,26 @@ void NetworkItem::updateView()
contentHeight += m_wirelessControlPanel->height(); contentHeight += m_wirelessControlPanel->height();
m_wirelessControlPanel->setVisible(wirelessDeviceCnt); m_wirelessControlPanel->setVisible(wirelessDeviceCnt);
int wiredItemsCount = 0;
if (m_switchWiredBtnState) {
wiredItemsCount = m_wiredItems.size();
}
auto wiredDeviceCnt = m_wiredItems.size(); auto wiredDeviceCnt = m_wiredItems.size();
if (wiredDeviceCnt) if (wiredDeviceCnt)
contentHeight += m_wiredControlPanel->height(); contentHeight += m_wiredControlPanel->height();
m_wiredControlPanel->setVisible(wiredDeviceCnt); m_wiredControlPanel->setVisible(wiredDeviceCnt);
itemCount += wiredItemsCount; itemCount += wiredDeviceCnt;
// 分割线 都有设备时才有 // 分割线 都有设备时才有
auto hasDevice = wirelessDeviceCnt && wiredDeviceCnt; // auto hasDevice = wirelessDeviceCnt && wiredDeviceCnt;
m_line->setVisible(hasDevice); // m_line->setVisible(hasDevice);
auto centralWidget = m_applet->widget(); auto centralWidget = m_applet->widget();
if (itemCount <= constDisplayItemCnt) { if (itemCount <= constDisplayItemCnt) {
contentHeight += (itemCount - wiredItemsCount) * ItemHeight; contentHeight += (itemCount - wiredDeviceCnt) * ItemHeight;
contentHeight += wiredItemsCount * ItemHeight; contentHeight += wiredDeviceCnt * ItemHeight;
centralWidget->setFixedHeight(contentHeight); centralWidget->setFixedHeight(contentHeight);
m_applet->setFixedHeight(contentHeight); m_applet->setFixedHeight(contentHeight);
} else { } else {
contentHeight += (itemCount - wiredItemsCount) * ItemHeight; contentHeight += (itemCount - wiredDeviceCnt) * ItemHeight;
contentHeight += wiredItemsCount * ItemHeight; contentHeight += wiredDeviceCnt * ItemHeight;
centralWidget->setFixedHeight(contentHeight); centralWidget->setFixedHeight(contentHeight);
m_applet->setFixedHeight(constDisplayItemCnt * ItemHeight); m_applet->setFixedHeight(constDisplayItemCnt * ItemHeight);
m_applet->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); m_applet->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
@ -1032,7 +1011,10 @@ void NetworkItem::updateMasterControlSwitch()
bool deviceState = false; bool deviceState = false;
for (auto wirelessItem : m_wirelessItems) { for (auto wirelessItem : m_wirelessItems) {
if (wirelessItem) if (wirelessItem)
deviceState |= wirelessItem->deviceActivated(); if (wirelessItem->deviceEanbled()) {
deviceState = true;
break;
}
} }
m_switchWirelessBtn->blockSignals(true); m_switchWirelessBtn->blockSignals(true);
m_switchWirelessBtn->setChecked(deviceState); m_switchWirelessBtn->setChecked(deviceState);
@ -1057,27 +1039,14 @@ void NetworkItem::updateMasterControlSwitch()
deviceState = false; deviceState = false;
for (auto wiredItem : m_wiredItems) { for (auto wiredItem : m_wiredItems) {
if (wiredItem) if (wiredItem)
deviceState |= wiredItem->deviceActivated(); if (wiredItem->deviceEabled()) {
deviceState = true;
break;
}
} }
m_switchWiredBtn->blockSignals(true); m_switchWiredBtn->blockSignals(true);
m_switchWiredBtn->setChecked(deviceState); m_switchWiredBtn->setChecked(deviceState);
m_switchWiredBtn->blockSignals(false); 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; m_switchWiredBtnState = deviceState;
} }
@ -1116,7 +1085,7 @@ void NetworkItem::refreshTips()
strTips.chop(1); strTips.chop(1);
m_tipsWidget->setText(strTips); m_tipsWidget->setText(strTips);
} }
break; break;
case Aconnected: { case Aconnected: {
QString strTips; QString strTips;
for (auto wirelessItem : m_connectedWirelessDevice) { for (auto wirelessItem : m_connectedWirelessDevice) {
@ -1133,7 +1102,7 @@ void NetworkItem::refreshTips()
strTips.chop(1); strTips.chop(1);
m_tipsWidget->setText(strTips); m_tipsWidget->setText(strTips);
} }
break; break;
case Bconnected: { case Bconnected: {
QString strTips; QString strTips;
for (auto wiredItem : m_connectedWiredDevice) { for (auto wiredItem : m_connectedWiredDevice) {
@ -1150,7 +1119,7 @@ void NetworkItem::refreshTips()
strTips.chop(1); strTips.chop(1);
m_tipsWidget->setText(strTips); m_tipsWidget->setText(strTips);
} }
break; break;
case Disconnected: case Disconnected:
case Adisconnected: case Adisconnected:
case Bdisconnected: case Bdisconnected:

View File

@ -1,6 +1,7 @@
#ifndef NETWORKITEM_H #ifndef NETWORKITEM_H
#define NETWORKITEM_H #define NETWORKITEM_H
#include <DGuiApplicationHelper>
#include <DSwitchButton> #include <DSwitchButton>
#include <QScrollArea> #include <QScrollArea>
@ -8,6 +9,7 @@
#include <QLabel> #include <QLabel>
#include <QTimer> #include <QTimer>
DGUI_USE_NAMESPACE
DWIDGET_USE_NAMESPACE DWIDGET_USE_NAMESPACE
class PluginState; class PluginState;
@ -58,7 +60,6 @@ public:
void refreshTips(); void refreshTips();
public slots: public slots:
void deviceDel();
void updateSelf(); void updateSelf();
void refreshIcon(); void refreshIcon();
@ -69,6 +70,7 @@ protected:
private slots: private slots:
void wiredsEnable(bool enable); void wiredsEnable(bool enable);
void wirelessEnable(bool enable); void wirelessEnable(bool enable);
void onThemeTypeChanged(DGuiApplicationHelper::ColorType themeType);
private: private:
void getPluginState(); void getPluginState();
@ -86,7 +88,7 @@ private:
QWidget *m_wiredControlPanel; QWidget *m_wiredControlPanel;
bool m_switchWiredBtnState; bool m_switchWiredBtnState;
HorizontalSeperator *m_line; // HorizontalSeperator *m_line;
QLabel *m_wirelessTitle; QLabel *m_wirelessTitle;
DSwitchButton *m_switchWirelessBtn; DSwitchButton *m_switchWirelessBtn;

View File

@ -164,20 +164,42 @@ void NetworkPlugin::onDeviceListChanged(const QList<NetworkDevice *> devices)
QMap<QString, WirelessItem*> wirelessItems; QMap<QString, WirelessItem*> wirelessItems;
QMap<QString, WiredItem *> wiredItems; QMap<QString, WiredItem *> 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) { for (auto device : devices) {
const QString &path = device->path(); const QString &path = device->path();
// new device // new device
DeviceItem *item = nullptr; DeviceItem *item = nullptr;
switch (device->type()) { switch (device->type()) {
case NetworkDevice::Wired: case NetworkDevice::Wired:
item = new WiredItem(static_cast<WiredDevice *>(device)); wiredNum++;
if (wiredDeviceCnt == 1)
text = tr("Wired Network");
else
text = tr("Wired Network %1").arg(wiredNum);
item = new WiredItem(static_cast<WiredDevice *>(device), text);
wiredItems.insert(path, static_cast<WiredItem *>(item)); wiredItems.insert(path, static_cast<WiredItem *>(item));
connect(static_cast<WiredItem *>(item), &WiredItem::wiredStateChanged, connect(static_cast<WiredItem *>(item), &WiredItem::wiredStateChanged,
m_networkItem, &NetworkItem::updateSelf); m_networkItem, &NetworkItem::updateSelf);
connect(static_cast<WiredItem *>(item), &WiredItem::enableChanged,
m_networkItem, &NetworkItem::updateSelf);
break; break;
case NetworkDevice::Wireless: case NetworkDevice::Wireless:
item = new WirelessItem(static_cast<WirelessDevice *>(device)); item = new WirelessItem(static_cast<WirelessDevice *>(device));
static_cast<WirelessItem *>(item)->setDeviceInfo(wirelessDeviceCnt == 1 ? -1 : ++wirelessNum);
wirelessItems.insert(path, static_cast<WirelessItem *>(item)); wirelessItems.insert(path, static_cast<WirelessItem *>(item));
connect(static_cast<WirelessItem *>(item), &WirelessItem::queryActiveConnInfo, connect(static_cast<WirelessItem *>(item), &WirelessItem::queryActiveConnInfo,
@ -207,8 +229,6 @@ void NetworkPlugin::onDeviceListChanged(const QList<NetworkDevice *> devices)
Q_UNREACHABLE(); Q_UNREACHABLE();
} }
connect(device, &dde::network::NetworkDevice::removed,
m_networkItem, &NetworkItem::deviceDel);
connect(item, &DeviceItem::requestSetDeviceEnable, m_networkWorker, &NetworkWorker::setDeviceEnable); connect(item, &DeviceItem::requestSetDeviceEnable, m_networkWorker, &NetworkWorker::setDeviceEnable);
connect(m_networkModel, &NetworkModel::connectivityChanged, m_networkItem, &NetworkItem::updateSelf); connect(m_networkModel, &NetworkModel::connectivityChanged, m_networkItem, &NetworkItem::updateSelf);
} }

View File

@ -171,6 +171,14 @@
<source>Network</source> <source>Network</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Wired Network</source>
<translation>线</translation>
</message>
<message>
<source>Wired Network %1</source>
<translation>线%1</translation>
</message>
</context> </context>
<context> <context>
<name>OnboardPlugin</name> <name>OnboardPlugin</name>