Better handling of missing and overwrite files
This commit is contained in:
+40
-1
@@ -407,6 +407,9 @@ void MainWindow::copyOrMove(bool copy, const QString &dest)
|
|||||||
if(!dest.isEmpty() && dir.exists())
|
if(!dest.isEmpty() && dir.exists())
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
int missing = 0;
|
||||||
|
bool overwriteAll = false;
|
||||||
|
bool skipAll = false;
|
||||||
QStringList files = m_database->getMarkedFiles();
|
QStringList files = m_database->getMarkedFiles();
|
||||||
QProgressDialog progress(copy ? tr("Copying") : tr("Moving"), tr("Cancel"), 0, files.size(), this);
|
QProgressDialog progress(copy ? tr("Copying") : tr("Moving"), tr("Cancel"), 0, files.size(), this);
|
||||||
progress.setWindowModality(Qt::WindowModal);
|
progress.setWindowModality(Qt::WindowModal);
|
||||||
@@ -418,8 +421,42 @@ void MainWindow::copyOrMove(bool copy, const QString &dest)
|
|||||||
QFile srcFile(file);
|
QFile srcFile(file);
|
||||||
QFile dstFile(dir.absoluteFilePath(info.fileName()));
|
QFile dstFile(dir.absoluteFilePath(info.fileName()));
|
||||||
|
|
||||||
if(dstFile.exists())
|
if(!srcFile.exists())
|
||||||
|
{
|
||||||
|
missing++;
|
||||||
continue;
|
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())
|
if(progress.wasCanceled())
|
||||||
return;
|
return;
|
||||||
@@ -458,6 +495,8 @@ void MainWindow::copyOrMove(bool copy, const QString &dest)
|
|||||||
progress.setValue(i++);
|
progress.setValue(i++);
|
||||||
}
|
}
|
||||||
m_database->clearMarkedFiles();
|
m_database->clearMarkedFiles();
|
||||||
|
if(missing)
|
||||||
|
QMessageBox::information(this, tr("Missing marked files"), tr("%1 marked files were missing. They were skipped.").arg(missing));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user