summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2018-02-17 08:05:36 +0100
committerArno <arno@disconnect.de>2018-02-17 08:05:36 +0100
commit613f1e254738ee4b9e23c7dee14e901d50abfb49 (patch)
tree840de522f9ebde5d9fa799a713ace4a66c3d6d34
parent7ea45995fe16be78ebeebd8d79b8145802699eaa (diff)
downloadBeetPlayer-613f1e254738ee4b9e23c7dee14e901d50abfb49.tar.gz
BeetPlayer-613f1e254738ee4b9e23c7dee14e901d50abfb49.tar.bz2
BeetPlayer-613f1e254738ee4b9e23c7dee14e901d50abfb49.zip
New class: CollectionFoldersView
Basically the same as doPopulateByFolder, just wrapped in a shiny, new CollectionWidget.
-rw-r--r--BeetPlayer.pro6
-rw-r--r--collectionfoldersview.cpp59
-rw-r--r--collectionfoldersview.h18
3 files changed, 81 insertions, 2 deletions
diff --git a/BeetPlayer.pro b/BeetPlayer.pro
index 270c436..66d9073 100644
--- a/BeetPlayer.pro
+++ b/BeetPlayer.pro
@@ -40,7 +40,8 @@ SOURCES += main.cpp\
collectionalbumsview.cpp \
collectiondatesview.cpp \
collectionfavoritesview.cpp \
- collectionwebradioview.cpp
+ collectionwebradioview.cpp \
+ collectionfoldersview.cpp
HEADERS += beetplayer.h \
configurationdialog.h \
@@ -57,7 +58,8 @@ HEADERS += beetplayer.h \
collectionalbumsview.h \
collectiondatesview.h \
collectionfavoritesview.h \
- collectionwebradioview.h
+ collectionwebradioview.h \
+ collectionfoldersview.h
LIBS += -ltag
diff --git a/collectionfoldersview.cpp b/collectionfoldersview.cpp
new file mode 100644
index 0000000..4f1ad84
--- /dev/null
+++ b/collectionfoldersview.cpp
@@ -0,0 +1,59 @@
+#include <QSettings>
+#include <QStandardItem>
+#include <QDir>
+#include <QMimeDatabase>
+
+#include <taglib/fileref.h>
+
+#include "collectionfoldersview.h"
+
+CollectionFoldersView::CollectionFoldersView(QWidget *parent) : CollectionWidget(parent){
+ readSettings();
+}
+
+void CollectionFoldersView::populate(){
+ model()->clear();
+ model()->setHorizontalHeaderLabels(headers());
+ QStandardItem *root = model()->invisibleRootItem();
+ QDir d(mCurrentFolder);
+ QMimeDatabase db;
+ QIcon songIcon(":/song.png");
+ QIcon otherIcon(":/belly_right_and_clear.png");
+ QIcon dirIcon(":/folder.png");
+ QFileInfoList fl = d.entryInfoList(QStringList() << "*", QDir::Files | QDir::Dirs | QDir::NoDot, QDir::Name | QDir::DirsFirst);
+ for(const QFileInfo &fi : fl){
+ QStandardItem *cur = new QStandardItem;
+ cur->setEditable(false);
+ cur->setText(fi.fileName());
+ if(fi.isDir()){
+ cur->setIcon(dirIcon);
+ }else if(fi.isFile()){
+ QMimeType mt = db.mimeTypeForFile(fi);
+ if(mt.name().startsWith("audio")){
+ cur->setIcon(songIcon);
+ cur->setData(Song, TypeRole);
+ cur->setData(-1, IdRole);
+ TagLib::FileRef file(fi.absoluteFilePath().toUtf8());
+ if(!file.isNull()){
+ QString artist = QString::fromStdWString(file.tag()->artist().toWString());
+ cur->setData(artist.toLower(), ArtistRole);
+ QString album = QString::fromStdWString(file.tag()->album().toWString());
+ cur->setData(album.toLower(), AlbumRole);
+ QString genre = QString::fromStdWString(file.tag()->genre().toWString());
+ cur->setData(genre.toLower(), GenreRole);
+ QString title = QString::fromStdWString(file.tag()->title().toWString());
+ cur->setData(title.toLower(), TitleRole);
+ }
+ }else{
+ cur->setIcon(otherIcon);
+ }
+ }
+ cur->setData(fi.absoluteFilePath(), FullPathRole);
+ root->appendRow(cur);
+ }
+}
+
+void CollectionFoldersView::readSettings(){
+ QSettings s;
+ mCurrentFolder = s.value("folderdir", QDir::homePath()).toString();
+}
diff --git a/collectionfoldersview.h b/collectionfoldersview.h
new file mode 100644
index 0000000..20c041f
--- /dev/null
+++ b/collectionfoldersview.h
@@ -0,0 +1,18 @@
+#ifndef COLLECTIONFOLDERSVIEW_H
+#define COLLECTIONFOLDERSVIEW_H
+
+#include "collectionwidget.h"
+
+class CollectionFoldersView : public CollectionWidget {
+ public:
+ CollectionFoldersView(QWidget *parent = nullptr);
+
+ public slots:
+ virtual void populate();
+ virtual void readSettings();
+
+ private:
+ QString mCurrentFolder;
+};
+
+#endif // COLLECTIONFOLDERSVIEW_H