aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/General/statusicon/statusicon.cpp10
-rw-r--r--src/plugins/General/statusicon/statusicon.h2
-rw-r--r--src/plugins/General/statusicon/translations/statusicon_plugin_cs.ts14
-rw-r--r--src/plugins/General/statusicon/translations/statusicon_plugin_de.ts15
-rw-r--r--src/plugins/General/statusicon/translations/statusicon_plugin_ru.ts15
-rw-r--r--src/plugins/General/statusicon/translations/statusicon_plugin_uk_UA.ts15
-rw-r--r--src/plugins/General/statusicon/translations/statusicon_plugin_zh_CN.ts14
-rw-r--r--src/plugins/General/statusicon/translations/statusicon_plugin_zh_TW.ts14
-rw-r--r--src/qmmpui/CMakeLists.txt3
-rw-r--r--src/qmmpui/general.cpp6
-rw-r--r--src/qmmpui/general.h2
-rw-r--r--src/qmmpui/generalhandler.cpp100
-rw-r--r--src/qmmpui/generalhandler.h1
-rw-r--r--src/qmmpui/mediaplayer.cpp153
-rw-r--r--src/qmmpui/mediaplayer.h56
-rw-r--r--src/qmmpui/qmmpui.pro12
-rw-r--r--src/ui/mainwindow.cpp181
-rw-r--r--src/ui/mainwindow.h3
18 files changed, 318 insertions, 298 deletions
diff --git a/src/plugins/General/statusicon/statusicon.cpp b/src/plugins/General/statusicon/statusicon.cpp
index 1b2ee4bfb..8e4f05b51 100644
--- a/src/plugins/General/statusicon/statusicon.cpp
+++ b/src/plugins/General/statusicon/statusicon.cpp
@@ -27,6 +27,7 @@
#include <QEvent>
#include <qmmp/soundcore.h>
+#include <qmmpui/mediaplayer.h>
#include "qmmptrayicon.h"
#include "statusicon.h"
@@ -39,12 +40,13 @@ StatusIcon::StatusIcon(QObject *parent)
m_tray->setIcon ( QIcon(":/tray_stop.png"));
m_tray->show();
m_core = SoundCore::instance();
+ m_player = MediaPlayer::instance();
QMenu *menu = new QMenu(qobject_cast<QWidget *>(parent));
- menu->addAction(tr("Play"), this, SLOT(play()));
+ menu->addAction(tr("Play"), m_player, SLOT(play()));
menu->addAction(tr("Pause"), m_core, SLOT(pause()));
menu->addAction(tr("Stop"), m_core, SLOT(stop()));
- /*menu->addAction(tr("Next"), control, SLOT(next()));
- menu->addAction(tr("Previous"), control, SLOT(previous()));*/
+ menu->addAction(tr("Next"), m_player, SLOT(next()));
+ menu->addAction(tr("Previous"), m_player, SLOT(previous()));
menu->addSeparator();
menu->addAction(tr("Exit"), this, SLOT(exit()));
m_tray->setContextMenu(menu);
@@ -112,7 +114,7 @@ void StatusIcon::trayActivated(QSystemTrayIcon::ActivationReason reason)
else if (reason == QSystemTrayIcon::MiddleClick)
{
if (SoundCore::instance()->state() == Qmmp::Stopped)
- play();
+ m_player->play();
else
m_core->pause();
}
diff --git a/src/plugins/General/statusicon/statusicon.h b/src/plugins/General/statusicon/statusicon.h
index 67fae06e6..42978d592 100644
--- a/src/plugins/General/statusicon/statusicon.h
+++ b/src/plugins/General/statusicon/statusicon.h
@@ -27,6 +27,7 @@
#include <qmmp/qmmp.h>
class SoundCore;
+class MediaPlayer;
class QEvent;
/**
@@ -55,6 +56,7 @@ private:
bool m_enabled;
int m_messageDelay;
SoundCore *m_core;
+ MediaPlayer *m_player;
};
#endif
diff --git a/src/plugins/General/statusicon/translations/statusicon_plugin_cs.ts b/src/plugins/General/statusicon/translations/statusicon_plugin_cs.ts
index c18335ed6..11082ac76 100644
--- a/src/plugins/General/statusicon/translations/statusicon_plugin_cs.ts
+++ b/src/plugins/General/statusicon/translations/statusicon_plugin_cs.ts
@@ -36,37 +36,37 @@
<context>
<name>StatusIcon</name>
<message>
- <location filename="../statusicon.cpp" line="39"/>
+ <location filename="../statusicon.cpp" line="45"/>
<source>Play</source>
<translation>Přehrát</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="40"/>
+ <location filename="../statusicon.cpp" line="46"/>
<source>Pause</source>
<translation>Pauza</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="41"/>
+ <location filename="../statusicon.cpp" line="47"/>
<source>Stop</source>
<translation>Stop</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="42"/>
+ <location filename="../statusicon.cpp" line="48"/>
<source>Next</source>
<translation>Další</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="43"/>
+ <location filename="../statusicon.cpp" line="49"/>
<source>Previous</source>
<translation>Předchozí</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="45"/>
+ <location filename="../statusicon.cpp" line="51"/>
<source>Exit</source>
<translation>Ukončit</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="96"/>
+ <location filename="../statusicon.cpp" line="104"/>
<source>Now Playing</source>
<translation>Nyní hraje</translation>
</message>
diff --git a/src/plugins/General/statusicon/translations/statusicon_plugin_de.ts b/src/plugins/General/statusicon/translations/statusicon_plugin_de.ts
index e2eb485a9..f7dffe7b6 100644
--- a/src/plugins/General/statusicon/translations/statusicon_plugin_de.ts
+++ b/src/plugins/General/statusicon/translations/statusicon_plugin_de.ts
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="1.1" language="de">
-<defaultcodec></defaultcodec>
<context>
<name>SettingsDialog</name>
<message>
@@ -37,37 +36,37 @@
<context>
<name>StatusIcon</name>
<message>
- <location filename="../statusicon.cpp" line="39"/>
+ <location filename="../statusicon.cpp" line="45"/>
<source>Play</source>
<translation>Wiedergeben</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="40"/>
+ <location filename="../statusicon.cpp" line="46"/>
<source>Pause</source>
<translation>Anhalten</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="41"/>
+ <location filename="../statusicon.cpp" line="47"/>
<source>Stop</source>
<translation>Stop</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="42"/>
+ <location filename="../statusicon.cpp" line="48"/>
<source>Next</source>
<translation>Nächster</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="43"/>
+ <location filename="../statusicon.cpp" line="49"/>
<source>Previous</source>
<translation>Vorheriger</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="45"/>
+ <location filename="../statusicon.cpp" line="51"/>
<source>Exit</source>
<translation>Beenden</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="96"/>
+ <location filename="../statusicon.cpp" line="104"/>
<source>Now Playing</source>
<translation>Aktueller Titel</translation>
</message>
diff --git a/src/plugins/General/statusicon/translations/statusicon_plugin_ru.ts b/src/plugins/General/statusicon/translations/statusicon_plugin_ru.ts
index 94631a52c..6e292344c 100644
--- a/src/plugins/General/statusicon/translations/statusicon_plugin_ru.ts
+++ b/src/plugins/General/statusicon/translations/statusicon_plugin_ru.ts
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="1.1" language="ru">
-<defaultcodec></defaultcodec>
<context>
<name>SettingsDialog</name>
<message>
@@ -37,37 +36,37 @@
<context>
<name>StatusIcon</name>
<message>
- <location filename="../statusicon.cpp" line="39"/>
+ <location filename="../statusicon.cpp" line="45"/>
<source>Play</source>
<translation>Воспроизвести</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="40"/>
+ <location filename="../statusicon.cpp" line="46"/>
<source>Pause</source>
<translation>Пауза</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="41"/>
+ <location filename="../statusicon.cpp" line="47"/>
<source>Stop</source>
<translation>Стоп</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="42"/>
+ <location filename="../statusicon.cpp" line="48"/>
<source>Next</source>
<translation>Следующий фрагмент</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="43"/>
+ <location filename="../statusicon.cpp" line="49"/>
<source>Previous</source>
<translation>Предыдущий фрагмент</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="45"/>
+ <location filename="../statusicon.cpp" line="51"/>
<source>Exit</source>
<translation>Выход</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="96"/>
+ <location filename="../statusicon.cpp" line="104"/>
<source>Now Playing</source>
<translation>Сейчас играет</translation>
</message>
diff --git a/src/plugins/General/statusicon/translations/statusicon_plugin_uk_UA.ts b/src/plugins/General/statusicon/translations/statusicon_plugin_uk_UA.ts
index f96bc7df6..99fe033e8 100644
--- a/src/plugins/General/statusicon/translations/statusicon_plugin_uk_UA.ts
+++ b/src/plugins/General/statusicon/translations/statusicon_plugin_uk_UA.ts
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="1.1" language="uk">
-<defaultcodec></defaultcodec>
<context>
<name>SettingsDialog</name>
<message>
@@ -37,37 +36,37 @@
<context>
<name>StatusIcon</name>
<message>
- <location filename="../statusicon.cpp" line="39"/>
+ <location filename="../statusicon.cpp" line="45"/>
<source>Play</source>
<translation>Грати</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="40"/>
+ <location filename="../statusicon.cpp" line="46"/>
<source>Pause</source>
<translation>Пауза</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="41"/>
+ <location filename="../statusicon.cpp" line="47"/>
<source>Stop</source>
<translation>Стоп</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="42"/>
+ <location filename="../statusicon.cpp" line="48"/>
<source>Next</source>
<translation>Вперед</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="43"/>
+ <location filename="../statusicon.cpp" line="49"/>
<source>Previous</source>
<translation>Назад</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="45"/>
+ <location filename="../statusicon.cpp" line="51"/>
<source>Exit</source>
<translation>Вихід</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="96"/>
+ <location filename="../statusicon.cpp" line="104"/>
<source>Now Playing</source>
<translation>Зараз грає</translation>
</message>
diff --git a/src/plugins/General/statusicon/translations/statusicon_plugin_zh_CN.ts b/src/plugins/General/statusicon/translations/statusicon_plugin_zh_CN.ts
index 1c0041ed7..f583cfa25 100644
--- a/src/plugins/General/statusicon/translations/statusicon_plugin_zh_CN.ts
+++ b/src/plugins/General/statusicon/translations/statusicon_plugin_zh_CN.ts
@@ -36,37 +36,37 @@
<context>
<name>StatusIcon</name>
<message>
- <location filename="../statusicon.cpp" line="39"/>
+ <location filename="../statusicon.cpp" line="45"/>
<source>Play</source>
<translation>播放</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="40"/>
+ <location filename="../statusicon.cpp" line="46"/>
<source>Pause</source>
<translation>暂停</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="41"/>
+ <location filename="../statusicon.cpp" line="47"/>
<source>Stop</source>
<translation>停止</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="42"/>
+ <location filename="../statusicon.cpp" line="48"/>
<source>Next</source>
<translation>下一曲</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="43"/>
+ <location filename="../statusicon.cpp" line="49"/>
<source>Previous</source>
<translation>上一曲</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="45"/>
+ <location filename="../statusicon.cpp" line="51"/>
<source>Exit</source>
<translation>退出</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="96"/>
+ <location filename="../statusicon.cpp" line="104"/>
<source>Now Playing</source>
<translation>正在播放</translation>
</message>
diff --git a/src/plugins/General/statusicon/translations/statusicon_plugin_zh_TW.ts b/src/plugins/General/statusicon/translations/statusicon_plugin_zh_TW.ts
index 11795bf1c..b0075fbea 100644
--- a/src/plugins/General/statusicon/translations/statusicon_plugin_zh_TW.ts
+++ b/src/plugins/General/statusicon/translations/statusicon_plugin_zh_TW.ts
@@ -36,37 +36,37 @@
<context>
<name>StatusIcon</name>
<message>
- <location filename="../statusicon.cpp" line="39"/>
+ <location filename="../statusicon.cpp" line="45"/>
<source>Play</source>
<translation>播放</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="40"/>
+ <location filename="../statusicon.cpp" line="46"/>
<source>Pause</source>
<translation>暫停</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="41"/>
+ <location filename="../statusicon.cpp" line="47"/>
<source>Stop</source>
<translation>停止</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="42"/>
+ <location filename="../statusicon.cpp" line="48"/>
<source>Next</source>
<translation>下一曲</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="43"/>
+ <location filename="../statusicon.cpp" line="49"/>
<source>Previous</source>
<translation>上一曲</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="45"/>
+ <location filename="../statusicon.cpp" line="51"/>
<source>Exit</source>
<translation>結束</translation>
</message>
<message>
- <location filename="../statusicon.cpp" line="96"/>
+ <location filename="../statusicon.cpp" line="104"/>
<source>Now Playing</source>
<translation>正在播放</translation>
</message>
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 = .
diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp
index 4f38ec160..badd54efa 100644
--- a/src/ui/mainwindow.cpp
+++ b/src/ui/mainwindow.cpp
@@ -35,6 +35,7 @@
#include <qmmpui/filedialog.h>
#include <qmmpui/fileloader.h>
#include <qmmpui/playlistmodel.h>
+#include <qmmpui/mediaplayer.h>
#include "textscroller.h"
#include "mainwindow.h"
@@ -60,77 +61,70 @@ MainWindow::MainWindow(const QStringList& args, BuiltinCommandLineOption* option
seeking = FALSE;
m_update = FALSE;
m_paused = FALSE;
- m_elapsed = 0;
+ m_playlistName = tr("Default");
m_option_manager = option_manager;
- m_core = new SoundCore(this);
-
setWindowIcon(QIcon(":/32x32/qmmp.png"));
+ setWindowFlags(Qt::FramelessWindowHint);
+ setFixedSize (275,116);
+
+ //prepare libqmmp and libqmmpui libraries for playing
+ m_player = new MediaPlayer(this);
+ m_core = new SoundCore(this);
+ m_playListModel = new PlayListModel(this);
+ m_player->initialize(m_core, m_playListModel);
+ //additional featuries
+ new PlaylistParser(this);
+ Visual::initialize(this, m_visMenu, SLOT(updateActions()));
+ m_generalHandler = new GeneralHandler(this);
+ //user interface
m_skin = new Skin(this);
Dock *dock = new Dock(this);
dock->setMainWidget(this);
-
- setWindowFlags(Qt::FramelessWindowHint);
- setFixedSize (275,116);
-
display = new MainDisplay(this);
setCentralWidget(display);
display->show();
display->setFocus ();
- m_playlistName = tr("Default");
-
- new PlaylistParser(this);
m_playlist = new PlayList(this);
-
- connect (m_playlist,SIGNAL(next()),SLOT(next()));
- connect (m_playlist,SIGNAL(prev()),SLOT(previous()));
- connect (m_playlist,SIGNAL(play()),SLOT(play()));
- connect (m_playlist,SIGNAL(pause()),SLOT(pause()));
- connect (m_playlist,SIGNAL(stop()),SLOT(stop()));
- connect (m_playlist,SIGNAL(eject()),SLOT(addFile()));
-
- connect (m_playlist,SIGNAL(newPlaylist()),SLOT(newPlaylist()));
- connect (m_playlist,SIGNAL(loadPlaylist()),SLOT(loadPlaylist()));
- connect (m_playlist,SIGNAL(savePlaylist()),SLOT(savePlaylist()));
-
- m_playListModel = new PlayListModel(this);
-
- connect(display,SIGNAL(shuffleToggled(bool)),m_playListModel,SLOT(prepareForShufflePlaying(bool)));
- connect(display,SIGNAL(repeatableToggled(bool)),m_playListModel,SLOT(prepareForRepeatablePlaying(bool)));
-
+ m_playlist->setModel(m_playListModel);
dock->addWidget(m_playlist);
m_equalizer = new EqWidget(this);
dock->addWidget(m_equalizer);
- connect(m_equalizer, SIGNAL(valueChanged()), SLOT(updateEQ()));
-
- m_playlist->setModel(m_playListModel);
m_jumpDialog = new JumpToTrackDialog(this);
m_jumpDialog->setModel(m_playListModel);
- connect(m_jumpDialog,SIGNAL(playRequest()),this,SLOT(play()));
m_jumpDialog->hide();
- createActions();
-
m_titlebar = new TitleBar(this);
m_titlebar->move(0,0);
m_titlebar->show();
m_titlebar->setActive(TRUE);
- readSettings();
- dock->updateDock();
+ m_vis = MainVisual::getPointer();
+ Visual::add(m_vis);
- display->setEQ(m_equalizer);
- display->setPL(m_playlist);
+ createActions();
+ //connections
+ connect (m_playlist,SIGNAL(next()),SLOT(next()));
+ connect (m_playlist,SIGNAL(prev()),SLOT(previous()));
+ connect (m_playlist,SIGNAL(play()),SLOT(play()));
+ connect (m_playlist,SIGNAL(pause()), m_core ,SLOT(pause()));
+ connect (m_playlist,SIGNAL(stop()),SLOT(stop()));
+ connect (m_playlist,SIGNAL(eject()),SLOT(addFile()));
+ connect (m_playlist,SIGNAL(newPlaylist()),SLOT(newPlaylist()));
+ connect (m_playlist,SIGNAL(loadPlaylist()),SLOT(loadPlaylist()));
+ connect (m_playlist,SIGNAL(savePlaylist()),SLOT(savePlaylist()));
- m_vis = MainVisual::getPointer();
+ connect(display,SIGNAL(shuffleToggled(bool)),m_playListModel,SLOT(prepareForShufflePlaying(bool)));
+ connect(display,SIGNAL(repeatableToggled(bool)),m_playListModel,SLOT(prepareForRepeatablePlaying(bool)));
- Visual::initialize(this, m_visMenu, SLOT(updateActions()));
- Visual::add(m_vis);
+ connect(m_equalizer, SIGNAL(valueChanged()), SLOT(updateEQ()));
+
+ connect(m_jumpDialog,SIGNAL(playRequest()),this,SLOT(play()));
- connect(m_core, SIGNAL(finished()), SLOT(next()));
+ //connect(m_core, SIGNAL(finished()), SLOT(next()));
connect(m_core, SIGNAL(stateChanged(Qmmp::State)), SLOT(showState(Qmmp::State)));
connect(m_core, SIGNAL(elapsedChanged(qint64)),m_playlist, SLOT(setTime(qint64)));
connect(m_core, SIGNAL(elapsedChanged(qint64)),m_titlebar, SLOT(setTime(qint64)));
@@ -138,14 +132,15 @@ MainWindow::MainWindow(const QStringList& args, BuiltinCommandLineOption* option
connect(m_core, SIGNAL(bufferingProgress(int)), TextScroller::getPointer(),
SLOT(setProgress(int)));
- updateEQ();
-
- m_generalHandler = new GeneralHandler(this);
- connect(m_generalHandler, SIGNAL(playCalled()), SLOT(play()));
connect(m_generalHandler, SIGNAL(toggleVisibilityCalled()), SLOT(toggleVisibility()));
connect(m_generalHandler, SIGNAL(exitCalled()), SLOT(close()));
+ readSettings();
+ display->setEQ(m_equalizer);
+ display->setPL(m_playlist);
+ dock->updateDock();
m_playListModel->readSettings();
+ updateEQ();
char buf[PATH_MAX + 1];
QString cwd = QString::fromLocal8Bit(getcwd(buf,PATH_MAX));
processCommandArgs(args,cwd);
@@ -161,56 +156,7 @@ MainWindow::~MainWindow()
void MainWindow::play()
{
- disconnect(m_playListModel, SIGNAL(firstAdded()), this, SLOT(play()));
- m_playListModel->doCurrentVisibleRequest();
-
- if (m_core->state() == Qmmp::Paused)
- {
- pause();
- return;
- }
- //stop();
- if (m_playListModel->count() == 0)
- return;
-
- m_equalizer->loadPreset(m_playListModel->currentItem()->url().section("/",-1));
- //m_playListModel->currentItem()->updateTags();
- m_playlist->listWidget()->updateList();
- QString s = m_playListModel->currentItem()->url();
- if (s.isEmpty())
- return;
- if (m_core->play(s))
- /*m_generalHandler->setTime(0)*/;
- else
- {
- //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_playListModel->isEmptyQueue())
- {
- m_playListModel->setCurrentToQueued();
- }
- else if (!m_playListModel->next())
- {
- stop();
- display->hideTimeDisplay();
- return;
- }
- m_playlist->update();
- play();
- break;
- }
- }
- }
+ m_player->play();
}
void MainWindow::replay()
@@ -255,47 +201,12 @@ void MainWindow::stop()
void MainWindow::next()
{
- if (!m_playListModel->isEmptyQueue())
- {
- m_playListModel->setCurrentToQueued();
- }
- else if (!m_playListModel->next())
- {
- stop();
- display->hideTimeDisplay();
- return;
- }
- m_playlist->update();
- if (m_core->state() != Qmmp::Stopped)
- {
- if (m_core->state() == Qmmp::Paused)
- stop();
- m_elapsed = 0;
- play();
- }
- else
- display->hideTimeDisplay();
+ m_player->next();
}
void MainWindow::previous()
{
- if (!m_playListModel->previous())
- {
- stop();
- display->hideTimeDisplay();
- return;
- }
-
- m_playlist->update();
- if (m_core->state() != Qmmp::Stopped)
- {
- if (m_core->state() == Qmmp::Paused)
- stop();
- m_elapsed = 0;
- play();
- }
- else
- display->hideTimeDisplay();
+ m_player->previous();
}
void MainWindow::updateEQ()
@@ -309,10 +220,12 @@ void MainWindow::updateEQ()
void MainWindow::showState(Qmmp::State state)
{
+ disconnect(m_playListModel, SIGNAL(firstAdded()), this, SLOT(play()));
switch ((int) state)
{
case Qmmp::Playing:
{
+ m_equalizer->loadPreset(m_playListModel->currentItem()->url().section("/",-1));
if (m_playlist->listWidget())
m_playlist->listWidget()->updateList(); //removes progress message from TextScroller
break;
@@ -497,7 +410,7 @@ void MainWindow::createActions()
{
m_mainMenu = new QMenu(this);
m_mainMenu->addAction(tr("&Play"),this, SLOT(play()), tr("X"));
- m_mainMenu->addAction(tr("&Pause"),this, SLOT(pause()), tr("C"));
+ m_mainMenu->addAction(tr("&Pause"),m_core, SLOT(pause()), tr("C"));
m_mainMenu->addAction(tr("&Stop"),this, SLOT(stop()), tr("V"));
m_mainMenu->addAction(tr("&Previous"),this, SLOT(previous()), tr("Z"));
m_mainMenu->addAction(tr("&Next"),this, SLOT(next()), tr("B"));
@@ -609,7 +522,7 @@ void MainWindow::setFileList(const QStringList & l)
void MainWindow::playPause()
{
if (m_core->state() == Qmmp::Playing)
- pause();
+ m_core->pause();
else
play();
}
diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h
index 4add7ccb3..5442c9dfb 100644
--- a/src/ui/mainwindow.h
+++ b/src/ui/mainwindow.h
@@ -43,6 +43,7 @@ class SoundCore;
class JumpToTrackDialog;
class VisualMenu;
class GeneralHandler;
+class MediaPlayer;
class QMenu;
class QKeyEvent;
@@ -130,10 +131,10 @@ private:
QString m_playlistName;
JumpToTrackDialog* m_jumpDialog;
bool m_hideOnClose, m_startHidden;
- int m_elapsed;
VisualMenu *m_visMenu;
BuiltinCommandLineOption* m_option_manager;
GeneralHandler *m_generalHandler;
+ MediaPlayer *m_player;
};
#endif