summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--beetplayer.cpp14
-rw-r--r--beetplayer.h2
-rw-r--r--playerwidget.cpp54
-rw-r--r--playerwidget.h5
4 files changed, 44 insertions, 31 deletions
diff --git a/beetplayer.cpp b/beetplayer.cpp
index fd0d174..7bc0df9 100644
--- a/beetplayer.cpp
+++ b/beetplayer.cpp
@@ -22,7 +22,7 @@ BeetPlayer::BeetPlayer(QWidget *parent, Qt::WindowFlags f) : QMainWindow(parent,
createGlobalActions();
mPlayerWidget = new PlayerWidget;
connect(mPlayerWidget, SIGNAL(viewModeChanged(QString)), this, SLOT(setViewMode(QString)));
- connect(mPlayerWidget->player(), SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(setPlayMode(QMediaPlayer::State)));
+ connect(mPlayerWidget, SIGNAL(playModeChanged(QString)), this, SLOT(setPlayMode(QString)));
connect(mPlayerWidget, SIGNAL(numFilesChanged(int)), this, SLOT(setNumFiles(int)));
connect(mPlayerWidget, SIGNAL(playListLengthChanged(quint64)), this, SLOT(setPlayListLength(quint64)));
connect(mPlayerWidget, SIGNAL(message(QString)), this, SLOT(setMessage(QString)));
@@ -78,16 +78,8 @@ void BeetPlayer::setViewMode(const QString &viewMode){
mModeL->setText(viewMode);
}
-void BeetPlayer::setPlayMode(QMediaPlayer::State state){
- if(state == QMediaPlayer::StoppedState){
- mActionL->setText(tr("Stopped"));
- }else if(state == QMediaPlayer::PlayingState){
- mActionL->setText("Playing");
- }else if(state == QMediaPlayer::PausedState){
- mActionL->setText("Paused");
- }else{
- mActionL->setText(tr("Unknown"));
- }
+void BeetPlayer::setPlayMode(const QString &playMode){
+ mActionL->setText(playMode);
}
void BeetPlayer::setNumFiles(int numFiles){
diff --git a/beetplayer.h b/beetplayer.h
index d6e9a7b..688ae32 100644
--- a/beetplayer.h
+++ b/beetplayer.h
@@ -16,7 +16,7 @@ class BeetPlayer : public QMainWindow {
public slots:
void configure();
void setViewMode(const QString &viewMode);
- void setPlayMode(QMediaPlayer::State state);
+ void setPlayMode(const QString &playMode);
void setNumFiles(int numFiles);
void setPlayListLength(quint64 seconds);
void setMessage(const QString &msg);
diff --git a/playerwidget.cpp b/playerwidget.cpp
index 77afffc..d2c30ac 100644
--- a/playerwidget.cpp
+++ b/playerwidget.cpp
@@ -40,7 +40,7 @@ void PlayerWidget::setupGui(){
mPlayer = new QMediaPlayer(this);
connect(mPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(setPosition(qint64)));
connect(mPlayer, SIGNAL(durationChanged(qint64)), this, SLOT(setDuration(qint64)));
- connect(mPlayer, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(continuePlaying(QMediaPlayer::State)));
+ connect(mPlayer, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(continuePlaying(QMediaPlayer::MediaStatus)));
//THE view
mView = new BeetView;
@@ -197,15 +197,15 @@ void PlayerWidget::createActions(){
mPlayA->setCheckable(true);
playAG->addAction(mPlayA);
connect(mPlayA, SIGNAL(triggered()), this, SLOT(doPlay()));
- QAction *pauseA = new QAction(QIcon(":/pause.png"), tr("Pause"), this);
- pauseA->setCheckable(true);
- playAG->addAction(pauseA);
- connect(pauseA, SIGNAL(triggered()), mPlayer, SLOT(pause()));
+ mPauseA = new QAction(QIcon(":/pause.png"), tr("Pause"), this);
+ mPauseA->setCheckable(true);
+ playAG->addAction(mPauseA);
+ connect(mPauseA, SIGNAL(triggered()), this, SLOT(doPause()));
mStopA = new QAction(QIcon(":/stop.png"), tr("Stop"), this);
mStopA->setCheckable(true);
playAG->addAction(mStopA);
- mStopA->trigger();
- connect(mStopA, SIGNAL(triggered()), mPlayer, SLOT(stop()));
+ mStopA->setChecked(true);
+ connect(mStopA, SIGNAL(triggered()), this, SLOT(doStop()));
QAction *previousA = new QAction(QIcon(":/previous.png"), tr("Previous"), this);
connect(previousA, SIGNAL(triggered()), this, SLOT(previous()));
QAction *nextA = new QAction(QIcon(":/next.png"), tr("Next"), this);
@@ -246,7 +246,7 @@ void PlayerWidget::createActions(){
spacer1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
mToolBar->addWidget(spacer1);
mToolBar->addAction(mPlayA);
- mToolBar->addAction(pauseA);
+ mToolBar->addAction(mPauseA);
mToolBar->addAction(mStopA);
mToolBar->addSeparator();
mToolBar->addAction(previousA);
@@ -532,10 +532,16 @@ void PlayerWidget::viewDoubleClicked(const QModelIndex &idx){
}
void PlayerWidget::doPlay(){
+ if(mPlayer->state() == QMediaPlayer::PausedState){
+ mPlayer->play();
+ mPlayA->setChecked(true);
+ emit playModeChanged(tr("Playing"));
+ return;
+ }
int playListCount = mPlayListModel->rowCount();
if(playListCount == 0){
emit message(tr("Playlist is empty! Dazed and confused, but trying to continue..."));
- mStopA->trigger();
+ doStop();
return;
}
QModelIndexList sel = mPlayListView->selectionModel()->selectedRows();
@@ -546,6 +552,18 @@ void PlayerWidget::doPlay(){
playCurrent(sel.first());
}
+void PlayerWidget::doStop(){
+ mPlayer->stop();
+ mStopA->setChecked(true);
+ emit playModeChanged(tr("Stopped"));
+}
+
+void PlayerWidget::doPause(){
+ mPlayer->pause();
+ mPauseA->setChecked(true);
+ emit playModeChanged(tr("Paused"));
+}
+
void PlayerWidget::recurse(const QModelIndex &parent){
for(int i = 0; i < mCurrentModel->rowCount(parent); ++i){
QModelIndex cur = mCurrentModel->index(i, 0, parent);
@@ -751,7 +769,7 @@ void PlayerWidget::randomPlay(){
}
void PlayerWidget::playCurrent(const QModelIndex &index){
- mStopA->trigger();
+ mPlayer->stop();
QString fullPath = index.data(FullPathRole).toString();
play(fullPath);
}
@@ -776,8 +794,11 @@ void PlayerWidget::play(const QString &fullPath){
mCurrentTE->append(QString("%1 %2").arg(tr("Genre:"), -20).arg(genre));
mCurrentTE->append(QString("%1 %2").arg(tr("Track:"), -20).arg(track, 3, 10, QChar('0')));
mCurrentTE->append(QString("%1 %2").arg(tr("Year:"), -20).arg(year, 4, 10));
+ QString msg = QString("File: %1").arg(fullPath);
+ emit message(msg);
mPlayer->play();
mPlayA->setChecked(true);
+ emit playModeChanged(tr("Playing"));
}
void PlayerWidget::volumeChanged(int volume){
@@ -798,15 +819,14 @@ void PlayerWidget::previous(){
}
void PlayerWidget::advance(int numSongs){
- mStopA->trigger();
+ mPlayer->stop();
QModelIndexList sel = mPlayListView->selectionModel()->selectedRows();
if(sel.isEmpty()){
QStandardItem *root = mPlayListModel->invisibleRootItem();
if(root->rowCount() > 0){
QModelIndex first = mPlayListModel->index(0, 0);
mPlayListView->selectionModel()->setCurrentIndex(first, QItemSelectionModel::ClearAndSelect);
- QString fp = first.data(FullPathRole).toString();
- play(fp);
+ playCurrent(first);
return;
}
return;
@@ -815,9 +835,7 @@ void PlayerWidget::advance(int numSongs){
QModelIndex nextIdx = mPlayListModel->index(cur.row() + numSongs, 0);
if(nextIdx.isValid()){
mPlayListView->selectionModel()->setCurrentIndex(nextIdx, QItemSelectionModel::ClearAndSelect);
- cur = nextIdx;
- QString fp = cur.data(FullPathRole).toString();
- play(fp);
+ playCurrent(nextIdx);
}
}
@@ -849,8 +867,8 @@ void PlayerWidget::setDuration(qint64 dur){
mCurrentTE->append(QString("%1 %2:%3").arg(tr("Length:"), -20).arg(minutes, 2, 10, QChar('0')).arg(seconds, 2, 10, QChar('0')));
}
-void PlayerWidget::continuePlaying(QMediaPlayer::State state){
- if(mPlayA->isChecked() && state == QMediaPlayer::StoppedState){
+void PlayerWidget::continuePlaying(QMediaPlayer::MediaStatus state){
+ if(state == QMediaPlayer::EndOfMedia){
next();
}
}
diff --git a/playerwidget.h b/playerwidget.h
index 14df101..4a152f6 100644
--- a/playerwidget.h
+++ b/playerwidget.h
@@ -33,6 +33,8 @@ class PlayerWidget : public QWidget {
void doPopulateByFolder(QString dir = QString());
void viewDoubleClicked(const QModelIndex &idx);
void doPlay();
+ void doStop();
+ void doPause();
void doFilter();
void clearFilter();
void reindex();
@@ -50,7 +52,7 @@ class PlayerWidget : public QWidget {
void setPosition(qint64 pos);
void setDuration(qint64 dur);
void slide(int value);
- void continuePlaying(QMediaPlayer::State state);
+ void continuePlaying(QMediaPlayer::MediaStatus state);
void expand();
signals:
@@ -90,6 +92,7 @@ class PlayerWidget : public QWidget {
QToolBar *mToolBar;
QAction *mPlayA;
QAction *mStopA;
+ QAction *mPauseA;
qint64 mDurSecs;
quint64 mPlayListLength;
};