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->playbackStatus() == QLatin1String("Playing")) { | ||||
95 | if (playerInterface->canPause()) { | ||||
96 | playerInterface->Pause(); | ||||
97 | } | ||||
98 | } else { | ||||
99 | if (playerInterface->canPlay()) { | ||||
100 | playerInterface->Play(); | ||||
101 | } | ||||
102 | } | ||||
103 | } | ||||
93 | } | 104 | } | ||
94 | } | 105 | } | ||
95 | ); | 106 | ); | ||
96 | 107 | | |||
97 | QAction *nextAction = m_actionCollection->addAction(QStringLiteral("nextmedia")); | 108 | QAction *nextAction = m_actionCollection->addAction(QStringLiteral("nextmedia")); | ||
98 | nextAction->setText(i18n("Media playback next")); | 109 | nextAction->setText(i18n("Media playback next")); | ||
99 | KGlobalAccel::setGlobalShortcut(nextAction, Qt::Key_MediaNext); | 110 | KGlobalAccel::setGlobalShortcut(nextAction, Qt::Key_MediaNext); | ||
100 | connect(nextAction, &QAction::triggered, this, | 111 | connect(nextAction, &QAction::triggered, this, | ||
101 | [this] { | 112 | [this] { | ||
102 | if (m_control) { | 113 | if (m_control) { | ||
103 | m_control->playerInterface()->Next(); | 114 | auto playerInterface = m_control->playerInterface(); | ||
115 | if (playerInterface->canControl() && playerInterface->canGoNext()) { | ||||
116 | playerInterface->Next(); | ||||
117 | } | ||||
104 | } | 118 | } | ||
105 | } | 119 | } | ||
106 | ); | 120 | ); | ||
107 | 121 | | |||
108 | QAction *previousAction = m_actionCollection->addAction(QStringLiteral("previousmedia")); | 122 | QAction *previousAction = m_actionCollection->addAction(QStringLiteral("previousmedia")); | ||
109 | previousAction->setText(i18n("Media playback previous")); | 123 | previousAction->setText(i18n("Media playback previous")); | ||
110 | KGlobalAccel::setGlobalShortcut(previousAction, Qt::Key_MediaPrevious); | 124 | KGlobalAccel::setGlobalShortcut(previousAction, Qt::Key_MediaPrevious); | ||
111 | connect(previousAction, &QAction::triggered, this, | 125 | connect(previousAction, &QAction::triggered, this, | ||
112 | [this] { | 126 | [this] { | ||
113 | if (m_control) { | 127 | if (m_control) { | ||
114 | m_control->playerInterface()->Previous(); | 128 | auto playerInterface = m_control->playerInterface(); | ||
129 | if (playerInterface->canControl() && playerInterface->canGoPrevious()) { | ||||
130 | playerInterface->Previous(); | ||||
131 | } | ||||
115 | } | 132 | } | ||
116 | } | 133 | } | ||
117 | ); | 134 | ); | ||
118 | 135 | | |||
119 | QAction *stopAction = m_actionCollection->addAction(QStringLiteral("stopmedia")); | 136 | QAction *stopAction = m_actionCollection->addAction(QStringLiteral("stopmedia")); | ||
120 | stopAction->setText(i18n("Stop media playback")); | 137 | stopAction->setText(i18n("Stop media playback")); | ||
121 | KGlobalAccel::setGlobalShortcut(stopAction, Qt::Key_MediaStop); | 138 | KGlobalAccel::setGlobalShortcut(stopAction, Qt::Key_MediaStop); | ||
122 | connect(stopAction, &QAction::triggered, this, | 139 | connect(stopAction, &QAction::triggered, this, | ||
123 | [this] { | 140 | [this] { | ||
124 | if (m_control) { | 141 | if (m_control) { | ||
125 | m_control->playerInterface()->Stop(); | 142 | auto playerInterface = m_control->playerInterface(); | ||
143 | if (playerInterface->canControl()) { | ||||
144 | playerInterface->Stop(); | ||||
145 | } | ||||
126 | } | 146 | } | ||
127 | } | 147 | } | ||
128 | ); | 148 | ); | ||
129 | } | 149 | } | ||
130 | 150 | |