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 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/library/coverart.cpp') 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) && -- cgit v1.2.3