From 8d6375e7ae353ead5949fa15ce34cf421cc1d984 Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 18 Feb 2018 05:20:47 +0100 Subject: Re-introduce MusicBrainz search --- playerwidget.cpp | 40 +++++++++++++++------------------------- playerwidget.h | 4 ++-- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/playerwidget.cpp b/playerwidget.cpp index fb8d563..f589f4d 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -164,17 +164,21 @@ void PlayerWidget::setupGui(QSplashScreen *splash){ QAction *addToPlayListAndClearA = new QAction(QIcon(":/belly_right_and_clear.png"), tr("Clear and add"), this); connect(addToPlayListAndClearA, &QAction::triggered, this, &PlayerWidget::addToPlayListAndClear); curW->view()->addAction(addToPlayListAndClearA); + curW->view()->addAction(Helper::createSeparator(this)); QStandardItemModel *model = curW->model(); QModelIndex rootIdx = model->invisibleRootItem()->index(); if(model->hasChildren(model->index(0, 0, rootIdx))){ QAction *expandA = new QAction(Helper::iconFromQChar(QChar(0x2640), 90), tr("Expand"), this); connect(expandA, &QAction::triggered, [curW] { curW->view()->expandOrCollapse(BeetView::Expand);} ); - curW->view()->addAction(Helper::createSeparator(this)); curW->view()->addAction(expandA); QAction *collapseA = new QAction(Helper::iconFromQChar(QChar(0x2642), 120), tr("Collapse"), this); connect(collapseA, &QAction::triggered, [curW] { curW->view()->expandOrCollapse(BeetView::Collapse);} ); curW->view()->addAction(collapseA); + curW->view()->addAction(Helper::createSeparator(this)); } + QAction *searchMBA = new QAction(QIcon(":/bizarre_amputee.png"), tr("Search Musicbrainz"), this); + connect(searchMBA, &QAction::triggered, [this, curW] { searchMusicbrainz(curW->view()->selectionModel()->currentIndex()); }); + curW->view()->addAction(searchMBA); } //left widget @@ -370,16 +374,12 @@ void PlayerWidget::createActions(){ connect(aboutQtA, &QAction::triggered, qApp, &QApplication::aboutQt); helpM->addAction(aboutQtA); helpA->setMenu(helpM); - QAction *miscPrintA = new QAction(QIcon(":/clean_tampon.png"), tr("List selected"), this); - connect(miscPrintA, &QAction::triggered, this, &PlayerWidget::printList); - QAction *miscMusicBrainzRightA = new QAction(QIcon(":/bizarre_amputee.png"), tr("Search Musicbrainz"), this); - connect(miscMusicBrainzRightA, &QAction::triggered, this, &PlayerWidget::searchMusicbrainzRight); - QAction *miscMusicBrainzLeftA = new QAction(QIcon(":/bizarre_amputee.png"), tr("Search Musicbrainz"), this); - connect(miscMusicBrainzLeftA, &QAction::triggered, this, &PlayerWidget::searchMusicbrainzLeft); + QAction *plSearchMB = new QAction(QIcon(":/bizarre_amputee.png"), tr("Search Musicbrainz"), this); + connect(plSearchMB, &QAction::triggered, [this] { searchMusicbrainz(mPlayListView->selectionModel()->currentIndex()); }); mPlayListView->addAction(removeFromPlayListA); mPlayListView->addAction(Helper::createSeparator(this)); - mPlayListView->addAction(miscMusicBrainzRightA); + mPlayListView->addAction(plSearchMB); mPlayListView->addAction(Helper::createSeparator(this)); mPlayListView->addAction(shufflePlayistA); mPlayListView->addAction(clearPlayListA); @@ -723,24 +723,18 @@ void PlayerWidget::printList(){ mLeftTE->setPlainText(output); } -void PlayerWidget::searchMusicbrainzRight(){ - QModelIndex idx = mPlayListView->selectionModel()->currentIndex(); +void PlayerWidget::searchMusicbrainz(const QModelIndex &idx){ if(!idx.isValid()){ return; } QString artist = idx.data(ArtistRole).toString(); QString album = idx.data(AlbumRole).toString(); - mWebDownloader->fetchData(artist, album); -} - -void PlayerWidget::searchMusicbrainzLeft(){ - CollectionWidget *curWidget = qobject_cast(mCollectionStack->currentWidget()); - QModelIndex idx = curWidget->view()->selectionModel()->currentIndex(); - if(!idx.isValid()){ - return; + if(album.isEmpty()){ + QModelIndex firstChild = idx.model()->index(0, 0, idx); + if(firstChild.isValid()){ + album = firstChild.data(AlbumRole).toString(); + } } - QString artist = idx.data(ArtistRole).toString().toLower(); - QString album = idx.data(AlbumRole).toString().toLower(); mWebDownloader->fetchData(artist, album); } @@ -760,9 +754,6 @@ void PlayerWidget::webDlDone(){ if(!aId.isEmpty()){ text.append(QString(tr("Musicbrainz:"))); text.append(QString(tr("")).arg(aId).arg(mWebDownloader->artist())); - for(const QString &alId : mWebDownloader->data()){ - text.append(QString("").arg(alId).arg(mWebDownloader->album())); - } text.append("
Artist%2
Album%2
"); QList > other = mWebDownloader->otherData(); std::sort(other.begin(), other.end(), [](auto a, auto b){ @@ -880,10 +871,9 @@ void PlayerWidget::play(const QString &fullPath){ mTrayIcon->setToolTip(mCurToolTip); mTrayIcon->showMessage(QString(tr("Now Playing:")), mCurToolTip, QSystemTrayIcon::Information, 5000); emit setWinTitle(mCurWinTitle); - mPlayer->play(); mPlayA->setChecked(true); - searchMusicbrainzRight(); + searchMusicbrainz(mPlayListView->selectionModel()->currentIndex()); emit playModeChanged(tr("Playing")); } diff --git a/playerwidget.h b/playerwidget.h index 84b2ba3..c4ca8ec 100644 --- a/playerwidget.h +++ b/playerwidget.h @@ -57,8 +57,7 @@ class PlayerWidget : public QWidget { void randomPlay(); void playCurrent(const QModelIndex &index); void printList(); - void searchMusicbrainzRight(); - void searchMusicbrainzLeft(); + void searchMusicbrainz(const QModelIndex &idx); void webDlDone(); void doMetadataChange(const QString &key, const QVariant &value); void updateStreamData(); @@ -83,6 +82,7 @@ class PlayerWidget : public QWidget { void modelChanged(); void setWinTitle(const QString &title); void streamDataNeedsUpdate(); + void currentPlayListChanged(const QModelIndex &cur); private: void setupGui(QSplashScreen *splash); -- cgit v1.2.3-70-g09d2