summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/MediaPlayer.qml19
-rw-r--r--app/api/LightMediaScanner.qml40
-rw-r--r--app/app.pri3
-rw-r--r--app/dbus.cpp54
-rw-r--r--app/dbus.h3
-rw-r--r--app/lightmediascanner.cpp63
-rw-r--r--app/lightmediascanner.h41
-rw-r--r--app/main.cpp23
8 files changed, 34 insertions, 212 deletions
diff --git a/app/MediaPlayer.qml b/app/MediaPlayer.qml
index 95af8c0..71bda77 100644
--- a/app/MediaPlayer.qml
+++ b/app/MediaPlayer.qml
@@ -54,21 +54,6 @@ ApplicationWindow {
Connections {
target: dbus
- onStopPlayback: {
- player.stop()
- playlist.clear()
- playlistmodel.setSource(playlist)
- playlistview.visible = false
- }
-
- onProcessPlaylistUpdate: {
- playlist.clear()
- playlist.addItems(mediaFiles)
-
- playlistmodel.setSource(playlist)
- playlistview.visible = bluetooth.connected == false
- }
-
onProcessPlaylistHide: {
playlistview.visible = false
player.stop()
@@ -126,10 +111,6 @@ ApplicationWindow {
Playlist {
id: playlist
playbackMode: random.checked ? Playlist.Random : loop.checked ? Playlist.Loop : Playlist.Sequential
-
- Component.onCompleted: {
- playlist.addItems(mediaFiles)
- }
}
diff --git a/app/api/LightMediaScanner.qml b/app/api/LightMediaScanner.qml
index 1fe2f25..d0b7137 100644
--- a/app/api/LightMediaScanner.qml
+++ b/app/api/LightMediaScanner.qml
@@ -43,21 +43,30 @@ WebSocket {
console.debug("response: " + JSON.stringify(response))
switch (json[0]) {
case msgid.call:
- break
+ break
case msgid.retok:
- root.statusString = request.status
- var verb = verbs.shift()
- if (verb == "media_added") {
- console.debug("Media is inserted")
- } else if (verb == "media_removed") {
- console.debug("Media is removed")
- }
- break
+ root.statusString = request.status
+ var verb = verbs.shift()
+ if (verb == "media_result") {
+ console.debug("Media result returned")
+ playlist.addItems(response.Media)
+ }
+ break
case msgid.reterr:
- root.statusString = "Bad return value, binding probably not installed"
- break
+ root.statusString = "Bad return value, binding probably not installed"
+ break
case msgid.event:
- break
+ var payload = JSON.parse(JSON.stringify(json[2]))
+ var event = payload.event
+ if (event == "media-manager/media_added") {
+ console.debug("Media is inserted")
+ playlist.addItems(json[2].data.Media)
+ } else if (event == "media-manager/media_removed") {
+ console.debug("Media is removed")
+ player.stop()
+ playlist.clear()
+ }
+ break
}
}
@@ -65,6 +74,9 @@ WebSocket {
switch (status) {
case WebSocket.Open:
console.debug("onStatusChanged: Open")
+ sendSocketMessage("subscribe", { value: "media_added" })
+ sendSocketMessage("subscribe", { value: "media_removed" })
+ root.populateMediaPlaylist()
break
case WebSocket.Error:
root.statusString = "WebSocket error: " + root.errorString
@@ -79,4 +91,8 @@ WebSocket {
verbs.push(verb)
sendTextMessage(JSON.stringify(requestJson))
}
+
+ function populateMediaPlaylist() {
+ sendSocketMessage("media_result", 'None')
+ }
}
diff --git a/app/app.pri b/app/app.pri
index 82f5a74..56bc949 100644
--- a/app/app.pri
+++ b/app/app.pri
@@ -10,10 +10,7 @@ config_libhomescreen {
}
packagesExist(sqlite3 lightmediascanner) {
- HEADERS += lightmediascanner.h
- SOURCES += lightmediascanner.cpp
DEFINES += HAVE_LIGHTMEDIASCANNER
- QT += sql
}
packagesExist(dbus-1) {
diff --git a/app/dbus.cpp b/app/dbus.cpp
index 3c298a0..a562989 100644
--- a/app/dbus.cpp
+++ b/app/dbus.cpp
@@ -22,60 +22,6 @@ DbusService::DbusService(QObject *parent) : QObject(parent)
}
/*
- * Light Media Scanner
- */
-
-bool DbusService::enableLMS()
-{
- QDBusConnection session_bus = QDBusConnection::sessionBus();
- QDBusConnection system_bus = QDBusConnection::systemBus();
- bool ret;
-
- if (!session_bus.isConnected())
- return false;
-
- if (!system_bus.isConnected())
- return false;
-
- ret = session_bus.connect(QString("org.lightmediascanner"), QString("/org/lightmediascanner/Scanner1"), "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(lmsUpdate(QString,QVariantMap,QStringList)));
- if (!ret)
- return false;
-
- /* Only subscribe to DeviceRemoved events, since we need lms scan to complete on insert */
- return system_bus.connect(QString("org.freedesktop.UDisks"), QString("/org/freedesktop/UDisks"), "org.freedesktop.UDisks", "DeviceRemoved", this, SLOT(mediaRemoved(QDBusObjectPath)));
-}
-
-void DbusService::mediaRemoved(const QDBusObjectPath&)
-{
- emit stopPlayback();
-}
-
-#if defined(HAVE_LIGHTMEDIASCANNER)
-void DbusService::lmsUpdate(const QString&, const QVariantMap& map, const QStringList&)
-{
- QVariantList mediaFiles;
- QString music;
-
- if (!map.contains("IsScanning") && !map.contains("WriteLocked"))
- return;
-
- if (map["IsScanning"].toBool() || map["WriteLocked"].toBool())
- return;
-
- mediaFiles = LightMediaScanner::processLightMediaScanner();
-
- if (!mediaFiles.isEmpty())
- emit processPlaylistUpdate(mediaFiles);
- else
- emit processPlaylistHide();
-}
-#else
-void DbusService::lmsUpdate(const QString&, const QVariantMap&, const QStringList&)
-{
-}
-#endif
-
-/*
* Bluetooth
*/
diff --git a/app/dbus.h b/app/dbus.h
index 2dd6e34..d857f1a 100644
--- a/app/dbus.h
+++ b/app/dbus.h
@@ -35,7 +35,6 @@ class DbusService : public QObject {
public:
explicit DbusService(QObject *parent = 0);
- bool enableLMS();
bool enableBluetooth();
Q_INVOKABLE void processQMLEvent(const QString&);
Q_INVOKABLE long getCurrentPosition();
@@ -59,8 +58,6 @@ signals:
void updatePlayerStatus(const QString status);
private slots:
- void lmsUpdate(const QString&, const QVariantMap&, const QStringList&);
- void mediaRemoved(const QDBusObjectPath&);
void newBluetoothDevice(const QDBusObjectPath&, const QVariantMap&);
void removeBluetoothDevice(const QDBusObjectPath&, const QStringList&);
void processBluetoothEvent(const QString&, const QVariantMap&, const QStringList&);
diff --git a/app/lightmediascanner.cpp b/app/lightmediascanner.cpp
deleted file mode 100644
index 7081f50..0000000
--- a/app/lightmediascanner.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2017 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "lightmediascanner.h"
-
-LightMediaScanner::LightMediaScanner(const QString& path)
-{
- lms = QSqlDatabase::addDatabase("QSQLITE");
- lms.setDatabaseName(path);
-
- if (!lms.open()) {
- qDebug() << "Cannot open database: " << path;
- } else {
- query = QSqlQuery(lms);
- query.prepare("SELECT files.path FROM files LEFT JOIN audios WHERE audios.id = files.id ORDER BY audios.artist_id, audios.album_id, audios.trackno");
- if (!query.exec())
- qDebug() << "Cannot run SQL query";
- }
-}
-
-LightMediaScanner::~LightMediaScanner()
-{
- lms.close();
- QSqlDatabase::removeDatabase(lms.connectionName());
-}
-
-bool LightMediaScanner::next(QString& item)
-{
- if (!query.next())
- return false;
-
- item = query.value(0).toString();
-
- return true;
-}
-
-QVariantList LightMediaScanner::processLightMediaScanner()
-{
- QVariantList mediaFiles;
- QString music;
- LightMediaScanner scanner(QDir::homePath() + "/.config/lightmediascannerd/db.sqlite3");
- while (scanner.next(music)) {
- QFileInfo fileInfo(music);
- // Possible for stale entries due to removable media
- if (!fileInfo.exists())
- continue;
- mediaFiles.append(QUrl::fromLocalFile(music));
- }
- return mediaFiles;
-}
diff --git a/app/lightmediascanner.h b/app/lightmediascanner.h
deleted file mode 100644
index 4323457..0000000
--- a/app/lightmediascanner.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2017 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef LIGHTMEDIASCANNER_H
-#define LIGHTMEDIASCANNER_H
-
-#include <QtCore/QDir>
-#include <QtCore/QUrl>
-#include <QtCore/QFileInfo>
-#include <QtCore/QDebug>
-#include <QtCore/QStandardPaths>
-#include <QtCore/QString>
-#include <QtSql/QSqlDatabase>
-#include <QtSql/QSqlRecord>
-#include <QtSql/QSqlQuery>
-
-class LightMediaScanner {
-public:
- LightMediaScanner(const QString& path);
- ~LightMediaScanner();
- bool next(QString& item);
- static QVariantList processLightMediaScanner();
-private:
- QSqlDatabase lms;
- QSqlQuery query;
-};
-
-#endif
diff --git a/app/main.cpp b/app/main.cpp
index 528f840..a5bab67 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -29,10 +29,6 @@
#include <libhomescreen.hpp>
#endif
-#ifdef HAVE_LIGHTMEDIASCANNER
-#include "lightmediascanner.h"
-#endif
-
#ifdef HAVE_DBUS
#include "dbus.h"
#endif
@@ -73,20 +69,19 @@ int main(int argc, char *argv[])
qmlRegisterType<PlaylistWithMetadata>("MediaPlayer", 1, 0, "PlaylistWithMetadata");
- QVariantList mediaFiles;
+ QQmlApplicationEngine engine;
+ QQmlContext *context = engine.rootContext();
-#ifdef HAVE_LIGHTMEDIASCANNER
- mediaFiles = LightMediaScanner::processLightMediaScanner();
-#else
+#ifndef HAVE_LIGHTMEDIASCANNER
+ QVariantList mediaFiles;
QString music;
for (const auto &music : QStandardPaths::standardLocations(QStandardPaths::MusicLocation)) {
mediaFiles.append(readMusicFile(music));
}
-#endif
- QQmlApplicationEngine engine;
- QQmlContext *context = engine.rootContext();
+ context->setContextProperty("mediaFiles", mediaFiles);
+#endif
QCommandLineParser parser;
parser.addPositionalArgument("port", app.translate("main", "port for binding"));
@@ -110,8 +105,6 @@ int main(int argc, char *argv[])
context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
}
- context->setContextProperty("mediaFiles", mediaFiles);
-
#if defined(HAVE_DBUS)
DbusService dbus_service;
context->setContextProperty("dbus", &dbus_service);
@@ -120,10 +113,6 @@ int main(int argc, char *argv[])
engine.load(QUrl(QStringLiteral("qrc:/MediaPlayer.qml")));
#if defined(HAVE_DBUS)
-#if defined(HAVE_LIGHTMEDIASCANNER)
- if (!dbus_service.enableLMS())
- qWarning() << "Cannot run enableLMS";
-#endif
if (!dbus_service.enableBluetooth())
qWarning() << "Cannot run enableBluetooth";
#endif