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.
17 #include <QtCore/QDebug>
18 #include <QtCore/QCommandLineParser>
19 #include <QtCore/QUrlQuery>
20 #include <QtGui/QGuiApplication>
21 #include <QtQml/QQmlApplicationEngine>
22 #include <QtQml/QQmlContext>
23 #include <QtQuickControls2/QQuickStyle>
24 #include <QQuickWindow>
25 #include <libhomescreen.hpp>
26 #include <qlibwindowmanager.h>
28 int main(int argc, char *argv[])
30 QString myname = QString("HVAC");
32 QGuiApplication app(argc, argv);
33 app.setApplicationVersion(QStringLiteral("0.1.0"));
34 app.setOrganizationDomain(QStringLiteral("automotivelinux.org"));
35 app.setOrganizationName(QStringLiteral("AutomotiveGradeLinux"));
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();
47 QQmlApplicationEngine engine;
48 if (positionalArguments.length() == 2) {
49 int port = positionalArguments.takeFirst().toInt();
50 QString secret = positionalArguments.takeFirst();
52 bindingAddress.setScheme(QStringLiteral("ws"));
53 bindingAddress.setHost(QStringLiteral("localhost"));
54 bindingAddress.setPort(port);
55 bindingAddress.setPath(QStringLiteral("/api"));
57 query.addQueryItem(QStringLiteral("token"), secret);
58 bindingAddress.setQuery(query);
59 QQmlContext *context = engine.rootContext();
60 context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
62 std::string token = secret.toStdString();
63 LibHomeScreen* hs = new LibHomeScreen();
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) {
74 // Create an event callbnewack against an event type. Here a lambda is called when SyncDraw event occurs
75 qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwm, myname](json_object *object) {
76 fprintf(stderr, "Surface got syncDraw!\n");
81 hs->init(port, token.c_str());
82 // Set the event handler for Event_TapShortcut which will activate the surface for windowmanager
83 hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [qwm, myname](json_object *object){
84 json_object *appnameJ = nullptr;
85 if(json_object_object_get_ex(object, "application_name", &appnameJ))
87 const char *appname = json_object_get_string(appnameJ);
90 qDebug("Surface %s got tapShortcut\n", appname);
91 qwm->activateSurface(myname);
96 engine.load(QUrl(QStringLiteral("qrc:/HVAC.qml")));
97 QObject *root = engine.rootObjects().first();
98 QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
99 QObject::connect(window, SIGNAL(frameSwapped()), qwm, SLOT(slotActivateSurface()