From d6d546addf41c2aefaa57b33a9fbf6d13f132421 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 21 Mar 2021 16:09:12 +0000 Subject: library: show album year git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9770 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/library/librarymodel.cpp | 15 ++++++++++++--- src/plugins/General/library/librarymodel.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/plugins/General/library/librarymodel.cpp b/src/plugins/General/library/librarymodel.cpp index 9541bb382..019118797 100644 --- a/src/plugins/General/library/librarymodel.cpp +++ b/src/plugins/General/library/librarymodel.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,7 @@ public: } QString name; + int year = 0; Qmmp::MetaData type = Qmmp::UNKNOWN; QList children; LibraryTreeItem *parent = nullptr; @@ -62,6 +64,8 @@ public: LibraryModel::LibraryModel(QObject *parent) : QAbstractItemModel(parent) { m_rootItem = new LibraryTreeItem; + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + m_showYear = settings.value("Library/show_year", false).toBool(); refresh(); } @@ -132,11 +136,11 @@ void LibraryModel::fetchMore(const QModelIndex &parent) QSqlQuery query(db); if(m_filter.isEmpty()) { - query.prepare("SELECT DISTINCT Album from track_library WHERE Artist = :artist"); + query.prepare("SELECT DISTINCT Album, Year from track_library WHERE Artist = :artist"); } else { - query.prepare("SELECT DISTINCT Album from track_library WHERE Artist = :artist AND SearchString LIKE :filter"); + query.prepare("SELECT DISTINCT Album, Year from track_library WHERE Artist = :artist AND SearchString LIKE :filter"); query.bindValue(":filter", QString("%%1%").arg(m_filter.toLower())); } query.bindValue(":artist", parentItem->name); @@ -151,6 +155,7 @@ void LibraryModel::fetchMore(const QModelIndex &parent) { LibraryTreeItem *item = new LibraryTreeItem; item->name = query.value("Album").toString(); + item->year = query.value("Year").toInt(); item->type = Qmmp::ALBUM; item->parent = parentItem; parentItem->children << item; @@ -194,7 +199,11 @@ QVariant LibraryModel::data(const QModelIndex &index, int role) const if(!index.isValid() || role != Qt::DisplayRole) return QVariant(); - return static_cast(index.internalPointer())->name; + LibraryTreeItem *item = static_cast(index.internalPointer()); + if(item->type == Qmmp::ALBUM && m_showYear && item->year > 0) + return tr("%1 - %2").arg(item->year).arg(item->name); + else + return item->name; } QModelIndex LibraryModel::parent(const QModelIndex &child) const diff --git a/src/plugins/General/library/librarymodel.h b/src/plugins/General/library/librarymodel.h index 4ba2c2529..6efda252b 100644 --- a/src/plugins/General/library/librarymodel.h +++ b/src/plugins/General/library/librarymodel.h @@ -61,6 +61,7 @@ private: LibraryTreeItem *m_rootItem; QString m_filter; + bool m_showYear; }; #endif // LIBRARYMODEL_H -- cgit v1.2.3-13-gbd6f