From f98f55db9d6dc669e4b49c70baa006fc1801d44d Mon Sep 17 00:00:00 2001 From: Egor Matirov Date: Wed, 27 Nov 2013 23:26:26 +0100 Subject: [PATCH] Extend AudioPlayer so that it gives info about if something is playing at the moment or not Reviewed by Jaydeep Solanki REVIEW: 114019 --- core/audioplayer.cpp | 10 +++++++++- core/audioplayer.h | 23 +++++++++++++++++++++++ core/audioplayer_p.h | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/core/audioplayer.cpp b/core/audioplayer.cpp index af59588f6..3638040f6 100644 --- a/core/audioplayer.cpp +++ b/core/audioplayer.cpp @@ -85,7 +85,7 @@ public: AudioPlayerPrivate::AudioPlayerPrivate( AudioPlayer * qq ) - : q( qq ) + : q( qq ), m_state( AudioPlayer::StoppedState ) { QObject::connect( &m_mapper, SIGNAL(mapped(int)), q, SLOT(finished(int)) ); } @@ -173,6 +173,7 @@ bool AudioPlayerPrivate::play( const SoundInfo& si ) QObject::connect( data->m_mediaobject, SIGNAL(finished()), &m_mapper, SLOT(map()) ); kDebug(OkularDebug) << "PLAY"; data->play(); + m_state = AudioPlayer::PlayingState; } return valid; } @@ -181,6 +182,7 @@ void AudioPlayerPrivate::stopPlayings() { qDeleteAll( m_playing ); m_playing.clear(); + m_state = AudioPlayer::StoppedState; } void AudioPlayerPrivate::finished( int id ) @@ -201,6 +203,7 @@ void AudioPlayerPrivate::finished( int id ) m_mapper.removeMappings( it.value()->m_mediaobject ); delete it.value(); m_playing.erase( it ); + m_state = AudioPlayer::StoppedState; } kDebug(OkularDebug) << "finished," << m_playing.count(); } @@ -248,4 +251,9 @@ void AudioPlayer::stopPlaybacks() d->stopPlayings(); } +AudioPlayer::State AudioPlayer::state() const +{ + return d->m_state; +} + #include "audioplayer.moc" diff --git a/core/audioplayer.h b/core/audioplayer.h index 7697562ab..b335b5ef9 100644 --- a/core/audioplayer.h +++ b/core/audioplayer.h @@ -32,6 +32,23 @@ class OKULAR_EXPORT AudioPlayer : public QObject Q_OBJECT public: + + /** + * The state of AudioPlayer + * @since 0.19 (KDE 4.13) + */ + enum State + { + /** + * The AudioPlayer is playing a audio file. + */ + PlayingState, + /** + * The AudioPlayer isn't playing a audio file. + */ + StoppedState + }; + ~AudioPlayer(); /** @@ -50,6 +67,12 @@ class OKULAR_EXPORT AudioPlayer : public QObject */ void stopPlaybacks(); + /** + * Return state of sound (playing/stopped) + * @since 0.19 (KDE 4.13) + */ + State state() const; + private: AudioPlayer(); diff --git a/core/audioplayer_p.h b/core/audioplayer_p.h index c6d43cf3c..32fe4de8a 100644 --- a/core/audioplayer_p.h +++ b/core/audioplayer_p.h @@ -42,6 +42,7 @@ public: QHash< int, PlayData * > m_playing; QSignalMapper m_mapper; KUrl m_currentDocument; + AudioPlayer::State m_state; }; }