Skip to content

Commit

Permalink
Merge pull request #4560 from ronso0/remove-from-disk-fix-undeleted
Browse files Browse the repository at this point in the history
Remove from disk: add to deck track menu, fix undeleted message
  • Loading branch information
daschuer authored Feb 21, 2022
2 parents 4ed8721 + 3c6e33d commit 1b688f2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 28 deletions.
97 changes: 69 additions & 28 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ void WTrackMenu::setupActions() {
}
}

if (featureIsEnabled(Feature::RemoveFromDisk) &&
m_pTrackModel->hasCapabilities(TrackModel::Capability::RemoveFromDisk)) {
if (featureIsEnabled(Feature::RemoveFromDisk)) {
m_pRemoveFromDiskMenu->addAction(m_pRemoveFromDiskAct);
addMenu(m_pRemoveFromDiskMenu);
}
Expand Down Expand Up @@ -790,9 +789,11 @@ void WTrackMenu::updateMenus() {
}

if (featureIsEnabled(Feature::RemoveFromDisk)) {
bool locked = m_pTrackModel->hasCapabilities(TrackModel::Capability::Locked);
if (m_pTrackModel->hasCapabilities(TrackModel::Capability::RemoveFromDisk)) {
m_pRemoveFromDiskAct->setEnabled(!locked);
if (m_pTrackModel) {
bool locked = m_pTrackModel->hasCapabilities(TrackModel::Capability::Locked);
if (m_pTrackModel->hasCapabilities(TrackModel::Capability::RemoveFromDisk)) {
m_pRemoveFromDiskAct->setEnabled(!locked);
}
}
}

Expand Down Expand Up @@ -1704,14 +1705,21 @@ class RemoveTrackFilesFromDiskTrackPointerOperation : public mixxx::TrackPointer
} // anonymous namespace

void WTrackMenu::slotRemoveFromDisk() {
const auto trackRefs = getTrackRefs();
QStringList locations;
locations.reserve(trackRefs.size());
for (const auto& trackRef : trackRefs) {
QString location = trackRef.getLocation();
if (m_pTrackModel) {
const auto trackRefs = getTrackRefs();
locations.reserve(trackRefs.size());
for (const auto& trackRef : trackRefs) {
QString location = trackRef.getLocation();
locations.append(location);
}
locations.removeDuplicates();
} else if (m_pTrack) {
QString location = m_pTrack->getLocation();
locations.append(location);
} else {
return;
}
locations.removeDuplicates();

{
// Prepare the delete confirmation dialog
Expand All @@ -1724,15 +1732,24 @@ void WTrackMenu::slotRemoveFromDisk() {
delListWidget->setFocusPolicy(Qt::ClickFocus);
delListWidget->addItems(locations);
mixxx::widgethelper::growListWidget(*delListWidget, *this);
// Warning text

QString delWarningText;
if (m_pTrackModel) {
delWarningText = tr("Permanently delete these files from disk?") +
QStringLiteral("<br><br><b>") +
tr("This can not be undone!") + QStringLiteral("</b>");
} else {
delWarningText =
tr("Stop the deck and permanently delete this track file from disk?") +
QStringLiteral("<br><br><b>") +
tr("This can not be undone!") + QStringLiteral("</b>");
}
QLabel* delWarning = new QLabel();
delWarning->setText(tr("Permanently delete these files from disk?") +
QString("<br><br><b>") +
tr("This can not be undone!") + QString("</b>"));
delWarning->setText(delWarningText);
delWarning->setTextFormat(Qt::RichText);
delWarning->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,
QSizePolicy::Minimum));
// Buttons

QDialogButtonBox* delButtons = new QDialogButtonBox();
QPushButton* cancelBtn = delButtons->addButton(
tr("Cancel"),
Expand Down Expand Up @@ -1762,6 +1779,13 @@ void WTrackMenu::slotRemoveFromDisk() {
}
}

// If the operation was initiated from a deck's track menu
// we'll first stop the deck and eject the track.
if (m_pTrack) {
ControlObject::set(ConfigKey(m_deckGroup, "stop"), 1.0);
ControlObject::set(ConfigKey(m_deckGroup, "eject"), 1.0);
}

// Set up and initiate the track batch operation
const auto progressLabelText =
tr("Removing %1 track file(s) from disk...",
Expand All @@ -1782,14 +1806,25 @@ void WTrackMenu::slotRemoveFromDisk() {
// Show purge summary message
QMessageBox msgBoxPurgeTracks;
msgBoxPurgeTracks.setIcon(QMessageBox::Information);
msgBoxPurgeTracks.setWindowTitle(tr("Track Files Deleted"));
msgBoxPurgeTracks.setText(
tr("%1 track files were deleted from disk and purged "
"from the Mixxx database.")
.arg(QString::number(tracksToPurge.length())) +
QString("<br><br>") +
tr("Note: if you are in Browse or Recording you need to "
"click the current view again to see changes."));
QString msgTitle;
QString msgText;
if (m_pTrackModel) {
msgTitle = tr("Track Files Deleted");
msgText =
tr("%1 track files were deleted from disk and purged "
"from the Mixxx database.")
.arg(QString::number(tracksToPurge.length())) +
QStringLiteral("<br><br>") +
tr("Note: if you are in Browse or Recording you need to "
"click the current view again to see changes.");
} else {
msgTitle = tr("Track File Deleted");
msgText = tr(
"Track file was deleted from disk and purged "
"from the Mixxx database.");
}
msgBoxPurgeTracks.setWindowTitle(msgTitle);
msgBoxPurgeTracks.setText(msgText);
msgBoxPurgeTracks.setTextFormat(Qt::RichText);
msgBoxPurgeTracks.setStandardButtons(QMessageBox::Ok);
msgBoxPurgeTracks.exec();
Expand All @@ -1802,10 +1837,16 @@ void WTrackMenu::slotRemoveFromDisk() {
}
// Else show a message with a list of tracks that could not be deleted.
QLabel* notDeletedLabel = new QLabel;
notDeletedLabel->setText(
tr("The following %1 files could not be deleted from disk")
.arg(QString::number(
tracksToKeep.length())));
QString msgText;
if (m_pTrackModel) {
msgText =
tr("The following %1 file(s) could not be deleted from disk")
.arg(QString::number(
tracksToKeep.length()));
} else {
msgText = tr("This track file could not be deleted from disk");
}
notDeletedLabel->setText(msgText);
notDeletedLabel->setTextFormat(Qt::RichText);

QListWidget* notDeletedListWidget = new QListWidget;
Expand All @@ -1825,7 +1866,7 @@ void WTrackMenu::slotRemoveFromDisk() {

QDialog dlgNotDeleted;
dlgNotDeleted.setModal(true);
dlgNotDeleted.setWindowTitle(tr("Remaining Track Files"));
dlgNotDeleted.setWindowTitle(tr("Remaining Track File(s)"));
dlgNotDeleted.setLayout(notDeletedLayout);
// Required for being able to close the dialog
connect(closeBtn, &QPushButton::clicked, &dlgNotDeleted, &QDialog::close);
Expand Down
2 changes: 2 additions & 0 deletions src/widget/wtrackproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ constexpr WTrackMenu::Features kTrackMenuFeatures =
WTrackMenu::Feature::Reset |
WTrackMenu::Feature::BPM |
WTrackMenu::Feature::Color |
WTrackMenu::Feature::RemoveFromDisk |
WTrackMenu::Feature::FileBrowser |
WTrackMenu::Feature::Properties |
WTrackMenu::Feature::UpdateReplayGain;
Expand Down Expand Up @@ -94,6 +95,7 @@ void WTrackProperty::mouseMoveEvent(QMouseEvent* event) {
DragAndDropHelper::dragTrack(m_pCurrentTrack, this, m_group);
}
}

void WTrackProperty::mouseDoubleClickEvent(QMouseEvent* event) {
Q_UNUSED(event);
if (m_pCurrentTrack) {
Expand Down

0 comments on commit 1b688f2

Please sign in to comment.