mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
fix(network):Abnormal hot swap of wired network
有线网络热插拔异常 bug:20058 (cherry picked from commit 9ddcdfbefbeffa7b8c89a584002451c970b448f7)
This commit is contained in:
parent
068b3e028b
commit
0231f82a01
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<void (NetworkDevice::*)(const bool) const>(&NetworkDevice::enableChanged),
|
||||
this, &WiredItem::enableChanged);
|
||||
connect(m_device, static_cast<void (NetworkDevice::*)(NetworkDevice::DeviceStatus) const>(&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<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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -25,12 +25,14 @@
|
||||
#include "deviceitem.h"
|
||||
|
||||
#include <WiredDevice>
|
||||
#include <DGuiApplicationHelper>
|
||||
#include <DSpinner>
|
||||
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -4,14 +4,11 @@
|
||||
#include "../../widgets/tipswidget.h"
|
||||
#include "../frame/util/imageutil.h"
|
||||
|
||||
#include <DGuiApplicationHelper>
|
||||
#include <DDBusSender>
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QJsonDocument>
|
||||
|
||||
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<QString, WiredItem *> &wiredItems, QMap<QString, WirelessItem *> &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<QString, WiredItem *> &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<QString, WiredItem *> &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<QString, WiredItem *> &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<QString, QVariant> 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<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)
|
||||
{
|
||||
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:
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef NETWORKITEM_H
|
||||
#define NETWORKITEM_H
|
||||
|
||||
#include <DGuiApplicationHelper>
|
||||
#include <DSwitchButton>
|
||||
|
||||
#include <QScrollArea>
|
||||
@ -8,6 +9,7 @@
|
||||
#include <QLabel>
|
||||
#include <QTimer>
|
||||
|
||||
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;
|
||||
|
@ -164,20 +164,42 @@ void NetworkPlugin::onDeviceListChanged(const QList<NetworkDevice *> devices)
|
||||
QMap<QString, WirelessItem*> wirelessItems;
|
||||
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) {
|
||||
const QString &path = device->path();
|
||||
// new device
|
||||
DeviceItem *item = nullptr;
|
||||
switch (device->type()) {
|
||||
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));
|
||||
|
||||
connect(static_cast<WiredItem *>(item), &WiredItem::wiredStateChanged,
|
||||
m_networkItem, &NetworkItem::updateSelf);
|
||||
connect(static_cast<WiredItem *>(item), &WiredItem::enableChanged,
|
||||
m_networkItem, &NetworkItem::updateSelf);
|
||||
break;
|
||||
case NetworkDevice::Wireless:
|
||||
item = new WirelessItem(static_cast<WirelessDevice *>(device));
|
||||
static_cast<WirelessItem *>(item)->setDeviceInfo(wirelessDeviceCnt == 1 ? -1 : ++wirelessNum);
|
||||
wirelessItems.insert(path, static_cast<WirelessItem *>(item));
|
||||
|
||||
connect(static_cast<WirelessItem *>(item), &WirelessItem::queryActiveConnInfo,
|
||||
@ -207,8 +229,6 @@ void NetworkPlugin::onDeviceListChanged(const QList<NetworkDevice *> 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);
|
||||
}
|
||||
|
@ -171,6 +171,14 @@
|
||||
<source>Network</source>
|
||||
<translation>网络</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Wired Network</source>
|
||||
<translation>有线网络</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Wired Network %1</source>
|
||||
<translation>有线网络%1</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>OnboardPlugin</name>
|
||||
|
Loading…
x
Reference in New Issue
Block a user