don't cache settings... use the settings file directly
This commit is contained in:
parent
b3ea0d1a1b
commit
c40a9eaa45
@ -30,18 +30,21 @@ namespace guhserver {
|
|||||||
GuhConfiguration::GuhConfiguration(QObject *parent) :
|
GuhConfiguration::GuhConfiguration(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
// Load guhd settings
|
// Init server uuid if we don't have one.
|
||||||
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
QUuid id = serverUuid();
|
||||||
settings.beginGroup("guhd");
|
if (id.isNull()) {
|
||||||
m_serverName = settings.value("name", "guhIO").toString();
|
id = QUuid::createUuid();
|
||||||
m_timeZone = settings.value("timeZone", QTimeZone::systemTimeZoneId()).toByteArray();
|
setServerUuid(id);
|
||||||
m_locale = QLocale(settings.value("language", "en_US").toString());
|
|
||||||
m_serverUuid = settings.value("uuid", QUuid()).toUuid();
|
|
||||||
if (m_serverUuid.isNull()) {
|
|
||||||
m_serverUuid = QUuid::createUuid();
|
|
||||||
settings.setValue("uuid", m_serverUuid);
|
|
||||||
}
|
}
|
||||||
settings.endGroup();
|
|
||||||
|
// Make sure default values are in configuration file so that it's easier for users to modify
|
||||||
|
setServerName(serverName());
|
||||||
|
setTimeZone(timeZone());
|
||||||
|
setLocale(locale());
|
||||||
|
setBluetoothServerEnabled(bluetoothServerEnabled());
|
||||||
|
setSslCertificate(sslCertificate(), sslCertificateKey());
|
||||||
|
|
||||||
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
|
||||||
#ifndef TESTING_ENABLED
|
#ifndef TESTING_ENABLED
|
||||||
// TcpServer
|
// TcpServer
|
||||||
@ -168,26 +171,20 @@ GuhConfiguration::GuhConfiguration(QObject *parent) :
|
|||||||
wssConfig.authenticationEnabled = true;
|
wssConfig.authenticationEnabled = true;
|
||||||
m_webSocketServerConfigs[wssConfig.id] = wssConfig;
|
m_webSocketServerConfigs[wssConfig.id] = wssConfig;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Bluetooth server
|
|
||||||
settings.beginGroup("BluetoothServer");
|
|
||||||
setBluetoothServerEnabled(settings.value("enabled", false).toBool());
|
|
||||||
settings.endGroup();
|
|
||||||
|
|
||||||
// SSL configuration
|
|
||||||
settings.beginGroup("SSL");
|
|
||||||
setSslCertificate(settings.value("certificate", "/etc/ssl/certs/guhd-certificate.crt").toString(), settings.value("certificate-key", "/etc/ssl/certs/guhd-certificate.key").toString());
|
|
||||||
settings.endGroup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid GuhConfiguration::serverUuid() const
|
QUuid GuhConfiguration::serverUuid() const
|
||||||
{
|
{
|
||||||
return m_serverUuid;
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("guhd");
|
||||||
|
return settings.value("uuid", QUuid()).toUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GuhConfiguration::serverName() const
|
QString GuhConfiguration::serverName() const
|
||||||
{
|
{
|
||||||
return m_serverName;
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("guhd");
|
||||||
|
return settings.value("name", "guhIO").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuhConfiguration::setServerName(const QString &serverName)
|
void GuhConfiguration::setServerName(const QString &serverName)
|
||||||
@ -198,14 +195,14 @@ void GuhConfiguration::setServerName(const QString &serverName)
|
|||||||
settings.beginGroup("guhd");
|
settings.beginGroup("guhd");
|
||||||
settings.setValue("name", serverName);
|
settings.setValue("name", serverName);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
m_serverName = serverName;
|
|
||||||
emit serverNameChanged();
|
emit serverNameChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray GuhConfiguration::timeZone() const
|
QByteArray GuhConfiguration::timeZone() const
|
||||||
{
|
{
|
||||||
return m_timeZone;
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("guhd");
|
||||||
|
return settings.value("timeZone", QTimeZone::systemTimeZoneId()).toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuhConfiguration::setTimeZone(const QByteArray &timeZone)
|
void GuhConfiguration::setTimeZone(const QByteArray &timeZone)
|
||||||
@ -216,14 +213,14 @@ void GuhConfiguration::setTimeZone(const QByteArray &timeZone)
|
|||||||
settings.beginGroup("guhd");
|
settings.beginGroup("guhd");
|
||||||
settings.setValue("timeZone", timeZone);
|
settings.setValue("timeZone", timeZone);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
m_timeZone = timeZone;
|
|
||||||
emit timeZoneChanged();
|
emit timeZoneChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QLocale GuhConfiguration::locale() const
|
QLocale GuhConfiguration::locale() const
|
||||||
{
|
{
|
||||||
return m_locale;
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("guhd");
|
||||||
|
return settings.value("language", "en_US").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuhConfiguration::setLocale(const QLocale &locale)
|
void GuhConfiguration::setLocale(const QLocale &locale)
|
||||||
@ -234,8 +231,6 @@ void GuhConfiguration::setLocale(const QLocale &locale)
|
|||||||
settings.beginGroup("guhd");
|
settings.beginGroup("guhd");
|
||||||
settings.setValue("language", locale.name());
|
settings.setValue("language", locale.name());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
m_locale = locale;
|
|
||||||
emit localeChanged();
|
emit localeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +303,9 @@ void GuhConfiguration::removeWebSocketServerConfiguration(const QString &id)
|
|||||||
|
|
||||||
bool GuhConfiguration::bluetoothServerEnabled() const
|
bool GuhConfiguration::bluetoothServerEnabled() const
|
||||||
{
|
{
|
||||||
return m_bluetoothServerEnabled;
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("BluetoothServer");
|
||||||
|
return settings.value("enabled", false).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuhConfiguration::setBluetoothServerEnabled(const bool &enabled)
|
void GuhConfiguration::setBluetoothServerEnabled(const bool &enabled)
|
||||||
@ -319,19 +316,21 @@ void GuhConfiguration::setBluetoothServerEnabled(const bool &enabled)
|
|||||||
settings.beginGroup("BluetoothServer");
|
settings.beginGroup("BluetoothServer");
|
||||||
settings.setValue("enabled", enabled);
|
settings.setValue("enabled", enabled);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
m_bluetoothServerEnabled = enabled;
|
|
||||||
emit bluetoothServerEnabled();
|
emit bluetoothServerEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GuhConfiguration::sslCertificate() const
|
QString GuhConfiguration::sslCertificate() const
|
||||||
{
|
{
|
||||||
return m_sslCertificate;
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("SSL");
|
||||||
|
return settings.value("certificate", "/etc/ssl/certs/guhd-certificate.crt").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GuhConfiguration::sslCertificateKey() const
|
QString GuhConfiguration::sslCertificateKey() const
|
||||||
{
|
{
|
||||||
return m_sslCertificateKey;
|
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||||
|
settings.beginGroup("SSL");
|
||||||
|
return settings.value("certificate-key", "/etc/ssl/certs/guhd-certificate.key").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuhConfiguration::setSslCertificate(const QString &sslCertificate, const QString &sslCertificateKey)
|
void GuhConfiguration::setSslCertificate(const QString &sslCertificate, const QString &sslCertificateKey)
|
||||||
@ -343,10 +342,6 @@ void GuhConfiguration::setSslCertificate(const QString &sslCertificate, const QS
|
|||||||
settings.setValue("certificate", sslCertificate);
|
settings.setValue("certificate", sslCertificate);
|
||||||
settings.setValue("certificate-key", sslCertificateKey);
|
settings.setValue("certificate-key", sslCertificateKey);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
m_sslCertificate = sslCertificate;
|
|
||||||
m_sslCertificateKey = sslCertificateKey;
|
|
||||||
|
|
||||||
emit sslCertificateChanged();
|
emit sslCertificateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,8 +353,6 @@ void GuhConfiguration::setServerUuid(const QUuid &uuid)
|
|||||||
settings.beginGroup("guhd");
|
settings.beginGroup("guhd");
|
||||||
settings.setValue("uuid", uuid);
|
settings.setValue("uuid", uuid);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
m_serverUuid = uuid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuhConfiguration::storeServerConfig(const QString &group, const ServerConfiguration &config)
|
void GuhConfiguration::storeServerConfig(const QString &group, const ServerConfiguration &config)
|
||||||
|
|||||||
@ -106,20 +106,10 @@ public:
|
|||||||
void setSslCertificate(const QString &sslCertificate, const QString &sslCertificateKey);
|
void setSslCertificate(const QString &sslCertificate, const QString &sslCertificateKey);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_serverUuid;
|
|
||||||
QString m_serverName;
|
|
||||||
QByteArray m_timeZone;
|
|
||||||
QLocale m_locale;
|
|
||||||
|
|
||||||
QHash<QString, ServerConfiguration> m_tcpServerConfigs;
|
QHash<QString, ServerConfiguration> m_tcpServerConfigs;
|
||||||
QHash<QString, WebServerConfiguration> m_webServerConfigs;
|
QHash<QString, WebServerConfiguration> m_webServerConfigs;
|
||||||
QHash<QString, ServerConfiguration> m_webSocketServerConfigs;
|
QHash<QString, ServerConfiguration> m_webSocketServerConfigs;
|
||||||
|
|
||||||
bool m_bluetoothServerEnabled;
|
|
||||||
|
|
||||||
QString m_sslCertificate;
|
|
||||||
QString m_sslCertificateKey;
|
|
||||||
|
|
||||||
void setServerUuid(const QUuid &uuid);
|
void setServerUuid(const QUuid &uuid);
|
||||||
void setWebServerPublicFolder(const QString & path);
|
void setWebServerPublicFolder(const QString & path);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user