File indexing completed on 2024-05-12 03:54:31
0001 /* 0002 This file is part of the KDE libraries 0003 0004 SPDX-FileCopyrightText: 2003 Cornelius Schumacher <schumacher@kde.org> 0005 SPDX-FileCopyrightText: 2003 Waldo Bastian <bastian@kde.org> 0006 SPDX-FileCopyrightText: 2003 Zack Rusin <zack@kde.org> 0007 SPDX-FileCopyrightText: 2006 Michaƫl Larouche <michael.larouche@kdemail.net> 0008 SPDX-FileCopyrightText: 2008 Allen Winter <winter@kde.org> 0009 SPDX-FileCopyrightText: 2020 Tomaz Cananbrava <tcanabrava@kde.org> 0010 0011 SPDX-License-Identifier: LGPL-2.0-or-later 0012 */ 0013 0014 #ifndef KCONFIGXMLPARSER_H 0015 #define KCONFIGXMLPARSER_H 0016 0017 #include <QDomDocument> 0018 #include <QRegularExpression> 0019 #include <QString> 0020 0021 #include "KConfigCommonStructs.h" 0022 #include "KConfigParameters.h" 0023 0024 /* This parses the contents of a Xml file into a ParseResult Structure, 0025 * It also fails hard: 0026 * If start() succeeds, you can use the result, 0027 * if start() fails, the program aborts with an error message so there's 0028 * no possibility of generating incorrect code information. 0029 */ 0030 class KConfigXmlParser 0031 { 0032 public: 0033 KConfigXmlParser(const KConfigParameters &cfg, const QString &inputFileName); 0034 0035 // Start the parser and reads the contents of the inputFileName into the ParseResult Structure 0036 void start(); 0037 0038 // Get the result of the parse 0039 ParseResult getParseResult() const; 0040 0041 private: 0042 // creates a `somethingChanged` signal for every property 0043 void createChangedSignal(CfgEntry &readEntry); 0044 0045 void validateNameAndKey(CfgEntry &readEntry, const QDomElement &element); 0046 0047 // TODO: Use std::optional and CfgEntry (without heap allocation) for this function 0048 // *or* fail hard if the parse fails. 0049 CfgEntry *parseEntry(const QString &group, const QString &parentGroup, const QDomElement &element); 0050 0051 // Steps 0052 void readIncludeTag(const QDomElement &element); 0053 void readGroupTag(const QDomElement &element); 0054 void readKcfgfileTag(const QDomElement &element); 0055 void readSignalTag(const QDomElement &element); 0056 0057 // Those are the Entries in the Xml, that represent a parameter within the <group> </group> tag. 0058 void readParameterFromEntry(CfgEntry &entry, const QDomElement &element); 0059 bool hasDefaultCode(CfgEntry &entry, const QDomElement &element); 0060 void readChoicesFromEntry(CfgEntry &entry, const QDomElement &element); 0061 void readGroupElements(CfgEntry &entry, const QDomElement &element); 0062 void readParamDefaultValues(CfgEntry &entry, const QDomElement &element); 0063 0064 private: 0065 ParseResult mParseResult; 0066 KConfigParameters cfg; 0067 QString mInputFileName; 0068 QStringList mAllNames; 0069 QRegularExpression mValidNameRegexp; 0070 }; 0071 0072 #endif