Debian Codegraph @

autotests/fakebluez/mediaplayerinterface.cpp

raw
1 /*
2 * SPDX-FileCopyrightText: 2014-2015 David Rosca <[email protected]>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6
7 #include "mediaplayerinterface.h"
8 #include "objectmanager.h"
9
10 #include <QDBusArgument>
11 #include <QDBusConnection>
12
13 // MediaPlayerObject
14 MediaPlayerObject::MediaPlayerObject(const QDBusObjectPath &path, QObject *parent)
15 : QObject(parent)
16 {
17 QDBusConnection::sessionBus().registerObject(path.path(), this);
18 }
19
20 // MediaPlayerInterface
21 MediaPlayerInterface::MediaPlayerInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent)
22 : QDBusAbstractAdaptor(parent)
23 {
24 setPath(path);
25 setObjectParent(parent);
26 setProperties(properties);
27 setName(QStringLiteral("org.bluez.MediaPlayer1"));
28 }
29
30 QString MediaPlayerInterface::name() const
31 {
32 return Object::property(QStringLiteral("Name")).toString();
33 }
34
35 QString MediaPlayerInterface::equalizer() const
36 {
37 return Object::property(QStringLiteral("Equalizer")).toString();
38 }
39
40 void MediaPlayerInterface::setEqualizer(const QString &equalizer)
41 {
42 Object::changeProperty(QStringLiteral("Equalizer"), equalizer);
43 }
44
45 QString MediaPlayerInterface::repeat() const
46 {
47 return Object::property(QStringLiteral("Repeat")).toString();
48 }
49
50 void MediaPlayerInterface::setRepeat(const QString &repeat)
51 {
52 Object::changeProperty(QStringLiteral("Repeat"), repeat);
53 }
54
55 QString MediaPlayerInterface::shuffle() const
56 {
57 return Object::property(QStringLiteral("Shuffle")).toString();
58 }
59
60 void MediaPlayerInterface::setShuffle(const QString &shuffle)
61 {
62 Object::changeProperty(QStringLiteral("Shuffle"), shuffle);
63 }
64
65 QString MediaPlayerInterface::status() const
66 {
67 return Object::property(QStringLiteral("Status")).toString();
68 }
69
70 QVariantMap MediaPlayerInterface::track() const
71 {
72 return qdbus_cast<QVariantMap>(Object::property(QStringLiteral("Track")));
73 }
74
75 quint32 MediaPlayerInterface::position() const
76 {
77 return Object::property(QStringLiteral("Position")).toUInt();
78 }
79
80 QDBusObjectPath MediaPlayerInterface::device() const
81 {
82 return Object::property(QStringLiteral("Device")).value<QDBusObjectPath>();
83 }
84
85 void MediaPlayerInterface::Play()
86 {
87 Object::changeProperty(QStringLiteral("Status"), QStringLiteral("playing"));
88 }
89
90 void MediaPlayerInterface::Pause()
91 {
92 Object::changeProperty(QStringLiteral("Status"), QStringLiteral("paused"));
93 }
94
95 void MediaPlayerInterface::Stop()
96 {
97 Object::changeProperty(QStringLiteral("Status"), QStringLiteral("stopped"));
98 }
99
100 void MediaPlayerInterface::Next()
101 {
102 QVariantMap t = track();
103 t[QStringLiteral("Title")] = QVariant(t[QStringLiteral("Title")].toString() + QLatin1String("_next"));
104 t[QStringLiteral("TrackNumber")] = t[QStringLiteral("TrackNumber")].toUInt() + 1;
105
106 Object::changeProperty(QStringLiteral("Track"), t);
107 }
108
109 void MediaPlayerInterface::Previous()
110 {
111 QVariantMap t = track();
112 t[QStringLiteral("Title")] = QVariant(t[QStringLiteral("Title")].toString() + QLatin1String("_prev"));
113 t[QStringLiteral("TrackNumber")] = t[QStringLiteral("TrackNumber")].toUInt() - 1;
114
115 Object::changeProperty(QStringLiteral("Track"), t);
116 }
117
118 void MediaPlayerInterface::FastForward()
119 {
120 Object::changeProperty(QStringLiteral("Status"), QStringLiteral("forward-seek"));
121 }
122
123 void MediaPlayerInterface::Rewind()
124 {
125 Object::changeProperty(QStringLiteral("Status"), QStringLiteral("reverse-seek"));
126 }
127
128 #include "moc_mediaplayerinterface.cpp"