File indexing completed on 2025-01-19 04:28:11

0001 /**
0002  * SPDX-FileCopyrightText: 2014 Sujith Haridasan <sujith.haridasan@kdemail.net>
0003  * SPDX-FileCopyrightText: 2014 Ashish Madeti <ashishmadeti@gmail.com>
0004  * SPDX-FileCopyrightText: 2016 Matthieu Gallien <matthieu_gallien@yahoo.fr>
0005  * SPDX-FileCopyrightText: 2022-2023 Bart De Vries <bart@mogwai.be>
0006  *
0007  * SPDX-License-Identifier: GPL-3.0-or-later
0008  */
0009 
0010 #include "mediaplayer2player.h"
0011 #include "mpris2.h"
0012 #include "mpris2logging.h"
0013 
0014 #include "kmediasession.h"
0015 #include "metadata.h"
0016 
0017 #include <QCryptographicHash>
0018 #include <QDBusConnection>
0019 #include <QDBusMessage>
0020 #include <QDebug>
0021 #include <QMetaClassInfo>
0022 #include <QStringList>
0023 #include <QTimer>
0024 
0025 MediaPlayer2Player::MediaPlayer2Player(KMediaSession *audioPlayer, bool showProgressOnTaskBar, QObject *parent)
0026     : QDBusAbstractAdaptor(parent)
0027     , m_audioPlayer(audioPlayer)
0028     , mProgressIndicatorSignal(
0029           QDBusMessage::createSignal(QStringLiteral("/org/kde/kmediasession"), QStringLiteral("com.canonical.Unity.LauncherEntry"), QStringLiteral("Update")))
0030     , mShowProgressOnTaskBar(showProgressOnTaskBar)
0031 {
0032     qCDebug(Mpris2Log) << "MediaPlayer2Player::MediaPlayer2Player()";
0033     // This will signal when the track is changed
0034     connect(m_audioPlayer, &KMediaSession::sourceChanged, this, &MediaPlayer2Player::setSource);
0035 
0036     // Signals from KMediaSession which are directly forwarded
0037     // TODO: implement this in KMediaSession, such that it can be forwarded
0038     // connect(m_audioPlayer, &KMediaSession::minimumRateChanged,
0039     //        this, &MediaPlayer2Player::mimimumRateChanged);
0040     // connect(m_audioPlayer, &KMediaSession::maximumRateChanged,
0041     //        this, &MediaPlayer2Player::maximumRateChanged);
0042     connect(m_audioPlayer, &KMediaSession::seekableChanged, this, &MediaPlayer2Player::canSeekChanged);
0043 
0044     // Signals which are semi-wrapped signals from KMediaSession
0045     connect(m_audioPlayer, &KMediaSession::playbackStateChanged, this, &MediaPlayer2Player::playerPlaybackStateChanged);
0046     connect(m_audioPlayer, &KMediaSession::playbackRateChanged, this, &MediaPlayer2Player::playerPlaybackRateChanged);
0047     connect(m_audioPlayer, &KMediaSession::volumeChanged, this, &MediaPlayer2Player::playerVolumeChanged);
0048     connect(m_audioPlayer, &KMediaSession::positionJumped, this, &MediaPlayer2Player::playerSeeked); // Implement Seeked signal
0049 
0050     connect(m_audioPlayer, &KMediaSession::canPlayChanged, this, &MediaPlayer2Player::playerCanPlayChanged);
0051     connect(m_audioPlayer, &KMediaSession::canPauseChanged, this, &MediaPlayer2Player::playerCanPauseChanged);
0052     connect(m_audioPlayer, &KMediaSession::canGoNextChanged, this, &MediaPlayer2Player::playerCanGoNextChanged);
0053     connect(m_audioPlayer, &KMediaSession::canGoPreviousChanged, this, &MediaPlayer2Player::playerCanGoPreviousChanged);
0054 
0055     connect(m_audioPlayer, &KMediaSession::seekableChanged, this, &MediaPlayer2Player::playerCanSeekChanged);
0056     connect(m_audioPlayer, &KMediaSession::metaDataChanged, this, &MediaPlayer2Player::playerMetaDataChanged);
0057 
0058     // signals needed for progress indicator on taskbar
0059     connect(m_audioPlayer, &KMediaSession::durationChanged, this, &MediaPlayer2Player::audioDurationChanged);
0060     connect(m_audioPlayer, &KMediaSession::positionChanged, this, &MediaPlayer2Player::audioPositionChanged);
0061 
0062     // Update DBUS object if desktopEntryName changes
0063     connect(m_audioPlayer, &KMediaSession::desktopEntryNameChanged, this, [this](const QString &desktopName) {
0064         QString newDesktopName = QStringLiteral("/") + desktopName;
0065         newDesktopName.replace(QStringLiteral("."), QStringLiteral("/"));
0066         mProgressIndicatorSignal = QDBusMessage::createSignal(newDesktopName, QStringLiteral("com.canonical.Unity.LauncherEntry"), QStringLiteral("Update"));
0067     });
0068 
0069     if (m_audioPlayer) {
0070         m_volume = m_audioPlayer->volume() / 100;
0071         signalPropertiesChange(QStringLiteral("Volume"), Volume());
0072 
0073         if (!m_audioPlayer->source().isEmpty()) {
0074             setSource(m_audioPlayer->source());
0075         }
0076     }
0077 }
0078 
0079 QString MediaPlayer2Player::PlaybackStatus() const
0080 {
0081     qCDebug(Mpris2Log) << "MediaPlayer2Player::PlaybackStatus()";
0082     QString result;
0083 
0084     if (m_audioPlayer->playbackState() == KMediaSession::StoppedState) {
0085         result = QStringLiteral("Stopped");
0086     } else if (m_audioPlayer->playbackState() == KMediaSession::PlayingState) {
0087         result = QStringLiteral("Playing");
0088     } else {
0089         result = QStringLiteral("Paused");
0090     }
0091 
0092     if (mShowProgressOnTaskBar) {
0093         QVariantMap parameters;
0094 
0095         if (m_audioPlayer->playbackState() == KMediaSession::StoppedState || m_audioPlayer->duration() == 0) {
0096             parameters.insert(QStringLiteral("progress-visible"), false);
0097             parameters.insert(QStringLiteral("progress"), 0);
0098         } else {
0099             parameters.insert(QStringLiteral("progress-visible"), true);
0100             parameters.insert(QStringLiteral("progress"), qRound(static_cast<double>(m_position / m_audioPlayer->duration())) / 1000.0);
0101         }
0102 
0103         const QString fullDesktopPath = QStringLiteral("application://") + m_audioPlayer->desktopEntryName() + QStringLiteral(".desktop");
0104         mProgressIndicatorSignal.setArguments({fullDesktopPath, parameters});
0105 
0106         QDBusConnection::sessionBus().send(mProgressIndicatorSignal);
0107     }
0108 
0109     return result;
0110 }
0111 
0112 bool MediaPlayer2Player::CanGoNext() const
0113 {
0114     qCDebug(Mpris2Log) << "MediaPlayer2Player::CanGoNext()";
0115     if (m_audioPlayer) {
0116         return m_audioPlayer->canGoNext();
0117     } else {
0118         return false;
0119     }
0120 }
0121 
0122 void MediaPlayer2Player::Next()
0123 {
0124     qCDebug(Mpris2Log) << "MediaPlayer2Player::Next()";
0125     if (m_audioPlayer) {
0126         QTimer::singleShot(0, this, [this]() {
0127             Q_EMIT m_audioPlayer->nextRequested();
0128         });
0129     }
0130 }
0131 
0132 bool MediaPlayer2Player::CanGoPrevious() const
0133 {
0134     qCDebug(Mpris2Log) << "MediaPlayer2Player::CanGoPrevious()";
0135     if (m_audioPlayer) {
0136         return m_audioPlayer->canGoPrevious();
0137     } else {
0138         return false;
0139     }
0140 }
0141 
0142 void MediaPlayer2Player::Previous()
0143 {
0144     qCDebug(Mpris2Log) << "MediaPlayer2Player::Previous()";
0145     if (m_audioPlayer) {
0146         QTimer::singleShot(0, this, [this]() {
0147             Q_EMIT m_audioPlayer->previousRequested();
0148         });
0149     }
0150 }
0151 
0152 bool MediaPlayer2Player::CanPause() const
0153 {
0154     qCDebug(Mpris2Log) << "MediaPlayer2Player::CanPause()";
0155     if (m_audioPlayer) {
0156         return m_audioPlayer->canPause();
0157     } else {
0158         return false;
0159     }
0160 }
0161 
0162 void MediaPlayer2Player::Pause()
0163 {
0164     qCDebug(Mpris2Log) << "MediaPlayer2Player::Pause()";
0165     if (m_audioPlayer)
0166         m_audioPlayer->pause();
0167 }
0168 
0169 void MediaPlayer2Player::PlayPause()
0170 {
0171     qCDebug(Mpris2Log) << "MediaPlayer2Player::PlayPause()";
0172     if (m_audioPlayer) {
0173         if (m_audioPlayer->playbackState() != KMediaSession::PlaybackState::PlayingState) {
0174             m_audioPlayer->play();
0175         } else if (m_audioPlayer->playbackState() == KMediaSession::PlaybackState::PlayingState) {
0176             m_audioPlayer->pause();
0177         }
0178     }
0179 }
0180 
0181 void MediaPlayer2Player::Stop()
0182 {
0183     qCDebug(Mpris2Log) << "MediaPlayer2Player::Stop()";
0184     if (m_audioPlayer) {
0185         if (!m_audioPlayer->mpris2PauseInsteadOfStop()) {
0186             m_audioPlayer->stop();
0187         } else if (m_audioPlayer->playbackState() == KMediaSession::PlaybackState::PlayingState) {
0188             m_audioPlayer->pause();
0189         }
0190     }
0191 }
0192 
0193 bool MediaPlayer2Player::CanPlay() const
0194 {
0195     qCDebug(Mpris2Log) << "MediaPlayer2Player::CanPlay()";
0196     if (m_audioPlayer) {
0197         return m_audioPlayer->canPlay();
0198     } else {
0199         return false;
0200     }
0201 }
0202 
0203 void MediaPlayer2Player::Play()
0204 {
0205     qCDebug(Mpris2Log) << "MediaPlayer2Player::Play()";
0206     if (m_audioPlayer)
0207         m_audioPlayer->play();
0208 }
0209 
0210 double MediaPlayer2Player::Volume() const
0211 {
0212     qCDebug(Mpris2Log) << "MediaPlayer2Player::Volume()";
0213     return m_volume;
0214 }
0215 
0216 void MediaPlayer2Player::setVolume(double volume)
0217 {
0218     qCDebug(Mpris2Log) << "MediaPlayer2Player::setVolume(" << volume << ")";
0219     if (m_audioPlayer) {
0220         m_volume = qBound(0.0, volume, 1.0);
0221         Q_EMIT volumeChanged(m_volume);
0222 
0223         m_audioPlayer->setVolume(100 * m_volume);
0224 
0225         signalPropertiesChange(QStringLiteral("Volume"), Volume());
0226     }
0227 }
0228 
0229 QVariantMap MediaPlayer2Player::Metadata() const
0230 {
0231     qCDebug(Mpris2Log) << "MediaPlayer2Player::Metadata()";
0232     return m_metadata;
0233 }
0234 
0235 qlonglong MediaPlayer2Player::Position() const
0236 {
0237     qCDebug(Mpris2Log) << "MediaPlayer2Player::Position()";
0238     return qlonglong(m_audioPlayer->position()) * 1000;
0239 }
0240 
0241 double MediaPlayer2Player::Rate() const
0242 {
0243     qCDebug(Mpris2Log) << "MediaPlayer2Player::Rate()";
0244     if (m_audioPlayer)
0245         return m_audioPlayer->playbackRate();
0246     else
0247         return 1.0;
0248 }
0249 
0250 double MediaPlayer2Player::MinimumRate() const
0251 {
0252     qCDebug(Mpris2Log) << "MediaPlayer2Player::MinimumRate()";
0253     if (m_audioPlayer)
0254         return m_audioPlayer->minimumPlaybackRate();
0255     else
0256         return 1.0;
0257 }
0258 
0259 double MediaPlayer2Player::MaximumRate() const
0260 {
0261     qCDebug(Mpris2Log) << "MediaPlayer2Player::MaximumRate()";
0262     if (m_audioPlayer)
0263         return m_audioPlayer->maximumPlaybackRate();
0264     else
0265         return 1.0;
0266 }
0267 
0268 void MediaPlayer2Player::setRate(double newRate)
0269 {
0270     qCDebug(Mpris2Log) << "MediaPlayer2Player::setRate(" << newRate << ")";
0271     if (newRate <= 0.0001 && newRate >= -0.0001) {
0272         Pause();
0273     } else {
0274         m_audioPlayer->setPlaybackRate(newRate);
0275     }
0276 }
0277 
0278 bool MediaPlayer2Player::CanSeek() const
0279 {
0280     qCDebug(Mpris2Log) << "MediaPlayer2Player::CanSeek()";
0281     if (m_audioPlayer)
0282         return m_audioPlayer->seekable();
0283     else
0284         return false;
0285 }
0286 
0287 bool MediaPlayer2Player::CanControl() const
0288 {
0289     qCDebug(Mpris2Log) << "MediaPlayer2Player::CanControl()";
0290     return true;
0291 }
0292 
0293 void MediaPlayer2Player::Seek(qlonglong Offset)
0294 {
0295     qCDebug(Mpris2Log) << "MediaPlayer2Player::Seek(" << Offset << ")";
0296     if (m_audioPlayer) {
0297         auto offset = (m_position + Offset) / 1000;
0298         m_audioPlayer->setPosition(int(offset));
0299     }
0300 }
0301 
0302 void MediaPlayer2Player::SetPosition(const QDBusObjectPath &trackId, qlonglong pos)
0303 {
0304     qCDebug(Mpris2Log) << "MediaPlayer2Player::SetPosition(" << pos << ")";
0305     if (m_audioPlayer) {
0306         if (!m_audioPlayer->source().isEmpty()) {
0307             if (trackId.path() == m_currentTrackId) {
0308                 m_audioPlayer->setPosition(int(pos / 1000));
0309             }
0310         }
0311     }
0312 }
0313 
0314 void MediaPlayer2Player::OpenUri(const QString &uri)
0315 {
0316     qCDebug(Mpris2Log) << "MediaPlayer2Player::OpenUri(" << uri << ")";
0317     Q_UNUSED(uri);
0318 }
0319 
0320 void MediaPlayer2Player::playerPlaybackStateChanged()
0321 {
0322     qCDebug(Mpris2Log) << "MediaPlayer2Player::playerPlaybackStateChanged()";
0323     signalPropertiesChange(QStringLiteral("PlaybackStatus"), PlaybackStatus());
0324     Q_EMIT playbackStatusChanged();
0325 }
0326 
0327 void MediaPlayer2Player::playerPlaybackRateChanged()
0328 {
0329     qCDebug(Mpris2Log) << "MediaPlayer2Player::playerPlaybackRateChanged()";
0330     signalPropertiesChange(QStringLiteral("Rate"), Rate());
0331     // Q_EMIT rateChanged(Rate());
0332 }
0333 
0334 void MediaPlayer2Player::playerSeeked(qint64 position)
0335 {
0336     qCDebug(Mpris2Log) << "MediaPlayer2Player::playerSeeked(" << position << ")";
0337     Q_EMIT Seeked(position * 1000);
0338 }
0339 
0340 void MediaPlayer2Player::audioPositionChanged()
0341 {
0342     qCDebug(Mpris2Log) << "MediaPlayer2Player::audioPositionChanged()";
0343     // for progress indicator on taskbar
0344     if (m_audioPlayer)
0345         setPropertyPosition(static_cast<int>(m_audioPlayer->position()));
0346 
0347     // Occasionally send updated position through MPRIS to make sure that
0348     // audio position is still correct if playing without seeking for a long
0349     // time.  This will also guarantee correct playback position if the MPRIS
0350     // client does not support non-standard playback rates
0351     qlonglong position = Position();
0352     if (abs(position - m_lastSentPosition) > 10000000) { // every 10 seconds
0353         m_lastSentPosition = position;
0354         Q_EMIT Seeked(position);
0355     }
0356 }
0357 
0358 void MediaPlayer2Player::audioDurationChanged()
0359 {
0360     qCDebug(Mpris2Log) << "MediaPlayer2Player::audioDurationChanged()";
0361     // We reset all metadata in case the audioDuration changed
0362     // This is done because duration is not yet available when setEntry is
0363     // called (this is before the QMediaPlayer has read the new track
0364     if (m_audioPlayer) {
0365         // qCDebug(Mpris2Log) << "Signal change of audio duration through MPRIS2" << m_audioPlayer->duration();
0366         if (!m_audioPlayer->source().isEmpty()) {
0367             m_metadata = getMetadataOfCurrentTrack();
0368             signalPropertiesChange(QStringLiteral("Metadata"), Metadata());
0369             signalPropertiesChange(QStringLiteral("CanPause"), CanPause());
0370             signalPropertiesChange(QStringLiteral("CanPlay"), CanPlay());
0371         }
0372 
0373         // for progress indicator on taskbar
0374         setPropertyPosition(static_cast<int>(m_audioPlayer->position()));
0375     }
0376 }
0377 
0378 void MediaPlayer2Player::playerVolumeChanged()
0379 {
0380     qCDebug(Mpris2Log) << "MediaPlayer2Player::playerVolumeChanged()";
0381     if (m_audioPlayer)
0382         setVolume(m_audioPlayer->volume() / 100.0);
0383 }
0384 
0385 void MediaPlayer2Player::playerCanPlayChanged()
0386 {
0387     qCDebug(Mpris2Log) << "MediaPlayer2Player::playerCanPlayChanged()";
0388     signalPropertiesChange(QStringLiteral("CanPlay"), CanPlay());
0389     // Q_EMIT canPlayChanged();
0390 }
0391 
0392 void MediaPlayer2Player::playerCanPauseChanged()
0393 {
0394     qCDebug(Mpris2Log) << "MediaPlayer2Player::playerCanPauseChanged()";
0395     signalPropertiesChange(QStringLiteral("CanPause"), CanPause());
0396     // Q_EMIT canPauseChanged();
0397 }
0398 
0399 void MediaPlayer2Player::playerCanGoNextChanged()
0400 {
0401     qCDebug(Mpris2Log) << "MediaPlayer2Player::playerCanGoNextChanged()";
0402     signalPropertiesChange(QStringLiteral("CanGoNext"), CanGoNext());
0403     // Q_EMIT canGoNextChanged();
0404 }
0405 
0406 void MediaPlayer2Player::playerCanGoPreviousChanged()
0407 {
0408     qCDebug(Mpris2Log) << "MediaPlayer2Player::playerCanGoPreviousChanged()";
0409     signalPropertiesChange(QStringLiteral("CanGoPrevious"), CanGoNext());
0410     // Q_EMIT canGoPreviousChanged();
0411 }
0412 
0413 void MediaPlayer2Player::playerCanSeekChanged()
0414 {
0415     qCDebug(Mpris2Log) << "MediaPlayer2Player::playerCanSeekChanged()";
0416     signalPropertiesChange(QStringLiteral("CanSeek"), CanSeek());
0417     // Q_EMIT canSeekChanged();
0418 }
0419 
0420 void MediaPlayer2Player::playerMetaDataChanged()
0421 {
0422     qCDebug(Mpris2Log) << "MediaPlayer2Player::playerMetaDataChanged()";
0423     m_metadata = getMetadataOfCurrentTrack();
0424     signalPropertiesChange(QStringLiteral("Metadata"), Metadata());
0425 }
0426 
0427 void MediaPlayer2Player::setSource(const QUrl &source)
0428 {
0429     qCDebug(Mpris2Log) << "MediaPlayer2Player::setSource(" << source << ")";
0430     if (source.isEmpty())
0431         return;
0432 
0433     if (m_audioPlayer) {
0434         if (!m_audioPlayer->source().isEmpty()) {
0435             if (m_audioPlayer->source() == source) {
0436                 int queuenr = 0; // TODO: figure out smart way to handle this
0437                 QString desktopName = QStringLiteral("/") + m_audioPlayer->desktopEntryName();
0438                 desktopName.replace(QStringLiteral("."), QStringLiteral("/"));
0439                 m_currentTrackId = QDBusObjectPath(desktopName + QLatin1String("/playlist/") + QString::number(queuenr)).path();
0440 
0441                 m_metadata = getMetadataOfCurrentTrack();
0442                 signalPropertiesChange(QStringLiteral("Metadata"), Metadata());
0443             }
0444         }
0445     }
0446 }
0447 
0448 QVariantMap MediaPlayer2Player::getMetadataOfCurrentTrack()
0449 {
0450     qCDebug(Mpris2Log) << "MediaPlayer2Player::getMetadataOfCurrentTrack()";
0451     auto result = QVariantMap();
0452 
0453     if (m_currentTrackId.isEmpty()) {
0454         return {};
0455     }
0456 
0457     if (!m_audioPlayer) {
0458         return {};
0459     }
0460 
0461     if (m_audioPlayer->source().isEmpty()) {
0462         return {};
0463     }
0464 
0465     result[QStringLiteral("mpris:trackid")] = QVariant::fromValue<QDBusObjectPath>(QDBusObjectPath(m_currentTrackId));
0466     result[QStringLiteral("mpris:length")] = qlonglong(m_audioPlayer->duration()) * 1000; // convert milli-seconds into micro-seconds
0467     if (!m_audioPlayer->metaData()->title().isEmpty()) {
0468         result[QStringLiteral("xesam:title")] = m_audioPlayer->metaData()->title();
0469     }
0470     if (!m_audioPlayer->metaData()->album().isEmpty()) {
0471         result[QStringLiteral("xesam:album")] = m_audioPlayer->metaData()->album();
0472     }
0473     if (!m_audioPlayer->metaData()->artist().isEmpty()) {
0474         result[QStringLiteral("xesam:artist")] = QStringList(m_audioPlayer->metaData()->artist());
0475     }
0476     if (!m_audioPlayer->metaData()->artworkUrl().isEmpty()) {
0477         result[QStringLiteral("mpris:artUrl")] = m_audioPlayer->metaData()->artworkUrl().toString();
0478     }
0479 
0480     return result;
0481 }
0482 
0483 void MediaPlayer2Player::setPropertyPosition(int newPositionInMs)
0484 {
0485     qCDebug(Mpris2Log) << "MediaPlayer2Player::setPropertyPosition(" << newPositionInMs << ")";
0486     // only needed for progressbar on taskbar (?)
0487     m_position = qlonglong(newPositionInMs) * 1000;
0488 
0489     /* only send new progress when it has advanced more than 1 %
0490      * to limit DBus traffic
0491      */
0492     const auto incrementalProgress = static_cast<double>(newPositionInMs - mPreviousProgressPosition) / m_audioPlayer->duration();
0493     if (mShowProgressOnTaskBar && (incrementalProgress > 0.01 || incrementalProgress < 0)) {
0494         mPreviousProgressPosition = newPositionInMs;
0495         QVariantMap parameters;
0496         parameters.insert(QStringLiteral("progress-visible"), true);
0497         parameters.insert(QStringLiteral("progress"), static_cast<double>(newPositionInMs) / m_audioPlayer->duration());
0498 
0499         const QString fullDesktopPath = QStringLiteral("application://") + m_audioPlayer->desktopEntryName() + QStringLiteral(".desktop");
0500         mProgressIndicatorSignal.setArguments({fullDesktopPath, parameters});
0501 
0502         QDBusConnection::sessionBus().send(mProgressIndicatorSignal);
0503     }
0504 }
0505 
0506 void MediaPlayer2Player::signalPropertiesChange(const QString &property, const QVariant &value)
0507 {
0508     qCDebug(Mpris2Log) << "MediaPlayer2Player::signalPropertiesChange(" << property << value << ")";
0509     // qDebug() << "mpris signal property change" << property << value;
0510     QVariantMap properties;
0511     properties[property] = value;
0512     const int ifaceIndex = metaObject()->indexOfClassInfo("D-Bus Interface");
0513     QDBusMessage msg = QDBusMessage::createSignal(QStringLiteral("/org/mpris/MediaPlayer2"),
0514                                                   QStringLiteral("org.freedesktop.DBus.Properties"),
0515                                                   QStringLiteral("PropertiesChanged"));
0516 
0517     msg << QLatin1String(metaObject()->classInfo(ifaceIndex).value());
0518     msg << properties;
0519     msg << QStringList();
0520 
0521     QDBusConnection::sessionBus().send(msg);
0522 }
0523 
0524 bool MediaPlayer2Player::showProgressOnTaskBar() const
0525 {
0526     qCDebug(Mpris2Log) << "MediaPlayer2Player::showProgressOnTaskBar()";
0527     return mShowProgressOnTaskBar;
0528 }
0529 
0530 void MediaPlayer2Player::setShowProgressOnTaskBar(bool value)
0531 {
0532     qCDebug(Mpris2Log) << "MediaPlayer2Player::setShowProgressOnTaskBar(" << value << ")";
0533     mShowProgressOnTaskBar = value;
0534 
0535     QVariantMap parameters;
0536 
0537     if (!mShowProgressOnTaskBar || m_audioPlayer->playbackState() == KMediaSession::StoppedState || m_audioPlayer->duration() == 0) {
0538         parameters.insert(QStringLiteral("progress-visible"), false);
0539         parameters.insert(QStringLiteral("progress"), 0);
0540     } else {
0541         parameters.insert(QStringLiteral("progress-visible"), true);
0542         parameters.insert(QStringLiteral("progress"), qRound(static_cast<double>(m_position / m_audioPlayer->duration())) / 1000.0);
0543     }
0544 
0545     const QString fullDesktopPath = QStringLiteral("application://") + m_audioPlayer->desktopEntryName() + QStringLiteral(".desktop");
0546     mProgressIndicatorSignal.setArguments({fullDesktopPath, parameters});
0547 
0548     QDBusConnection::sessionBus().send(mProgressIndicatorSignal);
0549 }