2 * Copyright (C) 2016 The Qt Company Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <QQmlContext>
19 #include <QtCore/QDebug>
20 #include <QtCore/QCommandLineParser>
21 #include <QtCore/QUrlQuery>
22 #include <QtGui/QGuiApplication>
23 #include <QtQml/QQmlContext>
24 #include <QtQml/QQmlApplicationEngine>
25 #include <QtQuickControls2/QQuickStyle>
26 #include <QtQuick/QQuickWindow>
28 #include "eventhandler.h"
30 static EventHandler* eventHandler;
32 int main(int argc, char *argv[])
34 qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
35 qputenv("QT_LOGGING_RULES", QByteArray("qt.virtualkeyboard=true"));
36 QGuiApplication app(argc, argv);
37 app.setApplicationName("onstestapp");
38 app.setApplicationVersion(QStringLiteral("3.99.3"));
39 app.setOrganizationDomain(QStringLiteral("automotivelinux.org"));
40 app.setOrganizationName(QStringLiteral("AutomotiveGradeLinux"));
42 //QQuickStyle::setStyle("AGL");
44 QCommandLineParser parser;
45 parser.addPositionalArgument("port", app.translate("main", "port for binding"));
46 parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
47 parser.addHelpOption();
48 parser.addVersionOption();
50 QStringList positionalArguments = parser.positionalArguments();
52 QQmlApplicationEngine engine;
53 QQmlContext *context = engine.rootContext();
57 if (positionalArguments.length() == 2) {
58 port = positionalArguments.takeFirst().toInt();
59 secret = positionalArguments.takeFirst();
60 bindingAddress.setScheme(QStringLiteral("ws"));
61 bindingAddress.setHost(QStringLiteral("localhost"));
62 bindingAddress.setPort(port);
63 bindingAddress.setPath(QStringLiteral("/api"));
65 query.addQueryItem(QStringLiteral("token"), secret);
66 bindingAddress.setQuery(query);
67 context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
69 context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
72 eventHandler = new EventHandler();
73 eventHandler->init(port, secret.toStdString().c_str());
74 engine.rootContext()->setContextProperty("eventHandler", eventHandler);
76 engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
77 QObject *root = engine.rootObjects().first();
78 QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
80 QObject::connect(eventHandler, SIGNAL(signalOnReplyShowWindow(QVariant)), window, SLOT(qmlOnReplyShowWindow(QVariant)));
81 eventHandler->setQuickWindow(window);