Merge lp:~stolowski/unity-scopes-shell/fix-current-nav-id into lp:unity-scopes-shell

Proposed by Paweł Stołowski
Status: Merged
Approved by: Pete Woods
Approved revision: 179
Merged at revision: 178
Proposed branch: lp:~stolowski/unity-scopes-shell/fix-current-nav-id
Merge into: lp:unity-scopes-shell
Diff against target: 156 lines (+55/-37)
2 files modified
src/Unity/scope.cpp (+54/-36)
src/Unity/scope.h (+1/-1)
To merge this branch: bzr merge lp:~stolowski/unity-scopes-shell/fix-current-nav-id
Reviewer Review Type Date Requested Status
Pete Woods (community) Approve
Marcus Tomlinson (community) Needs Information
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+243679@code.launchpad.net

Commit message

Don't conclude too early that current department id should be reset.

Description of the change

Don't conclude too early that current department id should be reset.

The flushUpdates() method gets called when search query finishes, but may also get called earlier (if scope is slow - plugin has a timer for that) to push whatever has been received so far. This method also resets the id of current deparment if departments have not been received and current department id is not empty.

This fix changes flushUpdates to only consider resetting current department id if the query has finished or departments have been received.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

8 - QObject::connect(&m_aggregatorTimer, &QTimer::timeout, this, &Scope::flushUpdates);
9 + QObject::connect(&m_aggregatorTimer, SIGNAL(timeout()), this, SLOT(flushUpdates()));

11 - QObject::connect(&m_clearTimer, &QTimer::timeout, this, &Scope::flushUpdates);
12 + QObject::connect(&m_clearTimer, SIGNAL(timeout()), this, SLOT(flushUpdates()));

Why are we replacing the safer C++11 connect calls with the older connect variant here?

review: Needs Information
Revision history for this message
Pete Woods (pete-woods) :
review: Approve
Revision history for this message
Pete Woods (pete-woods) wrote :

Marcus. I guess that lets us use the Qt mechanism for discarding arguments from signals when you connect to a zero argument slot.

Revision history for this message
Paweł Stołowski (stolowski) wrote :

> Marcus. I guess that lets us use the Qt mechanism for discarding arguments
> from signals when you connect to a zero argument slot.

Yes, this is the reason.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Unity/scope.cpp'
2--- src/Unity/scope.cpp 2014-11-19 15:12:52 +0000
3+++ src/Unity/scope.cpp 2014-12-04 14:53:30 +0000
4@@ -103,9 +103,9 @@
5 }
6 QObject::connect(&m_typingTimer, &QTimer::timeout, this, &Scope::typingFinished);
7 m_aggregatorTimer.setSingleShot(true);
8- QObject::connect(&m_aggregatorTimer, &QTimer::timeout, this, &Scope::flushUpdates);
9+ QObject::connect(&m_aggregatorTimer, SIGNAL(timeout()), this, SLOT(flushUpdates()));
10 m_clearTimer.setSingleShot(true);
11- QObject::connect(&m_clearTimer, &QTimer::timeout, this, &Scope::flushUpdates);
12+ QObject::connect(&m_clearTimer, SIGNAL(timeout()), this, SLOT(flushUpdates()));
13 m_invalidateTimer.setSingleShot(true);
14 m_invalidateTimer.setTimerType(Qt::CoarseTimer);
15 QObject::connect(&m_invalidateTimer, &QTimer::timeout, this, &Scope::invalidateResults);
16@@ -148,7 +148,7 @@
17 } else { // status in [FINISHED, ERROR]
18 m_aggregatorTimer.stop();
19
20- flushUpdates();
21+ flushUpdates(true);
22
23 setSearchInProgress(false);
24
25@@ -303,7 +303,7 @@
26 Q_EMIT searchQueryChanged();
27 }
28
29-void Scope::flushUpdates()
30+void Scope::flushUpdates(bool finalize)
31 {
32 if (m_delayedClear) {
33 // TODO: here we could do resultset diffs
34@@ -356,18 +356,26 @@
35
36 m_lastRootDepartment = m_rootDepartment;
37
38- bool containsDepartments = m_rootDepartment.get() != nullptr;
39- // design decision - no navigation when doing searches
40- containsDepartments &= m_searchQuery.isEmpty();
41-
42- if (containsDepartments != m_hasNavigation) {
43- m_hasNavigation = containsDepartments;
44- Q_EMIT hasNavigationChanged();
45- }
46-
47- if (!containsDepartments && !m_currentNavigationId.isEmpty()) {
48- m_currentNavigationId = "";
49- Q_EMIT currentNavigationIdChanged();
50+ //
51+ // only consider resetting current department id if we are in final flushUpdates
52+ // or received departments already. We don't know if we should reset it
53+ // until query finishes because departments may still arrive.
54+ if (finalize || m_rootDepartment.get() != nullptr)
55+ {
56+ bool containsDepartments = m_rootDepartment.get() != nullptr;
57+ // design decision - no navigation when doing searches
58+ containsDepartments &= m_searchQuery.isEmpty();
59+
60+ if (containsDepartments != m_hasNavigation) {
61+ m_hasNavigation = containsDepartments;
62+ Q_EMIT hasNavigationChanged();
63+ }
64+
65+ if (!containsDepartments && !m_currentNavigationId.isEmpty()) {
66+ qDebug() << "Resetting current nav id";
67+ m_currentNavigationId = "";
68+ Q_EMIT currentNavigationIdChanged();
69+ }
70 }
71
72 // process the alt navigation (sort order filter)
73@@ -389,26 +397,34 @@
74
75 m_lastSortOrderFilter = m_sortOrderFilter;
76
77- bool containsAltNav = m_sortOrderFilter.get() != nullptr;
78- // design decision - no navigation when doing searches
79- containsAltNav &= m_searchQuery.isEmpty();
80-
81- if (containsAltNav != m_hasAltNavigation) {
82- m_hasAltNavigation = containsAltNav;
83- Q_EMIT hasAltNavigationChanged();
84- }
85-
86- if (!containsAltNav && !m_currentAltNavigationId.isEmpty()) {
87- m_currentAltNavigationId = "";
88- Q_EMIT currentAltNavigationIdChanged();
89- }
90-
91- if (containsAltNav && currentAltNav != m_currentAltNavigationId) {
92- m_currentAltNavigationId = currentAltNav;
93- Q_EMIT currentAltNavigationIdChanged();
94-
95- // update the alt navigation models
96- updateNavigationModels(m_altNavTree.data(), m_altNavModels, m_currentAltNavigationId);
97+ //
98+ // only consider resetting alt nav id if we are in final flushUpdates
99+ // or received alt nav filter already. We don't know if we should reset it
100+ // until query finishes because filter may still arrive.
101+ if (finalize || m_sortOrderFilter.get() != nullptr)
102+ {
103+ bool containsAltNav = m_sortOrderFilter.get() != nullptr;
104+ // design decision - no navigation when doing searches
105+ containsAltNav &= m_searchQuery.isEmpty();
106+
107+ if (containsAltNav != m_hasAltNavigation) {
108+ m_hasAltNavigation = containsAltNav;
109+ Q_EMIT hasAltNavigationChanged();
110+ }
111+
112+ if (!containsAltNav && !m_currentAltNavigationId.isEmpty()) {
113+ qDebug() << "Resetting alt nav id";
114+ m_currentAltNavigationId = "";
115+ Q_EMIT currentAltNavigationIdChanged();
116+ }
117+
118+ if (containsAltNav && currentAltNav != m_currentAltNavigationId) {
119+ m_currentAltNavigationId = currentAltNav;
120+ Q_EMIT currentAltNavigationIdChanged();
121+
122+ // update the alt navigation models
123+ updateNavigationModels(m_altNavTree.data(), m_altNavModels, m_currentAltNavigationId);
124+ }
125 }
126 }
127
128@@ -624,6 +640,7 @@
129 void Scope::setCurrentNavigationId(QString const& id)
130 {
131 if (m_currentNavigationId != id) {
132+ qDebug() << "Setting current nav id:" << this->id() << id;
133 m_currentNavigationId = id;
134 Q_EMIT currentNavigationIdChanged();
135 }
136@@ -702,6 +719,7 @@
137 scopes::SearchListenerBase::SPtr listener(new SearchResultReceiver(this));
138 m_searchController->setListener(listener);
139 try {
140+ qDebug() << "Dispatching search:" << id() << m_searchQuery << m_currentNavigationId;
141 scopes::QueryCtrlProxy controller = m_proxy->search(m_searchQuery.toStdString(), m_currentNavigationId.toStdString(), m_filterState, meta, listener);
142 m_searchController->setController(controller);
143 } catch (std::exception& e) {
144
145=== modified file 'src/Unity/scope.h'
146--- src/Unity/scope.h 2014-10-15 09:59:13 +0000
147+++ src/Unity/scope.h 2014-12-04 14:53:30 +0000
148@@ -178,7 +178,7 @@
149
150 private Q_SLOTS:
151 void typingFinished();
152- void flushUpdates();
153+ void flushUpdates(bool finalize = false);
154 void metadataRefreshed();
155 void internetFlagChanged(QString const& key);
156 void departmentModelDestroyed(QObject* obj);

Subscribers

People subscribed via source and target branches

to all changes: