summaryrefslogtreecommitdiffstats
path: root/src/library/coverart.cpp
diff options
context:
space:
mode:
authorUwe Klotz <uklotz@mixxx.org>2020-02-20 10:15:19 +0100
committerUwe Klotz <uklotz@mixxx.org>2020-02-20 10:20:40 +0100
commit6ae12120234fcc0c0fc0f37f7ba0eb9ad54ba2ba (patch)
tree61dc1829e444854ba3cda36b95d69df6bb4cee97 /src/library/coverart.cpp
parent2a0f01e3027b3e69aaf69109cb48a973e5dc521a (diff)
Make loading of cover images a member function
Diffstat (limited to 'src/library/coverart.cpp')
-rw-r--r--src/library/coverart.cpp42
1 files changed, 42 insertions, 0 deletions
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<const CoverInfoRelative&>(a) ==
static_cast<const CoverInfoRelative&>(b) &&