summaryrefslogtreecommitdiffstats
path: root/playerwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'playerwidget.cpp')
-rw-r--r--playerwidget.cpp54
1 files changed, 36 insertions, 18 deletions
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();
}
}