@@ -33,12 +33,14 @@
3333#include <QQmlEngine>
3434
3535#include <UnityCore/Variant.h>
36+#include <UnityCore/GLibWrapper.h>
3637
3738#include <libintl.h>
3839#include <glib.h>
3940
4041Scope::Scope(QObject *parent) : QObject(parent)
4142 , m_formFactor("phone")
43+ , m_searchInProgress(false)
4244{
4345 m_categories.reset(new Categories(this));
4446}
@@ -68,6 +70,11 @@ QString Scope::searchHint() const
6870 return QString::fromStdString(m_unityScope->search_hint());
6971}
7072
73+bool Scope::searchInProgress() const
74+{
75+ return m_searchInProgress;
76+}
77+
7178bool Scope::visible() const
7279{
7380 return m_unityScope->visible();
@@ -115,10 +122,15 @@ void Scope::setSearchQuery(const QString& search_query)
115122 string ("") and m_searchQuery is the null string,
116123 search_query != m_searchQuery is still true.
117124 */
125+ using namespace std::placeholders;
126+
118127 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
119128 m_searchQuery = search_query;
120− m_unityScope->Search(search_query.toStdString(), sigc::mem_fun(this, &Scope::searchFinished));
129+ m_cancellable.Renew();
130+ m_searchInProgress = true;
131+ m_unityScope->Search(search_query.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
121132 Q_EMIT searchQueryChanged();
133+ Q_EMIT searchInProgressChanged();
122134 }
123135}
124136
@@ -275,8 +287,6 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
275287 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
276288 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
277289 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
278− /* Signals forwarding */
279− connect(this, SIGNAL(searchFinished(const std::string &, unity::glib::HintsMap const &, unity::glib::Error const &)), SLOT(onSearchFinished(const std::string &, unity::glib::HintsMap const &)));
280290
281291 /* FIXME: signal should be forwarded instead of calling the handler directly */
282292 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
@@ -297,18 +307,31 @@ unity::dash::Scope::Ptr Scope::unityScope() const
297307
298308void Scope::synchronizeStates()
299309{
310+ using namespace std::placeholders;
311+
300312 if (connected()) {
301313 /* Forward local states to m_unityScope */
302314 if (!m_searchQuery.isNull()) {
303− m_unityScope->Search(m_searchQuery.toStdString());
315+ m_cancellable.Renew();
316+ m_searchInProgress = true;
317+ m_unityScope->Search(m_searchQuery.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
318+ Q_EMIT searchInProgressChanged();
304319 }
305320 }
306321}
307322
308−void Scope::onSearchFinished(const std::string& /* query */, unity::glib::HintsMap const &hints)
323+void Scope::onSearchFinished(std::string const& query, unity::glib::HintsMap const& hints, unity::glib::Error const& err)
309324{
310325 QString hint;
311326
327+ GError* error = const_cast<unity::glib::Error&>(err);
328+
329+ if (!err || !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
330+ m_searchInProgress = false;
331+ Q_EMIT searchInProgressChanged();
332+ qWarning("search for %s finished", query.c_str());
333+ }
334+
312335 if (!m_unityScope->results()->count()) {
313336 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
314337 if (it != hints.end()) {