#include "headers/appsettings.h" AppSettings::AppSettings(QObject* parent) :QObject(parent) { // This is the Constructor of the AppSettings class // get writable path to store the settings.ini file QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); qDebug() << "app settings path: " << path; // create or open the settings.ini file this->settingsManager = new QSettings(path+"/settings.ini", QSettings::IniFormat); // set the values to their defaults if they haven't been created yet this->setDefault("score", "0"); // create or open the settings.ini file this->themeSettingsManager = new QSettings(":/themes/" + this->read("theme") + ".ini", QSettings::IniFormat); } QString AppSettings::read(QString key) { // function to read values from the settings file // open the value-group this->settingsManager->beginGroup("AppSettings"); // read the value QString value = this->settingsManager->value(key , false).toString(); // close the value-group this->settingsManager->endGroup(); // return the value return(value); } void AppSettings::write(QString key, QVariant value) { // function to write values to the settings file // open the value-group this->settingsManager->beginGroup("AppSettings"); // write the value this->settingsManager->setValue(key, value); // close the value-group this->settingsManager->endGroup(); } QString AppSettings::theme(QString key) { // function to get style settings from a theme file // open the value-group this->themeSettingsManager->beginGroup("ClickGameTheme"); // read the value QString value = this->themeSettingsManager->value(key , false).toString(); // close the value-group this->themeSettingsManager->endGroup(); // return the value return(value); } void AppSettings::setDefault(const QString &key, const QVariant &defaultValue) { // function to create a key (/ setting) with a default value if it hasnt been ceated yet // read the current value QString value = this->read(key); if(value == "false"){ // if it is nor defined yet, the read function will return "false" (as a string) // -> if that is the case -> create the key with the default value this->write(key, defaultValue); } } void AppSettings::reloadTheme() { delete this->themeSettingsManager; this->themeSettingsManager = new QSettings(":/themes/" + this->read("theme") + ".ini", QSettings::IniFormat); emit this->themeChanged(); } AppSettings::~AppSettings() { // This is the Destructor of the AppSettings class // delete the settings manager delete settingsManager; }