From de6604ba0154d3233889a330b8f229c952614021 Mon Sep 17 00:00:00 2001 From: Nikolay Tischenko Date: Sat, 11 Sep 2010 20:11:35 +0700 Subject: [PATCH] Created separate directory for player engine --- someplayer.pro | 18 +++++++++----- someplayer.pro.user | 2 +- src/libraryform.cpp | 14 +++++++++++ src/libraryform.h | 22 +++++++++++++++++ src/mainwindow.cpp | 35 ++++++++++++++++++++++++++ src/mainwindow.h | 10 ++++++++ src/player.cpp | 18 -------------- src/player.h | 24 ------------------ src/player/player.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++ src/player/player.h | 45 +++++++++++++++++++++++++++++++++ src/playerform.cpp | 19 ++++++++++++++ src/playerform.h | 27 ++++++++++++++++++++ src/someplayer.h | 6 +++++ src/track.cpp | 31 ++++++++++++++++++++--- src/track.h | 11 ++++++++- src/ui/libraryform.ui | 28 +++++++++++++++++++++ src/ui/mainwindow.ui | 66 ++++++++++++++++++++++++++++++------------------- src/ui/playerform.ui | 28 +++++++++++++++++++++ 18 files changed, 383 insertions(+), 78 deletions(-) create mode 100644 src/libraryform.cpp create mode 100644 src/libraryform.h delete mode 100644 src/player.cpp delete mode 100644 src/player.h create mode 100644 src/player/player.cpp create mode 100644 src/player/player.h create mode 100644 src/playerform.cpp create mode 100644 src/playerform.h create mode 100644 src/ui/libraryform.ui create mode 100644 src/ui/playerform.ui diff --git a/someplayer.pro b/someplayer.pro index 3a3ad14..ef76e94 100644 --- a/someplayer.pro +++ b/someplayer.pro @@ -12,7 +12,7 @@ TEMPLATE = app SOURCES += src/main.cpp\ src/mainwindow.cpp \ - src/player.cpp \ + src/player/player.cpp \ src/track.cpp \ src/trackmetainformation.cpp \ src/playlist.cpp \ @@ -20,11 +20,13 @@ SOURCES += src/main.cpp\ src/filestorage.cpp \ src/dbstorage.cpp \ src/mediascanner.cpp \ - src/tagresolver.cpp + src/tagresolver.cpp \ + src/playerform.cpp \ + src/libraryform.cpp HEADERS += src/mainwindow.h \ - src/player.h \ - src/track.h \ + src/player/player.h \ + src/track.h \ src/trackmetainformation.h \ src/playlist.h \ src/someplayer.h \ @@ -33,9 +35,13 @@ HEADERS += src/mainwindow.h \ src/filestorage.h \ src/dbstorage.h \ src/mediascanner.h \ - src/tagresolver.h + src/tagresolver.h \ + src/playerform.h \ + src/libraryform.h -FORMS += src/ui/mainwindow.ui +FORMS += src/ui/mainwindow.ui \ + src/ui/playerform.ui \ + src/ui/libraryform.ui CONFIG += mobility MOBILITY = diff --git a/someplayer.pro.user b/someplayer.pro.user index 2d3304b..94896bd 100644 --- a/someplayer.pro.user +++ b/someplayer.pro.user @@ -202,7 +202,7 @@ 1 - 2010-09-05T23:00:23 + 2010-09-10T01:22:53 1 diff --git a/src/libraryform.cpp b/src/libraryform.cpp new file mode 100644 index 0000000..b41545d --- /dev/null +++ b/src/libraryform.cpp @@ -0,0 +1,14 @@ +#include "libraryform.h" +#include "ui_libraryform.h" + +LibraryForm::LibraryForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::LibraryForm) +{ + ui->setupUi(this); +} + +LibraryForm::~LibraryForm() +{ + delete ui; +} diff --git a/src/libraryform.h b/src/libraryform.h new file mode 100644 index 0000000..a4aefc5 --- /dev/null +++ b/src/libraryform.h @@ -0,0 +1,22 @@ +#ifndef LIBRARYFORM_H +#define LIBRARYFORM_H + +#include + +namespace Ui { + class LibraryForm; +} + +class LibraryForm : public QWidget +{ + Q_OBJECT + +public: + explicit LibraryForm(QWidget *parent = 0); + ~LibraryForm(); + +private: + Ui::LibraryForm *ui; +}; + +#endif // LIBRARYFORM_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5038088..20dc3a9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -14,10 +14,25 @@ MainWindow::MainWindow(QWidget *parent) : { ui->setupUi(this); connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openMedia())); + connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt())); + connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about())); + connect(ui->actionPlayer, SIGNAL(triggered()), this, SLOT(player())); + connect(ui->actionLibrary, SIGNAL(triggered()), this, SLOT(library())); + setAnimated(true); + _playerForm = new PlayerForm(); + _libraryForm = new LibraryForm(); + ui->stackedWidget->insertWidget(0, _playerForm); + ui->stackedWidget->insertWidget(1, _libraryForm); + _playerForm->setAttribute(Qt::WA_Maemo5StackedWindow); + _libraryForm->setAttribute(Qt::WA_Maemo5StackedWindow); + connect(_playerForm, SIGNAL(library()), this, SLOT(library())); + library(); } MainWindow::~MainWindow() { + delete _playerForm; + delete _libraryForm; delete ui; } @@ -26,3 +41,23 @@ void MainWindow::openMedia() // SomePlayer::DataObjects::Library *l = new SomePlayer::DataObjects::Library("/tmp", "/tmp"); // l->addDirectory("/mnt/music/Three Days Grace"); } + +void MainWindow::aboutQt() { + QMessageBox::aboutQt(this, "About Qt"); +} + +void MainWindow::about() { + QMessageBox::about(this, "About SomePlayer", "Alternate music player for Maemo 5 " + "written in C++ with Qt4\n\n" + "Author: Nikolay Tischenko aka \"somebody\" "); +} + +void MainWindow::player() { + ui->stackedWidget->setCurrentIndex(0); + setWindowTitle("SomePlayer"); +} + +void MainWindow::library() { + ui->stackedWidget->setCurrentIndex(1); + setWindowTitle("SomePlayer Library"); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 6662fb8..5acedb4 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -2,6 +2,9 @@ #define MAINWINDOW_H #include +#include +#include "playerform.h" +#include "libraryform.h" namespace Ui { class MainWindow; @@ -20,6 +23,13 @@ private: public slots: void openMedia(); + void aboutQt(); + void about(); + void player(); + void library(); +private: + PlayerForm *_playerForm; + LibraryForm *_libraryForm; }; #endif // MAINWINDOW_H diff --git a/src/player.cpp b/src/player.cpp deleted file mode 100644 index 2b1caaa..0000000 --- a/src/player.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "player.h" - -Player::Player() : QObject() -{ -object = new Phonon::MediaObject(this); - output = new Phonon::AudioOutput(Phonon::MusicCategory, this); - Phonon::createPath(object, output); -} - -Player::~Player() -{ -} - -void Player::playSong(QString filename) -{ - object->setCurrentSource(Phonon::MediaSource(filename)); - object->play(); -} diff --git a/src/player.h b/src/player.h deleted file mode 100644 index 0350e02..0000000 --- a/src/player.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef PLAYER_H -#define PLAYER_H -#include -#include -#include -#include -#include -#include - -class Player : public QObject -{ - Q_OBJECT -public: - explicit Player(); - ~Player(); -private: - Phonon::MediaObject *object; - Phonon::AudioOutput *output; - -public slots: - void playSong(QString filename); -}; - -#endif // PLAYER_H diff --git a/src/player/player.cpp b/src/player/player.cpp new file mode 100644 index 0000000..4670db3 --- /dev/null +++ b/src/player/player.cpp @@ -0,0 +1,57 @@ +#include "player.h" +#include + +using namespace SomePlayer::Playback; +using namespace SomePlayer::DataObjects; + +Player::Player(QObject *parent) : + QObject(parent) +{ + _player = NULL; +} + +void Player::setTrack(Track &track) { + _current_track = track; + _create_player(); + emit stateChanged(PLAYER_LOADING); +} + +void Player::play() { + if (_player) { + _player->play(); + emit stateChanged(PLAYER_PLAYING); + } +} + +void Player::stop() { + if (_player) { + _player->stop(); + emit stateChanged(PLAYER_STOPPED); + } +} + +void Player::pause() { + if (_player) { + _player->pause(); + emit stateChanged(PLAYER_PAUSED); + } +} + +void Player::_create_player() { + if (_player) { + disconnect(_player, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(_stateChanged(Phonon::State,Phonon::State))); + delete _player; + } + _player = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource(_current_track.source())); + _player->setTickInterval(1000); + connect(_player, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(_stateChanged(Phonon::State,Phonon::State))); + connect(_player, SIGNAL(tick(qint64)), this, SLOT(_tick(qint64))); + emit stateChanged(PLAYER_STOPPED); +} + +void Player::_stateChanged(Phonon::State newState, Phonon::State oldState) { +} + +void Player::_tick(qint64 ticks) { + emit tick(ticks/1000, _current_track.metadata().length()); +} diff --git a/src/player/player.h b/src/player/player.h new file mode 100644 index 0000000..78e5ff4 --- /dev/null +++ b/src/player/player.h @@ -0,0 +1,45 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include +#include "someplayer.h" +#include "track.h" +#include +#include + +// represents player + +using SomePlayer::DataObjects::Track; + +namespace SomePlayer { + namespace Playback { + + enum PlayerState { PLAYER_STOPPED, PLAYER_PLAYING, PLAYER_PAUSED, PLAYER_LOADING, PLAYER_DONE }; + + class Player : public QObject + { + Q_OBJECT + public: + explicit Player(QObject *parent = 0); + + signals: + void stateChanged (PlayerState); + void tick (int, int); // played | all (seconds) + + public slots: + void setTrack(Track&); + void play(); + void pause(); + void stop(); + private slots: + void _stateChanged(Phonon::State, Phonon::State); + void _tick(qint64); + private: + Track _current_track; + Phonon::MediaObject *_player; + void _create_player(); + }; + }; +}; + +#endif // PLAYER_H diff --git a/src/playerform.cpp b/src/playerform.cpp new file mode 100644 index 0000000..3040bb1 --- /dev/null +++ b/src/playerform.cpp @@ -0,0 +1,19 @@ +#include "playerform.h" +#include "ui_playerform.h" + +PlayerForm::PlayerForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::PlayerForm) +{ + ui->setupUi(this); + connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(_library())); +} + +PlayerForm::~PlayerForm() +{ + delete ui; +} + +void PlayerForm::_library() { + emit library(); +} diff --git a/src/playerform.h b/src/playerform.h new file mode 100644 index 0000000..6c06393 --- /dev/null +++ b/src/playerform.h @@ -0,0 +1,27 @@ +#ifndef PLAYERFORM_H +#define PLAYERFORM_H + +#include + +namespace Ui { + class PlayerForm; +} + +class PlayerForm : public QWidget +{ + Q_OBJECT + +public: + explicit PlayerForm(QWidget *parent = 0); + ~PlayerForm(); +signals: + void library(); + +private slots: + void _library(); + +private: + Ui::PlayerForm *ui; +}; + +#endif // PLAYERFORM_H diff --git a/src/someplayer.h b/src/someplayer.h index f87ce07..b02f444 100644 --- a/src/someplayer.h +++ b/src/someplayer.h @@ -5,9 +5,15 @@ namespace SomePlayer { namespace DataObjects { + class Track; + class TrackMetadata; + class TagResolver; + class Playlist; }; namespace Storage { }; + namespace Playback { + }; }; // common includes diff --git a/src/track.cpp b/src/track.cpp index 4dcd9b9..b5634e6 100644 --- a/src/track.cpp +++ b/src/track.cpp @@ -1,21 +1,30 @@ #include "track.h" +#include "tagresolver.h" using namespace SomePlayer::DataObjects; -Track::Track() { +Track::Track() : QObject() { } -Track::Track(int id, TrackMetadata metadata, QString source) { +Track::Track(int id, TrackMetadata metadata, QString source) : QObject() { _id = id; _metadata = metadata; _source = source; } -Track::Track(const Track &track) { +Track::Track(const Track &track) : QObject() { this->_metadata = track.metadata(); this->_source = track.source(); } +Track::Track(QString source) :QObject() { + _resolver = new TagResolver(this); + connect(_resolver, SIGNAL(decoded(Track)), this, SLOT(decoded(Track))); + QStringList foo; + foo << source; + _resolver->decode(foo); +} + TrackMetadata Track::metadata() const { return _metadata; } @@ -39,3 +48,19 @@ int Track::count() const{ void Track::setCount(int count) { _count = count; } + +void Track::decoded(Track track) { + _id = track.id(); + _source = track.source(); + _metadata = track.metadata(); + delete _resolver; +} + +Track &Track::operator =(const Track &track) { + _id = track.id(); + _source = track.source(); + _metadata = track.metadata(); + return *this; +} + +Track::~Track() {} diff --git a/src/track.h b/src/track.h index 2ee621f..4288823 100644 --- a/src/track.h +++ b/src/track.h @@ -3,18 +3,24 @@ #include "someplayer.h" #include "trackmetainformation.h" +#include "tagresolver.h" // represents some track: metainformation + source url namespace SomePlayer { namespace DataObjects { - class Track + class Track : public QObject { + Q_OBJECT + public: Track(); Track(const Track &track); Track(int id, TrackMetadata metadata, QString source); + Track(QString source); + ~Track(); + Track &operator=(const Track &track); TrackMetadata metadata() const; //read-write QString source() const; int id() const; @@ -27,6 +33,9 @@ namespace SomePlayer { QString _source; int _count; int _id; + TagResolver *_resolver; + private slots: + void decoded(Track); }; }; diff --git a/src/ui/libraryform.ui b/src/ui/libraryform.ui new file mode 100644 index 0000000..79017b2 --- /dev/null +++ b/src/ui/libraryform.ui @@ -0,0 +1,28 @@ + + + LibraryForm + + + + 0 + 0 + 800 + 480 + + + + Form + + + + + + ОЛОЛО!! + + + + + + + + diff --git a/src/ui/mainwindow.ui b/src/ui/mainwindow.ui index 38afdfc..0a50b25 100644 --- a/src/ui/mainwindow.ui +++ b/src/ui/mainwindow.ui @@ -13,7 +13,16 @@ someplayer - + + + + + + + + + + @@ -23,43 +32,50 @@ 23 - + + + View + + + + + - File + Help - + + - + + Open media - + + + Player + + + + + Library + + + + + About + + + - Quit + About Qt - - - actionQuit - triggered() - MainWindow - close() - - - -1 - -1 - - - 399 - 239 - - - - + diff --git a/src/ui/playerform.ui b/src/ui/playerform.ui new file mode 100644 index 0000000..6311270 --- /dev/null +++ b/src/ui/playerform.ui @@ -0,0 +1,28 @@ + + + PlayerForm + + + + 0 + 0 + 800 + 480 + + + + Form + + + + + + ПЫЩ!! + + + + + + + + -- 1.7.9.5