22
33#include < QUrl>
44
5+ #include " library/basetracktablemodel.h"
56#include " library/library_prefs.h"
67#include " library/trackcollection.h"
78#include " library/trackcollectionmanager.h"
@@ -65,11 +66,55 @@ DlgPrefFingerprint::DlgPrefFingerprint(
6566 this ,
6667 &DlgPrefFingerprint::slotClearAllFingerprints);
6768
69+ // clicked(bool), not toggled(bool) -- toggled() also fires for the
70+ // programmatic setChecked() calls below in slotUpdate()/slotResetToDefaults(),
71+ // and we only want to validate on an actual user click.
72+ for (QCheckBox* pCheckBox : {checkBoxCmrtColumnShowArtist,
73+ checkBoxCmrtColumnShowTitle,
74+ checkBoxCmrtColumnShowGroupId,
75+ checkBoxCmrtColumnShowOffset,
76+ checkBoxCmrtColumnShowMatchScore}) {
77+ connect (pCheckBox,
78+ &QCheckBox::clicked,
79+ this ,
80+ &DlgPrefFingerprint::slotCmrtColumnFieldToggled);
81+ }
82+
6883 slotUpdate ();
6984 // No connections needed — the checkbox has no side effects on other
7085 // widgets. slotApply() reads its state directly.
7186}
7287
88+ void DlgPrefFingerprint::slotCmrtColumnFieldToggled () {
89+ const QList<QCheckBox*> fieldCheckBoxes = {
90+ checkBoxCmrtColumnShowArtist,
91+ checkBoxCmrtColumnShowTitle,
92+ checkBoxCmrtColumnShowGroupId,
93+ checkBoxCmrtColumnShowOffset,
94+ checkBoxCmrtColumnShowMatchScore};
95+
96+ // Constraint 1: at least one field must stay checked. If the user's
97+ // click just unchecked the last one, undo it -- QSignalBlocker
98+ // prevents this programmatic setChecked() from re-entering this slot.
99+ const bool anyChecked = std::any_of (fieldCheckBoxes.begin (),
100+ fieldCheckBoxes.end (),
101+ [](QCheckBox* pCheckBox) { return pCheckBox->isChecked (); });
102+ if (!anyChecked) {
103+ // sender() is whichever checkbox the user just clicked -- it's
104+ // the one that needs to be reverted back to checked.
105+ auto * pClicked = qobject_cast<QCheckBox*>(sender ());
106+ if (pClicked) {
107+ const QSignalBlocker blocker (pClicked);
108+ pClicked->setChecked (true );
109+ }
110+ }
111+
112+ // Constraint 2: Append/Prepend only matters when a name is shown.
113+ const bool nameShown = checkBoxCmrtColumnShowArtist->isChecked () ||
114+ checkBoxCmrtColumnShowTitle->isChecked ();
115+ checkBoxCmrtColumnGroupIdAppend->setEnabled (nameShown);
116+ }
117+
73118void DlgPrefFingerprint::slotUpdate () {
74119 const bool fingerprintEnabled = m_pConfig->getValue (
75120 kFingerprintAnalysisEnabledConfigKey , false );
@@ -88,6 +133,44 @@ void DlgPrefFingerprint::slotUpdate() {
88133 // Stored as a 0.0-1.0 fraction; the spin box shows it as a percentage.
89134 spinBoxCmrtMatchThreshold->setValue (matchThreshold * 100.0 );
90135
136+ const bool showArtist = m_pConfig->getValue (
137+ kCmrtColumnShowArtistConfigKey , BaseTrackTableModel::kCmrtColumnShowArtistDefault );
138+ checkBoxCmrtColumnShowArtist->setChecked (showArtist);
139+ BaseTrackTableModel::setCmrtColumnShowArtist (showArtist);
140+
141+ const bool showTitle = m_pConfig->getValue (
142+ kCmrtColumnShowTitleConfigKey , BaseTrackTableModel::kCmrtColumnShowTitleDefault );
143+ checkBoxCmrtColumnShowTitle->setChecked (showTitle);
144+ BaseTrackTableModel::setCmrtColumnShowTitle (showTitle);
145+
146+ const bool showGroupId = m_pConfig->getValue (
147+ kCmrtColumnShowGroupIdConfigKey , BaseTrackTableModel::kCmrtColumnShowGroupIdDefault );
148+ checkBoxCmrtColumnShowGroupId->setChecked (showGroupId);
149+ BaseTrackTableModel::setCmrtColumnShowGroupId (showGroupId);
150+
151+ const bool showOffset = m_pConfig->getValue (
152+ kCmrtColumnShowOffsetConfigKey , BaseTrackTableModel::kCmrtColumnShowOffsetDefault );
153+ checkBoxCmrtColumnShowOffset->setChecked (showOffset);
154+ BaseTrackTableModel::setCmrtColumnShowOffset (showOffset);
155+
156+ const bool showMatchScore = m_pConfig->getValue (
157+ kCmrtColumnShowMatchScoreConfigKey ,
158+ BaseTrackTableModel::kCmrtColumnShowMatchScoreDefault );
159+ checkBoxCmrtColumnShowMatchScore->setChecked (showMatchScore);
160+ BaseTrackTableModel::setCmrtColumnShowMatchScore (showMatchScore);
161+
162+ const bool groupIdAppend = m_pConfig->getValue (
163+ kCmrtColumnGroupIdPositionConfigKey ,
164+ BaseTrackTableModel::kCmrtColumnGroupIdAppendDefault );
165+ checkBoxCmrtColumnGroupIdAppend->setChecked (groupIdAppend);
166+ checkBoxCmrtColumnGroupIdAppend->setEnabled (showArtist || showTitle);
167+ BaseTrackTableModel::setCmrtColumnGroupIdAppend (groupIdAppend);
168+
169+ const QString delimiter = m_pConfig->getValue (
170+ kCmrtColumnDelimiterConfigKey , BaseTrackTableModel::kCmrtColumnDelimiterDefault );
171+ lineEditCmrtColumnDelimiter->setText (delimiter);
172+ BaseTrackTableModel::setCmrtColumnDelimiter (delimiter);
173+
91174 setAcoustIdGroupEnabled (fingerprintEnabled);
92175}
93176
@@ -110,13 +193,60 @@ void DlgPrefFingerprint::slotApply() {
110193 m_pConfig->set (
111194 kCmrtMatchThresholdConfigKey ,
112195 ConfigValue{spinBoxCmrtMatchThreshold->value () / 100.0 });
196+
197+ const bool showArtist = checkBoxCmrtColumnShowArtist->isChecked ();
198+ m_pConfig->set (kCmrtColumnShowArtistConfigKey , ConfigValue{showArtist});
199+ BaseTrackTableModel::setCmrtColumnShowArtist (showArtist);
200+
201+ const bool showTitle = checkBoxCmrtColumnShowTitle->isChecked ();
202+ m_pConfig->set (kCmrtColumnShowTitleConfigKey , ConfigValue{showTitle});
203+ BaseTrackTableModel::setCmrtColumnShowTitle (showTitle);
204+
205+ const bool showGroupId = checkBoxCmrtColumnShowGroupId->isChecked ();
206+ m_pConfig->set (kCmrtColumnShowGroupIdConfigKey , ConfigValue{showGroupId});
207+ BaseTrackTableModel::setCmrtColumnShowGroupId (showGroupId);
208+
209+ const bool showOffset = checkBoxCmrtColumnShowOffset->isChecked ();
210+ m_pConfig->set (kCmrtColumnShowOffsetConfigKey , ConfigValue{showOffset});
211+ BaseTrackTableModel::setCmrtColumnShowOffset (showOffset);
212+
213+ const bool showMatchScore = checkBoxCmrtColumnShowMatchScore->isChecked ();
214+ m_pConfig->set (kCmrtColumnShowMatchScoreConfigKey , ConfigValue{showMatchScore});
215+ BaseTrackTableModel::setCmrtColumnShowMatchScore (showMatchScore);
216+
217+ const bool groupIdAppend = checkBoxCmrtColumnGroupIdAppend->isChecked ();
218+ m_pConfig->set (kCmrtColumnGroupIdPositionConfigKey , ConfigValue{groupIdAppend});
219+ BaseTrackTableModel::setCmrtColumnGroupIdAppend (groupIdAppend);
220+
221+ const QString delimiter = lineEditCmrtColumnDelimiter->text ();
222+ m_pConfig->set (kCmrtColumnDelimiterConfigKey , ConfigValue{delimiter});
223+ BaseTrackTableModel::setCmrtColumnDelimiter (delimiter);
113224}
114225
115226void DlgPrefFingerprint::slotResetToDefaults () {
116227 checkBoxFingerprintEnabled->setChecked (false );
117228 lineEditAcoustIdApiKey->clear ();
118229 checkBoxAcoustIdAutoSubmit->setChecked (false );
119230 spinBoxCmrtMatchThreshold->setValue (kCmrtMatchThresholdDefault * 100.0 );
231+
232+ checkBoxCmrtColumnShowArtist->setChecked (BaseTrackTableModel::kCmrtColumnShowArtistDefault );
233+ checkBoxCmrtColumnShowTitle->setChecked (BaseTrackTableModel::kCmrtColumnShowTitleDefault );
234+ checkBoxCmrtColumnShowGroupId->setChecked (BaseTrackTableModel::kCmrtColumnShowGroupIdDefault );
235+ checkBoxCmrtColumnShowOffset->setChecked (BaseTrackTableModel::kCmrtColumnShowOffsetDefault );
236+ checkBoxCmrtColumnShowMatchScore->setChecked (
237+ BaseTrackTableModel::kCmrtColumnShowMatchScoreDefault );
238+
239+ checkBoxCmrtColumnGroupIdAppend->setChecked (
240+ BaseTrackTableModel::kCmrtColumnGroupIdAppendDefault );
241+
242+ lineEditCmrtColumnDelimiter->setText (BaseTrackTableModel::kCmrtColumnDelimiterDefault );
243+
244+ // Re-run constraint checks once so the UI reflects the correct state
245+ // Defaults are Artist=on, Title=on, so Append/Prepend ends up enabled after a reset.
246+ checkBoxCmrtColumnGroupIdAppend->setEnabled (
247+ checkBoxCmrtColumnShowArtist->isChecked () ||
248+ checkBoxCmrtColumnShowTitle->isChecked ());
249+
120250 // Reflect the cleared state immediately in the UI.
121251 setAcoustIdGroupEnabled (false );
122252}
0 commit comments