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 std::string myname = std::string("HVAC");
32 QGuiApplication app(argc, argv);
33 app.setApplicationName(myname.c_str());
34 app.setApplicationVersion(QStringLiteral("0.1.0"));
35 app.setOrganizationDomain(QStringLiteral("automotivelinux.org"));
36 app.setOrganizationName(QStringLiteral("AutomotiveGradeLinux"));
38 QQuickStyle::setStyle("AGL");
40 QCommandLineParser parser;
41 parser.addPositionalArgument("port", app.translate("main", "port for binding"));
42 parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
43 parser.addHelpOption();
44 parser.addVersionOption();
46 QStringList positionalArguments = parser.positionalArguments();
48 QQmlApplicationEngine engine;
49 if (positionalArguments.length() == 2) {
50 int port = positionalArguments.takeFirst().toInt();
51 QString secret = positionalArguments.takeFirst();
53 bindingAddress.setScheme(QStringLiteral("ws"));
54 bindingAddress.setHost(QStringLiteral("localhost"));
55 bindingAddress.setPort(port);
56 bindingAddress.setPath(QStringLiteral("/api"));
58 query.addQueryItem(QStringLiteral("token"), secret);
59 bindingAddress.setQuery(query);
60 QQmlContext *context = engine.rootContext();
61 context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
63 std::string token = secret.toStdString();
64 LibHomeScreen* hs = new LibHomeScreen();
65 QLibWindowmanager* qwm = new QLibWindowmanager();
68 if(qwm->init(port,secret) != 0){
71 if (qwm->requestSurface(json_object_new_string(myname.c_str())) != 0) {
74 qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwm, myname](json_object *object) {
75 fprintf(stderr, "Surface got syncDraw!\n");
76 qwm->endDraw(json_object_new_string(myname.c_str()));
80 hs->init(port, token.c_str());
81 hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [qwm, myname](json_object *object){
82 qDebug("object %s", json_object_to_json_string(object));
83 json_object *appnameJ = nullptr;
84 if(json_object_object_get_ex(object, "application_name", &appnameJ))
86 const char *appname = json_object_get_string(appnameJ);
87 qDebug("appnameJ %s", json_object_to_json_string(appnameJ));
90 qDebug("Surface %s got tapShortcut\n", appname);
91 qwm->activateSurface(json_object_new_string(myname.c_str()));
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()