@@ -43,6 +43,8 @@ Scope::Scope(QObject *parent) : QObject(parent)
43 , m_searchInProgress(false)
43 , m_searchInProgress(false)
45 m_categories.reset(new Categories(this));
45 m_categories.reset(new Categories(this));
47+ connect(this, &Scope::isActiveChanged, this, &Scope::scopeIsActiveChanged);
48QString Scope::id() const
50QString Scope::id() const
@@ -132,10 +134,12 @@ void Scope::setSearchQuery(const QString& search_query)
132 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
134 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
133 m_searchQuery = search_query;
135 m_searchQuery = search_query;
134 m_cancellable.Renew();
136 m_cancellable.Renew();
135− m_searchInProgress = true;
136 m_unityScope->Search(search_query.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
137 m_unityScope->Search(search_query.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
137 Q_EMIT searchQueryChanged();
138 Q_EMIT searchQueryChanged();
139+ if (!m_searchInProgress) {
140+ m_searchInProgress = true;
138− Q_EMIT searchInProgressChanged();
141+ Q_EMIT searchInProgressChanged();
@@ -299,6 +303,7 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
299 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
303 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
300 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
304 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
301 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
305 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
306+ m_unityScope->results_dirty.changed.connect(sigc::mem_fun(this, &Scope::resultsDirtyToggled));
303 /* FIXME: signal should be forwarded instead of calling the handler directly */
308 /* FIXME: signal should be forwarded instead of calling the handler directly */
304 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
309 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
@@ -322,16 +327,35 @@ void Scope::synchronizeStates()
322 using namespace std::placeholders;
327 using namespace std::placeholders;
324 if (connected()) {
329 if (connected()) {
330+ qWarning("refreshing scope %s... because of something", m_unityScope->id().c_str());
325 /* Forward local states to m_unityScope */
331 /* Forward local states to m_unityScope */
326 if (!m_searchQuery.isNull()) {
332 if (!m_searchQuery.isNull()) {
327 m_cancellable.Renew();
333 m_cancellable.Renew();
328− m_searchInProgress = true;
329 m_unityScope->Search(m_searchQuery.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
334 m_unityScope->Search(m_searchQuery.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
335+ if (!m_searchInProgress) {
336+ m_searchInProgress = true;
330− Q_EMIT searchInProgressChanged();
337+ Q_EMIT searchInProgressChanged();
343+void Scope::scopeIsActiveChanged()
345+ if (!isActive() || !m_unityScope || !m_unityScope->results_dirty()) return;
348+ synchronizeStates();
351+void Scope::resultsDirtyToggled(bool results_dirty)
353+ if (!results_dirty || !isActive()) return;
356+ synchronizeStates();
335void Scope::onSearchFinished(std::string const& /* query */, unity::glib::HintsMap const& hints, unity::glib::Error const& err)
359void Scope::onSearchFinished(std::string const& /* query */, unity::glib::HintsMap const& hints, unity::glib::Error const& err)
337 QString hint;
361 QString hint;
@@ -339,8 +363,10 @@ void Scope::onSearchFinished(std::string const& /* query */, unity::glib::HintsM
339 GError* error = const_cast<unity::glib::Error&>(err);
363 GError* error = const_cast<unity::glib::Error&>(err);
341 if (!err || !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
365 if (!err || !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
366+ if (m_searchInProgress) {
342− m_searchInProgress = false;
367+ m_searchInProgress = false;
343− Q_EMIT searchInProgressChanged();
368+ Q_EMIT searchInProgressChanged();
345 // no need to check the results hint, we're still searching
371 // no need to check the results hint, we're still searching