on xenial help sign in
Revert r376 that caused constant CPU usage due to the ActivityIndicator.
ec2e174Michał Sawicz
Components/PageHeader.qml+1−44
@@ -18,7 +18,6 @@ import QtQuick 2.0
18import Ubuntu.Components 0.1
18import Ubuntu.Components 0.1
19import Ubuntu.Components.Popups 0.1
19import Ubuntu.Components.Popups 0.1
20import Ubuntu.Components.ListItems 0.1 as ListItem
20import Ubuntu.Components.ListItems 0.1 as ListItem
21−import Unity 0.1
22
21
23Item {
22Item {
24 /*!
23 /*!
@@ -31,7 +30,6 @@ Item {
31 property bool searchEntryEnabled: false
30 property bool searchEntryEnabled: false
32 property alias searchQuery: searchField.text
31 property alias searchQuery: searchField.text
33 property ListModel searchHistory: SearchHistoryModel {}
32 property ListModel searchHistory: SearchHistoryModel {}
34− property Scope scope
35
33
36 height: units.gu(8.5)
34 height: units.gu(8.5)
37 implicitHeight: units.gu(8.5)
35 implicitHeight: units.gu(8.5)
@@ -150,7 +148,7 @@ Item {
150 hasClearButton: false
148 hasClearButton: false
151
149
152 primaryItem: AbstractButton {
150 primaryItem: AbstractButton {
153− enabled: searchField.text != "" && !searchIndicator.running
151+ enabled: searchField.text != ""
154 onClicked: {
152 onClicked: {
155 if (searchField.text != "") {
153 if (searchField.text != "") {
156 searchHistory.addQuery(searchField.text)
154 searchHistory.addQuery(searchField.text)
@@ -160,22 +158,8 @@ Item {
160 height: parent.height
158 height: parent.height
161 width: height
159 width: height
162
160
163− ActivityIndicator {
164− id: searchIndicator
165− objectName: "searchIndicator"
166−
167− anchors {
168− verticalCenter: parent.verticalCenter
169− left: parent.left
170− leftMargin: units.gu(0.5)
171− }
172−
173− running: opacity > 0
174− }
175−
176 Image {
161 Image {
177 id: primaryImage
162 id: primaryImage
178− objectName: "primaryImage"
179 anchors {
163 anchors {
180 verticalCenter: parent.verticalCenter
164 verticalCenter: parent.verticalCenter
181 left: parent.left
165 left: parent.left
@@ -183,7 +167,6 @@ Item {
183 }
167 }
184 width: units.gu(3)
168 width: units.gu(3)
185 height: units.gu(3)
169 height: units.gu(3)
186− visible: opacity > 0
187 }
170 }
188
171
189 Item {
172 Item {
@@ -202,32 +185,6 @@ Item {
202 onActiveFocusChanged: {
185 onActiveFocusChanged: {
203 if (!activeFocus) searchContainer.closePopover()
186 if (!activeFocus) searchContainer.closePopover()
204 }
187 }
205−
206− states: [
207− State {
208− name: "searching"
209− when: scope.searchInProgress && searchField.text !== ""
210− PropertyChanges { target: searchIndicator; running: true; opacity: 1 }
211− PropertyChanges { target: primaryImage; opacity: 0 }
212− },
213− State {
214− name: "idle"
215− when: !scope.searchInProgress || searchField.text === ""
216− PropertyChanges { target: searchIndicator; opacity: 0 }
217− PropertyChanges { target: primaryImage; opacity: 1 }
218− }
219− ]
220−
221− transitions: [
222− Transition {
223− to: "searching"
224− reversible: true
225− SequentialAnimation {
226− NumberAnimation { target: primaryImage; property: "opacity"; duration: UbuntuAnimation.FastDuration; easing.type: Easing.Linear }
227− NumberAnimation { target: searchIndicator; property: "opacity"; duration: UbuntuAnimation.FastDuration; easing.type: Easing.Linear }
228− }
229− }
230− ]
231 }
188 }
232
189
233 states: [
190 states: [
Dash/GenericScopeView.qml−1
@@ -190,7 +190,6 @@ ScopeView {
190 width: categoryView.width
190 width: categoryView.width
191 text: scopeView.scope.name
191 text: scopeView.scope.name
192 searchEntryEnabled: true
192 searchEntryEnabled: true
193− scope: scopeView.scope
194 }
193 }
195 }
194 }
196
195
plugins/Unity/scope.cpp+5−30
@@ -33,14 +33,12 @@
33#include <QQmlEngine>
33#include <QQmlEngine>
34
34
35#include <UnityCore/Variant.h>
35#include <UnityCore/Variant.h>
36−#include <UnityCore/GLibWrapper.h>
37
36
38#include <libintl.h>
37#include <libintl.h>
39#include <glib.h>
38#include <glib.h>
40
39
41Scope::Scope(QObject *parent) : QObject(parent)
40Scope::Scope(QObject *parent) : QObject(parent)
42 , m_formFactor("phone")
41 , m_formFactor("phone")
43− , m_searchInProgress(false)
44{
42{
45 m_categories.reset(new Categories(this));
43 m_categories.reset(new Categories(this));
46}
44}
@@ -70,11 +68,6 @@ QString Scope::searchHint() const
70 return QString::fromStdString(m_unityScope->search_hint());
68 return QString::fromStdString(m_unityScope->search_hint());
71}
69}
72
70
73−bool Scope::searchInProgress() const
74−{
75− return m_searchInProgress;
76−}
77−
78bool Scope::visible() const
71bool Scope::visible() const
79{
72{
80 return m_unityScope->visible();
73 return m_unityScope->visible();
@@ -122,15 +115,10 @@ void Scope::setSearchQuery(const QString& search_query)
122 string ("") and m_searchQuery is the null string,
115 string ("") and m_searchQuery is the null string,
123 search_query != m_searchQuery is still true.
116 search_query != m_searchQuery is still true.
124 */
117 */
125− using namespace std::placeholders;
126−
127 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
118 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
128 m_searchQuery = search_query;
119 m_searchQuery = search_query;
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);
120+ m_unityScope->Search(search_query.toStdString(), sigc::mem_fun(this, &Scope::searchFinished));
132 Q_EMIT searchQueryChanged();
121 Q_EMIT searchQueryChanged();
133− Q_EMIT searchInProgressChanged();
134 }
122 }
135}
123}
136
124
@@ -306,6 +294,8 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
306 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
294 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
307 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
295 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
308 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
296 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 &)));
309
299
310 /* FIXME: signal should be forwarded instead of calling the handler directly */
300 /* FIXME: signal should be forwarded instead of calling the handler directly */
311 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
301 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
@@ -326,33 +316,18 @@ unity::dash::Scope::Ptr Scope::unityScope() const
326
316
327void Scope::synchronizeStates()
317void Scope::synchronizeStates()
328{
318{
329− using namespace std::placeholders;
330−
331 if (connected()) {
319 if (connected()) {
332 /* Forward local states to m_unityScope */
320 /* Forward local states to m_unityScope */
333 if (!m_searchQuery.isNull()) {
321 if (!m_searchQuery.isNull()) {
334− m_cancellable.Renew();
335− m_searchInProgress = true;
336− m_unityScope->Search(m_searchQuery.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
322+ m_unityScope->Search(m_searchQuery.toStdString());
337− Q_EMIT searchInProgressChanged();
338 }
323 }
339 }
324 }
340}
325}
341
326
342−void Scope::onSearchFinished(std::string const& /* query */, unity::glib::HintsMap const& hints, unity::glib::Error const& err)
327+void Scope::onSearchFinished(const std::string& /* query */, unity::glib::HintsMap const &hints)
343{
328{
344 QString hint;
329 QString hint;
345
330
346− GError* error = const_cast<unity::glib::Error&>(err);
347−
348− if (!err || !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
349− m_searchInProgress = false;
350− Q_EMIT searchInProgressChanged();
351− } else {
352− // no need to check the results hint, we're still searching
353− return;
354− }
355−
356 if (!m_unityScope->results()->count()) {
331 if (!m_unityScope->results()->count()) {
357 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
332 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
358 if (it != hints.end()) {
333 if (it != hints.end()) {
plugins/Unity/scope.h+2−7
@@ -28,7 +28,6 @@
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>
32
31
33#include "categories.h"
32#include "categories.h"
34#include "filters.h"
33#include "filters.h"
@@ -44,7 +43,6 @@ class Scope : public QObject
44 Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
43 Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
45 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
44 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
46 Q_PROPERTY(QString searchHint READ searchHint NOTIFY searchHintChanged)
45 Q_PROPERTY(QString searchHint READ searchHint NOTIFY searchHintChanged)
47− Q_PROPERTY(bool searchInProgress READ searchInProgress NOTIFY searchInProgressChanged)
48 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
46 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
49 Q_PROPERTY(QString shortcut READ shortcut NOTIFY shortcutChanged)
47 Q_PROPERTY(QString shortcut READ shortcut NOTIFY shortcutChanged)
50 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
48 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
@@ -67,7 +65,6 @@ public:
67 bool visible() const;
65 bool visible() const;
68 QString shortcut() const;
66 QString shortcut() const;
69 bool connected() const;
67 bool connected() const;
70− bool searchInProgress() const;
71 Categories* categories() const;
68 Categories* categories() const;
72 Filters* filters() const;
69 Filters* filters() const;
73 QString searchQuery() const;
70 QString searchQuery() const;
@@ -98,11 +95,11 @@ Q_SIGNALS:
98 void iconHintChanged(const std::string&);
95 void iconHintChanged(const std::string&);
99 void descriptionChanged(const std::string&);
96 void descriptionChanged(const std::string&);
100 void searchHintChanged(const std::string&);
97 void searchHintChanged(const std::string&);
101− void searchInProgressChanged();
102 void visibleChanged(bool);
98 void visibleChanged(bool);
103 void shortcutChanged(const std::string&);
99 void shortcutChanged(const std::string&);
104 void connectedChanged(bool);
100 void connectedChanged(bool);
105 void categoriesChanged();
101 void categoriesChanged();
102+ void searchFinished(const std::string&, unity::glib::HintsMap const&, unity::glib::Error const&);
106 void searchQueryChanged();
103 void searchQueryChanged();
107 void noResultsHintChanged();
104 void noResultsHintChanged();
108 void formFactorChanged();
105 void formFactorChanged();
@@ -118,7 +115,7 @@ Q_SIGNALS:
118
115
119private Q_SLOTS:
116private Q_SLOTS:
120 void synchronizeStates();
117 void synchronizeStates();
121− void onSearchFinished(std::string const &, unity::glib::HintsMap const &, unity::glib::Error const&);
118+ void onSearchFinished(const std::string &, unity::glib::HintsMap const &);
122
119
123private:
120private:
124 unity::dash::LocalResult createLocalResult(const QVariant &uri, const QVariant &icon_hint,
121 unity::dash::LocalResult createLocalResult(const QVariant &uri, const QVariant &icon_hint,
@@ -136,8 +133,6 @@ private:
136 QString m_searchQuery;
133 QString m_searchQuery;
137 QString m_noResultsHint;
134 QString m_noResultsHint;
138 QString m_formFactor;
135 QString m_formFactor;
139− bool m_searchInProgress;
140− unity::glib::Cancellable m_cancellable;
141 unity::glib::Cancellable m_previewCancellable;
136 unity::glib::Cancellable m_previewCancellable;
142};
137};
143
138
tests/mocks/Unity/fake_scope.cpp−13
@@ -30,7 +30,6 @@ static DeeModel* create_results_model(unsigned category_count, unsigned result_c
30Scope::Scope(QObject* parent)
30Scope::Scope(QObject* parent)
31 : QObject(parent)
31 : QObject(parent)
32 , m_visible(false)
32 , m_visible(false)
33− , m_searching(false)
34 , m_categories(new Categories(this))
33 , m_categories(new Categories(this))
35 , m_results(new DeeListModel(this))
34 , m_results(new DeeListModel(this))
36{
35{
@@ -45,7 +44,6 @@ Scope::Scope(QString const& id, QString const& name, bool visible, QObject* pare
45 , m_id(id)
44 , m_id(id)
46 , m_name(name)
45 , m_name(name)
47 , m_visible(visible)
46 , m_visible(visible)
48− , m_searching(false)
49 , m_categories(new Categories(this))
47 , m_categories(new Categories(this))
50 , m_results(new DeeListModel(this))
48 , m_results(new DeeListModel(this))
51{
49{
@@ -87,10 +85,6 @@ bool Scope::connected() const {
87 return true;
85 return true;
88}
86}
89
87
90−bool Scope::searchInProgress() const {
91− return m_searching;
92−}
93−
94Categories* Scope::categories() const {
88Categories* Scope::categories() const {
95 return m_categories;
89 return m_categories;
96}
90}
@@ -128,13 +122,6 @@ void Scope::setFormFactor(const QString &str) {
128 }
122 }
129}
123}
130
124
131−void Scope::setSearchInProgress(const bool inProg) {
132− if (inProg != m_searching) {
133− m_searching = inProg;
134− Q_EMIT searchInProgressChanged();
135− }
136−}
137−
138void Scope::setNoResultsHint(const QString& str) {
125void Scope::setNoResultsHint(const QString& str) {
139 if (str != m_noResultsHint) {
126 if (str != m_noResultsHint) {
140 m_noResultsHint = str;
127 m_noResultsHint = str;
tests/mocks/Unity/fake_scope.h+1−5
@@ -37,7 +37,6 @@ class Scope : public QObject
37 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
37 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
38 Q_PROPERTY(Categories* categories READ categories NOTIFY categoriesChanged)
38 Q_PROPERTY(Categories* categories READ categories NOTIFY categoriesChanged)
39
39
40− Q_PROPERTY(bool searchInProgress READ searchInProgress WRITE setSearchInProgress NOTIFY searchInProgressChanged)
41 Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
40 Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
42 Q_PROPERTY(QString noResultsHint READ noResultsHint WRITE setNoResultsHint NOTIFY noResultsHintChanged)
41 Q_PROPERTY(QString noResultsHint READ noResultsHint WRITE setNoResultsHint NOTIFY noResultsHintChanged)
43 Q_PROPERTY(QString formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged)
42 Q_PROPERTY(QString formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged)
@@ -55,7 +54,6 @@ public:
55 bool visible() const;
54 bool visible() const;
56 QString shortcut() const;
55 QString shortcut() const;
57 bool connected() const;
56 bool connected() const;
58− bool searchInProgress() const;
59 Categories* categories() const;
57 Categories* categories() const;
60 QString searchQuery() const;
58 QString searchQuery() const;
61 QString noResultsHint() const;
59 QString noResultsHint() const;
@@ -66,7 +64,6 @@ public:
66 void setSearchQuery(const QString& search_query);
64 void setSearchQuery(const QString& search_query);
67 void setNoResultsHint(const QString& hint);
65 void setNoResultsHint(const QString& hint);
68 void setFormFactor(const QString& form_factor);
66 void setFormFactor(const QString& form_factor);
69− void setSearchInProgress(const bool inProg);
70
67
71 Q_INVOKABLE void activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
68 Q_INVOKABLE void activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
72 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
69 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
@@ -81,11 +78,11 @@ Q_SIGNALS:
81 void iconHintChanged(const QString&);
78 void iconHintChanged(const QString&);
82 void descriptionChanged(const QString&);
79 void descriptionChanged(const QString&);
83 void searchHintChanged(const QString&);
80 void searchHintChanged(const QString&);
84− void searchInProgressChanged();
85 void visibleChanged(bool);
81 void visibleChanged(bool);
86 void shortcutChanged(const QString&);
82 void shortcutChanged(const QString&);
87 void connectedChanged(bool);
83 void connectedChanged(bool);
88 void categoriesChanged();
84 void categoriesChanged();
85+ void searchFinished(const QString&);
89 void searchQueryChanged();
86 void searchQueryChanged();
90 void noResultsHintChanged();
87 void noResultsHintChanged();
91 void formFactorChanged();
88 void formFactorChanged();
@@ -106,7 +103,6 @@ protected:
106 QString m_noResultsHint;
103 QString m_noResultsHint;
107 QString m_formFactor;
104 QString m_formFactor;
108 bool m_visible;
105 bool m_visible;
109− bool m_searching;
110
106
111 Categories* m_categories;
107 Categories* m_categories;
112 DeeListModel* m_results;
108 DeeListModel* m_results;
tests/qmltests/Components/tst_PageHeader.qml−28
@@ -19,17 +19,12 @@ import QtTest 1.0
19import ".."
19import ".."
20import "../../../Components"
20import "../../../Components"
21import Ubuntu.Components 0.1
21import Ubuntu.Components 0.1
22−import Unity 0.1
23import Unity.Test 0.1 as UT
22import Unity.Test 0.1 as UT
24
23
25Item {
24Item {
26 width: units.gu(110)
25 width: units.gu(110)
27 height: units.gu(30)
26 height: units.gu(30)
28
27
29− Scope {
30− id: scopeMock
31− }
32−
33 UT.UnityTestCase {
28 UT.UnityTestCase {
34 name: "PageHeaderTest"
29 name: "PageHeaderTest"
35 when: windowShown
30 when: windowShown
@@ -137,27 +132,6 @@ Item {
137 compare(pageHeader.searchHistory.count, 3)
132 compare(pageHeader.searchHistory.count, 3)
138 compare(pageHeader.searchHistory.get(0).query, "humppa4")
133 compare(pageHeader.searchHistory.get(0).query, "humppa4")
139 }
134 }
140−
141− function test_search_indicator() {
142− var searchIndicator = findChild(pageHeader, "searchIndicator")
143− var primaryImage = findChild(pageHeader, "primaryImage")
144−
145− pageHeader.triggerSearch()
146−
147− scopeMock.searchInProgress = false
148− compare(searchIndicator.running, false, "Search indicator is running.")
149− tryCompare(primaryImage, "visible", true)
150−
151− scopeMock.searchInProgress = true
152− compare(searchIndicator.running, true, "Search indicator isn't running.")
153− tryCompare(primaryImage, "visible", false)
154−
155− pageHeader.resetSearch()
156− }
157−
158− function cleanup() {
159− scopeMock.searchInProgress = false
160− }
161 }
135 }
162
136
163 Column {
137 Column {
@@ -171,8 +145,6 @@ Item {
171 right: parent.right
145 right: parent.right
172 }
146 }
173
147
174− scope: scopeMock
175−
176 searchEntryEnabled: true
148 searchEntryEnabled: true
177 text: "%^$%^%^&%^&%^$%GHR%"
149 text: "%^$%^%^&%^&%^$%GHR%"
178 }
150 }