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

Library, remove/hide tracks dialog: add 'Don't ask again' checkbox #11239

Merged
merged 1 commit into from
Feb 4, 2023
Merged
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
11 changes: 10 additions & 1 deletion src/library/trackmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class TrackModel {
: m_db(db),
m_settingsNamespace(settingsNamespace),
m_iDefaultSortColumn(-1),
m_eDefaultSortOrder(Qt::AscendingOrder) {
m_eDefaultSortOrder(Qt::AscendingOrder),
m_confirmHideRemoveTracks(true) {
}
virtual ~TrackModel() {}

Expand Down Expand Up @@ -219,6 +220,13 @@ class TrackModel {
/// @param baseOnly return only a identifier for the whole subsystem
virtual QString modelKey(bool noSearch) const = 0;

virtual bool getRequireConfirmationToHideRemoveTracks() {
return m_confirmHideRemoveTracks;
}
virtual void setRequireConfirmationToHideRemoveTracks(bool require) {
m_confirmHideRemoveTracks = require;
}

virtual bool updateTrackGenre(
Track* pTrack,
const QString& genre) const = 0;
Expand All @@ -234,5 +242,6 @@ class TrackModel {
QList<int> m_emptyColumns;
int m_iDefaultSortColumn;
Qt::SortOrder m_eDefaultSortOrder;
bool m_confirmHideRemoveTracks;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(TrackModel::Capabilities)
81 changes: 55 additions & 26 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,41 +855,70 @@ void WTrackTableView::hideOrRemoveSelectedTracks() {
return;
}

saveCurrentIndex();

QMessageBox::StandardButton response;
TrackModel::Capability cap;
if (pTrackModel->hasCapabilities(TrackModel::Capability::Hide)) {
// Hide tracks if this is the main library table
response = QMessageBox::question(this,
tr("Confirm track hide"),
tr("Are you sure you want to hide the selected tracks?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if (response == QMessageBox::Yes) {
pTrackModel->hideTracks(indices);
}
cap = TrackModel::Capability::Hide;
} else if (pTrackModel->hasCapabilities(TrackModel::Capability::Remove)) {
cap = TrackModel::Capability::Remove;
} else if (pTrackModel->hasCapabilities(TrackModel::Capability::RemoveCrate)) {
cap = TrackModel::Capability::RemoveCrate;
} else if (pTrackModel->hasCapabilities(TrackModel::Capability::RemovePlaylist)) {
cap = TrackModel::Capability::RemovePlaylist;
} else {
// Else remove the tracks from AutoDJ/crate/playlist
return;
}

if (pTrackModel->getRequireConfirmationToHideRemoveTracks()) {
QString title;
QString message;
if (pTrackModel->hasCapabilities(TrackModel::Capability::Remove)) {
message = tr("Are you sure you want to remove the selected tracks from AutoDJ queue?");
} else if (pTrackModel->hasCapabilities(TrackModel::Capability::RemoveCrate)) {
message = tr("Are you sure you want to remove the selected tracks from this crate?");
} else if (pTrackModel->hasCapabilities(TrackModel::Capability::RemovePlaylist)) {
message = tr("Are you sure you want to remove the selected tracks from this playlist?");
if (cap == TrackModel::Capability::Hide) {
// Hide tracks if this is the main library table
title = tr("Confirm track hide");
message = tr("Are you sure you want to hide the selected tracks?");
} else {
title = tr("Confirm track removal");
// Else remove the tracks from AutoDJ/crate/playlist
if (cap == TrackModel::Capability::Remove) {
message =
tr("Are you sure you want to remove the selected "
"tracks from AutoDJ queue?");
} else if (cap == TrackModel::Capability::RemoveCrate) {
message =
tr("Are you sure you want to remove the selected "
"tracks from this crate?");
} else { // TrackModel::Capability::RemovePlaylist
message =
tr("Are you sure you want to remove the selected "
"tracks from this playlist?");
}
}

QMessageBox msg;
msg.setIcon(QMessageBox::Question);
msg.setWindowTitle(title);
msg.setText(message);
QCheckBox notAgainCB(tr("Don't ask again during this session"));
notAgainCB.setCheckState(Qt::Unchecked);
msg.setCheckBox(&notAgainCB);
msg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msg.setDefaultButton(QMessageBox::Cancel);
if (msg.exec() != QMessageBox::Ok) {
return;
}

response = QMessageBox::question(this,
tr("Confirm track removal"),
message,
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if (response == QMessageBox::Yes) {
pTrackModel->removeTracks(indices);
if (notAgainCB.isChecked()) {
pTrackModel->setRequireConfirmationToHideRemoveTracks(false);
}
}

saveCurrentIndex();

if (cap == TrackModel::Capability::Hide) {
pTrackModel->hideTracks(indices);
} else {
pTrackModel->removeTracks(indices);
}

restoreCurrentIndex();
}

Expand Down