mirror of
https://github.com/tnodir/fort
synced 2024-11-16 09:26:29 +00:00
45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
#include "inioptions.h"
|
|
|
|
#include "../fortsettings.h"
|
|
|
|
IniOptions::IniOptions(const IniOptions &o) : MapWrapper(o.map()) { }
|
|
|
|
QString IniOptions::defaultLanguage() const
|
|
{
|
|
return settings() ? settings()->defaultLanguage() : "en";
|
|
}
|
|
|
|
QVariant IniOptions::value(const QString &key, const QVariant &defaultValue) const
|
|
{
|
|
const QVariant v = MapWrapper::value(key);
|
|
if (!v.isNull())
|
|
return v;
|
|
|
|
return settings() ? settings()->iniValue(key, defaultValue) : defaultValue;
|
|
}
|
|
|
|
bool IniOptions::isTransientKey(const QString &key)
|
|
{
|
|
return key.endsWith('_');
|
|
}
|
|
|
|
void IniOptions::save(FortSettings *settings) const
|
|
{
|
|
auto it = map().constBegin();
|
|
const auto end = map().constEnd();
|
|
|
|
for (; it != end; ++it) {
|
|
const QString &key = it.key();
|
|
if (!isTransientKey(key)) {
|
|
settings->setIniValue(key, it.value());
|
|
}
|
|
}
|
|
|
|
if (hasPassword() != settings->hasPassword() || !password().isEmpty()) {
|
|
settings->setPassword(password());
|
|
if (!hasPassword()) {
|
|
settings->resetCheckedPassword();
|
|
}
|
|
}
|
|
}
|