forked from quickshell/quickshell
		
	service/mpris: make lengthSupported bindable and notify for changes
Fixes #109
This commit is contained in:
		
							parent
							
								
									71334bfcaf
								
							
						
					
					
						commit
						cee1f5837e
					
				
					 2 changed files with 7 additions and 6 deletions
				
			
		| 
						 | 
					@ -99,6 +99,8 @@ MprisPlayer::MprisPlayer(const QString& address, QObject* parent): QObject(paren
 | 
				
			||||||
		} else return static_cast<qlonglong>(-1);
 | 
							} else return static_cast<qlonglong>(-1);
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						this->bLengthSupported.setBinding([this]() { return this->bInternalLength != -1; });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this->bPlaybackState.setBinding([this]() {
 | 
						this->bPlaybackState.setBinding([this]() {
 | 
				
			||||||
		const auto& status = this->bpPlaybackStatus.value();
 | 
							const auto& status = this->bpPlaybackStatus.value();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -258,21 +260,19 @@ void MprisPlayer::setPosition(qlonglong position) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MprisPlayer::onExportedPositionChanged() {
 | 
					void MprisPlayer::onExportedPositionChanged() {
 | 
				
			||||||
	if (!this->lengthSupported()) emit this->lengthChanged();
 | 
						if (!this->bLengthSupported) emit this->lengthChanged();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MprisPlayer::onSeek(qlonglong time) { this->setPosition(time); }
 | 
					void MprisPlayer::onSeek(qlonglong time) { this->setPosition(time); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
qreal MprisPlayer::length() const {
 | 
					qreal MprisPlayer::length() const {
 | 
				
			||||||
	if (this->bInternalLength == -1) {
 | 
						if (!this->bLengthSupported) {
 | 
				
			||||||
		return this->position(); // unsupported
 | 
							return this->position(); // unsupported
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return static_cast<qreal>(this->bInternalLength / 1000) / 1000; // NOLINT
 | 
							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(); }
 | 
					bool MprisPlayer::volumeSupported() const { return this->pVolume.exists(); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MprisPlayer::setVolume(qreal volume) {
 | 
					void MprisPlayer::setVolume(qreal volume) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -117,7 +117,7 @@ class MprisPlayer: public QObject {
 | 
				
			||||||
	/// The length of the playing track, as seconds, with millisecond precision,
 | 
						/// The length of the playing track, as seconds, with millisecond precision,
 | 
				
			||||||
	/// or the value of @@position if @@lengthSupported is false.
 | 
						/// or the value of @@position if @@lengthSupported is false.
 | 
				
			||||||
	Q_PROPERTY(qreal length READ length NOTIFY lengthChanged);
 | 
						Q_PROPERTY(qreal length READ length NOTIFY lengthChanged);
 | 
				
			||||||
	Q_PROPERTY(bool lengthSupported READ lengthSupported NOTIFY lengthSupportedChanged);
 | 
						Q_PROPERTY(bool lengthSupported READ default NOTIFY lengthSupportedChanged BINDABLE bindableLengthSupported);
 | 
				
			||||||
	/// The volume of the playing track from 0.0 to 1.0, or 1.0 if @@volumeSupported is false.
 | 
						/// The volume of the playing track from 0.0 to 1.0, or 1.0 if @@volumeSupported is false.
 | 
				
			||||||
	///
 | 
						///
 | 
				
			||||||
	/// May only be written to if @@canControl and @@volumeSupported are true.
 | 
						/// May only be written to if @@canControl and @@volumeSupported are true.
 | 
				
			||||||
| 
						 | 
					@ -274,7 +274,7 @@ public:
 | 
				
			||||||
	void setPosition(qreal position);
 | 
						void setPosition(qreal position);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[[nodiscard]] qreal length() const;
 | 
						[[nodiscard]] qreal length() const;
 | 
				
			||||||
	[[nodiscard]] bool lengthSupported() const;
 | 
						[[nodiscard]] QBindable<bool> bindableLengthSupported() const { return &this->bLengthSupported; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[[nodiscard]] qreal volume() const { return this->bVolume; };
 | 
						[[nodiscard]] qreal volume() const { return this->bVolume; };
 | 
				
			||||||
	[[nodiscard]] bool volumeSupported() const;
 | 
						[[nodiscard]] bool volumeSupported() const;
 | 
				
			||||||
| 
						 | 
					@ -447,6 +447,7 @@ private:
 | 
				
			||||||
	Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, QString, bTrackAlbumArtist, &MprisPlayer::trackAlbumArtistChanged);
 | 
						Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, QString, bTrackAlbumArtist, &MprisPlayer::trackAlbumArtistChanged);
 | 
				
			||||||
	Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, QString, bTrackArtUrl, &MprisPlayer::trackArtUrlChanged);
 | 
						Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, QString, bTrackArtUrl, &MprisPlayer::trackArtUrlChanged);
 | 
				
			||||||
	Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, qlonglong, bInternalLength, &MprisPlayer::lengthChanged);
 | 
						Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, qlonglong, bInternalLength, &MprisPlayer::lengthChanged);
 | 
				
			||||||
 | 
						Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, bool, bLengthSupported, &MprisPlayer::lengthSupportedChanged);
 | 
				
			||||||
	Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, bool, bShuffle, &MprisPlayer::shuffleChanged);
 | 
						Q_OBJECT_BINDABLE_PROPERTY(MprisPlayer, bool, bShuffle, &MprisPlayer::shuffleChanged);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QS_DBUS_BINDABLE_PROPERTY_GROUP(MprisPlayer, playerProperties);
 | 
						QS_DBUS_BINDABLE_PROPERTY_GROUP(MprisPlayer, playerProperties);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue