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 | |
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).
-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 | ||||
-rw-r--r-- | src/trackinfoobject.cpp | 12 | ||||
-rw-r--r-- | src/trackinfoobject.h | 2 |
5 files changed, 30 insertions, 57 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); } diff --git a/src/trackinfoobject.cpp b/src/trackinfoobject.cpp index f29bde10bf..7c3f8568d6 100644 --- a/src/trackinfoobject.cpp +++ b/src/trackinfoobject.cpp @@ -28,7 +28,6 @@ #include "controlobject.h" #include "soundsourceproxy.h" #include "xmlparse.h" -#include "library/coverart.h" #include "track/beatfactory.h" #include "track/keyfactory.h" #include "track/keyutils.h" @@ -213,20 +212,15 @@ void TrackInfoObject::parse() { } } -QString TrackInfoObject::parseCoverArt() { +QImage TrackInfoObject::parseCoverArt() { const QString& canonicalLocation = m_fileInfo.canonicalFilePath(); SoundSourceProxy proxy(canonicalLocation, m_pSecurityToken); Mixxx::SoundSource* pProxiedSoundSource = proxy.getProxiedSoundSource(); if (pProxiedSoundSource != NULL && proxy.parseHeader() == OK) { - - QImage image = pProxiedSoundSource->getCoverArt(); - QString coverLocation = CoverArt::instance()->saveEmbeddedCover( - image, getArtist(), getAlbum(), getFilename()); - setCoverArtLocation(coverLocation); - return coverLocation; + return pProxiedSoundSource->getCoverArt(); } - return QString(); + return QImage(); } void TrackInfoObject::parseArtist() { diff --git a/src/trackinfoobject.h b/src/trackinfoobject.h index 9d1f30ee9d..acfa87df6e 100644 --- a/src/trackinfoobject.h +++ b/src/trackinfoobject.h @@ -64,7 +64,7 @@ class TrackInfoObject : public QObject { // this method will parse the information stored in the sound file // just to extract the embedded cover art - QString parseCoverArt(); + QImage parseCoverArt(); // Returns the duration in seconds int getDuration() const; |