dbus: check if lms library can be linked
[apps/mediaplayer.git] / app / dbus.cpp
1 /*
2  * Copyright (C) 2017 Konsulko Group
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 "dbus.h"
18
19
20 DbusService::DbusService(QObject *parent) : QObject(parent)
21 {
22 }
23
24 /*
25  * Light Media Scanner
26  */
27
28 bool DbusService::enableLMS()
29 {
30     QDBusConnection session_bus = QDBusConnection::sessionBus();
31
32     if (!session_bus.isConnected())
33         return false;
34
35     return session_bus.connect(QString("org.lightmediascanner"), QString("/org/lightmediascanner/Scanner1"), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(lmsUpdate(QString,QVariantMap,QStringList)));
36 }
37
38 #if defined(HAVE_LIGHTMEDIASCANNER)
39 void DbusService::lmsUpdate(const QString&, const QVariantMap& map, const QStringList&)
40 {
41     QVariantList mediaFiles;
42     QString music;
43
44     if (!map.contains("IsScanning") && !map.contains("WriteLocked"))
45         return;
46
47     if (map["IsScanning"].toBool() || map["WriteLocked"].toBool())
48         return;
49
50     mediaFiles = LightMediaScanner::processLightMediaScanner();
51
52     if (!mediaFiles.isEmpty())
53         emit processPlaylistUpdate(mediaFiles);
54     else
55         emit processPlaylistHide();
56 }
57 #else
58 void DbusService::lmsUpdate(const QString&, const QVariantMap&, const QStringList&)
59 {
60 }
61 #endif