David's comments

This commit is contained in:
Paweł Bara 2011-02-14 17:29:56 +00:00
parent 0182829223
commit d109b70898
3 changed files with 26 additions and 26 deletions

View File

@ -589,7 +589,7 @@ void LibraryModel::BeginReset() {
} }
// Smart playlists? // Smart playlists?
if (show_smart_playlists_ && query_options_.get_filter().isEmpty()) if (show_smart_playlists_ && query_options_.filter().isEmpty())
CreateSmartPlaylists(); CreateSmartPlaylists();
} }

View File

@ -23,8 +23,8 @@
#include <QSqlError> #include <QSqlError>
QueryOptions::QueryOptions() QueryOptions::QueryOptions()
: max_age(-1), : max_age_(-1),
query_mode(QueryMode_All) query_mode_(QueryMode_All)
{ {
} }
@ -33,14 +33,14 @@ LibraryQuery::LibraryQuery(const QueryOptions& options)
: join_with_fts_(false), : join_with_fts_(false),
limit_(-1) limit_(-1)
{ {
if (!options.get_filter().isEmpty()) { if (!options.filter().isEmpty()) {
// We need to munge the filter text a little bit to get it to work as // We need to munge the filter text a little bit to get it to work as
// expected with sqlite's FTS3: // expected with sqlite's FTS3:
// 1) Append * to all tokens. // 1) Append * to all tokens.
// 2) Prefix "fts" to column names. // 2) Prefix "fts" to column names.
// Split on whitespace // Split on whitespace
QStringList tokens(options.get_filter().split(QRegExp("\\s+"))); QStringList tokens(options.filter().split(QRegExp("\\s+")));
QString query; QString query;
foreach (QString token, tokens) { foreach (QString token, tokens) {
token.remove('('); token.remove('(');
@ -57,8 +57,8 @@ LibraryQuery::LibraryQuery(const QueryOptions& options)
join_with_fts_ = true; join_with_fts_ = true;
} }
if (options.get_max_age() != -1) { if (options.max_age() != -1) {
int cutoff = QDateTime::currentDateTime().toTime_t() - options.get_max_age(); int cutoff = QDateTime::currentDateTime().toTime_t() - options.max_age();
where_clauses_ << "ctime > ?"; where_clauses_ << "ctime > ?";
bound_values_ << cutoff; bound_values_ << cutoff;
@ -71,9 +71,9 @@ LibraryQuery::LibraryQuery(const QueryOptions& options)
// consistent - this way filtering is available only in the All mode. // consistent - this way filtering is available only in the All mode.
// remember though that when you fix the Duplicates + FTS cooperation, enable the // remember though that when you fix the Duplicates + FTS cooperation, enable the
// filtering in both Duplicates and Untagged modes. // filtering in both Duplicates and Untagged modes.
duplicates_only_ = options.get_query_mode() == QueryOptions::QueryMode_Duplicates; duplicates_only_ = options.query_mode() == QueryOptions::QueryMode_Duplicates;
if (options.get_query_mode() == QueryOptions::QueryMode_Untagged) { if (options.query_mode() == QueryOptions::QueryMode_Untagged) {
where_clauses_ << "(artist = '' OR album = '' OR title ='')"; where_clauses_ << "(artist = '' OR album = '' OR title ='')";
} }
} }
@ -159,16 +159,16 @@ QVariant LibraryQuery::Value(int column) const {
} }
bool QueryOptions::Matches(const Song& song) const { bool QueryOptions::Matches(const Song& song) const {
if (max_age != -1) { if (max_age_ != -1) {
const uint cutoff = QDateTime::currentDateTime().toTime_t() - max_age; const uint cutoff = QDateTime::currentDateTime().toTime_t() - max_age_;
if (song.ctime() <= cutoff) if (song.ctime() <= cutoff)
return false; return false;
} }
if (!filter.isNull()) { if (!filter_.isNull()) {
return song.artist().contains(filter, Qt::CaseInsensitive) || return song.artist().contains(filter_, Qt::CaseInsensitive) ||
song.album().contains(filter, Qt::CaseInsensitive) || song.album().contains(filter_, Qt::CaseInsensitive) ||
song.title().contains(filter, Qt::CaseInsensitive); song.title().contains(filter_, Qt::CaseInsensitive);
} }
return true; return true;

View File

@ -48,25 +48,25 @@ struct QueryOptions {
bool Matches(const Song& song) const; bool Matches(const Song& song) const;
QString get_filter() const { return filter; } QString filter() const { return filter_; }
void set_filter(const QString& filter) { void set_filter(const QString& filter) {
this->filter = filter; this->filter_ = filter;
this->query_mode = QueryMode_All; this->query_mode_ = QueryMode_All;
} }
int get_max_age() const { return max_age; } int max_age() const { return max_age_; }
void set_max_age(int max_age) { this->max_age = max_age; } void set_max_age(int max_age) { this->max_age_ = max_age; }
QueryMode get_query_mode() const { return query_mode; } QueryMode query_mode() const { return query_mode_; }
void set_query_mode(QueryMode query_mode) { void set_query_mode(QueryMode query_mode) {
this->query_mode = query_mode; this->query_mode_ = query_mode;
this->filter = QString(); this->filter_ = QString();
} }
private: private:
QString filter; QString filter_;
int max_age; int max_age_;
QueryMode query_mode; QueryMode query_mode_;
}; };
class LibraryQuery { class LibraryQuery {