summaryrefslogtreecommitdiffstats
path: root/playerwidget.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2017-09-21 16:34:26 +0200
committerArno <arno@disconnect.de>2017-09-21 16:34:26 +0200
commitaf4b07b399d22110b17f6a6dbc1c76152df1e9e0 (patch)
tree48dd6baa464752f8196383374969e2f4f3b1d9c2 /playerwidget.cpp
parent327e823ed0d9fcf4008521b9b12804db982b1c34 (diff)
downloadBeetPlayer-af4b07b399d22110b17f6a6dbc1c76152df1e9e0.tar.gz
BeetPlayer-af4b07b399d22110b17f6a6dbc1c76152df1e9e0.tar.bz2
BeetPlayer-af4b07b399d22110b17f6a6dbc1c76152df1e9e0.zip
Add Favorites
For now you can only add favorites, no view or removal. On the database side it's kinda awkward. I can't reference a song ID or something, because the DB is cleared on reindexing. So keep artist, song title and album as reference. I'm not yet sure if it's a good idea, though...
Diffstat (limited to 'playerwidget.cpp')
-rw-r--r--playerwidget.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/playerwidget.cpp b/playerwidget.cpp
index 451b0c8..da91986 100644
--- a/playerwidget.cpp
+++ b/playerwidget.cpp
@@ -378,6 +378,8 @@ void PlayerWidget::createActions(){
connect(miscFilterFromPlaylistA, &QAction::triggered, this, &PlayerWidget::filterFromPlaylist);
QAction *addToWebRadioA = new QAction(QIcon(":/dog_hood.png"), tr("Add Webradio"), this);
connect(addToWebRadioA, &QAction::triggered, this, &PlayerWidget::addWebRadio);
+ QAction *addToFavoritesA = new QAction(QIcon(":/male_chastity_belt.png"), tr("Add to Favorites"), this);
+ connect(addToFavoritesA, &QAction::triggered, this, &PlayerWidget::addToFavorites);
mView->addAction(addToPlayListA);
mView->addAction(addToPlayListAndClearA);
mView->addAction(Helper::createSeparator(this));
@@ -403,6 +405,8 @@ void PlayerWidget::createActions(){
mPlayListView->addAction(Helper::createSeparator(this));
mPlayListView->addAction(shufflePlayistA);
mPlayListView->addAction(clearPlayListA);
+ mPlayListView->addAction(Helper::createSeparator(this));
+ mPlayListView->addAction(addToFavoritesA);
QWidget* spacer1 = new QWidget();
spacer1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
mToolBar->addWidget(spacer1);
@@ -1040,6 +1044,7 @@ void PlayerWidget::addSong(const QModelIndex &idx){
item->setData(len, LengthRole);
item->setData(artist, ArtistRole);
item->setData(album, AlbumRole);
+ item->setData(title, TitleRole);
root->appendRow(item);
mPlayListLength += len;
}
@@ -1224,6 +1229,28 @@ void PlayerWidget::removeFromPlayList(){
emit playListLengthChanged(mPlayListLength);
}
+void PlayerWidget::addToFavorites(){
+ QModelIndexList sel = mPlayListView->selectionModel()->selectedRows();
+ QSqlDatabase db = QSqlDatabase::database("beetplayerdb");
+ QSqlQuery favInsertQ(db);
+ favInsertQ.prepare("INSERT INTO persistent_favorites (tartist_name, talbum_name, ttitle) VALUES(:artist, :album, :title)");
+ foreach(QModelIndex i, sel){
+ QString artist = i.data(ArtistRole).toString();
+ QString album = i.data(AlbumRole).toString();
+ QString title = i.data(TitleRole).toString();
+ QString msg;
+ favInsertQ.bindValue(":artist", artist);
+ favInsertQ.bindValue(":album", album);
+ favInsertQ.bindValue(":title", title);
+ if(favInsertQ.exec()){
+ msg = QString(tr("Added %1 to favorites")).arg(title);
+ }else{
+ msg = QString(tr("Oops! Failed to add %1 to favorites")).arg(title);
+ }
+ emit message(msg);
+ }
+}
+
void PlayerWidget::clearPlayList(){
mPlayListModel->clear();
mPlayListModel->setHorizontalHeaderLabels(QStringList() << "Title");
@@ -1266,6 +1293,7 @@ void PlayerWidget::randomPlay(){
item->setData(randomQ.value(6), LengthRole);
item->setData(randomQ.value(4), ArtistRole);
item->setData(randomQ.value(5), AlbumRole);
+ item->setData(randomQ.value(1), TitleRole);
mPlayListLength += randomQ.value(6).toInt();
root->appendRow(item);
}