diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2022-05-17 11:47:01 +0200 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2023-07-09 17:20:40 +0200 |
| commit | d13f6bb870cdda71257f665367be8ef9fca86255 (patch) | |
| tree | 52e214718478f1e52856572f5aa1a2ac58537f9f /src/profilesdialog.cpp | |
| parent | 86bb01ba9eac879d3685c439ac9da0028bc4bc80 (diff) | |
Apply clang-format.
Diffstat (limited to 'src/profilesdialog.cpp')
| -rw-r--r-- | src/profilesdialog.cpp | 168 |
1 files changed, 94 insertions, 74 deletions
diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 4abd95ac..674a7780 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -20,17 +20,17 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "profilesdialog.h" #include "ui_profilesdialog.h" -#include "shared/appconfig.h" #include "bsainvalidation.h" +#include "filesystemutilities.h" #include "iplugingame.h" +#include "localsavegames.h" #include "organizercore.h" #include "profile.h" #include "profileinputdialog.h" #include "report.h" -#include "transfersavesdialog.h" -#include "filesystemutilities.h" #include "settings.h" -#include "localsavegames.h" +#include "shared/appconfig.h" +#include "transfersavesdialog.h" #include <QDir> #include <QDirIterator> @@ -49,13 +49,10 @@ using namespace MOShared; Q_DECLARE_METATYPE(Profile::Ptr) - -ProfilesDialog::ProfilesDialog(const QString &profileName, OrganizerCore &organizer, QWidget *parent) - : TutorableDialog("Profiles", parent) - , ui(new Ui::ProfilesDialog) - , m_FailState(false) - , m_Game(organizer.managedGame()) - , m_ActiveProfileName("") +ProfilesDialog::ProfilesDialog(const QString& profileName, OrganizerCore& organizer, + QWidget* parent) + : TutorableDialog("Profiles", parent), ui(new Ui::ProfilesDialog), + m_FailState(false), m_Game(organizer.managedGame()), m_ActiveProfileName("") { ui->setupUi(this); @@ -66,28 +63,33 @@ ProfilesDialog::ProfilesDialog(const QString &profileName, OrganizerCore &organi while (profileIter.hasNext()) { profileIter.next(); - QListWidgetItem *item = addItem(profileIter.filePath()); + QListWidgetItem* item = addItem(profileIter.filePath()); if (profileName == profileIter.fileName()) { ui->profilesList->setCurrentItem(item); m_ActiveProfileName = profileName; } } - BSAInvalidation *invalidation = m_Game->feature<BSAInvalidation>(); + BSAInvalidation* invalidation = m_Game->feature<BSAInvalidation>(); if (invalidation == nullptr) { - ui->invalidationBox->setToolTip(tr("Archive invalidation isn't required for this game.")); + ui->invalidationBox->setToolTip( + tr("Archive invalidation isn't required for this game.")); ui->invalidationBox->setEnabled(false); } if (!m_Game->feature<LocalSavegames>()) { - ui->localSavesBox->setToolTip(tr("This game does not support profile-specific game saves.")); + ui->localSavesBox->setToolTip( + tr("This game does not support profile-specific game saves.")); ui->localSavesBox->setEnabled(false); } - connect(this, &ProfilesDialog::profileCreated, &organizer, &OrganizerCore::profileCreated); - connect(this, &ProfilesDialog::profileRenamed, &organizer, &OrganizerCore::profileRenamed); - connect(this, &ProfilesDialog::profileRemoved, &organizer, &OrganizerCore::profileRemoved); + connect(this, &ProfilesDialog::profileCreated, &organizer, + &OrganizerCore::profileCreated); + connect(this, &ProfilesDialog::profileRenamed, &organizer, + &OrganizerCore::profileRenamed); + connect(this, &ProfilesDialog::profileRemoved, &organizer, + &OrganizerCore::profileRemoved); } ProfilesDialog::~ProfilesDialog() @@ -101,7 +103,7 @@ int ProfilesDialog::exec() return QDialog::exec(); } -void ProfilesDialog::showEvent(QShowEvent *event) +void ProfilesDialog::showEvent(QShowEvent* event) { TutorableDialog::showEvent(event); @@ -109,9 +111,12 @@ void ProfilesDialog::showEvent(QShowEvent *event) QPoint pos = ui->profilesList->mapToGlobal(QPoint(0, 0)); pos.rx() += ui->profilesList->width() / 2; pos.ry() += (ui->profilesList->height() / 2) - 20; - QWhatsThis::showText(pos, - QObject::tr("Before you can use ModOrganizer, you need to create at least one profile. " - "ATTENTION: Run the game at least once before creating a profile!"), ui->profilesList); + QWhatsThis::showText( + pos, + QObject::tr( + "Before you can use ModOrganizer, you need to create at least one profile. " + "ATTENTION: Run the game at least once before creating a profile!"), + ui->profilesList); } } @@ -122,9 +127,8 @@ void ProfilesDialog::on_close_clicked() void ProfilesDialog::on_select_clicked() { - const Profile::Ptr currentProfile = ui->profilesList->currentItem() - ->data(Qt::UserRole) - .value<Profile::Ptr>(); + const Profile::Ptr currentProfile = + ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>(); if (!currentProfile) { return; @@ -139,12 +143,14 @@ std::optional<QString> ProfilesDialog::selectedProfile() const return m_Selected; } -QListWidgetItem *ProfilesDialog::addItem(const QString &name) +QListWidgetItem* ProfilesDialog::addItem(const QString& name) { QDir profileDir(name); - QListWidgetItem *newItem = new QListWidgetItem(profileDir.dirName(), ui->profilesList); + QListWidgetItem* newItem = + new QListWidgetItem(profileDir.dirName(), ui->profilesList); try { - newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(new Profile(profileDir, m_Game)))); + newItem->setData(Qt::UserRole, QVariant::fromValue( + Profile::Ptr(new Profile(profileDir, m_Game)))); m_FailState = false; } catch (const std::exception& e) { reportError(tr("failed to create profile: %1").arg(e.what())); @@ -152,10 +158,10 @@ QListWidgetItem *ProfilesDialog::addItem(const QString &name) return newItem; } -void ProfilesDialog::createProfile(const QString &name, bool useDefaultSettings) +void ProfilesDialog::createProfile(const QString& name, bool useDefaultSettings) { try { - QListWidgetItem *newItem = new QListWidgetItem(name, ui->profilesList); + QListWidgetItem* newItem = new QListWidgetItem(name, ui->profilesList); auto profile = Profile::Ptr(new Profile(name, m_Game, useDefaultSettings)); newItem->setData(Qt::UserRole, QVariant::fromValue(profile)); ui->profilesList->addItem(newItem); @@ -168,10 +174,10 @@ void ProfilesDialog::createProfile(const QString &name, bool useDefaultSettings) } } -void ProfilesDialog::createProfile(const QString &name, const Profile &reference) +void ProfilesDialog::createProfile(const QString& name, const Profile& reference) { try { - QListWidgetItem *newItem = new QListWidgetItem(name, ui->profilesList); + QListWidgetItem* newItem = new QListWidgetItem(name, ui->profilesList); auto profile = Profile::Ptr(Profile::createPtrFrom(name, reference, m_Game)); newItem->setData(Qt::UserRole, QVariant::fromValue(profile)); ui->profilesList->addItem(newItem); @@ -188,12 +194,12 @@ void ProfilesDialog::on_addProfileButton_clicked() { ProfileInputDialog dialog(this); bool okClicked = dialog.exec(); - QString name = dialog.getName(); + QString name = dialog.getName(); if (okClicked && (name.size() > 0)) { try { createProfile(name, dialog.getPreferDefaultSettings()); - } catch (const std::exception &e) { + } catch (const std::exception& e) { reportError(tr("failed to create profile: %1").arg(e.what())); } } @@ -202,47 +208,53 @@ void ProfilesDialog::on_addProfileButton_clicked() void ProfilesDialog::on_copyProfileButton_clicked() { bool okClicked; - QString name = QInputDialog::getText( - this, tr("Name"), tr("Please enter a name for the new profile"), - QLineEdit::Normal, QString(), &okClicked); + QString name = QInputDialog::getText(this, tr("Name"), + tr("Please enter a name for the new profile"), + QLineEdit::Normal, QString(), &okClicked); fixDirectoryName(name); if (okClicked) { if (name.size() > 0) { try { - const Profile::Ptr currentProfile = ui->profilesList->currentItem() - ->data(Qt::UserRole) - .value<Profile::Ptr>(); + const Profile::Ptr currentProfile = + ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>(); createProfile(name, *currentProfile); - } catch (const std::exception &e) { + } catch (const std::exception& e) { reportError(tr("failed to copy profile: %1").arg(e.what())); } } else { - QMessageBox::warning(this, tr("Invalid name"), - tr("Invalid profile name")); + QMessageBox::warning(this, tr("Invalid name"), tr("Invalid profile name")); } } } void ProfilesDialog::on_removeProfileButton_clicked() { - Profile::Ptr profileToDelete = ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>(); + Profile::Ptr profileToDelete = + ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>(); if (profileToDelete->name() == m_ActiveProfileName) { QMessageBox::warning(this, tr("Deleting active profile"), - tr("Unable to delete active profile. Please change to a different profile first.")); + tr("Unable to delete active profile. Please change to a " + "different profile first.")); return; } - QMessageBox confirmBox(QMessageBox::Question, tr("Confirm"), tr("Are you sure you want to remove this profile (including profile-specific save games, if any)?"), + QMessageBox confirmBox(QMessageBox::Question, tr("Confirm"), + tr("Are you sure you want to remove this profile (including " + "profile-specific save games, if any)?"), QMessageBox::Yes | QMessageBox::No, this); if (confirmBox.exec() == QMessageBox::Yes) { QString profilePath; if (profileToDelete.get() == nullptr) { - profilePath = Settings::instance().paths().profiles() - + "/" + ui->profilesList->currentItem()->text(); - if (QMessageBox::question(this, tr("Profile broken"), - tr("This profile you're about to delete seems to be broken or the path is invalid. " - "I'm about to delete the following folder: \"%1\". Proceed?").arg(profilePath), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) { + profilePath = Settings::instance().paths().profiles() + "/" + + ui->profilesList->currentItem()->text(); + if (QMessageBox::question( + this, tr("Profile broken"), + tr("This profile you're about to delete seems to be broken or the path " + "is invalid. " + "I'm about to delete the following folder: \"%1\". Proceed?") + .arg(profilePath), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) { return; } } else { @@ -255,7 +267,8 @@ void ProfilesDialog::on_removeProfileButton_clicked() delete item; } if (!shellDelete(QStringList(profilePath))) { - log::warn("Failed to shell-delete \"{}\" (errorcode {}), trying regular delete", profilePath, ::GetLastError()); + log::warn("Failed to shell-delete \"{}\" (errorcode {}), trying regular delete", + profilePath, ::GetLastError()); if (!removeDir(profilePath)) { log::warn("regular delete failed too"); } @@ -265,14 +278,15 @@ void ProfilesDialog::on_removeProfileButton_clicked() } } - void ProfilesDialog::on_renameButton_clicked() { - Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>(); + Profile::Ptr currentProfile = + ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>(); if (currentProfile->name() == m_ActiveProfileName) { QMessageBox::warning(this, tr("Renaming active profile"), - tr("The active profile cannot be renamed. Please change to a different profile first.")); + tr("The active profile cannot be renamed. Please change to a " + "different profile first.")); return; } @@ -281,10 +295,9 @@ void ProfilesDialog::on_renameButton_clicked() while (!valid) { bool ok = false; - name = QInputDialog::getText(this, tr("Rename Profile"), tr("New Name"), - QLineEdit::Normal, currentProfile->name(), - &ok); - valid = fixDirectoryName(name); + name = QInputDialog::getText(this, tr("Rename Profile"), tr("New Name"), + QLineEdit::Normal, currentProfile->name(), &ok); + valid = fixDirectoryName(name); if (!ok) { return; } @@ -298,10 +311,9 @@ void ProfilesDialog::on_renameButton_clicked() emit profileRenamed(currentProfile.get(), oldName, name); } - void ProfilesDialog::on_invalidationBox_stateChanged(int state) { - QListWidgetItem *currentItem = ui->profilesList->currentItem(); + QListWidgetItem* currentItem = ui->profilesList->currentItem(); if (currentItem == nullptr) { return; } @@ -313,35 +325,39 @@ void ProfilesDialog::on_invalidationBox_stateChanged(int state) if (!currentProfileVariant.isValid() || currentProfileVariant.isNull()) { return; } - const Profile::Ptr currentProfile = currentItem->data(Qt::UserRole).value<Profile::Ptr>(); + const Profile::Ptr currentProfile = + currentItem->data(Qt::UserRole).value<Profile::Ptr>(); if (state == Qt::Unchecked) { currentProfile->deactivateInvalidation(); } else { currentProfile->activateInvalidation(); } - } catch (const std::exception &e) { + } catch (const std::exception& e) { reportError(tr("failed to change archive invalidation state: %1").arg(e.what())); } } - -void ProfilesDialog::on_profilesList_currentItemChanged(QListWidgetItem *current, QListWidgetItem*) +void ProfilesDialog::on_profilesList_currentItemChanged(QListWidgetItem* current, + QListWidgetItem*) { if (current != nullptr) { - if (!current->data(Qt::UserRole).isValid()) return; - const Profile::Ptr currentProfile = current->data(Qt::UserRole).value<Profile::Ptr>(); + if (!current->data(Qt::UserRole).isValid()) + return; + const Profile::Ptr currentProfile = + current->data(Qt::UserRole).value<Profile::Ptr>(); try { bool invalidationSupported = false; ui->invalidationBox->blockSignals(true); - ui->invalidationBox->setChecked(currentProfile->invalidationActive(&invalidationSupported)); + ui->invalidationBox->setChecked( + currentProfile->invalidationActive(&invalidationSupported)); ui->invalidationBox->setEnabled(invalidationSupported); ui->invalidationBox->blockSignals(false); bool localSaves = currentProfile->localSavesEnabled(); ui->transferButton->setEnabled(localSaves); - // prevent the stateChanged-event for the saves-box from triggering, otherwise it may think local saves - // were disabled and delete the files/rename the dir + // prevent the stateChanged-event for the saves-box from triggering, otherwise it + // may think local saves were disabled and delete the files/rename the dir ui->localSavesBox->blockSignals(true); ui->localSavesBox->setChecked(localSaves); ui->localSavesBox->blockSignals(false); @@ -354,7 +370,8 @@ void ProfilesDialog::on_profilesList_currentItemChanged(QListWidgetItem *current ui->localIniFilesBox->setChecked(currentProfile->localSettingsEnabled()); ui->localIniFilesBox->blockSignals(false); } catch (const std::exception& E) { - reportError(tr("failed to determine if invalidation is active: %1").arg(E.what())); + reportError( + tr("failed to determine if invalidation is active: %1").arg(E.what())); ui->copyProfileButton->setEnabled(false); ui->removeProfileButton->setEnabled(false); ui->renameButton->setEnabled(false); @@ -375,7 +392,8 @@ void ProfilesDialog::on_profilesList_itemActivated(QListWidgetItem* item) void ProfilesDialog::on_localSavesBox_stateChanged(int state) { - Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>(); + Profile::Ptr currentProfile = + ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>(); if (currentProfile->enableLocalSaves(state == Qt::Checked)) { ui->transferButton->setEnabled(state == Qt::Checked); @@ -387,14 +405,16 @@ void ProfilesDialog::on_localSavesBox_stateChanged(int state) void ProfilesDialog::on_transferButton_clicked() { - const Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>(); + const Profile::Ptr currentProfile = + ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>(); TransferSavesDialog transferDialog(*currentProfile, m_Game, this); transferDialog.exec(); } void ProfilesDialog::on_localIniFilesBox_stateChanged(int state) { - Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>(); + Profile::Ptr currentProfile = + ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>(); if (!currentProfile->enableLocalSettings(state == Qt::Checked)) { // revert checkbox-state |
