app/main: Bring back secret and port to be able to access the 57/24857/1 9.99.1 9.99.2 9.99.3 9.99.4 jellyfish/9.99.1 jellyfish/9.99.2 jellyfish/9.99.3 jellyfish/9.99.4 jellyfish_9.99.1 jellyfish_9.99.2 jellyfish_9.99.3 jellyfish_9.99.4
authorMarius Vlad <marius.vlad@collabora.com>
Fri, 29 May 2020 14:57:33 +0000 (17:57 +0300)
committerMarius Vlad <marius.vlad@collabora.com>
Wed, 24 Jun 2020 15:13:15 +0000 (18:13 +0300)
bindingAdress

Bug-AGL: SPEC-3447

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Change-Id: I5afeecdbfc9d0272d9231d7d4c19334c1ce6d9cc

app/main.cpp

index 41b5892..76efbbf 100644 (file)
  */
 
 #include <QGuiApplication>
+#include <QtCore/QCommandLineParser>
+#include <QtCore/QUrlQuery>
 #include <QtGui/QGuiApplication>
 #include <QtQml/QQmlContext>
 #include <QtQml/QQmlApplicationEngine>
 #include <QtQml/qqml.h>
+#include <QDebug>
 
 #include "mixer.hpp"
 #include "audiorole.hpp"
@@ -30,9 +33,38 @@ int main(int argc, char *argv[])
         QGuiApplication app(argc, argv);
         app.setDesktopFileName("mixer");
 
-        QQmlApplicationEngine engine;
-        qmlRegisterType<Mixer>("Mixer", 1, 0, "Mixer");
-        engine.load(QUrl(QStringLiteral("qrc:/Mixer.qml")));
+       QQmlApplicationEngine engine;
+       QQmlContext *context = engine.rootContext();
+
+       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) {
+               int port = positionalArguments.takeFirst().toInt();
+               QString secret = positionalArguments.takeFirst();
+
+               QUrl bindingAddress;
+               QUrlQuery query;
+
+               bindingAddress.setScheme(QStringLiteral("ws"));
+               bindingAddress.setHost(QStringLiteral("localhost"));
+               bindingAddress.setPort(port);
+               bindingAddress.setPath(QStringLiteral("/api"));
+
+
+               query.addQueryItem(QStringLiteral("token"), secret);
+               bindingAddress.setQuery(query);
+               context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
+
+               qmlRegisterType<Mixer>("Mixer", 1, 0, "Mixer");
+       }
+
+       engine.load(QUrl(QStringLiteral("qrc:/Mixer.qml")));
         return app.exec();
 
 }