Skip to content

Commit cee1f58

Browse files
committed
service/mpris: make lengthSupported bindable and notify for changes
Fixes #109
1 parent 71334bf commit cee1f58

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/services/mpris/player.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ MprisPlayer::MprisPlayer(const QString& address, QObject* parent): QObject(paren
9999
} else return static_cast<qlonglong>(-1);
100100
});
101101

102+
this->bLengthSupported.setBinding([this]() { return this->bInternalLength != -1; });
103+
102104
this->bPlaybackState.setBinding([this]() {
103105
const auto& status = this->bpPlaybackStatus.value();
104106

@@ -258,21 +260,19 @@ void MprisPlayer::setPosition(qlonglong position) {
258260
}
259261

260262
void MprisPlayer::onExportedPositionChanged() {
261-
if (!this->lengthSupported()) emit this->lengthChanged();
263+
if (!this->bLengthSupported) emit this->lengthChanged();
262264
}
263265

264266
void MprisPlayer::onSeek(qlonglong time) { this->setPosition(time); }
265267

266268
qreal MprisPlayer::length() const {
267-
if (this->bInternalLength == -1) {
269+
if (!this->bLengthSupported) {
268270
return this->position(); // unsupported
269271
} else {
270272
return static_cast<qreal>(this->bInternalLength / 1000) / 1000; // NOLINT
271273
}
272274
}
273275

274-
bool MprisPlayer::lengthSupported() const { return this->bInternalLength != -1; }
275-
276276
bool MprisPlayer::volumeSupported() const { return this->pVolume.exists(); }
277277

278278
void MprisPlayer::setVolume(qreal volume) {

src/services/mpris/player.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class MprisPlayer: public QObject {
117117
/// The length of the playing track, as seconds, with millisecond precision,
118118
/// or the value of @@position if @@lengthSupported is false.
119119
Q_PROPERTY(qreal length READ length NOTIFY lengthChanged);
120-
Q_PROPERTY(bool lengthSupported READ lengthSupported NOTIFY lengthSupportedChanged);
120+
Q_PROPERTY(bool lengthSupported READ default NOTIFY lengthSupportedChanged BINDABLE bindableLengthSupported);
121121
/// The volume of the playing track from 0.0 to 1.0, or 1.0 if @@volumeSupported is false.
122122
///
123123
/// May only be written to if @@canControl and @@volumeSupported are true.
@@ -274,7 +274,7 @@ class MprisPlayer: public QObject {
274274
void setPosition(qreal position);
275275

276276
[[nodiscard]] qreal length() const;
277-
[[nodiscard]] bool lengthSupported() const;
277+
[[nodiscard]] QBindable<bool> bindableLengthSupported() const { return &this->bLengthSupported; }
278278

279279
[[nodiscard]] qreal volume() const { return this->bVolume; };
280280
[[nodiscard]] bool volumeSupported() const;
@@ -447,6 +447,7 @@ private slots:
447447
Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, QString, bTrackAlbumArtist, &MprisPlayer::trackAlbumArtistChanged);
448448
Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, QString, bTrackArtUrl, &MprisPlayer::trackArtUrlChanged);
449449
Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, qlonglong, bInternalLength, &MprisPlayer::lengthChanged);
450+
Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, bool, bLengthSupported, &MprisPlayer::lengthSupportedChanged);
450451
Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, bool, bShuffle, &MprisPlayer::shuffleChanged);
451452

452453
QS_DBUS_BINDABLE_PROPERTY_GROUP(MprisPlayer, playerProperties);

0 commit comments

Comments
 (0)