aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
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
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')
-rw-r--r--src/plugins/General/library/library.cpp6
-rw-r--r--src/plugins/General/library/librarymodel.cpp44
-rw-r--r--src/plugins/General/library/librarymodel.h4
-rw-r--r--src/plugins/General/library/librarywidget.cpp9
-rw-r--r--src/plugins/General/library/librarywidget.h3
-rw-r--r--src/plugins/General/library/librarywidget.ui7
6 files changed, 62 insertions, 11 deletions
diff --git a/src/plugins/General/library/library.cpp b/src/plugins/General/library/library.cpp
index e38309398..ebe36108b 100644
--- a/src/plugins/General/library/library.cpp
+++ b/src/plugins/General/library/library.cpp
@@ -128,7 +128,7 @@ bool Library::createTables()
"Timestamp TIMESTAMP NOT NULL,"
"Title TEXT, Artist TEXT, AlbumArtist TEXT, Album TEXT, Comment TEXT, Genre TEXT, Composer TEXT,"
"Year INTEGER, Track INTEGER, DiscNumer INTEGER, Duration INTEGER, "
- "AudioInfo BLOB, URL TEXT, FilePath TEXT)");
+ "AudioInfo BLOB, URL TEXT, FilePath TEXT, SearchString TEXT)");
if(!ok)
qWarning("Library: unable to create table, error: %s", qPrintable(query.lastError().text()));
@@ -148,7 +148,7 @@ void Library::addTrack(TrackInfo *track, const QString &filePath)
":timestamp, "
":title, :artist, :albumartist, :album, :comment, :genre, :composer, "
":year, :track, :discnumber, :duration, "
- ":audioinfo, :url, :filepath)");
+ ":audioinfo, :url, :filepath, :searchstring)");
query.bindValue(":timestamp", QFileInfo(filePath).lastModified());
query.bindValue(":title", track->value(Qmmp::TITLE));
@@ -165,6 +165,8 @@ void Library::addTrack(TrackInfo *track, const QString &filePath)
query.bindValue(":audioinfo", serializeAudioInfo(track->properties()));
query.bindValue(":url", track->path());
query.bindValue(":filepath", filePath);
+ query.bindValue(":searchstring", QString("%1|||%2|||%3").arg(track->value(Qmmp::ARTIST))
+ .arg(track->value(Qmmp::ALBUM)).arg(track->value(Qmmp::TITLE)).toLower());
if(!query.exec())
qWarning("Library: exec error: %s", qPrintable(query.lastError().text()));
}
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())
diff --git a/src/plugins/General/library/librarymodel.h b/src/plugins/General/library/librarymodel.h
index a06365330..327e91629 100644
--- a/src/plugins/General/library/librarymodel.h
+++ b/src/plugins/General/library/librarymodel.h
@@ -46,12 +46,14 @@ public:
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ void setFilter(const QString &filter);
void refresh();
+
private:
QList<QUrl> getUrls(const QModelIndex &index) const;
-
LibraryTreeItem *m_rootItem;
+ QString m_filter;
};
#endif // LIBRARYMODEL_H
diff --git a/src/plugins/General/library/librarywidget.cpp b/src/plugins/General/library/librarywidget.cpp
index ab7664d00..041ff0e13 100644
--- a/src/plugins/General/library/librarywidget.cpp
+++ b/src/plugins/General/library/librarywidget.cpp
@@ -50,5 +50,14 @@ LibraryWidget::~LibraryWidget()
void LibraryWidget::refresh()
{
+ m_ui->filterLineEdit->clear();
m_model->refresh();
}
+
+void LibraryWidget::on_filterLineEdit_textChanged(const QString &text)
+{
+ m_model->setFilter(text);
+ m_model->refresh();
+ if(text.count() >= 3)
+ m_ui->treeView->expandAll();
+}
diff --git a/src/plugins/General/library/librarywidget.h b/src/plugins/General/library/librarywidget.h
index 8a9db9288..a77e543a8 100644
--- a/src/plugins/General/library/librarywidget.h
+++ b/src/plugins/General/library/librarywidget.h
@@ -37,6 +37,9 @@ public:
~LibraryWidget();
void refresh();
+private slots:
+ void on_filterLineEdit_textChanged(const QString &text);
+
private:
Ui::LibraryWidget *m_ui;
LibraryModel *m_model;
diff --git a/src/plugins/General/library/librarywidget.ui b/src/plugins/General/library/librarywidget.ui
index 54c9b0b71..31caf95e6 100644
--- a/src/plugins/General/library/librarywidget.ui
+++ b/src/plugins/General/library/librarywidget.ui
@@ -24,6 +24,13 @@
<number>6</number>
</property>
<item>
+ <widget class="QLineEdit" name="filterLineEdit">
+ <property name="clearButtonEnabled">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QTreeView" name="treeView">
<property name="dragEnabled">
<bool>true</bool>