From 422fc5d6f99aa83809dfe96f08a9edbd7b39fa7f Mon Sep 17 00:00:00 2001 From: reionwong Date: Sat, 4 Sep 2021 01:47:54 +0800 Subject: [PATCH] Add trash restore option --- model/foldermodel.cpp | 42 ++++++++++++++++++++++++++++-- model/foldermodel.h | 2 ++ model/placesmodel.cpp | 10 +++++++- qml/SideBar.qml | 5 ++-- translations/en_US.ts | 59 +++++++++++++++++++++++-------------------- translations/zh_CN.ts | 59 +++++++++++++++++++++++-------------------- 6 files changed, 118 insertions(+), 59 deletions(-) diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index d5b21b1..6708b22 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -1003,6 +1003,10 @@ void FolderModel::openContextMenu(QQuickItem *visualParent, Qt::KeyboardModifier menu->addAction(m_actionCollection.action("properties")); } else { // Open the items menu. + + // Trash items + menu->addAction(m_actionCollection.action("restore")); + menu->addAction(m_actionCollection.action("open")); menu->addAction(m_actionCollection.action("openWith")); menu->addAction(m_actionCollection.action("cut")); @@ -1080,6 +1084,20 @@ void FolderModel::openChangeWallpaperDialog() QProcess::startDetached("cutefish-settings", QStringList() << "-m" << "background"); } +void FolderModel::restoreFromTrash() +{ + if (!m_selectionModel->hasSelection()) + return; + + if (QAction *action = m_actionCollection.action("restore")) + if (!action->isVisible()) + return; + + + KIO::RestoreJob *job = KIO::restoreFromTrash(selectedUrls()); + job->start(); +} + void FolderModel::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { QModelIndexList indices = selected.indexes(); @@ -1286,6 +1304,9 @@ void FolderModel::createActions() QAction *changeBackground = new QAction(tr("Change background"), this); QObject::connect(changeBackground, &QAction::triggered, this, &FolderModel::openChangeWallpaperDialog); + QAction *restore = new QAction(tr("Restore"), this); + QObject::connect(restore, &QAction::triggered, this, &FolderModel::restoreFromTrash); + m_actionCollection.addAction(QStringLiteral("open"), open); m_actionCollection.addAction(QStringLiteral("openWith"), openWith); m_actionCollection.addAction(QStringLiteral("cut"), cut); @@ -1300,6 +1321,7 @@ void FolderModel::createActions() m_actionCollection.addAction(QStringLiteral("wallpaper"), wallpaper); m_actionCollection.addAction(QStringLiteral("properties"), properties); m_actionCollection.addAction(QStringLiteral("changeBackground"), changeBackground); + m_actionCollection.addAction(QStringLiteral("restore"), restore); } void FolderModel::updateActions() @@ -1336,8 +1358,24 @@ void FolderModel::updateActions() } } + if (QAction *openAction = m_actionCollection.action(QStringLiteral("open"))) { + openAction->setVisible(!isTrash); + } + + if (QAction *copyAction = m_actionCollection.action(QStringLiteral("copy"))) { + copyAction->setVisible(!isTrash); + } + + if (QAction *cutAction = m_actionCollection.action(QStringLiteral("cut"))) { + cutAction->setVisible(!isTrash); + } + + if (QAction *restoreAction = m_actionCollection.action(QStringLiteral("restore"))) { + restoreAction->setVisible(items.count() >= 1 && isTrash); + } + if (QAction *openWith = m_actionCollection.action(QStringLiteral("openWith"))) { - openWith->setVisible(items.count() == 1); + openWith->setVisible(items.count() == 1 && !isTrash); } if (QAction *newFolder = m_actionCollection.action(QStringLiteral("newFolder"))) { @@ -1379,7 +1417,7 @@ void FolderModel::updateActions() } if (QAction *terminal = m_actionCollection.action("terminal")) { - terminal->setVisible(items.size() == 1 && items.first().isDir()); + terminal->setVisible(items.size() == 1 && items.first().isDir() && !isTrash); } if (QAction *terminal = m_actionCollection.action("wallpaper")) { diff --git a/model/foldermodel.h b/model/foldermodel.h index 071959f..e1fa0c0 100644 --- a/model/foldermodel.h +++ b/model/foldermodel.h @@ -197,6 +197,8 @@ public: Q_INVOKABLE void openInTerminal(); Q_INVOKABLE void openChangeWallpaperDialog(); + void restoreFromTrash(); + bool isDesktop() const; void setIsDesktop(bool isDesktop); diff --git a/model/placesmodel.cpp b/model/placesmodel.cpp index 337da74..29058ec 100644 --- a/model/placesmodel.cpp +++ b/model/placesmodel.cpp @@ -37,6 +37,7 @@ PlacesModel::PlacesModel(QObject *parent) if (QDir(homePath).exists()) { PlacesItem *item = new PlacesItem(tr("Home"), QUrl::fromLocalFile(homePath)); + item->setIconName("folder-home"); item->setIconPath("folder-home.svg"); m_items.append(item); } @@ -44,6 +45,7 @@ PlacesModel::PlacesModel(QObject *parent) const QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); if (QDir(desktopPath).exists()) { PlacesItem *item = new PlacesItem(tr("Desktop"), QUrl::fromLocalFile(desktopPath)); + item->setIconName("folder-desktop"); item->setIconPath("folder-desktop.svg"); m_items.append(item); } @@ -51,6 +53,7 @@ PlacesModel::PlacesModel(QObject *parent) const QString documentsPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); if (QDir(documentsPath).exists()) { PlacesItem *item = new PlacesItem(tr("Documents"), QUrl::fromLocalFile(documentsPath)); + item->setIconName("folder-document"); item->setIconPath("folder-document.svg"); m_items.append(item); } @@ -58,6 +61,7 @@ PlacesModel::PlacesModel(QObject *parent) const QString downloadPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); if (QDir(downloadPath).exists()) { PlacesItem *item = new PlacesItem(tr("Downloads"), QUrl::fromLocalFile(downloadPath)); + item->setIconName("folder-download"); item->setIconPath("folder-download.svg"); m_items.append(item); } @@ -65,6 +69,7 @@ PlacesModel::PlacesModel(QObject *parent) const QString musicPath = QStandardPaths::writableLocation(QStandardPaths::MusicLocation); if (QDir(musicPath).exists()) { PlacesItem *item = new PlacesItem(tr("Music"), QUrl::fromLocalFile(musicPath)); + item->setIconName("folder-music"); item->setIconPath("folder-music.svg"); m_items.append(item); } @@ -72,6 +77,7 @@ PlacesModel::PlacesModel(QObject *parent) const QString picturePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); if (QDir(picturePath).exists()) { PlacesItem *item = new PlacesItem(tr("Pictures"), QUrl::fromLocalFile(picturePath)); + item->setIconName("folder-picture"); item->setIconPath("folder-picture.svg"); m_items.append(item); } @@ -79,11 +85,13 @@ PlacesModel::PlacesModel(QObject *parent) const QString videoPath = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation); if (QDir(videoPath).exists()) { PlacesItem *item = new PlacesItem(tr("Videos"), QUrl::fromLocalFile(videoPath)); + item->setIconName("folder-video"); item->setIconPath("folder-video.svg"); m_items.append(item); } PlacesItem *trashItem = new PlacesItem(tr("Trash"), QUrl(QStringLiteral("trash:///"))); + trashItem->setIconName("folder-trash"); trashItem->setIconPath("user-trash.svg"); m_items.append(trashItem); @@ -119,7 +127,7 @@ QHash PlacesModel::roleNames() const { QHash roleNames; roleNames[PlacesModel::NameRole] = "name"; - roleNames[PlacesModel::IconNameRole] = "icon"; + roleNames[PlacesModel::IconNameRole] = "iconName"; roleNames[PlacesModel::IconPathRole] = "iconPath"; roleNames[PlacesModel::UrlRole] = "url"; roleNames[PlacesModel::PathRole] = "path"; diff --git a/qml/SideBar.qml b/qml/SideBar.qml index 24001be..d45e89e 100644 --- a/qml/SideBar.qml +++ b/qml/SideBar.qml @@ -20,6 +20,7 @@ import QtQuick 2.12 import QtQuick.Layouts 1.12 import QtQuick.Controls 2.12 +import QtQuick.Window 2.12 import FishUI 1.0 as FishUI import Cutefish.FileManager 1.0 @@ -123,8 +124,8 @@ ListView { Image { height: 22 width: height - sourceSize: Qt.size(width, height) - // source: model.iconPath ? model.iconPath : "image://icontheme/" + model.iconName + sourceSize: Qt.size(22, 22) + // source: "image://icontheme/" + model.iconName source: "qrc:/images/" + (FishUI.Theme.darkMode || _item.checked ? "dark/" : "light/") + model.iconPath Layout.alignment: Qt.AlignVCenter smooth: false diff --git a/translations/en_US.ts b/translations/en_US.ts index 4d35156..dcdcc55 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -109,95 +109,100 @@ FolderModel - + %1 item - + %1 items - + The file or folder %1 does not exist. - + Select All - + Open - + Open with - + Cut - + Copy - + Paste - + New Folder - + Move To Trash - + Empty Trash - + Delete - + Rename - + Open in Terminal - + Set as Wallpaper - + Properties - + Change background + + + Restore + + FolderPage @@ -357,43 +362,43 @@ - + Desktop - + Documents - + Downloads - + Music - + Pictures - + Videos - + Trash - - + + Drives diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index ea90e22..2f42e8f 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -109,95 +109,100 @@ FolderModel - + %1 item %1 项 - + %1 items %1 项 - + The file or folder %1 does not exist. 文件或文件夹 %1 不存在 - + Select All 全选 - + Open 打开 - + Open with 打开方式 - + Cut 剪切 - + Copy 复制 - + Paste 粘贴 - + New Folder 新建文件夹 - + Move To Trash 移动到回收站 - + Empty Trash 清空回收站 - + Delete 删除 - + Rename 重命名 - + Open in Terminal 在终端中打开 - + Set as Wallpaper 设置为壁纸 - + Properties 属性 - + Change background 更改桌面背景 + + + Restore + 恢复 + FolderPage @@ -357,43 +362,43 @@ 主文件夹 - + Desktop 桌面 - + Documents 文档 - + Downloads 下载 - + Music 音乐 - + Pictures 图片 - + Videos 视频 - + Trash 回收站 - - + + Drives 设备