File indexing completed on 2024-12-01 10:41:25

0001 /*
0002     SPDX-FileCopyrightText: 2024 Ralf Habacker  ralf.habacker @freenet.de
0003 
0004     This file is part of libalkimia.
0005 
0006     SPDX-License-Identifier: LGPL-2.1-or-later
0007 */
0008 
0009 #include "alkutils.h"
0010 
0011 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
0012 #include <QDir>
0013 #include <QStandardPaths>
0014 
0015 QStringList AlkUtils::getDataFiles(const QString &path, const QStringList &extensions)
0016 {
0017     QStringList resources;
0018     const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, path, QStandardPaths::LocateDirectory);
0019     Q_FOREACH (const QString& dir, dirs) {
0020         const QStringList fileNames = QDir(dir).entryList(extensions);
0021         Q_FOREACH (const QString& file, fileNames) {
0022             resources.append(dir + '/' + file);
0023         }
0024     }
0025     return resources;
0026 }
0027 
0028 QString AlkUtils::locateDataFile(const QString &filePath)
0029 {
0030 
0031     return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("alkimia%1/%2").arg(TARGET_SUFFIX, filePath));
0032 }
0033 
0034 #else
0035 #include <KGlobal>
0036 #include <KStandardDirs>
0037 
0038 QStringList AlkUtils::getDataFiles(const QString &path, const QStringList &extensions)
0039 {
0040     const QString filename = QString("%1/%2").arg(path, extensions.at(0));
0041     const QStringList resources = KStandardDirs().findAllResources("data", filename);
0042     return resources;
0043 }
0044 
0045 QString AlkUtils::locateDataFile(const QString &filePath)
0046 {
0047     return KGlobal::dirs()->findResource("appdata", filePath);
0048 }
0049 #endif