diff options
author | Arno <arno@disconnect.de> | 2017-03-05 17:23:33 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2017-03-05 17:23:33 +0100 |
commit | 2ff72f033af3f24ffb816bc19a34fc794f585775 (patch) | |
tree | be21b99d6ac7ebf60d398daca79567bb6e5b0565 /playerwidget.cpp | |
parent | 51990db36b7b4c1ff8ca72ff16ded36c72be24b9 (diff) | |
download | BeetPlayer-2ff72f033af3f24ffb816bc19a34fc794f585775.tar.gz BeetPlayer-2ff72f033af3f24ffb816bc19a34fc794f585775.tar.bz2 BeetPlayer-2ff72f033af3f24ffb816bc19a34fc794f585775.zip |
Implement statusBar
Display in statusBar:
* viewMode
* number of files in playlist
* length of playlist in h:m:s
* player status (Stopped, Playing, Paused)
Diffstat (limited to 'playerwidget.cpp')
-rw-r--r-- | playerwidget.cpp | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/playerwidget.cpp b/playerwidget.cpp index 40bca39..ebbbc16 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -22,6 +22,7 @@ #include <algorithm> #include <taglib/fileref.h> #include <taglib/tag.h> +#include <taglib/audioproperties.h> #include "playerwidget.h" #include "beetview.h" @@ -29,7 +30,7 @@ #include "globals.h" #include "helper.h" -PlayerWidget::PlayerWidget(QWidget *parent) : QWidget(parent){ +PlayerWidget::PlayerWidget(QWidget *parent) : QWidget(parent), mDurSecs(0), mPlayListLength(0){ setupGui(); createActions(); } @@ -280,7 +281,7 @@ void PlayerWidget::populateByArtist(QStandardItem *parent, const QString &filter QSqlQuery albumQ(db); albumQ.prepare("SELECT DISTINCT(songs.ialbums_id), talbum_name, siyear FROM songs, albums WHERE songs.iartists_id = :artistid AND songs.ialbums_id = albums.ialbums_id ORDER BY siyear ASC"); QSqlQuery songQ(db); - songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id FROM songs WHERE ialbums_id = :alid AND iartists_id = :arid ORDER BY sipos ASC"); + songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, ilength FROM songs WHERE ialbums_id = :alid AND iartists_id = :arid ORDER BY sipos ASC"); QIcon songIcon(":/song.png"); QIcon albumIcon(":/album.png"); QIcon artistIcon(":/artist.png"); @@ -324,6 +325,7 @@ void PlayerWidget::populateByArtist(QStandardItem *parent, const QString &filter curSong->setData(songQ.value(3), GenreRole); curSong->setData(artistsQ.value(1), ArtistRole); curSong->setData(songQ.value(1), TitleRole); + curSong->setData(songQ.value(4), LengthRole); curSong->setData(albumQ.value(1), AlbumRole); curAlbum->appendRow(curSong); } @@ -354,7 +356,7 @@ void PlayerWidget::populateByAlbum(QStandardItem *parent, const QVariant &filter curAlbum->setData(albumQ.value(0), IdRole); parent->appendRow(curAlbum); QSqlQuery songQ = QSqlQuery(db); - songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name, albums.talbum_name FROM songs, artists, albums WHERE albums.ialbums_id = :id AND songs.iartists_id = artists.iartists_id and songs.ialbums_id = albums.ialbums_id ORDER BY sipos"); + songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name, albums.talbum_name, ilength FROM songs, artists, albums WHERE albums.ialbums_id = :id AND songs.iartists_id = artists.iartists_id and songs.ialbums_id = albums.ialbums_id ORDER BY sipos"); songQ.bindValue(":id", albumQ.value(0)); songQ.exec(); while(songQ.next()){ @@ -372,6 +374,7 @@ void PlayerWidget::populateByAlbum(QStandardItem *parent, const QVariant &filter ++artistcount[songQ.value(4).toString()]; curSong->setData(songQ.value(1), TitleRole); curSong->setData(songQ.value(5), AlbumRole); + curSong->setData(songQ.value(6), LengthRole); curAlbum->appendRow(curSong); } QString albumText; @@ -390,9 +393,9 @@ void PlayerWidget::populateBySong(QStandardItem *parent, const QVariant &filter, QIcon songIcon(":/song.png"); QSqlQuery songQ = QSqlQuery(db); if(type == EmptyType){ - songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name, albums.talbum_name FROM songs, artists, albums WHERE songs.iartists_id = artists.iartists_id and songs.ialbums_id = albums.ialbums_id ORDER BY ttitle ASC"); + songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name, albums.talbum_name, ilength FROM songs, artists, albums WHERE songs.iartists_id = artists.iartists_id and songs.ialbums_id = albums.ialbums_id ORDER BY ttitle ASC"); }else if(type == FilterType){ - songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name, albums.talbum_name FROM songs, artists, albums WHERE ttitle ~ :f AND songs.iartists_id = artists.iartists_id and songs.ialbums_id = albums.ialbums_id ORDER BY ttitle ASC"); + songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name, albums.talbum_name, ilength FROM songs, artists, albums WHERE ttitle ~ :f AND songs.iartists_id = artists.iartists_id and songs.ialbums_id = albums.ialbums_id ORDER BY ttitle ASC"); songQ.bindValue(":f", filter); }else if(type == IdType){ songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name, albums.talbum_name FROM songs, artists, albums WHERE albums.ialbums_id = :id AND songs.iartists_id = artists.iartists_id and songs.ialbums_id = albums.ialbums_id ORDER BY sipos"); @@ -418,6 +421,7 @@ void PlayerWidget::populateBySong(QStandardItem *parent, const QVariant &filter, curSong->setData(songQ.value(4), ArtistRole); curSong->setData(songQ.value(1), TitleRole); curSong->setData(songQ.value(5), AlbumRole); + curSong->setData(songQ.value(6), LengthRole); root->appendRow(curSong); } } @@ -445,7 +449,7 @@ void PlayerWidget::populateByGenre(QStandardItem *parent, const QString &filter) curGenre->setData(genreQ.value(0), IdRole); root->appendRow(curGenre); QSqlQuery songQ = QSqlQuery(db); - songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name, albums.talbum_name FROM songs, artists, albums WHERE igenres_id = :id AND songs.iartists_id = artists.iartists_id AND songs.ialbums_id = albums.ialbums_id ORDER BY ttitle ASC"); + songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name, albums.talbum_name, ilength FROM songs, artists, albums WHERE igenres_id = :id AND songs.iartists_id = artists.iartists_id AND songs.ialbums_id = albums.ialbums_id ORDER BY ttitle ASC"); songQ.bindValue(":id", genreQ.value(0)); songQ.exec(); while(songQ.next()){ @@ -462,6 +466,7 @@ void PlayerWidget::populateByGenre(QStandardItem *parent, const QString &filter) curSong->setData(songQ.value(4), ArtistRole); curSong->setData(songQ.value(1), TitleRole); curSong->setData(songQ.value(5), AlbumRole); + curSong->setData(songQ.value(6), LengthRole); curGenre->appendRow(curSong); } } @@ -508,6 +513,7 @@ void PlayerWidget::doPopulateByFolder(QString dir){ root->appendRow(cur); } mView->setModel(mFolderModel); + emit viewModeChanged(tr("Folder")); } void PlayerWidget::viewDoubleClicked(const QModelIndex &idx){ @@ -555,7 +561,13 @@ void PlayerWidget::addSong(const QModelIndex &idx){ item->setText(display); item->setIcon(QIcon(":/song.png")); item->setData(idx.data(FullPathRole), FullPathRole); + int len = idx.data(LengthRole).toInt(); + if(len == 0){ + len = Helper::lengthInSeconds(idx.data(FullPathRole).toString()); + } + item->setData(len, LengthRole); root->appendRow(item); + mPlayListLength += len; } void PlayerWidget::doPopulateByArtist(){ @@ -567,6 +579,7 @@ void PlayerWidget::doPopulateByArtist(){ QStandardItem *root = mViewModel->invisibleRootItem(); populateByArtist(root, QString()); qApp->restoreOverrideCursor(); + emit viewModeChanged(tr("Artist")); } void PlayerWidget::doPopulateByAlbum(){ @@ -578,6 +591,7 @@ void PlayerWidget::doPopulateByAlbum(){ QStandardItem *root = mViewModel->invisibleRootItem(); populateByAlbum(root, QString(), EmptyType); qApp->restoreOverrideCursor(); + emit viewModeChanged(tr("Album")); } void PlayerWidget::doPopulateByGenre(){ @@ -589,6 +603,7 @@ void PlayerWidget::doPopulateByGenre(){ QStandardItem *root = mViewModel->invisibleRootItem(); populateByGenre(root, QString()); qApp->restoreOverrideCursor(); + emit viewModeChanged(tr("Genre")); } void PlayerWidget::doPopulateBySong(){ @@ -600,6 +615,7 @@ void PlayerWidget::doPopulateBySong(){ QStandardItem *root = mViewModel->invisibleRootItem(); populateBySong(root, QString(), EmptyType); qApp->restoreOverrideCursor(); + emit viewModeChanged(tr("Song")); } void PlayerWidget::doFilter(){ @@ -618,6 +634,7 @@ void PlayerWidget::doFilter(){ populateByGenre(root, filter); populateBySong(root, filter, FilterType); qApp->restoreOverrideCursor(); + emit viewModeChanged(tr("Search")); } void PlayerWidget::clearFilter(){ @@ -644,6 +661,9 @@ void PlayerWidget::addToPlayList(){ recurse(i); } } + QStandardItem *playListRoot = mPlayListModel->invisibleRootItem(); + emit numFilesChanged(playListRoot->rowCount()); + emit playListLengthChanged(mPlayListLength); } void PlayerWidget::addToPlayListAndClear(){ @@ -654,17 +674,26 @@ void PlayerWidget::addToPlayListAndClear(){ void PlayerWidget::removeFromPlayList(){ QModelIndexList sel = mPlayListView->selectionModel()->selectedRows(); QList<QPersistentModelIndex> persistent; + int subSecs = 0; foreach(QModelIndex i, sel){ + subSecs = i.data(LengthRole).toInt(); persistent << QPersistentModelIndex(i); } foreach(QPersistentModelIndex i, persistent){ mPlayListModel->removeRow(i.row()); } + QStandardItem *root = mPlayListModel->invisibleRootItem(); + emit numFilesChanged(root->rowCount()); + mPlayListLength -= subSecs; + emit playListLengthChanged(mPlayListLength); } void PlayerWidget::clearPlayList(){ mPlayListModel->clear(); mPlayListModel->setHorizontalHeaderLabels(QStringList() << "Title"); + mPlayListLength = 0; + emit numFilesChanged(0); + emit playListLengthChanged(0); } void PlayerWidget::shufflePlayList(){ @@ -683,13 +712,12 @@ void PlayerWidget::shufflePlayList(){ } void PlayerWidget::randomPlay(){ - mPlayListModel->clear(); - mPlayListModel->setHorizontalHeaderLabels(QStringList() << "Title"); + clearPlayList(); QStandardItem *root = mPlayListModel->invisibleRootItem(); QIcon songIcon(":/song.png"); QSqlDatabase db = QSqlDatabase::database("beetplayerdb"); QSqlQuery randomQ(db); - randomQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name, albums.talbum_name FROM songs, artists, albums WHERE songs.iartists_id = artists.iartists_id AND songs.ialbums_id = albums.ialbums_id ORDER BY random() LIMIT 1000"); + randomQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name, albums.talbum_name, ilength FROM songs, artists, albums WHERE songs.iartists_id = artists.iartists_id AND songs.ialbums_id = albums.ialbums_id ORDER BY random() LIMIT 1000"); randomQ.exec(); while(randomQ.next()){ QString display = QString(tr("%1 - %2 - %3")).arg(randomQ.value(4).toString()).arg(randomQ.value(1).toString()).arg(randomQ.value(5).toString()); @@ -699,8 +727,12 @@ void PlayerWidget::randomPlay(){ item->setText(display); item->setIcon(songIcon); item->setData(randomQ.value(2), FullPathRole); + item->setData(randomQ.value(6), LengthRole); + mPlayListLength += randomQ.value(6).toInt(); root->appendRow(item); } + emit numFilesChanged(root->rowCount()); + emit playListLengthChanged(mPlayListLength); } void PlayerWidget::playCurrent(const QModelIndex &index){ |