KShare/settings.cpp

27 lines
706 B
C++
Raw Normal View History

2017-04-23 15:05:48 +02:00
#include "settings.hpp"
2017-07-11 16:24:36 +02:00
#include <QDebug>
#include <QMutex>
2017-04-23 15:05:48 +02:00
#include <QStandardPaths>
QMutex *lock = new QMutex;
2017-05-06 13:21:12 +02:00
QSettings &settings::settings() {
QMutexLocker l(lock);
2017-07-11 16:24:36 +02:00
static QSettings settings(dir().absoluteFilePath("settings.ini"), QSettings::IniFormat);
return settings;
}
QDir settings::dir() {
static QDir configDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation));
if (configDir.dirName() != "KShare") {
2017-07-11 16:24:36 +02:00
if (!configDir.cd("KShare"))
if (!configDir.mkdir("KShare")) {
qFatal("Could not make config directory");
} else {
configDir.cd("KShare");
}
}
2017-07-11 16:24:36 +02:00
return configDir;
2017-04-23 15:05:48 +02:00
}