From 74c80e95e97929614091b78ae95e3a6b73646795 Mon Sep 17 00:00:00 2001 From: Marcos CARDINOT Date: Sun, 1 Jun 2014 12:02:47 +0100 Subject: coverart::searchInTrackDirectory() - removing regExp logic and just look for any image into track directory - not make sense have a list with all likely names, it's not efficient - now we list only the images and get the lighter one --- src/library/coverart.cpp | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/library/coverart.cpp b/src/library/coverart.cpp index 33022c8bec..c142450f9e 100644 --- a/src/library/coverart.cpp +++ b/src/library/coverart.cpp @@ -40,30 +40,23 @@ bool CoverArt::saveImage(QImage cover, QString location) { } QString CoverArt::searchInTrackDirectory(QString directory) { - // Implements regular expressions for image extensions - static QList regExpList; - QLatin1String format(".(jpe?g|png|gif|bmp)"); - if (regExpList.isEmpty()) { - regExpList << QRegExp(".*cover.*" + format, Qt::CaseInsensitive) - << QRegExp(".*album.*" + format, Qt::CaseInsensitive) - << QRegExp(".*front.*" + format, Qt::CaseInsensitive) - << QRegExp(".*folder.*" + format, Qt::CaseInsensitive); + QDir dir(directory); + dir.setFilter(QDir::NoDotAndDotDot | QDir::Files | QDir::Readable); + dir.setSorting(QDir::Size | QDir::Reversed); + + QStringList nameFilters; + nameFilters << "*.jpg" << "*.jpeg" << "*.png" << "*.gif" << "*.bmp"; + dir.setNameFilters(nameFilters); + + QString coverLocation; + QStringList imglist = dir.entryList(); + if (imglist.size() > 0) { + coverLocation = directory; + coverLocation.append("/"); + coverLocation.append(imglist[0]); } - const QFileInfoList fileList = QDir(directory) - .entryInfoList(QDir::NoDotAndDotDot | - QDir::Files | - QDir::Readable); - foreach (QFileInfo f, fileList) { - const QString filename = f.fileName(); - foreach (QRegExp re, regExpList) { - if (filename.contains(re)) { - return f.absoluteFilePath(); - } - } - } - - return QString(); + return coverLocation; } QString CoverArt::getDefaultCoverName(QString artist, -- cgit v1.2.3