Changeset View
Changeset View
Standalone View
Standalone View
src/mpris2/mediaplayer2player.cpp
| Show All 34 Lines | |||||
| 35 | #include <QDBusConnection> | 35 | #include <QDBusConnection> | ||
| 36 | 36 | | |||
| 37 | #include <QDebug> | 37 | #include <QDebug> | ||
| 38 | 38 | | |||
| 39 | static const double MAX_RATE = 1.0; | 39 | static const double MAX_RATE = 1.0; | ||
| 40 | static const double MIN_RATE = 1.0; | 40 | static const double MIN_RATE = 1.0; | ||
| 41 | 41 | | |||
| 42 | MediaPlayer2Player::MediaPlayer2Player(MediaPlayList *playListControler, ManageAudioPlayer *manageAudioPlayer, | 42 | MediaPlayer2Player::MediaPlayer2Player(MediaPlayList *playListControler, ManageAudioPlayer *manageAudioPlayer, | ||
| 43 | ManageMediaPlayerControl *manageMediaPlayerControl, ManageHeaderBar *manageHeaderBar, AudioWrapper *audioPlayer, QObject* parent) | 43 | ManageMediaPlayerControl *manageMediaPlayerControl, ManageHeaderBar *manageHeaderBar, | ||
| 44 | AudioWrapper *audioPlayer, bool showProgressOnTaskBar, QObject* parent) | ||||
| 44 | : QDBusAbstractAdaptor(parent), m_playListControler(playListControler), m_manageAudioPlayer(manageAudioPlayer), | 45 | : QDBusAbstractAdaptor(parent), m_playListControler(playListControler), m_manageAudioPlayer(manageAudioPlayer), | ||
| 45 | m_manageMediaPlayerControl(manageMediaPlayerControl), m_manageHeaderBar(manageHeaderBar), m_audioPlayer(audioPlayer), | 46 | m_manageMediaPlayerControl(manageMediaPlayerControl), m_manageHeaderBar(manageHeaderBar), m_audioPlayer(audioPlayer), | ||
| 46 | mProgressIndicatorSignal(QDBusMessage::createSignal(QStringLiteral("/org/kde/elisa"), | 47 | mProgressIndicatorSignal(QDBusMessage::createSignal(QStringLiteral("/org/kde/elisa"), | ||
| 47 | QStringLiteral("com.canonical.Unity.LauncherEntry"), | 48 | QStringLiteral("com.canonical.Unity.LauncherEntry"), | ||
| 48 | QStringLiteral("Update"))) | 49 | QStringLiteral("Update"))), | ||
| 50 | mShowProgressOnTaskBar(showProgressOnTaskBar) | ||||
| 49 | { | 51 | { | ||
| 50 | if (!m_playListControler) { | 52 | if (!m_playListControler) { | ||
| 51 | return; | 53 | return; | ||
| 52 | } | 54 | } | ||
| 53 | 55 | | |||
| 54 | connect(m_manageAudioPlayer, &ManageAudioPlayer::playerSourceChanged, | 56 | connect(m_manageAudioPlayer, &ManageAudioPlayer::playerSourceChanged, | ||
| 55 | this, &MediaPlayer2Player::playerSourceChanged, Qt::QueuedConnection); | 57 | this, &MediaPlayer2Player::playerSourceChanged, Qt::QueuedConnection); | ||
| 56 | connect(m_manageMediaPlayerControl, &ManageMediaPlayerControl::playControlEnabledChanged, | 58 | connect(m_manageMediaPlayerControl, &ManageMediaPlayerControl::playControlEnabledChanged, | ||
| Show All 35 Lines | 86 | { | |||
| 92 | if (m_manageAudioPlayer->playerPlaybackState() == QMediaPlayer::StoppedState) { | 94 | if (m_manageAudioPlayer->playerPlaybackState() == QMediaPlayer::StoppedState) { | ||
| 93 | result = QStringLiteral("Stopped"); | 95 | result = QStringLiteral("Stopped"); | ||
| 94 | } else if (m_manageAudioPlayer->playerPlaybackState() == QMediaPlayer::PlayingState) { | 96 | } else if (m_manageAudioPlayer->playerPlaybackState() == QMediaPlayer::PlayingState) { | ||
| 95 | result = QStringLiteral("Playing"); | 97 | result = QStringLiteral("Playing"); | ||
| 96 | } else { | 98 | } else { | ||
| 97 | result = QStringLiteral("Paused"); | 99 | result = QStringLiteral("Paused"); | ||
| 98 | } | 100 | } | ||
| 99 | 101 | | |||
| 102 | if (mShowProgressOnTaskBar) { | ||||
| 100 | QVariantMap parameters; | 103 | QVariantMap parameters; | ||
| 101 | 104 | | |||
| 102 | if (m_manageAudioPlayer->playerPlaybackState() == QMediaPlayer::StoppedState || m_audioPlayer->duration() == 0) { | 105 | if (m_manageAudioPlayer->playerPlaybackState() == QMediaPlayer::StoppedState || m_audioPlayer->duration() == 0) { | ||
| 103 | parameters.insert(QStringLiteral("progress-visible"), false); | 106 | parameters.insert(QStringLiteral("progress-visible"), false); | ||
| 104 | parameters.insert(QStringLiteral("progress"), 0); | 107 | parameters.insert(QStringLiteral("progress"), 0); | ||
| 105 | } else { | 108 | } else { | ||
| 106 | parameters.insert(QStringLiteral("progress-visible"), true); | 109 | parameters.insert(QStringLiteral("progress-visible"), true); | ||
| 107 | parameters.insert(QStringLiteral("progress"), qRound(static_cast<double>(m_position / m_audioPlayer->duration())) / 1000.0); | 110 | parameters.insert(QStringLiteral("progress"), qRound(static_cast<double>(m_position / m_audioPlayer->duration())) / 1000.0); | ||
| 108 | } | 111 | } | ||
| 109 | 112 | | |||
| 110 | mProgressIndicatorSignal.setArguments({QStringLiteral("application://org.kde.elisa.desktop"), parameters}); | 113 | mProgressIndicatorSignal.setArguments({QStringLiteral("application://org.kde.elisa.desktop"), parameters}); | ||
| 111 | 114 | | |||
| 112 | QDBusConnection::sessionBus().send(mProgressIndicatorSignal); | 115 | QDBusConnection::sessionBus().send(mProgressIndicatorSignal); | ||
| 116 | } | ||||
| 113 | 117 | | |||
| 114 | return result; | 118 | return result; | ||
| 115 | } | 119 | } | ||
| 116 | 120 | | |||
| 117 | bool MediaPlayer2Player::CanGoNext() const | 121 | bool MediaPlayer2Player::CanGoNext() const | ||
| 118 | { | 122 | { | ||
| 119 | return m_canGoNext; | 123 | return m_canGoNext; | ||
| 120 | } | 124 | } | ||
| ▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | |||||
| 211 | 215 | | |||
| 212 | void MediaPlayer2Player::setPropertyPosition(int newPositionInMs) | 216 | void MediaPlayer2Player::setPropertyPosition(int newPositionInMs) | ||
| 213 | { | 217 | { | ||
| 214 | m_position = qlonglong(newPositionInMs) * 1000; | 218 | m_position = qlonglong(newPositionInMs) * 1000; | ||
| 215 | signalPropertiesChange(QStringLiteral("Position"), Position()); | 219 | signalPropertiesChange(QStringLiteral("Position"), Position()); | ||
| 216 | 220 | | |||
| 217 | Q_EMIT Seeked(m_position); | 221 | Q_EMIT Seeked(m_position); | ||
| 218 | 222 | | |||
| 223 | if (mShowProgressOnTaskBar) { | ||||
| 219 | QVariantMap parameters; | 224 | QVariantMap parameters; | ||
| 220 | parameters.insert(QStringLiteral("progress-visible"), true); | 225 | parameters.insert(QStringLiteral("progress-visible"), true); | ||
| 221 | parameters.insert(QStringLiteral("progress"), static_cast<double>(newPositionInMs) / m_audioPlayer->duration()); | 226 | parameters.insert(QStringLiteral("progress"), static_cast<double>(newPositionInMs) / m_audioPlayer->duration()); | ||
| 222 | 227 | | |||
| 223 | mProgressIndicatorSignal.setArguments({QStringLiteral("application://org.kde.elisa.desktop"), parameters}); | 228 | mProgressIndicatorSignal.setArguments({QStringLiteral("application://org.kde.elisa.desktop"), parameters}); | ||
| 224 | 229 | | |||
| 225 | QDBusConnection::sessionBus().send(mProgressIndicatorSignal); | 230 | QDBusConnection::sessionBus().send(mProgressIndicatorSignal); | ||
| 226 | } | 231 | } | ||
| 232 | } | ||||
| 227 | 233 | | |||
| 228 | double MediaPlayer2Player::Rate() const | 234 | double MediaPlayer2Player::Rate() const | ||
| 229 | { | 235 | { | ||
| 230 | return m_rate; | 236 | return m_rate; | ||
| 231 | } | 237 | } | ||
| 232 | 238 | | |||
| 233 | void MediaPlayer2Player::setRate(double newRate) | 239 | void MediaPlayer2Player::setRate(double newRate) | ||
| 234 | { | 240 | { | ||
| ▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Line(s) | 396 | { | |||
| 410 | return result; | 416 | return result; | ||
| 411 | } | 417 | } | ||
| 412 | 418 | | |||
| 413 | int MediaPlayer2Player::mediaPlayerPresent() const | 419 | int MediaPlayer2Player::mediaPlayerPresent() const | ||
| 414 | { | 420 | { | ||
| 415 | return m_mediaPlayerPresent; | 421 | return m_mediaPlayerPresent; | ||
| 416 | } | 422 | } | ||
| 417 | 423 | | |||
| 424 | bool MediaPlayer2Player::showProgressOnTaskBar() const | ||||
| 425 | { | ||||
| 426 | return mShowProgressOnTaskBar; | ||||
| 427 | } | ||||
| 428 | | ||||
| 429 | void MediaPlayer2Player::setShowProgressOnTaskBar(bool value) | ||||
| 430 | { | ||||
| 431 | mShowProgressOnTaskBar = value; | ||||
| 432 | | ||||
| 433 | QVariantMap parameters; | ||||
| 434 | | ||||
| 435 | if (!mShowProgressOnTaskBar || m_manageAudioPlayer->playerPlaybackState() == QMediaPlayer::StoppedState || m_audioPlayer->duration() == 0) { | ||||
| 436 | parameters.insert(QStringLiteral("progress-visible"), false); | ||||
| 437 | parameters.insert(QStringLiteral("progress"), 0); | ||||
| 438 | } else { | ||||
| 439 | parameters.insert(QStringLiteral("progress-visible"), true); | ||||
| 440 | parameters.insert(QStringLiteral("progress"), qRound(static_cast<double>(m_position / m_audioPlayer->duration())) / 1000.0); | ||||
| 441 | } | ||||
| 442 | | ||||
| 443 | mProgressIndicatorSignal.setArguments({QStringLiteral("application://org.kde.elisa.desktop"), parameters}); | ||||
| 444 | | ||||
| 445 | QDBusConnection::sessionBus().send(mProgressIndicatorSignal); | ||||
| 446 | } | ||||
| 447 | | ||||
| 418 | void MediaPlayer2Player::setMediaPlayerPresent(int status) | 448 | void MediaPlayer2Player::setMediaPlayerPresent(int status) | ||
| 419 | { | 449 | { | ||
| 420 | if (m_mediaPlayerPresent != status) { | 450 | if (m_mediaPlayerPresent != status) { | ||
| 421 | m_mediaPlayerPresent = status; | 451 | m_mediaPlayerPresent = status; | ||
| 422 | emit mediaPlayerPresentChanged(); | 452 | emit mediaPlayerPresentChanged(); | ||
| 423 | 453 | | |||
| 424 | signalPropertiesChange(QStringLiteral("CanGoNext"), CanGoNext()); | 454 | signalPropertiesChange(QStringLiteral("CanGoNext"), CanGoNext()); | ||
| 425 | signalPropertiesChange(QStringLiteral("CanGoPrevious"), CanGoPrevious()); | 455 | signalPropertiesChange(QStringLiteral("CanGoPrevious"), CanGoPrevious()); | ||
| Show All 25 Lines | |||||