diff --git a/src/library.cpp b/src/library.cpp index 4fb0715a4..66e5cf783 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -80,6 +80,9 @@ void Library::Initialise() { void Library::SongsDiscovered(const SongList& songs) { foreach (const Song& song, songs) { + if (!query_options_.Matches(song)) + continue; + LibraryItem* artist = NULL; LibraryItem* album = NULL; diff --git a/src/libraryquery.cpp b/src/libraryquery.cpp index d076e4ca5..d745e9e82 100644 --- a/src/libraryquery.cpp +++ b/src/libraryquery.cpp @@ -1,4 +1,5 @@ #include "libraryquery.h" +#include "song.h" #include #include @@ -54,3 +55,19 @@ QSqlQuery LibraryQuery::Query(QSqlDatabase db) const { return q; } + +bool QueryOptions::Matches(const Song& song) const { + if (max_age != -1) { + const uint cutoff = QDateTime::currentDateTime().toTime_t() - max_age; + if (song.ctime() <= cutoff) + return false; + } + + if (!filter.isNull()) { + return song.artist().contains(filter, Qt::CaseInsensitive) || + song.album().contains(filter, Qt::CaseInsensitive) || + song.title().contains(filter, Qt::CaseInsensitive); + } + + return true; +} diff --git a/src/libraryquery.h b/src/libraryquery.h index 5e3707238..307e0ec2c 100644 --- a/src/libraryquery.h +++ b/src/libraryquery.h @@ -7,9 +7,13 @@ #include #include +class Song; + struct QueryOptions { QueryOptions() : max_age(-1) {} + bool Matches(const Song& song) const; + QString filter; int max_age; };