From 6ae12120234fcc0c0fc0f37f7ba0eb9ad54ba2ba Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Thu, 20 Feb 2020 10:15:19 +0100 Subject: Make loading of cover images a member function --- src/library/coverart.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/library/coverart.h | 5 +++++ src/library/coverartcache.cpp | 2 +- src/library/coverartutils.cpp | 37 ------------------------------------- src/library/coverartutils.h | 2 -- 5 files changed, 48 insertions(+), 40 deletions(-) (limited to 'src/library') diff --git a/src/library/coverart.cpp b/src/library/coverart.cpp index da33aaa279..a7e44ea352 100644 --- a/src/library/coverart.cpp +++ b/src/library/coverart.cpp @@ -81,6 +81,48 @@ QDebug operator<<(QDebug dbg, const CoverInfoRelative& infoRelative) { .arg(coverInfoRelativeToString(infoRelative)); } +QImage CoverInfo::loadImage( + const SecurityTokenPointer& pTrackLocationToken) const { + if (type == CoverInfo::METADATA) { + if (trackLocation.isEmpty()) { + qDebug() << "CoverArtUtils::loadCover METADATA cover with empty trackLocation."; + return QImage(); + } + return CoverArtUtils::extractEmbeddedCover( + TrackFile(trackLocation), + pTrackLocationToken); + } else if (type == CoverInfo::FILE) { + if (trackLocation.isEmpty()) { + qDebug() << "CoverArtUtils::loadCover FILE cover with empty trackLocation." + << "Relative paths will not work."; + SecurityTokenPointer pToken = + Sandbox::openSecurityToken( + QFileInfo(coverLocation), + true); + return QImage(coverLocation); + } + + const QFileInfo coverFile( + TrackFile(trackLocation).directory(), + coverLocation); + const QString coverFilePath = coverFile.filePath(); + if (!coverFile.exists()) { + qDebug() << "CoverArtUtils::loadCover FILE cover does not exist:" + << coverFilePath; + return QImage(); + } + SecurityTokenPointer pToken = + Sandbox::openSecurityToken(coverFile, true); + return QImage(coverFilePath); + } else if (type == CoverInfo::NONE) { + return QImage(); + } else { + qDebug() << "CoverArtUtils::loadCover unhandled type"; + DEBUG_ASSERT(false); + return QImage(); + } +} + bool operator==(const CoverInfo& a, const CoverInfo& b) { return static_cast(a) == static_cast(b) && diff --git a/src/library/coverart.h b/src/library/coverart.h index ac5fb262ee..9a79ecc344 100644 --- a/src/library/coverart.h +++ b/src/library/coverart.h @@ -4,6 +4,8 @@ #include #include +#include "util/sandbox.h" + class CoverImageUtils { public: static quint16 calculateHash( @@ -76,6 +78,9 @@ class CoverInfo : public CoverInfoRelative { CoverInfo(CoverInfo&&) = default; CoverInfo& operator=(CoverInfo&&) = default; + QImage loadImage( + const SecurityTokenPointer& pTrackLocationToken = SecurityTokenPointer()) const; + QString trackLocation; }; diff --git a/src/library/coverartcache.cpp b/src/library/coverartcache.cpp index 20713464be..0baac7358d 100644 --- a/src/library/coverartcache.cpp +++ b/src/library/coverartcache.cpp @@ -133,7 +133,7 @@ CoverArtCache::FutureResult CoverArtCache::loadCover( << info << desiredWidth << signalWhenDone; } - QImage image = CoverArtUtils::loadCover(info); + QImage image = info.loadImage(); // TODO(XXX) Should we re-hash here? If the cover file (or track metadata) // has changed then info.hash may be incorrect. The fix diff --git a/src/library/coverartutils.cpp b/src/library/coverartutils.cpp index 5527f51157..3b7c0b39ca 100644 --- a/src/library/coverartutils.cpp +++ b/src/library/coverartutils.cpp @@ -42,43 +42,6 @@ QImage CoverArtUtils::extractEmbeddedCover( std::move(trackFile), std::move(pToken)); } -//static -QImage CoverArtUtils::loadCover(const CoverInfo& info) { - if (info.type == CoverInfo::METADATA) { - if (info.trackLocation.isEmpty()) { - qDebug() << "CoverArtUtils::loadCover METADATA cover with empty trackLocation."; - return QImage(); - } - const TrackFile trackFile(info.trackLocation); - return extractEmbeddedCover(trackFile); - } else if (info.type == CoverInfo::FILE) { - if (info.trackLocation.isEmpty()) { - qDebug() << "CoverArtUtils::loadCover FILE cover with empty trackLocation." - << "Relative paths will not work."; - SecurityTokenPointer pToken = Sandbox::openSecurityToken( - QFileInfo(info.coverLocation), true); - return QImage(info.coverLocation); - } - - QFileInfo coverFile(TrackFile(info.trackLocation).directory(), info.coverLocation); - QString coverFilePath = coverFile.filePath(); - if (!coverFile.exists()) { - qDebug() << "CoverArtUtils::loadCover FILE cover does not exist:" - << coverFilePath; - return QImage(); - } - SecurityTokenPointer pToken = Sandbox::openSecurityToken( - coverFile, true); - return QImage(coverFilePath); - } else if (info.type == CoverInfo::NONE) { - return QImage(); - } else { - qDebug() << "CoverArtUtils::loadCover unhandled type"; - DEBUG_ASSERT(false); - return QImage(); - } -} - //static QList CoverArtUtils::findPossibleCoversInFolder(const QString& folder) { // Search for image files in the track directory. diff --git a/src/library/coverartutils.h b/src/library/coverartutils.h index eb407a8a4a..a7abc84dfe 100644 --- a/src/library/coverartutils.h +++ b/src/library/coverartutils.h @@ -26,8 +26,6 @@ class CoverArtUtils { TrackFile trackFile, SecurityTokenPointer pToken); - static QImage loadCover(const CoverInfo& info); - static QStringList supportedCoverArtExtensions(); static QString supportedCoverArtExtensionsRegex(); -- cgit v1.2.3