harbour-aira 0.1.0: client Sailfish per pompa di calore Aira (bridge HTTP + stato e comandi ACS)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#include "settings.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
|
||||
QString Settings::configPath()
|
||||
{
|
||||
// Path canonico per la sandbox SailJail: con org/app impostati in main.cpp
|
||||
// (harbour/aira) AppConfigLocation = ~/.config/harbour/aira, l'unica zona
|
||||
// config persistente tra gli avvii.
|
||||
const QString dir = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
||||
QDir().mkpath(dir);
|
||||
return dir + QStringLiteral("/aira.conf");
|
||||
}
|
||||
|
||||
Settings::Settings(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_settings(configPath(), QSettings::IniFormat)
|
||||
{
|
||||
// Diagnostica: senza questa riga un problema di persistenza resta invisibile.
|
||||
qDebug() << "Settings file:" << m_settings.fileName();
|
||||
if (m_settings.status() != QSettings::NoError)
|
||||
qDebug() << "Settings WARNING: file di configurazione non accessibile";
|
||||
qDebug() << "Settings read: baseUrl=[" << baseUrl() << "] token impostato:" << !token().isEmpty();
|
||||
}
|
||||
|
||||
QString Settings::baseUrl() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral("baseUrl"), QString()).toString();
|
||||
}
|
||||
|
||||
void Settings::setBaseUrl(const QString &value)
|
||||
{
|
||||
if (value == baseUrl())
|
||||
return;
|
||||
m_settings.setValue(QStringLiteral("baseUrl"), value);
|
||||
m_settings.sync(); // le chiusure brusche perdono il flush del distruttore
|
||||
emit baseUrlChanged();
|
||||
}
|
||||
|
||||
QString Settings::token() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral("token"), QString()).toString();
|
||||
}
|
||||
|
||||
void Settings::setToken(const QString &value)
|
||||
{
|
||||
if (value == token())
|
||||
return;
|
||||
m_settings.setValue(QStringLiteral("token"), value);
|
||||
m_settings.sync();
|
||||
emit tokenChanged();
|
||||
}
|
||||
Reference in New Issue
Block a user