summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2020-09-23 16:57:33 -0400
committerScott Murray <scott.murray@konsulko.com>2020-09-23 17:00:30 -0400
commit05753692843e225d2370c63857334d2f675ed003 (patch)
tree98dc08a7257f6f592aa39f59c24d6a42fb879616
parentdfa4b434de916234e5b79cbdd2a2a2970e47ae36 (diff)
Fix signal-composer integration
Copy command-line parsing from hvac application to replace what was being done by the now removed QtAGLExtras code, this allows correctly instantiating the signal-composer object from qtappfw again. Bug-AGL: SPEC-3602 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: I0ec7f75af814d67fa0b4f431450e437fddf57e11
-rw-r--r--app/main.cpp33
1 files changed, 26 insertions, 7 deletions
diff --git a/app/main.cpp b/app/main.cpp
index 2eef1b0..6fe44d3 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -19,6 +19,8 @@
#include <QtQml/QQmlApplicationEngine>
#include <QtQml/QQmlContext>
#include <QtGui/QGuiApplication>
+#include <QtCore/QCommandLineParser>
+#include <QtCore/QUrlQuery>
#include <signalcomposer.h>
#include "translator.h"
@@ -27,15 +29,32 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
app.setDesktopFileName("dashboard");
+ 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();
+ if (positionalArguments.length() != 2) {
+ exit(EXIT_FAILURE);
+ }
+
+ int port = positionalArguments.takeFirst().toInt();
+ QString secret = positionalArguments.takeFirst();
+ QUrlQuery query;
+ query.addQueryItem(QStringLiteral("token"), secret);
+
+ QUrl bindingAddress;
+ bindingAddress.setScheme(QStringLiteral("ws"));
+ bindingAddress.setHost(QStringLiteral("localhost"));
+ bindingAddress.setPort(port);
+ bindingAddress.setPath(QStringLiteral("/api"));
+ bindingAddress.setQuery(query);
+
QQmlApplicationEngine engine;
QQmlContext *context = engine.rootContext();
- QVariant v = context->contextProperty(QStringLiteral("bindingAddress"));
- if(v.canConvert(QMetaType::QUrl)) {
- QUrl bindingAddress = v.toUrl();
- context->setContextProperty("SignalComposer", new SignalComposer(bindingAddress, context));
- } else {
- qCritical("Cannot find bindingAddress property in context, SignalComposer unavailable");
- }
+ context->setContextProperty("SignalComposer", new SignalComposer(bindingAddress, context));
qmlRegisterType<Translator>("Translator", 1, 0, "Translator");
engine.load(QUrl(QStringLiteral("qrc:/Dashboard.qml")));
return app.exec();