Skip to content

Commit

Permalink
Connect onProfileSettingChanged to the Profiles Dialog and emit signa…
Browse files Browse the repository at this point in the history
…l on checkbox values changing.
  • Loading branch information
cram42 committed Aug 3, 2024
1 parent 17ec95e commit 75814c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
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

0 comments on commit 75814c0

Please sign in to comment.