Merge lp:~mhr3/unity/fix-965492 into lp:unity

Proposed by Michal Hruby
Status: Merged
Approved by: Gord Allott
Approved revision: no longer in the source branch.
Merged at revision: 2219
Proposed branch: lp:~mhr3/unity/fix-965492
Merge into: lp:unity
Diff against target: 182 lines (+52/-7)
5 files modified
plugins/unityshell/src/DashView.cpp (+8/-1)
plugins/unityshell/src/LensView.cpp (+14/-5)
plugins/unityshell/src/LensView.h (+5/-1)
plugins/unityshell/src/SearchBar.cpp (+24/-0)
plugins/unityshell/src/SearchBar.h (+1/-0)
To merge this branch: bzr merge lp:~mhr3/unity/fix-965492
Reviewer Review Type Date Requested Status
Gord Allott (community) Approve
Review via email: mp+100809@code.launchpad.net

Commit message

Ensure that the spinner is shown even for empty searches

Description of the change

The initial display of the home lens can take some time and during this time the user has no feedback that there's something going on inside the dash.

Whenever we display the dash, the Search() method of lenses is called, so we're properly notified when the search finishes (libunity makes sure of that). This allows us to display the spinner meanwhile, and user knows there's some activity going on.

Because of the timing nature of the change, there are no new tests, but at least existing tests still pass.

To post a comment you must log in.
Revision history for this message
Gord Allott (gordallott) wrote :

+1 from me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/DashView.cpp'
2--- plugins/unityshell/src/DashView.cpp 2012-03-30 11:40:10 +0000
3+++ plugins/unityshell/src/DashView.cpp 2012-04-04 15:50:26 +0000
4@@ -146,6 +146,9 @@
5 active_lens_view_->lens()->view_type = ViewType::LENS_VIEW;
6 }
7
8+ // this will make sure the spinner animates if the search takes a while
9+ search_bar_->ForceSearchChanged();
10+
11 renderer_.AboutToShow();
12 }
13
14@@ -438,7 +441,7 @@
15 LOG_DEBUG(logger) << "Live search reached: " << search_string;
16 if (active_lens_view_)
17 {
18- active_lens_view_->search_string = search_string;
19+ active_lens_view_->PerformSearch(search_string);
20 }
21 }
22
23@@ -491,6 +494,10 @@
24
25 search_bar_->search_string = view->search_string;
26 search_bar_->search_hint = view->lens()->search_hint;
27+ // lenses typically return immediately from Search() if the search query
28+ // doesn't change, so SearchFinished will be called in a few ms
29+ // FIXME: if we're forcing a search here, why don't we get rid of view types?
30+ search_bar_->ForceSearchChanged();
31
32 bool expanded = view->filters_expanded;
33 search_bar_->showing_filters = expanded;
34
35=== modified file 'plugins/unityshell/src/LensView.cpp'
36--- plugins/unityshell/src/LensView.cpp 2012-04-02 12:28:41 +0000
37+++ plugins/unityshell/src/LensView.cpp 2012-04-04 15:50:26 +0000
38@@ -117,7 +117,6 @@
39
40 LensView::LensView()
41 : nux::View(NUX_TRACKER_LOCATION)
42- , search_string("")
43 , filters_expanded(false)
44 , can_refine_search(false)
45 , no_results_active_(false)
46@@ -126,7 +125,6 @@
47
48 LensView::LensView(Lens::Ptr lens, nux::Area* show_filters)
49 : nux::View(NUX_TRACKER_LOCATION)
50- , search_string("")
51 , filters_expanded(false)
52 , can_refine_search(false)
53 , lens_(lens)
54@@ -142,7 +140,7 @@
55 dash::Style::Instance().columns_changed.connect(sigc::mem_fun(this, &LensView::OnColumnsChanged));
56
57 lens_->connected.changed.connect([&](bool is_connected) { if (is_connected) initial_activation_ = true; });
58- search_string.changed.connect([&](std::string const& search) { lens_->Search(search); });
59+ search_string.SetGetterFunction(sigc::mem_fun(this, &LensView::get_search_string));
60 filters_expanded.changed.connect([&](bool expanded) { fscroll_view_->SetVisible(expanded); QueueRelayout(); OnColumnsChanged(); });
61 view_type.changed.connect(sigc::mem_fun(this, &LensView::OnViewTypeChanged));
62
63@@ -386,7 +384,7 @@
64 {
65 gint count = lens_->results()->count();
66
67- if (!count && !no_results_active_)
68+ if (count == 0 && !no_results_active_ && !search_string_.empty())
69 {
70 std::stringstream markup;
71 Lens::Hints::const_iterator it;
72@@ -433,6 +431,17 @@
73 }
74 }
75
76+void LensView::PerformSearch(std::string const& search_query)
77+{
78+ search_string_ = search_query;
79+ lens_->Search(search_query);
80+}
81+
82+std::string LensView::get_search_string() const
83+{
84+ return search_string_;
85+}
86+
87 void LensView::OnGroupExpanded(PlacesGroup* group)
88 {
89 ResultViewGrid* grid = static_cast<ResultViewGrid*>(group->GetChildView());
90@@ -467,7 +476,7 @@
91 if (view_type != HIDDEN && initial_activation_)
92 {
93 /* We reset the lens for ourselves, in case this is a restart or something */
94- lens_->Search(search_string);
95+ lens_->Search(search_string_);
96 initial_activation_ = false;
97 }
98
99
100=== modified file 'plugins/unityshell/src/LensView.h'
101--- plugins/unityshell/src/LensView.h 2012-03-21 14:18:06 +0000
102+++ plugins/unityshell/src/LensView.h 2012-04-04 15:50:26 +0000
103@@ -63,13 +63,14 @@
104
105 virtual void ActivateFirst();
106
107- nux::Property<std::string> search_string;
108+ nux::ROProperty<std::string> search_string;
109 nux::Property<bool> filters_expanded;
110 nux::Property<ViewType> view_type;
111 nux::Property<bool> can_refine_search;
112
113 sigc::signal<void, std::string const&> uri_activated;
114
115+ void PerformSearch(std::string const& search_query);
116 void CheckNoResults(Lens::Hints const& hints);
117 void HideResultsMessage();
118
119@@ -99,6 +100,8 @@
120 virtual std::string GetName() const;
121 virtual void AddProperties(GVariantBuilder* builder);
122
123+ std::string get_search_string() const;
124+
125 private:
126 UBusManager ubus_manager_;
127 Lens::Ptr lens_;
128@@ -106,6 +109,7 @@
129 ResultCounts counts_;
130 bool initial_activation_;
131 bool no_results_active_;
132+ std::string search_string_;
133
134 nux::HLayout* layout_;
135 LensScrollView* scroll_view_;
136
137=== modified file 'plugins/unityshell/src/SearchBar.cpp'
138--- plugins/unityshell/src/SearchBar.cpp 2012-03-27 15:20:51 +0000
139+++ plugins/unityshell/src/SearchBar.cpp 2012-04-04 15:50:26 +0000
140@@ -473,6 +473,30 @@
141 activated.emit();
142 }
143
144+void SearchBar::ForceSearchChanged()
145+{
146+ // this method will emit search_changed (and live_search_reached after
147+ // returning to mainloop) and starts animating the spinner
148+
149+ if (live_search_timeout_)
150+ g_source_remove(live_search_timeout_);
151+
152+ live_search_timeout_ = g_idle_add_full(G_PRIORITY_DEFAULT,
153+ (GSourceFunc)&OnLiveSearchTimeout,
154+ this, NULL);
155+
156+ // Don't animate the spinner immediately, the searches are fast and
157+ // the spinner would just flicker
158+ if (start_spinner_timeout_)
159+ g_source_remove(start_spinner_timeout_);
160+
161+ start_spinner_timeout_ = g_timeout_add(SPINNER_TIMEOUT * 2,
162+ (GSourceFunc)&OnSpinnerStartCb,
163+ this);
164+
165+ search_changed.emit(pango_entry_->GetText());
166+}
167+
168 void
169 SearchBar::SearchFinished()
170 {
171
172=== modified file 'plugins/unityshell/src/SearchBar.h'
173--- plugins/unityshell/src/SearchBar.h 2012-03-27 15:09:26 +0000
174+++ plugins/unityshell/src/SearchBar.h 2012-04-04 15:50:26 +0000
175@@ -60,6 +60,7 @@
176 SearchBar(bool show_filter_hint, NUX_FILE_LINE_PROTO);
177 ~SearchBar();
178
179+ void ForceSearchChanged();
180 void SearchFinished();
181 nux::TextEntry* text_entry() const;
182 nux::View* show_filters() const;