mirror of https://github.com/nymea/nymea.git
store configured devices in config file
parent
efcecb0dd1
commit
f042911fd1
|
|
@ -1,5 +1,13 @@
|
|||
#include "device.h"
|
||||
|
||||
Device::Device(const QUuid &id, const QUuid &deviceClassId, QObject *parent):
|
||||
QObject(parent),
|
||||
m_id(id),
|
||||
m_deviceClassId(deviceClassId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Device::Device(const QUuid &deviceClassId, QObject *parent):
|
||||
QObject(parent),
|
||||
m_id(QUuid::createUuid()),
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ class Device: public QObject
|
|||
Q_PROPERTY(QUuid id READ id CONSTANT)
|
||||
|
||||
public:
|
||||
Device(const QUuid &id, const QUuid &deviceClassId, QObject *parent = 0);
|
||||
Device(const QUuid &deviceClassId, QObject *parent = 0);
|
||||
|
||||
QUuid id() const;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include <QPluginLoader>
|
||||
#include <QtPlugin>
|
||||
#include <QDebug>
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
|
||||
Q_IMPORT_PLUGIN(RfRemoteMumbi)
|
||||
|
||||
|
|
@ -18,6 +20,7 @@ DeviceManager::DeviceManager(QObject *parent) :
|
|||
m_radio433 = new Radio433(this);
|
||||
|
||||
QMetaObject::invokeMethod(this, "loadPlugins", Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(this, "loadConfiguredDevices", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
QList<DeviceClass> DeviceManager::supportedDevices()
|
||||
|
|
@ -45,6 +48,9 @@ DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const QUuid &devic
|
|||
device->setName(deviceClass.name());
|
||||
device->setParams(params);
|
||||
m_configuredDevices.append(device);
|
||||
|
||||
storeConfiguredDevices();
|
||||
|
||||
return DeviceErrorNoError;
|
||||
}
|
||||
|
||||
|
|
@ -94,3 +100,30 @@ void DeviceManager::loadPlugins()
|
|||
}
|
||||
}
|
||||
|
||||
void DeviceManager::loadConfiguredDevices()
|
||||
{
|
||||
QSettings settings;
|
||||
qDebug() << "loading devices";
|
||||
foreach (const QString &idString, settings.childGroups()) {
|
||||
qDebug() << "found stored device" << idString;
|
||||
settings.beginGroup(idString);
|
||||
Device *device = new Device(QUuid(idString), settings.value("deviceClassId").toUuid(), this);
|
||||
device->setName(settings.value("devicename").toString());
|
||||
device->setParams(device->params());
|
||||
settings.endGroup();
|
||||
m_configuredDevices.append(device);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManager::storeConfiguredDevices()
|
||||
{
|
||||
QSettings settings;
|
||||
foreach (Device *device, m_configuredDevices) {
|
||||
settings.beginGroup(device->id().toString());
|
||||
settings.setValue("devicename", device->name());
|
||||
settings.setValue("deviceClassId", device->deviceClassId().toString());
|
||||
settings.setValue("params", device->params());
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ signals:
|
|||
|
||||
private slots:
|
||||
void loadPlugins();
|
||||
void loadConfiguredDevices();
|
||||
void storeConfiguredDevices();
|
||||
|
||||
private:
|
||||
QList<DeviceClass> m_supportedDevices;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ HiveCore::HiveCore(QObject *parent) :
|
|||
QObject(parent)
|
||||
{
|
||||
|
||||
|
||||
qDebug() << "creating devmanager";
|
||||
m_deviceManager = new DeviceManager(this);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
a.setOrganizationName("hiveyourhome");
|
||||
|
||||
HiveCore::instance();
|
||||
|
||||
return a.exec();
|
||||
|
|
|
|||
Loading…
Reference in New Issue