File indexing completed on 2025-02-16 09:55:07
0001 /* 0002 * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "mediaplayerinterface.h" 0008 #include "objectmanager.h" 0009 0010 #include <QDBusArgument> 0011 #include <QDBusConnection> 0012 0013 // MediaPlayerObject 0014 MediaPlayerObject::MediaPlayerObject(const QDBusObjectPath &path, QObject *parent) 0015 : QObject(parent) 0016 { 0017 QDBusConnection::sessionBus().registerObject(path.path(), this); 0018 } 0019 0020 // MediaPlayerInterface 0021 MediaPlayerInterface::MediaPlayerInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent) 0022 : QDBusAbstractAdaptor(parent) 0023 { 0024 setPath(path); 0025 setObjectParent(parent); 0026 setProperties(properties); 0027 setName(QStringLiteral("org.bluez.MediaPlayer1")); 0028 } 0029 0030 QString MediaPlayerInterface::name() const 0031 { 0032 return Object::property(QStringLiteral("Name")).toString(); 0033 } 0034 0035 QString MediaPlayerInterface::equalizer() const 0036 { 0037 return Object::property(QStringLiteral("Equalizer")).toString(); 0038 } 0039 0040 void MediaPlayerInterface::setEqualizer(const QString &equalizer) 0041 { 0042 Object::changeProperty(QStringLiteral("Equalizer"), equalizer); 0043 } 0044 0045 QString MediaPlayerInterface::repeat() const 0046 { 0047 return Object::property(QStringLiteral("Repeat")).toString(); 0048 } 0049 0050 void MediaPlayerInterface::setRepeat(const QString &repeat) 0051 { 0052 Object::changeProperty(QStringLiteral("Repeat"), repeat); 0053 } 0054 0055 QString MediaPlayerInterface::shuffle() const 0056 { 0057 return Object::property(QStringLiteral("Shuffle")).toString(); 0058 } 0059 0060 void MediaPlayerInterface::setShuffle(const QString &shuffle) 0061 { 0062 Object::changeProperty(QStringLiteral("Shuffle"), shuffle); 0063 } 0064 0065 QString MediaPlayerInterface::status() const 0066 { 0067 return Object::property(QStringLiteral("Status")).toString(); 0068 } 0069 0070 QVariantMap MediaPlayerInterface::track() const 0071 { 0072 return qdbus_cast<QVariantMap>(Object::property(QStringLiteral("Track"))); 0073 } 0074 0075 quint32 MediaPlayerInterface::position() const 0076 { 0077 return Object::property(QStringLiteral("Position")).toUInt(); 0078 } 0079 0080 QDBusObjectPath MediaPlayerInterface::device() const 0081 { 0082 return Object::property(QStringLiteral("Device")).value<QDBusObjectPath>(); 0083 } 0084 0085 void MediaPlayerInterface::Play() 0086 { 0087 Object::changeProperty(QStringLiteral("Status"), QStringLiteral("playing")); 0088 } 0089 0090 void MediaPlayerInterface::Pause() 0091 { 0092 Object::changeProperty(QStringLiteral("Status"), QStringLiteral("paused")); 0093 } 0094 0095 void MediaPlayerInterface::Stop() 0096 { 0097 Object::changeProperty(QStringLiteral("Status"), QStringLiteral("stopped")); 0098 } 0099 0100 void MediaPlayerInterface::Next() 0101 { 0102 QVariantMap t = track(); 0103 t[QStringLiteral("Title")] = QVariant(t[QStringLiteral("Title")].toString() + QLatin1String("_next")); 0104 t[QStringLiteral("TrackNumber")] = t[QStringLiteral("TrackNumber")].toUInt() + 1; 0105 0106 Object::changeProperty(QStringLiteral("Track"), t); 0107 } 0108 0109 void MediaPlayerInterface::Previous() 0110 { 0111 QVariantMap t = track(); 0112 t[QStringLiteral("Title")] = QVariant(t[QStringLiteral("Title")].toString() + QLatin1String("_prev")); 0113 t[QStringLiteral("TrackNumber")] = t[QStringLiteral("TrackNumber")].toUInt() - 1; 0114 0115 Object::changeProperty(QStringLiteral("Track"), t); 0116 } 0117 0118 void MediaPlayerInterface::FastForward() 0119 { 0120 Object::changeProperty(QStringLiteral("Status"), QStringLiteral("forward-seek")); 0121 } 0122 0123 void MediaPlayerInterface::Rewind() 0124 { 0125 Object::changeProperty(QStringLiteral("Status"), QStringLiteral("reverse-seek")); 0126 } 0127 0128 #include "moc_mediaplayerinterface.cpp"