2016-12-27 21:25:07 +01:00
|
|
|
#include "settings.h"
|
2017-01-05 23:54:13 +01:00
|
|
|
#include "models/setting.h"
|
2016-12-27 21:25:07 +01:00
|
|
|
|
|
|
|
using namespace jop;
|
2017-01-05 23:54:13 +01:00
|
|
|
|
2017-01-06 23:09:10 +01:00
|
|
|
Settings::Settings() : QSettings() {}
|
2017-01-05 23:54:13 +01:00
|
|
|
|
|
|
|
bool readSqlite(QIODevice &device, QSettings::SettingsMap &map) {
|
2017-01-10 18:05:58 +01:00
|
|
|
Q_UNUSED(device);
|
2017-01-06 23:09:10 +01:00
|
|
|
map = Setting::settings();
|
2017-01-05 23:54:13 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool writeSqlite(QIODevice &device, const QSettings::SettingsMap &map) {
|
2017-01-06 23:09:10 +01:00
|
|
|
// HACK: QSettings requires a readable/writable file to be present
|
|
|
|
// for the custom handler to work. However, we don't need such a
|
|
|
|
// file since we write to the db. So to simulate it, we write once
|
|
|
|
// to that file. Without this, readSqlite in particular will never
|
|
|
|
// get called.
|
|
|
|
device.write("X", 1);
|
|
|
|
Setting::setSettings(map);
|
2017-01-05 23:54:13 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::initialize() {
|
2017-01-06 23:09:10 +01:00
|
|
|
const QSettings::Format SqliteFormat = QSettings::registerFormat("sqlite", &readSqlite, &writeSqlite);
|
|
|
|
QSettings::setDefaultFormat(SqliteFormat);
|
2017-01-05 23:54:13 +01:00
|
|
|
}
|