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 <QtQuick/QQuickWindow>
25 #include "translator.h"
27 #ifdef HAVE_LIBHOMESCREEN
28 #include <libhomescreen.hpp>
30 #ifdef HAVE_QLIBWINDOWMANAGER
31 #include <qlibwindowmanager.h>
34 int main(int argc, char *argv[])
36 QString myname = QString("HVAC");
38 QGuiApplication app(argc, argv);
39 app.setApplicationVersion(QStringLiteral("0.1.0"));
40 app.setOrganizationDomain(QStringLiteral("automotivelinux.org"));
41 app.setOrganizationName(QStringLiteral("AutomotiveGradeLinux"));
43 QCommandLineParser parser;
44 parser.addPositionalArgument("port", app.translate("main", "port for binding"));
45 parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
46 parser.addHelpOption();
47 parser.addVersionOption();
49 QStringList positionalArguments = parser.positionalArguments();
51 qmlRegisterType<Translator>("Translator", 1, 0, "Translator");
53 QQmlApplicationEngine engine;
54 QQmlContext *context = engine.rootContext();
59 if (positionalArguments.length() == 2) {
60 port = positionalArguments.takeFirst().toInt();
61 secret = positionalArguments.takeFirst();
62 bindingAddress.setScheme(QStringLiteral("ws"));
63 bindingAddress.setHost(QStringLiteral("localhost"));
64 bindingAddress.setPort(port);
65 bindingAddress.setPath(QStringLiteral("/api"));
67 query.addQueryItem(QStringLiteral("token"), secret);
68 bindingAddress.setQuery(query);
70 context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
71 #ifdef HAVE_QLIBWINDOWMANAGER
72 QLibWindowmanager* qwm = new QLibWindowmanager();
75 if(qwm->init(port,secret) != 0){
78 AGLScreenInfo screenInfo(qwm->get_scale_factor());
79 engine.rootContext()->setContextProperty(QStringLiteral("screenInfo"), &screenInfo);
80 // Request a surface as described in layers.json windowmanager’s file
81 if (qwm->requestSurface(myname) != 0) {
84 // Create an event callbnewack against an event type. Here a lambda is called when SyncDraw event occurs
85 qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwm, myname](json_object *object) {
86 fprintf(stderr, "Surface got syncDraw!\n");
91 #ifdef HAVE_LIBHOMESCREEN
92 LibHomeScreen* hs = new LibHomeScreen();
95 std::string token = secret.toStdString();
96 hs->init(port, token.c_str());
97 // Set the event handler for Event_TapShortcut which will activate the surface for windowmanager
98 hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [qwm, myname](json_object *object){
99 json_object *appnameJ = nullptr;
100 if(json_object_object_get_ex(object, "application_name", &appnameJ))
102 const char *appname = json_object_get_string(appnameJ);
103 if(myname == appname)
105 qDebug("Surface %s got tapShortcut\n", appname);
106 qwm->activateSurface(myname);
112 engine.load(QUrl(QStringLiteral("qrc:/HVAC.qml")));
113 QObject *root = engine.rootObjects().first();
114 QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
115 #ifdef HAVE_QLIBWINDOWMANAGER
116 QObject::connect(window, SIGNAL(frameSwapped()), qwm, SLOT(slotActivateSurface()));
118 window->resize(1080, 1920 - 218 - 215);
119 window->setVisible(true);