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 <QCommandLineParser>
21 #include <QtGui/QGuiApplication>
22 #include <QtQml/QQmlApplicationEngine>
23 #include <QtQuickControls2/QQuickStyle>
24 #include <QQuickWindow>
25 #include <qlibhomescreen.h>
26 #include <qlibwindowmanager.h>
27 #include "hmi-debug.h"
29 int main(int argc, char *argv[])
31 QGuiApplication app(argc, argv);
32 app.setApplicationVersion(QStringLiteral("3.99.3"));
33 app.setOrganizationDomain(QStringLiteral("automotivelinux.org"));
34 app.setOrganizationName(QStringLiteral("AutomotiveGradeLinux"));
36 QQuickStyle::setStyle("AGL");
38 QCommandLineParser parser;
39 parser.addPositionalArgument("port", app.translate("main", "port for binding"));
40 parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
41 parser.addHelpOption();
42 parser.addVersionOption();
44 QStringList positionalArguments = parser.positionalArguments();
46 QQmlApplicationEngine engine;
47 if (positionalArguments.length() == 2) {
48 int port = positionalArguments.takeFirst().toInt();
49 QString secret = positionalArguments.takeFirst();
51 bindingAddress.setScheme(QStringLiteral("ws"));
52 bindingAddress.setHost(QStringLiteral("localhost"));
53 bindingAddress.setPort(port);
54 bindingAddress.setPath(QStringLiteral("/api"));
56 query.addQueryItem(QStringLiteral("token"), secret);
57 bindingAddress.setQuery(query);
58 QQmlContext *context = engine.rootContext();
59 context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
61 QString myname = QString("onstest");
63 QLibHomeScreen* homescreenHandler = new QLibHomeScreen();
64 QLibWindowmanager* qwm = new QLibWindowmanager();
67 if(qwm->init(port,secret) != 0){
70 // Request a surface as described in layers.json windowmanager’s file
71 if (qwm->requestSurface(myname) != 0) {
76 homescreenHandler->init(port, secret);
78 engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
79 engine.rootContext()->setContextProperty("homescreenHandler", homescreenHandler);
81 QObject *root = engine.rootObjects().first();
82 QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
83 QObject::connect(window, SIGNAL(frameSwapped()), qwm, SLOT(slotActivateSurface()));
85 // Create an event callback against an event type. Here a lambda is called when SyncDraw event occurs
86 qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwm, myname, root](json_object *object) {
87 fprintf(stderr, "Surface got syncDraw!\n");
91 homescreenHandler->set_event_handler(QLibHomeScreen::Event_TapShortcut, [qwm, myname](json_object *object){
92 json_object *appnameJ = nullptr;
93 if(json_object_object_get_ex(object, "application_name", &appnameJ))
95 const char *appname = json_object_get_string(appnameJ);
96 qDebug("Surface %s got tapShortcut\n", appname);
97 if(strcmp("onstest", appname) == 0)
99 qwm->activateSurface(myname);