Changeset View
Changeset View
Standalone View
Standalone View
src/filescanner.cpp
Show All 37 Lines | |||||
38 | 38 | | |||
39 | #include <QFileInfo> | 39 | #include <QFileInfo> | ||
40 | #include <QLocale> | 40 | #include <QLocale> | ||
41 | #include <QDir> | 41 | #include <QDir> | ||
42 | 42 | | |||
43 | class FileScannerPrivate | 43 | class FileScannerPrivate | ||
44 | { | 44 | { | ||
45 | public: | 45 | public: | ||
46 | 46 | static const QStringList constSearchStrings; | |||
47 | #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND | 47 | #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND | ||
48 | KFileMetaData::ExtractorCollection mAllExtractors; | 48 | KFileMetaData::ExtractorCollection mAllExtractors; | ||
49 | 49 | | |||
50 | KFileMetaData::PropertyMap mAllProperties; | 50 | KFileMetaData::PropertyMap mAllProperties; | ||
51 | 51 | | |||
52 | QString checkForMultipleEntries(KFileMetaData::Property::Property property); | 52 | QString checkForMultipleEntries(KFileMetaData::Property::Property property); | ||
53 | 53 | | |||
54 | KFileMetaData::EmbeddedImageData mImageScanner; | 54 | KFileMetaData::EmbeddedImageData mImageScanner; | ||
55 | #endif | 55 | #endif | ||
56 | 56 | | |||
57 | }; | 57 | }; | ||
58 | 58 | | |||
59 | const QStringList FileScannerPrivate::constSearchStrings = { | ||||
60 | QStringLiteral("*[Cc]over*.jpg"), | ||||
61 | QStringLiteral("*[Cc]over*.png"), | ||||
62 | QStringLiteral("*[Ff]older*.jpg"), | ||||
63 | QStringLiteral("*[Ff]older*.png"), | ||||
64 | QStringLiteral("*[Ff]ront*.jpg"), | ||||
65 | QStringLiteral("*[Ff]ront*.png") | ||||
66 | }; | ||||
67 | | ||||
59 | FileScanner::FileScanner() : d(std::make_unique<FileScannerPrivate>()) | 68 | FileScanner::FileScanner() : d(std::make_unique<FileScannerPrivate>()) | ||
60 | { | 69 | { | ||
61 | } | 70 | } | ||
62 | 71 | | |||
63 | FileScanner::~FileScanner() = default; | 72 | FileScanner::~FileScanner() = default; | ||
64 | 73 | | |||
65 | MusicAudioTrack FileScanner::scanOneFile(const QUrl &scanFile, const QMimeDatabase &mimeDatabase) | 74 | MusicAudioTrack FileScanner::scanOneFile(const QUrl &scanFile, const QMimeDatabase &mimeDatabase) | ||
66 | { | 75 | { | ||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Line(s) | 258 | { | |||
265 | } | 274 | } | ||
266 | } | 275 | } | ||
267 | #endif | 276 | #endif | ||
268 | 277 | | |||
269 | QUrl FileScanner::searchForCoverFile(const QString &localFileName) | 278 | QUrl FileScanner::searchForCoverFile(const QString &localFileName) | ||
270 | { | 279 | { | ||
271 | QFileInfo trackFilePath(localFileName); | 280 | QFileInfo trackFilePath(localFileName); | ||
272 | QDir trackFileDir = trackFilePath.absoluteDir(); | 281 | QDir trackFileDir = trackFilePath.absoluteDir(); | ||
282 | trackFileDir.setFilter(QDir::Files); | ||||
283 | trackFileDir.setNameFilters(d->constSearchStrings); | ||||
284 | QFileInfoList coverFiles = trackFileDir.entryInfoList(); | ||||
285 | if (coverFiles.isEmpty()) { | ||||
273 | QString dirNamePattern = QStringLiteral("*") + trackFileDir.dirName() + QStringLiteral("*"); | 286 | QString dirNamePattern = QStringLiteral("*") + trackFileDir.dirName() + QStringLiteral("*"); | ||
274 | QStringList filters; | 287 | QString dirNameNoSpaces = dirNamePattern.remove(QLatin1Char(' ')); | ||
275 | filters << QStringLiteral("*[Cc]over*.jpg") << QStringLiteral("*[Cc]over*.png") | 288 | QStringList filters = { | ||
276 | << QStringLiteral("*[Ff]older*.jpg") << QStringLiteral("*[Ff]older*.png") | 289 | dirNamePattern + QStringLiteral(".jpg"), | ||
277 | << QStringLiteral("*[Ff]ront*.jpg") << QStringLiteral("*[Ff]ront*.png") | 290 | dirNamePattern + QStringLiteral(".png"), | ||
278 | << dirNamePattern + QStringLiteral(".jpg") << dirNamePattern + QStringLiteral(".png") | 291 | | ||
279 | << dirNamePattern.toLower() + QStringLiteral(".jpg") << dirNamePattern.toLower() + QStringLiteral(".png"); | 292 | dirNameNoSpaces + QStringLiteral(".jpg"), | ||
280 | dirNamePattern.remove(QLatin1Char(' ')); | 293 | dirNameNoSpaces + QStringLiteral(".png") | ||
281 | filters << dirNamePattern + QStringLiteral(".jpg") << dirNamePattern + QStringLiteral(".png") | 294 | }; | ||
282 | << dirNamePattern.toLower() + QStringLiteral(".jpg") << dirNamePattern.toLower() + QStringLiteral(".png"); | | |||
283 | trackFileDir.setNameFilters(filters); | 295 | trackFileDir.setNameFilters(filters); | ||
284 | QFileInfoList coverFiles = trackFileDir.entryInfoList(); | 296 | coverFiles = trackFileDir.entryInfoList(); | ||
297 | } | ||||
285 | if (coverFiles.isEmpty()) { | 298 | if (coverFiles.isEmpty()) { | ||
286 | return QUrl(); | 299 | return QUrl(); | ||
287 | } else { | | |||
288 | return QUrl::fromLocalFile(coverFiles.at(0).absoluteFilePath()); | | |||
289 | } | 300 | } | ||
301 | return QUrl::fromLocalFile(coverFiles.first().absoluteFilePath()); | ||||
290 | } | 302 | } | ||
291 | 303 | | |||
292 | bool FileScanner::checkEmbeddedCoverImage(const QString &localFileName) | 304 | bool FileScanner::checkEmbeddedCoverImage(const QString &localFileName) | ||
293 | { | 305 | { | ||
294 | #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND | 306 | #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND | ||
295 | auto imageData = d->mImageScanner.imageData(localFileName); | 307 | auto imageData = d->mImageScanner.imageData(localFileName); | ||
296 | 308 | | |||
297 | if (imageData.contains(KFileMetaData::EmbeddedImageData::FrontCover)) { | 309 | if (imageData.contains(KFileMetaData::EmbeddedImageData::FrontCover)) { | ||
298 | if (!imageData[KFileMetaData::EmbeddedImageData::FrontCover].isEmpty()) { | 310 | if (!imageData[KFileMetaData::EmbeddedImageData::FrontCover].isEmpty()) { | ||
299 | return true; | 311 | return true; | ||
300 | } | 312 | } | ||
301 | } | 313 | } | ||
302 | #endif | 314 | #endif | ||
303 | 315 | | |||
304 | return false; | 316 | return false; | ||
305 | } | 317 | } |