service/mpris: make lengthSupported bindable and notify for changes

Fixes #109
This commit is contained in:
outfoxxed 2025-07-13 20:32:51 -07:00
parent 71334bfcaf
commit cee1f5837e
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
2 changed files with 7 additions and 6 deletions

View file

@ -99,6 +99,8 @@ MprisPlayer::MprisPlayer(const QString& address, QObject* parent): QObject(paren
} else return static_cast<qlonglong>(-1);
});
this->bLengthSupported.setBinding([this]() { return this->bInternalLength != -1; });
this->bPlaybackState.setBinding([this]() {
const auto& status = this->bpPlaybackStatus.value();
@ -258,21 +260,19 @@ void MprisPlayer::setPosition(qlonglong position) {
}
void MprisPlayer::onExportedPositionChanged() {
if (!this->lengthSupported()) emit this->lengthChanged();
if (!this->bLengthSupported) emit this->lengthChanged();
}
void MprisPlayer::onSeek(qlonglong time) { this->setPosition(time); }
qreal MprisPlayer::length() const {
if (this->bInternalLength == -1) {
if (!this->bLengthSupported) {
return this->position(); // unsupported
} else {
return static_cast<qreal>(this->bInternalLength / 1000) / 1000; // NOLINT
}
}
bool MprisPlayer::lengthSupported() const { return this->bInternalLength != -1; }
bool MprisPlayer::volumeSupported() const { return this->pVolume.exists(); }
void MprisPlayer::setVolume(qreal volume) {