mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
watch user trash floder
Change-Id: I2f2fd86934b49e81c97a4b8c5c5f1850cc0c9f06
This commit is contained in:
parent
14873b08af
commit
014b1ed603
@ -3,27 +3,40 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QProcess>
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
#include <QDir>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
const QString TrashDir = QDir::homePath() + "/.local/share/Trash/files";
|
||||
|
||||
PopupControlWidget::PopupControlWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
||||
m_openBtn(new DLinkButton(tr("Open"), this)),
|
||||
m_clearBtn(new DLinkButton(tr("Clear"), this))
|
||||
m_clearBtn(new DLinkButton(tr("Clear"), this)),
|
||||
|
||||
m_fsWatcher(new QFileSystemWatcher(this))
|
||||
{
|
||||
m_fsWatcher->addPath(TrashDir);
|
||||
|
||||
QVBoxLayout *centeralLayout = new QVBoxLayout;
|
||||
centeralLayout->addWidget(m_openBtn);
|
||||
centeralLayout->addWidget(m_clearBtn);
|
||||
|
||||
connect(m_openBtn, &DLinkButton::clicked, this, &PopupControlWidget::openTrashFloder);
|
||||
connect(m_clearBtn, &DLinkButton::clicked, this, &PopupControlWidget::clearTrashFloder);
|
||||
connect(m_fsWatcher, &QFileSystemWatcher::directoryChanged, this, &PopupControlWidget::trashStatusChanged, Qt::QueuedConnection);
|
||||
|
||||
setLayout(centeralLayout);
|
||||
setFixedWidth(80);
|
||||
setFixedHeight(60);
|
||||
}
|
||||
|
||||
bool PopupControlWidget::empty() const
|
||||
{
|
||||
return m_empty;
|
||||
}
|
||||
|
||||
void PopupControlWidget::openTrashFloder()
|
||||
{
|
||||
QProcess *proc = new QProcess;
|
||||
@ -32,3 +45,25 @@ void PopupControlWidget::openTrashFloder()
|
||||
|
||||
proc->startDetached("gvfs-open trash://");
|
||||
}
|
||||
|
||||
void PopupControlWidget::clearTrashFloder()
|
||||
{
|
||||
for (auto item : QDir(TrashDir).entryInfoList())
|
||||
{
|
||||
if (item.isFile())
|
||||
QFile(item.fileName()).remove();
|
||||
else if (item.isDir())
|
||||
QDir(item.path()).removeRecursively();
|
||||
}
|
||||
}
|
||||
|
||||
void PopupControlWidget::trashStatusChanged()
|
||||
{
|
||||
const bool empty = QDir(TrashDir).entryList().count() == 2;
|
||||
|
||||
if (m_empty == empty)
|
||||
return;
|
||||
|
||||
m_empty = empty;
|
||||
emit emptyChanged(m_empty);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define POPUPCONTROLWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QFileSystemWatcher>
|
||||
|
||||
#include <dlinkbutton.h>
|
||||
|
||||
@ -12,12 +13,23 @@ class PopupControlWidget : public QWidget
|
||||
public:
|
||||
explicit PopupControlWidget(QWidget *parent = 0);
|
||||
|
||||
bool empty() const;
|
||||
|
||||
signals:
|
||||
void emptyChanged(const bool empty) const;
|
||||
|
||||
private slots:
|
||||
void openTrashFloder();
|
||||
void clearTrashFloder();
|
||||
void trashStatusChanged();
|
||||
|
||||
private:
|
||||
bool m_empty;
|
||||
|
||||
Dtk::Widget::DLinkButton *m_openBtn;
|
||||
Dtk::Widget::DLinkButton *m_clearBtn;
|
||||
|
||||
QFileSystemWatcher *m_fsWatcher;
|
||||
};
|
||||
|
||||
#endif // POPUPCONTROLWIDGET_H
|
||||
|
@ -2,10 +2,8 @@
|
||||
|
||||
TrashPlugin::TrashPlugin(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_trashWidget(new TrashWidget),
|
||||
m_popupApplet(new PopupControlWidget)
|
||||
m_trashWidget(new TrashWidget)
|
||||
{
|
||||
m_popupApplet->setVisible(false);
|
||||
}
|
||||
|
||||
const QString TrashPlugin::pluginName() const
|
||||
@ -31,7 +29,7 @@ QWidget *TrashPlugin::itemPopupApplet(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return m_popupApplet;
|
||||
return m_trashWidget->popupApplet();
|
||||
}
|
||||
|
||||
const QString TrashPlugin::itemCommand(const QString &itemKey)
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "trashwidget.h"
|
||||
#include "popupcontrolwidget.h"
|
||||
|
||||
class TrashPlugin : public QObject, PluginsItemInterface
|
||||
{
|
||||
@ -23,7 +22,6 @@ public:
|
||||
|
||||
private:
|
||||
TrashWidget *m_trashWidget;
|
||||
PopupControlWidget *m_popupApplet;
|
||||
};
|
||||
|
||||
#endif // TRASHPLUGIN_H
|
||||
|
@ -4,9 +4,18 @@
|
||||
#include <QIcon>
|
||||
|
||||
TrashWidget::TrashWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent),
|
||||
|
||||
m_popupApplet(new PopupControlWidget(this))
|
||||
{
|
||||
QIcon::setThemeName("deepin");
|
||||
|
||||
m_popupApplet->setVisible(false);
|
||||
}
|
||||
|
||||
QWidget *TrashWidget::popupApplet()
|
||||
{
|
||||
return m_popupApplet;
|
||||
}
|
||||
|
||||
void TrashWidget::paintEvent(QPaintEvent *e)
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef TRASHWIDGET_H
|
||||
#define TRASHWIDGET_H
|
||||
|
||||
#include "popupcontrolwidget.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class TrashWidget : public QWidget
|
||||
@ -10,8 +12,13 @@ class TrashWidget : public QWidget
|
||||
public:
|
||||
explicit TrashWidget(QWidget *parent = 0);
|
||||
|
||||
QWidget *popupApplet();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
||||
private:
|
||||
PopupControlWidget *m_popupApplet;
|
||||
};
|
||||
|
||||
#endif // TRASHWIDGET_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user