diff --git a/src/smartplaylists/querywizardplugin.cpp b/src/smartplaylists/querywizardplugin.cpp index d35de4c7c..328b9a18c 100644 --- a/src/smartplaylists/querywizardplugin.cpp +++ b/src/smartplaylists/querywizardplugin.cpp @@ -127,6 +127,13 @@ int QueryWizardPlugin::CreatePages(QWizard* wizard, int finish_page_id) { // Set up the preview widget that's already at the bottom of the sort page sort_ui_->preview->set_library(library_); + connect(sort_ui_->field, SIGNAL(toggled(bool)), SLOT(UpdateSortPreview())); + connect(sort_ui_->field_value, SIGNAL(currentIndexChanged(int)), SLOT(UpdateSortPreview())); + connect(sort_ui_->limit_limit, SIGNAL(toggled(bool)), SLOT(UpdateSortPreview())); + connect(sort_ui_->limit_none, SIGNAL(toggled(bool)), SLOT(UpdateSortPreview())); + connect(sort_ui_->limit_value, SIGNAL(valueChanged(QString)), SLOT(UpdateSortPreview())); + connect(sort_ui_->order, SIGNAL(currentIndexChanged(int)), SLOT(UpdateSortPreview())); + connect(sort_ui_->random, SIGNAL(toggled(bool)), SLOT(UpdateSortPreview())); // Configure the page text search_page_->setTitle(tr("Search terms")); diff --git a/src/smartplaylists/search.cpp b/src/smartplaylists/search.cpp index ec5aca471..f474e0748 100644 --- a/src/smartplaylists/search.cpp +++ b/src/smartplaylists/search.cpp @@ -79,6 +79,14 @@ bool Search::is_valid() const { return !terms_.isEmpty(); } +bool Search::operator ==(const Search& other) const { + return search_type_ == other.search_type_ && + terms_ == other.terms_ && + sort_type_ == other.sort_type_ && + sort_field_ == other.sort_field_ && + limit_ == other.limit_; +} + } // namespace QDataStream& operator <<(QDataStream& s, const smart_playlists::Search& search) { diff --git a/src/smartplaylists/search.h b/src/smartplaylists/search.h index 897c8e047..3a1a4fe1b 100644 --- a/src/smartplaylists/search.h +++ b/src/smartplaylists/search.h @@ -46,6 +46,8 @@ public: int limit = Generator::kDefaultLimit); bool is_valid() const; + bool operator ==(const Search& other) const; + bool operator !=(const Search& other) const { return !(*this == other); } SearchType search_type_; TermList terms_; diff --git a/src/smartplaylists/searchpreview.cpp b/src/smartplaylists/searchpreview.cpp index 12174c05b..8a836d8ec 100644 --- a/src/smartplaylists/searchpreview.cpp +++ b/src/smartplaylists/searchpreview.cpp @@ -58,6 +58,11 @@ void SearchPreview::set_library(LibraryBackend* backend) { } void SearchPreview::Update(const Search& search) { + if (search == last_search_) { + // This search was the same as the last one we did + return; + } + if (generator_) { // It's busy generating something already pending_search_ = search; @@ -84,9 +89,11 @@ void SearchPreview::RunSearch(const Search& search) { void SearchPreview::SearchFinished() { FutureWatcher* watcher = static_cast(sender()); watcher->deleteLater(); + + last_search_ = generator_->search(); generator_.reset(); - if (pending_search_.is_valid()) { + if (pending_search_.is_valid() && pending_search_ != last_search_) { // There was another search done while we were running - throw away these // results and do that one now instead RunSearch(pending_search_); diff --git a/src/smartplaylists/searchpreview.h b/src/smartplaylists/searchpreview.h index 9e31c8d72..855a12caf 100644 --- a/src/smartplaylists/searchpreview.h +++ b/src/smartplaylists/searchpreview.h @@ -56,6 +56,7 @@ private: Playlist* model_; Search pending_search_; + Search last_search_; boost::scoped_ptr generator_; }; diff --git a/src/smartplaylists/searchterm.cpp b/src/smartplaylists/searchterm.cpp index 837a20be2..0a257469f 100644 --- a/src/smartplaylists/searchterm.cpp +++ b/src/smartplaylists/searchterm.cpp @@ -71,6 +71,12 @@ bool SearchTerm::is_valid() const { return false; } +bool SearchTerm::operator ==(const SearchTerm& other) const { + return field_ == other.field_ && + operator_ == other.operator_ && + value_ == other.value_; +} + SearchTerm::Type SearchTerm::TypeOf(Field field) { switch (field) { case Field_Length: diff --git a/src/smartplaylists/searchterm.h b/src/smartplaylists/searchterm.h index 5af676409..7c40525ed 100644 --- a/src/smartplaylists/searchterm.h +++ b/src/smartplaylists/searchterm.h @@ -85,6 +85,8 @@ public: QString ToSql() const; bool is_valid() const; + bool operator ==(const SearchTerm& other) const; + bool operator !=(const SearchTerm& other) const { return !(*this == other); } static Type TypeOf(Field field); static QList OperatorsForType(Type type);