|
@ -7,42 +7,42 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#include <QTranslator>
|
|
|
#include <QTranslator>
|
|
|
|
|
|
#include <QSettings>
|
|
|
#include <QString>
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
|
#include "settings.h"
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
|
Settings *Settings::_singleton = NULL; |
|
|
Settings *Settings::_singleton = NULL; |
|
|
|
|
|
|
|
|
Settings::Settings(void) |
|
|
|
|
|
|
|
|
Settings::Settings(QObject *parent) : QSettings(parent) |
|
|
{ |
|
|
{ |
|
|
QSettings s; |
|
|
|
|
|
struct Room room; |
|
|
struct Room room; |
|
|
struct Heater heater; |
|
|
struct Heater heater; |
|
|
int nb_rooms; |
|
|
int nb_rooms; |
|
|
|
|
|
|
|
|
nb_rooms = s.beginReadArray("rooms"); |
|
|
|
|
|
|
|
|
nb_rooms = this->beginReadArray("rooms"); |
|
|
if (nb_rooms > MAX_NB_ZONES) { |
|
|
if (nb_rooms > MAX_NB_ZONES) { |
|
|
// TODO;
|
|
|
// TODO;
|
|
|
nb_rooms = MAX_NB_ZONES; |
|
|
nb_rooms = MAX_NB_ZONES; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for (int i = 0; i < nb_rooms; ++i) { |
|
|
for (int i = 0; i < nb_rooms; ++i) { |
|
|
s.setArrayIndex(i); |
|
|
|
|
|
room.name = s.value("name", "").toString(); |
|
|
|
|
|
room.sensor_topic = s.value("sensor_topic", "").toString(); |
|
|
|
|
|
room.availability_topic = s.value("availability_topic", "").toString(); |
|
|
|
|
|
int size = s.beginReadArray("heaters"); |
|
|
|
|
|
|
|
|
this->setArrayIndex(i); |
|
|
|
|
|
room.name = this->value("name", "").toString(); |
|
|
|
|
|
room.sensor_topic = this->value("sensor_topic", "").toString(); |
|
|
|
|
|
room.availability_topic = this->value("availability_topic", "").toString(); |
|
|
|
|
|
int size = this->beginReadArray("heaters"); |
|
|
for (int j = 0; j < size; ++j) { |
|
|
for (int j = 0; j < size; ++j) { |
|
|
s.setArrayIndex(j); |
|
|
|
|
|
heater.ctrl_topic = s.value("control_topic", "").toString(); |
|
|
|
|
|
|
|
|
this->setArrayIndex(j); |
|
|
|
|
|
heater.ctrl_topic = this->value("control_topic", "").toString(); |
|
|
room.heaters << heater; |
|
|
room.heaters << heater; |
|
|
} |
|
|
} |
|
|
s.endArray(); |
|
|
|
|
|
|
|
|
this->endArray(); |
|
|
m_rooms << room; |
|
|
m_rooms << room; |
|
|
} |
|
|
} |
|
|
s.endArray(); |
|
|
|
|
|
m_broker.address = s.value("broker/address", "localhost").toString(); |
|
|
|
|
|
m_broker.port = s.value("broker/port", 1883).toInt(); |
|
|
|
|
|
|
|
|
this->endArray(); |
|
|
|
|
|
m_broker.address = this->value("broker/address", "localhost").toString(); |
|
|
|
|
|
m_broker.port = this->value("broker/port", 1883).toInt(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int Settings::nbZones(void) |
|
|
int Settings::nbZones(void) |
|
@ -57,7 +57,7 @@ Settings::~Settings(void) |
|
|
Settings *Settings::getInstance(void) |
|
|
Settings *Settings::getInstance(void) |
|
|
{ |
|
|
{ |
|
|
if (!_singleton) { |
|
|
if (!_singleton) { |
|
|
_singleton = new Settings; |
|
|
|
|
|
|
|
|
_singleton = new Settings(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return _singleton; |
|
|
return _singleton; |
|
|