summaryrefslogtreecommitdiffstats
path: root/mediaplayer/mediaplayer.cpp
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2018-06-29 12:01:11 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2018-06-29 19:17:30 -0700
commit87db6cfd047e2c1d247dbfb45cad8b03e5dd6248 (patch)
treea8d1c1b00a323f470dc34709aaf3058611455f8e /mediaplayer/mediaplayer.cpp
parent058f4d47801b968cc237066d9dec4ff21edb4b0a (diff)
libqtappfw: mediaplayer: change from JSON objects to proper Qt model
Switch to using proper Qt model versus JSON objects being passed to QML Bug-AGL: SPEC-1430 Change-Id: Ic07a355fee3292d113bc62bee9acb0764a0a5458 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'mediaplayer/mediaplayer.cpp')
-rw-r--r--mediaplayer/mediaplayer.cpp35
1 files changed, 33 insertions, 2 deletions
diff --git a/mediaplayer/mediaplayer.cpp b/mediaplayer/mediaplayer.cpp
index 5755f37..384badf 100644
--- a/mediaplayer/mediaplayer.cpp
+++ b/mediaplayer/mediaplayer.cpp
@@ -19,11 +19,26 @@
#include "mediaplayer.h"
#include "mediaplayermessage.h"
-Mediaplayer::Mediaplayer (QUrl &url, QObject * parent) :
+Playlist::Playlist(QVariantMap &item)
+{
+ m_index = item["index"].toInt();
+ m_duration = item["duration"].toInt();
+ m_genre = item["genre"].toString();
+ m_path = item["path"].toString();
+ m_title = item["title"].toString();
+ m_album = item["album"].toString();
+ m_artist = item["artist"].toString();
+}
+
+Playlist::~Playlist() {}
+
+Mediaplayer::Mediaplayer (QUrl &url, QQmlContext *context, QObject * parent) :
QObject(parent),
m_mloop(nullptr)
{
m_mloop = new MessageEngine(url);
+ m_context = context;
+ m_context->setContextProperty("MediaplayerModel", QVariant::fromValue(m_playlist));
QObject::connect(m_mloop, &MessageEngine::connected, this, &Mediaplayer::onConnected);
QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Mediaplayer::onDisconnected);
QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Mediaplayer::onMessageReceived);
@@ -34,6 +49,22 @@ Mediaplayer::~Mediaplayer()
delete m_mloop;
}
+// Qt UI Context
+
+void Mediaplayer::updatePlaylist(QVariantMap playlist)
+{
+ QVariantList list = playlist["list"].toList();
+
+ m_playlist.clear();
+
+ for (auto i : list) {
+ QVariantMap item = qvariant_cast<QVariantMap>(i);
+ m_playlist.append(new Playlist(item));
+ }
+
+ // Refresh model
+ m_context->setContextProperty("MediaplayerModel", QVariant::fromValue(m_playlist));
+}
// Control Verb methods
@@ -161,7 +192,7 @@ void Mediaplayer::onMessageReceived(MessageType type, Message *message)
if (tmsg->isEvent()) {
if (tmsg->isPlaylistEvent()) {
- emit playlistChanged(tmsg->eventData().toVariantMap());
+ updatePlaylist(tmsg->eventData().toVariantMap());
} else if (tmsg->isMetadataEvent()) {
emit metadataChanged(tmsg->eventData().toVariantMap());
}