1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-15 18:58:55 +01:00

Obey the filter when updating songs in the database/library.

This commit is contained in:
David Sansome 2010-01-15 21:43:57 +00:00
parent 70613f5299
commit 07ef49f380
3 changed files with 24 additions and 0 deletions

View File

@ -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;

View File

@ -1,4 +1,5 @@
#include "libraryquery.h"
#include "song.h"
#include <QtDebug>
#include <QDateTime>
@ -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;
}

View File

@ -7,9 +7,13 @@
#include <QStringList>
#include <QVariantList>
class Song;
struct QueryOptions {
QueryOptions() : max_age(-1) {}
bool Matches(const Song& song) const;
QString filter;
int max_age;
};