diff options
| author | Sandro Jäckel <sandro.jaeckel@gmail.com> | 2018-02-23 01:45:58 +0100 |
|---|---|---|
| committer | Sandro Jäckel <sandro.jaeckel@gmail.com> | 2018-02-23 01:45:58 +0100 |
| commit | ea6292168a6acd4c263913f0ccd7dd64daf4f5cf (patch) | |
| tree | 312024abbd7c3c100274f3a8031d49096480b654 /src/transfersavesdialog.cpp | |
| parent | 5e5c9c07291f6b09623d31c92b1fb61c4ede576e (diff) | |
Revert "Applied clang-format on source"
This reverts commit 5e5c9c07291f6b09623d31c92b1fb61c4ede576e.
Diffstat (limited to 'src/transfersavesdialog.cpp')
| -rw-r--r-- | src/transfersavesdialog.cpp | 442 |
1 files changed, 254 insertions, 188 deletions
diff --git a/src/transfersavesdialog.cpp b/src/transfersavesdialog.cpp index dc139b39..b8dda056 100644 --- a/src/transfersavesdialog.cpp +++ b/src/transfersavesdialog.cpp @@ -19,12 +19,13 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "transfersavesdialog.h"
+#include "ui_transfersavesdialog.h"
#include "iplugingame.h"
#include "isavegame.h"
#include "savegameinfo.h"
-#include "ui_transfersavesdialog.h"
#include <utility.h>
+#include <QtDebug>
#include <QDateTime>
#include <QDir>
#include <QFile>
@@ -36,259 +37,324 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QMessageBox>
#include <QPushButton>
#include <QStringList>
-#include <QtDebug>
using namespace MOBase;
using namespace MOShared;
-// These two classes give the save-transfer box a smidgin of useful info even
-// if save game isn't supported yet.
+//These two classes give the save-transfer box a smidgin of useful info even
+//if save game isn't supported yet.
namespace {
-class DummySave : public ISaveGame {
+class DummySave : public ISaveGame
+{
public:
- DummySave(QString const& filename) : m_File(filename) {}
+ DummySave(QString const &filename) :
+ m_File(filename)
+ {}
- ~DummySave() {}
+ ~DummySave() {}
- virtual QString getFilename() const override { return m_File; }
+ virtual QString getFilename() const override
+ {
+ return m_File;
+ }
- virtual QDateTime getCreationTime() const override { return QFileInfo(m_File).created(); }
+ virtual QDateTime getCreationTime() const override
+ {
+ return QFileInfo(m_File).created();
+ }
- virtual QString getSaveGroupIdentifier() const override { return m_File; }
+ virtual QString getSaveGroupIdentifier() const override
+ {
+ return m_File;
+ }
- virtual QStringList allFiles() const override { return {m_File}; }
+ virtual QStringList allFiles() const override
+ {
+ return { m_File };
+ }
private:
- QString m_File;
+ QString m_File;
};
-class DummyInfo : public SaveGameInfo {
+class DummyInfo : public SaveGameInfo
+{
public:
- virtual MOBase::ISaveGame const* getSaveGameInfo(QString const& file) const override { return new DummySave(file); }
+ virtual MOBase::ISaveGame const *getSaveGameInfo(QString const &file) const override
+ {
+ return new DummySave(file);
+ }
- virtual MissingAssets getMissingAssets(QString const&) const override { return {}; }
+ virtual MissingAssets getMissingAssets(QString const &) const override
+ {
+ return {};
+ }
- MOBase::ISaveGameInfoWidget* getSaveGameWidget(QWidget*) const override { return nullptr; }
+ MOBase::ISaveGameInfoWidget *getSaveGameWidget(QWidget *) const override
+ {
+ return nullptr;
+ }
};
-} // end anonymous namespace
+} //end anonymous namespace
-TransferSavesDialog::TransferSavesDialog(const Profile& profile, IPluginGame const* gamePlugin, QWidget* parent)
- : TutorableDialog("TransferSaves", parent), ui(new Ui::TransferSavesDialog), m_Profile(profile),
- m_GamePlugin(gamePlugin) {
- ui->setupUi(this);
- ui->label_2->setText(tr("Characters for profile %1").arg(m_Profile.name()));
- refreshGlobalSaves();
- refreshLocalSaves();
- refreshGlobalCharacters();
- refreshLocalCharacters();
+TransferSavesDialog::TransferSavesDialog(const Profile &profile, IPluginGame const *gamePlugin, QWidget *parent)
+ : TutorableDialog("TransferSaves", parent)
+ , ui(new Ui::TransferSavesDialog)
+ , m_Profile(profile)
+ , m_GamePlugin(gamePlugin)
+{
+ ui->setupUi(this);
+ ui->label_2->setText(tr("Characters for profile %1").arg(m_Profile.name()));
+ refreshGlobalSaves();
+ refreshLocalSaves();
+ refreshGlobalCharacters();
+ refreshLocalCharacters();
}
-TransferSavesDialog::~TransferSavesDialog() { delete ui; }
+TransferSavesDialog::~TransferSavesDialog()
+{
+ delete ui;
+}
-void TransferSavesDialog::refreshGlobalSaves() {
- refreshSaves(m_GlobalSaves, m_GamePlugin->savesDirectory().absolutePath());
+void TransferSavesDialog::refreshGlobalSaves()
+{
+ refreshSaves(m_GlobalSaves, m_GamePlugin->savesDirectory().absolutePath());
}
-void TransferSavesDialog::refreshLocalSaves() { refreshSaves(m_LocalSaves, m_Profile.savePath()); }
-void TransferSavesDialog::refreshGlobalCharacters() {
- refreshCharacters(m_GlobalSaves, ui->globalCharacterList, ui->copyToLocalBtn, ui->moveToLocalBtn);
+void TransferSavesDialog::refreshLocalSaves()
+{
+ refreshSaves(m_LocalSaves, m_Profile.savePath());
}
-void TransferSavesDialog::refreshLocalCharacters() {
- refreshCharacters(m_LocalSaves, ui->localCharacterList, ui->copyToGlobalBtn, ui->moveToGlobalBtn);
+
+void TransferSavesDialog::refreshGlobalCharacters()
+{
+ refreshCharacters(m_GlobalSaves, ui->globalCharacterList, ui->copyToLocalBtn, ui->moveToLocalBtn);
}
-bool TransferSavesDialog::testOverwrite(OverwriteMode& overwriteMode, const QString& destinationFile) {
- QMessageBox::StandardButton res = overwriteMode == OVERWRITE_YES ? QMessageBox::Yes : QMessageBox::No;
- if (overwriteMode == OVERWRITE_ASK) {
- res = QMessageBox::question(this, tr("Overwrite"), tr("Overwrite the file \"%1\"").arg(destinationFile),
- QMessageBox::Yes | QMessageBox::No | QMessageBox::YesToAll | QMessageBox::NoToAll);
- if (res == QMessageBox::YesToAll) {
- overwriteMode = OVERWRITE_YES;
- res = QMessageBox::Yes;
- } else if (res == QMessageBox::NoToAll) {
- overwriteMode = OVERWRITE_NO;
- res = QMessageBox::No;
- }
+
+void TransferSavesDialog::refreshLocalCharacters()
+{
+ refreshCharacters(m_LocalSaves, ui->localCharacterList, ui->copyToGlobalBtn, ui->moveToGlobalBtn);
+}
+
+
+bool TransferSavesDialog::testOverwrite(OverwriteMode &overwriteMode, const QString &destinationFile)
+{
+ QMessageBox::StandardButton res = overwriteMode == OVERWRITE_YES ? QMessageBox::Yes : QMessageBox::No;
+ if (overwriteMode == OVERWRITE_ASK) {
+ res = QMessageBox::question(this, tr("Overwrite"),
+ tr("Overwrite the file \"%1\"").arg(destinationFile),
+ QMessageBox::Yes | QMessageBox::No | QMessageBox::YesToAll | QMessageBox::NoToAll);
+ if (res == QMessageBox::YesToAll) {
+ overwriteMode = OVERWRITE_YES;
+ res = QMessageBox::Yes;
+ } else if (res == QMessageBox::NoToAll) {
+ overwriteMode = OVERWRITE_NO;
+ res = QMessageBox::No;
}
- return res == QMessageBox::Yes;
+ }
+ return res == QMessageBox::Yes;
}
-#define MOVE_SAVES "Move all save games of character \"%1\""
-#define COPY_SAVES "Copy all save games of character \"%1\""
+
+#define MOVE_SAVES "Move all save games of character \"%1\""
+#define COPY_SAVES "Copy all save games of character \"%1\""
#define TO_PROFILE "to the profile?"
-#define TO_GLOBAL "to the global location? Please be aware that this will mess up the running number of save games."
+#define TO_GLOBAL "to the global location? Please be aware that this will mess up the running number of save games."
-void TransferSavesDialog::on_moveToLocalBtn_clicked() {
- QString character = ui->globalCharacterList->currentItem()->text();
- if (transferCharacters(character, MOVE_SAVES TO_PROFILE, m_GlobalSaves[character], m_Profile.savePath(),
- [this](const QString& source, const QString& destination) -> bool {
- return shellMove(source, destination, this);
- },
- "Failed to move %s to %s")) {
- refreshGlobalSaves();
- refreshGlobalCharacters();
- refreshLocalSaves();
- refreshLocalCharacters();
- }
+void TransferSavesDialog::on_moveToLocalBtn_clicked()
+{
+ QString character = ui->globalCharacterList->currentItem()->text();
+ if (transferCharacters(
+ character, MOVE_SAVES TO_PROFILE, m_GlobalSaves[character],
+ m_Profile.savePath(),
+ [this](const QString &source, const QString &destination) -> bool {
+ return shellMove(source, destination, this);
+ },
+ "Failed to move %s to %s")) {
+ refreshGlobalSaves();
+ refreshGlobalCharacters();
+ refreshLocalSaves();
+ refreshLocalCharacters();
+ }
}
-void TransferSavesDialog::on_copyToLocalBtn_clicked() {
- QString character = ui->globalCharacterList->currentItem()->text();
- if (transferCharacters(character, COPY_SAVES TO_PROFILE, m_GlobalSaves[character], m_Profile.savePath(),
- [this](const QString& source, const QString& destination) -> bool {
- return shellCopy(source, destination, this);
- },
- "Failed to copy %s to %s")) {
- refreshLocalSaves();
- refreshLocalCharacters();
- }
+void TransferSavesDialog::on_copyToLocalBtn_clicked()
+{
+ QString character = ui->globalCharacterList->currentItem()->text();
+ if (transferCharacters(
+ character, COPY_SAVES TO_PROFILE, m_GlobalSaves[character],
+ m_Profile.savePath(),
+ [this](const QString &source, const QString &destination) -> bool {
+ return shellCopy(source, destination, this);
+ },
+ "Failed to copy %s to %s")) {
+ refreshLocalSaves();
+ refreshLocalCharacters();
+ }
}
-void TransferSavesDialog::on_moveToGlobalBtn_clicked() {
- QString character = ui->localCharacterList->currentItem()->text();
- if (transferCharacters(character, MOVE_SAVES TO_GLOBAL, m_LocalSaves[character],
- m_GamePlugin->savesDirectory().absolutePath(),
- [this](const QString& source, const QString& destination) -> bool {
- return shellMove(source, destination, this);
- },
- "Failed to move %s to %s")) {
- refreshGlobalSaves();
- refreshGlobalCharacters();
- refreshLocalSaves();
- refreshLocalCharacters();
- }
+void TransferSavesDialog::on_moveToGlobalBtn_clicked()
+{
+ QString character = ui->localCharacterList->currentItem()->text();
+ if (transferCharacters(
+ character, MOVE_SAVES TO_GLOBAL, m_LocalSaves[character],
+ m_GamePlugin->savesDirectory().absolutePath(),
+ [this](const QString &source, const QString &destination) -> bool {
+ return shellMove(source, destination, this);
+ },
+ "Failed to move %s to %s")) {
+ refreshGlobalSaves();
+ refreshGlobalCharacters();
+ refreshLocalSaves();
+ refreshLocalCharacters();
+ }
}
-void TransferSavesDialog::on_copyToGlobalBtn_clicked() {
- QString character = ui->localCharacterList->currentItem()->text();
- if (transferCharacters(character, COPY_SAVES TO_GLOBAL, m_LocalSaves[character],
- m_GamePlugin->savesDirectory().absolutePath(),
- [this](const QString& source, const QString& destination) -> bool {
- return shellCopy(source, destination, this);
- },
- "Failed to copy %s to %s")) {
- refreshGlobalSaves();
- refreshGlobalCharacters();
- }
+void TransferSavesDialog::on_copyToGlobalBtn_clicked()
+{
+ QString character = ui->localCharacterList->currentItem()->text();
+ if (transferCharacters(
+ character, COPY_SAVES TO_GLOBAL, m_LocalSaves[character],
+ m_GamePlugin->savesDirectory().absolutePath(),
+ [this](const QString &source, const QString &destination) -> bool {
+ return shellCopy(source, destination, this);
+ },
+ "Failed to copy %s to %s")) {
+ refreshGlobalSaves();
+ refreshGlobalCharacters();
+ }
}
-void TransferSavesDialog::on_doneButton_clicked() { close(); }
+void TransferSavesDialog::on_doneButton_clicked()
+{
+ close();
+}
-void TransferSavesDialog::on_globalCharacterList_currentTextChanged(const QString& currentText) {
- ui->globalSavesList->clear();
- // sadly this can get called while we're resetting the list, with an invalid
- // name, so we have to check.
- SaveCollection::const_iterator saveList = m_GlobalSaves.find(currentText);
- if (saveList != m_GlobalSaves.end()) {
- for (SaveListItem const& save : saveList->second) {
- ui->globalSavesList->addItem(QFileInfo(save->getFilename()).fileName());
- }
+void TransferSavesDialog::on_globalCharacterList_currentTextChanged(const QString ¤tText)
+{
+ ui->globalSavesList->clear();
+ //sadly this can get called while we're resetting the list, with an invalid
+ //name, so we have to check.
+ SaveCollection::const_iterator saveList = m_GlobalSaves.find(currentText);
+ if (saveList != m_GlobalSaves.end()) {
+ for (SaveListItem const &save : saveList->second) {
+ ui->globalSavesList->addItem(QFileInfo(save->getFilename()).fileName());
}
+ }
}
-void TransferSavesDialog::on_localCharacterList_currentTextChanged(const QString& currentText) {
- ui->localSavesList->clear();
- // sadly this can get called while we're resetting the list, with an invalid
- // name, so we have to check.
- SaveCollection::const_iterator saveList = m_LocalSaves.find(currentText);
- if (saveList != m_LocalSaves.end()) {
- for (SaveListItem const& save : saveList->second) {
- ui->localSavesList->addItem(QFileInfo(save->getFilename()).fileName());
- }
+void TransferSavesDialog::on_localCharacterList_currentTextChanged(const QString ¤tText)
+{
+ ui->localSavesList->clear();
+ //sadly this can get called while we're resetting the list, with an invalid
+ //name, so we have to check.
+ SaveCollection::const_iterator saveList = m_LocalSaves.find(currentText);
+ if (saveList != m_LocalSaves.end()) {
+ for (SaveListItem const &save : saveList->second) {
+ ui->localSavesList->addItem(QFileInfo(save->getFilename()).fileName());
}
+ }
}
-void TransferSavesDialog::refreshSaves(SaveCollection& saveCollection, QString const& savedir) {
- saveCollection.clear();
- QDir savesDir(savedir);
- savesDir.setNameFilters(QStringList() << QString("*.%1").arg(m_GamePlugin->savegameExtension()));
+void TransferSavesDialog::refreshSaves(SaveCollection &saveCollection, QString const &savedir)
+{
+ saveCollection.clear();
+ QDir savesDir(savedir);
+ savesDir.setNameFilters(QStringList() << QString("*.%1").arg(m_GamePlugin->savegameExtension()));
- SaveGameInfo const* info = m_GamePlugin->feature<SaveGameInfo>();
- if (info == nullptr) {
- static DummyInfo dummyInfo;
- info = &dummyInfo;
- }
+ SaveGameInfo const *info = m_GamePlugin->feature<SaveGameInfo>();
+ if (info == nullptr) {
+ static DummyInfo dummyInfo;
+ info = &dummyInfo;
+ }
- QStringList files = savesDir.entryList(QDir::Files, QDir::Time);
- for (const QString& filename : files) {
- QString file = savesDir.absoluteFilePath(filename);
- MOBase::ISaveGame const* save = info->getSaveGameInfo(file);
- saveCollection[save->getSaveGroupIdentifier()].push_back(std::unique_ptr<MOBase::ISaveGame const>(save));
- }
+ QStringList files = savesDir.entryList(QDir::Files, QDir::Time);
+ for (const QString &filename : files) {
+ QString file = savesDir.absoluteFilePath(filename);
+ MOBase::ISaveGame const *save = info->getSaveGameInfo(file);
+ saveCollection[save->getSaveGroupIdentifier()].push_back(
+ std::unique_ptr<MOBase::ISaveGame const>(save));
+ }
}
-void TransferSavesDialog::refreshCharacters(const SaveCollection& saveCollection, QListWidget* charList,
- QPushButton* copy, QPushButton* move) {
- charList->clear();
- for (SaveCollection::value_type const& val : saveCollection) {
- charList->addItem(val.first);
- }
- if (charList->count() > 0) {
- charList->setCurrentRow(0);
- copy->setEnabled(true);
- move->setEnabled(true);
- } else {
- copy->setEnabled(false);
- move->setEnabled(false);
- }
+void TransferSavesDialog::refreshCharacters(const SaveCollection &saveCollection,
+ QListWidget *charList, QPushButton *copy, QPushButton *move)
+{
+ charList->clear();
+ for (SaveCollection::value_type const &val : saveCollection) {
+ charList->addItem(val.first);
+ }
+ if (charList->count() > 0) {
+ charList->setCurrentRow(0);
+ copy->setEnabled(true);
+ move->setEnabled(true);
+ } else {
+ copy->setEnabled(false);
+ move->setEnabled(false);
+ }
}
-bool TransferSavesDialog::transferCharacters(QString const& character, char const* message, SaveList& saves,
- QString const& dest,
- const std::function<bool(const QString&, const QString&)>& method,
- char const* errmsg) {
- if (QMessageBox::question(this, tr("Confirm"), tr(message).arg(character), QMessageBox::Yes | QMessageBox::No) !=
- QMessageBox::Yes) {
- return false;
- }
+bool TransferSavesDialog::transferCharacters(
+ QString const &character, char const *message, SaveList &saves,
+ QString const &dest,
+ const std::function<bool(const QString &, const QString &)> &method,
+ char const *errmsg)
+{
+ if (QMessageBox::question(this, tr("Confirm"),
+ tr(message).arg(character),
+ QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
+ return false;
+ }
- OverwriteMode overwriteMode = OVERWRITE_ASK;
+ OverwriteMode overwriteMode = OVERWRITE_ASK;
- QDir destination(dest);
- for (SaveListItem const& save : saves) {
- for (QString source : save->allFiles()) {
- QFileInfo sourceFile(source);
- QString destinationFile(destination.absoluteFilePath(sourceFile.fileName()));
+ QDir destination(dest);
+ for (SaveListItem const &save : saves) {
+ for (QString source : save->allFiles()) {
+ QFileInfo sourceFile(source);
+ QString destinationFile(destination.absoluteFilePath(sourceFile.fileName()));
- // If the file is already there, let them skip (or not).
- if (QFile::exists(destinationFile)) {
- if (!testOverwrite(overwriteMode, destinationFile)) {
- continue;
- }
- // OK, they want to remove it.
- QFile::remove(destinationFile);
- }
+ //If the file is already there, let them skip (or not).
+ if (QFile::exists(destinationFile)) {
+ if (! testOverwrite(overwriteMode, destinationFile)) {
+ continue;
+ }
+ //OK, they want to remove it.
+ QFile::remove(destinationFile);
+ }
- if (!method(sourceFile.absoluteFilePath(), destinationFile)) {
- qCritical(errmsg, sourceFile.absoluteFilePath().toUtf8().constData(),
- destinationFile.toUtf8().constData());
- }
+ if (!method(sourceFile.absoluteFilePath(), destinationFile)) {
+ qCritical(errmsg,
+ sourceFile.absoluteFilePath().toUtf8().constData(),
+ destinationFile.toUtf8().constData());
+ }
- QFileInfo sourceFileSE(sourceFile.absolutePath() + "/" + sourceFile.completeBaseName() + "." +
- m_GamePlugin->savegameSEExtension());
- if (sourceFileSE.exists()) {
- QString destinationFileSE(destination.absoluteFilePath(sourceFileSE.fileName()));
+ QFileInfo sourceFileSE(sourceFile.absolutePath() + "/" + sourceFile.completeBaseName() + "." + m_GamePlugin->savegameSEExtension());
+ if (sourceFileSE.exists()) {
+ QString destinationFileSE(destination.absoluteFilePath(sourceFileSE.fileName()));
- // If the file is already there, let them skip (or not).
- if (QFile::exists(destinationFileSE)) {
- if (!testOverwrite(overwriteMode, destinationFileSE)) {
- continue;
- }
- // OK, they want to remove it.
- QFile::remove(destinationFileSE);
- }
+ //If the file is already there, let them skip (or not).
+ if (QFile::exists(destinationFileSE)) {
+ if (!testOverwrite(overwriteMode, destinationFileSE)) {
+ continue;
+ }
+ //OK, they want to remove it.
+ QFile::remove(destinationFileSE);
+ }
- if (!method(sourceFileSE.absoluteFilePath(), destinationFileSE)) {
- qCritical(errmsg, sourceFileSE.absoluteFilePath().toUtf8().constData(),
- destinationFileSE.toUtf8().constData());
- }
- }
+ if (!method(sourceFileSE.absoluteFilePath(), destinationFileSE)) {
+ qCritical(errmsg,
+ sourceFileSE.absoluteFilePath().toUtf8().constData(),
+ destinationFileSE.toUtf8().constData());
}
+ }
}
- return true;
+ }
+ return true;
}
|
