@@ -43,6 +43,8 @@ Scope::Scope(QObject *parent) : QObject(parent)
4343 , m_searchInProgress(false)
4444{
4545 m_categories.reset(new Categories(this));
46+
47+ connect(this, &Scope::isActiveChanged, this, &Scope::scopeIsActiveChanged);
4648}
4749
4850QString Scope::id() const
@@ -110,6 +112,11 @@ QString Scope::formFactor() const
110112 return m_formFactor;
111113}
112114
115+bool Scope::isActive() const
116+{
117+ return m_isActive;
118+}
119+
113120Filters* Scope::filters() const
114121{
115122 return m_filters.get();
@@ -127,10 +134,12 @@ void Scope::setSearchQuery(const QString& search_query)
127134 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
128135 m_searchQuery = search_query;
129136 m_cancellable.Renew();
130− m_searchInProgress = true;
131137 m_unityScope->Search(search_query.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
132138 Q_EMIT searchQueryChanged();
133− Q_EMIT searchInProgressChanged();
139+ if (!m_searchInProgress) {
140+ m_searchInProgress = true;
141+ Q_EMIT searchInProgressChanged();
142+ }
134143 }
135144}
136145
@@ -152,6 +161,13 @@ void Scope::setFormFactor(const QString& form_factor) {
152161 }
153162}
154163
164+void Scope::setActive(const bool active) {
165+ if (active != m_isActive) {
166+ m_isActive = active;
167+ Q_EMIT isActiveChanged(m_isActive);
168+ }
169+}
170+
155171unity::dash::LocalResult Scope::createLocalResult(const QVariant &uri, const QVariant &icon_hint,
156172 const QVariant &category, const QVariant &result_type,
157173 const QVariant &mimetype, const QVariant &title,
@@ -306,6 +322,7 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
306322 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
307323 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
308324 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
325+ m_unityScope->results_dirty.changed.connect(sigc::mem_fun(this, &Scope::resultsDirtyToggled));
309326
310327 /* FIXME: signal should be forwarded instead of calling the handler directly */
311328 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
@@ -332,13 +349,31 @@ void Scope::synchronizeStates()
332349 /* Forward local states to m_unityScope */
333350 if (!m_searchQuery.isNull()) {
334351 m_cancellable.Renew();
335− m_searchInProgress = true;
336352 m_unityScope->Search(m_searchQuery.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
337− Q_EMIT searchInProgressChanged();
353+ if (!m_searchInProgress) {
354+ m_searchInProgress = true;
355+ Q_EMIT searchInProgressChanged();
356+ }
338357 }
339358 }
340359}
341360
361+void Scope::scopeIsActiveChanged()
362+{
363+ if (!isActive() || !m_unityScope || !m_unityScope->results_dirty()) return;
364+
365+ // force new search
366+ synchronizeStates();
367+}
368+
369+void Scope::resultsDirtyToggled(bool results_dirty)
370+{
371+ if (!results_dirty || !isActive()) return;
372+
373+ // force new search
374+ synchronizeStates();
375+}
376+
342377void Scope::onSearchFinished(std::string const& /* query */, unity::glib::HintsMap const& hints, unity::glib::Error const& err)
343378{
344379 QString hint;
@@ -346,8 +381,10 @@ void Scope::onSearchFinished(std::string const& /* query */, unity::glib::HintsM
346381 GError* error = const_cast<unity::glib::Error&>(err);
347382
348383 if (!err || !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
349− m_searchInProgress = false;
350− Q_EMIT searchInProgressChanged();
384+ if (m_searchInProgress) {
385+ m_searchInProgress = false;
386+ Q_EMIT searchInProgressChanged();
387+ }
351388 } else {
352389 // no need to check the results hint, we're still searching
353390 return;