refactor persistent settings
This commit is contained in:
parent
e98b6f5734
commit
488328a05e
|
@ -1,7 +1,6 @@
|
|||
#include "sacnexplorer.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QSettings>
|
||||
|
||||
SacnExplorer::SacnExplorer(int argc, char *argv[])
|
||||
: QApplication(argc, argv)
|
||||
|
@ -10,15 +9,29 @@ SacnExplorer::SacnExplorer(int argc, char *argv[])
|
|||
setOrganizationDomain("company235.com");
|
||||
setApplicationName(tr("sACN Explorer"));
|
||||
|
||||
loadSettings();
|
||||
// Persistant configuration
|
||||
settings_ = new QSettings();
|
||||
qDebug() << "Loaded application settings from" << settings_->fileName();
|
||||
settings_->beginGroup("ACN");
|
||||
auto cid = settings_->value("CID", QUuid::createUuid().toString()).toUuid();
|
||||
auto uacn = settings_->value("UACN", applicationName()).toString();
|
||||
settings_->endGroup();
|
||||
settings_->beginGroup("sACN");
|
||||
settings_->beginGroup("receiver");
|
||||
auto discovery = settings_->value("discovery", true).toBool();
|
||||
settings_->endGroup();
|
||||
settings_->endGroup();
|
||||
|
||||
node_ = new QSacnNode(this, cid_);
|
||||
qDebug() << "sACN node started with CID" << node_->cid().string().c_str();
|
||||
node_->assignUserName(applicationName().toStdString());
|
||||
node_->discoveryStart();
|
||||
// sACN Node
|
||||
qDebug() << "sACN node" << uacn << "starting with CID" << cid.toString();
|
||||
node_ = new QSacnNode(this, cid, applicationName());
|
||||
node_->assignUserName(uacn.toStdString());
|
||||
if (discovery)
|
||||
node_->discoveryStart();
|
||||
|
||||
window = new MultiverseView(nullptr, node_);
|
||||
window->show();
|
||||
// Multiverse Explorer
|
||||
window_ = new MultiverseView(nullptr, node_);
|
||||
window_->show();
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,36 +39,26 @@ SacnExplorer::~SacnExplorer()
|
|||
{
|
||||
saveSettings();
|
||||
|
||||
delete window;
|
||||
delete settings_;
|
||||
delete window_;
|
||||
delete node_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MultiverseView::loadSettings
|
||||
*/
|
||||
void SacnExplorer::loadSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
qDebug() << "Loading application settings from" << settings.fileName();
|
||||
|
||||
settings.beginGroup("acn");
|
||||
cid_ = QUuid(settings.value("cid",
|
||||
QUuid::createUuid().toString()).toString());
|
||||
qDebug() << "Persistent CID is" << cid_.toString().toStdString().c_str();
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief MultiverseView::saveSettings
|
||||
*/
|
||||
void SacnExplorer::saveSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
qDebug() << "Saving application settings to" << settings.fileName();
|
||||
|
||||
settings.beginGroup("acn");
|
||||
settings.setValue("cid", cid_.toString());
|
||||
settings.endGroup();
|
||||
qDebug() << "Saving application settings to" << settings_->fileName();
|
||||
settings_->beginGroup("ACN");
|
||||
settings_->setValue("CID", node_->cid().string().c_str());
|
||||
settings_->setValue("UACN", node_->name().c_str());
|
||||
settings_->endGroup();
|
||||
settings_->beginGroup("sACN");
|
||||
settings_->beginGroup("receiver");
|
||||
settings_->setValue("discovery", node_->isDiscovering());
|
||||
settings_->endGroup();
|
||||
settings_->endGroup();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "qsacnnode.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QUuid>
|
||||
#include <QSettings>
|
||||
|
||||
class SacnExplorer
|
||||
: public QApplication
|
||||
|
@ -18,8 +18,8 @@ private:
|
|||
void loadSettings();
|
||||
void saveSettings();
|
||||
|
||||
MultiverseView* window;
|
||||
MultiverseView* window_;
|
||||
QSacnNode *node_;
|
||||
QUuid cid_;
|
||||
QSettings *settings_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue