Skip to content

Commit

Permalink
Tag Fetcher: allow to apply only found cover
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Sep 7, 2023
1 parent 37f764d commit fa5ea5d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
32 changes: 22 additions & 10 deletions src/library/dlgtagfetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ void DlgTagFetcher::init() {
btnPrev->hide();
}

connect(btnApply, &QPushButton::clicked, this, &DlgTagFetcher::apply);
connect(btnApply, &QPushButton::clicked, this, &DlgTagFetcher::applyTagsAndCover);
connect(btnApplyCover, &QPushButton::clicked, this, &DlgTagFetcher::applyCover);
connect(btnQuit, &QPushButton::clicked, this, &DlgTagFetcher::quit);
connect(btnRetry, &QPushButton::clicked, this, &DlgTagFetcher::retry);
connect(tags, &QTreeWidget::currentItemChanged, this, &DlgTagFetcher::tagSelected);
Expand Down Expand Up @@ -234,6 +235,7 @@ void DlgTagFetcher::loadTrack(const TrackPointer& pTrack) {

btnRetry->setDisabled(true);
btnApply->setDisabled(true);
btnApplyCover->setDisabled(true);
statusMessage->setVisible(false);
loadingProgressBar->setVisible(true);
loadingProgressBar->setValue(kMinimumValueOfQProgressBar);
Expand Down Expand Up @@ -261,7 +263,7 @@ void DlgTagFetcher::slotTrackChanged(TrackId trackId) {
}
}

void DlgTagFetcher::apply() {
void DlgTagFetcher::applyTagsAndCover() {
int tagIndex = m_data.m_selectedTag;
if (tagIndex < 0) {
return;
Expand Down Expand Up @@ -325,6 +327,19 @@ void DlgTagFetcher::apply() {
}
#endif // __EXTRA_METADATA__

applyCover();

statusMessage->setText(tr("Selected metadata applied"));

m_pTrack->replaceMetadataFromSource(
std::move(trackMetadata),
// Prevent re-import of outdated metadata from file tags
// by explicitly setting the synchronization time stamp
// to the current time.
QDateTime::currentDateTimeUtc());
}

void DlgTagFetcher::applyCover() {
if (!m_fetchedCoverArtByteArrays.isNull()) {
VERIFY_OR_DEBUG_ASSERT(m_isCoverArtCopyWorkerRunning == false) {
return;
Expand Down Expand Up @@ -371,19 +386,13 @@ void DlgTagFetcher::apply() {
m_pWorker->start();
}

statusMessage->setText(tr("Selected metadata applied"));

m_pTrack->replaceMetadataFromSource(
std::move(trackMetadata),
// Prevent re-import of outdated metadata from file tags
// by explicitly setting the synchronization time stamp
// to the current time.
QDateTime::currentDateTimeUtc());
statusMessage->setText(tr("Selected cover art applied"));
}

void DlgTagFetcher::retry() {
btnRetry->setDisabled(true);
btnApply->setDisabled(true);
btnApplyCover->setDisabled(true);
loadingProgressBar->setValue(kMinimumValueOfQProgressBar);
m_tagFetcher.startFetch(m_pTrack);
}
Expand Down Expand Up @@ -434,6 +443,7 @@ void DlgTagFetcher::fetchTagFinished(
return;
} else {
btnApply->setEnabled(true);
btnApplyCover->setEnabled(true);
btnRetry->setEnabled(false);
loadingProgressBar->setVisible(false);
statusMessage->setVisible(true);
Expand Down Expand Up @@ -589,6 +599,8 @@ void DlgTagFetcher::slotLoadBytesToLabel(const QByteArray& data) {
m_pWFetchedCoverArtLabel->loadData(
m_fetchedCoverArtByteArrays); // This data loaded because for full size.
m_pWFetchedCoverArtLabel->setCoverArt(coverInfo, fetchedCoverArtPixmap);

btnApplyCover->setEnabled(!data.isNull());
}

void DlgTagFetcher::getCoverArt(const QString& url) {
Expand Down
3 changes: 2 additions & 1 deletion src/library/dlgtagfetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class DlgTagFetcher : public QDialog, public Ui::DlgTagFetcher {
void slotNetworkResult(int httpStatus, const QString& app, const QString& message, int code);
// Called when apply is pressed.
void slotTrackChanged(TrackId trackId);
void apply();
void applyTagsAndCover();
void applyCover();
void retry();
void quit();
void reject() override;
Expand Down
10 changes: 9 additions & 1 deletion src/library/dlgtagfetcher.ui
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,14 @@
</widget>
</item>
<item>
<spacer name="lowerLabelSpacer">
<widget class="QPushButton" name="btnApplyCover">
<property name="text">
<string>Apply Cover</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
Expand Down Expand Up @@ -428,6 +435,7 @@
<tabstop>submit_tree</tabstop>
<tabstop>btnPrev</tabstop>
<tabstop>btnNext</tabstop>
<tabstop>btnApplyCover</tabstop>
<tabstop>btnApply</tabstop>
<tabstop>btnQuit</tabstop>
<tabstop>btnRetry</tabstop>
Expand Down

0 comments on commit fa5ea5d

Please sign in to comment.