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