mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
add disk mount plugin
Change-Id: Ie84fcda69aa50b67a8c3d5a4de26198bf2db0cca
This commit is contained in:
parent
3fdb1db032
commit
6cd10fa3cf
@ -22,13 +22,14 @@ PluginsItem::PluginsItem(PluginsItemInterface* const pluginInter, const QString
|
||||
{
|
||||
Q_ASSERT(m_centeralWidget);
|
||||
|
||||
m_centeralWidget->installEventFilter(this);
|
||||
|
||||
QBoxLayout *hLayout = new QHBoxLayout;
|
||||
hLayout->addWidget(m_centeralWidget);
|
||||
hLayout->setSpacing(0);
|
||||
hLayout->setMargin(0);
|
||||
|
||||
m_centeralWidget->installEventFilter(this);
|
||||
m_centeralWidget->setVisible(true);
|
||||
|
||||
setLayout(hLayout);
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
}
|
||||
|
@ -13,14 +13,19 @@ DISTFILES += disk-mount.json
|
||||
HEADERS += \
|
||||
diskmountplugin.h \
|
||||
dbus/dbusdiskmount.h \
|
||||
dbus/variant/diskinfo.h
|
||||
dbus/variant/diskinfo.h \
|
||||
diskcontrolwidget.h \
|
||||
diskpluginitem.h
|
||||
|
||||
SOURCES += \
|
||||
diskmountplugin.cpp \
|
||||
dbus/dbusdiskmount.cpp \
|
||||
dbus/variant/diskinfo.cpp
|
||||
dbus/variant/diskinfo.cpp \
|
||||
diskcontrolwidget.cpp \
|
||||
diskpluginitem.cpp
|
||||
|
||||
target.path = $${PREFIX}/lib/dde-dock/plugins/
|
||||
INSTALLS += target
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc
|
||||
|
19
plugins/disk-mount/diskcontrolwidget.cpp
Normal file
19
plugins/disk-mount/diskcontrolwidget.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "diskcontrolwidget.h"
|
||||
|
||||
DiskControlWidget::DiskControlWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
||||
m_diskInter(new DBusDiskMount(this))
|
||||
{
|
||||
|
||||
connect(m_diskInter, &DBusDiskMount::DiskListChanged, this, &DiskControlWidget::diskListChanged);
|
||||
|
||||
QMetaObject::invokeMethod(this, "diskListChanged", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void DiskControlWidget::diskListChanged()
|
||||
{
|
||||
m_diskInfoList = m_diskInter->diskList();
|
||||
|
||||
emit diskCountChanged(m_diskInfoList.count());
|
||||
}
|
27
plugins/disk-mount/diskcontrolwidget.h
Normal file
27
plugins/disk-mount/diskcontrolwidget.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef DISKCONTROLWIDGET_H
|
||||
#define DISKCONTROLWIDGET_H
|
||||
|
||||
#include "dbus/dbusdiskmount.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class DiskControlWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DiskControlWidget(QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void diskCountChanged(const int count) const;
|
||||
|
||||
private slots:
|
||||
void diskListChanged();
|
||||
|
||||
private:
|
||||
DBusDiskMount *m_diskInter;
|
||||
|
||||
DiskInfoList m_diskInfoList;
|
||||
};
|
||||
|
||||
#endif // DISKCONTROLWIDGET_H
|
@ -3,9 +3,13 @@
|
||||
DiskMountPlugin::DiskMountPlugin(QObject *parent)
|
||||
: QObject(parent),
|
||||
|
||||
m_diskInter(new DBusDiskMount(this))
|
||||
m_pluginAdded(false),
|
||||
|
||||
m_diskPluginItem(new DiskPluginItem),
|
||||
m_diskControlApplet(nullptr)
|
||||
{
|
||||
qDebug() << m_diskInter->diskList();
|
||||
m_diskPluginItem->setVisible(false);
|
||||
m_diskPluginItem->setDockDisplayMode(displayMode());
|
||||
}
|
||||
|
||||
const QString DiskMountPlugin::pluginName() const
|
||||
@ -16,11 +20,46 @@ const QString DiskMountPlugin::pluginName() const
|
||||
void DiskMountPlugin::init(PluginProxyInterface *proxyInter)
|
||||
{
|
||||
m_proxyInter = proxyInter;
|
||||
|
||||
initCompoments();
|
||||
}
|
||||
|
||||
QWidget *DiskMountPlugin::itemWidget(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return nullptr;
|
||||
return m_diskPluginItem;
|
||||
}
|
||||
|
||||
QWidget *DiskMountPlugin::itemPopupApplet(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return m_diskControlApplet;
|
||||
}
|
||||
|
||||
void DiskMountPlugin::initCompoments()
|
||||
{
|
||||
m_diskControlApplet = new DiskControlWidget;
|
||||
m_diskControlApplet->setVisible(false);
|
||||
|
||||
connect(m_diskControlApplet, &DiskControlWidget::diskCountChanged, this, &DiskMountPlugin::diskCountChanged);
|
||||
}
|
||||
|
||||
void DiskMountPlugin::displayModeChanged(const Dock::DisplayMode mode)
|
||||
{
|
||||
m_diskPluginItem->setDockDisplayMode(mode);
|
||||
}
|
||||
|
||||
void DiskMountPlugin::diskCountChanged(const int count)
|
||||
{
|
||||
if (m_pluginAdded == bool(count))
|
||||
return;
|
||||
|
||||
m_pluginAdded = bool(count);
|
||||
|
||||
if (m_pluginAdded)
|
||||
m_proxyInter->itemAdded(this, QString());
|
||||
else
|
||||
m_proxyInter->itemRemoved(this, QString());
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
#define DISKMOUNTPLUGIN_H
|
||||
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "dbus/dbusdiskmount.h"
|
||||
#include "diskcontrolwidget.h"
|
||||
#include "diskpluginitem.h"
|
||||
|
||||
class DiskMountPlugin : public QObject, PluginsItemInterface
|
||||
{
|
||||
@ -17,9 +18,21 @@ public:
|
||||
void init(PluginProxyInterface *proxyInter);
|
||||
|
||||
QWidget *itemWidget(const QString &itemKey);
|
||||
QWidget *itemPopupApplet(const QString &itemKey);
|
||||
|
||||
private:
|
||||
DBusDiskMount *m_diskInter;
|
||||
void initCompoments();
|
||||
|
||||
void displayModeChanged(const Dock::DisplayMode mode);
|
||||
|
||||
private slots:
|
||||
void diskCountChanged(const int count);
|
||||
|
||||
private:
|
||||
bool m_pluginAdded;
|
||||
|
||||
DiskPluginItem *m_diskPluginItem;
|
||||
DiskControlWidget *m_diskControlApplet;
|
||||
};
|
||||
|
||||
#endif // DISKMOUNTPLUGIN_H
|
||||
|
47
plugins/disk-mount/diskpluginitem.cpp
Normal file
47
plugins/disk-mount/diskpluginitem.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include "diskpluginitem.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
|
||||
DiskPluginItem::DiskPluginItem(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
m_displayMode(Dock::Efficient)
|
||||
{
|
||||
}
|
||||
|
||||
void DiskPluginItem::setDockDisplayMode(const Dock::DisplayMode mode)
|
||||
{
|
||||
m_displayMode = mode;
|
||||
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
void DiskPluginItem::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QWidget::paintEvent(e);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.drawPixmap(rect().center() - m_icon.rect().center(), m_icon);
|
||||
}
|
||||
|
||||
void DiskPluginItem::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
QWidget::resizeEvent(e);
|
||||
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
QSize DiskPluginItem::sizeHint() const
|
||||
{
|
||||
return QSize(24, 24);
|
||||
}
|
||||
|
||||
void DiskPluginItem::updateIcon()
|
||||
{
|
||||
if (m_displayMode == Dock::Efficient)
|
||||
m_icon = QPixmap(":/icons/resources/icon_small.png");
|
||||
else
|
||||
m_icon = QPixmap(":/icons/resources/icon.png");
|
||||
|
||||
update();
|
||||
}
|
33
plugins/disk-mount/diskpluginitem.h
Normal file
33
plugins/disk-mount/diskpluginitem.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef DISKPLUGINITEM_H
|
||||
#define DISKPLUGINITEM_H
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPixmap>
|
||||
|
||||
class DiskPluginItem : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DiskPluginItem(QWidget *parent = 0);
|
||||
|
||||
public slots:
|
||||
void setDockDisplayMode(const Dock::DisplayMode mode);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
QSize sizeHint() const;
|
||||
|
||||
private:
|
||||
void updateIcon();
|
||||
|
||||
private:
|
||||
Dock::DisplayMode m_displayMode;
|
||||
|
||||
QPixmap m_icon;
|
||||
};
|
||||
|
||||
#endif // DISKPLUGINITEM_H
|
6
plugins/disk-mount/resources.qrc
Normal file
6
plugins/disk-mount/resources.qrc
Normal file
@ -0,0 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/icons">
|
||||
<file>resources/icon_small.png</file>
|
||||
<file>resources/icon.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
Before Width: | Height: | Size: 358 B After Width: | Height: | Size: 358 B |
Loading…
x
Reference in New Issue
Block a user