File indexing completed on 2024-11-10 05:02:44
0001 /* 0002 SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com> 0003 SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "imagefinder.h" 0009 0010 #include <QDir> 0011 #include <QImageReader> 0012 0013 #include "findsymlinktarget.h" 0014 #include "suffixcheck.h" 0015 0016 ImageFinder::ImageFinder(const QStringList &paths, QObject *parent) 0017 : QObject(parent) 0018 , m_paths(paths) 0019 { 0020 } 0021 0022 void ImageFinder::run() 0023 { 0024 QStringList images; 0025 0026 QDir dir; 0027 dir.setFilter(QDir::AllDirs | QDir::Files | QDir::Readable | QDir::NoDotAndDotDot); 0028 dir.setNameFilters(suffixes()); 0029 0030 const auto filterCondition = [](const QFileInfo &info) { 0031 const QString path = info.absoluteFilePath(); 0032 0033 return info.baseName() != QLatin1String("screenshot") && !path.contains(QLatin1String("contents/images/")) 0034 && !path.contains(QLatin1String("contents/images_dark/")); 0035 }; 0036 int i; 0037 0038 for (i = 0; i < m_paths.size(); ++i) { 0039 const QString &path = m_paths.at(i); 0040 const QFileInfo info(findSymlinkTarget(QFileInfo(path))); 0041 const QString target = info.absoluteFilePath(); 0042 0043 if (!info.exists() || !filterCondition(info)) { 0044 // is in a package 0045 continue; 0046 } 0047 0048 if (info.isFile()) { 0049 if (isAcceptableSuffix(info.suffix()) && !info.isSymLink()) { 0050 images.append(target); 0051 } 0052 0053 continue; 0054 } 0055 0056 dir.setPath(target); 0057 const QFileInfoList files = dir.entryInfoList(); 0058 0059 for (const QFileInfo &wp : files) { 0060 const QFileInfo realwp(findSymlinkTarget(wp)); 0061 0062 if (realwp.isFile()) { 0063 if (filterCondition(realwp) && !realwp.isSymLink()) { 0064 images.append(realwp.filePath()); 0065 } 0066 } else if (realwp.isDir() && !realwp.absoluteFilePath().contains(QLatin1String("contents/images"))) { 0067 // add this to the directories we should be looking at 0068 if (!m_paths.contains(realwp.filePath())) { 0069 m_paths.append(realwp.filePath()); 0070 } 0071 } 0072 } 0073 } 0074 0075 images.removeAll(QString()); 0076 images.removeDuplicates(); 0077 0078 Q_EMIT imageFound(images); 0079 }