diff options
author | Marcos CARDINOT <mcardinot@gmail.com> | 2014-06-01 09:39:03 +0100 |
---|---|---|
committer | Marcos CARDINOT <mcardinot@gmail.com> | 2014-06-01 09:39:03 +0100 |
commit | 8b1b6c6e6d1d16ae8b37d1855c7728278a0a9687 (patch) | |
tree | c493186a8440d4fac3b8883d942333cae90c5a14 /src/library | |
parent | 36b6d8ace619e55b3b5a6b801d944f36a6275597 (diff) |
coverart::searchcover() - improvements to make the code more redable
- stop saving covers into TIO::parseCover()
- Now we'll just look for qimages, instead do it and save them at the same time.
- checking if the newCoverLocation is not empty (before request a new pixmap).
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/coverart.cpp | 52 | ||||
-rw-r--r-- | src/library/coverart.h | 6 | ||||
-rw-r--r-- | src/library/dao/coverartdao.cpp | 15 |
3 files changed, 26 insertions, 47 deletions
diff --git a/src/library/coverart.cpp b/src/library/coverart.cpp index 31adec067c..33022c8bec 100644 --- a/src/library/coverart.cpp +++ b/src/library/coverart.cpp @@ -31,24 +31,12 @@ bool CoverArt::deleteFile(const QString& location) { return true; } -bool CoverArt::saveFile(QImage cover, QString location) { - return cover.save(location, m_cDefaultImageFormat); -} - -QString CoverArt::saveEmbeddedCover(QImage cover, QString artist, - QString album, QString filename) { +bool CoverArt::saveImage(QImage cover, QString location) { if (cover.isNull()) { - return ""; + return false; } - QString coverName = getDefaultCoverName(artist, album, filename); - QString location = getDefaultCoverLocation(coverName); - - if (saveFile(cover, location)) { - return location; - } - - return ""; + return cover.save(location, m_cDefaultImageFormat); } QString CoverArt::searchInTrackDirectory(QString directory) { @@ -100,38 +88,22 @@ QString CoverArt::getDefaultCoverLocation(TrackPointer pTrack) { return getDefaultCoverLocation(coverArtName); } -QString CoverArt::searchCoverArtFile(TrackPointer pTrack) { +QImage CoverArt::searchCoverArt(TrackPointer pTrack) { // - // Step 1: Look for cover art in disk-cache directory. + // Step 1: Look for embedded cover art. // - QString coverLocation = getDefaultCoverLocation(pTrack); - if(QFile::exists(coverLocation)) { - return coverLocation; // FOUND! - } - - // - // Step 2: Look for embedded cover art. - // - coverLocation = pTrack->parseCoverArt(); - if (!coverLocation.isEmpty()) { - return coverLocation; // FOUND! + QImage image = pTrack->parseCoverArt(); + if (!image.isNull()) { + return image; // FOUND! } // - // Step 3: Look for cover stored in track diretory. + // Step 2: Look for cover stored in track diretory. // - QImage image(searchInTrackDirectory(pTrack->getDirectory())); - + image.load(searchInTrackDirectory(pTrack->getDirectory())); if (!image.isNull()) { - // try to store the image in our disk-cache! - coverLocation = getDefaultCoverLocation(pTrack); - if (saveFile(image, coverLocation)) { - return coverLocation; // FOUND! - } + return image; // FOUND! } - // - // Not found. - // - return QString(); + return QImage(); } diff --git a/src/library/coverart.h b/src/library/coverart.h index dfcc06e736..a303ada84b 100644 --- a/src/library/coverart.h +++ b/src/library/coverart.h @@ -17,10 +17,8 @@ class CoverArt : public QObject, public Singleton<CoverArt> { QString getDefaultCoverName(QString artist, QString album, QString filename); bool deleteFile(const QString& location); - bool saveFile(QImage cover, QString location); - QString saveEmbeddedCover(QImage cover, QString artist, - QString album, QString filename); - QString searchCoverArtFile(TrackPointer pTrack); + bool saveImage(QImage cover, QString location); + QImage searchCoverArt(TrackPointer pTrack); protected: CoverArt(); diff --git a/src/library/dao/coverartdao.cpp b/src/library/dao/coverartdao.cpp index f923ed41a5..f5d332cd11 100644 --- a/src/library/dao/coverartdao.cpp +++ b/src/library/dao/coverartdao.cpp @@ -60,13 +60,22 @@ void CoverArtDAO::slotCoverArtScan(TrackPointer pTrack) { } } - // if we found something, it'll return an existing and valid location - QString newCoverLocation = m_pCoverArt->searchCoverArtFile(pTrack); + // looking for cover art in disk-cache directory. + QString newCoverLocation = m_pCoverArt->getDefaultCoverLocation(pTrack); + if(!QFile::exists(newCoverLocation)) { + // looking for embedded covers and covers into track directory. + QImage image = m_pCoverArt->searchCoverArt(pTrack); + if (!m_pCoverArt->saveImage(image, newCoverLocation)) { + newCoverLocation.clear(); + } + } if (coverLocation != newCoverLocation) { saveCoverLocation(newCoverLocation); pTrack->setCoverArtLocation(newCoverLocation); - CoverArtCache::getInstance()->requestPixmap(pTrack); + if (!newCoverLocation.isEmpty()) { + CoverArtCache::getInstance()->requestPixmap(pTrack); + } } else if (removedFromDisk) { CoverArtCache::getInstance()->requestPixmap(pTrack); } |