summaryrefslogtreecommitdiffstats
path: root/app/main.cpp
diff options
context:
space:
mode:
authorTasuku Suzuki <tasuku.suzuki@qt.io>2016-12-13 12:22:08 +0900
committerTasuku Suzuki <tasuku.suzuki@qt.io>2016-12-13 23:42:32 +0900
commit1252fdb973f7ba815017447c1a3ed49852de0597 (patch)
tree50d5cda4cee0cf793a5ff72b20b266178ae08670 /app/main.cpp
parent560062626becb4d211a9948bf3008921129711cf (diff)
add binding initial code in qml
Change-Id: I0efeb67ff2659a0a01be116ab59947db77ec6574 Signed-off-by: Tasuku Suzuki <tasuku.suzuki@qt.io>
Diffstat (limited to 'app/main.cpp')
-rw-r--r--app/main.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/main.cpp b/app/main.cpp
index b2133f7..b532b73 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -15,8 +15,11 @@
*/
#include <QtCore/QDebug>
+#include <QtCore/QCommandLineParser>
+#include <QtCore/QUrlQuery>
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
+#include <QtQml/QQmlContext>
#include <QtQuickControls2/QQuickStyle>
#ifdef HAVE_LIBHOMESCREEN
@@ -35,10 +38,37 @@ int main(int argc, char *argv[])
#endif
QGuiApplication app(argc, argv);
+ app.setApplicationName(QStringLiteral("HVAC"));
+ app.setApplicationVersion(QStringLiteral("0.1.0"));
+ app.setOrganizationDomain(QStringLiteral("automotivelinux.org"));
+ app.setOrganizationName(QStringLiteral("AutomotiveGradeLinux"));
QQuickStyle::setStyle("AGL");
+ QCommandLineParser parser;
+ 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();
+
+
QQmlApplicationEngine engine;
+ if (positionalArguments.length() == 2) {
+ int port = positionalArguments.takeFirst().toInt();
+ QString secret = positionalArguments.takeFirst();
+ QUrl bindingAddress;
+ bindingAddress.setScheme(QStringLiteral("ws"));
+ bindingAddress.setHost(QStringLiteral("localhost"));
+ bindingAddress.setPort(port);
+ bindingAddress.setPath(QStringLiteral("/api"));
+ QUrlQuery query;
+ query.addQueryItem(QStringLiteral("token"), secret);
+ bindingAddress.setQuery(query);
+ QQmlContext *context = engine.rootContext();
+ context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
+ }
engine.load(QUrl(QStringLiteral("qrc:/HVAC.qml")));
return app.exec();