Add sample application[phone]
[staging/soundmanager.git] / sample / phone / app / main.cpp
1 /*
2  * Copyright (C) 2016 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
17 #include <QtCore/QDebug>
18 #include <QtCore/QCommandLineParser>
19 #include <QtCore/QUrlQuery>
20 #include <QtGui/QGuiApplication>
21 #include <QtQml/QQmlApplicationEngine>
22 #include <QtQml/QQmlContext>
23 #include <QtQuickControls2/QQuickStyle>
24
25 #ifdef HAVE_LIBHOMESCREEN
26 #include <libhomescreen.hpp>
27 #endif
28
29 int main(int argc, char *argv[])
30 {
31 #ifdef HAVE_LIBHOMESCREEN
32     LibHomeScreen libHomeScreen;
33
34     if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) {
35         qWarning() << "renderAppToAreaAllowed is denied";
36         return -1;
37     }
38 #endif
39
40     QGuiApplication app(argc, argv);
41
42     QQuickStyle::setStyle("AGL");
43
44     QQmlApplicationEngine engine;
45
46     QCommandLineParser parser;
47     parser.addPositionalArgument("port", app.translate("main", "port for binding"));
48     parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
49     parser.addHelpOption();
50     parser.addVersionOption();
51     parser.process(app);
52     QStringList positionalArguments = parser.positionalArguments();
53     if (positionalArguments.length() == 2) {
54         int port = positionalArguments.takeFirst().toInt();
55         QString secret = positionalArguments.takeFirst();
56         QUrl bindingAddress;
57         bindingAddress.setScheme(QStringLiteral("ws"));
58         bindingAddress.setHost(QStringLiteral("localhost"));
59         bindingAddress.setPort(port);
60         bindingAddress.setPath(QStringLiteral("/api"));
61         QUrlQuery query;
62         query.addQueryItem(QStringLiteral("token"), secret);
63         bindingAddress.setQuery(query);
64
65     QUrl bindingAddressSM;
66     bindingAddressSM.setScheme(QStringLiteral("ws"));
67     bindingAddressSM.setHost(QStringLiteral("localhost"));
68     bindingAddressSM.setPort(port);
69     bindingAddressSM.setPath(QStringLiteral("/api"));
70     bindingAddressSM.setQuery(query);
71
72         QQmlContext *context = engine.rootContext();
73         context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
74     context->setContextProperty(QStringLiteral("bindingAddressSM"), bindingAddressSM);
75     }
76     engine.load(QUrl(QStringLiteral("qrc:/Phone.qml")));
77
78     return app.exec();
79 }
80