From e216af6a6d60e76432a55b6d031a9be5ebddcc66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Sun, 6 Oct 2024 21:44:30 +0200 Subject: [PATCH] Better handling of missing and overwrite files --- mainwindow.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index a65ff39..09750c9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -407,6 +407,9 @@ void MainWindow::copyOrMove(bool copy, const QString &dest) if(!dest.isEmpty() && dir.exists()) { int i = 0; + int missing = 0; + bool overwriteAll = false; + bool skipAll = false; QStringList files = m_database->getMarkedFiles(); QProgressDialog progress(copy ? tr("Copying") : tr("Moving"), tr("Cancel"), 0, files.size(), this); progress.setWindowModality(Qt::WindowModal); @@ -418,8 +421,42 @@ void MainWindow::copyOrMove(bool copy, const QString &dest) QFile srcFile(file); QFile dstFile(dir.absoluteFilePath(info.fileName())); - if(dstFile.exists()) + if(!srcFile.exists()) + { + missing++; continue; + } + + if(dstFile.exists()) + { + if(skipAll) + { + continue; + } + else if(overwriteAll) + { + dstFile.remove(); + } + else + { + QMessageBox::StandardButton button = QMessageBox::question(this, tr("Overwrite file?"), tr("Destination file %1 already exists. Overwrite?").arg(dstFile.fileName()), + QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll); + switch (button) + { + case QMessageBox::YesToAll: + overwriteAll = true; + case QMessageBox::Yes: + dstFile.remove(); + break; + case QMessageBox::NoToAll: + skipAll = true; + case QMessageBox::No: + continue; + default: + break; + } + } + } if(progress.wasCanceled()) return; @@ -458,6 +495,8 @@ void MainWindow::copyOrMove(bool copy, const QString &dest) progress.setValue(i++); } m_database->clearMarkedFiles(); + if(missing) + QMessageBox::information(this, tr("Missing marked files"), tr("%1 marked files were missing. They were skipped.").arg(missing)); } }