on xenial help sign in
Revert r376 that caused constant CPU usage due to the ActivityIndicator.

Approved by PS Jenkins bot, Loïc Minier.

commitec2e17445ba52d60148d0f1407b4eec599c97af6 authorMichał Sawicz <michal.sawicz@canonical.com> dateSat 5 Oct 2013, 10:39 (13 years ago) parent9cb0c29ac50b85
7 files changed+9−128
Components/PageHeader.qml+1−44 Dash/GenericScopeView.qml−1 plugins/Unity/scope.cpp+5−30 plugins/Unity/scope.h+2−7 tests/mocks/Unity/fake_scope.cpp−13 tests/mocks/Unity/fake_scope.h+1−5 tests/qmltests/Components/tst_PageHeader.qml−28
Components/PageHeader.qml+1−44
@@ -18,7 +18,6 @@ import QtQuick 2.0
1818import Ubuntu.Components 0.1
1919import Ubuntu.Components.Popups 0.1
2020import Ubuntu.Components.ListItems 0.1 as ListItem
21−import Unity 0.1
2221
2322Item {
2423 /*!
@@ -31,7 +30,6 @@ Item {
3130 property bool searchEntryEnabled: false
3231 property alias searchQuery: searchField.text
3332 property ListModel searchHistory: SearchHistoryModel {}
34− property Scope scope
3533
3634 height: units.gu(8.5)
3735 implicitHeight: units.gu(8.5)
@@ -150,7 +148,7 @@ Item {
150148 hasClearButton: false
151149
152150 primaryItem: AbstractButton {
153− enabled: searchField.text != "" && !searchIndicator.running
151+ enabled: searchField.text != ""
154152 onClicked: {
155153 if (searchField.text != "") {
156154 searchHistory.addQuery(searchField.text)
@@ -160,22 +158,8 @@ Item {
160158 height: parent.height
161159 width: height
162160
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−
176161 Image {
177162 id: primaryImage
178− objectName: "primaryImage"
179163 anchors {
180164 verticalCenter: parent.verticalCenter
181165 left: parent.left
@@ -183,7 +167,6 @@ Item {
183167 }
184168 width: units.gu(3)
185169 height: units.gu(3)
186− visible: opacity > 0
187170 }
188171
189172 Item {
@@ -202,32 +185,6 @@ Item {
202185 onActiveFocusChanged: {
203186 if (!activeFocus) searchContainer.closePopover()
204187 }
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− ]
231188 }
232189
233190 states: [
Dash/GenericScopeView.qml−1
@@ -190,7 +190,6 @@ ScopeView {
190190 width: categoryView.width
191191 text: scopeView.scope.name
192192 searchEntryEnabled: true
193− scope: scopeView.scope
194193 }
195194 }
196195
plugins/Unity/scope.cpp+5−30
@@ -33,14 +33,12 @@
3333#include <QQmlEngine>
3434
3535#include <UnityCore/Variant.h>
36−#include <UnityCore/GLibWrapper.h>
3736
3837#include <libintl.h>
3938#include <glib.h>
4039
4140Scope::Scope(QObject *parent) : QObject(parent)
4241 , m_formFactor("phone")
43− , m_searchInProgress(false)
4442{
4543 m_categories.reset(new Categories(this));
4644}
@@ -70,11 +68,6 @@ QString Scope::searchHint() const
7068 return QString::fromStdString(m_unityScope->search_hint());
7169}
7270
73−bool Scope::searchInProgress() const
74−{
75− return m_searchInProgress;
76−}
77−
7871bool Scope::visible() const
7972{
8073 return m_unityScope->visible();
@@ -122,15 +115,10 @@ void Scope::setSearchQuery(const QString& search_query)
122115 string ("") and m_searchQuery is the null string,
123116 search_query != m_searchQuery is still true.
124117 */
125− using namespace std::placeholders;
126−
127118 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
128119 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));
132121 Q_EMIT searchQueryChanged();
133− Q_EMIT searchInProgressChanged();
134122 }
135123}
136124
@@ -306,6 +294,8 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
306294 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
307295 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
308296 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 &)));
309299
310300 /* FIXME: signal should be forwarded instead of calling the handler directly */
311301 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
@@ -326,33 +316,18 @@ unity::dash::Scope::Ptr Scope::unityScope() const
326316
327317void Scope::synchronizeStates()
328318{
329− using namespace std::placeholders;
330−
331319 if (connected()) {
332320 /* Forward local states to m_unityScope */
333321 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);
337− Q_EMIT searchInProgressChanged();
322+ m_unityScope->Search(m_searchQuery.toStdString());
338323 }
339324 }
340325}
341326
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)
343328{
344329 QString hint;
345330
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−
356331 if (!m_unityScope->results()->count()) {
357332 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
358333 if (it != hints.end()) {
plugins/Unity/scope.h+2−7
@@ -28,7 +28,6 @@
2828// libunity-core
2929#include <UnityCore/Scope.h>
3030#include <UnityCore/Results.h>
31−#include <UnityCore/GLibWrapper.h>
3231
3332#include "categories.h"
3433#include "filters.h"
@@ -44,7 +43,6 @@ class Scope : public QObject
4443 Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
4544 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
4645 Q_PROPERTY(QString searchHint READ searchHint NOTIFY searchHintChanged)
47− Q_PROPERTY(bool searchInProgress READ searchInProgress NOTIFY searchInProgressChanged)
4846 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
4947 Q_PROPERTY(QString shortcut READ shortcut NOTIFY shortcutChanged)
5048 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
@@ -67,7 +65,6 @@ public:
6765 bool visible() const;
6866 QString shortcut() const;
6967 bool connected() const;
70− bool searchInProgress() const;
7168 Categories* categories() const;
7269 Filters* filters() const;
7370 QString searchQuery() const;
@@ -98,11 +95,11 @@ Q_SIGNALS:
9895 void iconHintChanged(const std::string&);
9996 void descriptionChanged(const std::string&);
10097 void searchHintChanged(const std::string&);
101− void searchInProgressChanged();
10298 void visibleChanged(bool);
10399 void shortcutChanged(const std::string&);
104100 void connectedChanged(bool);
105101 void categoriesChanged();
102+ void searchFinished(const std::string&, unity::glib::HintsMap const&, unity::glib::Error const&);
106103 void searchQueryChanged();
107104 void noResultsHintChanged();
108105 void formFactorChanged();
@@ -118,7 +115,7 @@ Q_SIGNALS:
118115
119116private Q_SLOTS:
120117 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 &);
122119
123120private:
124121 unity::dash::LocalResult createLocalResult(const QVariant &uri, const QVariant &icon_hint,
@@ -136,8 +133,6 @@ private:
136133 QString m_searchQuery;
137134 QString m_noResultsHint;
138135 QString m_formFactor;
139− bool m_searchInProgress;
140− unity::glib::Cancellable m_cancellable;
141136 unity::glib::Cancellable m_previewCancellable;
142137};
143138
tests/mocks/Unity/fake_scope.cpp−13
@@ -30,7 +30,6 @@ static DeeModel* create_results_model(unsigned category_count, unsigned result_c
3030Scope::Scope(QObject* parent)
3131 : QObject(parent)
3232 , m_visible(false)
33− , m_searching(false)
3433 , m_categories(new Categories(this))
3534 , m_results(new DeeListModel(this))
3635{
@@ -45,7 +44,6 @@ Scope::Scope(QString const& id, QString const& name, bool visible, QObject* pare
4544 , m_id(id)
4645 , m_name(name)
4746 , m_visible(visible)
48− , m_searching(false)
4947 , m_categories(new Categories(this))
5048 , m_results(new DeeListModel(this))
5149{
@@ -87,10 +85,6 @@ bool Scope::connected() const {
8785 return true;
8886}
8987
90−bool Scope::searchInProgress() const {
91− return m_searching;
92−}
93−
9488Categories* Scope::categories() const {
9589 return m_categories;
9690}
@@ -128,13 +122,6 @@ void Scope::setFormFactor(const QString &str) {
128122 }
129123}
130124
131−void Scope::setSearchInProgress(const bool inProg) {
132− if (inProg != m_searching) {
133− m_searching = inProg;
134− Q_EMIT searchInProgressChanged();
135− }
136−}
137−
138125void Scope::setNoResultsHint(const QString& str) {
139126 if (str != m_noResultsHint) {
140127 m_noResultsHint = str;
tests/mocks/Unity/fake_scope.h+1−5
@@ -37,7 +37,6 @@ class Scope : public QObject
3737 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
3838 Q_PROPERTY(Categories* categories READ categories NOTIFY categoriesChanged)
3939
40− Q_PROPERTY(bool searchInProgress READ searchInProgress WRITE setSearchInProgress NOTIFY searchInProgressChanged)
4140 Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
4241 Q_PROPERTY(QString noResultsHint READ noResultsHint WRITE setNoResultsHint NOTIFY noResultsHintChanged)
4342 Q_PROPERTY(QString formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged)
@@ -55,7 +54,6 @@ public:
5554 bool visible() const;
5655 QString shortcut() const;
5756 bool connected() const;
58− bool searchInProgress() const;
5957 Categories* categories() const;
6058 QString searchQuery() const;
6159 QString noResultsHint() const;
@@ -66,7 +64,6 @@ public:
6664 void setSearchQuery(const QString& search_query);
6765 void setNoResultsHint(const QString& hint);
6866 void setFormFactor(const QString& form_factor);
69− void setSearchInProgress(const bool inProg);
7067
7168 Q_INVOKABLE void activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
7269 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
@@ -81,11 +78,11 @@ Q_SIGNALS:
8178 void iconHintChanged(const QString&);
8279 void descriptionChanged(const QString&);
8380 void searchHintChanged(const QString&);
84− void searchInProgressChanged();
8581 void visibleChanged(bool);
8682 void shortcutChanged(const QString&);
8783 void connectedChanged(bool);
8884 void categoriesChanged();
85+ void searchFinished(const QString&);
8986 void searchQueryChanged();
9087 void noResultsHintChanged();
9188 void formFactorChanged();
@@ -106,7 +103,6 @@ protected:
106103 QString m_noResultsHint;
107104 QString m_formFactor;
108105 bool m_visible;
109− bool m_searching;
110106
111107 Categories* m_categories;
112108 DeeListModel* m_results;
tests/qmltests/Components/tst_PageHeader.qml−28
@@ -19,17 +19,12 @@ import QtTest 1.0
1919import ".."
2020import "../../../Components"
2121import Ubuntu.Components 0.1
22−import Unity 0.1
2322import Unity.Test 0.1 as UT
2423
2524Item {
2625 width: units.gu(110)
2726 height: units.gu(30)
2827
29− Scope {
30− id: scopeMock
31− }
32−
3328 UT.UnityTestCase {
3429 name: "PageHeaderTest"
3530 when: windowShown
@@ -137,27 +132,6 @@ Item {
137132 compare(pageHeader.searchHistory.count, 3)
138133 compare(pageHeader.searchHistory.get(0).query, "humppa4")
139134 }
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− }
161135 }
162136
163137 Column {
@@ -171,8 +145,6 @@ Item {
171145 right: parent.right
172146 }
173147
174− scope: scopeMock
175−
176148 searchEntryEnabled: true
177149 text: "%^$%^%^&%^&%^$%GHR%"
178150 }