summaryrefslogtreecommitdiffstats
path: root/playerwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'playerwidget.cpp')
-rw-r--r--playerwidget.cpp62
1 files changed, 59 insertions, 3 deletions
diff --git a/playerwidget.cpp b/playerwidget.cpp
index 603334a..2c28d13 100644
--- a/playerwidget.cpp
+++ b/playerwidget.cpp
@@ -32,6 +32,7 @@ void PlayerWidget::setupGui(){
mView->setModel(mViewModel);
mSearchModel = new QStandardItemModel;
mView->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ currentModel = mViewModel;
//filter
QGroupBox *filterGB = new QGroupBox(tr("Filter"));
@@ -84,8 +85,10 @@ void PlayerWidget::setupGui(){
//playlist
mPlayListModel = new QStandardItemModel;
+ mPlayListModel->setHorizontalHeaderLabels(QStringList() << "Title");
mPlayListView = new BeetView;
mPlayListView->setModel(mPlayListModel);
+ mPlayListView->setRootIsDecorated(false);
QGroupBox *playListGB = new QGroupBox(tr("Playlist"));
QVBoxLayout *playListL = new QVBoxLayout;
playListL->addWidget(mPlayListView);
@@ -113,6 +116,7 @@ void PlayerWidget::createActions(){
QAction *pauseA = new QAction(QIcon(":/pause.png"), tr("Pause"), this);
QAction *stopA = new QAction(QIcon(":/stop.png"), tr("Stop"), this);
QAction *addToPlayListA = new QAction(QIcon(":/belly_right.png"), tr("Add to playlist"), this);
+ connect(addToPlayListA, SIGNAL(triggered()), this, SLOT(addToPlayList()));
QAction *removeFromPlayListA = new QAction(QIcon(":/belly_left.png"), tr("Remove from playlist"), this);
QAction *clearPlayListA = new QAction(QIcon(":/delete.png"), tr("Clear Playlist"), this);
QAction *refreshA = new QAction(QIcon(":/refresh.png"), tr("Refresh..."), this);
@@ -191,6 +195,9 @@ void PlayerWidget::populateByArtist(QStandardItem *parent, const QString &filter
curSong->setData(songQ.value(0), IdRole);
curSong->setData(songQ.value(2), FullPathRole);
curSong->setData(songQ.value(3), GenreRole);
+ curSong->setData(artistsQ.value(1), ArtistRole);
+ curSong->setData(songQ.value(1), TitleRole);
+ curSong->setData(albumQ.value(1), AlbumRole);
curAlbum->appendRow(curSong);
}
}
@@ -201,18 +208,21 @@ void PlayerWidget::populateBySong(QStandardItem *parent, const QString &filter){
QSqlDatabase db = QSqlDatabase::database("beetplayerdb");
QStandardItem *root = parent;
QSqlQuery songQ = QSqlQuery(db);
- songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name FROM songs, artists WHERE ttitle ~ :f AND songs.iartists_id = artists.iartists_id ORDER BY ttitle ASC");
+ 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.bindValue(":f", filter);
songQ.exec();
while(songQ.next()){
QStandardItem *curSong = new QStandardItem;
curSong->setEditable(false);
curSong->setFont(QFont("courier"));
- QString songText = QString(tr("%1 %2 (%3)")).arg(QString("🅢")).arg(songQ.value(1).toString()).arg(songQ.value(4).toString());
+ QString songText = QString(tr("%1 %2 (%3)")).arg(QChar(0x266C)).arg(songQ.value(1).toString()).arg(songQ.value(4).toString());
curSong->setText(songText);
curSong->setData(songQ.value(0), IdRole);
curSong->setData(songQ.value(2), FullPathRole);
curSong->setData(songQ.value(3), GenreRole);
+ curSong->setData(songQ.value(4), ArtistRole);
+ curSong->setData(songQ.value(1), TitleRole);
+ curSong->setData(songQ.value(5), AlbumRole);
root->appendRow(curSong);
}
}
@@ -234,7 +244,8 @@ 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 FROM songs, artists WHERE igenres_id = :id AND songs.iartists_id = artists.iartists_id ORDER BY ttitle ASC");
+ //songQ.prepare("SELECT sipos, ttitle, tfullpath, igenres_id, artists.tartists_name FROM songs, artists WHERE igenres_id = :id AND songs.iartists_id = artists.iartists_id ORDER BY ttitle ASC");
+ 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.bindValue(":id", genreQ.value(0));
songQ.exec();
while(songQ.next()){
@@ -247,11 +258,39 @@ void PlayerWidget::populateByGenre(QStandardItem *parent, const QString &filter)
curSong->setData(songQ.value(0), IdRole);
curSong->setData(songQ.value(2), FullPathRole);
curSong->setData(songQ.value(3), GenreRole);
+ curSong->setData(songQ.value(4), ArtistRole);
+ curSong->setData(songQ.value(1), TitleRole);
+ curSong->setData(songQ.value(5), AlbumRole);
curGenre->appendRow(curSong);
}
}
}
+void PlayerWidget::recurse(const QModelIndex &parent){
+ for(int i = 0; i < currentModel->rowCount(parent); ++i){
+ QModelIndex cur = currentModel->index(i, 0, parent);
+ int type = cur.data(TypeRole).toInt();
+ if(type == Song){
+ addSong(cur);
+ }else{
+ recurse(cur);
+ }
+ }
+}
+
+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 display = QString(tr("%1 - %2 - %3 - %4")).arg(QChar(0x266C)).arg(artist).arg(title).arg(album);
+ QStandardItem *item = new QStandardItem;
+ item->setFont(QFont("courier"));
+ item->setText(display);
+ item->setData(idx.data(FullPathRole), FullPathRole);
+ root->appendRow(item);
+}
+
void PlayerWidget::populate(){
mView->setModel(mViewModel);
mViewModel->clear();
@@ -268,6 +307,7 @@ void PlayerWidget::doFilter(){
mSearchModel->clear();
mSearchModel->setHorizontalHeaderLabels(QStringList() << tr("Name"));
mView->setModel(mSearchModel);
+ currentModel = mSearchModel;
QStandardItem *root = mSearchModel->invisibleRootItem();
populateByArtist(root, filter);
populateByGenre(root, filter);
@@ -277,9 +317,25 @@ void PlayerWidget::doFilter(){
void PlayerWidget::clearFilter(){
mFilter->clear();
mView->setModel(mViewModel);
+ currentModel = mViewModel;
}
void PlayerWidget::reindex(){
IndexerDialog dlg(this);
dlg.exec();
}
+
+void PlayerWidget::addToPlayList(){
+ QModelIndexList sel = mView->selectionModel()->selectedRows();
+ if(sel.isEmpty()){
+ return;
+ }
+ foreach(QModelIndex i, sel){
+ int type = i.data(TypeRole).toInt();
+ if(type == Song){
+ addSong(i);
+ }else{
+ recurse(i);
+ }
+ }
+}