mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
Some checks failed
CMake / build (build/xca-*-Linux.tar.gz, Unix Makefiles, linux, /usr, ubuntu, 5.15.2, ubuntu-latest) (push) Has been cancelled
CMake / build (build/xca-*-Linux.tar.gz, Unix Makefiles, linux, /usr, ubuntu, 6.6.2, ubuntu-latest) (push) Has been cancelled
CMake / build (build/xca-*.dmg, Unix Makefiles, mac, /opt/homebrew/opt/openssl, macos, 6.6.2, macos-latest) (push) Has been cancelled
CMake / build (build/xca-*.msi
build/xca-portable-*.zip
, MinGW Makefiles, windows, D:\msys2\msys64\mingw64, windows, 5.15.2, windows-2019, win64_mingw81) (push) Has been cancelled
Don't call getHomeDir() in global constructor before main()
117 lines
1.9 KiB
C++
117 lines
1.9 KiB
C++
/* vi: set sw=4 ts=4:
|
|
*
|
|
* Copyright (C) 2018 Christian Hohnstaedt.
|
|
*
|
|
* All rights reserved.
|
|
*/
|
|
|
|
#ifndef __SETTINGS_H
|
|
#define __SETTINGS_H
|
|
|
|
#include <QString>
|
|
#include <QStringList>
|
|
#include <QMap>
|
|
#include <Qt>
|
|
|
|
class settings;
|
|
class svalue
|
|
{
|
|
private:
|
|
settings *setting{};
|
|
QString key{};
|
|
QString get() const;
|
|
void set(const QString &val);
|
|
|
|
public:
|
|
svalue(settings *s, const QString &k);
|
|
QStringList split(QString sep)
|
|
{
|
|
return get().split(sep);
|
|
}
|
|
bool empty()
|
|
{
|
|
return get().isEmpty();
|
|
}
|
|
const QString &operator = (const QString &val)
|
|
{
|
|
set(val);
|
|
return val;
|
|
}
|
|
int operator = (int val)
|
|
{
|
|
set(QString("%1").arg(val));
|
|
return val;
|
|
}
|
|
unsigned operator = (unsigned val)
|
|
{
|
|
set(QString("%1").arg(val));
|
|
return val;
|
|
}
|
|
bool operator = (bool val)
|
|
{
|
|
set(QString(val ? "yes" : "no"));
|
|
return val;
|
|
}
|
|
enum Qt::CheckState operator = (enum Qt::CheckState val)
|
|
{
|
|
set(QString(val == Qt::Checked ? "yes" : "no"));
|
|
return val;
|
|
}
|
|
operator QString()
|
|
{
|
|
return get();
|
|
}
|
|
operator int()
|
|
{
|
|
return get().toInt();
|
|
}
|
|
operator unsigned()
|
|
{
|
|
return get().toUInt();
|
|
}
|
|
operator bool()
|
|
{
|
|
return get() == "yes";
|
|
}
|
|
operator enum Qt::CheckState()
|
|
{
|
|
return get() == "yes" ? Qt::Checked : Qt::Unchecked;
|
|
}
|
|
QString operator +(const QString &other)
|
|
{
|
|
return get() + other;
|
|
}
|
|
QString operator +(const char *other)
|
|
{
|
|
return get() + other;
|
|
}
|
|
};
|
|
|
|
class settings
|
|
{
|
|
friend class svalue;
|
|
|
|
private:
|
|
bool loaded{};
|
|
QStringList db_keys{}, hostspecific{};
|
|
QMap<QString, QString> values{};
|
|
void load_settings();
|
|
QString get(QString key);
|
|
void set(QString key, QString value);
|
|
void setAction(const QString &key, const QString &value);
|
|
const QMap<QString, QString> defaults() const;
|
|
|
|
public:
|
|
settings();
|
|
void clear();
|
|
QString defaults(const QString &key);
|
|
|
|
svalue operator[] (QString x)
|
|
{
|
|
return svalue(this, x);
|
|
}
|
|
};
|
|
|
|
extern settings Settings;
|
|
#endif
|