bluetooth: add a2dp metadata and avrcp controls
[apps/mediaplayer.git] / 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/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>
25
26 #ifdef HAVE_LIBHOMESCREEN
27 #include <libhomescreen.hpp>
28 #endif
29
30 #ifdef HAVE_LIGHTMEDIASCANNER
31 #include "lightmediascanner.h"
32 #endif
33
34 #ifdef HAVE_DBUS
35 #include "dbus.h"
36 #endif
37
38 #include "playlistwithmetadata.h"
39
40 #ifndef HAVE_LIGHTMEDIASCANNER
41 QVariantList readMusicFile(const QString &path)
42 {
43     QVariantList ret;
44     QDir dir(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()));
51         }
52     }
53     return ret;
54 }
55 #endif
56
57 int main(int argc, char *argv[])
58 {
59 #ifdef HAVE_LIBHOMESCREEN
60     LibHomeScreen libHomeScreen;
61
62     if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) {
63         qWarning() << "renderAppToAreaAllowed is denied";
64         return -1;
65     }
66 #endif
67
68     QGuiApplication app(argc, argv);
69
70     QQuickStyle::setStyle("AGL");
71
72     qmlRegisterType<PlaylistWithMetadata>("MediaPlayer", 1, 0, "PlaylistWithMetadata");
73
74     QVariantList mediaFiles;
75
76 #ifdef HAVE_LIGHTMEDIASCANNER
77     mediaFiles = LightMediaScanner::processLightMediaScanner();
78 #else
79     QString music;
80
81     for (const auto &music : QStandardPaths::standardLocations(QStandardPaths::MusicLocation)) {
82         mediaFiles.append(readMusicFile(music));
83     }
84 #endif
85
86     QQmlApplicationEngine engine;
87     QQmlContext *context = engine.rootContext();
88     context->setContextProperty("mediaFiles", mediaFiles);
89
90 #if defined(HAVE_DBUS)
91     DbusService dbus_service;
92     context->setContextProperty("dbus", &dbus_service);
93 #if defined(HAVE_LIGHTMEDIASCANNER)
94     if (!dbus_service.enableLMS())
95        qWarning() << "Cannot run enableLMS";
96 #endif
97     if (!dbus_service.enableBluetooth())
98        qWarning() << "Cannot run enableBluetooth";
99 #endif
100     engine.load(QUrl(QStringLiteral("qrc:/MediaPlayer.qml")));
101
102     return app.exec();
103 }