1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 03:22:33 +01:00

Add auto creation of settings file if its not existent

This commit is contained in:
kelteseth 2017-05-21 18:14:02 +02:00
parent 63b269dfed
commit 391f58f822

View File

@ -12,11 +12,8 @@ Settings::Settings(QObject* parent)
if (!configTmp.exists()) { if (!configTmp.exists()) {
//If we cannot find the settings json file we will create one //If we cannot find the settings json file we will create one
//createDefaultConfig(); createDefaultConfig();
} }
configTmp.open(QIODevice::ReadOnly | QIODevice::Text); configTmp.open(QIODevice::ReadOnly | QIODevice::Text);
QString config = configTmp.readAll(); QString config = configTmp.readAll();
configJsonDocument = QJsonDocument::fromJson(config.toUtf8(), &parseError); configJsonDocument = QJsonDocument::fromJson(config.toUtf8(), &parseError);
@ -35,9 +32,18 @@ Settings::Settings(QObject* parent)
void Settings::createDefaultConfig() void Settings::createDefaultConfig()
{ {
Q_INIT_RESOURCE(qml);
QFile file(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/settings.json"); QFile file(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/settings.json");
QFile defaultSettings(":/settings.json");
file.open(QIODevice::WriteOnly | QIODevice::Text); file.open(QIODevice::WriteOnly | QIODevice::Text);
QJsonObject tmpObj; defaultSettings.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream out(&file);
QTextStream defaultOut(&defaultSettings);
out << defaultOut.readAll();
file.close();
} }