diff --git a/Fwk/AppFwk/CommonCode/cafUtils.cpp b/Fwk/AppFwk/CommonCode/cafUtils.cpp index 1ee416b9a1..9326be8600 100644 --- a/Fwk/AppFwk/CommonCode/cafUtils.cpp +++ b/Fwk/AppFwk/CommonCode/cafUtils.cpp @@ -44,6 +44,9 @@ #include +#include +#include + namespace caf { @@ -161,5 +164,58 @@ QString Utils::indentString(int numSpacesToIndent, const QString& str) return retStr; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool Utils::getSaveDirectoryAndCheckOverwriteFiles(QString& saveDir, std::vector fileNames) +{ + bool overWriteFiles = false; + saveDir = QFileDialog::getExistingDirectory(NULL, "Select save directory", saveDir); + + std::vector filesToOverwrite; + for (QString fileName : fileNames) + { + QFileInfo fileInfo(saveDir + "/" + fileName); + if (fileInfo.exists()) + { + filesToOverwrite.push_back(fileName); + } + } + + if (filesToOverwrite.size() > 0) + { + QMessageBox msgBox; + + QString message = "The following files will be overwritten in the export:"; + for (QString fileName : filesToOverwrite) + { + message += "\n" + saveDir + "/" + fileName; + } + msgBox.setText(message); + + + msgBox.setInformativeText("Do you want to continue?"); + msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Ok); + int ret = msgBox.exec(); + + switch (ret) + { + case QMessageBox::Ok: + overWriteFiles = true; + break; + case QMessageBox::Cancel: + overWriteFiles = false; + break; + default: + // should never be reached + break; + } + + } + + return overWriteFiles; +} + } // namespace caf diff --git a/Fwk/AppFwk/CommonCode/cafUtils.h b/Fwk/AppFwk/CommonCode/cafUtils.h index 7ff61e78d5..a7d39df275 100644 --- a/Fwk/AppFwk/CommonCode/cafUtils.h +++ b/Fwk/AppFwk/CommonCode/cafUtils.h @@ -37,6 +37,8 @@ #pragma once +#include + class QLineEdit; class QString; class QStringList; @@ -60,6 +62,8 @@ public: static QString indentString(int numSpacesToIndent, const QString& str); + static bool getSaveDirectoryAndCheckOverwriteFiles(QString& defaultDir, std::vector fileNames); + }; }