mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
ebbb6b9440
* 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
66 lines
1.4 KiB
C++
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;
|
|
}
|
|
}
|
|
|
|
|