summaryrefslogtreecommitdiffstats
path: root/app/api/LightMediaScanner.qml
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2017-07-14 17:35:50 -0700
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2017-07-24 21:51:40 +0000
commit71b6e40301a2e23edfeaea5c33187db14c4d8917 (patch)
tree77275d972df9fcb151ed7f00334a8bb738c1d0f8 /app/api/LightMediaScanner.qml
parent213feb8d7c8c1d4ef75fc72df38e598c1ff44458 (diff)
media: binding: improve media removal supportdab_4.0.0dab/4.0.04.0.0
Use glib's inotify support instead of UDisks to get the actual path of an unmounted drive. This in turn allows removal of items on the playlist respective to only that device. Bug-AGL: SPEC-610 SPEC-757 Change-Id: Iaabb004934367bf1e60dab3f9f3365c2eb0b517d Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'app/api/LightMediaScanner.qml')
-rw-r--r--app/api/LightMediaScanner.qml24
1 files changed, 21 insertions, 3 deletions
diff --git a/app/api/LightMediaScanner.qml b/app/api/LightMediaScanner.qml
index d0b7137..cbacb8c 100644
--- a/app/api/LightMediaScanner.qml
+++ b/app/api/LightMediaScanner.qml
@@ -26,6 +26,7 @@ WebSocket {
property string statusString: "waiting..."
property string apiString: "media-manager"
property var verbs: []
+ property var items: []
property string payloadLength: "9999"
readonly property var msgid: {
@@ -35,6 +36,16 @@ WebSocket {
"event": 5
}
+ function validateItem(media) {
+ for (var i = 0; i < media.length; i++) {
+ var item = media[i]
+ if (root.items.indexOf(item) < 0) {
+ playlist.addItem(item)
+ root.items.push(item)
+ }
+ }
+ }
+
onTextMessageReceived: {
var json = JSON.parse(message)
console.debug("Raw response: " + message)
@@ -49,7 +60,7 @@ WebSocket {
var verb = verbs.shift()
if (verb == "media_result") {
console.debug("Media result returned")
- playlist.addItems(response.Media)
+ validateItem(response.Media)
}
break
case msgid.reterr:
@@ -60,11 +71,18 @@ WebSocket {
var event = payload.event
if (event == "media-manager/media_added") {
console.debug("Media is inserted")
- playlist.addItems(json[2].data.Media)
+ validateItem(json[2].data.Media)
} else if (event == "media-manager/media_removed") {
+ var removed = 0
console.debug("Media is removed")
player.stop()
- playlist.clear()
+
+ for (var i = 0; i < root.items.length; i++) {
+ if (root.items[i].startsWith(json[2].data.Path)) {
+ playlist.removeItem(i - removed++)
+ }
+ }
+ root.items = root.items.filter(function (item) { return !item.startsWith(json[2].data.Path) })
}
break
}