diff --git a/mainwindow.cpp b/mainwindow.cpp index b21b143..83966e5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -131,6 +131,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) fileMenu->addSeparator(); fileMenu->addAction(tr("Copy marked files"), this, SLOT(copyMarked()), Qt::Key_F5); fileMenu->addAction(tr("Move marked files"), this, SLOT(moveMarked()), Qt::Key_F6); + fileMenu->addAction(tr("Move marked files to trash"), this, &MainWindow::deleteMarked, QKeySequence::Delete); fileMenu->addSeparator(); fileMenu->addAction(tr("Index directory"), this, SLOT(indexDir())); fileMenu->addAction(tr("Reindex files"), this, SLOT(reindex())); @@ -552,6 +553,34 @@ void MainWindow::moveMarked() copyOrMove(false); } +void MainWindow::deleteMarked() +{ + QStringList files = m_database->getMarkedFiles(); + if(QMessageBox::question(this, tr("Move files to trash?"), tr("Do you want to move %1 files to trash?").arg(files.size())) != QMessageBox::Yes) + return; + + QProgressDialog progress(tr("Moving marked files to trash"), tr("Cancel"), 0, files.size(), this); + progress.setWindowModality(Qt::WindowModal); + progress.show(); + int i = 0; + for(const QString &file : files) + { + if(!QFile::exists(file)) + continue; + + if(progress.wasCanceled()) + return; + + if(!QFile::moveToTrash(file)) + { + QMessageBox::warning(this, tr("Failed to move file to trash"), tr("Failed to move file to trash %1").arg(file)); + return; + } + progress.setValue(i++); + } + m_database->clearMarkedFiles(); +} + void MainWindow::toggleFullScreen() { if(isFullScreen()) diff --git a/mainwindow.h b/mainwindow.h index ff85bac..c5f6c5c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -59,6 +59,7 @@ protected slots: void unmarkAndNext(); void copyMarked(); void moveMarked(); + void deleteMarked(); void toggleFullScreen(); void liveMode(bool active); void imageStats(bool imageStats);