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 #include "playlistwithmetadata.h"
32 QVariantList readMusicFile(const QString &path)
36 for (const auto &entry : dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name)) {
37 QFileInfo fileInfo(dir.absoluteFilePath(entry));
38 if (fileInfo.isDir()) {
39 ret.append(readMusicFile(fileInfo.absoluteFilePath()));
40 } else if (fileInfo.isFile()) {
41 ret.append(QUrl::fromLocalFile(fileInfo.absoluteFilePath()));
47 int main(int argc, char *argv[])
49 #ifdef HAVE_LIBHOMESCREEN
50 LibHomeScreen libHomeScreen;
52 if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) {
53 qWarning() << "renderAppToAreaAllowed is denied";
58 QGuiApplication app(argc, argv);
60 QQuickStyle::setStyle("AGL");
62 qmlRegisterType<PlaylistWithMetadata>("MediaPlayer", 1, 0, "PlaylistWithMetadata");
64 QVariantList mediaFiles;
65 for (const auto &music : QStandardPaths::standardLocations(QStandardPaths::MusicLocation)) {
66 mediaFiles.append(readMusicFile(music));
69 QQmlApplicationEngine engine;
70 QQmlContext *context = engine.rootContext();
71 context->setContextProperty("mediaFiles", mediaFiles);
72 engine.load(QUrl(QStringLiteral("qrc:/MediaPlayer.qml")));