v0.0.7
This commit is contained in:
parent
26d3fce10a
commit
984c5acacc
1 changed files with 376 additions and 37 deletions
|
|
@ -21,16 +21,20 @@ ConfigInterface::ConfigInterface(QObject *parent)
|
|||
auto data = config.readAll();
|
||||
config.close();
|
||||
QJsonObject top = QJsonDocument::fromJson(data).object();
|
||||
QString max, min, alert;
|
||||
QString max, min, alert, mode, url;
|
||||
bool flipbits;
|
||||
max = top["max_threshold"].toString();
|
||||
min = top["min_threshold"].toString();
|
||||
alert = top["alert_threshold"].toString();
|
||||
flipbits = top["flip_bits"].toBool();
|
||||
mode = top["mode"].toString();
|
||||
url = top["url"].toString();
|
||||
setMax(max);
|
||||
setMin(min);
|
||||
setAlert(alert);
|
||||
setFlipBits(flipbits);
|
||||
setMode(mode);
|
||||
setUrl(url);
|
||||
}
|
||||
else {
|
||||
qDebug() << "File does not exist creating one...";
|
||||
|
|
@ -38,6 +42,9 @@ ConfigInterface::ConfigInterface(QObject *parent)
|
|||
top["max_threshold"] = "125";
|
||||
top["min_threshold"] = "25";
|
||||
top["alert_threshold"] = "100";
|
||||
top["flip_bits"] = true;
|
||||
top["mode"] = "http";
|
||||
top["url"] = "https://unrealdragon.in/server/waterlevel";
|
||||
QByteArray data = QJsonDocument(top).toJson();
|
||||
bool ok = config.open(QFile::WriteOnly);
|
||||
if(!ok) {
|
||||
|
|
@ -47,10 +54,17 @@ ConfigInterface::ConfigInterface(QObject *parent)
|
|||
config.write(data);
|
||||
config.flush();
|
||||
config.close();
|
||||
setMax("125");
|
||||
setMin("25");
|
||||
setAlert("100");
|
||||
setFlipBits(true);
|
||||
setMode("http");
|
||||
setUrl("https://unrealdragon.in/server/waterlevel");
|
||||
qDebug() << "Config set initial values completed";
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigInterface::saveConfig(QString max, QString min, QString alert, bool flipbits)
|
||||
void ConfigInterface::saveConfig(QString max, QString min, QString alert, bool flipbits, QString mode, QString url)
|
||||
{
|
||||
auto paths = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||
qDebug() << "Got writable path as: " << paths;
|
||||
|
|
@ -62,9 +76,12 @@ void ConfigInterface::saveConfig(QString max, QString min, QString alert, bool f
|
|||
top["min_threshold"] = min;
|
||||
top["alert_threshold"] = alert;
|
||||
top["flip_bits"] = flipbits;
|
||||
top["mode"] = mode;
|
||||
top["url"] = url;
|
||||
setMax(max);
|
||||
setMin(min);
|
||||
setAlert(alert);
|
||||
setMode(mode);
|
||||
QByteArray data = QJsonDocument(top).toJson();
|
||||
config.open(QIODevice::WriteOnly);
|
||||
config.write(data);
|
||||
|
|
@ -123,3 +140,29 @@ void ConfigInterface::setFlipBits(bool newFlipBits)
|
|||
m_flipBits = newFlipBits;
|
||||
emit flipBitsChanged();
|
||||
}
|
||||
|
||||
QString ConfigInterface::mode() const
|
||||
{
|
||||
return m_mode;
|
||||
}
|
||||
|
||||
void ConfigInterface::setMode(const QString &newMode)
|
||||
{
|
||||
if (m_mode == newMode)
|
||||
return;
|
||||
m_mode = newMode;
|
||||
emit modeChanged();
|
||||
}
|
||||
|
||||
QString ConfigInterface::url() const
|
||||
{
|
||||
return m_url;
|
||||
}
|
||||
|
||||
void ConfigInterface::setUrl(const QString &newUrl)
|
||||
{
|
||||
if (m_url == newUrl)
|
||||
return;
|
||||
m_url = newUrl;
|
||||
emit urlChanged();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue