Skip to content

Commit c9aef25

Browse files
committed
Prefs: Add "Clear All Fingerprints" button to fingerprint preferences page
1 parent 77ae456 commit c9aef25

4 files changed

Lines changed: 91 additions & 9 deletions

File tree

src/preferences/dialog/dlgpreferences.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,14 @@ DlgPreferences::DlgPreferences(
230230
new QTreeWidgetItem(contentsTreeWidget, QTreeWidgetItem::Type)),
231231
tr("Key Detection"),
232232
"ic_preferences_keydetect.svg");
233-
addPageWidget(PreferencesPage(
234-
new DlgPrefFingerprint(this, m_pConfig),
235-
new QTreeWidgetItem(contentsTreeWidget, QTreeWidgetItem::Type)),
233+
addPageWidget(PreferencesPage(new DlgPrefFingerprint(this,
234+
m_pConfig,
235+
pLibrary->trackCollectionManager()),
236+
new QTreeWidgetItem(
237+
contentsTreeWidget, QTreeWidgetItem::Type)),
236238
tr("Fingerprint Analysis"),
237-
"ic_preferences_bpmdetect.svg"); // TODO(CMRT): replace with dedicated fingerprint icon
239+
"ic_preferences_bpmdetect.svg"); // TODO(CMRT): replace with
240+
// dedicated fingerprint icon
238241
addPageWidget(PreferencesPage(
239242
new DlgPrefReplayGain(this, m_pConfig),
240243
new QTreeWidgetItem(contentsTreeWidget, QTreeWidgetItem::Type)),

src/preferences/dialog/dlgpreffingerprint.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ const QString kAcoustIdApiKeyUrl =
1818

1919
} // anonymous namespace
2020

21-
DlgPrefFingerprint::DlgPrefFingerprint(QWidget* parent, UserSettingsPointer pConfig)
21+
DlgPrefFingerprint::DlgPrefFingerprint(
22+
QWidget* parent,
23+
UserSettingsPointer pConfig,
24+
TrackCollectionManager* pTrackCollectionManager)
2225
: DlgPreferencePage(parent),
23-
m_pConfig(pConfig) {
26+
m_pConfig(pConfig),
27+
m_pTrackCollectionManager(pTrackCollectionManager) {
2428
setupUi(this);
2529

2630
// Build the "Get your key ↗" link using the preference page's link colour
@@ -56,6 +60,11 @@ DlgPrefFingerprint::DlgPrefFingerprint(QWidget* parent, UserSettingsPointer pCon
5660
}
5761
});
5862

63+
connect(btnClearAllFingerprints,
64+
&QPushButton::clicked,
65+
this,
66+
&DlgPrefFingerprint::slotClearAllFingerprints);
67+
5968
slotUpdate();
6069
// No connections needed — the checkbox has no side effects on other
6170
// widgets. slotApply() reads its state directly.
@@ -122,3 +131,39 @@ void DlgPrefFingerprint::setAcoustIdGroupEnabled(bool fingerprintEnabled) {
122131
}
123132
}
124133
}
134+
135+
void DlgPrefFingerprint::slotClearAllFingerprints() {
136+
// Confirmation dialog — same pattern as slotRemoveDir() in DlgPrefLibrary.
137+
QMessageBox msgBox;
138+
msgBox.setIcon(QMessageBox::Warning);
139+
msgBox.setWindowTitle(tr("Clear All Fingerprints?"));
140+
msgBox.setText(tr(
141+
"This will delete all stored Chromaprint fingerprints, AcoustID queue "
142+
"entries, and CMRT group memberships for every track in your library."
143+
"Tracks will be re-fingerprinted the next time fingerprint analysis runs."
144+
"This cannot be undone."));
145+
QPushButton* clearButton = msgBox.addButton(
146+
tr("Clear All"), QMessageBox::DestructiveRole);
147+
msgBox.addButton(QMessageBox::Cancel);
148+
msgBox.setDefaultButton(QMessageBox::Cancel);
149+
msgBox.exec();
150+
151+
if (msgBox.clickedButton() != clearButton) {
152+
return;
153+
}
154+
155+
if (!m_pTrackCollectionManager) {
156+
qWarning() << "DlgPrefFingerprint::slotClearAllFingerprints: "
157+
"no TrackCollectionManager available";
158+
return;
159+
}
160+
161+
TrackFingerprintDao& dao =
162+
m_pTrackCollectionManager->internalCollection()->getTrackFingerprintDAO();
163+
const int cleared = dao.clearAllFingerprintData();
164+
165+
QMessageBox::information(
166+
this,
167+
tr("Fingerprints Cleared"),
168+
tr("Cleared fingerprint data for %n track(s).", "", cleared));
169+
}

src/preferences/dialog/dlgpreffingerprint.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class TrackCollectionManager;
99
class DlgPrefFingerprint : public DlgPreferencePage, public Ui::DlgPrefFingerprintDlg {
1010
Q_OBJECT
1111
public:
12-
DlgPrefFingerprint(QWidget* parent, UserSettingsPointer pConfig);
12+
DlgPrefFingerprint(QWidget* parent,
13+
UserSettingsPointer pConfig,
14+
TrackCollectionManager* pTrackCollectionManager);
1315
~DlgPrefFingerprint() override = default;
1416

1517
public slots:
@@ -21,11 +23,13 @@ class DlgPrefFingerprint : public DlgPreferencePage, public Ui::DlgPrefFingerpri
2123
// Called when the fingerprint-enabled checkbox is toggled.
2224
// Enables or disables the AcoustID submission group box to match.
2325
void slotFingerprintEnabledToggled(bool enabled);
26+
void slotClearAllFingerprints();
2427

2528
private:
2629
// Applies the enabled/disabled state to the AcoustID group and, within it,
2730
// the auto-submit checkbox (which additionally requires a non-empty key).
2831
void setAcoustIdGroupEnabled(bool fingerprintEnabled);
2932

3033
UserSettingsPointer m_pConfig;
34+
TrackCollectionManager* m_pTrackCollectionManager;
3135
};

src/preferences/dialog/dlgpreffingerprint.ui

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>576</width>
10-
<height>280</height>
10+
<height>400</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -85,7 +85,37 @@
8585
</widget>
8686
</item>
8787

88-
<item row="2" column="0">
88+
<item row="2" column="0" colspan="2">
89+
<widget class="QGroupBox" name="groupBoxClearFingerprints">
90+
<property name="title">
91+
<string>Library-wide Fingerprint Cleanup</string>
92+
</property>
93+
<layout class="QVBoxLayout" name="verticalLayoutClear">
94+
<item>
95+
<widget class="QLabel" name="labelClearInfo">
96+
<property name="text">
97+
<string>Removes all stored Chromaprint fingerprints, AcoustID queue entries, and CMRT group memberships from the entire library. Individual tracks can also be cleared via the right-click context menu.</string>
98+
</property>
99+
<property name="wordWrap">
100+
<bool>true</bool>
101+
</property>
102+
</widget>
103+
</item>
104+
<item>
105+
<widget class="QPushButton" name="btnClearAllFingerprints">
106+
<property name="toolTip">
107+
<string>Deletes all .chroma files and removes all fingerprint metadata from the database. Tracks will be re-fingerprinted the next time fingerprint analysis runs.</string>
108+
</property>
109+
<property name="text">
110+
<string>Clear All Fingerprints…</string>
111+
</property>
112+
</widget>
113+
</item>
114+
</layout>
115+
</widget>
116+
</item>
117+
118+
<item row="3" column="0">
89119
<spacer name="verticalSpacer">
90120
<property name="orientation">
91121
<enum>Qt::Vertical</enum>

0 commit comments

Comments
 (0)