Add trash restore option

This commit is contained in:
reionwong 2021-09-04 01:47:54 +08:00
parent dfb4e6f6e0
commit 422fc5d6f9
6 changed files with 118 additions and 59 deletions

View file

@ -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")) {

View file

@ -197,6 +197,8 @@ public:
Q_INVOKABLE void openInTerminal();
Q_INVOKABLE void openChangeWallpaperDialog();
void restoreFromTrash();
bool isDesktop() const;
void setIsDesktop(bool isDesktop);

View file

@ -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<int, QByteArray> PlacesModel::roleNames() const
{
QHash<int, QByteArray> 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";

View file

@ -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

View file

@ -109,95 +109,100 @@
<context>
<name>FolderModel</name>
<message>
<location filename="../model/foldermodel.cpp" line="182"/>
<location filename="../model/foldermodel.cpp" line="183"/>
<source>%1 item</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="182"/>
<location filename="../model/foldermodel.cpp" line="183"/>
<source>%1 items</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="247"/>
<location filename="../model/foldermodel.cpp" line="248"/>
<source>The file or folder %1 does not exist.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="980"/>
<location filename="../model/foldermodel.cpp" line="985"/>
<source>Select All</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1242"/>
<location filename="../model/foldermodel.cpp" line="1265"/>
<source>Open</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1245"/>
<location filename="../model/foldermodel.cpp" line="1268"/>
<source>Open with</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1248"/>
<location filename="../model/foldermodel.cpp" line="1271"/>
<source>Cut</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1251"/>
<location filename="../model/foldermodel.cpp" line="1274"/>
<source>Copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1254"/>
<location filename="../model/foldermodel.cpp" line="1277"/>
<source>Paste</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1257"/>
<location filename="../model/foldermodel.cpp" line="1280"/>
<source>New Folder</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1260"/>
<location filename="../model/foldermodel.cpp" line="1283"/>
<source>Move To Trash</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1263"/>
<location filename="../model/foldermodel.cpp" line="1286"/>
<source>Empty Trash</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1266"/>
<location filename="../model/foldermodel.cpp" line="1289"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1269"/>
<location filename="../model/foldermodel.cpp" line="1292"/>
<source>Rename</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1272"/>
<location filename="../model/foldermodel.cpp" line="1295"/>
<source>Open in Terminal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1275"/>
<location filename="../model/foldermodel.cpp" line="1298"/>
<source>Set as Wallpaper</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1278"/>
<location filename="../model/foldermodel.cpp" line="1301"/>
<source>Properties</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1281"/>
<location filename="../model/foldermodel.cpp" line="1304"/>
<source>Change background</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1307"/>
<source>Restore</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FolderPage</name>
@ -357,43 +362,43 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="46"/>
<location filename="../model/placesmodel.cpp" line="47"/>
<source>Desktop</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="53"/>
<location filename="../model/placesmodel.cpp" line="55"/>
<source>Documents</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="60"/>
<location filename="../model/placesmodel.cpp" line="63"/>
<source>Downloads</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="67"/>
<location filename="../model/placesmodel.cpp" line="71"/>
<source>Music</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="74"/>
<location filename="../model/placesmodel.cpp" line="79"/>
<source>Pictures</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="81"/>
<location filename="../model/placesmodel.cpp" line="87"/>
<source>Videos</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="86"/>
<location filename="../model/placesmodel.cpp" line="93"/>
<source>Trash</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="109"/>
<location filename="../model/placesmodel.cpp" line="257"/>
<location filename="../model/placesmodel.cpp" line="117"/>
<location filename="../model/placesmodel.cpp" line="265"/>
<source>Drives</source>
<translation type="unfinished"></translation>
</message>

View file

@ -109,95 +109,100 @@
<context>
<name>FolderModel</name>
<message>
<location filename="../model/foldermodel.cpp" line="182"/>
<location filename="../model/foldermodel.cpp" line="183"/>
<source>%1 item</source>
<translation>%1 </translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="182"/>
<location filename="../model/foldermodel.cpp" line="183"/>
<source>%1 items</source>
<translation>%1 </translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="247"/>
<location filename="../model/foldermodel.cpp" line="248"/>
<source>The file or folder %1 does not exist.</source>
<translation> %1 </translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="980"/>
<location filename="../model/foldermodel.cpp" line="985"/>
<source>Select All</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1242"/>
<location filename="../model/foldermodel.cpp" line="1265"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1245"/>
<location filename="../model/foldermodel.cpp" line="1268"/>
<source>Open with</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1248"/>
<location filename="../model/foldermodel.cpp" line="1271"/>
<source>Cut</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1251"/>
<location filename="../model/foldermodel.cpp" line="1274"/>
<source>Copy</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1254"/>
<location filename="../model/foldermodel.cpp" line="1277"/>
<source>Paste</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1257"/>
<location filename="../model/foldermodel.cpp" line="1280"/>
<source>New Folder</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1260"/>
<location filename="../model/foldermodel.cpp" line="1283"/>
<source>Move To Trash</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1263"/>
<location filename="../model/foldermodel.cpp" line="1286"/>
<source>Empty Trash</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1266"/>
<location filename="../model/foldermodel.cpp" line="1289"/>
<source>Delete</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1269"/>
<location filename="../model/foldermodel.cpp" line="1292"/>
<source>Rename</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1272"/>
<location filename="../model/foldermodel.cpp" line="1295"/>
<source>Open in Terminal</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1275"/>
<location filename="../model/foldermodel.cpp" line="1298"/>
<source>Set as Wallpaper</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1278"/>
<location filename="../model/foldermodel.cpp" line="1301"/>
<source>Properties</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1281"/>
<location filename="../model/foldermodel.cpp" line="1304"/>
<source>Change background</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1307"/>
<source>Restore</source>
<translation></translation>
</message>
</context>
<context>
<name>FolderPage</name>
@ -357,43 +362,43 @@
<translation></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="46"/>
<location filename="../model/placesmodel.cpp" line="47"/>
<source>Desktop</source>
<translation></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="53"/>
<location filename="../model/placesmodel.cpp" line="55"/>
<source>Documents</source>
<translation></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="60"/>
<location filename="../model/placesmodel.cpp" line="63"/>
<source>Downloads</source>
<translation></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="67"/>
<location filename="../model/placesmodel.cpp" line="71"/>
<source>Music</source>
<translation></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="74"/>
<location filename="../model/placesmodel.cpp" line="79"/>
<source>Pictures</source>
<translation></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="81"/>
<location filename="../model/placesmodel.cpp" line="87"/>
<source>Videos</source>
<translation></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="86"/>
<location filename="../model/placesmodel.cpp" line="93"/>
<source>Trash</source>
<translation></translation>
</message>
<message>
<location filename="../model/placesmodel.cpp" line="109"/>
<location filename="../model/placesmodel.cpp" line="257"/>
<location filename="../model/placesmodel.cpp" line="117"/>
<location filename="../model/placesmodel.cpp" line="265"/>
<source>Drives</source>
<translation></translation>
</message>