Changeset View
Changeset View
Standalone View
Standalone View
src/mpris2/mediaplayer2player.cpp
Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Line(s) | 77 | { | |||
---|---|---|---|---|---|
93 | return result; | 93 | return result; | ||
94 | } | 94 | } | ||
95 | 95 | | |||
96 | bool MediaPlayer2Player::CanGoNext() const | 96 | bool MediaPlayer2Player::CanGoNext() const | ||
97 | { | 97 | { | ||
98 | return m_canGoNext; | 98 | return m_canGoNext; | ||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | void MediaPlayer2Player::Next() const | 101 | void MediaPlayer2Player::Next() | ||
102 | { | 102 | { | ||
103 | emit next(); | 103 | emit next(); | ||
104 | 104 | | |||
105 | if (m_playListControler) { | 105 | if (m_playListControler) { | ||
106 | m_playListControler->skipNextTrack(); | 106 | m_playListControler->skipNextTrack(); | ||
107 | } | 107 | } | ||
108 | } | 108 | } | ||
109 | 109 | | |||
110 | bool MediaPlayer2Player::CanGoPrevious() const | 110 | bool MediaPlayer2Player::CanGoPrevious() const | ||
111 | { | 111 | { | ||
112 | return m_canGoPrevious; | 112 | return m_canGoPrevious; | ||
113 | } | 113 | } | ||
114 | 114 | | |||
115 | void MediaPlayer2Player::Previous() const | 115 | void MediaPlayer2Player::Previous() | ||
116 | { | 116 | { | ||
117 | emit previous(); | 117 | emit previous(); | ||
118 | 118 | | |||
119 | if (m_playListControler) { | 119 | if (m_playListControler) { | ||
120 | m_playListControler->skipPreviousTrack(); | 120 | m_playListControler->skipPreviousTrack(); | ||
121 | } | 121 | } | ||
122 | } | 122 | } | ||
123 | 123 | | |||
124 | bool MediaPlayer2Player::CanPause() const | 124 | bool MediaPlayer2Player::CanPause() const | ||
125 | { | 125 | { | ||
126 | return !m_canPlay; | 126 | return !m_canPlay; | ||
127 | } | 127 | } | ||
128 | 128 | | |||
129 | void MediaPlayer2Player::Pause() const | 129 | void MediaPlayer2Player::Pause() | ||
130 | { | 130 | { | ||
131 | if (m_playListControler) { | 131 | if (m_playListControler) { | ||
132 | m_manageAudioPlayer->playPause(); | 132 | m_manageAudioPlayer->playPause(); | ||
133 | } | 133 | } | ||
134 | } | 134 | } | ||
135 | 135 | | |||
136 | void MediaPlayer2Player::PlayPause() | 136 | void MediaPlayer2Player::PlayPause() | ||
137 | { | 137 | { | ||
138 | emit playPause(); | 138 | emit playPause(); | ||
139 | 139 | | |||
140 | if (m_playListControler) { | 140 | if (m_playListControler) { | ||
141 | m_manageAudioPlayer->playPause(); | 141 | m_manageAudioPlayer->playPause(); | ||
142 | } | 142 | } | ||
143 | } | 143 | } | ||
144 | 144 | | |||
145 | void MediaPlayer2Player::Stop() const | 145 | void MediaPlayer2Player::Stop() | ||
146 | { | 146 | { | ||
147 | emit stop(); | 147 | emit stop(); | ||
148 | } | 148 | } | ||
149 | 149 | | |||
150 | bool MediaPlayer2Player::CanPlay() const | 150 | bool MediaPlayer2Player::CanPlay() const | ||
151 | { | 151 | { | ||
152 | return m_canPlay; | 152 | return m_canPlay; | ||
153 | } | 153 | } | ||
154 | 154 | | |||
155 | void MediaPlayer2Player::Play() const | 155 | void MediaPlayer2Player::Play() | ||
156 | { | 156 | { | ||
157 | if (m_playListControler) { | 157 | if (m_playListControler) { | ||
158 | m_manageAudioPlayer->playPause(); | 158 | m_manageAudioPlayer->playPause(); | ||
159 | } | 159 | } | ||
160 | } | 160 | } | ||
161 | 161 | | |||
162 | double MediaPlayer2Player::Volume() const | 162 | double MediaPlayer2Player::Volume() const | ||
163 | { | 163 | { | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 223 | { | |||
224 | return m_playerIsSeekableChanged; | 224 | return m_playerIsSeekableChanged; | ||
225 | } | 225 | } | ||
226 | 226 | | |||
227 | bool MediaPlayer2Player::CanControl() const | 227 | bool MediaPlayer2Player::CanControl() const | ||
228 | { | 228 | { | ||
229 | return true; | 229 | return true; | ||
230 | } | 230 | } | ||
231 | 231 | | |||
232 | void MediaPlayer2Player::Seek(qlonglong Offset) const | 232 | void MediaPlayer2Player::Seek(qlonglong Offset) | ||
233 | { | 233 | { | ||
234 | if (mediaPlayerPresent()) { | 234 | if (mediaPlayerPresent()) { | ||
235 | int offset = (m_position + Offset) / 1000; | 235 | int offset = (m_position + Offset) / 1000; | ||
236 | m_manageAudioPlayer->playerSeek(offset); | 236 | m_manageAudioPlayer->playerSeek(offset); | ||
237 | } | 237 | } | ||
238 | } | 238 | } | ||
239 | 239 | | |||
240 | void MediaPlayer2Player::emitSeeked(int pos) | 240 | void MediaPlayer2Player::emitSeeked(int pos) | ||
241 | { | 241 | { | ||
242 | emit Seeked(qlonglong(pos) * 1000); | 242 | emit Seeked(qlonglong(pos) * 1000); | ||
243 | } | 243 | } | ||
244 | 244 | | |||
245 | void MediaPlayer2Player::SetPosition(const QDBusObjectPath &trackId, qlonglong pos) const | 245 | void MediaPlayer2Player::SetPosition(const QDBusObjectPath &trackId, qlonglong pos) | ||
246 | { | 246 | { | ||
247 | if (trackId.path() == m_currentTrackId) { | 247 | if (trackId.path() == m_currentTrackId) { | ||
248 | m_manageAudioPlayer->playerSeek(pos / 1000); | 248 | m_manageAudioPlayer->playerSeek(pos / 1000); | ||
249 | } | 249 | } | ||
250 | } | 250 | } | ||
251 | 251 | | |||
252 | void MediaPlayer2Player::OpenUri(const QString &uri) const | 252 | void MediaPlayer2Player::OpenUri(const QString &uri) | ||
253 | { | 253 | { | ||
254 | Q_UNUSED(uri); | 254 | Q_UNUSED(uri); | ||
255 | } | 255 | } | ||
256 | 256 | | |||
257 | void MediaPlayer2Player::playerSourceChanged() | 257 | void MediaPlayer2Player::playerSourceChanged() | ||
258 | { | 258 | { | ||
259 | if (!m_playListControler) { | 259 | if (!m_playListControler) { | ||
260 | return; | 260 | return; | ||
261 | } | 261 | } | ||
262 | 262 | | |||
263 | setCurrentTrack(m_manageAudioPlayer->playListPosition()); | 263 | setCurrentTrack(m_manageAudioPlayer->playListPosition()); | ||
264 | } | 264 | } | ||
265 | 265 | | |||
266 | void MediaPlayer2Player::playControlEnabledChanged() | 266 | void MediaPlayer2Player::playControlEnabledChanged() | ||
267 | { | 267 | { | ||
268 | if (!m_playListControler) { | 268 | if (!m_playListControler) { | ||
269 | return; | 269 | return; | ||
270 | } | 270 | } | ||
271 | 271 | | |||
272 | m_canPlay = m_manageMediaPlayerControl->playControlEnabled(); | 272 | m_canPlay = m_manageMediaPlayerControl->playControlEnabled(); | ||
273 | 273 | | |||
274 | signalPropertiesChange(QStringLiteral("CanPause"), CanPause()); | 274 | signalPropertiesChange(QStringLiteral("CanPause"), CanPause()); | ||
275 | signalPropertiesChange(QStringLiteral("CanPlay"), CanPlay()); | 275 | signalPropertiesChange(QStringLiteral("CanPlay"), CanPlay()); | ||
276 | | ||||
277 | emit canPauseChanged(); | ||||
278 | emit canPlayChanged(); | ||||
276 | } | 279 | } | ||
277 | 280 | | |||
278 | void MediaPlayer2Player::skipBackwardControlEnabledChanged() | 281 | void MediaPlayer2Player::skipBackwardControlEnabledChanged() | ||
279 | { | 282 | { | ||
280 | if (!m_playListControler) { | 283 | if (!m_playListControler) { | ||
281 | return; | 284 | return; | ||
282 | } | 285 | } | ||
283 | 286 | | |||
284 | m_canGoPrevious = m_manageMediaPlayerControl->skipBackwardControlEnabled(); | 287 | m_canGoPrevious = m_manageMediaPlayerControl->skipBackwardControlEnabled(); | ||
285 | 288 | | |||
286 | signalPropertiesChange(QStringLiteral("CanGoPrevious"), CanGoPrevious()); | 289 | signalPropertiesChange(QStringLiteral("CanGoPrevious"), CanGoPrevious()); | ||
290 | emit canGoPreviousChanged(); | ||||
287 | } | 291 | } | ||
288 | 292 | | |||
289 | void MediaPlayer2Player::skipForwardControlEnabledChanged() | 293 | void MediaPlayer2Player::skipForwardControlEnabledChanged() | ||
290 | { | 294 | { | ||
291 | if (!m_playListControler) { | 295 | if (!m_playListControler) { | ||
292 | return; | 296 | return; | ||
293 | } | 297 | } | ||
294 | 298 | | |||
295 | m_canGoNext = m_manageMediaPlayerControl->skipForwardControlEnabled(); | 299 | m_canGoNext = m_manageMediaPlayerControl->skipForwardControlEnabled(); | ||
296 | 300 | | |||
297 | signalPropertiesChange(QStringLiteral("CanGoNext"), CanGoNext()); | 301 | signalPropertiesChange(QStringLiteral("CanGoNext"), CanGoNext()); | ||
302 | emit canGoNextChanged(); | ||||
298 | } | 303 | } | ||
299 | 304 | | |||
300 | void MediaPlayer2Player::playerPlaybackStateChanged() | 305 | void MediaPlayer2Player::playerPlaybackStateChanged() | ||
301 | { | 306 | { | ||
302 | signalPropertiesChange(QStringLiteral("PlaybackStatus"), PlaybackStatus()); | 307 | signalPropertiesChange(QStringLiteral("PlaybackStatus"), PlaybackStatus()); | ||
308 | emit playbackStatusChanged(); | ||||
303 | 309 | | |||
304 | playerIsSeekableChanged(); | 310 | playerIsSeekableChanged(); | ||
305 | } | 311 | } | ||
306 | 312 | | |||
307 | void MediaPlayer2Player::playerIsSeekableChanged() | 313 | void MediaPlayer2Player::playerIsSeekableChanged() | ||
308 | { | 314 | { | ||
309 | m_playerIsSeekableChanged = m_manageAudioPlayer->playerIsSeekable(); | 315 | m_playerIsSeekableChanged = m_manageAudioPlayer->playerIsSeekable(); | ||
310 | 316 | | |||
311 | signalPropertiesChange(QStringLiteral("CanSeek"), CanSeek()); | 317 | signalPropertiesChange(QStringLiteral("CanSeek"), CanSeek()); | ||
318 | emit canSeekChanged(); | ||||
312 | } | 319 | } | ||
313 | 320 | | |||
314 | void MediaPlayer2Player::audioPositionChanged() | 321 | void MediaPlayer2Player::audioPositionChanged() | ||
315 | { | 322 | { | ||
316 | setPropertyPosition(m_manageAudioPlayer->playerPosition()); | 323 | setPropertyPosition(m_manageAudioPlayer->playerPosition()); | ||
317 | } | 324 | } | ||
318 | 325 | | |||
319 | void MediaPlayer2Player::audioDurationChanged() | 326 | void MediaPlayer2Player::audioDurationChanged() | ||
Show All 17 Lines | |||||
337 | { | 344 | { | ||
338 | return m_manageAudioPlayer->playListPosition(); | 345 | return m_manageAudioPlayer->playListPosition(); | ||
339 | } | 346 | } | ||
340 | 347 | | |||
341 | void MediaPlayer2Player::setCurrentTrack(int newTrackPosition) | 348 | void MediaPlayer2Player::setCurrentTrack(int newTrackPosition) | ||
342 | { | 349 | { | ||
343 | m_currentTrack = m_manageAudioPlayer->playerSource().toString(); | 350 | m_currentTrack = m_manageAudioPlayer->playerSource().toString(); | ||
344 | m_currentTrackId = QDBusObjectPath(QStringLiteral("/org/kde/elisa/playlist/") + QString::number(newTrackPosition)).path(); | 351 | m_currentTrackId = QDBusObjectPath(QStringLiteral("/org/kde/elisa/playlist/") + QString::number(newTrackPosition)).path(); | ||
352 | | ||||
353 | emit currentTrackChanged(); | ||||
345 | } | 354 | } | ||
346 | 355 | | |||
347 | QVariantMap MediaPlayer2Player::getMetadataOfCurrentTrack() | 356 | QVariantMap MediaPlayer2Player::getMetadataOfCurrentTrack() | ||
348 | { | 357 | { | ||
349 | auto result = QVariantMap(); | 358 | auto result = QVariantMap(); | ||
350 | 359 | | |||
351 | result[QStringLiteral("mpris:trackid")] = QVariant::fromValue<QDBusObjectPath>(QDBusObjectPath(m_currentTrackId)); | 360 | result[QStringLiteral("mpris:trackid")] = QVariant::fromValue<QDBusObjectPath>(QDBusObjectPath(m_currentTrackId)); | ||
352 | result[QStringLiteral("mpris:length")] = qlonglong(m_manageAudioPlayer->audioDuration()) * 1000; | 361 | result[QStringLiteral("mpris:length")] = qlonglong(m_manageAudioPlayer->audioDuration()) * 1000; | ||
Show All 11 Lines | |||||
364 | { | 373 | { | ||
365 | return m_mediaPlayerPresent; | 374 | return m_mediaPlayerPresent; | ||
366 | } | 375 | } | ||
367 | 376 | | |||
368 | void MediaPlayer2Player::setMediaPlayerPresent(int status) | 377 | void MediaPlayer2Player::setMediaPlayerPresent(int status) | ||
369 | { | 378 | { | ||
370 | if (m_mediaPlayerPresent != status) { | 379 | if (m_mediaPlayerPresent != status) { | ||
371 | m_mediaPlayerPresent = status; | 380 | m_mediaPlayerPresent = status; | ||
381 | emit mediaPlayerPresentChanged(); | ||||
372 | 382 | | |||
373 | signalPropertiesChange(QStringLiteral("CanGoNext"), CanGoNext()); | 383 | signalPropertiesChange(QStringLiteral("CanGoNext"), CanGoNext()); | ||
374 | signalPropertiesChange(QStringLiteral("CanGoPrevious"), CanGoPrevious()); | 384 | signalPropertiesChange(QStringLiteral("CanGoPrevious"), CanGoPrevious()); | ||
375 | signalPropertiesChange(QStringLiteral("CanPause"), CanPause()); | 385 | signalPropertiesChange(QStringLiteral("CanPause"), CanPause()); | ||
376 | signalPropertiesChange(QStringLiteral("CanPlay"), CanPlay()); | 386 | signalPropertiesChange(QStringLiteral("CanPlay"), CanPlay()); | ||
387 | emit canGoNextChanged(); | ||||
388 | emit canGoPreviousChanged(); | ||||
389 | emit canPauseChanged(); | ||||
390 | emit canPlayChanged(); | ||||
377 | } | 391 | } | ||
378 | } | 392 | } | ||
379 | 393 | | |||
380 | void MediaPlayer2Player::signalPropertiesChange(const QString &property, const QVariant &value) | 394 | void MediaPlayer2Player::signalPropertiesChange(const QString &property, const QVariant &value) | ||
381 | { | 395 | { | ||
382 | QVariantMap properties; | 396 | QVariantMap properties; | ||
383 | properties[property] = value; | 397 | properties[property] = value; | ||
384 | const int ifaceIndex = metaObject()->indexOfClassInfo("D-Bus Interface"); | 398 | const int ifaceIndex = metaObject()->indexOfClassInfo("D-Bus Interface"); | ||
Show All 11 Lines |