aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2021-03-21 16:09:12 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2021-03-21 16:09:12 +0000
commitd6d546addf41c2aefaa57b33a9fbf6d13f132421 (patch)
tree691249ddaee413314c3765820f4c8246b8c6e400 /src/plugins
parente1d67586140fe18d48acf6fb4fef1556b15b091c (diff)
downloadqmmp-d6d546addf41c2aefaa57b33a9fbf6d13f132421.tar.gz
qmmp-d6d546addf41c2aefaa57b33a9fbf6d13f132421.tar.bz2
qmmp-d6d546addf41c2aefaa57b33a9fbf6d13f132421.zip
library: show album year
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9770 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/General/library/librarymodel.cpp15
-rw-r--r--src/plugins/General/library/librarymodel.h1
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 <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
+#include <QSettings>
#include <QtDebug>
#include <QMimeData>
#include <QHash>
@@ -54,6 +55,7 @@ public:
}
QString name;
+ int year = 0;
Qmmp::MetaData type = Qmmp::UNKNOWN;
QList<LibraryTreeItem *> 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<LibraryTreeItem *>(index.internalPointer())->name;
+ LibraryTreeItem *item = static_cast<LibraryTreeItem *>(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