2 * Copyright (C) 2016 The Qt Company Ltd.
3 * Copyright (C) 2018, 2019 Konsulko Group
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <QtCore/QDebug>
19 #include <QtCore/QCommandLineParser>
20 #include <QtCore/QUrlQuery>
21 #include <QtGui/QGuiApplication>
22 #include <QtQml/QQmlApplicationEngine>
23 #include <QtQml/QQmlContext>
24 #include <QtQml/qqml.h>
25 #include <QQuickWindow>
26 #include <QtQuickControls2/QQuickStyle>
29 #include <qlibwindowmanager.h>
30 #include <signalcomposer.h>
32 // Global indicating whether canned animation should run
33 bool runAnimation = true;
35 void read_config(void)
40 // Load settings from configuration file if it exists
41 conf_file = g_key_file_new();
43 g_key_file_load_from_dirs(conf_file,
45 (const gchar**) g_get_system_config_dirs(),
47 G_KEY_FILE_KEEP_COMMENTS,
50 value = g_key_file_get_boolean(conf_file,
60 qWarning("Invalid value for \"animation\" key!");
67 int main(int argc, char *argv[])
69 // Slight hack, using the homescreen role greatly simplifies things wrt
71 QString myname = QString("homescreen");
73 QGuiApplication app(argc, argv);
75 QCommandLineParser parser;
76 parser.addPositionalArgument("port", app.translate("main", "port for binding"));
77 parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
78 parser.addHelpOption();
79 parser.addVersionOption();
81 QStringList positionalArguments = parser.positionalArguments();
83 QQmlApplicationEngine engine;
85 if (positionalArguments.length() == 2) {
86 int port = positionalArguments.takeFirst().toInt();
87 QString secret = positionalArguments.takeFirst();
89 bindingAddress.setScheme(QStringLiteral("ws"));
90 bindingAddress.setHost(QStringLiteral("localhost"));
91 bindingAddress.setPort(port);
92 bindingAddress.setPath(QStringLiteral("/api"));
94 query.addQueryItem(QStringLiteral("token"), secret);
95 bindingAddress.setQuery(query);
96 QQmlContext *context = engine.rootContext();
97 context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
99 std::string token = secret.toStdString();
100 QLibWindowmanager* qwm = new QLibWindowmanager();
103 if(qwm->init(port, secret) != 0){
107 // Request a surface as described in layers.json windowmanager’s file
108 if (qwm->requestSurface(myname) != 0) {
112 // Create an event callback against an event type. Here a lambda is called when SyncDraw event occurs
113 qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwm, myname](json_object*) {
114 fprintf(stderr, "Surface got syncDraw!\n");
115 qwm->endDraw(myname);
118 context->setContextProperty("SignalComposer", new SignalComposer(bindingAddress, context));
120 context->setContextProperty("runAnimation", runAnimation);
122 engine.load(QUrl(QStringLiteral("qrc:/cluster-gauges.qml")));
124 // Find the instantiated model QObject and connect the signals/slots
125 QList<QObject *> mobjs = engine.rootObjects();
127 QQuickWindow *window = qobject_cast<QQuickWindow *>(mobjs.first());
128 QObject::connect(window, SIGNAL(frameSwapped()), qwm, SLOT(slotActivateSurface()));