Skip to content

Commit

Permalink
Merge pull request #11239 from ronso0/tracks-remove-confirm-checkbox
Browse files Browse the repository at this point in the history
Library, remove/hide tracks dialog: add 'Don't ask again' checkbox
  • Loading branch information
daschuer authored Feb 4, 2023
2 parents 3f6876f + 3e8f9f8 commit 45d46de
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 27 deletions.
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

0 comments on commit 45d46de

Please sign in to comment.