diff --git a/qml/DockItem.qml b/qml/DockItem.qml index 963bcef..bb292b2 100644 --- a/qml/DockItem.qml +++ b/qml/DockItem.qml @@ -57,6 +57,7 @@ Item { signal clicked(var mouse) signal rightClicked(var mouse) signal doubleClicked(var mouse) + signal dropped(var drop) Drag.active: mouseArea.drag.active && control.draggable Drag.dragType: Drag.Automatic @@ -94,6 +95,7 @@ Item { id: iconDropArea anchors.fill: icon enabled: draggable + onDropped: control.dropped(drop) } MouseArea { diff --git a/qml/main.qml b/qml/main.qml index 6587259..ff21851 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -142,14 +142,21 @@ Item { dropArea.enabled: true + onDropped: { + if (drop.hasUrls) { + trash.moveToTrash(drop.urls) + } + } + Rectangle { anchors.fill: parent anchors.margins: FishUI.Units.smallSpacing / 2 color: "transparent" border.color: FishUI.Theme.textColor radius: height * 0.3 - border.width: 1 - opacity: trashItem.dropArea.containsDrag ? 0.8 : 0 + border.width: 1 / FishUI.Units.devicePixelRatio + border.pixelAligned: FishUI.Units.devicePixelRatio > 1 ? false : true + opacity: trashItem.dropArea.containsDrag ? 0.5 : 0 Behavior on opacity { NumberAnimation { diff --git a/src/trashmanager.cpp b/src/trashmanager.cpp index 608120b..c4e0301 100644 --- a/src/trashmanager.cpp +++ b/src/trashmanager.cpp @@ -17,8 +17,11 @@ */ #include "trashmanager.h" + +#include #include #include +#include const QString TrashDir = QDir::homePath() + "/.local/share/Trash"; 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); } +void TrashManager::moveToTrash(QList 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() { QProcess::startDetached("cutefish-filemanager", QStringList() << "-e"); diff --git a/src/trashmanager.h b/src/trashmanager.h index 101bbe2..b55e2c5 100644 --- a/src/trashmanager.h +++ b/src/trashmanager.h @@ -31,6 +31,7 @@ class TrashManager : public QObject public: explicit TrashManager(QObject *parent = nullptr); + Q_INVOKABLE void moveToTrash(QList urls); Q_INVOKABLE void openTrash(); Q_INVOKABLE void emptyTrash();