64 lines
1.9 KiB
C++
64 lines
1.9 KiB
C++
|
/*
|
||
|
Speed Climbing Stopwatch - Simple Stopwatch for Climbers
|
||
|
Copyright (C) 2018 Itsblue Development - Dorian Zeder
|
||
|
|
||
|
This program is free software: you can redistribute it and/or modify
|
||
|
it under the terms of the GNU Affero General Public License as published
|
||
|
by the Free Software Foundation, version 3 of the License.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU Affero General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Affero General Public License
|
||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include "headers/appsettings.h"
|
||
|
|
||
|
AppSettings * pGlobalAppSettings = nullptr;
|
||
|
|
||
|
AppSettings::AppSettings(QObject* parent)
|
||
|
:QObject(parent)
|
||
|
{
|
||
|
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||
|
|
||
|
this->settingsManager = new QSettings(path+"/settings.ini", QSettings::IniFormat);
|
||
|
|
||
|
this->setDefaultSetting("highscore", "-1");
|
||
|
this->setDefaultSetting("theme", "0");
|
||
|
|
||
|
pGlobalAppSettings = this;
|
||
|
}
|
||
|
|
||
|
QString AppSettings::read(const QString &key)
|
||
|
{
|
||
|
this->settingsManager->beginGroup("AppSettings");
|
||
|
QString value = this->settingsManager->value(key , false).toString();
|
||
|
this->settingsManager->endGroup();
|
||
|
return(value);
|
||
|
}
|
||
|
|
||
|
void AppSettings::write(const QString &key, const QVariant &variant)
|
||
|
{
|
||
|
this->settingsManager->beginGroup("AppSettings");
|
||
|
this->settingsManager->setValue(key , variant);
|
||
|
this->settingsManager->endGroup();
|
||
|
}
|
||
|
|
||
|
void AppSettings::setDefaultSetting(const QString &key, const QVariant &defaultVariant)
|
||
|
{
|
||
|
QString value = this->read(key);
|
||
|
if(value == "false"){
|
||
|
this->write(key, defaultVariant);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
AppSettings::~AppSettings()
|
||
|
{
|
||
|
delete settingsManager;
|
||
|
}
|
||
|
|