2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
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.
17 #include <QGuiApplication>
18 #include <QCommandLineParser>
19 #include <QtGui/QGuiApplication>
20 #include <QtQml/QQmlApplicationEngine>
21 #include <QtQml/QQmlContext>
22 #include <QQuickWindow>
23 #include <QtQuickControls2/QQuickStyle>
25 #include "eventhandler.h"
28 int main(int argc, char *argv[])
30 QGuiApplication app(argc, argv);
32 QCoreApplication::setOrganizationDomain("LinuxFoundation");
33 QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
34 QCoreApplication::setApplicationName("Onscreenapp");
35 QCoreApplication::setApplicationVersion("0.1.0");
37 QQuickStyle::setStyle("AGL");
39 QCommandLineParser parser;
40 parser.addPositionalArgument("port", app.translate("main", "port for binding"));
41 parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
42 parser.addHelpOption();
43 parser.addVersionOption();
45 QStringList positionalArguments = parser.positionalArguments();
50 if (positionalArguments.length() == 2) {
51 port = positionalArguments.takeFirst().toInt();
52 token = positionalArguments.takeFirst();
55 HMI_DEBUG(APP_ID, "port = %d, token = %s", port, token.toStdString().c_str());
57 QQmlApplicationEngine engine;
58 EventHandler *eventHandler = new EventHandler();
59 eventHandler->init(port, token.toStdString().c_str());
60 engine.rootContext()->setContextProperty("eventHandler", eventHandler);
61 engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
62 if (engine.rootObjects().isEmpty()) {
63 HMI_DEBUG(APP_ID, "Fatal Error, rootObject is empty!");
67 QObject *root = engine.rootObjects().first();
68 QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
69 QObject::connect(eventHandler, SIGNAL(signalLoader(QVariant)), window, SLOT(qmlLoader(QVariant)));
70 QObject::connect(eventHandler, SIGNAL(signalOnScreenParameter(QVariant)), window, SLOT(qmlOnScreenParameter(QVariant)));
72 HMI_DEBUG(APP_ID, "Launched!");