From ee0b460145fd1edd0f76bbbf3680b9ebea927940 Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 5 Mar 2017 17:51:48 +0100 Subject: Fix play Button Print a statusbar message when the playlist is empty. If it isn't empty, but nothing is selected, select the first entry and play it. --- playerwidget.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'playerwidget.cpp') diff --git a/playerwidget.cpp b/playerwidget.cpp index ebbbc16..77afffc 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -196,7 +196,7 @@ void PlayerWidget::createActions(){ mPlayA = new QAction(QIcon(":/play.png"), tr("Play"), this); mPlayA->setCheckable(true); playAG->addAction(mPlayA); - connect(mPlayA, SIGNAL(triggered()), mPlayer, SLOT(play())); + connect(mPlayA, SIGNAL(triggered()), this, SLOT(doPlay())); QAction *pauseA = new QAction(QIcon(":/pause.png"), tr("Pause"), this); pauseA->setCheckable(true); playAG->addAction(pauseA); @@ -531,6 +531,21 @@ void PlayerWidget::viewDoubleClicked(const QModelIndex &idx){ } } +void PlayerWidget::doPlay(){ + int playListCount = mPlayListModel->rowCount(); + if(playListCount == 0){ + emit message(tr("Playlist is empty! Dazed and confused, but trying to continue...")); + mStopA->trigger(); + return; + } + QModelIndexList sel = mPlayListView->selectionModel()->selectedRows(); + if(sel.isEmpty()){ + mPlayListView->selectionModel()->select(mPlayListModel->index(0, 0), QItemSelectionModel::SelectCurrent); + sel = mPlayListView->selectionModel()->selectedRows(); + } + playCurrent(sel.first()); +} + void PlayerWidget::recurse(const QModelIndex &parent){ for(int i = 0; i < mCurrentModel->rowCount(parent); ++i){ QModelIndex cur = mCurrentModel->index(i, 0, parent); @@ -761,7 +776,8 @@ 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)); - mPlayA->trigger(); + mPlayer->play(); + mPlayA->setChecked(true); } void PlayerWidget::volumeChanged(int volume){ -- cgit v1.2.3-70-g09d2