Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onProfileSettingChanged #2088

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/organizercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -1203,6 +1210,13 @@ OrganizerCore::onProfileChanged(std::function<void(IProfile*, IProfile*)> const&
return m_ProfileChanged.connect(func);
}

boost::signals2::connection OrganizerCore::onProfileSettingChanged(
std::function<void(IProfile*, const QString& key, const QVariant&,
const QVariant&)> const& func)
{
return m_ProfileSettingChanged.connect(func);
}

boost::signals2::connection OrganizerCore::onPluginSettingChanged(
std::function<void(QString const&, const QString& key, const QVariant&,
const QVariant&)> const& func)
Expand Down
8 changes: 8 additions & 0 deletions src/organizercore.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class OrganizerCore : public QObject, public MOBase::IPluginDiagnose
using SignalProfileRemoved = boost::signals2::signal<void(QString const&)>;
using SignalProfileChanged =
boost::signals2::signal<void(MOBase::IProfile*, MOBase::IProfile*)>;
using SignalProfileSettingChanged = boost::signals2::signal<void(
MOBase::IProfile*, const QString& key, const QVariant&, const QVariant&)>;
using SignalPluginSettingChanged = boost::signals2::signal<void(
QString const&, const QString& key, const QVariant&, const QVariant&)>;
using SignalPluginEnabled = boost::signals2::signal<void(const MOBase::IPlugin*)>;
Expand Down Expand Up @@ -402,6 +404,9 @@ class OrganizerCore : public QObject, public MOBase::IPluginDiagnose
onProfileRemoved(std::function<void(QString const&)> const& func);
boost::signals2::connection onProfileChanged(
std::function<void(MOBase::IProfile*, MOBase::IProfile*)> const& func);
boost::signals2::connection onProfileSettingChanged(
std::function<void(MOBase::IProfile*, const QString& key, const QVariant&,
const QVariant&)> const& func);
boost::signals2::connection onPluginSettingChanged(
std::function<void(QString const&, const QString& key, const QVariant&,
const QVariant&)> const& func);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/organizerproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -395,6 +397,14 @@ bool OrganizerProxy::onProfileChanged(
{
return m_ProfileChanged.connect(func).connected();
}

bool OrganizerProxy::onProfileSettingChanged(
std::function<void(MOBase::IProfile*, const QString& key, const QVariant&,
const QVariant&)> const& func)
{
return m_ProfileSettingChanged.connect(func).connected();
}

// Always call these one, otherwise plugin cannot detect they are being enabled /
// disabled:
bool OrganizerProxy::onPluginSettingChanged(
Expand Down
4 changes: 4 additions & 0 deletions src/organizerproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class OrganizerProxy : public MOBase::IOrganizer
onProfileRemoved(std::function<void(QString const&)> const& func) override;
virtual bool onProfileChanged(
std::function<void(MOBase::IProfile*, MOBase::IProfile*)> const& func) override;
virtual bool onProfileSettingChanged(
std::function<void(MOBase::IProfile*, const QString& key, const QVariant&,
const QVariant&)> const& func) override;

// Plugin related:
virtual bool isPluginEnabled(QString const& pluginName) const override;
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 18 additions & 8 deletions src/profilesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -328,11 +330,14 @@ void ProfilesDialog::on_invalidationBox_stateChanged(int state)
}
const Profile::Ptr currentProfile =
currentItem->data(Qt::UserRole).value<Profile::Ptr>();
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()));
}
Expand Down Expand Up @@ -396,11 +401,13 @@ void ProfilesDialog::on_localSavesBox_stateChanged(int state)
Profile::Ptr currentProfile =
ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>();

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);
}
}

Expand All @@ -417,8 +424,11 @@ void ProfilesDialog::on_localIniFilesBox_stateChanged(int state)
Profile::Ptr currentProfile =
ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>();

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);
}
}
6 changes: 6 additions & 0 deletions src/profilesdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading