summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2018-02-17 07:03:44 +0100
committerArno <arno@disconnect.de>2018-02-17 07:03:44 +0100
commit3095a50fe57b9ccefca133106651f3bc2c3d7895 (patch)
treee8dadeb57be1a78f39592cda4307536303fc18dd
parentca1d008ebaa5a28284cdba97046b48be421ccacd (diff)
downloadBeetPlayer-3095a50fe57b9ccefca133106651f3bc2c3d7895.tar.gz
BeetPlayer-3095a50fe57b9ccefca133106651f3bc2c3d7895.tar.bz2
BeetPlayer-3095a50fe57b9ccefca133106651f3bc2c3d7895.zip
New class: CollectionFavoritesView
Basically the same as populateByFavorites, just wrapped in a shiny, new CollectionWidget.
-rw-r--r--BeetPlayer.pro6
-rw-r--r--collectionfavoritesview.cpp43
-rw-r--r--collectionfavoritesview.h14
3 files changed, 61 insertions, 2 deletions
diff --git a/BeetPlayer.pro b/BeetPlayer.pro
index 7f42954..db46255 100644
--- a/BeetPlayer.pro
+++ b/BeetPlayer.pro
@@ -38,7 +38,8 @@ SOURCES += main.cpp\
collectionwidget.cpp \
collectionartistsview.cpp \
collectionalbumsview.cpp \
- collectiondatesview.cpp
+ collectiondatesview.cpp \
+ collectionfavoritesview.cpp
HEADERS += beetplayer.h \
configurationdialog.h \
@@ -53,7 +54,8 @@ HEADERS += beetplayer.h \
collectionwidget.h \
collectionartistsview.h \
collectionalbumsview.h \
- collectiondatesview.h
+ collectiondatesview.h \
+ collectionfavoritesview.h
LIBS += -ltag
diff --git a/collectionfavoritesview.cpp b/collectionfavoritesview.cpp
new file mode 100644
index 0000000..d57d0d2
--- /dev/null
+++ b/collectionfavoritesview.cpp
@@ -0,0 +1,43 @@
+#include <QSqlDatabase>
+#include <QSqlQuery>
+#include <QStandardItem>
+
+#include "collectionfavoritesview.h"
+
+CollectionFavoritesView::CollectionFavoritesView(QWidget *parent) : CollectionWidget(parent) {
+}
+
+void CollectionFavoritesView::populate(){
+ model()->clear();
+ model()->setHorizontalHeaderLabels(headers());
+ QSqlDatabase db = QSqlDatabase::database("beetplayerdb");
+ QStandardItem *root = model()->invisibleRootItem();
+ QIcon songIcon(":/song.png");
+ QSqlQuery favQ2(db);
+ favQ2.prepare("SELECT sipos, tfullpath, igenres_id, artists.tartists_name, albums.talbum_name, ilength from songs, artists, albums WHERE songs.ttitle = :song AND albums.talbum_name = :album AND albums.ialbums_id = songs.ialbums_id AND artists.tartists_name = :artist AND artists.iartists_id = songs.iartists_id");
+ QSqlQuery favQ1("SELECT tartist_name, talbum_name, ttitle FROM persistent_favorites", db);
+ while(favQ1.next()){
+ QStandardItem *curSong = new QStandardItem;
+ curSong->setEditable(false);
+ curSong->setFont(QFont("courier"));
+ favQ2.bindValue(":song", favQ1.value(2));
+ favQ2.bindValue(":album", favQ1.value(1));
+ favQ2.bindValue(":artist", favQ1.value(0));
+ favQ2.exec();
+ favQ2.next();
+ QFontMetrics fm(QFont("courier"));
+ QString songTitle = fm.elidedText(favQ1.value(2).toString(), Qt::ElideRight, fm.width('X') * 28);
+ QString songText = QString("%1 - %2 - %3").arg(favQ1.value(0).toString(), -25).arg(songTitle, -30).arg(favQ1.value(1).toString());
+ curSong->setText(songText);
+ curSong->setIcon(songIcon);
+ curSong->setData(Song, TypeRole);
+ curSong->setData(favQ2.value(0), IdRole);
+ curSong->setData(favQ2.value(1), FullPathRole);
+ curSong->setData(favQ2.value(2), GenreRole);
+ curSong->setData(favQ1.value(0), ArtistRole);
+ curSong->setData(favQ1.value(2), TitleRole);
+ curSong->setData(favQ1.value(1), AlbumRole);
+ curSong->setData(favQ2.value(5), LengthRole);
+ root->appendRow(QList<QStandardItem*>() << curSong);
+ }
+}
diff --git a/collectionfavoritesview.h b/collectionfavoritesview.h
new file mode 100644
index 0000000..f7722c8
--- /dev/null
+++ b/collectionfavoritesview.h
@@ -0,0 +1,14 @@
+#ifndef COLLECTIONFAVORITESVIEW_H
+#define COLLECTIONFAVORITESVIEW_H
+
+#include "collectionwidget.h"
+
+class CollectionFavoritesView : public CollectionWidget {
+ public:
+ CollectionFavoritesView(QWidget *parent = nullptr);
+
+ public slots:
+ virtual void populate();
+};
+
+#endif // COLLECTIONFAVORITESVIEW_H