add wireless item applet

Change-Id: Ie996deff0d35a902223bca4177d615b4a680fce6
This commit is contained in:
石博文 2016-07-25 16:20:36 +08:00 committed by Hualet Wang
parent 2af94c195d
commit fe506e6807
9 changed files with 84 additions and 13 deletions

View File

@ -0,0 +1,12 @@
#include "wirelessapplet.h"
WirelessApplet::WirelessApplet(const QString &devicePath, QWidget *parent)
: QScrollArea(parent),
m_devicePath(devicePath)
{
setFixedHeight(300);
setFrameStyle(QFrame::NoFrame);
setFixedWidth(300);
setStyleSheet("background-color:transparent;");
}

View File

@ -0,0 +1,17 @@
#ifndef WIRELESSAPPLET_H
#define WIRELESSAPPLET_H
#include <QScrollArea>
class WirelessApplet : public QScrollArea
{
Q_OBJECT
public:
explicit WirelessApplet(const QString &devicePath, QWidget *parent = 0);
private:
const QString m_devicePath;
};
#endif // WIRELESSAPPLET_H

View File

@ -5,13 +5,15 @@
#include <QPainter>
WirelessItem::WirelessItem(const QUuid &uuid)
: DeviceItem(NetworkDevice::Wireless, uuid)
: DeviceItem(NetworkDevice::Wireless, uuid),
m_applet(nullptr)
{
QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection);
}
QWidget *WirelessItem::itemApplet()
{
return nullptr;
return m_applet;
}
void WirelessItem::paintEvent(QPaintEvent *e)
@ -45,18 +47,28 @@ const QPixmap WirelessItem::iconPix(const Dock::DisplayMode displayMode, const i
.arg(8)
.arg(displayMode == Dock::Fashion ? "" : "-symbolic");
if (!m_icons.contains(key))
m_icons.insert(key, ImageUtil::loadSvg(":/wireless/resources/wireless/" + key + ".svg", size));
return m_icons.value(key);
return cachedPix(key, size);
}
const QPixmap WirelessItem::backgroundPix(const int size)
{
const QString key = "wireless-background";
return cachedPix("wireless-background", size);
}
const QPixmap WirelessItem::cachedPix(const QString &key, const int size)
{
if (!m_icons.contains(key))
m_icons.insert(key, ImageUtil::loadSvg(":/wireless/resources/wireless/" + key + ".svg", size));
return m_icons.value(key);
}
void WirelessItem::init()
{
const QString devPath = m_networkManager->devicePath(m_deviceUuid);
m_applet = new WirelessApplet(devPath, this);
m_applet->setVisible(false);
// connect(m_networkManager, &NetworkManager::APPropertiesChanged, this, &WirelessItem::APPropertiesChanegd);
}

View File

@ -4,6 +4,7 @@
#include "constants.h"
#include "deviceitem.h"
#include "applet/wirelessapplet.h"
#include <QHash>
@ -23,9 +24,15 @@ protected:
private:
const QPixmap iconPix(const Dock::DisplayMode displayMode, const int size);
const QPixmap backgroundPix(const int size);
const QPixmap cachedPix(const QString &key, const int size);
private slots:
void init();
private:
QHash<QString, QPixmap> m_icons;
WirelessApplet *m_applet;
};
#endif // WIRELESSITEM_H

View File

@ -18,7 +18,8 @@ HEADERS += \
networkdevice.h \
util/imageutil.h \
item/deviceitem.h \
item/wirelessitem.h
item/wirelessitem.h \
item/applet/wirelessapplet.h
SOURCES += \
networkplugin.cpp \
@ -28,7 +29,8 @@ SOURCES += \
networkdevice.cpp \
util/imageutil.cpp \
item/deviceitem.cpp \
item/wirelessitem.cpp
item/wirelessitem.cpp \
item/applet/wirelessapplet.cpp
target.path = $${PREFIX}/lib/dde-dock/plugins/
INSTALLS += target

View File

@ -61,4 +61,3 @@ NetworkDevice::NetworkType NetworkDevice::deviceType(const QString &type)
return NetworkDevice::None;
}

View File

@ -11,8 +11,19 @@ class NetworkDevice
{
public:
enum NetworkState {
Unknow = 0,
Connected = 100,
Unknow = 0,
Unmanaged = 10,
Unavailable = 20,
Disconnected = 30,
Prepare = 40,
Config = 50,
NeedAuth = 60,
IpConfig = 70,
IpCheck = 80,
Secondaries = 90,
Activated = 100,
Deactivation = 110,
Failed = 120,
};
enum NetworkType {

View File

@ -55,6 +55,15 @@ const QString NetworkManager::deviceHwAddr(const QUuid &uuid) const
return item->hwAddress();
}
const QString NetworkManager::devicePath(const QUuid &uuid) const
{
const auto item = device(uuid);
if (item == m_deviceSet.cend())
return QString();
return item->path();
}
const QJsonObject NetworkManager::deviceInfo(const QUuid &uuid) const
{
const QString addr = deviceHwAddr(uuid);
@ -83,9 +92,9 @@ NetworkManager::NetworkManager(QObject *parent)
m_networkInter(new DBusNetwork(this))
{
connect(m_networkInter, &DBusNetwork::DevicesChanged, this, &NetworkManager::reloadDevices);
connect(m_networkInter, &DBusNetwork::ActiveConnectionsChanged, this, &NetworkManager::reloadActiveConnections);
connect(m_networkInter, &DBusNetwork::AccessPointPropertiesChanged, this, &NetworkManager::APPropertiesChanged);
}
const QSet<NetworkDevice>::const_iterator NetworkManager::device(const QUuid &uuid) const

View File

@ -24,6 +24,7 @@ public:
NetworkDevice::NetworkState deviceState(const QUuid &uuid) const;
const QString deviceHwAddr(const QUuid &uuid) const;
const QString devicePath(const QUuid &uuid) const;
const QJsonObject deviceInfo(const QUuid &uuid) const;
signals:
@ -32,6 +33,7 @@ signals:
void deviceRemoved(const NetworkDevice &device) const;
void activeConnectionChanged(const QUuid &uuid) const;
void networkStateChanged(const NetworkDevice::NetworkTypes &states) const;
void APPropertiesChanged(const QString &devicePath, const QString &info) const;
private:
explicit NetworkManager(QObject *parent = 0);