Merge lp:~mhr3/unity-lens-files/fix-749566 into lp:unity-lens-files

Proposed by Michal Hruby
Status: Merged
Approved by: Gord Allott
Approved revision: 226
Merged at revision: 225
Proposed branch: lp:~mhr3/unity-lens-files/fix-749566
Merge into: lp:unity-lens-files
Diff against target: 216 lines (+115/-15)
2 files modified
src/daemon.vala (+105/-15)
tests/manual/folders.txt (+10/-0)
To merge this branch: bzr merge lp:~mhr3/unity-lens-files/fix-749566
Reviewer Review Type Date Requested Status
Gord Allott (community) Approve
Review via email: mp+100655@code.launchpad.net

Commit message

Add also directory results to non-empty global searches

Description of the change

Searches in home lens do not include folders.

Extract folders for the uris we find and add them to the results (add to the beginning if they prefix match, to the end otherwise).

Added a manual test.

To post a comment you must log in.
lp:~mhr3/unity-lens-files/fix-749566 updated
226. By Michal Hruby

Add a manual test

Revision history for this message
Gord Allott (gordallott) wrote :

Seems good, +1

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-20 10:33:37 +0000
3+++ src/daemon.vala 2012-04-04 10:14:28 +0000
4@@ -428,9 +428,28 @@
5 var category_id = has_search ?
6 Categories.FILES_AND_FOLDERS : Categories.RECENT_FILES;
7
8- Unity.FilesLens.append_events_sorted (results, results_model,
9- 0, int64.MAX, ResultFlags.NONE,
10- null, category_id);
11+ Set<string>? bookmark_uris = null;
12+ if (has_search)
13+ {
14+ /* add bookmarks first */
15+ GLib.List<Bookmark> matching_bookmarks;
16+ matching_bookmarks = bookmarks.prefix_search (search.search_string);
17+ append_bookmarks (matching_bookmarks, results_model, category_id);
18+
19+ /* make sure we don't duplicate the bookmark uris */
20+ bookmark_uris = new Gee.HashSet<string> ();
21+ foreach (var bookmark_obj in matching_bookmarks)
22+ {
23+ /* uri has bookmark: scheme */
24+ bookmark_uris.add (bookmark_obj.dnd_uri);
25+ }
26+ }
27+
28+ var result_flags = has_search ? ResultFlags.EXTRACT_ORIGINS : 0;
29+ Unity.FilesLens.append_events_sorted (search.search_string,
30+ results, results_model,
31+ 0, int64.MAX, result_flags,
32+ bookmark_uris, category_id);
33
34 /* Add downloads catagory if we don't have a search */
35 if (has_search == false)
36@@ -443,7 +462,8 @@
37 cancellable,
38 true);
39
40- Unity.FilesLens.append_events_sorted (results, results_model,
41+ Unity.FilesLens.append_events_sorted (search.search_string,
42+ results, results_model,
43 0, int64.MAX, ResultFlags.NONE,
44 null, Categories.DOWNLOADS);
45 }
46@@ -512,7 +532,8 @@
47
48 if (results != null)
49 {
50- Unity.FilesLens.append_events_sorted (results, txn,
51+ Unity.FilesLens.append_events_sorted (search.search_string,
52+ results, txn,
53 min_size, max_size,
54 ResultFlags.SKIP_FOLDERS);
55 }
56@@ -526,7 +547,8 @@
57 cancellable,
58 true);
59
60- Unity.FilesLens.append_events_sorted (results, txn,
61+ Unity.FilesLens.append_events_sorted (search.search_string,
62+ results, txn,
63 min_size, max_size,
64 ResultFlags.NONE,
65 null, Categories.DOWNLOADS);
66@@ -574,7 +596,8 @@
67 bookmark_uris.add (bookmark_obj.dnd_uri);
68 }
69
70- Unity.FilesLens.append_events_sorted (results, results_model,
71+ Unity.FilesLens.append_events_sorted (search.search_string,
72+ results, results_model,
73 min_size, max_size,
74 ResultFlags.USE_ORIGIN,
75 bookmark_uris);
76@@ -879,12 +902,14 @@
77 {
78 NONE = 0,
79 USE_ORIGIN,
80+ EXTRACT_ORIGINS,
81 SKIP_FOLDERS,
82 }
83
84 /* Appends a set of Zeitgeist.Events to our Dee.Model assuming that
85 * these events are already sorted with descending timestamps */
86- public void append_events_sorted (Zeitgeist.ResultSet? events,
87+ public void append_events_sorted (string search_string,
88+ Zeitgeist.ResultSet? events,
89 Dee.Model results,
90 int64 min_size, int64 max_size,
91 ResultFlags flags,
92@@ -892,12 +917,62 @@
93 int category_override = -1)
94 {
95 if (events == null) return;
96+ uint category_id;
97+ Set<string>? extracted_directories = null;
98+
99+ if (ResultFlags.EXTRACT_ORIGINS in flags)
100+ {
101+ var folded_search = search_string.casefold ();
102+ var origins = new HashSet<string> ();
103+ // loop through all found events, take a look at origin field, add it
104+ // to result set if it matches our search
105+ // NOTE: using separate zg query with MOST_RECENT_ORIGINS grouping
106+ // is more likely to find relevant directories, but is much slower
107+ // than this kind of "approximation"
108+ foreach (var ev in events)
109+ {
110+ if (ev.num_subjects () > 0)
111+ {
112+ string origin = ev.get_subject (0).get_origin ();
113+ if (origin == null || origin == "") continue;
114+ var f = File.new_for_uri (origin);
115+ origin = f.get_uri ();
116+ if (excluded_uris != null && origin in excluded_uris) continue;
117+ if (!(origin in origins) && f.is_native () && f.query_exists ())
118+ {
119+ var display_name = Path.get_basename (f.get_parse_name ());
120+ if (display_name.casefold ().has_prefix (folded_search))
121+ {
122+ string mimetype = "inode/directory";
123+ string icon = Utils.get_icon_for_uri (origin, mimetype);
124+ if (category_override >= 0)
125+ category_id = category_override;
126+ else
127+ category_id = Categories.FOLDERS;
128+ results.append (origin, icon, category_id, mimetype,
129+ display_name, "", origin);
130+ }
131+ else
132+ {
133+ if (extracted_directories == null)
134+ {
135+ extracted_directories = new HashSet<string> ();
136+ }
137+ extracted_directories.add (origin);
138+ }
139+ origins.add (origin);
140+ }
141+ }
142+ }
143+ // we need this because of way ResultSet works with foreach
144+ if (events.size () > 0) events.seek (0);
145+ }
146 foreach (var ev in events)
147 {
148- if (ev.num_subjects() > 0)
149+ if (ev.num_subjects () > 0)
150 {
151 // FIXME: We only use the first subject...
152- Zeitgeist.Subject su = ev.get_subject(0);
153+ Zeitgeist.Subject su = ev.get_subject (0);
154
155 string uri;
156 string display_name;
157@@ -946,15 +1021,13 @@
158 }
159 file_type = info.get_file_type ();
160 }
161- catch (GLib.Error e)
162+ catch (GLib.Error e)
163 {
164 // as error occurred file must be missing therefore ignoring it
165 continue;
166 }
167 }
168 string icon = Utils.get_icon_for_uri (uri, mimetype);
169-
170- uint category_id;
171 string comment = file.get_parse_name ();
172
173 var is_dir = file_type == FileType.DIRECTORY;
174@@ -966,8 +1039,25 @@
175 category_id = is_dir ? Categories.FOLDERS : Categories.RECENT;
176
177 results.append (uri, icon, category_id, mimetype,
178- display_name, comment);
179-
180+ display_name, comment, uri);
181+
182+ }
183+ }
184+
185+ if (extracted_directories != null)
186+ {
187+ foreach (var dir_uri in extracted_directories)
188+ {
189+ var f = File.new_for_uri (dir_uri);
190+ var display_name = Path.get_basename (f.get_parse_name ());
191+ string mimetype = "inode/directory";
192+ string icon = Utils.get_icon_for_uri (dir_uri, mimetype);
193+ if (category_override >= 0)
194+ category_id = category_override;
195+ else
196+ category_id = Categories.FOLDERS;
197+ results.append (dir_uri, icon, category_id, mimetype,
198+ display_name, "", dir_uri);
199 }
200 }
201 }
202
203=== added file 'tests/manual/folders.txt'
204--- tests/manual/folders.txt 1970-01-01 00:00:00 +0000
205+++ tests/manual/folders.txt 2012-04-04 10:14:28 +0000
206@@ -0,0 +1,10 @@
207+Folders
208+=======
209+Tests that global searches find folders as well as files.
210+
211+#. Open the Dash.
212+#. Perform a generic search in the home view. (for example 'd')
213+
214+Outcome
215+ You should see "Files and Folders" category with both folders starting with 'd', followed by files containing 'd' or residing in a folder with 'd' in name.
216+

Subscribers

People subscribed via source and target branches