hyperion.ng/libsrc/webconfig/WebConfig.cpp
Paulchen Panther ebbb6b9440 JsonCpp to QTJson (Part 5) (#270)
* Update Hyperion.h

* Update ImageProcessorFactory.h

* Update ProtoConnection.h

* Update WebConfig.h

* Update CMakeLists.txt

* Update Hyperion.cpp

* Update CMakeLists.txt

* Update CMakeLists.txt

* Update CgiHandler.cpp

* Update CgiHandler.h

* Update WebConfig.cpp

* Update CMakeLists.txt

* Update hyperion-remote.cpp

* Update JsonConnection.cpp

* Update JsonConnection.h

* Update hyperiond.cpp

* Update hyperiond.h

* Delete JsonFactory.h

* Delete JsonSchemaChecker.h

* Delete JsonSchemaChecker.cpp

* Update WebConfig.cpp
2016-10-11 19:51:20 +02:00

66 lines
1.4 KiB
C++

#include "webconfig/WebConfig.h"
#include "StaticFileServing.h"
#include <QFileInfo>
WebConfig::WebConfig(QObject * parent)
: QObject(parent)
, _hyperion(Hyperion::getInstance())
, _server(nullptr)
{
Logger* log = Logger::getInstance("WEBSERVER");
_port = WEBCONFIG_DEFAULT_PORT;
_baseUrl = WEBCONFIG_DEFAULT_PATH;
const QJsonObject config = _hyperion->getQJsonConfig();
bool webconfigEnable = true;
if (config.contains("webConfig"))
{
const QJsonObject webconfigConfig = config["webConfig"].toObject();
webconfigEnable = webconfigConfig["enable"].toBool(true);
_port = webconfigConfig["port"].toInt(_port);
_baseUrl = webconfigConfig["document_root"].toString(_baseUrl);
}
if (_baseUrl != ":/webconfig")
{
QFileInfo info(_baseUrl);
if (!info.exists() || !info.isDir())
{
Error(log, "document_root '%s' is invalid, set to default '%s'", _baseUrl.toUtf8().constData(), WEBCONFIG_DEFAULT_PATH.toUtf8().constData());
_baseUrl = WEBCONFIG_DEFAULT_PATH;
}
}
Debug(log, "WebUI initialized, document root: %s", _baseUrl.toUtf8().constData());
if ( webconfigEnable )
{
start();
}
}
WebConfig::~WebConfig()
{
stop();
}
void WebConfig::start()
{
if ( _server == nullptr )
_server = new StaticFileServing (_hyperion, _baseUrl, _port, this);
}
void WebConfig::stop()
{
if ( _server != nullptr )
{
delete _server;
_server = nullptr;
}
}