summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/library/coverart.cpp42
-rw-r--r--src/library/coverart.h5
-rw-r--r--src/library/coverartcache.cpp2
-rw-r--r--src/library/coverartutils.cpp37
-rw-r--r--src/library/coverartutils.h2
-rw-r--r--src/test/coverartutils_test.cpp2
6 files changed, 49 insertions, 41 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) &&
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 <QString>
#include <QtDebug>
+#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
@@ -43,43 +43,6 @@ QImage CoverArtUtils::extractEmbeddedCover(
}
//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<QFileInfo> CoverArtUtils::findPossibleCoversInFolder(const QString& folder) {
// Search for image files in the track directory.
QRegExp coverArtFilenames(supportedCoverArtExtensionsRegex(),
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();
diff --git a/src/test/coverartutils_test.cpp b/src/test/coverartutils_test.cpp
index e5b17d46e9..52c1a71a12 100644
--- a/src/test/coverartutils_test.cpp
+++ b/src/test/coverartutils_test.cpp
@@ -142,7 +142,7 @@ TEST_F(CoverArtUtilTest, searchImage) {
// stuff below.
result.trackLocation = kTrackLocationTest;
- const QImage img = CoverArtUtils::loadCover(result);
+ const QImage img = result.loadImage();
EXPECT_EQ(img.isNull(), false);
QString trackBaseName = "cover-test";