Changeset View
Changeset View
Standalone View
Standalone View
wallpapers/image/backgroundlistmodel.cpp
Show First 20 Lines • Show All 147 Lines • ▼ Show 20 Line(s) | |||||
148 | 148 | | |||
149 | void BackgroundListModel::processPaths(const QStringList &paths) | 149 | void BackgroundListModel::processPaths(const QStringList &paths) | ||
150 | { | 150 | { | ||
151 | if (!m_wallpaper) { | 151 | if (!m_wallpaper) { | ||
152 | return; | 152 | return; | ||
153 | } | 153 | } | ||
154 | 154 | | |||
155 | QList<KPackage::Package> newPackages; | 155 | QList<KPackage::Package> newPackages; | ||
156 | Q_FOREACH (QString file, paths) { | 156 | for (QString file : paths) { | ||
157 | // check if the path is a symlink and if it is, | 157 | // check if the path is a symlink and if it is, | ||
158 | // work with the target rather than the symlink | 158 | // work with the target rather than the symlink | ||
159 | QFileInfo info(file); | 159 | QFileInfo info(file); | ||
160 | if (info.isSymLink()) { | 160 | if (info.isSymLink()) { | ||
161 | file = info.symLinkTarget(); | 161 | file = info.symLinkTarget(); | ||
162 | } | 162 | } | ||
163 | // now check if the path contains "contents" part | 163 | // now check if the path contains "contents" part | ||
164 | // which could indicate that the file is part of some other | 164 | // which could indicate that the file is part of some other | ||
Show All 25 Lines | 187 | if (!contains(file) && QFile::exists(file)) { | |||
190 | if (package.isValid()) { | 190 | if (package.isValid()) { | ||
191 | m_wallpaper->findPreferedImageInPackage(package); | 191 | m_wallpaper->findPreferedImageInPackage(package); | ||
192 | newPackages << package; | 192 | newPackages << package; | ||
193 | } | 193 | } | ||
194 | } | 194 | } | ||
195 | } | 195 | } | ||
196 | 196 | | |||
197 | // add new files to dirwatch | 197 | // add new files to dirwatch | ||
198 | Q_FOREACH (const KPackage::Package &b, newPackages) { | 198 | for (const KPackage::Package &b : qAsConst(newPackages)) { | ||
199 | if (!m_dirwatch.contains(b.path())) { | 199 | if (!m_dirwatch.contains(b.path())) { | ||
200 | m_dirwatch.addFile(b.path()); | 200 | m_dirwatch.addFile(b.path()); | ||
201 | } | 201 | } | ||
202 | } | 202 | } | ||
203 | 203 | | |||
204 | if (!newPackages.isEmpty()) { | 204 | if (!newPackages.isEmpty()) { | ||
205 | const int start = rowCount(); | 205 | const int start = rowCount(); | ||
206 | beginInsertRows(QModelIndex(), start, start + newPackages.size() - 1); | 206 | beginInsertRows(QModelIndex(), start, start + newPackages.size() - 1); | ||
▲ Show 20 Lines • Show All 299 Lines • ▼ Show 20 Line(s) | |||||
506 | 506 | | |||
507 | QStringList BackgroundFinder::suffixes() | 507 | QStringList BackgroundFinder::suffixes() | ||
508 | { | 508 | { | ||
509 | QMutexLocker lock(&s_suffixMutex); | 509 | QMutexLocker lock(&s_suffixMutex); | ||
510 | if (s_suffixes.isEmpty()) { | 510 | if (s_suffixes.isEmpty()) { | ||
511 | QSet<QString> suffixes; | 511 | QSet<QString> suffixes; | ||
512 | 512 | | |||
513 | QMimeDatabase db; | 513 | QMimeDatabase db; | ||
514 | Q_FOREACH (const QByteArray &mimeType, QImageReader::supportedMimeTypes()) { | 514 | const auto mimeTypes = QImageReader::supportedMimeTypes(); | ||
515 | for (const QByteArray &mimeType : mimeTypes) { | ||||
515 | QMimeType mime(db.mimeTypeForName(mimeType)); | 516 | QMimeType mime(db.mimeTypeForName(mimeType)); | ||
516 | Q_FOREACH (const QString &pattern, mime.globPatterns()) { | 517 | const auto patterns = mime.globPatterns(); | ||
518 | for (const QString &pattern : patterns) { | ||||
517 | suffixes.insert(pattern); | 519 | suffixes.insert(pattern); | ||
518 | } | 520 | } | ||
519 | } | 521 | } | ||
520 | 522 | | |||
521 | s_suffixes = suffixes.toList(); | 523 | s_suffixes = suffixes.toList(); | ||
522 | } | 524 | } | ||
523 | 525 | | |||
524 | return s_suffixes; | 526 | return s_suffixes; | ||
Show All 19 Lines | 538 | { | |||
544 | dir.setNameFilters(suffixes()); | 546 | dir.setNameFilters(suffixes()); | ||
545 | KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Wallpaper/Images")); | 547 | KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Wallpaper/Images")); | ||
546 | 548 | | |||
547 | int i; | 549 | int i; | ||
548 | for (i = 0; i < m_paths.count(); ++i) { | 550 | for (i = 0; i < m_paths.count(); ++i) { | ||
549 | const QString path = m_paths.at(i); | 551 | const QString path = m_paths.at(i); | ||
550 | dir.setPath(path); | 552 | dir.setPath(path); | ||
551 | const QFileInfoList files = dir.entryInfoList(); | 553 | const QFileInfoList files = dir.entryInfoList(); | ||
552 | Q_FOREACH (const QFileInfo &wp, files) { | 554 | for (const QFileInfo &wp : files) { | ||
553 | if (wp.isDir()) { | 555 | if (wp.isDir()) { | ||
554 | //qCDebug(IMAGEWALLPAPER) << "scanning directory" << wp.fileName(); | 556 | //qCDebug(IMAGEWALLPAPER) << "scanning directory" << wp.fileName(); | ||
555 | 557 | | |||
556 | const QString name = wp.fileName(); | 558 | const QString name = wp.fileName(); | ||
557 | if (name == QString::fromLatin1(".") || name == QString::fromLatin1("..")) { | 559 | if (name == QString::fromLatin1(".") || name == QString::fromLatin1("..")) { | ||
558 | // do nothing | 560 | // do nothing | ||
559 | continue; | 561 | continue; | ||
560 | } | 562 | } | ||
Show All 30 Lines |