app/: Avoid any AGL wrappers and use plain Qt
[apps/hvac.git] / app / main.cpp
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <QtGui/QGuiApplication>
18 #include <QDebug>
19 #include <QUrlQuery>
20 #include <QCommandLineParser>
21 #include <QtQml/QQmlApplicationEngine>
22 #include <QtQml/QQmlContext>
23
24 #include "translator.h"
25
26 int main(int argc, char *argv[])
27 {
28         setenv("QT_QPA_PLATFORM", "wayland", 1);
29         int port;
30         QString token;
31
32         QCommandLineParser parser;
33         QGuiApplication app(argc, argv);
34
35         parser.addPositionalArgument("port",
36                 app.translate("main", "port for binding"));
37         parser.addPositionalArgument("secret",
38                 app.translate("main", "secret for binding"));
39
40         parser.addHelpOption();
41         parser.addVersionOption();
42         parser.process(app);
43         QStringList positionalArguments = parser.positionalArguments();
44
45         if (positionalArguments.length() == 2) {
46                 port = positionalArguments.takeFirst().toInt();
47                 token = positionalArguments.takeFirst();
48                 qInfo() << "setting port:" << port << ", token:" << token;
49         } else {
50                 qInfo() << "Need to specify port and token";
51                 exit(EXIT_FAILURE);
52         }
53
54         QUrl bindingAddress;
55         bindingAddress.setScheme(QStringLiteral("ws"));
56         bindingAddress.setHost(QStringLiteral("localhost"));
57         bindingAddress.setPort(port);
58         bindingAddress.setPath(QStringLiteral("/api"));
59
60         QUrlQuery query;
61         query.addQueryItem(QStringLiteral("token"), token);
62         bindingAddress.setQuery(query);
63
64         QQmlApplicationEngine engine;
65         engine.rootContext()->setContextProperty("bindingAddress", bindingAddress);
66         qmlRegisterType<Translator>("Translator", 1, 0, "Translator");
67         engine.load(QUrl(QStringLiteral("qrc:/HVAC.qml")));
68
69         return app.exec();
70 }