on xenial help sign in
Add new searchInProgress property
376dd20Michal Hruby
plugins/Unity/scope.cpp+28−5
@@ -33,12 +33,14 @@
33#include <QQmlEngine>
33#include <QQmlEngine>
34
34
35#include <UnityCore/Variant.h>
35#include <UnityCore/Variant.h>
36+#include <UnityCore/GLibWrapper.h>
36
37
37#include <libintl.h>
38#include <libintl.h>
38#include <glib.h>
39#include <glib.h>
39
40
40Scope::Scope(QObject *parent) : QObject(parent)
41Scope::Scope(QObject *parent) : QObject(parent)
41 , m_formFactor("phone")
42 , m_formFactor("phone")
43+ , m_searchInProgress(false)
42{
44{
43 m_categories.reset(new Categories(this));
45 m_categories.reset(new Categories(this));
44}
46}
@@ -68,6 +70,11 @@ QString Scope::searchHint() const
68 return QString::fromStdString(m_unityScope->search_hint());
70 return QString::fromStdString(m_unityScope->search_hint());
69}
71}
70
72
73+bool Scope::searchInProgress() const
74+{
75+ return m_searchInProgress;
76+}
77+
71bool Scope::visible() const
78bool Scope::visible() const
72{
79{
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.
117 */
124 */
125+ using namespace std::placeholders;
126+
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();
122 }
134 }
123}
135}
124
136
@@ -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 &)));
280
290
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
297
307
298void Scope::synchronizeStates()
308void Scope::synchronizeStates()
299{
309{
310+ using namespace std::placeholders;
311+
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();
304 }
319 }
305 }
320 }
306}
321}
307
322
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)
309{
324{
310 QString hint;
325 QString hint;
311
326
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+
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()) {
plugins/Unity/scope.h+7−2
@@ -28,6 +28,7 @@
28// libunity-core
28// libunity-core
29#include <UnityCore/Scope.h>
29#include <UnityCore/Scope.h>
30#include <UnityCore/Results.h>
30#include <UnityCore/Results.h>
31+#include <UnityCore/GLibWrapper.h>
31
32
32#include "categories.h"
33#include "categories.h"
33#include "filters.h"
34#include "filters.h"
@@ -43,6 +44,7 @@ class Scope : public QObject
43 Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
44 Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
44 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
45 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
45 Q_PROPERTY(QString searchHint READ searchHint NOTIFY searchHintChanged)
46 Q_PROPERTY(QString searchHint READ searchHint NOTIFY searchHintChanged)
47+ Q_PROPERTY(QString searchInProgress READ searchInProgress NOTIFY searchInProgressChanged)
46 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
48 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
47 Q_PROPERTY(QString shortcut READ shortcut NOTIFY shortcutChanged)
49 Q_PROPERTY(QString shortcut READ shortcut NOTIFY shortcutChanged)
48 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
50 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
@@ -65,6 +67,7 @@ public:
65 bool visible() const;
67 bool visible() const;
66 QString shortcut() const;
68 QString shortcut() const;
67 bool connected() const;
69 bool connected() const;
70+ bool searchInProgress() const;
68 Categories* categories() const;
71 Categories* categories() const;
69 Filters* filters() const;
72 Filters* filters() const;
70 QString searchQuery() const;
73 QString searchQuery() const;
@@ -93,11 +96,11 @@ Q_SIGNALS:
93 void iconHintChanged(const std::string&);
96 void iconHintChanged(const std::string&);
94 void descriptionChanged(const std::string&);
97 void descriptionChanged(const std::string&);
95 void searchHintChanged(const std::string&);
98 void searchHintChanged(const std::string&);
99+ void searchInProgressChanged();
96 void visibleChanged(bool);
100 void visibleChanged(bool);
97 void shortcutChanged(const std::string&);
101 void shortcutChanged(const std::string&);
98 void connectedChanged(bool);
102 void connectedChanged(bool);
99 void categoriesChanged();
103 void categoriesChanged();
100− void searchFinished(const std::string&, unity::glib::HintsMap const&, unity::glib::Error const&);
101 void searchQueryChanged();
104 void searchQueryChanged();
102 void noResultsHintChanged();
105 void noResultsHintChanged();
103 void formFactorChanged();
106 void formFactorChanged();
@@ -113,7 +116,7 @@ Q_SIGNALS:
113
116
114private Q_SLOTS:
117private Q_SLOTS:
115 void synchronizeStates();
118 void synchronizeStates();
116− void onSearchFinished(const std::string &, unity::glib::HintsMap const &);
119+ void onSearchFinished(std::string const &, unity::glib::HintsMap const &, unity::glib::Error const&);
117
120
118private:
121private:
119 unity::dash::LocalResult createLocalResult(const QVariant &uri, const QVariant &icon_hint,
122 unity::dash::LocalResult createLocalResult(const QVariant &uri, const QVariant &icon_hint,
@@ -131,6 +134,8 @@ private:
131 QString m_searchQuery;
134 QString m_searchQuery;
132 QString m_noResultsHint;
135 QString m_noResultsHint;
133 QString m_formFactor;
136 QString m_formFactor;
137+ bool m_searchInProgress;
138+ unity::glib::Cancellable m_cancellable;
134};
139};
135
140
136Q_DECLARE_METATYPE(Scope*)
141Q_DECLARE_METATYPE(Scope*)