diff --git a/src/smartplaylists/querygenerator.cpp b/src/smartplaylists/querygenerator.cpp index ce5fba17b..019159ae4 100644 --- a/src/smartplaylists/querygenerator.cpp +++ b/src/smartplaylists/querygenerator.cpp @@ -24,13 +24,15 @@ namespace smart_playlists { QueryGenerator::QueryGenerator() - : dynamic_(false) + : dynamic_(false), + current_pos_(0) { } void QueryGenerator::Load(const Search& search) { search_ = search; dynamic_ = false; + current_pos_ = 0; } void QueryGenerator::Load(const QByteArray& data) { @@ -50,6 +52,7 @@ QByteArray QueryGenerator::Save() const { PlaylistItemList QueryGenerator::Generate() { previous_ids_.clear(); + current_pos_ = 0; return GenerateMore(0); } @@ -62,6 +65,11 @@ PlaylistItemList QueryGenerator::GenerateMore(int count) { search_copy.limit_ = kDynamicFuture; } + if (search_copy.sort_type_ != Search::Sort_Random) { + search_copy.first_item_ = current_pos_; + current_pos_ += search_copy.limit_; + } + SongList songs = backend_->FindSongs(search_copy); PlaylistItemList items; foreach (const Song& song, songs) { diff --git a/src/smartplaylists/querygenerator.h b/src/smartplaylists/querygenerator.h index 7ea0030dc..87e7c24c1 100644 --- a/src/smartplaylists/querygenerator.h +++ b/src/smartplaylists/querygenerator.h @@ -45,6 +45,7 @@ private: bool dynamic_; QList previous_ids_; + int current_pos_; }; } // namespace diff --git a/src/smartplaylists/search.cpp b/src/smartplaylists/search.cpp index 2f0ebe24b..19e85ca5f 100644 --- a/src/smartplaylists/search.cpp +++ b/src/smartplaylists/search.cpp @@ -33,7 +33,8 @@ Search::Search( terms_(terms), sort_type_(sort_type), sort_field_(sort_field), - limit_(limit) + limit_(limit), + first_item_(-1) { } @@ -43,6 +44,7 @@ void Search::Reset() { sort_type_ = Sort_Random; sort_field_ = SearchTerm::Field_Title; limit_ = -1; + first_item_ = -1; } QString Search::ToSql(const QString& songs_table) const { @@ -82,7 +84,9 @@ QString Search::ToSql(const QString& songs_table) const { } // Add limit - if (limit_ != -1) { + if (first_item_) { + sql += QString(" LIMIT %1,%2").arg(first_item_).arg(limit_); + } else if (limit_ != -1) { sql += " LIMIT " + QString::number(limit_); } diff --git a/src/smartplaylists/search.h b/src/smartplaylists/search.h index db2fb19ef..cca1662b5 100644 --- a/src/smartplaylists/search.h +++ b/src/smartplaylists/search.h @@ -56,7 +56,9 @@ public: SearchTerm::Field sort_field_; int limit_; + // Not persisted, used to alter the behaviour of the query QList id_not_in_; + int first_item_; void Reset(); QString ToSql(const QString& songs_table) const;