2 * Copyright (C) 2016 The Qt Company Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <QtCore/QCommandLineParser>
18 #include <QtCore/QDebug>
19 #include <QtCore/QDir>
20 #include <QtCore/QStandardPaths>
21 #include <QtCore/QUrlQuery>
22 #include <QtGui/QGuiApplication>
23 #include <QtQml/QQmlApplicationEngine>
24 #include <QtQml/QQmlContext>
25 #include <QtQml/qqml.h>
26 #include <QtQuickControls2/QQuickStyle>
28 #ifdef HAVE_LIBHOMESCREEN
29 #include <libhomescreen.hpp>
32 #include "playlistwithmetadata.h"
34 int main(int argc, char *argv[])
36 #ifdef HAVE_LIBHOMESCREEN
37 LibHomeScreen libHomeScreen;
39 if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) {
40 qWarning() << "renderAppToAreaAllowed is denied";
45 QGuiApplication app(argc, argv);
47 QQuickStyle::setStyle("AGL");
49 qmlRegisterType<PlaylistWithMetadata>("MediaPlayer", 1, 0, "PlaylistWithMetadata");
51 QQmlApplicationEngine engine;
52 QQmlContext *context = engine.rootContext();
54 QCommandLineParser parser;
55 parser.addPositionalArgument("port", app.translate("main", "port for binding"));
56 parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
57 parser.addHelpOption();
58 parser.addVersionOption();
60 QStringList positionalArguments = parser.positionalArguments();
62 if (positionalArguments.length() == 2) {
63 int port = positionalArguments.takeFirst().toInt();
64 QString secret = positionalArguments.takeFirst();
66 bindingAddress.setScheme(QStringLiteral("ws"));
67 bindingAddress.setHost(QStringLiteral("localhost"));
68 bindingAddress.setPort(port);
69 bindingAddress.setPath(QStringLiteral("/api"));
71 query.addQueryItem(QStringLiteral("token"), secret);
72 bindingAddress.setQuery(query);
73 context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
76 engine.load(QUrl(QStringLiteral("qrc:/MediaPlayer.qml")));