diff options
author | Mateusz Łukasik <mati75@linuxmint.pl> | 2017-11-25 21:06:12 +0100 |
---|---|---|
committer | Mateusz Łukasik <mati75@linuxmint.pl> | 2017-11-25 21:06:12 +0100 |
commit | d766ddb2d0f17beb0589a0375ee2d0509de2641d (patch) | |
tree | ee518316cae614b29dbd2ffc35fd5a39b52c5796 /src/mpris2 | |
parent | 257473284e04d45384e8e504d3c69b79872785b0 (diff) |
New upstream version 17.11.2~ds0
Diffstat (limited to 'src/mpris2')
-rw-r--r-- | src/mpris2/mediaplayer2player.cpp | 281 |
1 files changed, 131 insertions, 150 deletions
diff --git a/src/mpris2/mediaplayer2player.cpp b/src/mpris2/mediaplayer2player.cpp index 9059b7a..e11d076 100644 --- a/src/mpris2/mediaplayer2player.cpp +++ b/src/mpris2/mediaplayer2player.cpp @@ -46,8 +46,7 @@ #include <QCryptographicHash> -static QByteArray makeTrackId(const QString& source) -{ +static QByteArray makeTrackId(const QString& source) { return QByteArray("/org/smplayer/") + "smplayer" + "/tid_" + QCryptographicHash::hash(source.toLocal8Bit(), QCryptographicHash::Sha1) .toHex(); @@ -58,235 +57,217 @@ MediaPlayer2Player::MediaPlayer2Player(BaseGui * gui, QObject* parent) m_core(gui->getCore()), m_playlist(gui->getPlaylist()) { -// connect(m_core, SIGNAL(tick(qint64)), this, SLOT(tick(qint64))); -// connect(m_core, SIGNAL(seekableChanged(bool)), this, SLOT(seekableChanged(bool))); - connect(m_core, SIGNAL(mediaPlaying(QString,QString)), this, SLOT(currentSourceChanged())); - connect(m_core, SIGNAL(stateChanged(Core::State)), this, SLOT(stateUpdated())); - connect(m_core, SIGNAL(mediaInfoChanged()), this, SLOT(emitMetadataChange())); - connect(m_core, SIGNAL(volumeChanged(int)), this, SLOT(volumeChanged())); + //connect(m_core, SIGNAL(tick(qint64)), this, SLOT(tick(qint64))); + //connect(m_core, SIGNAL(seekableChanged(bool)), this, SLOT(seekableChanged(bool))); + connect(m_core, SIGNAL(mediaPlaying(QString,QString)), this, SLOT(currentSourceChanged())); + connect(m_core, SIGNAL(stateChanged(Core::State)), this, SLOT(stateUpdated())); + connect(m_core, SIGNAL(mediaInfoChanged()), this, SLOT(emitMetadataChange())); + connect(m_core, SIGNAL(volumeChanged(int)), this, SLOT(volumeChanged())); } -MediaPlayer2Player::~MediaPlayer2Player() -{ +MediaPlayer2Player::~MediaPlayer2Player() { } -bool MediaPlayer2Player::CanGoNext() const -{ - return true; +bool MediaPlayer2Player::CanGoNext() const { + return true; } -void MediaPlayer2Player::Next() const -{ - m_playlist->playNext(); +void MediaPlayer2Player::Next() const { + qDebug("MediaPlayer2Player::Next"); + m_playlist->playNext(); } -bool MediaPlayer2Player::CanGoPrevious() const -{ - return true; +bool MediaPlayer2Player::CanGoPrevious() const { + return true; } -void MediaPlayer2Player::Previous() const -{ +void MediaPlayer2Player::Previous() const { + qDebug("MediaPlayer2Player::Previous"); m_playlist->playPrev(); } -bool MediaPlayer2Player::CanPause() const -{ - return true; +bool MediaPlayer2Player::CanPause() const { + return true; } -void MediaPlayer2Player::Pause() const -{ - m_core->pause(); +void MediaPlayer2Player::Pause() const { + qDebug("MediaPlayer2Player::Pause"); + m_core->pause(); } -void MediaPlayer2Player::PlayPause() const -{ - m_core->play_or_pause(); +void MediaPlayer2Player::PlayPause() const { + qDebug("MediaPlayer2Player::PlayPause"); + m_core->play_or_pause(); } -void MediaPlayer2Player::Stop() const -{ - m_core->stop(); +void MediaPlayer2Player::Stop() const { + qDebug("MediaPlayer2Player::Stop"); + m_core->stop(); } -bool MediaPlayer2Player::CanPlay() const -{ - return true; +bool MediaPlayer2Player::CanPlay() const { + return true; } -void MediaPlayer2Player::Play() const -{ - m_core->play(); +void MediaPlayer2Player::Play() const { + qDebug("MediaPlayer2Player::Play"); + m_core->play(); } -void MediaPlayer2Player::SetPosition(const QDBusObjectPath& TrackId, qlonglong Position) const -{ - if (TrackId.path().toLocal8Bit() == makeTrackId(m_core->mdat.filename)) - m_core->seek(static_cast<int>(Position / 1000000)); +void MediaPlayer2Player::SetPosition(const QDBusObjectPath& TrackId, qlonglong Position) const { + double secs = Position / 1000000; + qDebug() << "MediaPlayer2Player::SetPosition: TrackId:" << TrackId.path() << "Position:" << Position << "(secs:" << secs << ")"; + if (TrackId.path().toLocal8Bit() == makeTrackId(m_core->mdat.filename)) { + m_core->goToSec(secs); + } } -void MediaPlayer2Player::OpenUri(QString uri) const -{ - m_core->open(uri); +void MediaPlayer2Player::OpenUri(QString uri) const { + qDebug() << "MediaPlayer2Player::OpenUri:" << uri; + m_core->open(uri); } -QString MediaPlayer2Player::PlaybackStatus() const -{ - return m_core->stateToString(); +QString MediaPlayer2Player::PlaybackStatus() const { + return m_core->stateToString(); } -QString MediaPlayer2Player::LoopStatus() const -{ - return "None"; +QString MediaPlayer2Player::LoopStatus() const { + return "None"; } -void MediaPlayer2Player::setLoopStatus(const QString& loopStatus) const -{ - Q_UNUSED(loopStatus) +void MediaPlayer2Player::setLoopStatus(const QString& loopStatus) const { + Q_UNUSED(loopStatus) } -double MediaPlayer2Player::Rate() const -{ - return m_core->mset.speed; +double MediaPlayer2Player::Rate() const { + return m_core->mset.speed; } -void MediaPlayer2Player::setRate(double rate) const -{ - m_core->setSpeed(rate); +void MediaPlayer2Player::setRate(double rate) const { + qDebug() << "MediaPlayer2Player::setRate:" << rate; + m_core->setSpeed(rate); } -bool MediaPlayer2Player::Shuffle() const -{ - return false; +bool MediaPlayer2Player::Shuffle() const { + return false; } -void MediaPlayer2Player::setShuffle(bool shuffle) const -{ - Q_UNUSED(shuffle) +void MediaPlayer2Player::setShuffle(bool shuffle) const { + Q_UNUSED(shuffle) } -QVariantMap MediaPlayer2Player::Metadata() const -{ - QVariantMap metaData; +QVariantMap MediaPlayer2Player::Metadata() const { + QVariantMap metaData; - if (!m_core->mdat.initialized) - return metaData; + if (!m_core->mdat.initialized) { + return metaData; + } - metaData["mpris:trackid"] = QVariant::fromValue<QDBusObjectPath>(QDBusObjectPath(makeTrackId(m_core->mdat.filename).constData())); + metaData["mpris:trackid"] = QVariant::fromValue<QDBusObjectPath>(QDBusObjectPath(makeTrackId(m_core->mdat.filename).constData())); metaData["mpris:length"] = m_core->mdat.duration * 1000000; - if (m_core->mdat.type == TYPE_STREAM) - metaData["xesam:url"] = m_core->mdat.stream_url; - else - metaData["xesam:url"] = m_core->mdat.filename; + if (m_core->mdat.type == TYPE_STREAM) + metaData["xesam:url"] = m_core->mdat.stream_url; + else + metaData["xesam:url"] = m_core->mdat.filename; - if (!m_core->mdat.clip_album.isEmpty()) - metaData["xesam:album"] = m_core->mdat.clip_album; - if (!m_core->mdat.clip_name.isEmpty()) - metaData["xesam:title"] = m_core->mdat.clip_name; - else if (!m_core->mdat.filename.isEmpty()) { - QFileInfo fileInfo(m_core->mdat.filename); - metaData["xesam:title"] = fileInfo.fileName(); - } - if (!m_core->mdat.clip_artist.isEmpty()) - metaData["xesam:artist"] = m_core->mdat.clip_artist; - if (!m_core->mdat.clip_genre.isEmpty()) - metaData["xesam:genre"] = m_core->mdat.clip_genre; + if (!m_core->mdat.clip_album.isEmpty()) + metaData["xesam:album"] = m_core->mdat.clip_album; + if (!m_core->mdat.clip_name.isEmpty()) + metaData["xesam:title"] = m_core->mdat.clip_name; + else if (!m_core->mdat.filename.isEmpty()) { + QFileInfo fileInfo(m_core->mdat.filename); + metaData["xesam:title"] = fileInfo.fileName(); + } + if (!m_core->mdat.clip_artist.isEmpty()) + metaData["xesam:artist"] = m_core->mdat.clip_artist; + if (!m_core->mdat.clip_genre.isEmpty()) + metaData["xesam:genre"] = m_core->mdat.clip_genre; - return metaData; + return metaData; } -double MediaPlayer2Player::Volume() const -{ - return static_cast<double>(m_core->mset.volume / 100.0); +double MediaPlayer2Player::Volume() const { + return static_cast<double>(m_core->mset.volume / 100.0); } -void MediaPlayer2Player::setVolume(double volume) const -{ - m_core->setVolume(static_cast<int>(volume*100)); +void MediaPlayer2Player::setVolume(double volume) const { + qDebug() << "MediaPlayer2Player::setVolume:" << volume; + m_core->setVolume(static_cast<int>(volume*100)); } -qlonglong MediaPlayer2Player::Position() const -{ +qlonglong MediaPlayer2Player::Position() const { return static_cast<qlonglong>(m_core->mset.current_sec * 1000000); } -double MediaPlayer2Player::MinimumRate() const -{ - return 0.01; +double MediaPlayer2Player::MinimumRate() const { + return 0.01; } -double MediaPlayer2Player::MaximumRate() const -{ - return 100.0; +double MediaPlayer2Player::MaximumRate() const { + return 100.0; } -bool MediaPlayer2Player::CanSeek() const -{ - return true; +bool MediaPlayer2Player::CanSeek() const { + return true; } -void MediaPlayer2Player::Seek(qlonglong Offset) const -{ - m_core->seek(static_cast<int>(Offset/1000000)); +void MediaPlayer2Player::Seek(qlonglong Offset) const { + int secs = Offset/1000000; + qDebug() << "MediaPlayer2Player::Seek:" << Offset << "(secs" << secs << ")"; + m_core->seek(secs); } -bool MediaPlayer2Player::CanControl() const -{ - return true; +bool MediaPlayer2Player::CanControl() const { + return true; } -void MediaPlayer2Player::tick(qint64 newPos) -{ -// if (newPos - oldPos > tickInterval + 250 || newPos < oldPos) -// emit Seeked(newPos * 1000); +void MediaPlayer2Player::tick(qint64 newPos) { + /* + if (newPos - oldPos > tickInterval + 250 || newPos < oldPos) { + emit Seeked(newPos * 1000); + } + */ - oldPos = newPos; + oldPos = newPos; } -void MediaPlayer2Player::emitMetadataChange() const -{ - QVariantMap properties; - properties["Metadata"] = Metadata(); - Mpris2::signalPropertiesChange(this, properties); +void MediaPlayer2Player::emitMetadataChange() const { + QVariantMap properties; + properties["Metadata"] = Metadata(); + Mpris2::signalPropertiesChange(this, properties); } -void MediaPlayer2Player::currentSourceChanged() const -{ - QVariantMap properties; - properties["Metadata"] = Metadata(); - properties["CanSeek"] = CanSeek(); - Mpris2::signalPropertiesChange(this, properties); +void MediaPlayer2Player::currentSourceChanged() const { + QVariantMap properties; + properties["Metadata"] = Metadata(); + properties["CanSeek"] = CanSeek(); + Mpris2::signalPropertiesChange(this, properties); } -void MediaPlayer2Player::stateUpdated() const -{ - QVariantMap properties; - properties["PlaybackStatus"] = PlaybackStatus(); - properties["CanPause"] = CanPause(); - Mpris2::signalPropertiesChange(this, properties); +void MediaPlayer2Player::stateUpdated() const { + QVariantMap properties; + properties["PlaybackStatus"] = PlaybackStatus(); + properties["CanPause"] = CanPause(); + Mpris2::signalPropertiesChange(this, properties); } -void MediaPlayer2Player::totalTimeChanged() const -{ - QVariantMap properties; - properties["Metadata"] = Metadata(); - Mpris2::signalPropertiesChange(this, properties); +void MediaPlayer2Player::totalTimeChanged() const { + QVariantMap properties; + properties["Metadata"] = Metadata(); + Mpris2::signalPropertiesChange(this, properties); } -void MediaPlayer2Player::seekableChanged(bool seekable) const -{ - QVariantMap properties; - properties["CanSeek"] = seekable; - Mpris2::signalPropertiesChange(this, properties); +void MediaPlayer2Player::seekableChanged(bool seekable) const { + QVariantMap properties; + properties["CanSeek"] = seekable; + Mpris2::signalPropertiesChange(this, properties); } -void MediaPlayer2Player::volumeChanged() const -{ - QVariantMap properties; - properties["Volume"] = Volume(); - Mpris2::signalPropertiesChange(this, properties); +void MediaPlayer2Player::volumeChanged() const { + QVariantMap properties; + properties["Volume"] = Volume(); + Mpris2::signalPropertiesChange(this, properties); } #include "moc_mediaplayer2player.cpp" |