Created separate directory for player engine
authorNikolay Tischenko <niktischenko@gmail.com>
Sat, 11 Sep 2010 13:11:35 +0000 (20:11 +0700)
committerNikolay Tischenko <niktischenko@gmail.com>
Sat, 11 Sep 2010 13:11:35 +0000 (20:11 +0700)
18 files changed:
someplayer.pro
someplayer.pro.user
src/libraryform.cpp [new file with mode: 0644]
src/libraryform.h [new file with mode: 0644]
src/mainwindow.cpp
src/mainwindow.h
src/player.cpp [deleted file]
src/player.h [deleted file]
src/player/player.cpp [new file with mode: 0644]
src/player/player.h [new file with mode: 0644]
src/playerform.cpp [new file with mode: 0644]
src/playerform.h [new file with mode: 0644]
src/someplayer.h
src/track.cpp
src/track.h
src/ui/libraryform.ui [new file with mode: 0644]
src/ui/mainwindow.ui
src/ui/playerform.ui [new file with mode: 0644]

index 3a3ad14..161de1c 100644 (file)
@@ -20,7 +20,9 @@ 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 \
@@ -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 = 
index 2d3304b..94896bd 100644 (file)
     <valuemap key="Qt4ProjectManager.MaemoRunConfiguration.DebuggingHelpersLastDeployed" type="QVariantMap"/>
     <value key="Qt4ProjectManager.MaemoRunConfiguration.DeviceId" type="qulonglong">1</value>
     <valuemap key="Qt4ProjectManager.MaemoRunConfiguration.LastDeployed" type="QVariantMap">
-     <value key="192.168.77.2" type="QDateTime">2010-09-05T23:00:23</value>
+     <value key="192.168.77.2" type="QDateTime">2010-09-10T01:22:53</value>
     </valuemap>
    </valuemap>
    <value key="ProjectExplorer.Target.RunConfigurationCount" type="int">1</value>
diff --git a/src/libraryform.cpp b/src/libraryform.cpp
new file mode 100644 (file)
index 0000000..b41545d
--- /dev/null
@@ -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 (file)
index 0000000..a4aefc5
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef LIBRARYFORM_H
+#define LIBRARYFORM_H
+
+#include <QWidget>
+
+namespace Ui {
+    class LibraryForm;
+}
+
+class LibraryForm : public QWidget
+{
+    Q_OBJECT
+
+public:
+    explicit LibraryForm(QWidget *parent = 0);
+    ~LibraryForm();
+
+private:
+    Ui::LibraryForm *ui;
+};
+
+#endif // LIBRARYFORM_H
index 5038088..20dc3a9 100644 (file)
@@ -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\" <niktischenko@gmail.com>");
+}
+
+void MainWindow::player() {
+       ui->stackedWidget->setCurrentIndex(0);
+       setWindowTitle("SomePlayer");
+}
+
+void MainWindow::library() {
+       ui->stackedWidget->setCurrentIndex(1);
+       setWindowTitle("SomePlayer Library");
+}
index 6662fb8..5acedb4 100644 (file)
@@ -2,6 +2,9 @@
 #define MAINWINDOW_H
 
 #include <QMainWindow>
+#include <QMessageBox>
+#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 (file)
index 2b1caaa..0000000
+++ /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 (file)
index 0350e02..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef PLAYER_H
-#define PLAYER_H
-#include <QObject>
-#include <phonon/audiooutput.h>
-#include <phonon/seekslider.h>
-#include <phonon/mediaobject.h>
-#include <phonon/volumeslider.h>
-#include <phonon/backendcapabilities.h>
-
-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 (file)
index 0000000..4670db3
--- /dev/null
@@ -0,0 +1,57 @@
+#include "player.h"
+#include <phonon/MediaSource>
+
+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 (file)
index 0000000..78e5ff4
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef PLAYER_H
+#define PLAYER_H
+
+#include <QObject>
+#include "someplayer.h"
+#include "track.h"
+#include <phonon/MediaObject>
+#include <phonon/AudioOutput>
+
+// 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 (file)
index 0000000..3040bb1
--- /dev/null
@@ -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 (file)
index 0000000..6c06393
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef PLAYERFORM_H
+#define PLAYERFORM_H
+
+#include <QWidget>
+
+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
index f87ce07..b02f444 100644 (file)
@@ -5,9 +5,15 @@
 
 namespace SomePlayer {
        namespace DataObjects {
+               class Track;
+               class TrackMetadata;
+               class TagResolver;
+               class Playlist;
        };
        namespace Storage {
        };
+       namespace Playback {
+       };
 };
 
 // common includes
index 4dcd9b9..b5634e6 100644 (file)
@@ -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() {}
index 2ee621f..4288823 100644 (file)
@@ -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 (file)
index 0000000..79017b2
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LibraryForm</class>
+ <widget class="QWidget" name="LibraryForm">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>480</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QPushButton" name="pushButton">
+     <property name="text">
+      <string>ОЛОЛО!!</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
index 38afdfc..0a50b25 100644 (file)
   <property name="windowTitle">
    <string>someplayer</string>
   </property>
-  <widget class="QWidget" name="centralWidget"/>
+  <widget class="QWidget" name="centralWidget">
+   <layout class="QGridLayout" name="gridLayout_2">
+    <item row="0" column="0">
+     <widget class="QStackedWidget" name="stackedWidget">
+      <widget class="QWidget" name="page"/>
+      <widget class="QWidget" name="page_2"/>
+     </widget>
+    </item>
+   </layout>
+  </widget>
   <widget class="QMenuBar" name="menuBar">
    <property name="geometry">
     <rect>
      <height>23</height>
     </rect>
    </property>
-   <widget class="QMenu" name="menuFile">
+   <widget class="QMenu" name="menuView">
+    <property name="title">
+     <string>View</string>
+    </property>
+    <addaction name="actionLibrary"/>
+    <addaction name="actionPlayer"/>
+   </widget>
+   <widget class="QMenu" name="menuHelp">
     <property name="title">
-     <string>File</string>
+     <string>Help</string>
     </property>
-    <addaction name="actionOpen"/>
+    <addaction name="actionAbout"/>
+    <addaction name="actionAbout_Qt"/>
    </widget>
-   <addaction name="menuFile"/>
+   <addaction name="menuView"/>
+   <addaction name="menuHelp"/>
   </widget>
   <action name="actionOpen">
    <property name="text">
     <string>Open media</string>
    </property>
   </action>
-  <action name="actionQuit">
+  <action name="actionPlayer">
+   <property name="text">
+    <string>Player</string>
+   </property>
+  </action>
+  <action name="actionLibrary">
+   <property name="text">
+    <string>Library</string>
+   </property>
+  </action>
+  <action name="actionAbout">
+   <property name="text">
+    <string>About</string>
+   </property>
+  </action>
+  <action name="actionAbout_Qt">
    <property name="text">
-    <string>Quit</string>
+    <string>About Qt</string>
    </property>
   </action>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
  <resources/>
- <connections>
-  <connection>
-   <sender>actionQuit</sender>
-   <signal>triggered()</signal>
-   <receiver>MainWindow</receiver>
-   <slot>close()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>-1</x>
-     <y>-1</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>399</x>
-     <y>239</y>
-    </hint>
-   </hints>
-  </connection>
- </connections>
+ <connections/>
 </ui>
diff --git a/src/ui/playerform.ui b/src/ui/playerform.ui
new file mode 100644 (file)
index 0000000..6311270
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PlayerForm</class>
+ <widget class="QWidget" name="PlayerForm">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>480</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QPushButton" name="pushButton">
+     <property name="text">
+      <string>ПЫЩ!!</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>