File indexing completed on 2024-05-12 04:39:39
0001 /* 0002 SPDX-FileCopyrightText: 2014 Sergey Kalinichev <kalinichev.so.0@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef SETTINGSMANAGER_H 0008 #define SETTINGSMANAGER_H 0009 0010 #include "../idefinesandincludesmanager.h" 0011 0012 #include "compilerprovider.h" 0013 #include "icompiler.h" 0014 0015 #include <QVector> 0016 0017 class KConfig; 0018 0019 namespace KDevelop { 0020 class IProject; 0021 class ProjectBaseItem; 0022 } 0023 0024 struct ParserArguments 0025 { 0026 public: 0027 const QString& operator[](Utils::LanguageType languageType) const 0028 { 0029 Q_ASSERT(languageType >= Utils::C && languageType < Utils::Other); 0030 return arguments[languageType]; 0031 } 0032 0033 QString& operator[](Utils::LanguageType languageType) 0034 { 0035 Q_ASSERT(languageType >= Utils::C && languageType < Utils::Other); 0036 return arguments[languageType]; 0037 } 0038 0039 /// Is any of the arguments empty? 0040 bool isAnyEmpty() const; 0041 0042 private: 0043 QString arguments[Utils::Other]; 0044 0045 public: 0046 bool parseAmbiguousAsCPP; 0047 }; 0048 0049 Q_DECLARE_METATYPE(ParserArguments) 0050 Q_DECLARE_TYPEINFO(ParserArguments, Q_MOVABLE_TYPE); 0051 0052 struct ConfigEntry 0053 { 0054 QString path; 0055 QStringList includes; 0056 KDevelop::Defines defines; 0057 CompilerPointer compiler; 0058 ParserArguments parserArguments; 0059 0060 explicit ConfigEntry( const QString& path = QString() ); 0061 0062 // FIXME: get rid of this but stay backwards compatible 0063 void setDefines(const QHash<QString, QVariant>& defines); 0064 }; 0065 Q_DECLARE_TYPEINFO(ConfigEntry, Q_MOVABLE_TYPE); 0066 0067 namespace Utils 0068 { 0069 LanguageType languageType(const QString& path, bool treatAmbiguousAsCPP = true); 0070 } 0071 0072 class SettingsManager 0073 { 0074 public: 0075 ~SettingsManager(); 0076 0077 QVector<ConfigEntry> readPaths(KConfig* cfg) const; 0078 void writePaths(KConfig* cfg, const QVector<ConfigEntry>& paths); 0079 0080 QVector<CompilerPointer> userDefinedCompilers() const; 0081 void writeUserDefinedCompilers(const QVector<CompilerPointer>& compilers); 0082 0083 bool needToReparseCurrentProject( KConfig* cfg ) const; 0084 0085 ParserArguments defaultParserArguments() const; 0086 0087 CompilerProvider* provider(); 0088 const CompilerProvider* provider() const; 0089 0090 static SettingsManager* globalInstance(); 0091 0092 private: 0093 SettingsManager(); 0094 CompilerProvider m_provider; 0095 }; 0096 0097 #endif // SETTINGSMANAGER_H