File indexing completed on 2024-05-12 03:54:55
0001 /* 0002 This software is a contribution of the LiMux project of the city of Munich. 0003 SPDX-FileCopyrightText: 2021 Robert Hoffmann <robert@roberthoffmann.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 #ifndef KNETWORKMOUNTS_P_H 0008 #define KNETWORKMOUNTS_P_H 0009 0010 #include "knetworkmounts.h" 0011 0012 #include <QMetaEnum> 0013 #include <QSettings> 0014 0015 class KNetworkMountsPrivate 0016 { 0017 public: 0018 KNetworkMountsPrivate(KNetworkMounts *); 0019 0020 KNetworkMounts *q; 0021 0022 QSettings *m_settings = nullptr; 0023 0024 private: 0025 }; 0026 0027 // Append trailing slashes to path string if missing 0028 static bool ensureTrailingSlash(QString *path) 0029 { 0030 bool changed = false; 0031 if (!path->isEmpty() && !path->endsWith(QLatin1Char('/'))) { 0032 path->append(QLatin1Char('/')); 0033 changed = true; 0034 } 0035 0036 return changed; 0037 } 0038 0039 // Append trailing slashes to path strings if missing 0040 static bool ensureTrailingSlashes(QStringList *paths) 0041 { 0042 bool changed = false; 0043 for (QString &path : *paths) { 0044 if (ensureTrailingSlash(&path)) { 0045 changed = true; 0046 } 0047 } 0048 0049 return changed; 0050 } 0051 0052 // Return the matching configured slow path 0053 static QString getMatchingPath(const QString &_path, const QStringList &slowPaths) 0054 { 0055 if (slowPaths.isEmpty()) { 0056 return QString(); 0057 } 0058 0059 QString path = _path; 0060 if (!path.endsWith(QLatin1Char('/'))) { 0061 path.append(QLatin1Char('/')); 0062 } 0063 0064 for (const QString &slp : slowPaths) { 0065 if (path.startsWith(slp)) { 0066 return slp; 0067 } 0068 } 0069 0070 return QString(); 0071 } 0072 0073 // Convert the enums KNetworkMountsType and KNetworkMountOption to QString 0074 template<typename EnumType> 0075 static QString enumToString(EnumType type) 0076 { 0077 const int intValue = static_cast<int>(type); 0078 return QString::fromUtf8(QMetaEnum::fromType<EnumType>().valueToKey(intValue)); 0079 } 0080 0081 #endif