add visa, start websocket implementation
[staging/HomeScreen.git] / HomeScreen / src2 / usermanagement.cpp
1 #include "usermanagement.h"
2 #include <QApplication>
3 #include <QDebug>
4 UserManagement::UserManagement(QObject *home, QObject *shortcutArea, QObject *statusArea) : QObject()
5 {
6     this->home = home;
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"));
15 }
16 void UserManagement::slot_timerTest()
17 {
18     if(currentLanguage == "fr")
19         currentLanguage = "en";
20     else
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é!"));
31     } else {
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é!"));
36     }
37 }
38 void UserManagement::connectWebsockets(const QUrl &url)
39 {
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));
46 }
47 void UserManagement::onConnected()
48 {
49     connect(&webSocket, &QWebSocket::textMessageReceived,
50             this, &UserManagement::onTextMessageReceived);
51     webSocket.sendTextMessage(QStringLiteral("Hello, world!"));
52
53 }
54 void UserManagement::onTextMessageReceived(QString message)
55 {
56     qWarning()<<"message received:"<<message;
57 }
58
59 void UserManagement::onClosed()
60 {
61     qWarning()<<"webSocket closed";
62 }