1/*
2 * BluezQt - Asynchronous Bluez wrapper library
3 *
4 * SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "declarativemediaplayer.h"
10
11DeclarativeMediaPlayer::DeclarativeMediaPlayer(BluezQt::MediaPlayerPtr mediaPlayer, QObject *parent)
12 : QObject(parent)
13 , m_mediaPlayer(mediaPlayer)
14{
15 connect(sender: m_mediaPlayer.data(), signal: &BluezQt::MediaPlayer::nameChanged, context: this, slot: &DeclarativeMediaPlayer::nameChanged);
16 connect(sender: m_mediaPlayer.data(), signal: &BluezQt::MediaPlayer::equalizerChanged, context: this, slot: &DeclarativeMediaPlayer::equalizerChanged);
17 connect(sender: m_mediaPlayer.data(), signal: &BluezQt::MediaPlayer::repeatChanged, context: this, slot: &DeclarativeMediaPlayer::repeatChanged);
18 connect(sender: m_mediaPlayer.data(), signal: &BluezQt::MediaPlayer::shuffleChanged, context: this, slot: &DeclarativeMediaPlayer::shuffleChanged);
19 connect(sender: m_mediaPlayer.data(), signal: &BluezQt::MediaPlayer::statusChanged, context: this, slot: &DeclarativeMediaPlayer::statusChanged);
20 connect(sender: m_mediaPlayer.data(), signal: &BluezQt::MediaPlayer::positionChanged, context: this, slot: &DeclarativeMediaPlayer::positionChanged);
21
22 connect(sender: m_mediaPlayer.data(), signal: &BluezQt::MediaPlayer::trackChanged, context: this, slot: [this]() {
23 updateTrack();
24 Q_EMIT trackChanged(track: m_track);
25 });
26
27 updateTrack();
28}
29
30QString DeclarativeMediaPlayer::name() const
31{
32 return m_mediaPlayer->name();
33}
34
35BluezQt::MediaPlayer::Equalizer DeclarativeMediaPlayer::equalizer() const
36{
37 return m_mediaPlayer->equalizer();
38}
39
40void DeclarativeMediaPlayer::setEqualizer(BluezQt::MediaPlayer::Equalizer equalizer)
41{
42 m_mediaPlayer->setEqualizer(equalizer);
43}
44
45BluezQt::MediaPlayer::Repeat DeclarativeMediaPlayer::repeat() const
46{
47 return m_mediaPlayer->repeat();
48}
49
50void DeclarativeMediaPlayer::setRepeat(BluezQt::MediaPlayer::Repeat repeat)
51{
52 m_mediaPlayer->setRepeat(repeat);
53}
54
55BluezQt::MediaPlayer::Shuffle DeclarativeMediaPlayer::shuffle() const
56{
57 return m_mediaPlayer->shuffle();
58}
59
60void DeclarativeMediaPlayer::setShuffle(BluezQt::MediaPlayer::Shuffle shuffle)
61{
62 m_mediaPlayer->setShuffle(shuffle);
63}
64
65BluezQt::MediaPlayer::Status DeclarativeMediaPlayer::status() const
66{
67 return m_mediaPlayer->status();
68}
69
70QJsonObject DeclarativeMediaPlayer::track() const
71{
72 return m_track;
73}
74
75quint32 DeclarativeMediaPlayer::position() const
76{
77 return m_mediaPlayer->position();
78}
79
80BluezQt::PendingCall *DeclarativeMediaPlayer::play()
81{
82 return m_mediaPlayer->play();
83}
84
85BluezQt::PendingCall *DeclarativeMediaPlayer::pause()
86{
87 return m_mediaPlayer->pause();
88}
89
90BluezQt::PendingCall *DeclarativeMediaPlayer::stop()
91{
92 return m_mediaPlayer->stop();
93}
94
95BluezQt::PendingCall *DeclarativeMediaPlayer::next()
96{
97 return m_mediaPlayer->next();
98}
99
100BluezQt::PendingCall *DeclarativeMediaPlayer::previous()
101{
102 return m_mediaPlayer->previous();
103}
104
105BluezQt::PendingCall *DeclarativeMediaPlayer::fastForward()
106{
107 return m_mediaPlayer->fastForward();
108}
109
110BluezQt::PendingCall *DeclarativeMediaPlayer::rewind()
111{
112 return m_mediaPlayer->rewind();
113}
114
115void DeclarativeMediaPlayer::updateTrack()
116{
117 m_track[QStringLiteral("valid")] = m_mediaPlayer->track().isValid();
118 m_track[QStringLiteral("title")] = m_mediaPlayer->track().title();
119 m_track[QStringLiteral("artist")] = m_mediaPlayer->track().artist();
120 m_track[QStringLiteral("album")] = m_mediaPlayer->track().album();
121 m_track[QStringLiteral("genre")] = m_mediaPlayer->track().genre();
122 m_track[QStringLiteral("numberOfTracks")] = qint64(m_mediaPlayer->track().numberOfTracks());
123 m_track[QStringLiteral("trackNumber")] = qint64(m_mediaPlayer->track().trackNumber());
124 m_track[QStringLiteral("duration")] = qint64(m_mediaPlayer->track().duration());
125}
126
127#include "moc_declarativemediaplayer.cpp"
128

source code of bluez-qt/src/imports/declarativemediaplayer.cpp