on xenial help sign in
Re-query scopes when results are invalidated
8c0896aMichal Hruby
plugins/Unity/CMakeLists.txt+1−1
@@ -7,7 +7,7 @@ add_subdirectory(IndicatorsLegacy)
7# Dependencies
7# Dependencies
8include(FindPkgConfig)
8include(FindPkgConfig)
9pkg_check_modules(QTDEE REQUIRED libdee-qt5>=3.2)
9pkg_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)
11
11
12include_directories(
12include_directories(
13 ${CMAKE_CURRENT_SOURCE_DIR}
13 ${CMAKE_CURRENT_SOURCE_DIR}
plugins/Unity/scope.cpp+32−6
@@ -43,6 +43,8 @@ Scope::Scope(QObject *parent) : QObject(parent)
43 , m_searchInProgress(false)
43 , m_searchInProgress(false)
44{
44{
45 m_categories.reset(new Categories(this));
45 m_categories.reset(new Categories(this));
46+
47+ connect(this, &Scope::isActiveChanged, this, &Scope::scopeIsActiveChanged);
46}
48}
47
49
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();
142+ }
139 }
143 }
140}
144}
141
145
@@ -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));
302
307
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;
323
328
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();
338+ }
331 }
339 }
332 }
340 }
333}
341}
334
342
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+
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)
336{
360{
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);
340
364
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();
369+ }
344 } else {
370 } else {
345 // no need to check the results hint, we're still searching
371 // no need to check the results hint, we're still searching
346 return;
372 return;
plugins/Unity/scope.h+2
@@ -120,6 +120,7 @@ Q_SIGNALS:
120
120
121private Q_SLOTS:
121private Q_SLOTS:
122 void synchronizeStates();
122 void synchronizeStates();
123+ void scopeIsActiveChanged();
123 void onSearchFinished(std::string const &, unity::glib::HintsMap const &, unity::glib::Error const&);
124 void onSearchFinished(std::string const &, unity::glib::HintsMap const &, unity::glib::Error const&);
124
125
125private:
126private:
@@ -131,6 +132,7 @@ private:
131 void onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints);
132 void onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints);
132 void onPreviewReady(unity::dash::LocalResult const& result, unity::dash::Preview::Ptr const& preview);
133 void onPreviewReady(unity::dash::LocalResult const& result, unity::dash::Preview::Ptr const& preview);
133 void fallbackActivate(const QString& uri);
134 void fallbackActivate(const QString& uri);
135+ void resultsDirtyToggled(bool);
134
136
135 unity::dash::Scope::Ptr m_unityScope;
137 unity::dash::Scope::Ptr m_unityScope;
136 std::unique_ptr<Categories> m_categories;
138 std::unique_ptr<Categories> m_categories;