Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

MPRIS: for images report the slideshow interval as well as timer resets

Summary:
Setting "mpris:length" "Metadata" property of images matching the interval of the
slideshow, signalling resets of the "Position" and delivering the
current timeout progress in the autoadvance timer, all that allows
MPRIS controllers to show the timely progress in the slideshow.

Supporting the same for video files is left-out for now, that needs
some bigger refactoring to have this information properly modelled
by the slideshow object.

((The Plasma media controller applet of <= 5.12 sadly only shows time
progress information if CanSeek=true. That got fixed for Plasma 5.13,
which will show a read-only progressbar instead of a slider))

Reviewers: #gwenview, rkflx

Reviewed By: #gwenview, rkflx

Subscribers: rkflx

Differential Revision: https://phabricator.kde.org/D11359
parent 8d61a5b9
......@@ -65,6 +65,8 @@ MprisMediaPlayer2Player::MprisMediaPlayer2Player(const QString &objectDBusPath,
connect(mSlideShow, &SlideShow::stateChanged,
this, &MprisMediaPlayer2Player::onSlideShowStateChanged);
connect(mSlideShow, &SlideShow::intervalChanged,
this, &MprisMediaPlayer2Player::onMetaInfoUpdated);
connect(mContextManager, &ContextManager::currentUrlChanged,
this, &MprisMediaPlayer2Player::onCurrentUrlChanged);
connect(mSlideShow->randomAction(), &QAction::toggled,
......@@ -184,7 +186,8 @@ QVariantMap MprisMediaPlayer2Player::metadata() const
qlonglong MprisMediaPlayer2Player::position() const
{
return 0;
// milliseconds -> microseconds
return mSlideShow->position() * 1000;
}
double MprisMediaPlayer2Player::rate() const
......@@ -245,6 +248,7 @@ void MprisMediaPlayer2Player::onSlideShowStateChanged()
return;
}
signalPropertyChange("Position", position());
signalPropertyChange("PlaybackStatus", mPlaybackStatus);
}
......@@ -259,6 +263,7 @@ void MprisMediaPlayer2Player::onCurrentUrlChanged(const QUrl& url)
}
onMetaInfoUpdated();
signalPropertyChange("Position", position());
}
void MprisMediaPlayer2Player::onMetaInfoUpdated()
......@@ -280,10 +285,9 @@ void MprisMediaPlayer2Player::onMetaInfoUpdated()
// TODO: for videos also get and report the length
if (MimeTypeUtils::urlKind(url) != MimeTypeUtils::KIND_VIDEO) {
// TODO: implement other MPRIS API for position
// convert seconds in microseconds
// const qlonglong duration = qlonglong(mSlideShow->interval() * 1000000);
// updatedMetaData.insert(QStringLiteral("mpris:length"), duration);
const qlonglong duration = qlonglong(mSlideShow->interval() * 1000000);
updatedMetaData.insert(QStringLiteral("mpris:length"), duration);
}
// TODO: update on metadata changes, given user can edit most of this data
......@@ -329,6 +333,7 @@ void MprisMediaPlayer2Player::onFullScreenActionToggled()
return;
}
signalPropertyChange("Position", position());
signalPropertyChange("PlaybackStatus", mPlaybackStatus);
}
......@@ -346,6 +351,7 @@ void MprisMediaPlayer2Player::onToggleSlideShowActionChanged()
signalPropertyChange("CanPlay", mSlideShowEnabled);
signalPropertyChange("CanPause", mSlideShowEnabled);
if (playbackStatusChanged) {
signalPropertyChange("Position", position());
signalPropertyChange("PlaybackStatus", mPlaybackStatus);
}
}
......
......@@ -238,6 +238,7 @@ void SlideShow::setInterval(int intervalInSeconds)
{
GwenviewConfig::setInterval(double(intervalInSeconds));
d->updateTimerInterval();
emit intervalChanged(intervalInSeconds);
}
int SlideShow::interval() const
......@@ -245,6 +246,24 @@ int SlideShow::interval() const
return GwenviewConfig::interval();
}
int SlideShow::position() const
{
// TODO: also support videos
// QTimer::remainingTime() returns -1 if inactive
// and there are moments where mState == Started but timer already done but not yet next url reached
// so handle that
if (d->mState == Started) {
if (d->mTimer->isActive()) {
return interval() * 1000 - d->mTimer->remainingTime();
}
// already timeout reached, but not yet progressed to next url
return interval();
}
return 0;
}
void SlideShow::stop()
{
LOG("Stopping timer");
......
......@@ -51,7 +51,14 @@ public:
/** @return true if the slideshow is running */
bool isRunning() const;
/**
* @return interval in seconds
*/
int interval() const;
/**
* @return position in time slot for current image in milliseconds
*/
int position() const;
public Q_SLOTS:
void setInterval(int);
......@@ -68,6 +75,11 @@ Q_SIGNALS:
* Slideshow has been started or stopped
*/
void stateChanged(bool running);
/**
* Emitted when interval has been changed
* @param interval interval in seconds
*/
void intervalChanged(int interval);
private Q_SLOTS:
void goToNextUrl();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment