diff options
author | Arno <arno@disconnect.de> | 2018-02-18 13:54:07 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2018-02-18 13:54:07 +0100 |
commit | c40077648a603d003aef3a54e0d3cd80e3e217d9 (patch) | |
tree | d663916ab2b79f7c283336bdfe506069ccc77197 | |
parent | 7c0e52be015c1521153d307f28486008fb733bbf (diff) | |
download | BeetPlayer-c40077648a603d003aef3a54e0d3cd80e3e217d9.tar.gz BeetPlayer-c40077648a603d003aef3a54e0d3cd80e3e217d9.tar.bz2 BeetPlayer-c40077648a603d003aef3a54e0d3cd80e3e217d9.zip |
Play WebRadio again
To make this work, remove duplicate Enums from PlayerWidget. Btw,
WebRadio was defined twice: as ModelType and as ItemTime, with the former
always taking preference.
Doesn't really matter, because I think I have to completely revamp the
WebRadio handling...
-rw-r--r-- | collectionwebradioview.cpp | 2 | ||||
-rw-r--r-- | playerwidget.cpp | 97 | ||||
-rw-r--r-- | playerwidget.h | 7 |
3 files changed, 43 insertions, 63 deletions
diff --git a/collectionwebradioview.cpp b/collectionwebradioview.cpp index 805c78c..7fa01de 100644 --- a/collectionwebradioview.cpp +++ b/collectionwebradioview.cpp @@ -23,6 +23,8 @@ void CollectionWebradioView::populate(){ curWr->setIcon(wrIcon); curWr->setData(wrQ.value(1), UrlRole); curWr->setData(wrQ.value(0), TitleRole); + curWr->setData(WebRadio, TypeRole); + curWr->setData(true, RemoteRole); root->appendRow(curWr); } enableSorting(); diff --git a/playerwidget.cpp b/playerwidget.cpp index 6dd794a..4c9af4a 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -50,7 +50,7 @@ #include "collectionwebradioview.h" #include "collectionwidgetproxy.h" -PlayerWidget::PlayerWidget(QSplashScreen *splash, QWidget *parent) : QWidget(parent), mDurSecs(0), mPlayListLength(0), mIsStream(false), mModelType(DoNotCare){ +PlayerWidget::PlayerWidget(QSplashScreen *splash, QWidget *parent) : QWidget(parent), mDurSecs(0), mPlayListLength(0) { mStarting = true; setupGui(splash); createActions(); @@ -439,23 +439,13 @@ void PlayerWidget::createActions(){ void PlayerWidget::rightCurrentChanged(const QModelIndex &cur, const QModelIndex &prev){ Q_UNUSED(prev) - QString fullPath(cur.data(FullPathRole).toString()); + QString fullPath(cur.data(CollectionWidget::FullPathRole).toString()); TagLib::FileRef file(QString(fullPath).toUtf8()); fillWithText(mRightTE, file); } -void PlayerWidget::leftCurrentChanged(const QModelIndex &cur, const QModelIndex &prev){ - Q_UNUSED(prev) - if(mModelType == WebRadio){ - QString descr = cur.data(Qt::DisplayRole).toString(); - QString url = cur.data(UrlRole).toString(); - QString text = QString("%1\n%2").arg(descr).arg(url); - mRightTE->setText(text); - } -} - void PlayerWidget::doPlay(){ - if(mPlayer->state() == QMediaPlayer::PausedState || mIsStream){ + if(mPlayer->state() == QMediaPlayer::PausedState){ mPlayer->play(); mPlayA->setChecked(true); emit playModeChanged(tr("Playing")); @@ -564,8 +554,8 @@ void PlayerWidget::recurse(const QModelIndex &parent){ const QAbstractItemModel *m = parent.model(); for(int i = 0; i < m->rowCount(parent); ++i){ QModelIndex cur = m->index(i, 0, parent); - int type = cur.data(TypeRole).toInt(); - if(type == Song){ + int type = cur.data(CollectionWidget::TypeRole).toInt(); + if(type == CollectionWidget::Song){ addSong(cur); }else{ recurse(cur); @@ -575,9 +565,9 @@ void PlayerWidget::recurse(const QModelIndex &parent){ void PlayerWidget::addSong(const QModelIndex &idx){ QStandardItem *root = mPlayListModel->invisibleRootItem(); - QString title = idx.data(TitleRole).toString(); - QString artist = idx.data(ArtistRole).toString(); - QString album = idx.data(AlbumRole).toString(); + QString title = idx.data(CollectionWidget::TitleRole).toString(); + QString artist = idx.data(CollectionWidget::ArtistRole).toString(); + QString album = idx.data(CollectionWidget::AlbumRole).toString(); QStringList args = QStringList() << title << artist << album; for(QString &s : args){ if(s.isEmpty()){ @@ -590,15 +580,15 @@ void PlayerWidget::addSong(const QModelIndex &idx){ item->setFont(QFont("courier")); item->setText(display); item->setIcon(QIcon(":/song.png")); - item->setData(idx.data(FullPathRole), FullPathRole); - int len = idx.data(LengthRole).toInt(); + item->setData(idx.data(CollectionWidget::FullPathRole), CollectionWidget::FullPathRole); + int len = idx.data(CollectionWidget::LengthRole).toInt(); if(len == 0){ - len = Helper::lengthInSeconds(idx.data(FullPathRole).toString()); + len = Helper::lengthInSeconds(idx.data(CollectionWidget::FullPathRole).toString()); } - item->setData(len, LengthRole); - item->setData(artist, ArtistRole); - item->setData(album, AlbumRole); - item->setData(title, TitleRole); + item->setData(len, CollectionWidget::LengthRole); + item->setData(artist, CollectionWidget::ArtistRole); + item->setData(album, CollectionWidget::AlbumRole); + item->setData(title, CollectionWidget::TitleRole); root->appendRow(item); mPlayListLength += len; } @@ -615,19 +605,21 @@ void PlayerWidget::addToPlayList(){ return; } for(const QModelIndex &i : sel){ - int type = i.data(TypeRole).toInt(); - if(type == Song){ + qDebug() << i.data(CollectionWidget::TypeRole) << i.data(); + int type = i.data(CollectionWidget::TypeRole).toInt(); + if(type == CollectionWidget::Song){ addSong(i); - }else if (type == Webradio){ + }else if (type == CollectionWidget::WebRadio){ mPlayListModel->clear(); QStandardItem *root = mPlayListModel->invisibleRootItem(); mPlayListModel->setHorizontalHeaderLabels(QStringList() << tr("Title")); QStandardItem *wrItem = new QStandardItem; wrItem->setEditable(false); wrItem->setIcon(QIcon(":dog_hood.png")); - wrItem->setText(i.data(TitleRole).toString()); - wrItem->setData(Webradio, TypeRole); - wrItem->setData(i.data(UrlRole), UrlRole); + wrItem->setText(i.data(CollectionWidget::TitleRole).toString()); + wrItem->setData(CollectionWidget::WebRadio, CollectionWidget::TypeRole); + wrItem->setData(i.data(CollectionWidget::UrlRole), CollectionWidget::UrlRole); + wrItem->setData(true, CollectionWidget::RemoteRole); root->appendRow(wrItem); }else{ recurse(i); @@ -648,7 +640,7 @@ void PlayerWidget::removeFromPlayList(){ QList<QPersistentModelIndex> persistent; int subSecs = 0; for(const QModelIndex &i : sel){ - subSecs = i.data(LengthRole).toInt(); + subSecs = i.data(CollectionWidget::LengthRole).toInt(); persistent << QPersistentModelIndex(i); } for(const QPersistentModelIndex &i : persistent){ @@ -698,11 +690,11 @@ void PlayerWidget::randomPlay(){ item->setFont(QFont("courier")); item->setText(display); item->setIcon(songIcon); - item->setData(randomQ.value(2), FullPathRole); - item->setData(randomQ.value(6), LengthRole); - item->setData(randomQ.value(4), ArtistRole); - item->setData(randomQ.value(5), AlbumRole); - item->setData(randomQ.value(1), TitleRole); + item->setData(randomQ.value(2), CollectionWidget::FullPathRole); + item->setData(randomQ.value(6), CollectionWidget::LengthRole); + item->setData(randomQ.value(4), CollectionWidget::ArtistRole); + item->setData(randomQ.value(5), CollectionWidget::AlbumRole); + item->setData(randomQ.value(1), CollectionWidget::TitleRole); mPlayListLength += randomQ.value(6).toInt(); root->appendRow(item); } @@ -711,12 +703,13 @@ void PlayerWidget::randomPlay(){ } void PlayerWidget::playCurrent(const QModelIndex &index){ - int isRemote = index.data(RemoteRole).toInt(); + int isRemote = index.data(CollectionWidget::RemoteRole).toInt(); if(isRemote){ + playUrl(index.data(CollectionWidget::UrlRole).toString()); return; } mPlayer->stop(); - QString fullPath = index.data(FullPathRole).toString(); + QString fullPath = index.data(CollectionWidget::FullPathRole).toString(); play(fullPath); mTrayIcon->setIcon(QIcon(":/play.png")); mTrayIcon->setToolTip(mCurToolTip); @@ -730,7 +723,7 @@ void PlayerWidget::printList(){ } QString output; for(const QModelIndex &i : sel){ - QString fp = i.data(FullPathRole).toString(); + QString fp = i.data(CollectionWidget::FullPathRole).toString(); TagLib::FileRef fr(fp.toUtf8()); if(!fr.isNull()){ quint16 track = fr.tag()->track(); @@ -750,12 +743,12 @@ void PlayerWidget::searchMusicbrainz(const QModelIndex &idx){ if(!idx.isValid()){ return; } - QString artist = idx.data(ArtistRole).toString(); - QString album = idx.data(AlbumRole).toString(); + QString artist = idx.data(CollectionWidget::ArtistRole).toString(); + QString album = idx.data(CollectionWidget::AlbumRole).toString(); if(album.isEmpty()){ QModelIndex firstChild = idx.model()->index(0, 0, idx); if(firstChild.isValid()){ - album = firstChild.data(AlbumRole).toString(); + album = firstChild.data(CollectionWidget::AlbumRole).toString(); } } mWebDownloader->fetchData(artist, album); @@ -832,9 +825,9 @@ void PlayerWidget::doMetadataChange(const QString &key, const QVariant &value){ nowP->setFont(QFont("courier")); nowP->setEditable(false); nowP->setIcon(QIcon(":/dog_hood.png")); - nowP->setData(1, RemoteRole); - nowP->setData(artist, ArtistRole); - nowP->setData(title, TitleRole); + nowP->setData(1, CollectionWidget::RemoteRole); + nowP->setData(artist, CollectionWidget::ArtistRole); + nowP->setData(title, CollectionWidget::TitleRole); nowP->setText(np); plRoot->appendRow(nowP); mCurrentTE->clear(); @@ -867,7 +860,6 @@ void PlayerWidget::updateStreamData(){ void PlayerWidget::play(const QString &fullPath){ disconnect(mPlayer, static_cast<void(QMediaObject::*)(const QString &, const QVariant &)>(&QMediaObject::metaDataChanged), this, &PlayerWidget::doMetadataChange); - mIsStream = false; mSongSlider->setEnabled(true); mLeftTE->clear(); mPlayer->setMedia(QUrl::fromLocalFile(fullPath)); @@ -903,7 +895,6 @@ void PlayerWidget::play(const QString &fullPath){ void PlayerWidget::playUrl(const QString &url){ disconnect(mPlayer, static_cast<void(QMediaObject::*)(const QString &, const QVariant &)>(&QMediaObject::metaDataChanged), this, &PlayerWidget::doMetadataChange); connect(mPlayer, static_cast<void(QMediaObject::*)(const QString &, const QVariant &)>(&QMediaObject::metaDataChanged), this, &PlayerWidget::doMetadataChange); - mIsStream = true; mSongSlider->setValue(0); mSongSlider->setEnabled(false); mPlayer->setMedia(QUrl(url)); @@ -937,9 +928,6 @@ void PlayerWidget::previous(){ } void PlayerWidget::advance(int numSongs){ - if(mIsStream){ - return; - } mPlayer->stop(); QModelIndexList sel = mPlayListView->selectionModel()->selectedRows(); if(sel.isEmpty()){ @@ -967,9 +955,6 @@ void PlayerWidget::slide(int value){ void PlayerWidget::setPosition(qint64 pos){ int curPos = pos / 1000; - if(!mIsStream){ - mSongSlider->setValue(curPos); - } int minutes = curPos / 60; int seconds = curPos % 60; QString posString = QString("%1:%2").arg(minutes, 2, 10, QChar('0')).arg(seconds, 2, 10, QChar('0')); @@ -1012,10 +997,10 @@ void PlayerWidget::aboutDlg(){ void PlayerWidget::gotoAlbum(){ CollectionArtistsView *artistView = mCollectionStack->findChild<CollectionArtistsView*>("artists"); CollectionAlbumsView *albumView = mCollectionStack->findChild<CollectionAlbumsView*>("albums"); - QString album = artistView->view()->selectionModel()->currentIndex().data(AlbumRole).toString(); + QString album = artistView->view()->selectionModel()->currentIndex().data(CollectionWidget::AlbumRole).toString(); if(!album.isEmpty()){ const CollectionWidgetProxy *proxy = qobject_cast<const CollectionWidgetProxy*>(albumView->view()->model()); - QModelIndexList albumIdxs = proxy->match(proxy->index(0, 0, QModelIndex()), AlbumRole, album); + QModelIndexList albumIdxs = proxy->match(proxy->index(0, 0, QModelIndex()), CollectionWidget::AlbumRole, album); if(!albumIdxs.isEmpty()){ mViewByAlbumsA->trigger(); QModelIndex albumIdx = albumIdxs.first(); diff --git a/playerwidget.h b/playerwidget.h index 3d190a7..050418f 100644 --- a/playerwidget.h +++ b/playerwidget.h @@ -30,17 +30,12 @@ class QSplashScreen; class PlayerWidget : public QWidget { Q_OBJECT public: - enum ItemType { Artist, Album, Song, Genre, WebRadio }; - enum PopulateType { FilterType, IdType, EmptyType }; - enum CustomRoles { TypeRole = Qt::UserRole + 1, IdRole = Qt::UserRole + 2, FullPathRole = Qt::UserRole + 3, GenreRole = Qt::UserRole + 4, ArtistRole = Qt::UserRole + 5, TitleRole = Qt::UserRole + 6, AlbumRole = Qt::UserRole + 7, LengthRole = Qt::UserRole + 8, UrlRole = Qt::UserRole + 9, RemoteRole = Qt::UserRole + 10 }; - enum ModelType { Webradio, Favorites, Folders, DoNotCare }; explicit PlayerWidget(QSplashScreen *splash, QWidget *parent = nullptr); ~PlayerWidget(); const QMediaPlayer* player() const { return mPlayer; } public slots: void rightCurrentChanged(const QModelIndex &cur, const QModelIndex &prev); - void leftCurrentChanged(const QModelIndex &cur, const QModelIndex &prev); void doPlay(); void doStop(); void doPause(); @@ -120,8 +115,6 @@ class PlayerWidget : public QWidget { bool mStarting; WebDownloader *mWebDownloader; QMap<QString, QVariant> mOtherMeta; - bool mIsStream; - int mModelType; QStackedWidget *mCollectionStack; }; |