diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-12-14 13:55:02 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-12-14 13:55:02 +0000 |
| commit | f47fcc22ac3f91dec7824c011b3f23d1e8279507 (patch) | |
| tree | c947493c838d29ba77233857824ce3c6892c662e /src/qmmpui | |
| parent | 5b875657aba150137a2f46910d676289a878b4d6 (diff) | |
| download | qmmp-f47fcc22ac3f91dec7824c011b3f23d1e8279507.tar.gz qmmp-f47fcc22ac3f91dec7824c011b3f23d1e8279507.tar.bz2 qmmp-f47fcc22ac3f91dec7824c011b3f23d1e8279507.zip | |
mediplayer class, enabled all statusicon actions
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@681 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui')
| -rw-r--r-- | src/qmmpui/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/qmmpui/general.cpp | 6 | ||||
| -rw-r--r-- | src/qmmpui/general.h | 2 | ||||
| -rw-r--r-- | src/qmmpui/generalhandler.cpp | 100 | ||||
| -rw-r--r-- | src/qmmpui/generalhandler.h | 1 | ||||
| -rw-r--r-- | src/qmmpui/mediaplayer.cpp | 153 | ||||
| -rw-r--r-- | src/qmmpui/mediaplayer.h | 56 | ||||
| -rw-r--r-- | src/qmmpui/qmmpui.pro | 12 |
8 files changed, 219 insertions, 114 deletions
diff --git a/src/qmmpui/CMakeLists.txt b/src/qmmpui/CMakeLists.txt index e02ee1ce8..0531bf210 100644 --- a/src/qmmpui/CMakeLists.txt +++ b/src/qmmpui/CMakeLists.txt @@ -40,6 +40,7 @@ SET(libqmmpui_SRCS playstate.cpp playlistmodel.cpp playlistitem.cpp + mediaplayer.cpp ) SET(libqmmpui_MOC_HDRS @@ -58,6 +59,7 @@ SET(libqmmpui_MOC_HDRS playstate.h playlistmodel.h playlistitem.h + mediaplayer.h ) SET(libqmmpui_DEVEL_HDRS @@ -74,6 +76,7 @@ SET(libqmmpui_DEVEL_HDRS abstractplaylistitem.h playlistmodel.h playlistitem.h + mediaplayer.h ) diff --git a/src/qmmpui/general.cpp b/src/qmmpui/general.cpp index a4580941e..7bed340e1 100644 --- a/src/qmmpui/general.cpp +++ b/src/qmmpui/general.cpp @@ -72,12 +72,6 @@ General::General(QObject *parent) General::~General() {} -void General::play() -{ - //TODO use AbstractPlayList and SoundCore - emit playCalled(); -} - void General::exit() { emit exitCalled(); diff --git a/src/qmmpui/general.h b/src/qmmpui/general.h index edcb884b6..ae94288e2 100644 --- a/src/qmmpui/general.h +++ b/src/qmmpui/general.h @@ -46,12 +46,10 @@ public: static bool isEnabled(GeneralFactory* factory); public slots: - void play(); void exit(); void toggleVisibility(); signals: - void playCalled(); void exitCalled(); void toggleVisibilityCalled(); diff --git a/src/qmmpui/generalhandler.cpp b/src/qmmpui/generalhandler.cpp index fcae3ddd0..b371b8253 100644 --- a/src/qmmpui/generalhandler.cpp +++ b/src/qmmpui/generalhandler.cpp @@ -46,7 +46,6 @@ GeneralHandler::GeneralHandler(QObject *parent) { General *general = factory->create(parent); connect (general, SIGNAL(toggleVisibilityCalled()), SIGNAL(toggleVisibilityCalled())); - connect (general, SIGNAL(playCalled()), SIGNAL(playCalled())); connect (general, SIGNAL(exitCalled()), SIGNAL(exitCalled())); m_generals.insert(factory, general); } @@ -58,62 +57,6 @@ GeneralHandler::GeneralHandler(QObject *parent) GeneralHandler::~GeneralHandler() {} -/*void GeneralHandler::setState(uint state) -{ - if (state == m_state) - return; - m_state = state; - General *general; - if (state == General::Stopped) - { - m_songInfo.clear(); - m_time = 0; - } - - foreach(general, m_generals.values()) - { - general->setState(state); - } -}*/ - -/*void GeneralHandler::setSongInfo(const SongInfo &info) -{ - if (m_state == General::Stopped) - return; - if (m_songInfo != info) - { - m_songInfo = info; - General *general; - foreach(general, m_generals.values()) - { - general->setSongInfo(m_songInfo); - } - } -} - -void GeneralHandler::setVolume(int left, int right) -{ - m_left = left; - m_right = right; - General *general; - foreach(general, m_generals.values()) - { - general->setVolume(left, right); - } -} - -void GeneralHandler::setTime(int time) -{ - if(m_time == time) - return; - m_time = time; - General *general; - foreach(general, m_generals.values()) - { - general->setTime(time); - } -}*/ - void GeneralHandler::setEnabled(GeneralFactory* factory, bool enable) { if (enable == m_generals.keys().contains(factory)) @@ -122,7 +65,6 @@ void GeneralHandler::setEnabled(GeneralFactory* factory, bool enable) { General *general = factory->create(parent()); connect (general, SIGNAL(toggleVisibilityCalled()), SIGNAL(toggleVisibilityCalled())); - connect (general, SIGNAL(playCalled()), SIGNAL(playCalled())); connect (general, SIGNAL(exitCalled()), SIGNAL(exitCalled())); m_generals.insert(factory, general); //general->setVolume(m_left, m_right); @@ -152,7 +94,6 @@ void GeneralHandler::showSettings(GeneralFactory* factory, QWidget* parentWidget delete m_generals.value(factory); General *general = factory->create(parent()); connect (general, SIGNAL(toggleVisibilityCalled()), SIGNAL(toggleVisibilityCalled())); - connect (general, SIGNAL(playCalled()), SIGNAL(playCalled())); connect (general, SIGNAL(exitCalled()), SIGNAL(exitCalled())); m_generals[factory] = general; /*general->setVolume(m_left, m_right); @@ -187,44 +128,3 @@ GeneralHandler* GeneralHandler::instance() return m_instance; } -/*void GeneralHandler::processCommand(uint command) -{ - switch ((uint) command) - { - case Control::Play: - { - emit playCalled(); - break; - } - case Control::Stop: - { - emit stopCalled(); - break; - } - case Control::Pause: - { - emit pauseCalled(); - break; - } - case Control::Previous: - { - emit previousCalled(); - break; - } - case Control::Next: - { - emit nextCalled(); - break; - } - case Control::Exit: - { - emit exitCalled(); - break; - } - case Control::ToggleVisibility: - { - emit toggleVisibilityCalled(); - break; - } - } -}*/ diff --git a/src/qmmpui/generalhandler.h b/src/qmmpui/generalhandler.h index 7a1eb3502..689170fce 100644 --- a/src/qmmpui/generalhandler.h +++ b/src/qmmpui/generalhandler.h @@ -46,7 +46,6 @@ public: static GeneralHandler* instance(); signals: - void playCalled(); void exitCalled(); void toggleVisibilityCalled(); diff --git a/src/qmmpui/mediaplayer.cpp b/src/qmmpui/mediaplayer.cpp new file mode 100644 index 000000000..dbcd7ee31 --- /dev/null +++ b/src/qmmpui/mediaplayer.cpp @@ -0,0 +1,153 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <QApplication> +#include <QString> +#include <qmmp/soundcore.h> + +#include "playlistmodel.h" +#include "playlistitem.h" + +#include "mediaplayer.h" + +MediaPlayer *MediaPlayer::m_instance = 0; + +MediaPlayer::MediaPlayer(QObject *parent) + : QObject(parent) +{ + m_instance = this; + m_model = 0; + m_core = 0; +} + + +MediaPlayer::~MediaPlayer() +{ +} + +MediaPlayer* MediaPlayer::instance() +{ + return m_instance; +} + +void MediaPlayer::initialize(SoundCore *core, PlayListModel *model) +{ + Q_CHECK_PTR(core); + Q_CHECK_PTR(model); + m_core = core; + m_model = model; + connect(m_core, SIGNAL(finished()), SLOT(next())); +} + +void MediaPlayer::play() +{ + m_model->doCurrentVisibleRequest(); + if (m_core->state() == Qmmp::Paused) + { + m_core->pause(); + return; + } + + if (m_model->count() == 0) + return; + + QString s = m_model->currentItem()->url(); + if (s.isEmpty()) + return; + qDebug(qPrintable(s)); + if (!m_core->play(s)) + { + //find out the reason why playback failed + switch ((int) m_core->state()) + { + case Qmmp::FatalError: + { + stop(); + return; //unrecovable error in output, so abort playing + } + case Qmmp::NormalError: + { + //error in decoder, so we should try to play next song + qApp->processEvents(); + if (!m_model->isEmptyQueue()) + { + m_model->setCurrentToQueued(); + } + else if (!m_model->next()) + { + stop(); + //display->hideTimeDisplay(); + return; + } + play(); + break; + } + } + } +} + +void MediaPlayer::stop() +{ + m_core->stop(); +} + +void MediaPlayer::next() +{ + if (!m_model->isEmptyQueue()) + { + m_model->setCurrentToQueued(); + } + else if (!m_model->next()) + { + stop(); + //display->hideTimeDisplay(); + return; + } + //m_playlist->update(); + if (m_core->state() != Qmmp::Stopped) + { + if (m_core->state() == Qmmp::Paused) + stop(); + play(); + } + /*else + display->hideTimeDisplay();*/ +} + +void MediaPlayer::previous() +{ + if (!m_model->previous()) + { + stop(); + //display->hideTimeDisplay(); + return; + } + + //m_playlist->update(); + if (m_core->state() != Qmmp::Stopped) + { + if (m_core->state() == Qmmp::Paused) + stop(); + play(); + } + /*else + display->hideTimeDisplay();*/ +} + diff --git a/src/qmmpui/mediaplayer.h b/src/qmmpui/mediaplayer.h new file mode 100644 index 000000000..f1717360b --- /dev/null +++ b/src/qmmpui/mediaplayer.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef MEDIAPLAYER_H +#define MEDIAPLAYER_H + +#include <QObject> + +class PlayListModel; +class SoundCore; + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class MediaPlayer : public QObject +{ +Q_OBJECT +public: + MediaPlayer(QObject *parent = 0); + + ~MediaPlayer(); + + static MediaPlayer* instance(); + + void initialize(SoundCore *core, PlayListModel *model); + +public slots: + void play(); + void stop(); + void next(); + void previous(); + +private: + PlayListModel *m_model; + SoundCore *m_core; + static MediaPlayer* m_instance; + +}; + +#endif diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro index 4ab86004e..5148a612e 100644 --- a/src/qmmpui/qmmpui.pro +++ b/src/qmmpui/qmmpui.pro @@ -44,7 +44,8 @@ HEADERS += general.h \ playlistitem.h \ playlistmodel.h \ playstate.h \ - fileloader.h + fileloader.h \ + mediaplayer.h SOURCES += general.cpp \ generalhandler.cpp \ playlistparser.cpp \ @@ -52,10 +53,11 @@ SOURCES += general.cpp \ filedialog.cpp \ qtfiledialog.cpp \ abstractplaylistitem.cpp \ - playlistmodel.cpp \ - playstate.cpp \ - playlistitem.cpp \ - fileloader.cpp + playlistmodel.cpp \ + playstate.cpp \ + playlistitem.cpp \ + fileloader.cpp \ + mediaplayer.cpp DESTDIR = . |
