From 17ec95ed1b4fb024e1380a7d7e6c9f88ee0595f8 Mon Sep 17 00:00:00 2001 From: Cram42 Date: Sat, 3 Aug 2024 11:44:00 +0800 Subject: [PATCH 1/2] Add support for onProfileSettingChanged for callback registration for the new profileSettingChanged signal. --- src/organizercore.cpp | 14 ++++++++++++++ src/organizercore.h | 8 ++++++++ src/organizerproxy.cpp | 10 ++++++++++ src/organizerproxy.h | 4 ++++ 4 files changed, 36 insertions(+) diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 0f6a14551..95dea7319 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -354,6 +354,13 @@ void OrganizerCore::profileRemoved(QString const& profileName) m_ProfileRemoved(profileName); } +void OrganizerCore::profileSettingChanged(MOBase::IProfile* profile, const QString& settingName, + const QVariant& oldValue, const QVariant& newValue) +{ + m_ProfileSettingChanged(profile, settingName, oldValue, newValue); +} + + void OrganizerCore::downloadRequested(QNetworkReply* reply, QString gameName, int modID, const QString& fileName) { @@ -1203,6 +1210,13 @@ OrganizerCore::onProfileChanged(std::function const& return m_ProfileChanged.connect(func); } +boost::signals2::connection OrganizerCore::onProfileSettingChanged( + std::function const& func) +{ + return m_ProfileSettingChanged.connect(func); +} + boost::signals2::connection OrganizerCore::onPluginSettingChanged( std::function const& func) diff --git a/src/organizercore.h b/src/organizercore.h index 923adc12d..b6f57cfb8 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -95,6 +95,8 @@ class OrganizerCore : public QObject, public MOBase::IPluginDiagnose using SignalProfileRemoved = boost::signals2::signal; using SignalProfileChanged = boost::signals2::signal; + using SignalProfileSettingChanged = boost::signals2::signal; using SignalPluginSettingChanged = boost::signals2::signal; using SignalPluginEnabled = boost::signals2::signal; @@ -402,6 +404,9 @@ class OrganizerCore : public QObject, public MOBase::IPluginDiagnose onProfileRemoved(std::function const& func); boost::signals2::connection onProfileChanged( std::function const& func); + boost::signals2::connection onProfileSettingChanged( + std::function const& func); boost::signals2::connection onPluginSettingChanged( std::function const& func); @@ -452,6 +457,8 @@ public slots: void profileRenamed(MOBase::IProfile* profile, QString const& oldName, QString const& newName); void profileRemoved(QString const& profileName); + void profileSettingChanged(MOBase::IProfile* profile, const QString& settingName, + const QVariant& oldValue, const QVariant& newValue); bool nexusApi(bool retry = false); @@ -544,6 +551,7 @@ private slots: SignalProfileRenamed m_ProfileRenamed; SignalProfileRemoved m_ProfileRemoved; SignalProfileChanged m_ProfileChanged; + SignalProfileSettingChanged m_ProfileSettingChanged; SignalPluginSettingChanged m_PluginSettingChanged; SignalPluginEnabled m_PluginEnabled; SignalPluginEnabled m_PluginDisabled; diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index 6edbdbab7..d65e130d5 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -50,6 +50,8 @@ void OrganizerProxy::connectSignals() m_Proxied->onProfileRemoved(callSignalIfPluginActive(this, m_ProfileRemoved))); m_Connections.push_back( m_Proxied->onProfileChanged(callSignalIfPluginActive(this, m_ProfileChanged))); + m_Connections.push_back( + m_Proxied->onProfileSettingChanged(callSignalIfPluginActive(this, m_ProfileSettingChanged))); m_Connections.push_back(m_Proxied->onUserInterfaceInitialized( callSignalAlways(m_UserInterfaceInitialized))); @@ -395,6 +397,14 @@ bool OrganizerProxy::onProfileChanged( { return m_ProfileChanged.connect(func).connected(); } + +bool OrganizerProxy::onProfileSettingChanged( + std::function const& func) +{ + return m_ProfileSettingChanged.connect(func).connected(); +} + // Always call these one, otherwise plugin cannot detect they are being enabled / // disabled: bool OrganizerProxy::onPluginSettingChanged( diff --git a/src/organizerproxy.h b/src/organizerproxy.h index fbae7cde6..377606f90 100644 --- a/src/organizerproxy.h +++ b/src/organizerproxy.h @@ -93,6 +93,9 @@ class OrganizerProxy : public MOBase::IOrganizer onProfileRemoved(std::function const& func) override; virtual bool onProfileChanged( std::function const& func) override; + virtual bool onProfileSettingChanged( + std::function const& func) override; // Plugin related: virtual bool isPluginEnabled(QString const& pluginName) const override; @@ -145,6 +148,7 @@ class OrganizerProxy : public MOBase::IOrganizer OrganizerCore::SignalProfileRenamed m_ProfileRenamed; OrganizerCore::SignalProfileRemoved m_ProfileRemoved; OrganizerCore::SignalProfileChanged m_ProfileChanged; + OrganizerCore::SignalProfileSettingChanged m_ProfileSettingChanged; OrganizerCore::SignalPluginSettingChanged m_PluginSettingChanged; OrganizerCore::SignalPluginEnabled m_PluginEnabled; OrganizerCore::SignalPluginEnabled m_PluginDisabled; From 75814c0fde2fa23f1580338d2e29f9d9a28818db Mon Sep 17 00:00:00 2001 From: Cram42 Date: Sat, 3 Aug 2024 11:54:38 +0800 Subject: [PATCH 2/2] Connect onProfileSettingChanged to the Profiles Dialog and emit signal on checkbox values changing. --- src/profilesdialog.cpp | 26 ++++++++++++++++++-------- src/profilesdialog.h | 6 ++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 24eddc204..7d485e44a 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -91,6 +91,8 @@ ProfilesDialog::ProfilesDialog(const QString& profileName, OrganizerCore& organi &OrganizerCore::profileRenamed); connect(this, &ProfilesDialog::profileRemoved, &organizer, &OrganizerCore::profileRemoved); + connect(this, &ProfilesDialog::profileSettingChanged, &organizer, + &OrganizerCore::profileSettingChanged); } ProfilesDialog::~ProfilesDialog() @@ -328,11 +330,14 @@ void ProfilesDialog::on_invalidationBox_stateChanged(int state) } const Profile::Ptr currentProfile = currentItem->data(Qt::UserRole).value(); - if (state == Qt::Unchecked) { - currentProfile->deactivateInvalidation(); - } else { + + bool enable = (state == Qt::Checked); + if (enable) { currentProfile->activateInvalidation(); + } else { + currentProfile->deactivateInvalidation(); } + emit profileSettingChanged(currentProfile.get(), "Invalidation", !enable, enable); } catch (const std::exception& e) { reportError(tr("failed to change archive invalidation state: %1").arg(e.what())); } @@ -396,11 +401,13 @@ void ProfilesDialog::on_localSavesBox_stateChanged(int state) Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value(); - if (currentProfile->enableLocalSaves(state == Qt::Checked)) { - ui->transferButton->setEnabled(state == Qt::Checked); + bool enable = (state == Qt::Checked); + if (currentProfile->enableLocalSaves(enable)) { + ui->transferButton->setEnabled(enable); + emit profileSettingChanged(currentProfile.get(), "LocalSaves", !enable, enable); } else { // revert checkbox-state - ui->localSavesBox->setChecked(state != Qt::Checked); + ui->localSavesBox->setChecked(!enable); } } @@ -417,8 +424,11 @@ void ProfilesDialog::on_localIniFilesBox_stateChanged(int state) Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value(); - if (!currentProfile->enableLocalSettings(state == Qt::Checked)) { + bool enable = (state == Qt::Checked); + if (currentProfile->enableLocalSettings(enable)) { + emit profileSettingChanged(currentProfile.get(), "LocalSettings", !enable, enable); + } else { // revert checkbox-state - ui->localIniFilesBox->setChecked(state != Qt::Checked); + ui->localIniFilesBox->setChecked(!enable); } } diff --git a/src/profilesdialog.h b/src/profilesdialog.h index 1a2a36e24..139133d51 100644 --- a/src/profilesdialog.h +++ b/src/profilesdialog.h @@ -93,6 +93,12 @@ class ProfilesDialog : public MOBase::TutorableDialog */ void profileRemoved(QString const& profileName); + /** + * @brief Signal emitted when a profile's setting has been changed. + */ + void profileSettingChanged(Profile* profile, const QString& settingName, + const QVariant& oldValue, const QVariant& newValue); + protected: virtual void showEvent(QShowEvent* event);