From 35b2beb4fba153c952b00c6f9adf450520a9c6cf Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sat, 9 Jan 2021 17:15:37 +0000 Subject: library: added quick search git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9623 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/library/librarymodel.cpp | 44 +++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'src/plugins/General/library/librarymodel.cpp') 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()) -- cgit v1.2.3-13-gbd6f