2 * Copyright (C) 2016 The Qt Company Ltd.
3 * Copyright (C) 2016, 2017 Konsulko Group
4 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <QtCore/QDebug>
20 #include <QtCore/QCommandLineParser>
21 #include <QtCore/QUrlQuery>
22 #include <QtCore/QSettings>
23 #include <QtGui/QGuiApplication>
24 #include <QtQml/QQmlApplicationEngine>
25 #include <QtQml/QQmlContext>
26 #include <QtQuickControls2/QQuickStyle>
28 #include "PresetDataObject.h"
31 #ifdef HAVE_LIBHOMESCREEN
32 #include <libhomescreen.hpp>
35 int main(int argc, char *argv[])
37 #ifdef HAVE_LIBHOMESCREEN
38 LibHomeScreen libHomeScreen;
40 if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) {
41 qWarning() << "renderAppToAreaAllowed is denied";
46 QGuiApplication app(argc, argv);
48 QQuickStyle::setStyle("AGL");
50 QCommandLineParser parser;
51 parser.addPositionalArgument("port", app.translate("main", "port for binding"));
52 parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
53 parser.addHelpOption();
54 parser.addVersionOption();
56 QStringList positionalArguments = parser.positionalArguments();
58 // Read presets from configuration file
60 // If HOME is set, use $HOME/app-data/radio/presets.conf, else fall back
61 // to the QSettings default locations with organization "AGL" and a
62 // file name of radio-presets.conf. See:
64 // http://doc.qt.io/qt-5/qsettings.html#platform-specific-notes
66 // for details on the locations and their order of priority.
68 QSettings *pSettings = NULL;
69 char *p = getenv("HOME");
72 confPath.append("/app-data/radio/presets.conf");
73 pSettings = new QSettings(confPath, QSettings::NativeFormat);
75 pSettings = new QSettings("AGL", "radio-presets");
77 QList<QObject*> presetDataList;
78 int size = pSettings->beginReadArray("fmPresets");
79 for (int i = 0; i < size; ++i) {
80 pSettings->setArrayIndex(i);
81 presetDataList.append(new PresetDataObject(pSettings->value("title").toString(),
82 pSettings->value("frequency").toInt(),
85 pSettings->endArray();
87 QQmlApplicationEngine engine;
88 QQmlContext *context = engine.rootContext();
89 context->setContextProperty("presetModel", QVariant::fromValue(presetDataList));
90 if (positionalArguments.length() == 2) {
91 int port = positionalArguments.takeFirst().toInt();
92 QString secret = positionalArguments.takeFirst();
94 bindingAddress.setScheme(QStringLiteral("ws"));
95 bindingAddress.setHost(QStringLiteral("localhost"));
96 bindingAddress.setPort(port);
97 bindingAddress.setPath(QStringLiteral("/api"));
99 query.addQueryItem(QStringLiteral("token"), secret);
100 bindingAddress.setQuery(query);
102 QUrl bindingAddressSM;
103 bindingAddressSM.setScheme(QStringLiteral("ws"));
104 bindingAddressSM.setHost(QStringLiteral("localhost"));
105 bindingAddressSM.setPort(port);
106 bindingAddressSM.setPath(QStringLiteral("/api"));
107 bindingAddressSM.setQuery(query);
109 context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
110 context->setContextProperty(QStringLiteral("bindingAddressSM"), bindingAddressSM);
112 engine.load(QUrl(QStringLiteral("qrc:/Radio.qml")));