Player factory
authorNikolay Tischenko <niktischenko@gmail.com>
Sun, 20 Mar 2011 14:08:00 +0000 (20:08 +0600)
committerNikolay Tischenko <niktischenko@gmail.com>
Sun, 20 Mar 2011 14:08:00 +0000 (20:08 +0600)
13 files changed:
src/config.cpp
src/dbusadaptor.cpp
src/dbusclient.h
src/mainwindow.cpp
src/player/abstractplayer.cpp [new file with mode: 0644]
src/player/abstractplayer.h [new file with mode: 0644]
src/player/player.cpp
src/player/player.h
src/player/playerfactory.cpp [new file with mode: 0644]
src/player/playerfactory.h [new file with mode: 0644]
src/playerform.cpp
src/playerform.h
src/src.pro

index 58cb3ba..f39bb7b 100644 (file)
@@ -35,6 +35,8 @@ Config::Config()
                _settings->setValue("ui/gradient", "yes");
        if (_settings->value("ui/language").toString() == "")
                _settings->setValue("ui/language", "en");
+       if (_settings->value("playback/player").isNull())
+               _settings->setValue("playback/player", "inner");
        if (_settings->value("ui/trackcolor").toString() == "")
                _settings->setValue("ui/trackcolor", "blue");
        _equalizer_settings = new QSettings("/etc/skel/.someplayer/equalizer.ini", QSettings::IniFormat);
index 72a61a1..83c1d5a 100644 (file)
@@ -27,7 +27,6 @@
 #include <QtCore/QVariant>
 #include <QDebug>
 #include "config.h"
-#include "player/player.h"
 
 /*
  * Implementation of adaptor class DBusAdaptop
index 0705294..5945464 100644 (file)
@@ -24,7 +24,6 @@
 #include <QtDBus/QtDBus>
 #include <QTimer>
 #include <QTime>
-#include "player/player.h"
 
 #define MM_KEY_UP (73)
 #define MM_KEY_DOWN (74)
index 2c26d35..b888452 100644 (file)
@@ -27,8 +27,6 @@
 #include <QTranslator>
 #include <QKeyEvent>
 
-#include "player/player.h"
-
 #include "library.h"
 #include "timerdialog.h"
 #include "equalizerdialog.h"
diff --git a/src/player/abstractplayer.cpp b/src/player/abstractplayer.cpp
new file mode 100644 (file)
index 0000000..7d07599
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * SomePlayer - An alternate music player for Maemo 5
+ * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include "abstractplayer.h"
+
+using namespace SomePlayer::Playback;
+
+AbstractPlayer::AbstractPlayer(QObject *parent) :
+               QObject(parent)
+{
+}
diff --git a/src/player/abstractplayer.h b/src/player/abstractplayer.h
new file mode 100644 (file)
index 0000000..148d392
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * SomePlayer - An alternate music player for Maemo 5
+ * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef ABSTRACTPLAYER_H
+#define ABSTRACTPLAYER_H
+
+#include <QObject>
+#include "../someplayer.h"
+#include "../track.h"
+#include "../trackmetainformation.h"
+#include "../playlist.h"
+
+using SomePlayer::DataObjects::Track;
+using SomePlayer::DataObjects::Playlist;
+using SomePlayer::DataObjects::LastPlayed;
+
+namespace SomePlayer {
+       namespace Playback {
+
+               enum PlayerState { PLAYER_STOPPED, PLAYER_PLAYING, PLAYER_PAUSED, PLAYER_LOADING, PLAYER_DONE, PLAYER_ERROR };
+               enum RepeatRule {REPEAT_NO, REPEAT_ALL, REPEAT_ONE};
+
+               class AbstractPlayer : public QObject
+               {
+
+                       Q_OBJECT
+               public:
+                       explicit AbstractPlayer(QObject *parent = 0);
+                       virtual bool random() = 0;
+                       virtual RepeatRule repeat() = 0;
+                       virtual bool equalizerEnabled() = 0;
+                       virtual bool equalizerAvailable() = 0;
+                       virtual Track current() = 0;
+                       virtual void setAwaitingSeek(int pos) = 0;
+
+               signals:
+                       void stateChanged (PlayerState);
+                       void trackChanged (Track);
+                       void tick (int, int); // played | all (seconds)
+                       void trackDone(Track);
+                       void saveLastPlayed(LastPlayed);
+                       void startPlaylist();
+
+               public slots:
+                       virtual void setTrackId(int id) = 0;
+                       virtual void enqueue(int id) = 0;
+                       virtual void toggle() = 0;
+                       virtual void play() = 0;
+                       virtual void pause() = 0;
+                       virtual void playIfPaused() = 0;
+                       virtual void stop() = 0;
+                       virtual void next() = 0;
+                       virtual void prev() = 0;
+                       virtual void setPlaylist(Playlist) = 0;
+                       virtual void toggleRandom() = 0;
+                       virtual void toggleRepeat() = 0;
+                       virtual void seek(int) = 0;
+                       virtual void enableEqualizer() = 0;
+                       virtual void disableEqualizer() = 0;
+                       virtual void setEqualizerValue(int band, double value) = 0;
+                       virtual void equalizerValue(int band, double *) = 0;
+                       virtual QString artist() = 0;
+                       virtual QString album() = 0;
+                       virtual QString title() = 0;
+                       virtual PlayerState state() = 0;
+                       virtual QString stateText() = 0;
+                       virtual QString albumart() = 0;
+                       virtual void setAlbumart(QString albumart) = 0;
+               };
+       };
+};
+
+#endif // ABSTRACTPLAYER_H
index 3bb3039..81c2525 100644 (file)
@@ -41,7 +41,7 @@ inline QList<Track> __sub(QList<Track> one, QList<Track> two, Track three) {
 }
 
 Player::Player(QObject *parent) :
-    QObject(parent)
+    AbstractPlayer(parent)
 {
        _awaiting_seek = false;
        _player = new Phonon::MediaObject(this);
index ab26c9d..3f780b5 100644 (file)
@@ -25,6 +25,7 @@
 #include "../track.h"
 #include "../trackmetainformation.h"
 #include "../playlist.h"
+#include "abstractplayer.h"
 #include <phonon/MediaObject>
 #include <phonon/AudioOutput>
 #include <phonon/Effect>
@@ -43,29 +44,31 @@ using SomePlayer::Storage::Config;
 namespace SomePlayer {
        namespace Playback {
 
-               enum PlayerState { PLAYER_STOPPED, PLAYER_PLAYING, PLAYER_PAUSED, PLAYER_LOADING, PLAYER_DONE, PLAYER_ERROR };
-               enum RepeatRule {REPEAT_NO, REPEAT_ALL, REPEAT_ONE};
+               class Randomizer {
+               public:
+                       void setPlaylist(QList<int>);
+                       int next();
+                       void removeId(int);
+               private:
+                       QList<int> _playlist;
+                       QList<int> _rand;
+                       void _shuffle();
+                       int _last;
+               };
 
-               class Player : public QObject
+               class Player : public AbstractPlayer
                {
                        Q_OBJECT
                public:
                        explicit Player(QObject *parent = 0);
                        ~Player();
-                       bool random() {return _random;}
-                       RepeatRule repeat() {return _repeat;}
-                       Phonon::MediaObject* mediaObject() {return _player;}
-                       bool equalizerEnabled() {return _equalizer_enabled;}
-                       bool equalizerAvailable() {return _equalizer != NULL;}
-                       Track current();
-                       void setAwaitingSeek(int pos) {_awaiting_seek = true; _awaiting_seek_pos = pos;}
-               signals:
-                       void stateChanged (PlayerState);
-                       void trackChanged (Track);
-                       void tick (int, int); // played | all (seconds)
-                       void trackDone(Track);
-                       void startPlaylist();
-                       void saveLastPlayed(LastPlayed);
+
+                       virtual bool random() {return _random;}
+                       virtual RepeatRule repeat() {return _repeat;}
+                       virtual bool equalizerEnabled() {return _equalizer_enabled;}
+                       virtual bool equalizerAvailable() {return _equalizer != NULL;}
+                       virtual Track current();
+                       virtual void setAwaitingSeek(int pos) {_awaiting_seek_pos = pos; _awaiting_seek = true;}
 
                public slots:
                        void setTrackId(int id);
diff --git a/src/player/playerfactory.cpp b/src/player/playerfactory.cpp
new file mode 100644 (file)
index 0000000..d61d4e2
--- /dev/null
@@ -0,0 +1,16 @@
+#include "playerfactory.h"
+#include "player.h"
+
+using namespace SomePlayer::Playback;
+using namespace SomePlayer::Storage;
+
+
+AbstractPlayer *SomePlayer::Playback::Factory::constructPlayer(QObject *parent) {
+       AbstractPlayer *player = NULL;
+       Config config;
+       QString player_type = config.getValue("playback/player").toString();
+       if (player_type == "inner") {
+               player = new Player(parent);
+       }
+       return player;
+}
diff --git a/src/player/playerfactory.h b/src/player/playerfactory.h
new file mode 100644 (file)
index 0000000..e1a09fa
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef PLAYERFACTORY_H
+#define PLAYERFACTORY_H
+
+#include <QObject>
+#include "../someplayer.h"
+#include "abstractplayer.h"
+
+namespace SomePlayer {
+       namespace Playback {
+               namespace Factory {
+                       AbstractPlayer *constructPlayer(QObject *parent);
+               };
+       };
+};
+
+
+#endif // PLAYERFACTORY_H
index d07efb3..3234910 100644 (file)
@@ -20,7 +20,7 @@
 #include "playerform.h"
 #include "ui_playerform.h"
 #include "library.h"
-#include "player/player.h"
+#include "player/abstractplayer.h"
 #include <QTime>
 #include <QSlider>
 #include "trackrenderer.h"
@@ -57,7 +57,7 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) :
        _lib = lib;
        Config config;
        _icons_theme = config.getValue("ui/iconstheme").toString();
-       _player = new Player(this);
+       _player = SomePlayer::Playback::Factory::constructPlayer(this);
        _time = new QTime();
        ui->setupUi(this);
        if (_player->random()) {
index ff8afbb..c795f57 100644 (file)
@@ -24,7 +24,8 @@
 #include "someplayer.h"
 #include "playlist.h"
 #include <QStandardItemModel>
-#include "player/player.h"
+#include "player/abstractplayer.h"
+#include "player/playerfactory.h"
 #include <QSlider>
 #include <QMenu>
 #include <QTime>
@@ -44,7 +45,7 @@ namespace Ui {
 using SomePlayer::DataObjects::Library;
 using SomePlayer::DataObjects::Playlist;
 using SomePlayer::DataObjects::Track;
-using SomePlayer::Playback::Player;
+using SomePlayer::Playback::AbstractPlayer;
 using SomePlayer::Playback::PlayerState;
 using SomePlayer::DataObjects::TagResolver;
 
@@ -129,7 +130,7 @@ private:
        QTime *_time;
        QStandardItemModel *_model;
        CoverFinder *_coverfinder;
-       Player *_player;
+       AbstractPlayer *_player;
        QSlider *_seek_slider;
        QMenu *_context_menu;
        QString _search_pattern;
index bcfc591..aa7fca7 100644 (file)
@@ -130,7 +130,9 @@ SOURCES += main.cpp\
     dbusclient.cpp \
     fmtxsettingsdialog.cpp \
     aboutform.cpp \
-    playlistsortform.cpp
+    playlistsortform.cpp \
+    player/abstractplayer.cpp \
+    player/playerfactory.cpp
 
 HEADERS  += mainwindow.h \
                player/player.h \
@@ -239,7 +241,9 @@ HEADERS  += mainwindow.h \
     dbusclient.h \
     fmtxsettingsdialog.h \
     aboutform.h \
-    playlistsortform.h
+    playlistsortform.h \
+    player/abstractplayer.h \
+    player/playerfactory.h
 
 FORMS    += ui/mainwindow.ui \
     ui/playerform.ui \