summaryrefslogtreecommitdiff
path: root/src/transfersavesdialog.cpp
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2022-05-17 11:47:01 +0200
committerMikaël Capelle <capelle.mikael@gmail.com>2023-07-09 17:20:40 +0200
commitd13f6bb870cdda71257f665367be8ef9fca86255 (patch)
tree52e214718478f1e52856572f5aa1a2ac58537f9f /src/transfersavesdialog.cpp
parent86bb01ba9eac879d3685c439ac9da0028bc4bc80 (diff)
Apply clang-format.
Diffstat (limited to 'src/transfersavesdialog.cpp')
-rw-r--r--src/transfersavesdialog.cpp139
1 files changed, 67 insertions, 72 deletions
diff --git a/src/transfersavesdialog.cpp b/src/transfersavesdialog.cpp
index e7c84e0a..2761ed1d 100644
--- a/src/transfersavesdialog.cpp
+++ b/src/transfersavesdialog.cpp
@@ -19,14 +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 <utility.h>
+#include "ui_transfersavesdialog.h"
#include <log.h>
+#include <utility.h>
-#include <QtDebug>
#include <QDateTime>
#include <QDir>
#include <QFile>
@@ -38,15 +37,15 @@ 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;
-TransferSavesDialog::TransferSavesDialog(const Profile &profile, IPluginGame const *gamePlugin, QWidget *parent)
- : TutorableDialog("TransferSaves", parent)
- , ui(new Ui::TransferSavesDialog)
- , m_Profile(profile)
- , m_GamePlugin(gamePlugin)
+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()));
@@ -66,59 +65,59 @@ 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);
+ refreshCharacters(m_GlobalSaves, ui->globalCharacterList, ui->copyToLocalBtn,
+ ui->moveToLocalBtn);
}
-
void TransferSavesDialog::refreshLocalCharacters()
{
- refreshCharacters(m_LocalSaves, ui->localCharacterList, ui->copyToGlobalBtn, ui->moveToGlobalBtn);
+ refreshCharacters(m_LocalSaves, ui->localCharacterList, ui->copyToGlobalBtn,
+ ui->moveToGlobalBtn);
}
-
-bool TransferSavesDialog::testOverwrite(OverwriteMode &overwriteMode, const QString &destinationFile)
+bool TransferSavesDialog::testOverwrite(OverwriteMode& overwriteMode,
+ const QString& destinationFile)
{
- QMessageBox::StandardButton res = overwriteMode == OVERWRITE_YES ? QMessageBox::Yes : QMessageBox::No;
+ 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);
+ QMessageBox::Yes | QMessageBox::No |
+ QMessageBox::YesToAll | QMessageBox::NoToAll);
if (res == QMessageBox::YesToAll) {
overwriteMode = OVERWRITE_YES;
- res = QMessageBox::Yes;
+ res = QMessageBox::Yes;
} else if (res == QMessageBox::NoToAll) {
overwriteMode = OVERWRITE_NO;
- res = QMessageBox::No;
+ res = QMessageBox::No;
}
}
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_GamePlugin->savesDirectory(),
- m_GlobalSaves[character],
- m_Profile.savePath(),
- [this](const QString &source, const QString &destination) -> bool {
+ character, MOVE_SAVES TO_PROFILE, m_GamePlugin->savesDirectory(),
+ m_GlobalSaves[character], m_Profile.savePath(),
+ [this](const QString& source, const QString& destination) -> bool {
return shellMove(source, destination, this);
},
"Failed to move {} to {}")) {
@@ -133,11 +132,9 @@ void TransferSavesDialog::on_copyToLocalBtn_clicked()
{
QString character = ui->globalCharacterList->currentItem()->text();
if (transferCharacters(
- character, COPY_SAVES TO_PROFILE,
- m_GamePlugin->savesDirectory(),
- m_GlobalSaves[character],
- m_Profile.savePath(),
- [this](const QString &source, const QString &destination) -> bool {
+ character, COPY_SAVES TO_PROFILE, m_GamePlugin->savesDirectory(),
+ m_GlobalSaves[character], m_Profile.savePath(),
+ [this](const QString& source, const QString& destination) -> bool {
return shellCopy(source, destination, this);
},
"Failed to copy {} to {}")) {
@@ -150,11 +147,9 @@ void TransferSavesDialog::on_moveToGlobalBtn_clicked()
{
QString character = ui->localCharacterList->currentItem()->text();
if (transferCharacters(
- character, MOVE_SAVES TO_GLOBAL,
- m_Profile.savePath(),
- m_LocalSaves[character],
- m_GamePlugin->savesDirectory().absolutePath(),
- [this](const QString &source, const QString &destination) -> bool {
+ character, MOVE_SAVES TO_GLOBAL, m_Profile.savePath(),
+ m_LocalSaves[character], m_GamePlugin->savesDirectory().absolutePath(),
+ [this](const QString& source, const QString& destination) -> bool {
return shellMove(source, destination, this);
},
"Failed to move {} to {}")) {
@@ -169,11 +164,9 @@ void TransferSavesDialog::on_copyToGlobalBtn_clicked()
{
QString character = ui->localCharacterList->currentItem()->text();
if (transferCharacters(
- character, COPY_SAVES TO_GLOBAL,
- m_Profile.savePath(),
- m_LocalSaves[character],
- m_GamePlugin->savesDirectory().absolutePath(),
- [this](const QString &source, const QString &destination) -> bool {
+ character, COPY_SAVES TO_GLOBAL, m_Profile.savePath(),
+ m_LocalSaves[character], m_GamePlugin->savesDirectory().absolutePath(),
+ [this](const QString& source, const QString& destination) -> bool {
return shellCopy(source, destination, this);
},
"Failed to copy {} to {}")) {
@@ -187,51 +180,55 @@ void TransferSavesDialog::on_doneButton_clicked()
close();
}
-void TransferSavesDialog::on_globalCharacterList_currentTextChanged(const QString &currentText)
+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.
+ // 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) {
+ for (SaveListItem const& save : saveList->second) {
ui->globalSavesList->addItem(QFileInfo(save->getFilepath()).fileName());
}
}
}
-void TransferSavesDialog::on_localCharacterList_currentTextChanged(const QString &currentText)
+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.
+ // 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) {
+ for (SaveListItem const& save : saveList->second) {
ui->localSavesList->addItem(QFileInfo(save->getFilepath()).fileName());
}
}
}
-void TransferSavesDialog::refreshSaves(SaveCollection &saveCollection, QString const &savedir)
+void TransferSavesDialog::refreshSaves(SaveCollection& saveCollection,
+ QString const& savedir)
{
saveCollection.clear();
auto saves = m_GamePlugin->listSaves(savedir);
std::sort(saves.begin(), saves.end(), [](auto const& lhs, auto const& rhs) {
return lhs->getCreationTime() > rhs->getCreationTime();
- });
+ });
- for (auto& save: saves) {
+ for (auto& save : saves) {
saveCollection[save->getSaveGroupIdentifier()].push_back(save);
}
}
-void TransferSavesDialog::refreshCharacters(const SaveCollection &saveCollection,
- QListWidget *charList, QPushButton *copy, QPushButton *move)
+void TransferSavesDialog::refreshCharacters(const SaveCollection& saveCollection,
+ QListWidget* charList, QPushButton* copy,
+ QPushButton* move)
{
charList->clear();
- for (SaveCollection::value_type const &val : saveCollection) {
+ for (SaveCollection::value_type const& val : saveCollection) {
charList->addItem(val.first);
}
if (charList->count() > 0) {
@@ -245,32 +242,30 @@ void TransferSavesDialog::refreshCharacters(const SaveCollection &saveCollection
}
bool TransferSavesDialog::transferCharacters(
- QString const &character, char const *message,
- QDir const& sourceDirectory,
- SaveList &saves,
- QDir const& destination,
- const std::function<bool(const QString &, const QString &)> &method,
- char const *errmsg)
+ QString const& character, char const* message, QDir const& sourceDirectory,
+ SaveList& saves, QDir const& destination,
+ 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;
+ if (QMessageBox::question(this, tr("Confirm"), tr(message).arg(character),
+ QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
+ return false;
}
OverwriteMode overwriteMode = OVERWRITE_ASK;
- for (SaveListItem const &save : saves) {
+ for (SaveListItem const& save : saves) {
for (QString source : save->allFiles()) {
QFileInfo sourceFile(source);
- QString destinationFile(destination.absoluteFilePath(sourceDirectory.relativeFilePath(source)));
+ QString destinationFile(
+ destination.absoluteFilePath(sourceDirectory.relativeFilePath(source)));
- //If the file is already there, let them skip (or not).
+ // If the file is already there, let them skip (or not).
if (QFile::exists(destinationFile)) {
- if (! testOverwrite(overwriteMode, destinationFile)) {
+ if (!testOverwrite(overwriteMode, destinationFile)) {
continue;
}
- //OK, they want to remove it.
+ // OK, they want to remove it.
QFile::remove(destinationFile);
}