File indexing completed on 2024-05-12 05:46:41
0001 /* This file is part of the KDE libraries 0002 * Copyright (C) 1999 Waldo Bastian <bastian@kde.org> 0003 * Copyright (C) 2005-2013 David Faure <faure@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License version 2 as published by the Free Software Foundation; 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 **/ 0019 0020 #ifndef KSYCOCAUTILS_P_H 0021 #define KSYCOCAUTILS_P_H 0022 0023 #include <QFileInfo> 0024 #include <QString> 0025 #include <QDir> 0026 0027 class QStringList; 0028 class QDataStream; 0029 0030 namespace KSycocaUtilsPrivate 0031 { 0032 0033 // helper function for visitResourceDirectory 0034 template<typename Visitor> 0035 bool visitResourceDirectoryHelper(const QString &dirname, Visitor visitor) 0036 { 0037 QDir dir(dirname); 0038 const QFileInfoList list = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs, QDir::Unsorted); 0039 for (const QFileInfo &fi : list) { 0040 if (fi.isDir() && !fi.isSymLink() && !fi.isBundle()) { // same check as in vfolder_menu.cpp 0041 if (!visitor(fi)) { 0042 return false; 0043 } 0044 if (!visitResourceDirectoryHelper(fi.filePath(), visitor)) { 0045 return false; 0046 } 0047 } 0048 } 0049 return true; 0050 } 0051 0052 // visitor is a function/functor accepts QFileInfo as argument and returns bool 0053 // visitResourceDirectory will visit the resource directory in a depth-first way. 0054 // visitor can terminate the visit by returning false, and visitResourceDirectory 0055 // will also return false in this case, otherwise it will return true. 0056 template<typename Visitor> 0057 bool visitResourceDirectory(const QString &dirname, Visitor visitor) 0058 { 0059 QFileInfo info(dirname); 0060 if (!visitor(info)) { 0061 return false; 0062 } 0063 0064 // Recurse only for services and menus. 0065 // Apps and servicetypes don't need recursion, so save the directory listing. 0066 if (!dirname.contains(QLatin1String("/applications")) && !dirname.contains(QLatin1String("/kservicetypes5"))) { 0067 return visitResourceDirectoryHelper(dirname, visitor); 0068 } 0069 0070 return true; 0071 } 0072 0073 } 0074 0075 #endif /* KSYCOCAUTILS_P_H */ 0076