diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp index 2ed0dd3e..afa26997 100644 --- a/libguh/devicemanager.cpp +++ b/libguh/devicemanager.cpp @@ -316,6 +316,7 @@ void DeviceManager::setLocale(const QLocale &locale) } } + emit languageUpdated(); } /*! Returns all the \l{DevicePlugin}{DevicePlugins} loaded in the system. */ diff --git a/libguh/devicemanager.h b/libguh/devicemanager.h index 24737050..cb4682d3 100644 --- a/libguh/devicemanager.h +++ b/libguh/devicemanager.h @@ -145,6 +145,7 @@ public: signals: void loaded(); + void languageUpdated(); void eventTriggered(const Event &event); void deviceStateChanged(Device *device, const QUuid &stateTypeId, const QVariant &value); void deviceRemoved(const DeviceId &deviceId); diff --git a/server/jsonrpc/configurationhandler.cpp b/server/jsonrpc/configurationhandler.cpp index 4b203faf..595a7345 100644 --- a/server/jsonrpc/configurationhandler.cpp +++ b/server/jsonrpc/configurationhandler.cpp @@ -138,12 +138,18 @@ ConfigurationHandler::ConfigurationHandler(QObject *parent): params.insert("port", JsonTypes::basicTypeToString(JsonTypes::Uint)); setParams("WebSocketServerConfigurationChanged", params); + params.clear(); returns.clear(); + setDescription("LanguageChanged", "Emitted whenever the language of the server changed. The Plugins, Vendors and DeviceClasses have to be reloaded to get the translated data."); + params.insert("language", JsonTypes::basicTypeToString(JsonTypes::String)); + setParams("LanguageChanged", params); + connect(GuhCore::instance()->configuration(), &GuhConfiguration::serverNameChanged, this, &ConfigurationHandler::onBasicConfigurationChanged); connect(GuhCore::instance()->configuration(), &GuhConfiguration::timeZoneChanged, this, &ConfigurationHandler::onBasicConfigurationChanged); connect(GuhCore::instance()->configuration(), &GuhConfiguration::localeChanged, this, &ConfigurationHandler::onBasicConfigurationChanged); connect(GuhCore::instance()->configuration(), &GuhConfiguration::tcpServerConfigurationChanged, this, &ConfigurationHandler::onTcpServerConfigurationChanged); connect(GuhCore::instance()->configuration(), &GuhConfiguration::webServerConfigurationChanged, this, &ConfigurationHandler::onWebServerConfigurationChanged); connect(GuhCore::instance()->configuration(), &GuhConfiguration::webSocketServerConfigurationChanged, this, &ConfigurationHandler::onWebSocketServerConfigurationChanged); + connect(GuhCore::instance()->deviceManager(), &DeviceManager::languageUpdated, this, &ConfigurationHandler::onLanguageChanged); } QString ConfigurationHandler::name() const @@ -315,4 +321,12 @@ void ConfigurationHandler::onWebSocketServerConfigurationChanged() emit WebSocketServerConfigurationChanged(params); } +void ConfigurationHandler::onLanguageChanged() +{ + QVariantMap params; + qCDebug(dcJsonRpc()) << "Notification: language configuration changed"; + params.insert("language", GuhCore::instance()->configuration()->locale().name()); + emit LanguageChanged(params); +} + } diff --git a/server/jsonrpc/configurationhandler.h b/server/jsonrpc/configurationhandler.h index c324ae34..bf9768b7 100644 --- a/server/jsonrpc/configurationhandler.h +++ b/server/jsonrpc/configurationhandler.h @@ -50,12 +50,14 @@ signals: void TcpServerConfigurationChanged(const QVariantMap ¶ms); void WebServerConfigurationChanged(const QVariantMap ¶ms); void WebSocketServerConfigurationChanged(const QVariantMap ¶ms); + void LanguageChanged(const QVariantMap ¶ms); private slots: void onBasicConfigurationChanged(); void onTcpServerConfigurationChanged(); void onWebServerConfigurationChanged(); void onWebSocketServerConfigurationChanged(); + void onLanguageChanged(); }; diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 0cb8abe7..d3561bd1 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -18,5 +18,5 @@ SUBDIRS = versioning \ logging \ restlogging \ coap \ - #timemanager \ - + timemanager \ + configurations \ diff --git a/tests/auto/configurations/configurations.pro b/tests/auto/configurations/configurations.pro new file mode 100644 index 00000000..36a9da78 --- /dev/null +++ b/tests/auto/configurations/configurations.pro @@ -0,0 +1,7 @@ +TARGET = testconfigurations + +include(../../../guh.pri) +include(../autotests.pri) + +SOURCES += testconfigurations.cpp + diff --git a/tests/auto/configurations/testconfigurations.cpp b/tests/auto/configurations/testconfigurations.cpp new file mode 100644 index 00000000..b46087b3 --- /dev/null +++ b/tests/auto/configurations/testconfigurations.cpp @@ -0,0 +1,77 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2015 Simon Stürz * + * Copyright (C) 2014 Michael Zanetti * + * * + * This file is part of guh. * + * * + * Guh is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, version 2 of the License. * + * * + * Guh is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with guh. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "guhtestbase.h" +#include "guhcore.h" +#include "devicemanager.h" +#include "mocktcpserver.h" + +#include +#include +#include +#include +#include +#include +#include + +using namespace guhserver; + +class TestConfigurations: public GuhTestBase +{ + Q_OBJECT + +private slots: + void getConfigurations(); + + void testTimeZones(); + + +}; + +void TestConfigurations::getConfigurations() +{ + QVariant response = injectAndWait("Configuration.GetConfigurations"); + QVariantMap configurations = response.toMap().value("params").toMap(); + qDebug() << qUtf8Printable(QJsonDocument::fromVariant(configurations).toJson()); + + QVERIFY(configurations.contains("basicConfiguration")); + QVERIFY(!configurations.value("basicConfiguration").toMap().value("serverUuid").toUuid().isNull()); + + QVERIFY(configurations.contains("sslConfiguration")); + QVERIFY(configurations.contains("tcpServerConfiguration")); + QVERIFY(configurations.contains("webServerConfiguration")); + QVERIFY(configurations.contains("webSocketServerConfiguration")); +} + +void TestConfigurations::testTimeZones() +{ + QVariantMap configurations = injectAndWait("Configuration.GetConfigurations").toMap().value("params").toMap(); + QString currentTimeZone = configurations.value("basicConfiguration").toMap().value("timeZone").toString(); + QString currentTime = configurations.value("basicConfiguration").toMap().value("serverTime").toString(); + qDebug() << currentTimeZone << QDateTime::fromTime_t(currentTime.toInt()); + QVariantList timeZones = injectAndWait("Configuration.GetTimeZones").toMap().value("params").toMap().value("timeZones").toList(); + QVERIFY(timeZones.count() > 0); + QVERIFY(timeZones.contains("America/Toronto")); + +} + +#include "testconfigurations.moc" +QTEST_MAIN(TestConfigurations)