From 164701b69d3d84b5530e93866dea93b446654a8e Mon Sep 17 00:00:00 2001 From: Arno Date: Mon, 19 Feb 2018 02:08:54 +0100 Subject: Add "remove from Favorites" Implemented as a custom action. Works out fine so far :) --- collectionfavoritesview.cpp | 24 ++++++++++++++++++++++++ collectionfavoritesview.h | 1 + playerwidget.cpp | 1 + 3 files changed, 26 insertions(+) diff --git a/collectionfavoritesview.cpp b/collectionfavoritesview.cpp index a202fcb..54ce2f5 100644 --- a/collectionfavoritesview.cpp +++ b/collectionfavoritesview.cpp @@ -1,10 +1,16 @@ #include #include #include +#include #include "collectionfavoritesview.h" +#include "helper.h" CollectionFavoritesView::CollectionFavoritesView(QWidget *parent) : CollectionWidget(parent) { + QAction *removeFromFavoritesA = new QAction(QIcon(":/delete.png"), tr("Remove from Favorites"), this); + connect(removeFromFavoritesA, &QAction::triggered, [this] { removeFromFavorites(view()->selectionModel()->selectedRows()); }); + customActions()->addAction(Helper::createSeparator(this)); + customActions()->addAction(removeFromFavoritesA); } void CollectionFavoritesView::populate(){ @@ -43,3 +49,21 @@ void CollectionFavoritesView::populate(){ } enableSorting(); } + +void CollectionFavoritesView::removeFromFavorites(const QModelIndexList &idxs){ + if(!idxs.isEmpty()){ + QSqlDatabase db = QSqlDatabase::database("beetplayerdb"); + QSqlQuery favRemoveQ(db); + favRemoveQ.prepare("DELETE FROM persistent_favorites WHERE tartist_name = :artist AND talbum_name = :album AND ttitle = :title"); + int removeCtr = 0; + for(const QModelIndex &idx : idxs){ + favRemoveQ.bindValue(":artist", idx.data(ArtistRole)); + favRemoveQ.bindValue(":album", idx.data(AlbumRole)); + favRemoveQ.bindValue(":title", idx.data(TitleRole)); + if(favRemoveQ.exec()){ + ++removeCtr; + } + } + populate(); + } +} diff --git a/collectionfavoritesview.h b/collectionfavoritesview.h index 4d3f7b5..d8d34d1 100644 --- a/collectionfavoritesview.h +++ b/collectionfavoritesview.h @@ -10,6 +10,7 @@ class CollectionFavoritesView : public CollectionWidget { public slots: virtual void populate(); + void removeFromFavorites(const QModelIndexList &idxs); }; #endif // COLLECTIONFAVORITESVIEW_H diff --git a/playerwidget.cpp b/playerwidget.cpp index d34b954..bb8509a 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -208,6 +208,7 @@ void PlayerWidget::setupGui(QSplashScreen *splash){ 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); + curW->view()->addActions(curW->customActions()->actions()); } } QAction *gotoAlbumA = new QAction(QIcon(":/next.png"), tr("Goto album"), this); -- cgit v1.2.3-70-g09d2