summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Uwe Broulik <[email protected]>2016-12-23 11:06:36 +0100
committerKai Uwe Broulik <[email protected]>2016-12-23 11:06:36 +0100
commit07402e9f70572faa3ecc3538f72c78a3a4ea398e (patch)
tree6608d0413b2605d26f50c80330fbfe14e941a21b
parente0b09c2929e09503023c5f5b49978f6d6844ac98 (diff)
[Folder View] Add "Restore" from trash option
This allows to restore files from trash as can be done in Dolphin. Differential Revision: https://phabricator.kde.org/D3756
-rw-r--r--containments/desktop/plugins/folder/foldermodel.cpp22
-rw-r--r--containments/desktop/plugins/folder/foldermodel.h1
2 files changed, 23 insertions, 0 deletions
diff --git a/containments/desktop/plugins/folder/foldermodel.cpp b/containments/desktop/plugins/folder/foldermodel.cpp
index f30d997..6441046 100644
--- a/containments/desktop/plugins/folder/foldermodel.cpp
+++ b/containments/desktop/plugins/folder/foldermodel.cpp
@@ -55,6 +55,7 @@
#include <KIO/JobUiDelegate>
#include <KIO/Paste>
#include <KIO/PasteJob>
+#include <KIO/RestoreJob>
#include <KLocalizedString>
#include <KPropertiesDialog>
#include <KSharedConfig>
@@ -1195,6 +1196,9 @@ void FolderModel::createActions()
QAction *emptyTrash = new QAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18n("&Empty Trash Bin"), this);
connect(emptyTrash, &QAction::triggered, this, &FolderModel::emptyTrashBin);
+ QAction *restoreFromTrash = new QAction(i18nc("Restore from trash", "Restore"), this);
+ connect(restoreFromTrash, &QAction::triggered, this, &FolderModel::restoreSelectedFromTrash);
+
QAction *del = new QAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("&Delete"), this);
connect(del, &QAction::triggered, this, &FolderModel::deleteSelected);
@@ -1212,6 +1216,7 @@ void FolderModel::createActions()
m_actionCollection.addAction(QStringLiteral("rename"), rename);
m_actionCollection.addAction(QStringLiteral("trash"), trash);
m_actionCollection.addAction(QStringLiteral("del"), del);
+ m_actionCollection.addAction(QStringLiteral("restoreFromTrash"), restoreFromTrash);
m_actionCollection.addAction(QStringLiteral("emptyTrash"), emptyTrash);
m_newMenu = new KNewFileMenu(&m_actionCollection, QStringLiteral("newMenu"), QApplication::desktop());
@@ -1251,6 +1256,10 @@ void FolderModel::updateActions()
}
}
+ if (QAction *restoreFromTrash = m_actionCollection.action(QStringLiteral("restoreFromTrash"))) {
+ restoreFromTrash->setVisible(isTrash);
+ }
+
QAction *paste = m_actionCollection.action(QStringLiteral("paste"));
if (paste) {
@@ -1344,6 +1353,7 @@ void FolderModel::openContextMenu()
}
menu->addAction(m_actionCollection.action(QStringLiteral("rename")));
+ menu->addAction(m_actionCollection.action(QStringLiteral("restoreFromTrash")));
KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::NoGlobals);
KConfigGroup cg(globalConfig, "KDE");
@@ -1513,6 +1523,18 @@ void FolderModel::emptyTrashBin()
}
}
+void FolderModel::restoreSelectedFromTrash()
+{
+ if (!m_selectionModel->hasSelection()) {
+ return;
+ }
+
+ const auto &urls = selectedUrls(true);
+
+ KIO::RestoreJob *job = KIO::restoreFromTrash(urls);
+ job->ui()->setAutoErrorHandlingEnabled(true);
+}
+
void FolderModel::undoTextChanged(const QString &text)
{
if (QAction *action = m_actionCollection.action(QStringLiteral("undo"))) {
diff --git a/containments/desktop/plugins/folder/foldermodel.h b/containments/desktop/plugins/folder/foldermodel.h
index 844f8dc..c395b5d 100644
--- a/containments/desktop/plugins/folder/foldermodel.h
+++ b/containments/desktop/plugins/folder/foldermodel.h
@@ -239,6 +239,7 @@ class FolderModel : public QSortFilterProxyModel
void refresh();
void moveSelectedToTrash();
void emptyTrashBin();
+ void restoreSelectedFromTrash();
void undoTextChanged(const QString &text);
private: