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"
34 #include "playlistwithmetadata.h"
36 #ifndef HAVE_LIGHTMEDIASCANNER
37 QVariantList readMusicFile(const QString &path)
41 for (const auto &entry : dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name)) {
42 QFileInfo fileInfo(dir.absoluteFilePath(entry));
43 if (fileInfo.isDir()) {
44 ret.append(readMusicFile(fileInfo.absoluteFilePath()));
45 } else if (fileInfo.isFile()) {
46 ret.append(QUrl::fromLocalFile(fileInfo.absoluteFilePath()));
53 int main(int argc, char *argv[])
55 #ifdef HAVE_LIBHOMESCREEN
56 LibHomeScreen libHomeScreen;
58 if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) {
59 qWarning() << "renderAppToAreaAllowed is denied";
64 QGuiApplication app(argc, argv);
66 QQuickStyle::setStyle("AGL");
68 qmlRegisterType<PlaylistWithMetadata>("MediaPlayer", 1, 0, "PlaylistWithMetadata");
70 QVariantList mediaFiles;
73 #ifdef HAVE_LIGHTMEDIASCANNER
74 LightMediaScanner scanner(QDir::homePath() + "/.config/lightmediascannerd/db.sqlite3");
75 while (scanner.next(music)) {
76 QFileInfo fileInfo(music);
77 // Possible for stale entries due to removable media
78 if (!fileInfo.exists())
80 mediaFiles.append(QUrl::fromLocalFile(music));
83 for (const auto &music : QStandardPaths::standardLocations(QStandardPaths::MusicLocation)) {
84 mediaFiles.append(readMusicFile(music));
88 QQmlApplicationEngine engine;
89 QQmlContext *context = engine.rootContext();
90 context->setContextProperty("mediaFiles", mediaFiles);
91 engine.load(QUrl(QStringLiteral("qrc:/MediaPlayer.qml")));