@@ -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();
@@ -275,8 +287,6 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
275 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
287 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
276 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
288 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
277 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
289 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 &)));
281 /* FIXME: signal should be forwarded instead of calling the handler directly */
291 /* FIXME: signal should be forwarded instead of calling the handler directly */
282 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
292 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
@@ -297,18 +307,31 @@ unity::dash::Scope::Ptr Scope::unityScope() const
298void Scope::synchronizeStates()
308void Scope::synchronizeStates()
310+ using namespace std::placeholders;
300 if (connected()) {
312 if (connected()) {
301 /* Forward local states to m_unityScope */
313 /* Forward local states to m_unityScope */
302 if (!m_searchQuery.isNull()) {
314 if (!m_searchQuery.isNull()) {
315+ m_cancellable.Renew();
316+ m_searchInProgress = true;
303− m_unityScope->Search(m_searchQuery.toStdString());
317+ m_unityScope->Search(m_searchQuery.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
318+ Q_EMIT searchInProgressChanged();
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)
310 QString hint;
325 QString hint;
327+ GError* error = const_cast<unity::glib::Error&>(err);
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());
312 if (!m_unityScope->results()->count()) {
335 if (!m_unityScope->results()->count()) {
313 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
336 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
314 if (it != hints.end()) {
337 if (it != hints.end()) {