app/main: Bring back secret and port to be able to access the
[apps/mixer.git] / app / main.cpp
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  * Copyright (C) 2016,2017 Konsulko Group
4  * Copyright (C) 2018 IoT.bzh
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <QGuiApplication>
20 #include <QtCore/QCommandLineParser>
21 #include <QtCore/QUrlQuery>
22 #include <QtGui/QGuiApplication>
23 #include <QtQml/QQmlContext>
24 #include <QtQml/QQmlApplicationEngine>
25 #include <QtQml/qqml.h>
26 #include <QDebug>
27
28 #include "mixer.hpp"
29 #include "audiorole.hpp"
30
31 int main(int argc, char *argv[])
32 {
33         QGuiApplication app(argc, argv);
34         app.setDesktopFileName("mixer");
35
36         QQmlApplicationEngine engine;
37         QQmlContext *context = engine.rootContext();
38
39         QCommandLineParser parser;
40         parser.addPositionalArgument("port", app.translate("main", "port for binding"));
41         parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
42         parser.addHelpOption();
43         parser.addVersionOption();
44         parser.process(app);
45         QStringList positionalArguments = parser.positionalArguments();
46
47         if (positionalArguments.length() == 2) {
48                 int port = positionalArguments.takeFirst().toInt();
49                 QString secret = positionalArguments.takeFirst();
50
51                 QUrl bindingAddress;
52                 QUrlQuery query;
53
54                 bindingAddress.setScheme(QStringLiteral("ws"));
55                 bindingAddress.setHost(QStringLiteral("localhost"));
56                 bindingAddress.setPort(port);
57                 bindingAddress.setPath(QStringLiteral("/api"));
58
59
60                 query.addQueryItem(QStringLiteral("token"), secret);
61                 bindingAddress.setQuery(query);
62                 context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
63
64                 qmlRegisterType<Mixer>("Mixer", 1, 0, "Mixer");
65         }
66
67         engine.load(QUrl(QStringLiteral("qrc:/Mixer.qml")));
68         return app.exec();
69
70 }