summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2017-07-14 17:35:50 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2017-07-20 17:29:45 -0700
commite799aff439bd86cf4048242069c5a277f48ec396 (patch)
treed4adbef91f5c8bd30483222b5d34a8b71dfdd2ce /app
parent3855968eb0f1ac8214787efe8281902145d79e17 (diff)
media: binding: improve media removal support
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')
-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
}