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/QDebug>
18 #include <QtCore/QDir>
19 #include <QtCore/QStandardPaths>
20 #include <QtGui/QGuiApplication>
21 #include <QtQml/QQmlApplicationEngine>
22 #include <QtQml/QQmlContext>
23 #include <QtQml/qqml.h>
24 #include <QtQuickControls2/QQuickStyle>
26 #ifdef HAVE_LIBHOMESCREEN
27 #include <libhomescreen.hpp>
30 #ifdef HAVE_LIGHTMEDIASCANNER
31 #include "lightmediascanner.h"
38 #include "playlistwithmetadata.h"
40 #ifndef HAVE_LIGHTMEDIASCANNER
41 QVariantList readMusicFile(const QString &path)
45 for (const auto &entry : dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name)) {
46 QFileInfo fileInfo(dir.absoluteFilePath(entry));
47 if (fileInfo.isDir()) {
48 ret.append(readMusicFile(fileInfo.absoluteFilePath()));
49 } else if (fileInfo.isFile()) {
50 ret.append(QUrl::fromLocalFile(fileInfo.absoluteFilePath()));
57 int main(int argc, char *argv[])
59 #ifdef HAVE_LIBHOMESCREEN
60 LibHomeScreen libHomeScreen;
62 if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) {
63 qWarning() << "renderAppToAreaAllowed is denied";
68 QGuiApplication app(argc, argv);
70 QQuickStyle::setStyle("AGL");
72 qmlRegisterType<PlaylistWithMetadata>("MediaPlayer", 1, 0, "PlaylistWithMetadata");
74 QVariantList mediaFiles;
76 #ifdef HAVE_LIGHTMEDIASCANNER
77 mediaFiles = LightMediaScanner::processLightMediaScanner();
81 for (const auto &music : QStandardPaths::standardLocations(QStandardPaths::MusicLocation)) {
82 mediaFiles.append(readMusicFile(music));
86 QQmlApplicationEngine engine;
87 QQmlContext *context = engine.rootContext();
88 context->setContextProperty("mediaFiles", mediaFiles);
90 #if defined(HAVE_DBUS)
91 DbusService dbus_service;
92 context->setContextProperty("dbus", &dbus_service);
95 engine.load(QUrl(QStringLiteral("qrc:/MediaPlayer.qml")));
97 #if defined(HAVE_DBUS)
98 #if defined(HAVE_LIGHTMEDIASCANNER)
99 if (!dbus_service.enableLMS())
100 qWarning() << "Cannot run enableLMS";
102 if (!dbus_service.enableBluetooth())
103 qWarning() << "Cannot run enableBluetooth";