Commit 180ba8db authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

allow to activate/deactivate the progress indicator on task bar entry

Summary:
the Elisa application menu has an entry to activate or deactivate the
reporting of progress on the task bar entry (currently supported on
Plasma, Windows and linux environments supporting
com.canonical.Unity.LauncherEntry .

BUG: 406454

Test Plan: One can activate or deactive the progress reporting

Reviewers: #elisa, ngraham

Differential Revision: https://phabricator.kde.org/D20636
parent f8029640
......@@ -38,12 +38,14 @@ static const double MAX_RATE = 1.0;
static const double MIN_RATE = 1.0;
MediaPlayer2Player::MediaPlayer2Player(MediaPlayList *playListControler, ManageAudioPlayer *manageAudioPlayer,
ManageMediaPlayerControl *manageMediaPlayerControl, ManageHeaderBar *manageHeaderBar, AudioWrapper *audioPlayer, QObject* parent)
ManageMediaPlayerControl *manageMediaPlayerControl, ManageHeaderBar *manageHeaderBar,
AudioWrapper *audioPlayer, bool showProgressOnTaskBar, QObject* parent)
: QDBusAbstractAdaptor(parent), m_playListControler(playListControler), m_manageAudioPlayer(manageAudioPlayer),
m_manageMediaPlayerControl(manageMediaPlayerControl), m_manageHeaderBar(manageHeaderBar), m_audioPlayer(audioPlayer),
mProgressIndicatorSignal(QDBusMessage::createSignal(QStringLiteral("/org/kde/elisa"),
QStringLiteral("com.canonical.Unity.LauncherEntry"),
QStringLiteral("Update")))
QStringLiteral("Update"))),
mShowProgressOnTaskBar(showProgressOnTaskBar)
{
if (!m_playListControler) {
return;
......@@ -95,19 +97,21 @@ QString MediaPlayer2Player::PlaybackStatus() const
result = QStringLiteral("Paused");
}
QVariantMap parameters;
if (mShowProgressOnTaskBar) {
QVariantMap parameters;
if (m_manageAudioPlayer->playerPlaybackState() == QMediaPlayer::StoppedState || m_audioPlayer->duration() == 0) {
parameters.insert(QStringLiteral("progress-visible"), false);
parameters.insert(QStringLiteral("progress"), 0);
} else {
parameters.insert(QStringLiteral("progress-visible"), true);
parameters.insert(QStringLiteral("progress"), qRound(static_cast<double>(m_position / m_audioPlayer->duration())) / 1000.0);
}
if (m_manageAudioPlayer->playerPlaybackState() == QMediaPlayer::StoppedState || m_audioPlayer->duration() == 0) {
parameters.insert(QStringLiteral("progress-visible"), false);
parameters.insert(QStringLiteral("progress"), 0);
} else {
parameters.insert(QStringLiteral("progress-visible"), true);
parameters.insert(QStringLiteral("progress"), qRound(static_cast<double>(m_position / m_audioPlayer->duration())) / 1000.0);
}
mProgressIndicatorSignal.setArguments({QStringLiteral("application://org.kde.elisa.desktop"), parameters});
mProgressIndicatorSignal.setArguments({QStringLiteral("application://org.kde.elisa.desktop"), parameters});
QDBusConnection::sessionBus().send(mProgressIndicatorSignal);
QDBusConnection::sessionBus().send(mProgressIndicatorSignal);
}
return result;
}
......@@ -217,7 +221,7 @@ void MediaPlayer2Player::setPropertyPosition(int newPositionInMs)
* to limit DBus traffic
*/
const auto incrementalProgress = static_cast<double>(newPositionInMs - mPreviousProgressPosition) / m_audioPlayer->duration();
if (incrementalProgress > 0.01 || incrementalProgress < 0)
if (mShowProgressOnTaskBar && (incrementalProgress > 0.01 || incrementalProgress < 0))
{
mPreviousProgressPosition = newPositionInMs;
QVariantMap parameters;
......@@ -420,6 +424,30 @@ int MediaPlayer2Player::mediaPlayerPresent() const
return m_mediaPlayerPresent;
}
bool MediaPlayer2Player::showProgressOnTaskBar() const
{
return mShowProgressOnTaskBar;
}
void MediaPlayer2Player::setShowProgressOnTaskBar(bool value)
{
mShowProgressOnTaskBar = value;
QVariantMap parameters;
if (!mShowProgressOnTaskBar || m_manageAudioPlayer->playerPlaybackState() == QMediaPlayer::StoppedState || m_audioPlayer->duration() == 0) {
parameters.insert(QStringLiteral("progress-visible"), false);
parameters.insert(QStringLiteral("progress"), 0);
} else {
parameters.insert(QStringLiteral("progress-visible"), true);
parameters.insert(QStringLiteral("progress"), qRound(static_cast<double>(m_position / m_audioPlayer->duration())) / 1000.0);
}
mProgressIndicatorSignal.setArguments({QStringLiteral("application://org.kde.elisa.desktop"), parameters});
QDBusConnection::sessionBus().send(mProgressIndicatorSignal);
}
void MediaPlayer2Player::setMediaPlayerPresent(int status)
{
if (m_mediaPlayerPresent != status) {
......@@ -443,7 +471,7 @@ void MediaPlayer2Player::signalPropertiesChange(const QString &property, const Q
properties[property] = value;
const int ifaceIndex = metaObject()->indexOfClassInfo("D-Bus Interface");
QDBusMessage msg = QDBusMessage::createSignal(QStringLiteral("/org/mpris/MediaPlayer2"),
QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged"));
QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged"));
msg << QLatin1String(metaObject()->classInfo(ifaceIndex).value());
msg << properties;
......
......@@ -61,6 +61,7 @@ public:
ManageMediaPlayerControl* manageMediaPlayerControl,
ManageHeaderBar * manageHeaderBar,
AudioWrapper *audioPlayer,
bool showProgressOnTaskBar,
QObject* parent = nullptr);
~MediaPlayer2Player() override;
......@@ -80,6 +81,9 @@ public:
int currentTrack() const;
int mediaPlayerPresent() const;
bool showProgressOnTaskBar() const;
void setShowProgressOnTaskBar(bool value);
Q_SIGNALS:
void Seeked(qlonglong Position);
......@@ -162,6 +166,7 @@ private:
AudioWrapper *m_audioPlayer = nullptr;
mutable QDBusMessage mProgressIndicatorSignal;
int mPreviousProgressPosition = 0;
bool mShowProgressOnTaskBar = true;
};
#endif // MEDIAPLAYER2PLAYER_H
......@@ -57,7 +57,7 @@ void Mpris2::initDBusService()
if (success) {
m_mp2 = std::make_unique<MediaPlayer2>(this);
m_mp2p = std::make_unique<MediaPlayer2Player>(m_playListModel, m_manageAudioPlayer, m_manageMediaPlayerControl, m_manageHeaderBar, m_audioPlayer, this);
m_mp2p = std::make_unique<MediaPlayer2Player>(m_playListModel, m_manageAudioPlayer, m_manageMediaPlayerControl, m_manageHeaderBar, m_audioPlayer, mShowProgressOnTaskBar, this);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/mpris/MediaPlayer2"), this, QDBusConnection::ExportAdaptors);
......@@ -98,6 +98,11 @@ AudioWrapper *Mpris2::audioPlayer() const
return m_audioPlayer;
}
bool Mpris2::showProgressOnTaskBar() const
{
return mShowProgressOnTaskBar;
}
void Mpris2::setPlayerName(const QString &playerName)
{
if (m_playerName == playerName) {
......@@ -198,4 +203,11 @@ void Mpris2::setAudioPlayer(AudioWrapper *audioPlayer)
emit audioPlayerChanged();
}
void Mpris2::setShowProgressOnTaskBar(bool value)
{
m_mp2p->setShowProgressOnTaskBar(value);
mShowProgressOnTaskBar = value;
Q_EMIT showProgressOnTaskBarChanged();
}
#include "moc_mpris2.cpp"
......@@ -70,6 +70,11 @@ class ELISALIB_EXPORT Mpris2 : public QObject
WRITE setAudioPlayer
NOTIFY audioPlayerChanged)
Q_PROPERTY(bool showProgressOnTaskBar
READ showProgressOnTaskBar
WRITE setShowProgressOnTaskBar
NOTIFY showProgressOnTaskBarChanged)
public:
explicit Mpris2(QObject* parent = nullptr);
~Mpris2() override;
......@@ -86,6 +91,8 @@ public:
AudioWrapper* audioPlayer() const;
bool showProgressOnTaskBar() const;
public Q_SLOTS:
void setPlayerName(const QString &playerName);
......@@ -100,6 +107,8 @@ public Q_SLOTS:
void setAudioPlayer(AudioWrapper* audioPlayer);
void setShowProgressOnTaskBar(bool value);
Q_SIGNALS:
void raisePlayer();
......@@ -115,6 +124,8 @@ Q_SIGNALS:
void audioPlayerChanged();
void showProgressOnTaskBarChanged();
private:
void initDBusService();
......@@ -127,6 +138,7 @@ private:
ManageMediaPlayerControl* m_manageMediaPlayerControl = nullptr;
ManageHeaderBar* m_manageHeaderBar = nullptr;
AudioWrapper* m_audioPlayer = nullptr;
bool mShowProgressOnTaskBar = true;
};
#endif //MEDIACENTER_MPRIS2_H
......@@ -63,6 +63,12 @@ Menu {
}
}
MenuItem {
text: mainWindow.showProgressOnTaskBar ? i18nc("Do not show progress on task bar menu entry in the elisa menu", "Do Not Show Progress on Task Bar Entries") :
i18nc("Show Progress on Task Bar Entries entry in the elisa menu", "Show Progress on Task Bar Entries")
onTriggered: mainWindow.showProgressOnTaskBar = !mainWindow.showProgressOnTaskBar
}
MenuSeparator {
visible: reportBugAction.text !== ""
}
......
......@@ -38,6 +38,8 @@ ApplicationWindow {
width: persistentSettings.width
height: persistentSettings.height
property bool showProgressOnTaskBar: persistentSettings.showProgressOnTaskBar
title: i18n("Elisa")
Accessible.role: Accessible.Application
......@@ -107,6 +109,8 @@ ApplicationWindow {
property bool showPlaylist: true
property bool headerBarIsMaximized: false
property bool showProgressOnTaskBar: true
}
Connections {
......@@ -138,6 +142,8 @@ ApplicationWindow {
persistentSettings.showPlaylist = contentView.showPlaylist
persistentSettings.headerBarIsMaximized = headerBar.isMaximized
persistentSettings.showProgressOnTaskBar = showProgressOnTaskBar
}
}
......@@ -153,6 +159,8 @@ ApplicationWindow {
player: elisa.audioPlayer
headerBarManager: elisa.manageHeaderBar
manageMediaPlayerControl: elisa.playerControl
showProgressOnTaskBar: mainWindow.showProgressOnTaskBar
onRaisePlayer: {
mainWindow.show()
mainWindow.raise()
......
......@@ -27,6 +27,7 @@ Item {
property alias player: mpris2Interface.audioPlayer
property alias headerBarManager: mpris2Interface.headerBarManager
property alias manageMediaPlayerControl: mpris2Interface.manageMediaPlayerControl
property alias showProgressOnTaskBar: mpris2Interface.showProgressOnTaskBar
signal raisePlayer()
......
......@@ -27,6 +27,7 @@ Item {
property var player
property var headerBarManager
property var manageMediaPlayerControl
property alias showProgressOnTaskBar: progressBar.active
signal raisePlayer()
......@@ -34,14 +35,24 @@ Item {
id: elisaTheme
}
TaskbarButton {
progress.minimum: 0
progress.maximum: player.duration
progress.value: player.position
progress.visible: manageMediaPlayerControl.musicPlaying
Loader {
id: progressBar
overlay.iconSource: (manageMediaPlayerControl.musicPlaying ?
Qt.resolvedUrl(elisaTheme.playingIndicatorIcon) : Qt.resolvedUrl(elisaTheme.pausedIndicatorIcon))
sourceComponent: taskBarComponent
}
Component {
id:taskBarComponent
TaskbarButton {
progress.minimum: 0
progress.maximum: player.duration
progress.value: player.position
progress.visible: manageMediaPlayerControl.musicPlaying
overlay.iconSource: (manageMediaPlayerControl.musicPlaying ?
Qt.resolvedUrl(elisaTheme.playingIndicatorIcon) : Qt.resolvedUrl(elisaTheme.pausedIndicatorIcon))
}
}
ThumbnailToolBar {
......
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