dbus: add signal support for removable media
[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 void DbusService::lmsUpdate(const QString&, const QVariantMap& map, const QStringList&)
39 {
40     QVariantList mediaFiles;
41     QString music;
42
43     if (!map.contains("IsScanning") && !map.contains("WriteLocked"))
44         return;
45
46     if (map["IsScanning"].toBool() || map["WriteLocked"].toBool())
47         return;
48
49     mediaFiles = LightMediaScanner::processLightMediaScanner();
50
51     if (!mediaFiles.isEmpty())
52         emit processPlaylistUpdate(mediaFiles);
53     else
54         emit processPlaylistHide();
55 }