1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1999 Waldo Bastian <bastian@kde.org>
4 SPDX-FileCopyrightText: 2005-2013 David Faure <faure@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-only
7*/
8
9#ifndef KSYCOCAUTILS_P_H
10#define KSYCOCAUTILS_P_H
11
12#include <QDir>
13#include <QFileInfo>
14#include <QString>
15
16namespace KSycocaUtilsPrivate
17{
18// helper function for visitResourceDirectory
19template<typename Visitor>
20bool visitResourceDirectoryHelper(const QString &dirname, Visitor visitor)
21{
22 QDir dir(dirname);
23 const QFileInfoList list = dir.entryInfoList(filters: QDir::NoDotAndDotDot | QDir::Dirs, sort: QDir::Unsorted);
24 for (const QFileInfo &fi : list) {
25 if (fi.isDir() && !fi.isSymLink() && !fi.isBundle()) { // same check as in vfolder_menu.cpp
26 if (!visitor(fi)) {
27 return false;
28 }
29 if (!visitResourceDirectoryHelper(fi.filePath(), visitor)) {
30 return false;
31 }
32 }
33 }
34 return true;
35}
36
37// visitor is a function/functor accepts QFileInfo as argument and returns bool
38// visitResourceDirectory will visit the resource directory in a depth-first way.
39// visitor can terminate the visit by returning false, and visitResourceDirectory
40// will also return false in this case, otherwise it will return true.
41template<typename Visitor>
42bool visitResourceDirectory(const QString &dirname, Visitor visitor)
43{
44 QFileInfo info(dirname);
45 if (!visitor(info)) {
46 return false;
47 }
48
49 // Recurse only for services and menus.
50 if (!dirname.contains(s: QLatin1String("/applications"))) {
51 return visitResourceDirectoryHelper(dirname, visitor);
52 }
53
54 return true;
55}
56
57}
58
59#endif /* KSYCOCAUTILS_P_H */
60

source code of kservice/src/sycoca/ksycocautils_p.h