Commit 7bd909fa authored by David Edmundson's avatar David Edmundson

Only enable MPRIS global shortcuts on demand

Summary:
The lockscreen uses the MPRIS dataengine. This leads to two applications
registring the service using the same component name which leads to the
shortcuts not working when the lock screen closes.

We want to have the applet register the shortcuts, but not every
dataengine user.

Ideally this shouldn't be in the dataengine either because DataEngines
are read only. This moves the logic to the service which is writable and
registers the shortcuts for the multiplexer there when requested from
the applet.

BUG: 380526
FIXED-IN: 5.10.1

Test Plan:
Opened media player.
Used play/pause shortcut. (the only one my keyboard has)

Reviewers: #plasma, broulik

Reviewed By: #plasma, broulik

Subscribers: broulik, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D6100
parent 8cc06c36
......@@ -184,6 +184,10 @@ Item {
}
}
Component.onCompleted: {
mpris2Source.serviceForSource("@multiplex").enableGlobalShortcuts();
}
function action_open() {
serviceOp(mpris2Source.current, "Raise");
}
......
......@@ -21,6 +21,11 @@
#include "multiplexer.h"
#include "playercontrol.h"
#include <mprisplayer.h>
#include <KLocalizedString>
#include <KActionCollection>
#include <KGlobalAccel>
MultiplexedService::MultiplexedService(Multiplexer *multiplexer, QObject *parent)
: Plasma::Service(parent)
......@@ -70,3 +75,56 @@ void MultiplexedService::activePlayerChanged(PlayerContainer *container)
updateEnabledOperations();
}
void MultiplexedService::enableGlobalShortcuts()
{
if (m_actionCollection) {
return;
}
m_actionCollection = new KActionCollection(this, QStringLiteral("mediacontrol"));
m_actionCollection->setComponentDisplayName(i18nc("Name for global shortcuts category", "Media Controller"));
QAction *playPauseAction = m_actionCollection->addAction(QStringLiteral("playpausemedia"));
playPauseAction->setText(i18n("Play/Pause media playback"));
KGlobalAccel::setGlobalShortcut(playPauseAction, Qt::Key_MediaPlay);
connect(playPauseAction, &QAction::triggered, this,
[this] {
if (m_control) {
m_control->playerInterface()->PlayPause();
}
}
);
QAction *nextAction = m_actionCollection->addAction(QStringLiteral("nextmedia"));
nextAction->setText(i18n("Media playback next"));
KGlobalAccel::setGlobalShortcut(nextAction, Qt::Key_MediaNext);
connect(nextAction, &QAction::triggered, this,
[this] {
if (m_control) {
m_control->playerInterface()->Next();
}
}
);
QAction *previousAction = m_actionCollection->addAction(QStringLiteral("previousmedia"));
previousAction->setText(i18n("Media playback previous"));
KGlobalAccel::setGlobalShortcut(previousAction, Qt::Key_MediaPrevious);
connect(previousAction, &QAction::triggered, this,
[this] {
if (m_control) {
m_control->playerInterface()->Previous();
}
}
);
QAction *stopAction = m_actionCollection->addAction(QStringLiteral("stopmedia"));
stopAction->setText(i18n("Stop media playback"));
KGlobalAccel::setGlobalShortcut(stopAction, Qt::Key_MediaStop);
connect(stopAction, &QAction::triggered, this,
[this] {
if (m_control) {
m_control->playerInterface()->Stop();
}
}
);
}
......@@ -26,6 +26,7 @@
class Multiplexer;
class PlayerControl;
class KActionCollection;
class MultiplexedService : public Plasma::Service
{
......@@ -38,12 +39,16 @@ protected:
Plasma::ServiceJob *createJob(const QString &operation,
QMap<QString,QVariant> &parameters) override;
public Q_SLOTS:
void enableGlobalShortcuts();
private Q_SLOTS:
void updateEnabledOperations();
void activePlayerChanged(PlayerContainer *container);
private:
QPointer<PlayerControl> m_control;
KActionCollection *m_actionCollection = nullptr;
};
#endif // MULTIPLEXEDSERVICE_H
......@@ -20,8 +20,6 @@
#include "multiplexer.h"
#include <mprisplayer.h>
#include <KActionCollection>
#include <KGlobalAccel>
#include <KLocalizedString>
#include <QDebug> // for Q_ASSERT
......@@ -36,53 +34,6 @@ Multiplexer::Multiplexer(QObject* parent)
: DataContainer(parent)
{
setObjectName(sourceName);
// setup actions
KActionCollection *actionCollection = new KActionCollection(this, QStringLiteral("mediacontrol"));
actionCollection->setComponentDisplayName(i18nc("Name for global shortcuts category", "Media Controller"));
QAction *playPauseAction = actionCollection->addAction(QStringLiteral("playpausemedia"));
playPauseAction->setText(i18n("Play/Pause media playback"));
KGlobalAccel::setGlobalShortcut(playPauseAction, Qt::Key_MediaPlay);
connect(playPauseAction, &QAction::triggered, this,
[this] {
if (PlayerContainer *active = activePlayer()) {
active->playerInterface()->PlayPause();
}
}
);
QAction *nextAction = actionCollection->addAction(QStringLiteral("nextmedia"));
nextAction->setText(i18n("Media playback next"));
KGlobalAccel::setGlobalShortcut(nextAction, Qt::Key_MediaNext);
connect(nextAction, &QAction::triggered, this,
[this] {
if (PlayerContainer *active = activePlayer()) {
active->playerInterface()->Next();
}
}
);
QAction *previousAction = actionCollection->addAction(QStringLiteral("previousmedia"));
previousAction->setText(i18n("Media playback previous"));
KGlobalAccel::setGlobalShortcut(previousAction, Qt::Key_MediaPrevious);
connect(previousAction, &QAction::triggered, this,
[this] {
if (PlayerContainer *active = activePlayer()) {
active->playerInterface()->Previous();
}
}
);
QAction *stopAction = actionCollection->addAction(QStringLiteral("stopmedia"));
stopAction->setText(i18n("Stop media playback"));
KGlobalAccel::setGlobalShortcut(stopAction, Qt::Key_MediaStop);
connect(stopAction, &QAction::triggered, this,
[this] {
if (PlayerContainer *active = activePlayer()) {
active->playerInterface()->Stop();
}
}
);
}
void Multiplexer::addPlayer(PlayerContainer *container)
......
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