From 3af36447bc990423bf1366799b944baff17b4918 Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Fri, 28 Feb 2020 14:10:42 +0100 Subject: Prepare CoverArtCache for migration to new hash function --- src/library/coverart.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/library/coverart.cpp') diff --git a/src/library/coverart.cpp b/src/library/coverart.cpp index 27f317d6ba..3b43890ceb 100644 --- a/src/library/coverart.cpp +++ b/src/library/coverart.cpp @@ -137,6 +137,32 @@ QImage CoverInfo::loadImage( } } +bool CoverInfo::refreshImageHash( + const QImage& loadedImage, + const SecurityTokenPointer& pTrackLocationToken) { + if (CoverImageUtils::isValidHash(hash)) { + // Trust that a valid hash has been calculated from the + // corresponding image. Otherwise we would refresh all + // hashes over and over again. + return false; + } + QImage image = loadedImage; + if (loadedImage.isNull()) { + image = loadImage(pTrackLocationToken); + } + if (image.isNull() && type != CoverInfo::NONE) { + kLogger.warning() + << "Resetting cover info" + << *this; + reset(); + return true; + } + hash = CoverImageUtils::calculateHash(image); + DEBUG_ASSERT(image.isNull() || CoverImageUtils::isValidHash(hash)); + DEBUG_ASSERT(!image.isNull() || hash == CoverImageUtils::defaultHash()); + return true; +} + bool operator==(const CoverInfo& a, const CoverInfo& b) { return static_cast(a) == static_cast(b) && -- cgit v1.2.3