| 1 | /* |
| 2 | This software is a contribution of the LiMux project of the city of Munich. |
| 3 | SPDX-FileCopyrightText: 2021 Robert Hoffmann <robert@roberthoffmann.de> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | #ifndef KNETWORKMOUNTS_P_H |
| 8 | #define KNETWORKMOUNTS_P_H |
| 9 | |
| 10 | #include "knetworkmounts.h" |
| 11 | |
| 12 | #include <QMetaEnum> |
| 13 | #include <QSettings> |
| 14 | |
| 15 | class KNetworkMountsPrivate |
| 16 | { |
| 17 | public: |
| 18 | KNetworkMountsPrivate(KNetworkMounts *); |
| 19 | |
| 20 | KNetworkMounts *q; |
| 21 | |
| 22 | QSettings *m_settings = nullptr; |
| 23 | |
| 24 | private: |
| 25 | }; |
| 26 | |
| 27 | // Append trailing slashes to path string if missing |
| 28 | static bool ensureTrailingSlash(QString *path) |
| 29 | { |
| 30 | bool changed = false; |
| 31 | if (!path->isEmpty() && !path->endsWith(c: QLatin1Char('/'))) { |
| 32 | path->append(c: QLatin1Char('/')); |
| 33 | changed = true; |
| 34 | } |
| 35 | |
| 36 | return changed; |
| 37 | } |
| 38 | |
| 39 | // Append trailing slashes to path strings if missing |
| 40 | static bool ensureTrailingSlashes(QStringList *paths) |
| 41 | { |
| 42 | bool changed = false; |
| 43 | for (QString &path : *paths) { |
| 44 | if (ensureTrailingSlash(path: &path)) { |
| 45 | changed = true; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return changed; |
| 50 | } |
| 51 | |
| 52 | // Return the matching configured slow path |
| 53 | static QString getMatchingPath(const QString &_path, const QStringList &slowPaths) |
| 54 | { |
| 55 | if (slowPaths.isEmpty()) { |
| 56 | return QString(); |
| 57 | } |
| 58 | |
| 59 | QString path = _path; |
| 60 | if (!path.endsWith(c: QLatin1Char('/'))) { |
| 61 | path.append(c: QLatin1Char('/')); |
| 62 | } |
| 63 | |
| 64 | for (const QString &slp : slowPaths) { |
| 65 | if (path.startsWith(s: slp)) { |
| 66 | return slp; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return QString(); |
| 71 | } |
| 72 | |
| 73 | // Convert the enums KNetworkMountsType and KNetworkMountOption to QString |
| 74 | template<typename EnumType> |
| 75 | static QString enumToString(EnumType type) |
| 76 | { |
| 77 | const int intValue = static_cast<int>(type); |
| 78 | return QString::fromUtf8(QMetaEnum::fromType<EnumType>().valueToKey(intValue)); |
| 79 | } |
| 80 | |
| 81 | #endif |
| 82 | |