File indexing completed on 2024-04-14 03:51:04

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2006, 2007 Thomas Braxton <kde.braxton@gmail.com>
0004     SPDX-FileCopyrightText: 2001 Waldo Bastian <bastian@kde.org>
0005     SPDX-FileCopyrightText: 1999 Preston Brown <pbrown@kde.org>
0006     SPDX-FileCopyrightText: 1997 Matthias Kalle Dalheimer <kalle@kde.org>
0007 
0008     SPDX-License-Identifier: LGPL-2.0-or-later
0009 */
0010 
0011 #ifndef KCONFIG_P_H
0012 #define KCONFIG_P_H
0013 
0014 #include "kconfigbackend_p.h"
0015 #include "kconfigdata_p.h"
0016 #include "kconfiggroup.h"
0017 
0018 #include <QDir>
0019 #include <QFile>
0020 #include <QStack>
0021 #include <QStringList>
0022 
0023 class KConfigPrivate
0024 {
0025     friend class KConfig;
0026 
0027 public:
0028     KConfig::OpenFlags openFlags;
0029     QStandardPaths::StandardLocation resourceType;
0030 
0031     void changeFileName(const QString &fileName);
0032 
0033     // functions for KConfigGroup
0034     bool canWriteEntry(const QString &group, QAnyStringView key, bool isDefault = false) const;
0035     QString lookupData(const QString &group, QAnyStringView key, KEntryMap::SearchFlags flags, bool *expand) const;
0036     QByteArray lookupData(const QString &group, QAnyStringView key, KEntryMap::SearchFlags flags) const;
0037     KEntry lookupInternalEntry(const QString &group, QAnyStringView key, KEntryMap::SearchFlags flags) const;
0038 
0039     void putData(const QString &groupName, const char *key, const QByteArray &value, KConfigBase::WriteConfigFlags flags, bool expand = false);
0040     void setEntryData(const QString &groupName, const char *key, const QByteArray &value, KEntryMap::EntryOptions flags)
0041     {
0042         if (entryMap.setEntry(groupName, key, value, flags)) {
0043             bDirty = true;
0044         }
0045     }
0046     void revertEntry(const QString &group, QAnyStringView key, KConfigBase::WriteConfigFlags flags);
0047     /**
0048      * Returns a list of keys used with entries in a particular group.
0049      *
0050      * This does not include keys of deleted entries or those with default values.
0051      * I.e. all the keys for which there will be also entries in KConfig::entryMap().
0052      *
0053      * @return A sorted list of keys in the group specified.
0054      *         The returned list may be empty if the group is empty, or not found.
0055      */
0056     QStringList usedKeyList(const QString &theGroup) const;
0057     QStringList groupList(const QString &groupName) const;
0058     // copies the entries from @p source to @p otherGroup changing all occurrences
0059     // of @p source with @p destination
0060     void copyGroup(const QString &source, const QString &destination, KConfigGroup *otherGroup, KConfigBase::WriteConfigFlags flags) const;
0061     QList<QByteArray> keyListImpl(const QString &groupName) const;
0062     QSet<QString> allSubGroups(const QString &parentGroupName) const;
0063     bool hasNonDeletedEntries(const QString &groupName) const;
0064 
0065     void notifyClients(const QHash<QString, QByteArrayList> &changes, const QString &path);
0066 
0067     static QString expandString(const QString &value);
0068 
0069 protected:
0070     QExplicitlySharedDataPointer<KConfigBackend> mBackend;
0071 
0072     KConfigPrivate(KConfig::OpenFlags flags, QStandardPaths::StandardLocation type);
0073 
0074     virtual ~KConfigPrivate()
0075     {
0076     }
0077 
0078     bool bDynamicBackend : 1; // do we own the backend?
0079 private:
0080     bool bDirty : 1;
0081     bool bReadDefaults : 1;
0082     bool bFileImmutable : 1;
0083     bool bForceGlobal : 1;
0084     bool bSuppressGlobal : 1;
0085 
0086     static bool mappingsRegistered;
0087 
0088     KEntryMap entryMap;
0089     QString backendType;
0090     QStack<QString> extraFiles;
0091 
0092     QString locale;
0093     QString fileName;
0094     QString etc_kderc;
0095     KConfigBase::AccessMode configState;
0096 
0097     bool wantGlobals() const
0098     {
0099         return openFlags & KConfig::IncludeGlobals && !bSuppressGlobal;
0100     }
0101     bool wantDefaults() const
0102     {
0103         return openFlags & KConfig::CascadeConfig;
0104     }
0105     bool isSimple() const
0106     {
0107         return openFlags == KConfig::SimpleConfig;
0108     }
0109     bool isReadOnly() const
0110     {
0111         return configState == KConfig::ReadOnly;
0112     }
0113 
0114     bool setLocale(const QString &aLocale);
0115     QStringList getGlobalFiles() const;
0116     void parseGlobalFiles();
0117     void parseConfigFiles();
0118     void initCustomized(KConfig *);
0119     bool lockLocal();
0120 };
0121 
0122 #endif // KCONFIG_P_H