From 88b5cf2461d724943a952906055876ec2b320307 Mon Sep 17 00:00:00 2001 From: Reverier-Xu Date: Wed, 13 Mar 2024 19:11:48 +0800 Subject: [PATCH] mpris2: Fix mpris:trackid type with Plasma 6 --- src/core/mpris2.cpp | 6 +++--- src/core/mpris2.h | 2 +- src/core/mpris_common.h | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/mpris2.cpp b/src/core/mpris2.cpp index 251984633..4246156c5 100644 --- a/src/core/mpris2.cpp +++ b/src/core/mpris2.cpp @@ -379,8 +379,8 @@ void Mpris2::SetRating(double rating) { } -QString Mpris2::current_track_id() const { - return QString("/org/strawberrymusicplayer/strawberry/Track/%1").arg(QString::number(app_->playlist_manager()->active()->current_row())); +QDBusObjectPath Mpris2::current_track_id() const { + return QDBusObjectPath(QString("/org/strawberrymusicplayer/strawberry/Track/%1").arg(QString::number(app_->playlist_manager()->active()->current_row()))); } // We send Metadata change notification as soon as the process of changing song starts... @@ -512,7 +512,7 @@ void Mpris2::Seek(qint64 offset) { void Mpris2::SetPosition(const QDBusObjectPath &trackId, qint64 offset) { - if (CanSeek() && trackId.path() == current_track_id() && offset >= 0) { + if (CanSeek() && trackId == current_track_id() && offset >= 0) { offset *= kNsecPerUsec; if (offset < app_->player()->GetCurrentItem()->Metadata().length_nanosec()) { diff --git a/src/core/mpris2.h b/src/core/mpris2.h index 6ceaa4901..b2a7b1e7c 100644 --- a/src/core/mpris2.h +++ b/src/core/mpris2.h @@ -225,7 +225,7 @@ class Mpris2 : public QObject { QString PlaybackStatus(EngineBase::State state) const; - QString current_track_id() const; + QDBusObjectPath current_track_id() const; bool CanSeek(EngineBase::State state) const; diff --git a/src/core/mpris_common.h b/src/core/mpris_common.h index 86a5c03b6..c17dfc5f6 100644 --- a/src/core/mpris_common.h +++ b/src/core/mpris_common.h @@ -28,6 +28,7 @@ #include #include #include +#include namespace mpris { @@ -55,6 +56,10 @@ inline void AddMetadata(const QString &key, const QDateTime &metadata, QVariantM if (metadata.isValid()) (*map)[key] = metadata; } +inline void AddMetadata(const QString &key, const QDBusObjectPath &metadata, QVariantMap *map) { + if (metadata.path().length() > 0) (*map)[key] = metadata; +} + inline QString AsMPRISDateTimeType(const qint64 time) { return time != -1 ? QDateTime::fromSecsSinceEpoch(time).toString(Qt::ISODate) : ""; }