@@ -33,12 +33,14 @@
33#include <QQmlEngine>
33#include <QQmlEngine>
35#include <UnityCore/Variant.h>
35#include <UnityCore/Variant.h>
36+#include <UnityCore/GLibWrapper.h>
37#include <libintl.h>
38#include <libintl.h>
38#include <glib.h>
39#include <glib.h>
40Scope::Scope(QObject *parent) : QObject(parent)
41Scope::Scope(QObject *parent) : QObject(parent)
41 , m_formFactor("phone")
42 , m_formFactor("phone")
43+ , m_searchInProgress(false)
43 m_categories.reset(new Categories(this));
45 m_categories.reset(new Categories(this));
@@ -68,6 +70,11 @@ QString Scope::searchHint() const
68 return QString::fromStdString(m_unityScope->search_hint());
70 return QString::fromStdString(m_unityScope->search_hint());
73+bool Scope::searchInProgress() const
75+ return m_searchInProgress;
71bool Scope::visible() const
78bool Scope::visible() const
73 return m_unityScope->visible();
80 return m_unityScope->visible();
@@ -115,10 +122,15 @@ void Scope::setSearchQuery(const QString& search_query)
115 string ("") and m_searchQuery is the null string,
122 string ("") and m_searchQuery is the null string,
116 search_query != m_searchQuery is still true.
123 search_query != m_searchQuery is still true.
125+ using namespace std::placeholders;
118 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
127 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
119 m_searchQuery = search_query;
128 m_searchQuery = search_query;
129+ m_cancellable.Renew();
130+ m_searchInProgress = true;
120− m_unityScope->Search(search_query.toStdString(), sigc::mem_fun(this, &Scope::searchFinished));
131+ m_unityScope->Search(search_query.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
121 Q_EMIT searchQueryChanged();
132 Q_EMIT searchQueryChanged();
133+ Q_EMIT searchInProgressChanged();
@@ -294,8 +306,6 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
294 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
306 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
295 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
307 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
296 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
308 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
297− /* Signals forwarding */
298− connect(this, SIGNAL(searchFinished(const std::string &, unity::glib::HintsMap const &, unity::glib::Error const &)), SLOT(onSearchFinished(const std::string &, unity::glib::HintsMap const &)));
300 /* FIXME: signal should be forwarded instead of calling the handler directly */
310 /* FIXME: signal should be forwarded instead of calling the handler directly */
301 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
311 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
@@ -316,18 +326,33 @@ unity::dash::Scope::Ptr Scope::unityScope() const
317void Scope::synchronizeStates()
327void Scope::synchronizeStates()
329+ using namespace std::placeholders;
319 if (connected()) {
331 if (connected()) {
320 /* Forward local states to m_unityScope */
332 /* Forward local states to m_unityScope */
321 if (!m_searchQuery.isNull()) {
333 if (!m_searchQuery.isNull()) {
334+ m_cancellable.Renew();
335+ m_searchInProgress = true;
322− m_unityScope->Search(m_searchQuery.toStdString());
336+ m_unityScope->Search(m_searchQuery.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
337+ Q_EMIT searchInProgressChanged();
327−void Scope::onSearchFinished(const std::string& /* query */, unity::glib::HintsMap const &hints)
342+void Scope::onSearchFinished(std::string const& /* query */, unity::glib::HintsMap const& hints, unity::glib::Error const& err)
329 QString hint;
344 QString hint;
346+ GError* error = const_cast<unity::glib::Error&>(err);
348+ if (!err || !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
349+ m_searchInProgress = false;
350+ Q_EMIT searchInProgressChanged();
352+ // no need to check the results hint, we're still searching
331 if (!m_unityScope->results()->count()) {
356 if (!m_unityScope->results()->count()) {
332 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
357 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
333 if (it != hints.end()) {
358 if (it != hints.end()) {