aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/General/library/librarymodel.cpp
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2021-01-09 17:15:37 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2021-01-09 17:15:37 +0000
commit35b2beb4fba153c952b00c6f9adf450520a9c6cf (patch)
tree1145428b100d73ca23e1d3ea06163279aa31d4bd /src/plugins/General/library/librarymodel.cpp
parentd3b39e7538baf4d1194c519c5c988d87e10d539b (diff)
downloadqmmp-35b2beb4fba153c952b00c6f9adf450520a9c6cf.tar.gz
qmmp-35b2beb4fba153c952b00c6f9adf450520a9c6cf.tar.bz2
qmmp-35b2beb4fba153c952b00c6f9adf450520a9c6cf.zip
library: added quick search
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9623 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/General/library/librarymodel.cpp')
-rw-r--r--src/plugins/General/library/librarymodel.cpp44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/plugins/General/library/librarymodel.cpp b/src/plugins/General/library/librarymodel.cpp
index ca42b3ef0..d347f0ffe 100644
--- a/src/plugins/General/library/librarymodel.cpp
+++ b/src/plugins/General/library/librarymodel.cpp
@@ -128,11 +128,18 @@ void LibraryModel::fetchMore(const QModelIndex &parent)
if(parentItem->type == Qmmp::ARTIST)
{
QSqlQuery query(db);
- query.prepare("SELECT DISTINCT Album from track_library WHERE Artist = :artist");
+ if(m_filter.isEmpty())
+ {
+ query.prepare("SELECT DISTINCT Album from track_library WHERE Artist = :artist");
+ }
+ else
+ {
+ query.prepare("SELECT DISTINCT Album from track_library WHERE Artist = :artist AND SearchString LIKE :filter");
+ query.bindValue(":filter", QString("%%1%").arg(m_filter.toLower()));
+ }
query.bindValue(":artist", parentItem->name);
- bool ok = query.exec();
- if(!ok)
+ if(!query.exec())
{
qWarning("Library: exec error: %s", qPrintable(query.lastError().text()));
return;
@@ -151,12 +158,20 @@ void LibraryModel::fetchMore(const QModelIndex &parent)
else if(parentItem->type == Qmmp::ALBUM)
{
QSqlQuery query(db);
- query.prepare("SELECT Title from track_library WHERE Artist = :artist AND Album = :album");
+ if(m_filter.isEmpty())
+ {
+ query.prepare("SELECT Title from track_library WHERE Artist = :artist AND Album = :album");
+ }
+ else
+ {
+ query.prepare("SELECT Title from track_library WHERE Artist = :artist AND Album = :album "
+ "AND SearchString LIKE :filter");
+ query.bindValue(":filter", QString("%%1%").arg(m_filter.toLower()));
+ }
query.bindValue(":artist", parentItem->parent->name);
query.bindValue(":album", parentItem->name);
- bool ok = query.exec();
- if(!ok)
+ if(!query.exec())
{
qWarning("Library: exec error: %s", qPrintable(query.lastError().text()));
return;
@@ -228,6 +243,11 @@ int LibraryModel::rowCount(const QModelIndex &parent) const
return qMax(1, parentItem->children.count());
}
+void LibraryModel::setFilter(const QString &filter)
+{
+ m_filter = filter;
+}
+
void LibraryModel::refresh()
{
beginResetModel();
@@ -253,9 +273,17 @@ void LibraryModel::refresh()
}
QSqlQuery query(db);
- bool ok = query.exec("SELECT DISTINCT Artist from track_library");
+ if(m_filter.isEmpty())
+ {
+ query.prepare("SELECT DISTINCT Artist from track_library");
+ }
+ else
+ {
+ query.prepare("SELECT DISTINCT Artist from track_library WHERE SearchString LIKE :filter");
+ query.bindValue(":filter", QString("%%1%").arg(m_filter.toLower()));
+ }
- if(!ok)
+ if(!query.exec())
qWarning("Library: exec error: %s", qPrintable(query.lastError().text()));
while(query.next())