X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=app%2Fmain.cpp;h=94b46ad5deabf62df0db8256e6a501fa78b5bc4c;hb=8e822732230d9a0498cd581dd5bb53bfa7e029a1;hp=2fac9aebff50aeae39383d7bbf6016608d90953a;hpb=f4cb3ec807e23788299f9bf1d9c323ff5690aafd;p=apps%2Fhvac.git diff --git a/app/main.cpp b/app/main.cpp index 2fac9ae..94b46ad 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -14,18 +14,59 @@ * limitations under the License. */ -#include +#include +#include +#include +#include #include +#include +#include #include "translator.h" int main(int argc, char *argv[]) { - AGLApplication app(argc, argv); - app.setApplicationName("HVAC"); - app.setupApplicationRole("hvac"); - qmlRegisterType("Translator", 1, 0, "Translator"); - app.load(QUrl(QStringLiteral("qrc:/HVAC.qml"))); - return app.exec(); -} + setenv("QT_QPA_PLATFORM", "wayland", 1); + int port; + QString token; + + QCommandLineParser parser; + QGuiApplication app(argc, argv); + + parser.addPositionalArgument("port", + app.translate("main", "port for binding")); + parser.addPositionalArgument("secret", + app.translate("main", "secret for binding")); + + parser.addHelpOption(); + parser.addVersionOption(); + parser.process(app); + QStringList positionalArguments = parser.positionalArguments(); + + if (positionalArguments.length() == 2) { + port = positionalArguments.takeFirst().toInt(); + token = positionalArguments.takeFirst(); + qInfo() << "setting port:" << port << ", token:" << token; + } else { + qInfo() << "Need to specify port and token"; + exit(EXIT_FAILURE); + } + QUrl bindingAddress; + bindingAddress.setScheme(QStringLiteral("ws")); + bindingAddress.setHost(QStringLiteral("localhost")); + bindingAddress.setPort(port); + bindingAddress.setPath(QStringLiteral("/api")); + + QUrlQuery query; + query.addQueryItem(QStringLiteral("token"), token); + bindingAddress.setQuery(query); + + QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty("bindingAddress", bindingAddress); + engine.rootContext()->setContextProperty("hvac", new HVAC(bindingAddress)); + qmlRegisterType("Translator", 1, 0, "Translator"); + engine.load(QUrl(QStringLiteral("qrc:/HVAC.qml"))); + + return app.exec(); +}