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

Cover Art Fetcher: allow applying just the found cover #11938

Merged
merged 3 commits into from
Sep 28, 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
40 changes: 27 additions & 13 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 All @@ -165,6 +166,7 @@ void DlgTagFetcher::init() {
loadingProgressBar->setMaximum(kMaximumValueOfQProgressBar);

btnRetry->setDisabled(true);
btnApplyCover->setDisabled(true);

CoverArtCache* pCache = CoverArtCache::instance();
if (pCache) {
Expand Down Expand Up @@ -234,6 +236,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 +264,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 +328,19 @@ void DlgTagFetcher::apply() {
}
#endif // __EXTRA_METADATA__

applyCover();

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 metadata applied"));
}

void DlgTagFetcher::applyCover() {
if (!m_fetchedCoverArtByteArrays.isNull()) {
VERIFY_OR_DEBUG_ASSERT(m_isCoverArtCopyWorkerRunning == false) {
return;
Expand Down Expand Up @@ -371,19 +387,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"));
}
Swiftb0y marked this conversation as resolved.
Show resolved Hide resolved

void DlgTagFetcher::retry() {
btnRetry->setDisabled(true);
btnApply->setDisabled(true);
btnApplyCover->setDisabled(true);
loadingProgressBar->setValue(kMinimumValueOfQProgressBar);
m_tagFetcher.startFetch(m_pTrack);
}
Expand Down Expand Up @@ -433,8 +443,9 @@ void DlgTagFetcher::fetchTagFinished(
loadingProgressBar->setFormat(emptyMessage);
return;
} else {
btnApply->setEnabled(true);
btnRetry->setEnabled(false);
btnApply->setDisabled(true);
btnApplyCover->setDisabled(true);
btnRetry->setDisabled(true);
loadingProgressBar->setVisible(false);
statusMessage->setVisible(true);

Expand Down Expand Up @@ -514,6 +525,7 @@ void DlgTagFetcher::tagSelected() {
m_pWFetchedCoverArtLabel->loadData(QByteArray());
m_pWFetchedCoverArtLabel->setCoverArt(CoverInfo{},
QPixmap(CoverArtUtils::defaultCoverLocation()));
btnApplyCover->setDisabled(true);

const mixxx::musicbrainz::TrackRelease& trackRelease = m_data.m_tags[tagIndex];
QUuid selectedTagAlbumId = trackRelease.albumReleaseId;
Expand Down Expand Up @@ -582,13 +594,15 @@ void DlgTagFetcher::slotLoadBytesToLabel(const QByteArray& data) {
coverInfo.setImage();

loadingProgressBar->setVisible(false);
statusMessage->setText(tr("Cover art is ready to be applied"));
statusMessage->clear();
statusMessage->setVisible(true);

m_fetchedCoverArtByteArrays = data;
m_pWFetchedCoverArtLabel->loadData(
m_fetchedCoverArtByteArrays); // This data loaded because for full size.
m_pWFetchedCoverArtLabel->setCoverArt(coverInfo, fetchedCoverArtPixmap);

btnApplyCover->setDisabled(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
63 changes: 37 additions & 26 deletions src/library/dlgtagfetcher.ui
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
</item>
<item row="0" column="0">
<widget class="QTreeWidget" name="tags">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="editTriggers">
<set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed</set>
</property>
Expand Down Expand Up @@ -194,6 +200,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="styleSheet">
<string notr="true">QLabel { font-weight: bold; }</string>
</property>
Expand All @@ -205,12 +214,15 @@
<item>
<widget class="QWidget" name="currentCover" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>250</horstretch>
<verstretch>250</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="currentCoverArtLayout">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="spacing">
<number>0</number>
</property>
Expand All @@ -229,9 +241,6 @@
<property name="bottomMargin">
<number>0</number>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTop|Qt::AlignCenter</set>
</property>
</layout>
</widget>
</item>
Expand All @@ -243,6 +252,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="styleSheet">
<string notr="true">QLabel { font-weight: bold; }</string>
</property>
Expand All @@ -254,12 +266,15 @@
<item>
<widget class="QWidget" name="fetchedCover" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>250</horstretch>
<verstretch>250</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="fetchedCoverArtLayout">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="spacing">
<number>0</number>
</property>
Expand All @@ -278,23 +293,21 @@
<property name="bottomMargin">
<number>0</number>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignBottom|Qt::AlignCenter</set>
</property>
</layout>
</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>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
Expand All @@ -304,9 +317,9 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="progressRetryLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="progressMessageLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
Expand All @@ -317,14 +330,17 @@
</property>
</widget>
</item>
<item alignment="Qt::AlignHCenter">
<item>
<widget class="QLabel" name="statusMessage">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
Expand Down Expand Up @@ -355,14 +371,8 @@
</item>
</layout>
</item>
<item alignment="Qt::AlignRight">
<item>
<widget class="QPushButton" name="btnRetry">
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Retry</string>
</property>
Expand Down Expand Up @@ -425,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
Loading