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:
Albert Vaca Cintora 2023-06-07 20:20:21 +02:00
parent 3cb40eab61
commit 2e0550651e
10 changed files with 26 additions and 74 deletions

View file

@ -17,7 +17,10 @@ Loader {
sourceComponent: plugin.canSeek ? seekBar : progressBar sourceComponent: plugin.canSeek ? seekBar : progressBar
onLastPositionChanged: { onLastPositionChanged: {
lastPositionTime = new Date(); if (item != null) {
item.value = lastPosition
lastPositionTime = new Date();
}
} }
Component { Component {
@ -54,11 +57,4 @@ Loader {
onTriggered: item.value = lastPosition + (new Date().getTime() - lastPositionTime.getTime()) onTriggered: item.value = lastPosition + (new Date().getTime() - lastPositionTime.getTime())
} }
Connections {
target: plugin
function onNowPlayingChanged() {
item.value = lastPosition
}
}
} }

View file

@ -78,36 +78,28 @@ Kirigami.Page
model: root.pluginInterface.playerList model: root.pluginInterface.playerList
onCurrentTextChanged: root.pluginInterface.player = currentText 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 { Label {
Layout.fillWidth: true Layout.fillWidth: true
text: root.pluginInterface.title text: root.pluginInterface.title
visible: !nowPlaying.visible
wrapMode: Text.Wrap wrapMode: Text.Wrap
} }
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true
text: root.pluginInterface.artist 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 wrapMode: Text.Wrap
} }
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true
text: root.pluginInterface.album 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 wrapMode: Text.Wrap
} }
Label { Label {
id: artistAlbum id: artistAlbum
Layout.fillWidth: true Layout.fillWidth: true
text: i18nd("kdeconnect-app", "%1 - %2", root.pluginInterface.artist, root.pluginInterface.album) 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 wrapMode: Text.Wrap
} }
RowLayout { RowLayout {

View file

@ -152,7 +152,6 @@ class KDECONNECTINTERFACES_EXPORT MprisDbusInterface : public OrgKdeKdeconnectDe
// the signals for the properties // the signals for the properties
Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY propertiesChangedProxy) Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY propertiesChangedProxy)
Q_PROPERTY(int length READ length 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 title READ title NOTIFY propertiesChangedProxy)
Q_PROPERTY(QString artist READ artist NOTIFY propertiesChangedProxy) Q_PROPERTY(QString artist READ artist NOTIFY propertiesChangedProxy)
Q_PROPERTY(QString album READ album NOTIFY propertiesChangedProxy) Q_PROPERTY(QString album READ album NOTIFY propertiesChangedProxy)

View file

@ -71,10 +71,6 @@ void MprisControlPlugin::sendMediaProperties(std::variant<NetworkPacket, QString
np.set(QStringLiteral("artist"), QString::fromWCharArray(mediaProperties.Artist().c_str())); np.set(QStringLiteral("artist"), QString::fromWCharArray(mediaProperties.Artist().c_str()));
np.set(QStringLiteral("album"), QString::fromWCharArray(mediaProperties.AlbumTitle().c_str())); np.set(QStringLiteral("album"), QString::fromWCharArray(mediaProperties.AlbumTitle().c_str()));
np.set(QStringLiteral("albumArtUrl"), randomUrl()); 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()); np.set(QStringLiteral("url"), QString());
sendTimelineProperties(np, player, true); // "length" sendTimelineProperties(np, player, true); // "length"

View file

@ -183,15 +183,13 @@ void MprisControlPlugin::propertiesChanged(const QString &propertyInterface, con
np.set(QStringLiteral("canGoPrevious"), properties[QStringLiteral("CanGoPrevious")].toBool()); np.set(QStringLiteral("canGoPrevious"), properties[QStringLiteral("CanGoPrevious")].toBool());
somethingToSend = true; somethingToSend = true;
} }
if (properties.contains(QStringLiteral("CanSeek"))) {
np.set(QStringLiteral("canSeek"), properties[QStringLiteral("CanSeek")].toBool());
somethingToSend = true;
}
if (somethingToSend) { if (somethingToSend) {
np.set(QStringLiteral("player"), playerName); np.set(QStringLiteral("player"), playerName);
// Always also update the position // Always also update the position if can seek
if (mediaPlayer2PlayerInterface->canSeek()) { bool canSeek = mediaPlayer2PlayerInterface->canSeek();
np.set(QStringLiteral("canSeek"), canSeek);
if (canSeek) {
long long pos = mediaPlayer2PlayerInterface->position(); long long pos = mediaPlayer2PlayerInterface->position();
np.set(QStringLiteral("pos"), pos / 1000); // Send milis instead of nanos 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("title"), title);
np.set(QStringLiteral("artist"), artist); np.set(QStringLiteral("artist"), artist);
np.set(QStringLiteral("album"), album); np.set(QStringLiteral("album"), album);
np.set(QStringLiteral("albumArtUrl"), albumArtUrl); np.set(QStringLiteral("albumArtUrl"), albumArtUrl);
np.set(QStringLiteral("nowPlaying"), nowPlaying);
bool hasLength = false; bool hasLength = false;
long long length = nowPlayingMap[QStringLiteral("mpris:length")].toLongLong(&hasLength) / 1000; // nanoseconds to milliseconds long long length = nowPlayingMap[QStringLiteral("mpris:length")].toLongLong(&hasLength) / 1000; // nanoseconds to milliseconds

View file

@ -22,7 +22,6 @@ MprisRemotePlayer::MprisRemotePlayer(QString id, MprisRemotePlugin *plugin)
, m_canPause(true) , m_canPause(true)
, m_canGoPrevious(true) , m_canGoPrevious(true)
, m_canGoNext(true) , m_canGoNext(true)
, m_nowPlaying()
, m_volume(50) , m_volume(50)
, m_length(0) , m_length(0)
, m_lastPosition(0) , m_lastPosition(0)
@ -54,30 +53,27 @@ void MprisRemotePlayer::parseNetworkPacket(const NetworkPacket &np)
bool trackInfoHasChanged = false; bool trackInfoHasChanged = false;
// Track properties // Track properties
QString newNowPlaying = np.get<QString>(QStringLiteral("nowPlaying"), m_nowPlaying);
QString newTitle = np.get<QString>(QStringLiteral("title"), m_title); QString newTitle = np.get<QString>(QStringLiteral("title"), m_title);
QString newArtist = np.get<QString>(QStringLiteral("artist"), m_artist); QString newArtist = np.get<QString>(QStringLiteral("artist"), m_artist);
QString newAlbum = np.get<QString>(QStringLiteral("album"), m_album); QString newAlbum = np.get<QString>(QStringLiteral("album"), m_album);
int newLength = np.get<int>(QStringLiteral("length"), m_length); int newLength = np.get<int>(QStringLiteral("length"), m_length);
// Check if they changed // 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; trackInfoHasChanged = true;
m_title = newTitle;
m_artist = newArtist;
m_album = newAlbum;
m_length = newLength;
Q_EMIT trackInfoChanged(); Q_EMIT trackInfoChanged();
} }
// Set the new values
m_nowPlaying = newNowPlaying;
m_title = newTitle;
m_artist = newArtist;
m_album = newAlbum;
m_length = newLength;
// Check volume changes // Check volume changes
int newVolume = np.get<int>(QStringLiteral("volume"), m_volume); int newVolume = np.get<int>(QStringLiteral("volume"), m_volume);
if (newVolume != m_volume) { if (newVolume != m_volume) {
m_volume = newVolume;
Q_EMIT volumeChanged(); Q_EMIT volumeChanged();
} }
m_volume = newVolume;
if (np.has(QStringLiteral("pos"))) { if (np.has(QStringLiteral("pos"))) {
// Check position // Check position
@ -86,8 +82,8 @@ void MprisRemotePlayer::parseNetworkPacket(const NetworkPacket &np)
m_lastPosition = newLastPosition; m_lastPosition = newLastPosition;
m_lastPositionTime = QDateTime::currentMSecsSinceEpoch(); m_lastPositionTime = QDateTime::currentMSecsSinceEpoch();
// Only consider it seeking if the position changed more than 1 second, and the track has not changed // Only consider it seeking if the position changed more than 1 second or the track has changed
if (qAbs(positionDiff) >= 1000 && !trackInfoHasChanged) { if (qAbs(positionDiff) >= 1000 || trackInfoHasChanged) {
Q_EMIT positionChanged(); Q_EMIT positionChanged();
} }
} }
@ -95,9 +91,9 @@ void MprisRemotePlayer::parseNetworkPacket(const NetworkPacket &np)
// Check if we started/stopped playing // Check if we started/stopped playing
bool newPlaying = np.get<bool>(QStringLiteral("isPlaying"), m_playing); bool newPlaying = np.get<bool>(QStringLiteral("isPlaying"), m_playing);
if (newPlaying != m_playing) { if (newPlaying != m_playing) {
m_playing = newPlaying;
Q_EMIT playingChanged(); Q_EMIT playingChanged();
} }
m_playing = newPlaying;
// Control properties // Control properties
bool newCanSeek = np.get<bool>(QStringLiteral("canSeek"), m_canSeek); 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 newCanPause = np.get<bool>(QStringLiteral("canPause"), m_canPause);
bool newCanGoPrevious = np.get<bool>(QStringLiteral("canGoPrevious"), m_canGoPrevious); bool newCanGoPrevious = np.get<bool>(QStringLiteral("canGoPrevious"), m_canGoPrevious);
bool newCanGoNext = np.get<bool>(QStringLiteral("canGoNext"), m_canGoNext); 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) { if (newCanSeek != m_canSeek || newCanPlay != m_canPlay || newCanPause != m_canPause || newCanGoPrevious != m_canGoPrevious || newCanGoNext != m_canGoNext) {
m_canSeek = newCanSeek;
m_canPlay = newCanPlay;
m_canPause = newCanPause;
m_canGoPrevious = newCanGoPrevious;
m_canGoNext = newCanGoNext;
Q_EMIT controlsChanged(); Q_EMIT controlsChanged();
} }
// Set the new values
m_canSeek = newCanSeek;
m_canPlay = newCanPlay;
m_canPause = newCanPause;
m_canGoPrevious = newCanGoPrevious;
m_canGoNext = newCanGoNext;
} }
long MprisRemotePlayer::position() const long MprisRemotePlayer::position() const
@ -148,11 +141,6 @@ bool MprisRemotePlayer::playing() const
return m_playing; return m_playing;
} }
QString MprisRemotePlayer::nowPlaying() const
{
return m_nowPlaying;
}
QString MprisRemotePlayer::title() const QString MprisRemotePlayer::title() const
{ {
return m_title; return m_title;

View file

@ -25,7 +25,6 @@ public:
int volume() const; int volume() const;
long length() const; long length() const;
bool playing() const; bool playing() const;
QString nowPlaying() const;
QString title() const; QString title() const;
QString artist() const; QString artist() const;
QString album() const; QString album() const;
@ -53,7 +52,6 @@ private:
bool m_canPause; bool m_canPause;
bool m_canGoPrevious; bool m_canGoPrevious;
bool m_canGoNext; bool m_canGoNext;
QString m_nowPlaying;
int m_volume; int m_volume;
long m_length; long m_length;
long m_lastPosition; long m_lastPosition;

View file

@ -248,7 +248,7 @@ void MprisRemotePlayerMediaPlayer2Player::emitPropertiesChanged()
// Send it over the correct DBus connection // Send it over the correct DBus connection
m_parent->dbus().send(message); m_parent->dbus().send(message);
if (m_positionChanged) { if (m_positionChanged || m_trackInfoChanged) {
Q_EMIT Seeked(Position()); Q_EMIT Seeked(Position());
} }

View file

@ -161,12 +161,6 @@ QStringList MprisRemotePlugin::playerList() const
return m_players.keys(); return m_players.keys();
} }
QString MprisRemotePlugin::nowPlaying() const
{
auto player = m_players.value(m_currentPlayer);
return player ? player->nowPlaying() : QString();
}
QString MprisRemotePlugin::title() const QString MprisRemotePlugin::title() const
{ {
auto player = m_players.value(m_currentPlayer); auto player = m_players.value(m_currentPlayer);

View file

@ -26,7 +26,6 @@ class Q_DECL_EXPORT MprisRemotePlugin : public KdeConnectPlugin
Q_PROPERTY(int position READ position WRITE setPosition NOTIFY propertiesChanged) Q_PROPERTY(int position READ position WRITE setPosition NOTIFY propertiesChanged)
Q_PROPERTY(QStringList playerList READ playerList NOTIFY propertiesChanged) Q_PROPERTY(QStringList playerList READ playerList NOTIFY propertiesChanged)
Q_PROPERTY(QString player READ player WRITE setPlayer) 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 title READ title NOTIFY propertiesChanged)
Q_PROPERTY(QString artist READ artist NOTIFY propertiesChanged) Q_PROPERTY(QString artist READ artist NOTIFY propertiesChanged)
Q_PROPERTY(QString album READ album NOTIFY propertiesChanged) Q_PROPERTY(QString album READ album NOTIFY propertiesChanged)
@ -42,7 +41,6 @@ public:
bool isPlaying() const; bool isPlaying() const;
QStringList playerList() const; QStringList playerList() const;
QString player() const; QString player() const;
QString nowPlaying() const;
QString title() const; QString title() const;
QString artist() const; QString artist() const;
QString album() const; QString album() const;