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 "mediaplayer.h" |
10 | #include "mediaplayer_p.h" |
11 | #include "pendingcall.h" |
12 | |
13 | namespace BluezQt |
14 | { |
15 | static QString equalizerToString(MediaPlayer::Equalizer equalizer) |
16 | { |
17 | switch (equalizer) { |
18 | case MediaPlayer::EqualizerOn: |
19 | return QStringLiteral("on" ); |
20 | default: |
21 | return QStringLiteral("off" ); |
22 | } |
23 | } |
24 | |
25 | static QString repeatToString(MediaPlayer::Repeat repeat) |
26 | { |
27 | switch (repeat) { |
28 | case MediaPlayer::RepeatSingleTrack: |
29 | return QStringLiteral("singletrack" ); |
30 | case MediaPlayer::RepeatAllTracks: |
31 | return QStringLiteral("alltracks" ); |
32 | case MediaPlayer::RepeatGroup: |
33 | return QStringLiteral("group" ); |
34 | default: |
35 | return QStringLiteral("off" ); |
36 | } |
37 | } |
38 | |
39 | static QString shuffleToString(MediaPlayer::Shuffle shuffle) |
40 | { |
41 | switch (shuffle) { |
42 | case MediaPlayer::ShuffleAllTracks: |
43 | return QStringLiteral("alltracks" ); |
44 | case MediaPlayer::ShuffleGroup: |
45 | return QStringLiteral("group" ); |
46 | default: |
47 | return QStringLiteral("off" ); |
48 | } |
49 | } |
50 | |
51 | MediaPlayer::MediaPlayer(const QString &path, const QVariantMap &properties) |
52 | : QObject() |
53 | , d(new MediaPlayerPrivate(path, properties)) |
54 | { |
55 | } |
56 | |
57 | MediaPlayer::~MediaPlayer() = default; |
58 | |
59 | MediaPlayerPtr MediaPlayer::toSharedPtr() const |
60 | { |
61 | return d->q.toStrongRef(); |
62 | } |
63 | |
64 | QString MediaPlayer::name() const |
65 | { |
66 | return d->m_name; |
67 | } |
68 | |
69 | MediaPlayer::Equalizer MediaPlayer::equalizer() const |
70 | { |
71 | return d->m_equalizer; |
72 | } |
73 | |
74 | PendingCall *MediaPlayer::setEqualizer(MediaPlayer::Equalizer equalizer) |
75 | { |
76 | return new PendingCall(d->setDBusProperty(QStringLiteral("Equalizer" ), value: equalizerToString(equalizer)), PendingCall::ReturnVoid, this); |
77 | } |
78 | |
79 | MediaPlayer::Repeat MediaPlayer::repeat() const |
80 | { |
81 | return d->m_repeat; |
82 | } |
83 | |
84 | PendingCall *MediaPlayer::setRepeat(MediaPlayer::Repeat repeat) |
85 | { |
86 | return new PendingCall(d->setDBusProperty(QStringLiteral("Repeat" ), value: repeatToString(repeat)), PendingCall::ReturnVoid, this); |
87 | } |
88 | |
89 | MediaPlayer::Shuffle MediaPlayer::shuffle() const |
90 | { |
91 | return d->m_shuffle; |
92 | } |
93 | |
94 | PendingCall *MediaPlayer::setShuffle(MediaPlayer::Shuffle shuffle) |
95 | { |
96 | return new PendingCall(d->setDBusProperty(QStringLiteral("Shuffle" ), value: shuffleToString(shuffle)), PendingCall::ReturnVoid, this); |
97 | } |
98 | |
99 | MediaPlayer::Status MediaPlayer::status() const |
100 | { |
101 | return d->m_status; |
102 | } |
103 | |
104 | MediaPlayerTrack MediaPlayer::track() const |
105 | { |
106 | return d->m_track; |
107 | } |
108 | |
109 | quint32 MediaPlayer::position() const |
110 | { |
111 | return d->m_position; |
112 | } |
113 | |
114 | PendingCall *MediaPlayer::play() |
115 | { |
116 | return new PendingCall(d->m_bluezMediaPlayer->Play(), PendingCall::ReturnVoid, this); |
117 | } |
118 | |
119 | PendingCall *MediaPlayer::pause() |
120 | { |
121 | return new PendingCall(d->m_bluezMediaPlayer->Pause(), PendingCall::ReturnVoid, this); |
122 | } |
123 | |
124 | PendingCall *MediaPlayer::stop() |
125 | { |
126 | return new PendingCall(d->m_bluezMediaPlayer->Stop(), PendingCall::ReturnVoid, this); |
127 | } |
128 | |
129 | PendingCall *MediaPlayer::next() |
130 | { |
131 | return new PendingCall(d->m_bluezMediaPlayer->Next(), PendingCall::ReturnVoid, this); |
132 | } |
133 | |
134 | PendingCall *MediaPlayer::previous() |
135 | { |
136 | return new PendingCall(d->m_bluezMediaPlayer->Previous(), PendingCall::ReturnVoid, this); |
137 | } |
138 | |
139 | PendingCall *MediaPlayer::fastForward() |
140 | { |
141 | return new PendingCall(d->m_bluezMediaPlayer->FastForward(), PendingCall::ReturnVoid, this); |
142 | } |
143 | |
144 | PendingCall *MediaPlayer::rewind() |
145 | { |
146 | return new PendingCall(d->m_bluezMediaPlayer->Rewind(), PendingCall::ReturnVoid, this); |
147 | } |
148 | |
149 | } // namespace BluezQt |
150 | |
151 | #include "moc_mediaplayer.cpp" |
152 | |