summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/MediaPlayer.qml6
-rw-r--r--app/api/LightMediaScanner.qml82
-rw-r--r--app/main.cpp25
-rw-r--r--app/mediaplayer.qrc1
4 files changed, 114 insertions, 0 deletions
diff --git a/app/MediaPlayer.qml b/app/MediaPlayer.qml
index 4a29d95..95af8c0 100644
--- a/app/MediaPlayer.qml
+++ b/app/MediaPlayer.qml
@@ -20,6 +20,7 @@ import QtQuick.Controls 2.0
import QtMultimedia 5.6
import AGL.Demo.Controls 1.0
import MediaPlayer 1.0
+import 'api' as API
ApplicationWindow {
id: root
@@ -45,6 +46,11 @@ ApplicationWindow {
}
}
+ API.LightMediaScanner {
+ id: binding
+ url: bindingAddress
+ }
+
Connections {
target: dbus
diff --git a/app/api/LightMediaScanner.qml b/app/api/LightMediaScanner.qml
new file mode 100644
index 0000000..1fe2f25
--- /dev/null
+++ b/app/api/LightMediaScanner.qml
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2016 The Qt Company Ltd.
+ * 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.
+ */
+
+import QtQuick 2.6
+import QtWebSockets 1.0
+
+WebSocket {
+ id: root
+ active: true
+ url: bindingAddress
+
+ property string statusString: "waiting..."
+ property string apiString: "media-manager"
+ property var verbs: []
+ property string payloadLength: "9999"
+
+ readonly property var msgid: {
+ "call": 2,
+ "retok": 3,
+ "reterr": 4,
+ "event": 5
+ }
+
+ onTextMessageReceived: {
+ var json = JSON.parse(message)
+ console.debug("Raw response: " + message)
+ var request = json[2].request
+ var response = json[2].response
+ console.debug("response: " + JSON.stringify(response))
+ switch (json[0]) {
+ case msgid.call:
+ 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
+ case msgid.reterr:
+ root.statusString = "Bad return value, binding probably not installed"
+ break
+ case msgid.event:
+ break
+ }
+ }
+
+ onStatusChanged: {
+ switch (status) {
+ case WebSocket.Open:
+ console.debug("onStatusChanged: Open")
+ break
+ case WebSocket.Error:
+ root.statusString = "WebSocket error: " + root.errorString
+ break
+ }
+ }
+
+ function sendSocketMessage(verb, parameter) {
+ var requestJson = [ msgid.call, payloadLength, apiString + '/'
+ + verb, parameter ]
+ console.debug("sendSocketMessage: " + JSON.stringify(requestJson))
+ verbs.push(verb)
+ sendTextMessage(JSON.stringify(requestJson))
+ }
+}
diff --git a/app/main.cpp b/app/main.cpp
index 8ad7b7f..528f840 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -14,9 +14,11 @@
* limitations under the License.
*/
+#include <QtCore/QCommandLineParser>
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QStandardPaths>
+#include <QtCore/QUrlQuery>
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
#include <QtQml/QQmlContext>
@@ -85,6 +87,29 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine;
QQmlContext *context = engine.rootContext();
+
+ QCommandLineParser parser;
+ parser.addPositionalArgument("port", app.translate("main", "port for binding"));
+ parser.addPositionalArgument("secret", app.translate("main", "secret for binding"));
+ parser.addHelpOption();
+ parser.addVersionOption();
+ parser.process(app);
+ QStringList positionalArguments = parser.positionalArguments();
+
+ if (positionalArguments.length() == 2) {
+ int port = positionalArguments.takeFirst().toInt();
+ QString secret = positionalArguments.takeFirst();
+ QUrl bindingAddress;
+ bindingAddress.setScheme(QStringLiteral("ws"));
+ bindingAddress.setHost(QStringLiteral("localhost"));
+ bindingAddress.setPort(port);
+ bindingAddress.setPath(QStringLiteral("/api"));
+ QUrlQuery query;
+ query.addQueryItem(QStringLiteral("token"), secret);
+ bindingAddress.setQuery(query);
+ context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
+ }
+
context->setContextProperty("mediaFiles", mediaFiles);
#if defined(HAVE_DBUS)
diff --git a/app/mediaplayer.qrc b/app/mediaplayer.qrc
index d3fa02e..22b52e1 100644
--- a/app/mediaplayer.qrc
+++ b/app/mediaplayer.qrc
@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>MediaPlayer.qml</file>
+ <file>api/LightMediaScanner.qml</file>
</qresource>
</RCC>