File indexing completed on 2024-12-01 12:29:49

0001 /*
0002  * BluezQt - Asynchronous Bluez wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #include "mediaplayer.h"
0010 #include "mediaplayer_p.h"
0011 #include "pendingcall.h"
0012 
0013 namespace BluezQt
0014 {
0015 static QString equalizerToString(MediaPlayer::Equalizer equalizer)
0016 {
0017     switch (equalizer) {
0018     case MediaPlayer::EqualizerOn:
0019         return QStringLiteral("on");
0020     default:
0021         return QStringLiteral("off");
0022     }
0023 }
0024 
0025 static QString repeatToString(MediaPlayer::Repeat repeat)
0026 {
0027     switch (repeat) {
0028     case MediaPlayer::RepeatSingleTrack:
0029         return QStringLiteral("singletrack");
0030     case MediaPlayer::RepeatAllTracks:
0031         return QStringLiteral("alltracks");
0032     case MediaPlayer::RepeatGroup:
0033         return QStringLiteral("group");
0034     default:
0035         return QStringLiteral("off");
0036     }
0037 }
0038 
0039 static QString shuffleToString(MediaPlayer::Shuffle shuffle)
0040 {
0041     switch (shuffle) {
0042     case MediaPlayer::ShuffleAllTracks:
0043         return QStringLiteral("alltracks");
0044     case MediaPlayer::ShuffleGroup:
0045         return QStringLiteral("group");
0046     default:
0047         return QStringLiteral("off");
0048     }
0049 }
0050 
0051 MediaPlayer::MediaPlayer(const QString &path, const QVariantMap &properties)
0052     : QObject()
0053     , d(new MediaPlayerPrivate(path, properties))
0054 {
0055 }
0056 
0057 MediaPlayer::~MediaPlayer()
0058 {
0059     delete d;
0060 }
0061 
0062 MediaPlayerPtr MediaPlayer::toSharedPtr() const
0063 {
0064     return d->q.toStrongRef();
0065 }
0066 
0067 QString MediaPlayer::name() const
0068 {
0069     return d->m_name;
0070 }
0071 
0072 MediaPlayer::Equalizer MediaPlayer::equalizer() const
0073 {
0074     return d->m_equalizer;
0075 }
0076 
0077 PendingCall *MediaPlayer::setEqualizer(MediaPlayer::Equalizer equalizer)
0078 {
0079     return new PendingCall(d->setDBusProperty(QStringLiteral("Equalizer"), equalizerToString(equalizer)), PendingCall::ReturnVoid, this);
0080 }
0081 
0082 MediaPlayer::Repeat MediaPlayer::repeat() const
0083 {
0084     return d->m_repeat;
0085 }
0086 
0087 PendingCall *MediaPlayer::setRepeat(MediaPlayer::Repeat repeat)
0088 {
0089     return new PendingCall(d->setDBusProperty(QStringLiteral("Repeat"), repeatToString(repeat)), PendingCall::ReturnVoid, this);
0090 }
0091 
0092 MediaPlayer::Shuffle MediaPlayer::shuffle() const
0093 {
0094     return d->m_shuffle;
0095 }
0096 
0097 PendingCall *MediaPlayer::setShuffle(MediaPlayer::Shuffle shuffle)
0098 {
0099     return new PendingCall(d->setDBusProperty(QStringLiteral("Shuffle"), shuffleToString(shuffle)), PendingCall::ReturnVoid, this);
0100 }
0101 
0102 MediaPlayer::Status MediaPlayer::status() const
0103 {
0104     return d->m_status;
0105 }
0106 
0107 MediaPlayerTrack MediaPlayer::track() const
0108 {
0109     return d->m_track;
0110 }
0111 
0112 quint32 MediaPlayer::position() const
0113 {
0114     return d->m_position;
0115 }
0116 
0117 PendingCall *MediaPlayer::play()
0118 {
0119     return new PendingCall(d->m_bluezMediaPlayer->Play(), PendingCall::ReturnVoid, this);
0120 }
0121 
0122 PendingCall *MediaPlayer::pause()
0123 {
0124     return new PendingCall(d->m_bluezMediaPlayer->Pause(), PendingCall::ReturnVoid, this);
0125 }
0126 
0127 PendingCall *MediaPlayer::stop()
0128 {
0129     return new PendingCall(d->m_bluezMediaPlayer->Stop(), PendingCall::ReturnVoid, this);
0130 }
0131 
0132 PendingCall *MediaPlayer::next()
0133 {
0134     return new PendingCall(d->m_bluezMediaPlayer->Next(), PendingCall::ReturnVoid, this);
0135 }
0136 
0137 PendingCall *MediaPlayer::previous()
0138 {
0139     return new PendingCall(d->m_bluezMediaPlayer->Previous(), PendingCall::ReturnVoid, this);
0140 }
0141 
0142 PendingCall *MediaPlayer::fastForward()
0143 {
0144     return new PendingCall(d->m_bluezMediaPlayer->FastForward(), PendingCall::ReturnVoid, this);
0145 }
0146 
0147 PendingCall *MediaPlayer::rewind()
0148 {
0149     return new PendingCall(d->m_bluezMediaPlayer->Rewind(), PendingCall::ReturnVoid, this);
0150 }
0151 
0152 } // namespace BluezQt
0153 
0154 #include "moc_mediaplayer.cpp"