Skip to content

Commit

Permalink
Pref AutoDJ: simplify, remove temp config settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed May 28, 2024
1 parent 61bd026 commit 113c113
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 127 deletions.
159 changes: 37 additions & 122 deletions src/preferences/dialog/dlgprefautodj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,181 +8,96 @@ DlgPrefAutoDJ::DlgPrefAutoDJ(QWidget* pParent,
m_pConfig(pConfig) {
setupUi(this);

// The auto-DJ replay-age for randomly-selected tracks
connect(RequeueIgnoreCheckBox,
&QCheckBox::stateChanged,
this,
&DlgPrefAutoDJ::slotToggleRequeueIgnore);

// Auto DJ random enqueue
connect(RandomQueueCheckBox,
&QCheckBox::stateChanged,
this,
&DlgPrefAutoDJ::slotToggleRandomQueue);

setScrollSafeGuardForAllInputWidgets(this);
}

void DlgPrefAutoDJ::slotUpdate() {
// The minimum available for randomly-selected tracks
MinimumAvailableSpinBox->setValue(
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "MinimumAvailable"), 20));
connect(MinimumAvailableSpinBox,
QOverload<int>::of(&QSpinBox::valueChanged),
this,
&DlgPrefAutoDJ::slotSetMinimumAvailable);

// The auto-DJ replay-age for randomly-selected tracks
RequeueIgnoreCheckBox->setChecked(m_pConfig->getValue(
ConfigKey("[Auto DJ]", "UseIgnoreTime"), false));
connect(RequeueIgnoreCheckBox,
&QCheckBox::stateChanged,
this,
&DlgPrefAutoDJ::slotToggleRequeueIgnore);
RequeueIgnoreTimeEdit->setTime(
QTime::fromString(
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "IgnoreTime"), "23:59"),
RequeueIgnoreTimeEdit->displayFormat()));
RequeueIgnoreTimeEdit->setEnabled(
RequeueIgnoreCheckBox->checkState() == Qt::Checked);
connect(RequeueIgnoreTimeEdit,
&QTimeEdit::timeChanged,
this,
&DlgPrefAutoDJ::slotSetRequeueIgnoreTime);

// Auto DJ random enqueue
RandomQueueCheckBox->setChecked(m_pConfig->getValue(
ConfigKey("[Auto DJ]", "EnableRandomQueue"), false));
// 5-arbitrary

RandomQueueMinimumSpinBox->setValue(
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "RandomQueueMinimumAllowed"), 5));
// "[Auto DJ], Requeue" is set by 'Repeat Playlist' toggle in DlgAutoDj GUI.
// If it's checked un-check 'Random Queue'
slotConsiderRepeatPlaylistState(
// TODO Add 'Repeat' checkbox here, or add a hint why the checkbox may be disabled
considerRepeatPlaylistState(
m_pConfig->getValue<bool>(ConfigKey("[Auto DJ]", "Requeue")));
slotToggleRandomQueue(
m_pConfig->getValue<bool>(
ConfigKey("[Auto DJ]", "EnableRandomQueue"))
? Qt::Checked
: Qt::Unchecked);
// Be ready to enable and modify the minimum number and un/check the checkbox
connect(RandomQueueCheckBox,
&QCheckBox::stateChanged,
this,
&DlgPrefAutoDJ::slotToggleRandomQueue);
connect(RandomQueueMinimumSpinBox,
QOverload<int>::of(&QSpinBox::valueChanged),
this,
&DlgPrefAutoDJ::slotSetRandomQueueMin);

setScrollSafeGuardForAllInputWidgets(this);
}

void DlgPrefAutoDJ::slotUpdate() {
}

void DlgPrefAutoDJ::slotApply() {
//Copy from Buffer to actual values
m_pConfig->setValue(ConfigKey("[Auto DJ]","MinimumAvailable"),
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "MinimumAvailableBuff"), 20));
m_pConfig->setValue(ConfigKey("[Auto DJ]", "MinimumAvailable"),
MinimumAvailableSpinBox->value());

m_pConfig->setValue(ConfigKey("[Auto DJ]", "IgnoreTime"),
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "IgnoreTimeBuff"), "23:59"));
m_pConfig->setValue(ConfigKey("[Auto DJ]", "UseIgnoreTime"),
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "UseIgnoreTimeBuff"), false));
RequeueIgnoreCheckBox->isChecked());
const QString ignTimeStr =
RequeueIgnoreTimeEdit->time().toString(RequeueIgnoreTimeEdit->displayFormat());
m_pConfig->setValue(ConfigKey("[Auto DJ]", "IgnoreTime"), ignTimeStr);

m_pConfig->setValue(ConfigKey("[Auto DJ]", "RandomQueueMinimumAllowed"),
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "RandomQueueMinimumAllowedBuff"), 5));
m_pConfig->setValue(ConfigKey("[Auto DJ]", "EnableRandomQueue"),
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "EnableRandomQueueBuff"), false));
}

void DlgPrefAutoDJ::slotCancel() {
// Load actual values and reset Buffer Values where ever needed
MinimumAvailableSpinBox->setValue(
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "MinimumAvailable"), 20));

RequeueIgnoreTimeEdit->setTime(
QTime::fromString(
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "IgnoreTime"), "23:59"),
RequeueIgnoreTimeEdit->displayFormat()));
RequeueIgnoreCheckBox->setChecked(
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "UseIgnoreTime"), false));
RequeueIgnoreTimeEdit->setEnabled(
RequeueIgnoreCheckBox->checkState() == Qt::Checked);
m_pConfig->setValue(ConfigKey("[Auto DJ]", "UseIgnoreTimeBuff"),
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "UseIgnoreTime"), false));

RandomQueueMinimumSpinBox->setValue(
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "RandomQueueMinimumAllowed"), 5));
RandomQueueCheckBox->setChecked(
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "EnableRandomQueue"), false));
m_pConfig->setValue(ConfigKey("[Auto DJ]", "EnableRandomQueueBuff"),
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "EnableRandomQueue"), false));
slotToggleRandomQueue(
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "EnableRandomQueue"), false)
? Qt::Checked
: Qt::Unchecked);
slotToggleRandomQueue(
m_pConfig->getValue<bool>(ConfigKey("[Auto DJ]", "Requeue")));
RandomQueueCheckBox->isChecked());
m_pConfig->setValue(
ConfigKey("[Auto DJ]", "RandomQueueMinimumAllowed"),
RandomQueueMinimumSpinBox->value());
}

void DlgPrefAutoDJ::slotResetToDefaults() {
// Re-queue tracks in AutoDJ
MinimumAvailableSpinBox->setValue(20);

RequeueIgnoreTimeEdit->setTime(QTime::fromString(
"23:59", RequeueIgnoreTimeEdit->displayFormat()));
RequeueIgnoreCheckBox->setChecked(false);
m_pConfig->setValue(ConfigKey("[Auto DJ]", "UseIgnoreTimeBuff"), false);
RequeueIgnoreTimeEdit->setEnabled(false);
RequeueIgnoreTimeEdit->setTime(QTime::fromString(
"23:59", RequeueIgnoreTimeEdit->displayFormat()));

RandomQueueMinimumSpinBox->setValue(5);
RandomQueueCheckBox->setChecked(false);
m_pConfig->setValue(ConfigKey("[Auto DJ]", "EnableRandomQueueBuff"), false);
RandomQueueMinimumSpinBox->setEnabled(false);
RandomQueueCheckBox->setEnabled(true);
}

void DlgPrefAutoDJ::slotSetMinimumAvailable(int a_iValue) {
m_pConfig->setValue(ConfigKey("[Auto DJ]", "MinimumAvailableBuff"), a_iValue);
RandomQueueMinimumSpinBox->setEnabled(false);
RandomQueueMinimumSpinBox->setValue(5);
}

void DlgPrefAutoDJ::slotToggleRequeueIgnore(int buttonState) {
bool checked = buttonState == Qt::Checked;
m_pConfig->setValue(ConfigKey("[Auto DJ]", "UseIgnoreTimeBuff"), checked);
RequeueIgnoreTimeEdit->setEnabled(checked);
}

void DlgPrefAutoDJ::slotSetRequeueIgnoreTime(const QTime& a_rTime) {
QString str = a_rTime.toString(RequeueIgnoreTimeEdit->displayFormat());
m_pConfig->set(ConfigKey("[Auto DJ]", "IgnoreTimeBuff"), str);
}

void DlgPrefAutoDJ::slotSetRandomQueueMin(int a_iValue) {
m_pConfig->setValue(ConfigKey("[Auto DJ]", "RandomQueueMinimumAllowedBuff"), a_iValue);
RequeueIgnoreTimeEdit->setEnabled(buttonState == Qt::Checked);
}

void DlgPrefAutoDJ::slotConsiderRepeatPlaylistState(bool enable) {
if (enable) {
// Requeue is enabled
RandomQueueCheckBox->setChecked(false);
// ToDo(ronso0): Redundant? If programmatic checkbox change is signaled
// to slotToggleRandomQueue
RandomQueueMinimumSpinBox->setEnabled(false);
m_pConfig->setValue(ConfigKey("[Auto DJ]", "EnableRandomQueueBuff"),
false);
} else {
RandomQueueMinimumSpinBox->setEnabled(
m_pConfig->getValue(
ConfigKey("[Auto DJ]", "EnableRandomQueueBuff"), false));
}
void DlgPrefAutoDJ::considerRepeatPlaylistState(bool enable) {
RandomQueueMinimumSpinBox->setEnabled(enable);
}

void DlgPrefAutoDJ::slotToggleRandomQueue(int buttonState) {
bool enable = buttonState == Qt::Checked;
// Toggle the option to select minimum tracks
RandomQueueMinimumSpinBox->setEnabled(enable);
m_pConfig->setValue(ConfigKey("[Auto DJ]", "EnableRandomQueueBuff"),
enable);
RandomQueueMinimumSpinBox->setEnabled(buttonState == Qt::Checked);
}
7 changes: 2 additions & 5 deletions src/preferences/dialog/dlgprefautodj.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ class DlgPrefAutoDJ : public DlgPreferencePage, public Ui::DlgPrefAutoDJDlg {
void slotUpdate() override;
void slotApply() override;
void slotResetToDefaults() override;
void slotCancel() override;

private slots:
void slotSetMinimumAvailable(int);
void slotToggleRequeueIgnore(int buttonState);
void slotSetRequeueIgnoreTime(const QTime& a_rTime);
void slotSetRandomQueueMin(int);
void slotConsiderRepeatPlaylistState(bool);
void slotToggleRandomQueue(int buttonState);

private:
void considerRepeatPlaylistState(bool);

UserSettingsPointer m_pConfig;
};

0 comments on commit 113c113

Please sign in to comment.