Remove mpris "nowPlaying" field
We've had separate title & artist for a while, and all clients should be using those by now. Also fixes the position change not being emitted when the song changes, and fixes the values being written after emitting that they changed.
This commit is contained in:
parent
3cb40eab61
commit
2e0550651e
10 changed files with 26 additions and 74 deletions
|
@ -17,8 +17,11 @@ Loader {
|
|||
sourceComponent: plugin.canSeek ? seekBar : progressBar
|
||||
|
||||
onLastPositionChanged: {
|
||||
if (item != null) {
|
||||
item.value = lastPosition
|
||||
lastPositionTime = new Date();
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: seekBar
|
||||
|
@ -54,11 +57,4 @@ Loader {
|
|||
|
||||
onTriggered: item.value = lastPosition + (new Date().getTime() - lastPositionTime.getTime())
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: plugin
|
||||
function onNowPlayingChanged() {
|
||||
item.value = lastPosition
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,36 +78,28 @@ Kirigami.Page
|
|||
model: root.pluginInterface.playerList
|
||||
onCurrentTextChanged: root.pluginInterface.player = currentText
|
||||
}
|
||||
Label {
|
||||
id: nowPlaying
|
||||
Layout.fillWidth: true
|
||||
text: root.pluginInterface.nowPlaying
|
||||
visible: root.pluginInterface.title.length == 0
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: root.pluginInterface.title
|
||||
visible: !nowPlaying.visible
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: root.pluginInterface.artist
|
||||
visible: !nowPlaying.visible && !artistAlbum.visible && root.pluginInterface.artist.length > 0
|
||||
visible: !artistAlbum.visible && root.pluginInterface.artist.length > 0
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: root.pluginInterface.album
|
||||
visible: !nowPlaying.visible && !artistAlbum.visible && root.pluginInterface.album.length > 0
|
||||
visible: !artistAlbum.visible && root.pluginInterface.album.length > 0
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
Label {
|
||||
id: artistAlbum
|
||||
Layout.fillWidth: true
|
||||
text: i18nd("kdeconnect-app", "%1 - %2", root.pluginInterface.artist, root.pluginInterface.album)
|
||||
visible: !nowPlaying.visible && root.pluginInterface.album.length > 0 && root.pluginInterface.artist.length > 0
|
||||
visible: root.pluginInterface.album.length > 0 && root.pluginInterface.artist.length > 0
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
RowLayout {
|
||||
|
|
|
@ -152,7 +152,6 @@ class KDECONNECTINTERFACES_EXPORT MprisDbusInterface : public OrgKdeKdeconnectDe
|
|||
// the signals for the properties
|
||||
Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY propertiesChangedProxy)
|
||||
Q_PROPERTY(int length READ length NOTIFY propertiesChangedProxy)
|
||||
Q_PROPERTY(QString nowPlaying READ nowPlaying NOTIFY propertiesChangedProxy)
|
||||
Q_PROPERTY(QString title READ title NOTIFY propertiesChangedProxy)
|
||||
Q_PROPERTY(QString artist READ artist NOTIFY propertiesChangedProxy)
|
||||
Q_PROPERTY(QString album READ album NOTIFY propertiesChangedProxy)
|
||||
|
|
|
@ -71,10 +71,6 @@ void MprisControlPlugin::sendMediaProperties(std::variant<NetworkPacket, QString
|
|||
np.set(QStringLiteral("artist"), QString::fromWCharArray(mediaProperties.Artist().c_str()));
|
||||
np.set(QStringLiteral("album"), QString::fromWCharArray(mediaProperties.AlbumTitle().c_str()));
|
||||
np.set(QStringLiteral("albumArtUrl"), randomUrl());
|
||||
np.set(QStringLiteral("nowPlaying"),
|
||||
mediaProperties.Artist().empty() ? QString::fromWCharArray(mediaProperties.Title().c_str())
|
||||
: (QString::fromWCharArray(mediaProperties.Artist().c_str()) + QStringLiteral(" - ")
|
||||
+ QString::fromWCharArray(mediaProperties.Title().c_str())));
|
||||
|
||||
np.set(QStringLiteral("url"), QString());
|
||||
sendTimelineProperties(np, player, true); // "length"
|
||||
|
|
|
@ -183,15 +183,13 @@ void MprisControlPlugin::propertiesChanged(const QString &propertyInterface, con
|
|||
np.set(QStringLiteral("canGoPrevious"), properties[QStringLiteral("CanGoPrevious")].toBool());
|
||||
somethingToSend = true;
|
||||
}
|
||||
if (properties.contains(QStringLiteral("CanSeek"))) {
|
||||
np.set(QStringLiteral("canSeek"), properties[QStringLiteral("CanSeek")].toBool());
|
||||
somethingToSend = true;
|
||||
}
|
||||
|
||||
if (somethingToSend) {
|
||||
np.set(QStringLiteral("player"), playerName);
|
||||
// Always also update the position
|
||||
if (mediaPlayer2PlayerInterface->canSeek()) {
|
||||
// Always also update the position if can seek
|
||||
bool canSeek = mediaPlayer2PlayerInterface->canSeek();
|
||||
np.set(QStringLiteral("canSeek"), canSeek);
|
||||
if (canSeek) {
|
||||
long long pos = mediaPlayer2PlayerInterface->position();
|
||||
np.set(QStringLiteral("pos"), pos / 1000); // Send milis instead of nanos
|
||||
}
|
||||
|
@ -388,17 +386,10 @@ void MprisControlPlugin::mprisPlayerMetadataToNetworkPacket(NetworkPacket &np, c
|
|||
}
|
||||
}
|
||||
|
||||
QString nowPlaying = title;
|
||||
|
||||
if (!artist.isEmpty()) {
|
||||
nowPlaying = artist + QStringLiteral(" - ") + title;
|
||||
}
|
||||
|
||||
np.set(QStringLiteral("title"), title);
|
||||
np.set(QStringLiteral("artist"), artist);
|
||||
np.set(QStringLiteral("album"), album);
|
||||
np.set(QStringLiteral("albumArtUrl"), albumArtUrl);
|
||||
np.set(QStringLiteral("nowPlaying"), nowPlaying);
|
||||
|
||||
bool hasLength = false;
|
||||
long long length = nowPlayingMap[QStringLiteral("mpris:length")].toLongLong(&hasLength) / 1000; // nanoseconds to milliseconds
|
||||
|
|
|
@ -22,7 +22,6 @@ MprisRemotePlayer::MprisRemotePlayer(QString id, MprisRemotePlugin *plugin)
|
|||
, m_canPause(true)
|
||||
, m_canGoPrevious(true)
|
||||
, m_canGoNext(true)
|
||||
, m_nowPlaying()
|
||||
, m_volume(50)
|
||||
, m_length(0)
|
||||
, m_lastPosition(0)
|
||||
|
@ -54,30 +53,27 @@ void MprisRemotePlayer::parseNetworkPacket(const NetworkPacket &np)
|
|||
bool trackInfoHasChanged = false;
|
||||
|
||||
// Track properties
|
||||
QString newNowPlaying = np.get<QString>(QStringLiteral("nowPlaying"), m_nowPlaying);
|
||||
QString newTitle = np.get<QString>(QStringLiteral("title"), m_title);
|
||||
QString newArtist = np.get<QString>(QStringLiteral("artist"), m_artist);
|
||||
QString newAlbum = np.get<QString>(QStringLiteral("album"), m_album);
|
||||
int newLength = np.get<int>(QStringLiteral("length"), m_length);
|
||||
|
||||
// Check if they changed
|
||||
if (newNowPlaying != m_nowPlaying || newTitle != m_title || newArtist != m_artist || newAlbum != m_album || newLength != m_length) {
|
||||
if (newTitle != m_title || newArtist != m_artist || newAlbum != m_album || newLength != m_length) {
|
||||
trackInfoHasChanged = true;
|
||||
Q_EMIT trackInfoChanged();
|
||||
}
|
||||
// Set the new values
|
||||
m_nowPlaying = newNowPlaying;
|
||||
m_title = newTitle;
|
||||
m_artist = newArtist;
|
||||
m_album = newAlbum;
|
||||
m_length = newLength;
|
||||
Q_EMIT trackInfoChanged();
|
||||
}
|
||||
|
||||
// Check volume changes
|
||||
int newVolume = np.get<int>(QStringLiteral("volume"), m_volume);
|
||||
if (newVolume != m_volume) {
|
||||
m_volume = newVolume;
|
||||
Q_EMIT volumeChanged();
|
||||
}
|
||||
m_volume = newVolume;
|
||||
|
||||
if (np.has(QStringLiteral("pos"))) {
|
||||
// Check position
|
||||
|
@ -86,8 +82,8 @@ void MprisRemotePlayer::parseNetworkPacket(const NetworkPacket &np)
|
|||
m_lastPosition = newLastPosition;
|
||||
m_lastPositionTime = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
// Only consider it seeking if the position changed more than 1 second, and the track has not changed
|
||||
if (qAbs(positionDiff) >= 1000 && !trackInfoHasChanged) {
|
||||
// Only consider it seeking if the position changed more than 1 second or the track has changed
|
||||
if (qAbs(positionDiff) >= 1000 || trackInfoHasChanged) {
|
||||
Q_EMIT positionChanged();
|
||||
}
|
||||
}
|
||||
|
@ -95,9 +91,9 @@ void MprisRemotePlayer::parseNetworkPacket(const NetworkPacket &np)
|
|||
// Check if we started/stopped playing
|
||||
bool newPlaying = np.get<bool>(QStringLiteral("isPlaying"), m_playing);
|
||||
if (newPlaying != m_playing) {
|
||||
m_playing = newPlaying;
|
||||
Q_EMIT playingChanged();
|
||||
}
|
||||
m_playing = newPlaying;
|
||||
|
||||
// Control properties
|
||||
bool newCanSeek = np.get<bool>(QStringLiteral("canSeek"), m_canSeek);
|
||||
|
@ -105,17 +101,14 @@ void MprisRemotePlayer::parseNetworkPacket(const NetworkPacket &np)
|
|||
bool newCanPause = np.get<bool>(QStringLiteral("canPause"), m_canPause);
|
||||
bool newCanGoPrevious = np.get<bool>(QStringLiteral("canGoPrevious"), m_canGoPrevious);
|
||||
bool newCanGoNext = np.get<bool>(QStringLiteral("canGoNext"), m_canGoNext);
|
||||
|
||||
// Check if they changed
|
||||
if (newCanSeek != m_canSeek || newCanPlay != m_canPlay || newCanPause != m_canPause || newCanGoPrevious != m_canGoPrevious || newCanGoNext != m_canGoNext) {
|
||||
Q_EMIT controlsChanged();
|
||||
}
|
||||
// Set the new values
|
||||
m_canSeek = newCanSeek;
|
||||
m_canPlay = newCanPlay;
|
||||
m_canPause = newCanPause;
|
||||
m_canGoPrevious = newCanGoPrevious;
|
||||
m_canGoNext = newCanGoNext;
|
||||
Q_EMIT controlsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
long MprisRemotePlayer::position() const
|
||||
|
@ -148,11 +141,6 @@ bool MprisRemotePlayer::playing() const
|
|||
return m_playing;
|
||||
}
|
||||
|
||||
QString MprisRemotePlayer::nowPlaying() const
|
||||
{
|
||||
return m_nowPlaying;
|
||||
}
|
||||
|
||||
QString MprisRemotePlayer::title() const
|
||||
{
|
||||
return m_title;
|
||||
|
|
|
@ -25,7 +25,6 @@ public:
|
|||
int volume() const;
|
||||
long length() const;
|
||||
bool playing() const;
|
||||
QString nowPlaying() const;
|
||||
QString title() const;
|
||||
QString artist() const;
|
||||
QString album() const;
|
||||
|
@ -53,7 +52,6 @@ private:
|
|||
bool m_canPause;
|
||||
bool m_canGoPrevious;
|
||||
bool m_canGoNext;
|
||||
QString m_nowPlaying;
|
||||
int m_volume;
|
||||
long m_length;
|
||||
long m_lastPosition;
|
||||
|
|
|
@ -248,7 +248,7 @@ void MprisRemotePlayerMediaPlayer2Player::emitPropertiesChanged()
|
|||
// Send it over the correct DBus connection
|
||||
m_parent->dbus().send(message);
|
||||
|
||||
if (m_positionChanged) {
|
||||
if (m_positionChanged || m_trackInfoChanged) {
|
||||
Q_EMIT Seeked(Position());
|
||||
}
|
||||
|
||||
|
|
|
@ -161,12 +161,6 @@ QStringList MprisRemotePlugin::playerList() const
|
|||
return m_players.keys();
|
||||
}
|
||||
|
||||
QString MprisRemotePlugin::nowPlaying() const
|
||||
{
|
||||
auto player = m_players.value(m_currentPlayer);
|
||||
return player ? player->nowPlaying() : QString();
|
||||
}
|
||||
|
||||
QString MprisRemotePlugin::title() const
|
||||
{
|
||||
auto player = m_players.value(m_currentPlayer);
|
||||
|
|
|
@ -26,7 +26,6 @@ class Q_DECL_EXPORT MprisRemotePlugin : public KdeConnectPlugin
|
|||
Q_PROPERTY(int position READ position WRITE setPosition NOTIFY propertiesChanged)
|
||||
Q_PROPERTY(QStringList playerList READ playerList NOTIFY propertiesChanged)
|
||||
Q_PROPERTY(QString player READ player WRITE setPlayer)
|
||||
Q_PROPERTY(QString nowPlaying READ nowPlaying NOTIFY propertiesChanged)
|
||||
Q_PROPERTY(QString title READ title NOTIFY propertiesChanged)
|
||||
Q_PROPERTY(QString artist READ artist NOTIFY propertiesChanged)
|
||||
Q_PROPERTY(QString album READ album NOTIFY propertiesChanged)
|
||||
|
@ -42,7 +41,6 @@ public:
|
|||
bool isPlaying() const;
|
||||
QStringList playerList() const;
|
||||
QString player() const;
|
||||
QString nowPlaying() const;
|
||||
QString title() const;
|
||||
QString artist() const;
|
||||
QString album() const;
|
||||
|
|
Loading…
Reference in a new issue