2021-04-08 10:29:21 +08:00
|
|
|
#ifndef SETTINGS_H
|
|
|
|
#define SETTINGS_H
|
|
|
|
|
|
|
|
#include <QSettings>
|
2021-04-13 22:17:18 +08:00
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
2021-04-08 10:29:21 +08:00
|
|
|
|
2021-04-15 11:18:14 +08:00
|
|
|
/**
|
|
|
|
* use the following command to get gcc's default bin/library folders:
|
|
|
|
* gcc -print-search-dirs
|
|
|
|
*/
|
|
|
|
|
2021-04-15 21:32:45 +08:00
|
|
|
#define SETTING_DIRS "Dirs"
|
|
|
|
#define SETTING_EDITOR "Editor"
|
|
|
|
#define SETTING_COMPILTER_SETS "CompilerSets"
|
|
|
|
#define SETTING_COMPILTER_SETS_DEFAULT_INDEX "defaultIndex"
|
|
|
|
#define SETTING_COMPILTER_SETS_COUNT "count"
|
|
|
|
#define SETTING_COMPILTER_SET "CompilerSet_%1"
|
2021-04-13 11:23:37 +08:00
|
|
|
#define SETTING_EDITOR_DEFAULT_ENCODING "default_encoding"
|
|
|
|
#define SETTING_EDITOR_AUTO_INDENT "default_auto_indent"
|
2021-04-09 17:48:25 +08:00
|
|
|
|
2021-04-15 11:18:14 +08:00
|
|
|
|
|
|
|
extern const char ValueToChar[28];
|
|
|
|
|
2021-04-13 22:17:18 +08:00
|
|
|
class Settings;
|
|
|
|
|
|
|
|
typedef struct {
|
2021-04-15 11:18:14 +08:00
|
|
|
QString name; // language table index of "Generate debugging info"
|
|
|
|
QString section; // language table index of "C options"
|
2021-04-13 22:17:18 +08:00
|
|
|
bool isC;
|
|
|
|
bool isCpp; // True (C++ option?) - can be both C and C++ option...
|
|
|
|
bool isLinker; // Is it a linker param
|
|
|
|
int value; // True
|
2021-04-15 11:18:14 +08:00
|
|
|
QString setting; // "-g3"
|
|
|
|
QStringList choices; // replaces "Yes/No" standard choices (max 30 different choices)
|
|
|
|
} CompilerOption;
|
|
|
|
|
|
|
|
using PCompilerOption = std::shared_ptr<CompilerOption>;
|
|
|
|
|
|
|
|
using CompilerOptionList=std::vector<std::shared_ptr<CompilerOption>>;
|
2021-04-08 10:29:21 +08:00
|
|
|
|
|
|
|
class Settings
|
|
|
|
{
|
2021-04-13 11:23:37 +08:00
|
|
|
private:
|
2021-04-15 11:18:14 +08:00
|
|
|
|
2021-04-13 11:23:37 +08:00
|
|
|
class _Base {
|
|
|
|
public:
|
|
|
|
explicit _Base(Settings* settings, const QString& groupName);
|
|
|
|
void setDefault(const QString &key, const QVariant &value);
|
|
|
|
void setValue(const QString &key, const QVariant &value);
|
|
|
|
QVariant value(const QString &key);
|
|
|
|
protected:
|
|
|
|
Settings* mSettings;
|
|
|
|
QString mGroup;
|
|
|
|
};
|
2021-04-08 10:29:21 +08:00
|
|
|
|
2021-04-13 11:23:37 +08:00
|
|
|
public:
|
|
|
|
class Dirs: public _Base {
|
|
|
|
public:
|
|
|
|
explicit Dirs(Settings * settings);
|
|
|
|
const QString app() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Editor: public _Base {
|
|
|
|
public:
|
|
|
|
explicit Editor(Settings * settings);
|
|
|
|
QByteArray defaultEncoding();
|
|
|
|
void setDefaultEncoding(const QByteArray& encoding);
|
|
|
|
bool autoIndent();
|
|
|
|
void setAutoIndent(bool indent);
|
|
|
|
};
|
2021-04-08 10:29:21 +08:00
|
|
|
|
2021-04-15 11:18:14 +08:00
|
|
|
class CompilerSet {
|
2021-04-13 22:17:18 +08:00
|
|
|
public:
|
2021-04-15 11:18:14 +08:00
|
|
|
explicit CompilerSet(const QString& compilerFolder = QString());
|
|
|
|
explicit CompilerSet(const CompilerSet& set);
|
|
|
|
|
|
|
|
CompilerSet& operator= (const CompilerSet& ) = delete;
|
|
|
|
CompilerSet& operator= (const CompilerSet&& ) = delete;
|
|
|
|
|
|
|
|
//properties
|
|
|
|
void addOption(const QString& name, const QString section, bool isC,
|
|
|
|
bool isCpp, bool isLinker,
|
|
|
|
int value, const QString& setting,
|
|
|
|
const QStringList& choices = QStringList());
|
2021-04-15 21:32:45 +08:00
|
|
|
PCompilerOption findOption(const QString& setting);
|
2021-04-15 11:18:14 +08:00
|
|
|
char getOptionValue(const QString& setting);
|
|
|
|
void setOption(const QString& setting, char valueChar);
|
|
|
|
void setOption(PCompilerOption& option, char valueChar);
|
|
|
|
|
|
|
|
const QString& CCompilerName() const;
|
|
|
|
void setCCompilerName(const QString& name);
|
2021-04-15 21:32:45 +08:00
|
|
|
const QString& cppCompilerName() const;
|
2021-04-15 11:18:14 +08:00
|
|
|
void setCppCompilerName(const QString& name);
|
2021-04-15 21:32:45 +08:00
|
|
|
const QString& makeName() const;
|
2021-04-15 11:18:14 +08:00
|
|
|
void setMakeName(const QString& name);
|
2021-04-15 21:32:45 +08:00
|
|
|
const QString& debuggerName() const;
|
2021-04-15 11:18:14 +08:00
|
|
|
void setDebuggerName(const QString& name);
|
2021-04-15 21:32:45 +08:00
|
|
|
const QString& profilerName() const;
|
2021-04-15 11:18:14 +08:00
|
|
|
void setProfilerName(const QString& name);
|
2021-04-15 21:32:45 +08:00
|
|
|
const QString& resourceCompilerName() const;
|
|
|
|
void setResourceCompilerName(const QString& name);
|
2021-04-15 11:18:14 +08:00
|
|
|
|
|
|
|
QStringList& binDirs();
|
|
|
|
QStringList& CIncludeDirs();
|
|
|
|
QStringList& CppIncludeDirs();
|
|
|
|
QStringList& LibDirs();
|
|
|
|
|
|
|
|
const QString& dumpMachine();
|
|
|
|
void setDumpMachine(const QString& value);
|
|
|
|
const QString& version();
|
|
|
|
void setVersion(const QString& value);
|
|
|
|
const QString& type();
|
|
|
|
void setType(const QString& value);
|
2021-04-15 21:32:45 +08:00
|
|
|
const QString& name();
|
|
|
|
void setName(const QString& value);
|
2021-04-15 11:18:14 +08:00
|
|
|
const QString& folder();
|
|
|
|
void setFolder(const QString& value);
|
|
|
|
QStringList& defines();
|
|
|
|
const QString& target();
|
|
|
|
void setTarget(const QString& value);
|
|
|
|
|
|
|
|
bool useCustomCompileParams();
|
|
|
|
void setUseCustomCompileParams(bool value);
|
|
|
|
bool useCustomLinkParams();
|
|
|
|
void setUseCustomLinkParams(bool value);
|
|
|
|
const QString& customCompileParams();
|
|
|
|
void setCustomCompileParams(const QString& value);
|
|
|
|
const QString& customLinkParams();
|
|
|
|
void setCustomLinkParams(const QString& value);
|
|
|
|
bool staticLink();
|
|
|
|
void setStaticLink(bool value);
|
|
|
|
bool autoAddCharsetParams();
|
|
|
|
void setAutoAddCharsetParams(bool value);
|
|
|
|
|
|
|
|
CompilerOptionList& options();
|
|
|
|
|
2021-04-15 21:32:45 +08:00
|
|
|
//Converts options to and from memory format
|
|
|
|
QByteArray iniOptions() const;
|
|
|
|
void setIniOptions(const QByteArray& value);
|
|
|
|
|
2021-04-15 11:18:14 +08:00
|
|
|
private:
|
|
|
|
int charToValue(char valueChar);
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
void setProperties(const QString& binDir);
|
|
|
|
void setExecutables();
|
|
|
|
void setDirectories();
|
|
|
|
void setUserInput();
|
|
|
|
void setOptions();
|
|
|
|
|
|
|
|
QByteArray getCompilerOutput(const QString& binDir, const QString& binFile,
|
|
|
|
const QStringList& arguments);
|
2021-04-13 22:17:18 +08:00
|
|
|
private:
|
|
|
|
// Executables, most are hardcoded
|
|
|
|
QString mCCompilerName;
|
2021-04-15 11:18:14 +08:00
|
|
|
QString mCppCompilerName;
|
2021-04-13 22:17:18 +08:00
|
|
|
QString mMakeName;
|
|
|
|
QString mDebuggerName;
|
|
|
|
QString mProfilerName;
|
|
|
|
QString mResourceCompilerName;
|
|
|
|
|
|
|
|
// Directories, mostly hardcoded too
|
|
|
|
QStringList mBinDirs;
|
|
|
|
QStringList mCIncludeDirs;
|
2021-04-15 11:18:14 +08:00
|
|
|
QStringList mCppIncludeDirs;
|
2021-04-13 22:17:18 +08:00
|
|
|
QStringList mLibDirs;
|
|
|
|
|
|
|
|
// Misc. properties
|
|
|
|
QString mDumpMachine; // "x86_64-w64-mingw32", "mingw32" etc
|
|
|
|
QString mVersion; // "4.7.1"
|
|
|
|
QString mType; // "TDM-GCC", "MinGW"
|
|
|
|
QString mName; // "TDM-GCC 4.7.1 Release"
|
|
|
|
QString mFolder; // MinGW64, MinGW32
|
2021-04-15 11:18:14 +08:00
|
|
|
QStringList mDefines; // list of predefined constants
|
2021-04-13 22:17:18 +08:00
|
|
|
QString mTarget; // 'X86_64' / 'i686'
|
|
|
|
|
|
|
|
// User settings
|
2021-04-15 11:18:14 +08:00
|
|
|
bool mUseCustomCompileParams;
|
|
|
|
bool mUseCustomLinkParams;
|
2021-04-13 22:17:18 +08:00
|
|
|
QString mCustomCompileParams;
|
|
|
|
QString mCustomLinkParams;
|
|
|
|
bool mStaticLink;
|
2021-04-15 11:18:14 +08:00
|
|
|
bool mAutoAddCharsetParams;
|
2021-04-13 22:17:18 +08:00
|
|
|
|
|
|
|
// Options
|
2021-04-15 11:18:14 +08:00
|
|
|
CompilerOptionList mOptions;
|
2021-04-13 22:17:18 +08:00
|
|
|
};
|
|
|
|
|
2021-04-15 21:32:45 +08:00
|
|
|
typedef std::shared_ptr<CompilerSet> PCompilerSet;
|
|
|
|
typedef std::vector<PCompilerSet> CompilerSetList;
|
|
|
|
|
|
|
|
class CompilerSets {
|
|
|
|
public:
|
|
|
|
explicit CompilerSets(Settings* settings);
|
|
|
|
|
|
|
|
PCompilerSet addSet(const CompilerSet& set);
|
|
|
|
PCompilerSet addSet(const QString& folder=QString());
|
|
|
|
|
|
|
|
void addSets(const QString& folder);
|
|
|
|
void clearSets();
|
|
|
|
void findSets();
|
|
|
|
void saveSets();
|
|
|
|
void loadSets();
|
|
|
|
//properties
|
|
|
|
CompilerSetList& list();
|
|
|
|
int size() const;
|
|
|
|
int defaultIndex() const;
|
|
|
|
void setDefaultIndex(int value);
|
|
|
|
private:
|
|
|
|
void saveSet(int index);
|
|
|
|
PCompilerSet loadSet(int index);
|
|
|
|
CompilerSetList mList;
|
|
|
|
int mDefaultIndex;
|
|
|
|
Settings* mSettings;
|
|
|
|
};
|
|
|
|
|
2021-04-08 10:29:21 +08:00
|
|
|
public:
|
2021-04-13 22:17:18 +08:00
|
|
|
explicit Settings(const QString& filename);
|
|
|
|
explicit Settings(Settings&& settings) = delete;
|
|
|
|
explicit Settings(const Settings& settings) = delete;
|
2021-04-08 10:29:21 +08:00
|
|
|
|
2021-04-13 22:17:18 +08:00
|
|
|
Settings& operator= (const Settings& settings) = delete;
|
|
|
|
Settings& operator= (const Settings&& settings) = delete;
|
2021-04-13 11:23:37 +08:00
|
|
|
void setDefault(const QString& group, const QString &key, const QVariant &value);
|
|
|
|
void setValue(const QString& group, const QString &key, const QVariant &value);
|
|
|
|
QVariant value(const QString& group, const QString &key);
|
|
|
|
|
|
|
|
Dirs& dirs();
|
|
|
|
Editor& editor();
|
2021-04-15 21:32:45 +08:00
|
|
|
CompilerSets& compilerSets();
|
2021-04-08 10:29:21 +08:00
|
|
|
private:
|
|
|
|
QSettings mSettings;
|
2021-04-13 11:23:37 +08:00
|
|
|
Dirs mDirs;
|
|
|
|
Editor mEditor;
|
2021-04-15 21:32:45 +08:00
|
|
|
CompilerSets mCompilerSets;
|
2021-04-08 10:29:21 +08:00
|
|
|
};
|
|
|
|
|
2021-04-13 11:23:37 +08:00
|
|
|
|
2021-04-08 10:29:21 +08:00
|
|
|
extern Settings* pSettings;
|
|
|
|
|
|
|
|
#endif // SETTINGS_H
|