"test/git@www.opencode.net:taylor-jaydee/geocoder.git" did not exist on "3b17a86906a939a97b924a91ca51f056e3dd1cb4"
Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "../utility/file.h"
#include "../utility/json.h"
#include "config.h"
namespace Core {
Config::Config(const QString &configsDir, QObject *parent) :
QObject(parent), _configsDir(configsDir)
{}
QJsonObject Config::get(const QString &name)
{
QString configFile = _configsDir + "/" + name + ".json";
if (!_cacheData.contains(name)) {
QString json = Utility::File::readText(configFile);
if (json.isEmpty()) {
json = "{}"; // Blank JSON data as default
}
_cacheData[name] = Utility::Json::convertStrToObj(json);
}
return _cacheData[name].toObject();
}
bool Config::set(const QString &name, const QJsonObject &jsonObj)
{
QString configFile = _configsDir + "/" + name + ".json";
QString json = Utility::Json::convertObjToStr(jsonObj);
Utility::File::makeDir(_configsDir);
if (Utility::File::writeText(configFile, json)) {
_cacheData[name] = jsonObj;
return true;
}
return false;
}
} // namespace Core