From 8e591143a5fce58597a1597887b1730e24263224 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Sat, 24 Oct 2020 20:54:22 +0200 Subject: Add IOrganizer::onProfileXXX callbacks. --- src/profilesdialog.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/profilesdialog.cpp') diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index bf6a1d5e..192aaaf3 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -23,6 +23,7 @@ along with Mod Organizer. If not, see . #include "shared/appconfig.h" #include "bsainvalidation.h" #include "iplugingame.h" +#include "organizercore.h" #include "profile.h" #include "profileinputdialog.h" #include "report.h" @@ -49,11 +50,11 @@ using namespace MOShared; Q_DECLARE_METATYPE(Profile::Ptr) -ProfilesDialog::ProfilesDialog(const QString &profileName, MOBase::IPluginGame const *game, QWidget *parent) +ProfilesDialog::ProfilesDialog(const QString &profileName, OrganizerCore &organizer, QWidget *parent) : TutorableDialog("Profiles", parent) , ui(new Ui::ProfilesDialog) , m_FailState(false) - , m_Game(game) + , m_Game(organizer.managedGame()) , m_ActiveProfileName("") { ui->setupUi(this); @@ -72,17 +73,21 @@ ProfilesDialog::ProfilesDialog(const QString &profileName, MOBase::IPluginGame c } } - BSAInvalidation *invalidation = game->feature(); + BSAInvalidation *invalidation = m_Game->feature(); if (invalidation == nullptr) { ui->invalidationBox->setToolTip(tr("Archive invalidation isn't required for this game.")); ui->invalidationBox->setEnabled(false); } - if (!game->feature()) { + if (!m_Game->feature()) { 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); } ProfilesDialog::~ProfilesDialog() @@ -133,9 +138,11 @@ void ProfilesDialog::createProfile(const QString &name, bool useDefaultSettings) { try { QListWidgetItem *newItem = new QListWidgetItem(name, ui->profilesList); - newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(new Profile(name, m_Game, useDefaultSettings)))); + Profile* profile = new Profile(name, m_Game, useDefaultSettings); + newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(profile))); ui->profilesList->addItem(newItem); m_FailState = false; + emit profileCreated(profile); } catch (const std::exception&) { m_FailState = true; throw; @@ -146,9 +153,11 @@ void ProfilesDialog::createProfile(const QString &name, const Profile &reference { try { QListWidgetItem *newItem = new QListWidgetItem(name, ui->profilesList); - newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(Profile::createPtrFrom(name, reference, m_Game)))); + Profile* profile = Profile::createPtrFrom(name, reference, m_Game); + newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(profile))); ui->profilesList->addItem(newItem); m_FailState = false; + emit profileCreated(profile); } catch (const std::exception&) { m_FailState = true; throw; @@ -231,6 +240,8 @@ void ProfilesDialog::on_removeProfileButton_clicked() log::warn("regular delete failed too"); } } + + emit profileRemoved(profileToDelete->name()); } } @@ -254,7 +265,11 @@ void ProfilesDialog::on_renameButton_clicked() } ui->profilesList->currentItem()->setText(name); + + QString oldName = currentProfile->name(); currentProfile->rename(name); + + emit profileRenamed(currentProfile.get(), oldName, name); } -- cgit v1.3.1