diff options
Diffstat (limited to 'src/qmmpui')
| -rw-r--r-- | src/qmmpui/mediaplayer.cpp | 62 | ||||
| -rw-r--r-- | src/qmmpui/mediaplayer.h | 12 | ||||
| -rw-r--r-- | src/qmmpui/playlistmodel.h | 7 |
3 files changed, 73 insertions, 8 deletions
diff --git a/src/qmmpui/mediaplayer.cpp b/src/qmmpui/mediaplayer.cpp index 594ecdd34..3fc6cd4a0 100644 --- a/src/qmmpui/mediaplayer.cpp +++ b/src/qmmpui/mediaplayer.cpp @@ -37,6 +37,7 @@ MediaPlayer::MediaPlayer(QObject *parent) m_core = 0; m_skips = 0; m_repeat = false; + m_autoStop = false; QTranslator *translator = new QTranslator(parent); QString locale = Qmmp::systemLanguageID(); translator->load(QString(":/libqmmpui_") + locale); @@ -58,6 +59,7 @@ void MediaPlayer::initialize(SoundCore *core, PlayListManager *pl_manager) m_core = core; m_pl_manager = pl_manager; m_repeat = false; + m_autoStop = false; connect(m_core, SIGNAL(aboutToFinish()), SLOT(updateNextUrl())); connect(m_core, SIGNAL(finished()), SLOT(playNext())); } @@ -72,6 +74,11 @@ bool MediaPlayer::isRepeatable() const return m_repeat; } +bool MediaPlayer::isAutoStopping() const +{ + return m_autoStop; +} + void MediaPlayer::play(qint64 offset) { m_pl_manager->currentPlayList()->doCurrentVisibleRequest(); @@ -174,15 +181,18 @@ void MediaPlayer::previous() void MediaPlayer::setRepeatable(bool r) { - if (r != m_repeat && !r) + if (!isAutoStopping()) { - disconnect(m_core, SIGNAL(finished()), this, SLOT(play())); - connect(m_core, SIGNAL(finished()), SLOT(playNext())); - } - else if (r != m_repeat && r) - { - disconnect(m_core, SIGNAL(finished()), this, SLOT(playNext())); - connect(m_core, SIGNAL(finished()), SLOT(play())); + if (r != m_repeat && !r) + { + disconnect(m_core, SIGNAL(finished()), this, SLOT(play())); + connect(m_core, SIGNAL(finished()), SLOT(playNext())); + } + else if (r != m_repeat && r) + { + disconnect(m_core, SIGNAL(finished()), this, SLOT(playNext())); + connect(m_core, SIGNAL(finished()), SLOT(play())); + } } m_repeat = r; emit repeatableChanged(r); @@ -198,6 +208,42 @@ void MediaPlayer::playNext() play(); } +void MediaPlayer::setAutoStop(bool enable) +{ + if (enable != m_autoStop) + { + if(enable) + { + if (m_repeat) + disconnect(m_core, SIGNAL(finished()), this, SLOT(play())); + else + disconnect(m_core, SIGNAL(finished()), this, SLOT(playNext())); + connect(m_core, SIGNAL(finished()), SLOT(autoStop())); + } + else + { + disconnect(m_core, SIGNAL(finished()), this, SLOT(autoStop())); + if (m_repeat) + connect(m_core, SIGNAL(finished()), SLOT(play())); + else + connect(m_core, SIGNAL(finished()), SLOT(playNext())); + } + m_autoStop = enable; + emit autoStopChanged(enable); + } +} + +void MediaPlayer::autoStop() +{ + if (!m_repeat && !m_pl_manager->currentPlayList()->isEmptyQueue()) + { + playNext(); + return; + } + setAutoStop(false); + stop(); +} + void MediaPlayer::updateNextUrl() { m_nextUrl.clear(); diff --git a/src/qmmpui/mediaplayer.h b/src/qmmpui/mediaplayer.h index 19fd3f991..3809cdb3c 100644 --- a/src/qmmpui/mediaplayer.h +++ b/src/qmmpui/mediaplayer.h @@ -59,6 +59,10 @@ public: * Returns \b true if "Repeate Track" option is enabled, otherwise returns \b false */ bool isRepeatable() const; + /*! + * Returns \b true if "Auto Stop" option is enabled, otherwise returns \b false + */ + bool isAutoStopping() const; public slots: /*! @@ -82,6 +86,11 @@ public slots: * @param enable Repeate state of the current track (\b true - to repeat, \b false - to stop repeating) */ void setRepeatable(bool enable); + /*! + * Toggles the AutoStop feature. + * @param enable the AutoStop state (\b true - automatic stop, \b false - normal play) + */ + void setAutoStop(bool enable); signals: /*! @@ -89,9 +98,11 @@ signals: * @param enabled New repeate state of the current track (\b true - enabled, \b false - disabled) */ void repeatableChanged(bool enabled); + void autoStopChanged(bool enabled); private slots: void playNext(); + void autoStop(); void updateNextUrl(); private: @@ -99,6 +110,7 @@ private: SoundCore *m_core; static MediaPlayer* m_instance; bool m_repeat; + bool m_autoStop; int m_skips; QString m_nextUrl; }; diff --git a/src/qmmpui/playlistmodel.h b/src/qmmpui/playlistmodel.h index ce047d759..2f1dca2e4 100644 --- a/src/qmmpui/playlistmodel.h +++ b/src/qmmpui/playlistmodel.h @@ -206,6 +206,13 @@ public: return m_queued_songs.indexOf(item); } /*! + * Returns the number of items in the queue + */ + int queueSize() const + { + return m_queued_songs.size(); + } + /*! * Returns current selection(playlist can contain a lot of selections, * this method returns selection which \b row belongs to) */ |
