DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dbusmpris.h
1// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DBUSMPRIS_H
6#define DBUSMPRIS_H
7
8#include <QtCore/QObject>
9#include <QtCore/QByteArray>
10#include <QtCore/QList>
11#include <QtCore/QMap>
12#include <QtCore/QString>
13#include <QtCore/QStringList>
14#include <QtCore/QVariant>
15#include <QtDBus/QtDBus>
16
17/*
18 * Proxy class for interface org.mpris.MediaPlayer2.Player
19 */
20class DBusMPRIS: public QDBusAbstractInterface
21{
22 Q_OBJECT
23
24 Q_SLOT void __propertyChanged__(const QDBusMessage& msg)
25 {
26 QList<QVariant> arguments = msg.arguments();
27 if (3 != arguments.count())
28 return;
29 QString interfaceName = msg.arguments().at(0).toString();
30 if (interfaceName != "org.mpris.MediaPlayer2.Player")
31 return;
32 QVariantMap changedProps = qdbus_cast<QVariantMap>(arguments.at(1).value<QDBusArgument>());
33 Q_FOREACH(const QString &prop, changedProps.keys()) {
34 const QMetaObject* self = metaObject();
35 for (int i=self->propertyOffset(); i < self->propertyCount(); ++i) {
36 QMetaProperty p = self->property(i);
37#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
38 QGenericArgument value(QMetaType::typeName(p.type()), const_cast<void*>(changedProps[prop].constData()));
39#else
40 QGenericArgument value{p.metaType().name(), const_cast<void*>(changedProps[prop].constData())};
41#endif
42 if (p.name() == prop) {
43 Q_EMIT p.notifySignal().invoke(this, value);
44 }
45 }
46 }
47 }
48public:
49 static inline const char *staticInterfaceName()
50 { return "org.mpris.MediaPlayer2.Player"; }
51
52public:
53 DBusMPRIS(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
54
55 ~DBusMPRIS();
56
57 Q_PROPERTY(bool CanControl READ canControl NOTIFY CanControlChanged)
58 inline bool canControl() const
59 { return qvariant_cast< bool >(property("CanControl")); }
60
61 Q_PROPERTY(bool CanShowInUI READ canShowInUI NOTIFY CanShowInUIChanged)
62 inline bool canShowInUI() const
63 {
64 QVariant showInUI = property("CanShowInUI");
65 // 属性有效且为假表示不能控制 无效或为真表示可以控制
66 return showInUI.isValid() ? showInUI.toBool() : true;
67 }
68
69 Q_PROPERTY(bool CanGoNext READ canGoNext NOTIFY CanGoNextChanged)
70 inline bool canGoNext() const
71 { return qvariant_cast< bool >(property("CanGoNext")); }
72
73 Q_PROPERTY(bool CanGoPrevious READ canGoPrevious NOTIFY CanGoPreviousChanged)
74 inline bool canGoPrevious() const
75 { return qvariant_cast< bool >(property("CanGoPrevious")); }
76
77 Q_PROPERTY(bool CanPause READ canPause NOTIFY CanPauseChanged)
78 inline bool canPause() const
79 { return qvariant_cast< bool >(property("CanPause")); }
80
81 Q_PROPERTY(bool CanPlay READ canPlay NOTIFY CanPlayChanged)
82 inline bool canPlay() const
83 { return qvariant_cast< bool >(property("CanPlay")); }
84
85 Q_PROPERTY(bool CanSeek READ canSeek NOTIFY CanSeekChanged)
86 inline bool canSeek() const
87 { return qvariant_cast< bool >(property("CanSeek")); }
88
89 Q_PROPERTY(QString LoopStatus READ loopStatus WRITE setLoopStatus NOTIFY LoopStatusChanged)
90 inline QString loopStatus() const
91 { return qvariant_cast< QString >(property("LoopStatus")); }
92 inline void setLoopStatus(const QString &value)
93 { setProperty("LoopStatus", QVariant::fromValue(value)); }
94
95 Q_PROPERTY(double MaximumRate READ maximumRate NOTIFY MaximumRateChanged)
96 inline double maximumRate() const
97 { return qvariant_cast< double >(property("MaximumRate")); }
98
99 Q_PROPERTY(QVariantMap Metadata READ metadata NOTIFY MetadataChanged)
100 inline QVariantMap metadata() const
101 { return qvariant_cast< QVariantMap >(property("Metadata")); }
102
103 Q_PROPERTY(double MinimumRate READ minimumRate NOTIFY MinimumRateChanged)
104 inline double minimumRate() const
105 { return qvariant_cast< double >(property("MinimumRate")); }
106
107 Q_PROPERTY(QString PlaybackStatus READ playbackStatus NOTIFY PlaybackStatusChanged)
108 inline QString playbackStatus() const
109 { return qvariant_cast< QString >(property("PlaybackStatus")); }
110
111 Q_PROPERTY(qlonglong Position READ position NOTIFY PositionChanged)
112 inline qlonglong position() const
113 { return qvariant_cast< qlonglong >(property("Position")); }
114
115 Q_PROPERTY(double Rate READ rate WRITE setRate NOTIFY RateChanged)
116 inline double rate() const
117 { return qvariant_cast< double >(property("Rate")); }
118 inline void setRate(double value)
119 { setProperty("Rate", QVariant::fromValue(value)); }
120
121 Q_PROPERTY(bool Shuffle READ shuffle WRITE setShuffle NOTIFY ShuffleChanged)
122 inline bool shuffle() const
123 { return qvariant_cast< bool >(property("Shuffle")); }
124 inline void setShuffle(bool value)
125 { setProperty("Shuffle", QVariant::fromValue(value)); }
126
127 Q_PROPERTY(double Volume READ volume WRITE setVolume NOTIFY VolumeChanged)
128 inline double volume() const
129 { return qvariant_cast< double >(property("Volume")); }
130 inline void setVolume(double value)
131 { setProperty("Volume", QVariant::fromValue(value)); }
132
133public Q_SLOTS: // METHODS
134 inline QDBusPendingReply<> Next()
135 {
136 QList<QVariant> argumentList;
137 return asyncCallWithArgumentList(QStringLiteral("Next"), argumentList);
138 }
139
140 inline QDBusPendingReply<> OpenUri(const QString &Uri)
141 {
142 QList<QVariant> argumentList;
143 argumentList << QVariant::fromValue(Uri);
144 return asyncCallWithArgumentList(QStringLiteral("OpenUri"), argumentList);
145 }
146
147 inline QDBusPendingReply<> Pause()
148 {
149 QList<QVariant> argumentList;
150 return asyncCallWithArgumentList(QStringLiteral("Pause"), argumentList);
151 }
152
153 inline QDBusPendingReply<> Play()
154 {
155 QList<QVariant> argumentList;
156 return asyncCallWithArgumentList(QStringLiteral("Play"), argumentList);
157 }
158
159 inline QDBusPendingReply<> PlayPause()
160 {
161 QList<QVariant> argumentList;
162 return asyncCallWithArgumentList(QStringLiteral("PlayPause"), argumentList);
163 }
164
165 inline QDBusPendingReply<> Previous()
166 {
167 QList<QVariant> argumentList;
168 return asyncCallWithArgumentList(QStringLiteral("Previous"), argumentList);
169 }
170
171 inline QDBusPendingReply<> Seek(qlonglong Offset)
172 {
173 QList<QVariant> argumentList;
174 argumentList << QVariant::fromValue(Offset);
175 return asyncCallWithArgumentList(QStringLiteral("Seek"), argumentList);
176 }
177
178 inline QDBusPendingReply<> SetPosition(const QDBusObjectPath &TrackId, qlonglong Position)
179 {
180 QList<QVariant> argumentList;
181 argumentList << QVariant::fromValue(TrackId) << QVariant::fromValue(Position);
182 return asyncCallWithArgumentList(QStringLiteral("SetPosition"), argumentList);
183 }
184
185 inline QDBusPendingReply<> Stop()
186 {
187 QList<QVariant> argumentList;
188 return asyncCallWithArgumentList(QStringLiteral("Stop"), argumentList);
189 }
190
191Q_SIGNALS: // SIGNALS
192 void Seeked(qlonglong Position);
193// begin property changed signals
194void CanControlChanged(bool value);
195void CanShowInUIChanged(bool value);
196void CanGoNextChanged(bool value);
197void CanGoPreviousChanged(bool value);
198void CanPauseChanged(bool value);
199void CanPlayChanged(bool value);
200void CanSeekChanged(bool value);
201void LoopStatusChanged(const QString & value);
202void MaximumRateChanged(double value);
203void MetadataChanged(const QVariantMap & value);
204void MinimumRateChanged(double value);
205void PlaybackStatusChanged(const QString & value);
206void PositionChanged(qlonglong value);
207void RateChanged(double value);
208void ShuffleChanged(bool value);
209void VolumeChanged(double value);
210};
211
212namespace org {
213 namespace mpris {
214 namespace MediaPlayer2 {
215 typedef ::DBusMPRIS Player;
216 }
217 }
218}
219#endif
Definition dbusmpris.h:21