Changeset View
Changeset View
Standalone View
Standalone View
dataengines/mpris2/multiplexedservice.cpp
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 79 | { | |||
---|---|---|---|---|---|
84 | m_actionCollection = new KActionCollection(this, QStringLiteral("mediacontrol")); | 84 | m_actionCollection = new KActionCollection(this, QStringLiteral("mediacontrol")); | ||
85 | m_actionCollection->setComponentDisplayName(i18nc("Name for global shortcuts category", "Media Controller")); | 85 | m_actionCollection->setComponentDisplayName(i18nc("Name for global shortcuts category", "Media Controller")); | ||
86 | QAction *playPauseAction = m_actionCollection->addAction(QStringLiteral("playpausemedia")); | 86 | QAction *playPauseAction = m_actionCollection->addAction(QStringLiteral("playpausemedia")); | ||
87 | playPauseAction->setText(i18n("Play/Pause media playback")); | 87 | playPauseAction->setText(i18n("Play/Pause media playback")); | ||
88 | KGlobalAccel::setGlobalShortcut(playPauseAction, Qt::Key_MediaPlay); | 88 | KGlobalAccel::setGlobalShortcut(playPauseAction, Qt::Key_MediaPlay); | ||
89 | connect(playPauseAction, &QAction::triggered, this, | 89 | connect(playPauseAction, &QAction::triggered, this, | ||
90 | [this] { | 90 | [this] { | ||
91 | if (m_control) { | 91 | if (m_control) { | ||
92 | m_control->playerInterface()->PlayPause(); | 92 | auto playerInterface = m_control->playerInterface(); | ||
93 | if (playerInterface->canControl()) { | ||||
94 | if (playerInterface->canPause()) { | ||||
95 | playerInterface->PlayPause(); | ||||
96 | } else if (playerInterface->canPlay()) { | ||||
97 | playerInterface->Play(); | ||||
98 | } | ||||
99 | } | ||||
93 | } | 100 | } | ||
94 | } | 101 | } | ||
95 | ); | 102 | ); | ||
96 | 103 | | |||
97 | QAction *nextAction = m_actionCollection->addAction(QStringLiteral("nextmedia")); | 104 | QAction *nextAction = m_actionCollection->addAction(QStringLiteral("nextmedia")); | ||
98 | nextAction->setText(i18n("Media playback next")); | 105 | nextAction->setText(i18n("Media playback next")); | ||
99 | KGlobalAccel::setGlobalShortcut(nextAction, Qt::Key_MediaNext); | 106 | KGlobalAccel::setGlobalShortcut(nextAction, Qt::Key_MediaNext); | ||
100 | connect(nextAction, &QAction::triggered, this, | 107 | connect(nextAction, &QAction::triggered, this, | ||
101 | [this] { | 108 | [this] { | ||
102 | if (m_control) { | 109 | if (m_control) { | ||
103 | m_control->playerInterface()->Next(); | 110 | auto playerInterface = m_control->playerInterface(); | ||
111 | if (playerInterface->canControl() && playerInterface->canGoNext()) { | ||||
112 | playerInterface->Next(); | ||||
113 | } | ||||
104 | } | 114 | } | ||
105 | } | 115 | } | ||
106 | ); | 116 | ); | ||
107 | 117 | | |||
108 | QAction *previousAction = m_actionCollection->addAction(QStringLiteral("previousmedia")); | 118 | QAction *previousAction = m_actionCollection->addAction(QStringLiteral("previousmedia")); | ||
109 | previousAction->setText(i18n("Media playback previous")); | 119 | previousAction->setText(i18n("Media playback previous")); | ||
110 | KGlobalAccel::setGlobalShortcut(previousAction, Qt::Key_MediaPrevious); | 120 | KGlobalAccel::setGlobalShortcut(previousAction, Qt::Key_MediaPrevious); | ||
111 | connect(previousAction, &QAction::triggered, this, | 121 | connect(previousAction, &QAction::triggered, this, | ||
112 | [this] { | 122 | [this] { | ||
113 | if (m_control) { | 123 | if (m_control) { | ||
114 | m_control->playerInterface()->Previous(); | 124 | auto playerInterface = m_control->playerInterface(); | ||
125 | if (playerInterface->canControl() && playerInterface->canGoPrevious()) { | ||||
126 | playerInterface->Previous(); | ||||
127 | } | ||||
115 | } | 128 | } | ||
116 | } | 129 | } | ||
117 | ); | 130 | ); | ||
118 | 131 | | |||
119 | QAction *stopAction = m_actionCollection->addAction(QStringLiteral("stopmedia")); | 132 | QAction *stopAction = m_actionCollection->addAction(QStringLiteral("stopmedia")); | ||
120 | stopAction->setText(i18n("Stop media playback")); | 133 | stopAction->setText(i18n("Stop media playback")); | ||
121 | KGlobalAccel::setGlobalShortcut(stopAction, Qt::Key_MediaStop); | 134 | KGlobalAccel::setGlobalShortcut(stopAction, Qt::Key_MediaStop); | ||
122 | connect(stopAction, &QAction::triggered, this, | 135 | connect(stopAction, &QAction::triggered, this, | ||
123 | [this] { | 136 | [this] { | ||
124 | if (m_control) { | 137 | if (m_control) { | ||
125 | m_control->playerInterface()->Stop(); | 138 | auto playerInterface = m_control->playerInterface(); | ||
139 | if (playerInterface->canControl()) { | ||||
140 | playerInterface->Stop(); | ||||
141 | } | ||||
126 | } | 142 | } | ||
127 | } | 143 | } | ||
128 | ); | 144 | ); | ||
129 | } | 145 | } | ||
130 | 146 | |