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/mainwindow.cpp | 6 +++--- src/organizercore.cpp | 32 ++++++++++++++++++++++++++++++++ src/organizercore.h | 13 +++++++++++++ src/organizerproxy.cpp | 15 +++++++++++++++ src/organizerproxy.h | 15 +++++++++------ src/profilesdialog.cpp | 27 +++++++++++++++++++++------ src/profilesdialog.h | 21 ++++++++++++++++++++- 7 files changed, 113 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3428d72a..18cc85f0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1765,9 +1765,9 @@ void MainWindow::on_profileBox_currentIndexChanged(int index) if (ui->profileBox->currentIndex() == 0) { ui->profileBox->setCurrentIndex(previousIndex); - ProfilesDialog(ui->profileBox->currentText(), m_OrganizerCore.managedGame(), this).exec(); + ProfilesDialog(ui->profileBox->currentText(), m_OrganizerCore, this).exec(); while (!refreshProfiles()) { - ProfilesDialog(ui->profileBox->currentText(), m_OrganizerCore.managedGame(), this).exec(); + ProfilesDialog(ui->profileBox->currentText(), m_OrganizerCore, this).exec(); } } else { activateSelectedProfile(); @@ -2432,7 +2432,7 @@ void MainWindow::on_actionAdd_Profile_triggered() { for (;;) { ProfilesDialog profilesDialog(m_OrganizerCore.currentProfile()->name(), - m_OrganizerCore.managedGame(), + m_OrganizerCore, this); // workaround: need to disable monitoring of the saves directory, otherwise the active diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 2aaeb86c..7c975053 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -378,6 +378,22 @@ void OrganizerCore::userInterfaceInitialized() m_UserInterfaceInitialized(m_UserInterface->mainWindow()); } +void OrganizerCore::profileCreated(MOBase::IProfile* profile) +{ + m_ProfileCreated(profile); +} + +void OrganizerCore::profileRenamed(MOBase::IProfile* profile, QString const& oldName, QString const& newName) +{ + m_ProfileRenamed(profile, oldName, newName); +} + +void OrganizerCore::profileRemoved(QString const& profileName) +{ + m_ProfileRemoved(profileName); +} + + void OrganizerCore::externalMessage(const QString &message) { if (MOShortcut moshortcut{ message } ) { @@ -470,6 +486,7 @@ void OrganizerCore::createDefaultProfile() if (QDir(profilesPath).entryList(QDir::AllDirs | QDir::NoDotAndDotDot).size() == 0) { Profile newProf("Default", managedGame(), false); + m_ProfileCreated(&newProf); } } @@ -1144,6 +1161,21 @@ bool OrganizerCore::onUserInterfaceInitialized(std::function return m_UserInterfaceInitialized.connect(func).connected(); } +bool OrganizerCore::onProfileCreated(std::function const& func) +{ + return m_ProfileCreated.connect(func).connected(); +} + +bool OrganizerCore::onProfileRenamed(std::function const& func) +{ + return m_ProfileRenamed.connect(func).connected(); +} + +bool OrganizerCore::onProfileRemoved(std::function const& func) +{ + return m_ProfileRemoved.connect(func).connected(); +} + bool OrganizerCore::onProfileChanged(std::function const& func) { return m_ProfileChanged.connect(func).connected(); diff --git a/src/organizercore.h b/src/organizercore.h index 813bf084..b545e4d7 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -82,6 +82,9 @@ private: using SignalFinishedRunApplication = boost::signals2::signal; using SignalModInstalled = boost::signals2::signal; using SignalUserInterfaceInitialized = boost::signals2::signal; + using SignalProfileCreated = boost::signals2::signal; + using SignalProfileRenamed = boost::signals2::signal; + using SignalProfileRemoved = boost::signals2::signal; using SignalProfileChanged = boost::signals2::signal; using SignalPluginSettingChanged = boost::signals2::signal; @@ -326,6 +329,9 @@ public: bool onAboutToRun(const std::function& func); bool onFinishedRun(const std::function& func); bool onUserInterfaceInitialized(std::function const& func); + bool onProfileCreated(std::function const& func); + bool onProfileRenamed(std::function const& func); + bool onProfileRemoved(std::function const& func); bool onProfileChanged(std::function const& func); bool onPluginSettingChanged(std::function const& func); @@ -367,6 +373,10 @@ public slots: void userInterfaceInitialized(); + void profileCreated(MOBase::IProfile* profile); + void profileRenamed(MOBase::IProfile* profile, QString const& oldName, QString const& newName); + void profileRemoved(QString const& profileName); + bool nexusApi(bool retry = false); signals: @@ -442,6 +452,9 @@ private: SignalFinishedRunApplication m_FinishedRun; SignalModInstalled m_ModInstalled; SignalUserInterfaceInitialized m_UserInterfaceInitialized; + SignalProfileCreated m_ProfileCreated; + SignalProfileRenamed m_ProfileRenamed; + SignalProfileRemoved m_ProfileRemoved; SignalProfileChanged m_ProfileChanged; SignalPluginSettingChanged m_PluginSettingChanged; diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index 2932e6bf..df73603a 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -282,6 +282,21 @@ bool OrganizerProxy::onUserInterfaceInitialized(std::functiononUserInterfaceInitialized(func); } +bool OrganizerProxy::onProfileCreated(std::function const& func) +{ + return m_Proxied->onProfileCreated(MOShared::callIfPluginActive(this, func)); +} + +bool OrganizerProxy::onProfileRenamed(std::function const& func) +{ + return m_Proxied->onProfileRenamed(MOShared::callIfPluginActive(this, func)); +} + +bool OrganizerProxy::onProfileRemoved(std::function const& func) +{ + return m_Proxied->onProfileRemoved(MOShared::callIfPluginActive(this, func)); +} + bool OrganizerProxy::onProfileChanged(std::function const& func) { return m_Proxied->onProfileChanged(MOShared::callIfPluginActive(this, func)); diff --git a/src/organizerproxy.h b/src/organizerproxy.h index cc059aa9..376d1a1a 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -59,12 +59,15 @@ public: virtual bool waitForApplication(HANDLE handle, LPDWORD exitCode = nullptr) const; virtual void refreshModList(bool saveChanges); - virtual bool onAboutToRun(const std::function &func); - virtual bool onFinishedRun(const std::function &func); - virtual bool onModInstalled(const std::function &func); - virtual bool onUserInterfaceInitialized(std::function const& func); - virtual bool onProfileChanged(std::function const& func); - virtual bool onPluginSettingChanged(std::function const& func); + virtual bool onAboutToRun(const std::function &func) override; + virtual bool onFinishedRun(const std::function &func) override; + virtual bool onModInstalled(const std::function &func) override; + virtual bool onUserInterfaceInitialized(std::function const& func) override; + virtual bool onProfileCreated(std::function const& func) override; + virtual bool onProfileRenamed(std::function const& func) override; + virtual bool onProfileRemoved(std::function const& func) override; + virtual bool onProfileChanged(std::function const& func) override; + virtual bool onPluginSettingChanged(std::function const& func) override; virtual MOBase::IPluginGame const *managedGame() const; 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); } diff --git a/src/profilesdialog.h b/src/profilesdialog.h index a47367be..08298d0e 100644 --- a/src/profilesdialog.h +++ b/src/profilesdialog.h @@ -22,6 +22,7 @@ along with Mod Organizer. If not, see . #include "tutorabledialog.h" class Profile; +class OrganizerCore; class QListWidget; class QListWidgetItem; @@ -46,9 +47,10 @@ public: * @brief constructor * * @param profileName currently enabled profile + * @param organizer * @param parent parent widget **/ - explicit ProfilesDialog(const QString &profileName, MOBase::IPluginGame const *game, QWidget *parent = 0); + explicit ProfilesDialog(const QString &profileName, OrganizerCore &organizer, QWidget *parent = 0); ~ProfilesDialog(); // also saves and restores geometry @@ -61,6 +63,23 @@ public: **/ bool failed() const { return m_FailState; } +signals: + + /** + * @brief Signal emitted when a profile is created. + */ + void profileCreated(Profile* profile); + + /** + * @brief Signal emitted when a profile is renamed. + */ + void profileRenamed(Profile* profile, QString const& oldName, QString const& newName); + + /** + * @brief Signal emitted when a profile has been removed. + */ + void profileRemoved(QString const& profileName); + protected: virtual void showEvent(QShowEvent *event); -- cgit v1.3.1 From 87a53eabd507a32500118fc5963538dc3b05ad4d Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sat, 24 Oct 2020 21:03:35 +0200 Subject: Wrap profile in Profile::Ptr when creating. --- src/profilesdialog.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 192aaaf3..14bf0da5 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -138,11 +138,11 @@ void ProfilesDialog::createProfile(const QString &name, bool useDefaultSettings) { try { QListWidgetItem *newItem = new QListWidgetItem(name, ui->profilesList); - Profile* profile = new Profile(name, m_Game, useDefaultSettings); - newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(profile))); + auto profile = Profile::Ptr(new Profile(name, m_Game, useDefaultSettings)); + newItem->setData(Qt::UserRole, QVariant::fromValue(profile)); ui->profilesList->addItem(newItem); m_FailState = false; - emit profileCreated(profile); + emit profileCreated(profile.get()); } catch (const std::exception&) { m_FailState = true; throw; @@ -153,11 +153,11 @@ void ProfilesDialog::createProfile(const QString &name, const Profile &reference { try { QListWidgetItem *newItem = new QListWidgetItem(name, ui->profilesList); - Profile* profile = Profile::createPtrFrom(name, reference, m_Game); - newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(profile))); + auto profile = Profile::Ptr(Profile::createPtrFrom(name, reference, m_Game)); + newItem->setData(Qt::UserRole, QVariant::fromValue(profile)); ui->profilesList->addItem(newItem); m_FailState = false; - emit profileCreated(profile); + emit profileCreated(profile.get()); } catch (const std::exception&) { m_FailState = true; throw; -- cgit v1.3.1