Merge lp:~mhr3/unity-lens-applications/no-recent-apps-search-just-filtering into lp:unity-lens-applications

Proposed by Michal Hruby on 2012-03-12
Status: Merged
Approved by: Neil J. Patel on 2012-03-15
Approved revision: 278
Merged at revision: 277
Proposed branch: lp:~mhr3/unity-lens-applications/no-recent-apps-search-just-filtering
Merge into: lp:unity-lens-applications
Diff against target: 250 lines (+106/-74)
2 files modified
src/daemon.vala (+100/-74)
tests/test-6-recent-results.sh (+6/-0)
To merge this branch: bzr merge lp:~mhr3/unity-lens-applications/no-recent-apps-search-just-filtering
Reviewer Review Type Date Requested Status
Neil J. Patel (community) 2012-03-12 Approve on 2012-03-15
Review via email: mp+97087@code.launchpad.net

Commit Message

Don't search in recent apps, just filter them when searching.

Description of the Change

According to design, the Recent Apps category is not supposed to do any search, it's a given set of 6 applications you used recently and searching can only filter any of these applications away.

To post a comment you must log in.
Michal Hruby (mhr3) wrote :

Sorry for the bigger diff - the change actually isn't as big, there's some whitespace changes plus a bit of moving code around.

278. By Michal Hruby on 2012-03-15

Add semi-automatic test

Neil J. Patel (njpatel) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/daemon.vala'
2--- src/daemon.vala 2012-03-12 15:41:00 +0000
3+++ src/daemon.vala 2012-03-15 12:14:19 +0000
4@@ -384,10 +384,10 @@
5 scope.queue_search_changed (SearchType.GLOBAL);
6 }
7
8- private string prepare_zg_search_string (Unity.LensSearch search,
9+ private string prepare_zg_search_string (string search_string,
10 OptionsFilter? options)
11 {
12- string s = search.search_string.strip ();
13+ string s = search_string.strip ();
14
15 if (!s.has_suffix ("*") && s != "")
16 s = s + "*";
17@@ -455,8 +455,6 @@
18
19 Timer timer = new Timer ();
20
21- var zg_search_string = prepare_zg_search_string (search, filter);
22-
23 var transaction = new Dee.Transaction (model);
24 transaction.clear ();
25
26@@ -465,35 +463,6 @@
27 * the Installed category too soon and this will cause flicker
28 * in the Dash. (lp:868192) */
29
30- if (local_apps_active () && display_recent_apps) {
31- try {
32- var results = yield zg_index.search (zg_search_string,
33- new Zeitgeist.TimeRange.anytime(),
34- zg_templates,
35- 0,
36- 20,
37- Zeitgeist.ResultType.MOST_RECENT_SUBJECTS,
38- cancellable);
39-
40- append_events_with_category (results, transaction, Category.RECENT, has_search);
41-
42- timer.stop ();
43- debug ("Entry search found %u/%u Recently Used apps in %fms for query '%s'",
44- results.size (), results.estimated_matches (),
45- timer.elapsed()*1000, zg_search_string);
46-
47- } catch (IOError.CANCELLED ioe) {
48- // no need to bother
49- return;
50- } catch (GLib.Error e) {
51- warning ("Error performing search '%s': %s",
52- search.search_string, e.message);
53- }
54- }
55-
56- transaction.commit ();
57-
58- timer.start ();
59 Set<string> installed_uris = new HashSet<string> ();
60 Set<string> available_uris = new HashSet<string> ();
61 var appresults = appsearcher.search (pkg_search_string, 0,
62@@ -504,13 +473,50 @@
63 if (local_apps_active ())
64 {
65 add_pkg_search_result (appresults, installed_uris, available_uris,
66- model, Category.INSTALLED);
67+ transaction, Category.INSTALLED);
68 }
69
70 timer.stop ();
71 debug ("Entry search listed %i Installed apps in %fms for query: %s",
72 appresults.num_hits, timer.elapsed ()*1000, pkg_search_string);
73
74+ if (local_apps_active () && display_recent_apps)
75+ {
76+ try
77+ {
78+ timer.start ();
79+ /* Ignore the search string, we want to keep displaying the same apps
80+ * in the recent category and just filter out those that don't match
81+ * the search query */
82+ var zg_search_string = prepare_zg_search_string ("", filter);
83+
84+ var results = yield zg_index.search (zg_search_string,
85+ new Zeitgeist.TimeRange.anytime(),
86+ zg_templates,
87+ 0,
88+ 20,
89+ Zeitgeist.ResultType.MOST_RECENT_SUBJECTS,
90+ cancellable);
91+
92+ append_events_with_category (results, transaction, Category.RECENT,
93+ false, 6, installed_uris);
94+
95+ timer.stop ();
96+ debug ("Entry search found %u/%u Recently Used apps in %fms for query '%s'",
97+ results.size (), results.estimated_matches (),
98+ timer.elapsed()*1000, zg_search_string);
99+
100+ } catch (IOError.CANCELLED ioe) {
101+ // no need to bother
102+ return;
103+ } catch (GLib.Error e) {
104+ warning ("Error performing search '%s': %s",
105+ search.search_string, e.message);
106+ }
107+ }
108+
109+ transaction.commit ();
110+
111 /* If we don't have a search we display 6 random apps */
112 if (usc_apps_active () && display_available_apps && pkgsearcher != null)
113 {
114@@ -598,10 +604,13 @@
115
116 Timer timer = new Timer ();
117
118- var zg_search_string = prepare_zg_search_string (search, null);
119+ if (local_apps_active () && display_recent_apps)
120+ {
121+ try
122+ {
123+ var zg_search_string = prepare_zg_search_string (search.search_string,
124+ null);
125
126- if (local_apps_active () && display_recent_apps) {
127- try {
128 var results = yield zg_index.search (zg_search_string,
129 new Zeitgeist.TimeRange.anytime(),
130 zg_templates,
131@@ -611,7 +620,8 @@
132 cancellable);
133
134 model.clear ();
135- append_events_with_category (results, model, Category.RECENT_APPS, false);
136+ append_events_with_category (results, model, Category.RECENT_APPS,
137+ false);
138
139 timer.stop ();
140 debug ("Entry search found %u/%u Recently Used apps in %fms for query '%s'",
141@@ -997,46 +1007,62 @@
142 public void append_events_with_category (Zeitgeist.ResultSet events,
143 Dee.Model results,
144 uint category_id,
145- bool include_favorites)
146+ bool include_favorites,
147+ int max_results = int.MAX,
148+ Set<string>? allowed_uris = null)
149 {
150+ int num_results = 0;
151 foreach (var ev in events)
152+ {
153+ string? app_uri = null;
154+ if (ev.num_subjects () > 0)
155+ app_uri = ev.get_subject (0).get_uri ();
156+
157+ if (app_uri == null)
158 {
159- string app_uri;
160- if (ev.num_subjects () > 0)
161- app_uri = ev.get_subject (0).get_uri ();
162- else
163- {
164- warning ("Unexpected event without subject");
165- continue;
166- }
167-
168- /* Assert that we indeed have a known application as actor */
169- string desktop_id = Utils.get_desktop_id_for_actor (app_uri);
170-
171- /* Discard Recently Used apps that are in the launcher */
172- if ((category_id == Category.RECENT ||
173- category_id == Category.RECENT_APPS) &&
174- !include_favorites &&
175- (favorite_apps.has_app_id (desktop_id)
176- || app_watcher.has_app_id (desktop_id)))
177- continue;
178-
179- var appmanager = AppInfoManager.get_default ();
180- AppInfo? app = appmanager.lookup (desktop_id);
181-
182- if (app == null)
183- continue;
184-
185- if (!app.should_show ())
186- continue;
187-
188- string full_path = appmanager.get_path (desktop_id);
189- string full_uri = full_path != null ? "file://" + full_path : app_uri;
190-
191- results.append (app_uri, app.get_icon().to_string(), category_id,
192- "application/x-desktop", app.get_display_name (),
193- app.get_description (), full_uri);
194+ warning ("Unexpected event without subject");
195+ continue;
196 }
197+
198+ /* Assert that we indeed have a known application as actor */
199+ string desktop_id = Utils.get_desktop_id_for_actor (app_uri);
200+
201+ /* Discard Recently Used apps that are in the launcher */
202+ if ((category_id == Category.RECENT ||
203+ category_id == Category.RECENT_APPS) &&
204+ !include_favorites &&
205+ (favorite_apps.has_app_id (desktop_id)
206+ || app_watcher.has_app_id (desktop_id)))
207+ continue;
208+
209+ var appmanager = AppInfoManager.get_default ();
210+ AppInfo? app = appmanager.lookup (desktop_id);
211+
212+ if (app == null)
213+ continue;
214+
215+ if (!app.should_show ())
216+ continue;
217+
218+ /* HACK! when using the max_results together with allowed_uris,
219+ * the limit serves as a truncation point - therefore results which
220+ * are not displayed the first time won't be displayed later
221+ * (consider results A, B, C - all of them are allowed and we use
222+ * limit 2 - so only A and B is displayed, later we change allowed to
223+ * B and C, so normally we would display both B and C, but that's not
224+ * desired because C wasn't shown in the first place, so we display
225+ * only B) */
226+ if (num_results++ >= max_results) break;
227+
228+ if (allowed_uris != null && !(app_uri in allowed_uris)) continue;
229+
230+ string full_path = appmanager.get_path (desktop_id);
231+ string full_uri = full_path != null ? "file://" + full_path : app_uri;
232+
233+ results.append (app_uri, app.get_icon().to_string(), category_id,
234+ "application/x-desktop", app.get_display_name (),
235+ app.get_description (), full_uri);
236+ }
237 }
238
239 } /* END: class Daemon */
240
241=== added file 'tests/test-6-recent-results.sh'
242--- tests/test-6-recent-results.sh 1970-01-01 00:00:00 +0000
243+++ tests/test-6-recent-results.sh 2012-03-15 12:14:19 +0000
244@@ -0,0 +1,6 @@
245+#!/bin/sh
246+
247+# Do empty search, print the results, look at the number of items
248+# for the recent category, make sure there are max 6
249+test `unity-tool -n com.canonical.Unity.Lens.Applications -p /com/canonical/unity/lens/applications -s "" --no-search-reply -r | awk -F "\t" ' { print $3; } ' | grep 0 | wc -l` -le 6
250+

Subscribers

People subscribed via source and target branches