feat(trash): support move to trash

This commit is contained in:
kateleet 2021-12-26 17:07:57 +08:00
parent 36fa1781ea
commit c189b0fb19
4 changed files with 28 additions and 2 deletions

View file

@ -57,6 +57,7 @@ Item {
signal clicked(var mouse) signal clicked(var mouse)
signal rightClicked(var mouse) signal rightClicked(var mouse)
signal doubleClicked(var mouse) signal doubleClicked(var mouse)
signal dropped(var drop)
Drag.active: mouseArea.drag.active && control.draggable Drag.active: mouseArea.drag.active && control.draggable
Drag.dragType: Drag.Automatic Drag.dragType: Drag.Automatic
@ -94,6 +95,7 @@ Item {
id: iconDropArea id: iconDropArea
anchors.fill: icon anchors.fill: icon
enabled: draggable enabled: draggable
onDropped: control.dropped(drop)
} }
MouseArea { MouseArea {

View file

@ -142,14 +142,21 @@ Item {
dropArea.enabled: true dropArea.enabled: true
onDropped: {
if (drop.hasUrls) {
trash.moveToTrash(drop.urls)
}
}
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
anchors.margins: FishUI.Units.smallSpacing / 2 anchors.margins: FishUI.Units.smallSpacing / 2
color: "transparent" color: "transparent"
border.color: FishUI.Theme.textColor border.color: FishUI.Theme.textColor
radius: height * 0.3 radius: height * 0.3
border.width: 1 border.width: 1 / FishUI.Units.devicePixelRatio
opacity: trashItem.dropArea.containsDrag ? 0.8 : 0 border.pixelAligned: FishUI.Units.devicePixelRatio > 1 ? false : true
opacity: trashItem.dropArea.containsDrag ? 0.5 : 0
Behavior on opacity { Behavior on opacity {
NumberAnimation { NumberAnimation {

View file

@ -17,8 +17,11 @@
*/ */
#include "trashmanager.h" #include "trashmanager.h"
#include <QDebug>
#include <QProcess> #include <QProcess>
#include <QDir> #include <QDir>
#include <QUrl>
const QString TrashDir = QDir::homePath() + "/.local/share/Trash"; const QString TrashDir = QDir::homePath() + "/.local/share/Trash";
const QDir::Filters ItemsShouldCount = QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot; const QDir::Filters ItemsShouldCount = QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot;
@ -32,6 +35,19 @@ TrashManager::TrashManager(QObject *parent)
connect(m_filesWatcher, &QFileSystemWatcher::directoryChanged, this, &TrashManager::onDirectoryChanged, Qt::QueuedConnection); connect(m_filesWatcher, &QFileSystemWatcher::directoryChanged, this, &TrashManager::onDirectoryChanged, Qt::QueuedConnection);
} }
void TrashManager::moveToTrash(QList<QUrl> urls)
{
QStringList paths;
for (const QUrl &url : urls) {
if (!url.isLocalFile())
continue;
paths.append(url.toLocalFile());
}
QProcess::startDetached("cutefish-filemanager", QStringList() << "--move-to-trash" << paths);
}
void TrashManager::emptyTrash() void TrashManager::emptyTrash()
{ {
QProcess::startDetached("cutefish-filemanager", QStringList() << "-e"); QProcess::startDetached("cutefish-filemanager", QStringList() << "-e");

View file

@ -31,6 +31,7 @@ class TrashManager : public QObject
public: public:
explicit TrashManager(QObject *parent = nullptr); explicit TrashManager(QObject *parent = nullptr);
Q_INVOKABLE void moveToTrash(QList<QUrl> urls);
Q_INVOKABLE void openTrash(); Q_INVOKABLE void openTrash();
Q_INVOKABLE void emptyTrash(); Q_INVOKABLE void emptyTrash();