plugins/mpriscontrol: use correct type for artist

In MPRIS2 xeasm:artist should have a string list type, not a string
type.  This change is compatible with previous KDEConnect versions
because QString in QVariant can be converted to QStringList.
This commit is contained in:
Fushan Wen 2023-03-25 13:07:34 +08:00
parent 87a608136f
commit e85002a311
No known key found for this signature in database
GPG key ID: 2E48D1487C91DCAA
8 changed files with 16 additions and 17 deletions

View file

@ -93,7 +93,7 @@ Kirigami.Page
}
Label {
Layout.fillWidth: true
text: root.pluginInterface.artist
text: root.pluginInterface.artist.join(', ')
visible: !nowPlaying.visible && !artistAlbum.visible && root.pluginInterface.artist.length > 0
wrapMode: Text.Wrap
}
@ -106,7 +106,7 @@ Kirigami.Page
Label {
id: artistAlbum
Layout.fillWidth: true
text: i18nd("kdeconnect-app", "%1 - %2", root.pluginInterface.artist, root.pluginInterface.album)
text: i18nd("kdeconnect-app", "%1 - %2", root.pluginInterface.artist.join(', '), root.pluginInterface.album)
visible: !nowPlaying.visible && root.pluginInterface.album.length > 0 && root.pluginInterface.artist.length > 0
wrapMode: Text.Wrap
}

View file

@ -152,7 +152,7 @@ class KDECONNECTINTERFACES_EXPORT MprisDbusInterface : public OrgKdeKdeconnectDe
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(QStringList artist READ artist NOTIFY propertiesChangedProxy)
Q_PROPERTY(QString album READ album NOTIFY propertiesChangedProxy)
Q_PROPERTY(QStringList playerList READ playerList NOTIFY propertiesChangedProxy)

View file

@ -68,7 +68,7 @@ void MprisControlPlugin::sendMediaProperties(std::variant<NetworkPacket, QString
auto mediaProperties = player.TryGetMediaPropertiesAsync().get();
np.set(QStringLiteral("title"), QString::fromWCharArray(mediaProperties.Title().c_str()));
np.set(QStringLiteral("artist"), QString::fromWCharArray(mediaProperties.Artist().c_str()));
np.set(QStringLiteral("artist"), QStringList{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"),

View file

@ -374,12 +374,12 @@ void MprisControlPlugin::sendPlayerList()
void MprisControlPlugin::mprisPlayerMetadataToNetworkPacket(NetworkPacket &np, const QVariantMap &nowPlayingMap) const
{
QString title = nowPlayingMap[QStringLiteral("xesam:title")].toString();
QString artist = nowPlayingMap[QStringLiteral("xesam:artist")].toString();
const QStringList artist = nowPlayingMap[QStringLiteral("xesam:artist")].toStringList();
QString album = nowPlayingMap[QStringLiteral("xesam:album")].toString();
QString albumArtUrl = nowPlayingMap[QStringLiteral("mpris:artUrl")].toString();
QUrl fileUrl = nowPlayingMap[QStringLiteral("xesam:url")].toUrl();
if (title.isEmpty() && artist.isEmpty() && fileUrl.isLocalFile()) {
if (title.isEmpty() && artist.empty() && fileUrl.isLocalFile()) {
title = fileUrl.fileName();
QStringList splitUrl = fileUrl.path().split(QDir::separator());
@ -390,8 +390,8 @@ void MprisControlPlugin::mprisPlayerMetadataToNetworkPacket(NetworkPacket &np, c
QString nowPlaying = title;
if (!artist.isEmpty()) {
nowPlaying = artist + QStringLiteral(" - ") + title;
if (!artist.empty()) {
nowPlaying = artist.join(QLatin1String(", ")) + QStringLiteral(" - ") + title;
}
np.set(QStringLiteral("title"), title);

View file

@ -28,7 +28,6 @@ MprisRemotePlayer::MprisRemotePlayer(QString id, MprisRemotePlugin *plugin)
, m_lastPosition(0)
, m_lastPositionTime()
, m_title()
, m_artist()
, m_album()
, m_canSeek(false)
, m_dbusConnectionName(QStringLiteral("mpris_") + QUuid::createUuid().toString(QUuid::Id128))
@ -56,7 +55,7 @@ void MprisRemotePlayer::parseNetworkPacket(const NetworkPacket &np)
// 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);
const QStringList newArtist = np.get<QStringList>(QStringLiteral("artist"), m_artist);
QString newAlbum = np.get<QString>(QStringLiteral("album"), m_album);
int newLength = np.get<int>(QStringLiteral("length"), m_length);
@ -158,7 +157,7 @@ QString MprisRemotePlayer::title() const
return m_title;
}
QString MprisRemotePlayer::artist() const
QStringList MprisRemotePlayer::artist() const
{
return m_artist;
}

View file

@ -27,7 +27,7 @@ public:
bool playing() const;
QString nowPlaying() const;
QString title() const;
QString artist() const;
QStringList artist() const;
QString album() const;
QString identity() const;
@ -59,7 +59,7 @@ private:
long m_lastPosition;
qint64 m_lastPositionTime;
QString m_title;
QString m_artist;
QStringList m_artist;
QString m_album;
bool m_canSeek;

View file

@ -179,10 +179,10 @@ QString MprisRemotePlugin::album() const
return player ? player->album() : QString();
}
QString MprisRemotePlugin::artist() const
QStringList MprisRemotePlugin::artist() const
{
auto player = m_players.value(m_currentPlayer);
return player ? player->artist() : QString();
return player ? player->artist() : QStringList();
}
bool MprisRemotePlugin::canSeek() const

View file

@ -28,7 +28,7 @@ class Q_DECL_EXPORT MprisRemotePlugin : public KdeConnectPlugin
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(QStringList artist READ artist NOTIFY propertiesChanged)
Q_PROPERTY(QString album READ album NOTIFY propertiesChanged)
Q_PROPERTY(bool canSeek READ canSeek NOTIFY propertiesChanged)
@ -44,7 +44,7 @@ public:
QString player() const;
QString nowPlaying() const;
QString title() const;
QString artist() const;
QStringList artist() const;
QString album() const;
bool canSeek() const;