1 #include "usermanagement.h"
2 #include <QApplication>
4 UserManagement::UserManagement(QObject *home, QObject *shortcutArea, QObject *statusArea) : QObject()
7 this->appModel = home->findChild<ApplicationModel *>("ApplicationModel");
8 this->shortcutArea = shortcutArea;
9 this->statusArea = statusArea;
10 this->currentLanguage = "en";
11 connect(&timerTest, SIGNAL(timeout()), this, SLOT(slot_timerTest()));
12 timerTest.setSingleShot(false);
13 timerTest.start(5000);
14 connectWebsockets(QStringLiteral("wss://echo.websocket.org"));
16 void UserManagement::slot_timerTest()
18 if(currentLanguage == "fr")
19 currentLanguage = "en";
21 currentLanguage = "fr";
22 appModel->changeLanguage(currentLanguage);
23 QMetaObject::invokeMethod(home, "languageChanged");
24 QMetaObject::invokeMethod(shortcutArea, "languageChanged", Q_ARG(QVariant, currentLanguage));
25 QMetaObject::invokeMethod(statusArea, "languageChanged", Q_ARG(QVariant, currentLanguage));
26 if(currentLanguage == "fr") {
27 QLocale::setDefault(QLocale("fr_FR"));
28 QMetaObject::invokeMethod(home, "showSign90", Q_ARG(QVariant, true));
29 QMetaObject::invokeMethod(home, "showVisa", Q_ARG(QVariant, false));
30 QMetaObject::invokeMethod(home, "showHello", Q_ARG(QVariant, "Bonjour José!"));
32 QLocale::setDefault(QLocale("en_US"));
33 QMetaObject::invokeMethod(home, "showSign90", Q_ARG(QVariant, false));
34 QMetaObject::invokeMethod(home, "showVisa", Q_ARG(QVariant, true));
35 QMetaObject::invokeMethod(home, "showHello", Q_ARG(QVariant, "Hello José!"));
38 void UserManagement::connectWebsockets(const QUrl &url)
40 QSslConfiguration config = QSslConfiguration::defaultConfiguration();
41 config.setProtocol(QSsl::SecureProtocols);
42 webSocket.setSslConfiguration(config);
43 connect(&webSocket, &QWebSocket::connected, this, &UserManagement::onConnected);
44 connect(&webSocket, &QWebSocket::disconnected, this, &UserManagement::onClosed);
45 webSocket.open(QUrl(url));
47 void UserManagement::onConnected()
49 connect(&webSocket, &QWebSocket::textMessageReceived,
50 this, &UserManagement::onTextMessageReceived);
51 webSocket.sendTextMessage(QStringLiteral("Hello, world!"));
54 void UserManagement::onTextMessageReceived(QString message)
56 qWarning()<<"message received:"<<message;
59 void UserManagement::onClosed()
61 qWarning()<<"webSocket closed";