on xenial help sign in
Re-query scopes when results are invalidated
commit8c0896af7f08fb5432cee87b38fd66a402678dc9 authorMichal Hruby <michal.mhr@gmail.com> dateWed 25 Sep 2013, 17:35 (13 years ago) parent22e43a1
3 files changed+35−7
plugins/Unity/CMakeLists.txt+1−1 plugins/Unity/scope.cpp+32−6 plugins/Unity/scope.h+2
plugins/Unity/CMakeLists.txt+1−1
@@ -7,7 +7,7 @@ add_subdirectory(IndicatorsLegacy)
77# Dependencies
88include(FindPkgConfig)
99pkg_check_modules(QTDEE REQUIRED libdee-qt5>=3.2)
10−pkg_check_modules(UNITYCORE REQUIRED unity-core-6.0)
10+pkg_check_modules(UNITYCORE REQUIRED unity-core-6.0>=7.1.1)
1111
1212include_directories(
1313 ${CMAKE_CURRENT_SOURCE_DIR}
plugins/Unity/scope.cpp+32−6
@@ -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
@@ -132,10 +134,12 @@ void Scope::setSearchQuery(const QString& search_query)
132134 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
133135 m_searchQuery = search_query;
134136 m_cancellable.Renew();
135− m_searchInProgress = true;
136137 m_unityScope->Search(search_query.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
137138 Q_EMIT searchQueryChanged();
138− Q_EMIT searchInProgressChanged();
139+ if (!m_searchInProgress) {
140+ m_searchInProgress = true;
141+ Q_EMIT searchInProgressChanged();
142+ }
139143 }
140144}
141145
@@ -299,6 +303,7 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
299303 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
300304 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
301305 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
306+ m_unityScope->results_dirty.changed.connect(sigc::mem_fun(this, &Scope::resultsDirtyToggled));
302307
303308 /* FIXME: signal should be forwarded instead of calling the handler directly */
304309 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
@@ -322,16 +327,35 @@ void Scope::synchronizeStates()
322327 using namespace std::placeholders;
323328
324329 if (connected()) {
330+ qWarning("refreshing scope %s... because of something", m_unityScope->id().c_str());
325331 /* Forward local states to m_unityScope */
326332 if (!m_searchQuery.isNull()) {
327333 m_cancellable.Renew();
328− m_searchInProgress = true;
329334 m_unityScope->Search(m_searchQuery.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
330− Q_EMIT searchInProgressChanged();
335+ if (!m_searchInProgress) {
336+ m_searchInProgress = true;
337+ Q_EMIT searchInProgressChanged();
338+ }
331339 }
332340 }
333341}
334342
343+void Scope::scopeIsActiveChanged()
344+{
345+ if (!isActive() || !m_unityScope || !m_unityScope->results_dirty()) return;
346+
347+ // force new search
348+ synchronizeStates();
349+}
350+
351+void Scope::resultsDirtyToggled(bool results_dirty)
352+{
353+ if (!results_dirty || !isActive()) return;
354+
355+ // force new search
356+ synchronizeStates();
357+}
358+
335359void Scope::onSearchFinished(std::string const& /* query */, unity::glib::HintsMap const& hints, unity::glib::Error const& err)
336360{
337361 QString hint;
@@ -339,8 +363,10 @@ void Scope::onSearchFinished(std::string const& /* query */, unity::glib::HintsM
339363 GError* error = const_cast<unity::glib::Error&>(err);
340364
341365 if (!err || !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
342− m_searchInProgress = false;
343− Q_EMIT searchInProgressChanged();
366+ if (m_searchInProgress) {
367+ m_searchInProgress = false;
368+ Q_EMIT searchInProgressChanged();
369+ }
344370 } else {
345371 // no need to check the results hint, we're still searching
346372 return;
plugins/Unity/scope.h+2
@@ -120,6 +120,7 @@ Q_SIGNALS:
120120
121121private Q_SLOTS:
122122 void synchronizeStates();
123+ void scopeIsActiveChanged();
123124 void onSearchFinished(std::string const &, unity::glib::HintsMap const &, unity::glib::Error const&);
124125
125126private:
@@ -131,6 +132,7 @@ private:
131132 void onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints);
132133 void onPreviewReady(unity::dash::LocalResult const& result, unity::dash::Preview::Ptr const& preview);
133134 void fallbackActivate(const QString& uri);
135+ void resultsDirtyToggled(bool);
134136
135137 unity::dash::Scope::Ptr m_unityScope;
136138 std::unique_ptr<Categories> m_categories;