mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
hide wired item when wireless actived
Change-Id: Ib43746e4bde740415b1c0939420b0b2c95d47f0c
This commit is contained in:
parent
b8597dbe20
commit
0dc3a9fd63
@ -20,13 +20,12 @@ DockPluginsController::~DockPluginsController()
|
||||
|
||||
void DockPluginsController::itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey)
|
||||
{
|
||||
PluginsItem *item = new PluginsItem(itemInter, itemKey);
|
||||
|
||||
// check if same item added
|
||||
if (m_pluginList.contains(itemInter))
|
||||
if (m_pluginList[itemInter].contains(itemKey))
|
||||
return;
|
||||
|
||||
PluginsItem *item = new PluginsItem(itemInter, itemKey);
|
||||
m_pluginList[itemInter][itemKey] = item;
|
||||
|
||||
emit pluginItemInserted(item);
|
||||
|
@ -1,8 +1,7 @@
|
||||
#include "deviceitem.h"
|
||||
|
||||
DeviceItem::DeviceItem(const NetworkDevice::NetworkType type, const QUuid &deviceUuid)
|
||||
DeviceItem::DeviceItem(const QUuid &deviceUuid)
|
||||
: QWidget(nullptr),
|
||||
m_type(type),
|
||||
m_deviceUuid(deviceUuid),
|
||||
|
||||
m_networkManager(NetworkManager::instance(this))
|
||||
@ -19,8 +18,3 @@ const QUuid DeviceItem::uuid() const
|
||||
{
|
||||
return m_deviceUuid;
|
||||
}
|
||||
|
||||
NetworkDevice::NetworkType DeviceItem::type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
@ -10,18 +10,18 @@ class DeviceItem : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DeviceItem(const NetworkDevice::NetworkType type, const QUuid &deviceUuid);
|
||||
explicit DeviceItem(const QUuid &deviceUuid);
|
||||
|
||||
const QUuid uuid() const;
|
||||
NetworkDevice::NetworkType type() const;
|
||||
|
||||
virtual NetworkDevice::NetworkType type() const = 0;
|
||||
virtual NetworkDevice::NetworkState state() const = 0;
|
||||
virtual QWidget *itemApplet() = 0;
|
||||
|
||||
protected:
|
||||
QSize sizeHint() const;
|
||||
|
||||
protected:
|
||||
NetworkDevice::NetworkType m_type;
|
||||
QUuid m_deviceUuid;
|
||||
|
||||
NetworkManager *m_networkManager;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <QPainter>
|
||||
|
||||
WiredItem::WiredItem(const QUuid &deviceUuid)
|
||||
: DeviceItem(NetworkDevice::Wired, deviceUuid),
|
||||
: DeviceItem(deviceUuid),
|
||||
|
||||
m_connected(false),
|
||||
m_itemTips(new QLabel(this))
|
||||
@ -20,6 +20,16 @@ WiredItem::WiredItem(const QUuid &deviceUuid)
|
||||
connect(m_networkManager, &NetworkManager::activeConnectionChanged, this, &WiredItem::activeConnectionChanged);
|
||||
}
|
||||
|
||||
NetworkDevice::NetworkType WiredItem::type() const
|
||||
{
|
||||
return NetworkDevice::Wired;
|
||||
}
|
||||
|
||||
NetworkDevice::NetworkState WiredItem::state() const
|
||||
{
|
||||
return m_connected ? NetworkDevice::Activated : NetworkDevice::Disconnected;
|
||||
}
|
||||
|
||||
QWidget *WiredItem::itemApplet()
|
||||
{
|
||||
m_itemTips->setText(tr("Unknow"));
|
||||
|
@ -13,6 +13,8 @@ class WiredItem : public DeviceItem
|
||||
public:
|
||||
explicit WiredItem(const QUuid &deviceUuid);
|
||||
|
||||
NetworkDevice::NetworkType type() const;
|
||||
NetworkDevice::NetworkState state() const;
|
||||
QWidget *itemApplet();
|
||||
|
||||
protected:
|
||||
|
@ -5,12 +5,22 @@
|
||||
#include <QPainter>
|
||||
|
||||
WirelessItem::WirelessItem(const QUuid &uuid)
|
||||
: DeviceItem(NetworkDevice::Wireless, uuid),
|
||||
: DeviceItem(uuid),
|
||||
m_applet(nullptr)
|
||||
{
|
||||
QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
NetworkDevice::NetworkType WirelessItem::type() const
|
||||
{
|
||||
return NetworkDevice::Wireless;
|
||||
}
|
||||
|
||||
NetworkDevice::NetworkState WirelessItem::state() const
|
||||
{
|
||||
return m_applet->wirelessState();
|
||||
}
|
||||
|
||||
QWidget *WirelessItem::itemApplet()
|
||||
{
|
||||
return m_applet;
|
||||
|
@ -15,6 +15,8 @@ class WirelessItem : public DeviceItem
|
||||
public:
|
||||
explicit WirelessItem(const QUuid &uuid);
|
||||
|
||||
NetworkDevice::NetworkType type() const;
|
||||
NetworkDevice::NetworkState state() const;
|
||||
QWidget *itemApplet();
|
||||
|
||||
protected:
|
||||
|
@ -137,6 +137,8 @@ void NetworkManager::reloadDevices()
|
||||
return;
|
||||
|
||||
m_types = types;
|
||||
emit deviceTypesChanged(m_types);
|
||||
|
||||
qDebug() << "device type: " << m_types;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ signals:
|
||||
void deviceRemoved(const NetworkDevice &device) const;
|
||||
void activeConnectionChanged(const QUuid &uuid) const;
|
||||
void networkStateChanged(const NetworkDevice::NetworkTypes &states) const;
|
||||
void deviceTypesChanged(const NetworkDevice::NetworkTypes &types) const;
|
||||
|
||||
private:
|
||||
explicit NetworkManager(QObject *parent = 0);
|
||||
|
@ -32,7 +32,9 @@ QWidget *NetworkPlugin::itemWidget(const QString &itemKey)
|
||||
{
|
||||
for (auto deviceItem : m_deviceItemList)
|
||||
if (deviceItem->uuid() == itemKey)
|
||||
{
|
||||
return deviceItem;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@ -60,7 +62,7 @@ void NetworkPlugin::deviceAdded(const NetworkDevice &device)
|
||||
return;
|
||||
|
||||
m_deviceItemList.append(item);
|
||||
m_proxyInter->itemAdded(this, device.uuid().toString());
|
||||
refershDeviceItemVisible();
|
||||
}
|
||||
|
||||
void NetworkPlugin::deviceRemoved(const NetworkDevice &device)
|
||||
@ -80,23 +82,37 @@ void NetworkPlugin::networkStateChanged(const NetworkDevice::NetworkTypes &state
|
||||
{
|
||||
Q_UNUSED(states)
|
||||
|
||||
qDebug() << states;
|
||||
|
||||
// for (auto item : m_deviceItemList)
|
||||
// if (item->ty)
|
||||
// const QList<NetworkDevice> deviceList = m_networkManager->deviceList();
|
||||
// const auto items = states.testFlag(NetworkDevice::Wireless)
|
||||
// ? std::find_if(m_deviceList.cbegin(), m_deviceList.cend(),
|
||||
// [] (const NetworkDevice &dev) {return dev.type() == NetworkDevice::Wireless;})
|
||||
// : std::find_if(m_deviceList.cbegin(), m_deviceList.cend(),
|
||||
// [] (const NetworkDevice &dev) {return dev.type() == NetworkDevice::Wired;});
|
||||
|
||||
// for (auto dev : deviceList)
|
||||
// qDebug() << dev.uuid() << dev.type();
|
||||
|
||||
// // has wired connection
|
||||
// if (states.testFlag(NetworkDevice::Wired))
|
||||
// m_proxyInter->itemAdded(this, WIRED_ITEM);
|
||||
// else
|
||||
// m_proxyInter->itemRemoved(this, WIRED_ITEM);
|
||||
refershDeviceItemVisible();
|
||||
}
|
||||
|
||||
void NetworkPlugin::deviceTypesChanged(const NetworkDevice::NetworkTypes &types)
|
||||
{
|
||||
Q_UNUSED(types)
|
||||
|
||||
refershDeviceItemVisible();
|
||||
}
|
||||
|
||||
void NetworkPlugin::refershDeviceItemVisible()
|
||||
{
|
||||
const NetworkDevice::NetworkTypes types = m_networkManager->types();
|
||||
const bool hasWirelessDevice = types.testFlag(NetworkDevice::Wireless);
|
||||
|
||||
for (auto item : m_deviceItemList)
|
||||
{
|
||||
switch (item->type())
|
||||
{
|
||||
case NetworkDevice::Wireless:
|
||||
m_proxyInter->itemAdded(this, item->uuid().toString());
|
||||
break;
|
||||
|
||||
case NetworkDevice::Wired:
|
||||
if (item->state() == NetworkDevice::Activated || !hasWirelessDevice)
|
||||
m_proxyInter->itemAdded(this, item->uuid().toString());
|
||||
else
|
||||
m_proxyInter->itemRemoved(this, item->uuid().toString());
|
||||
break;
|
||||
|
||||
default:;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ private slots:
|
||||
void deviceAdded(const NetworkDevice &device);
|
||||
void deviceRemoved(const NetworkDevice &device);
|
||||
void networkStateChanged(const NetworkDevice::NetworkTypes &states);
|
||||
void deviceTypesChanged(const NetworkDevice::NetworkTypes &types);
|
||||
void refershDeviceItemVisible();
|
||||
|
||||
private:
|
||||
NetworkManager *m_networkManager;
|
||||
|
Loading…
x
Reference in New Issue
Block a user