Merge lp:~kamstrup/unity-lens-files/home-lenses into lp:unity-lens-files

Proposed by Mikkel Kamstrup Erlandsen
Status: Merged
Approved by: Michal Hruby
Approved revision: 209
Merged at revision: 206
Proposed branch: lp:~kamstrup/unity-lens-files/home-lenses
Merge into: lp:unity-lens-files
Diff against target: 200 lines (+90/-14)
2 files modified
src/daemon.vala (+86/-13)
src/schemas.vala (+4/-1)
To merge this branch: bzr merge lp:~kamstrup/unity-lens-files/home-lenses
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+89671@code.launchpad.net

Description of the change

Implement the new home screen policy. That is; when we don't have a global search show the Recent Files and Downloads categories (in that order), and when we do have a global search show only a Files and Folders category. See also https://code.launchpad.net/~kamstrup/unity/home-lenses/+merge/89669

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

Looks fine.

review: Approve
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity-lens-files/7/console reported an error when processing this lp:~kamstrup/unity-lens-files/home-lenses branch.
Not merging it.

Michal Hruby (mhr3) wrote :

Don't be lazy bot!

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-01-16 18:09:28 +0000
3+++ src/daemon.vala 2012-01-23 12:01:17 +0000
4@@ -185,6 +185,10 @@
5 var cat = new Unity.Category (_("Recent"),
6 new FileIcon (icon_dir.get_child ("group-recent.svg")));
7 categories.append (cat);
8+
9+ cat = new Unity.Category (_("Recent Files"),
10+ new FileIcon (icon_dir.get_child ("group-recent.svg")));
11+ categories.append (cat);
12
13 cat = new Unity.Category (_("Downloads"),
14 new FileIcon (icon_dir.get_child ("group-downloads.svg")));
15@@ -194,6 +198,10 @@
16 new FileIcon (icon_dir.get_child ("group-folders.svg")));
17 categories.append (cat);
18
19+ cat = new Unity.Category (_("Files & Folders"),
20+ new FileIcon (icon_dir.get_child ("group-folders.svg")));
21+ categories.append (cat);
22+
23 lens.categories = categories;
24 }
25
26@@ -314,13 +322,18 @@
27 private async void update_global_search_async (LensSearch search,
28 Cancellable cancellable)
29 {
30- var results_model = search.results_model;
31-
32 if (search_is_invalid (search))
33 {
34- results_model.clear ();
35+ yield update_global_without_search_async (search, cancellable);
36 return;
37 }
38+
39+ /*
40+ * For global searches we collate all results under one category heading
41+ * called Files & Folders
42+ */
43+
44+ var results_model = search.results_model;
45
46 var search_string = prepare_search_string (search);
47
48@@ -349,18 +362,26 @@
49 var checked_url = urls.check_url (search.search_string);
50 if (checked_url != null)
51 {
52- results_model.append (checked_url, urls.icon, Categories.RECENT,
53+ results_model.append (checked_url, urls.icon,
54+ Categories.FILES_AND_FOLDERS,
55 "text/html", search.search_string,
56 checked_url, checked_url);
57 }
58- var bookmark_matches = bookmarks.prefix_search (search.search_string);
59- append_bookmarks (bookmark_matches, results_model, Categories.FOLDERS);
60
61 int64 min_size, max_size;
62 get_current_size_limits (out min_size, out max_size);
63
64 Unity.FilesLens.append_events_sorted (results, results_model,
65- min_size, max_size, false);
66+ min_size, max_size, false,
67+ Categories.FILES_AND_FOLDERS);
68+
69+ /* Add downloads catagory if we don't have a search */
70+ if (search_is_invalid (search))
71+ {
72+ yield update_downloads_async (results_model, cancellable,
73+ search.search_string,
74+ Categories.FILES_AND_FOLDERS);
75+ }
76
77 } catch (IOError.CANCELLED ioe) {
78 return;
79@@ -589,6 +610,46 @@
80 e.message);
81 }
82 }
83+
84+ private async void update_global_without_search_async (LensSearch search,
85+ Cancellable cancellable)
86+ {
87+ var results_model = search.results_model;
88+
89+ /* Grab the pre-compiled template we're going to use */
90+ var templates = new PtrArray.sized(1);
91+ templates.add (type_templates.lookup ("all"));
92+
93+ try {
94+ /* Get results ranked by recency */
95+ var timer = new Timer ();
96+ var results = yield log.find_events (new Zeitgeist.TimeRange.anytime(),
97+ templates,
98+ Zeitgeist.StorageState.ANY,
99+ 20,
100+ ResultType.MOST_RECENT_SUBJECTS,
101+ cancellable);
102+
103+ timer.stop ();
104+ debug ("Found %u/%u global results in %fms",
105+ results.size (), results.estimated_matches (),
106+ timer.elapsed()*1000);
107+
108+ results_model.clear ();
109+
110+ Unity.FilesLens.append_events_sorted (results, results_model,
111+ int64.MIN, int64.MAX,
112+ false, Categories.RECENT_FILES);
113+
114+ yield update_downloads_async (results_model, cancellable);
115+
116+ } catch (IOError.CANCELLED ioe) {
117+ return;
118+ } catch (GLib.Error e) {
119+ warning ("Error performing empty search: %s",
120+ e.message);
121+ }
122+ }
123
124 private void append_bookmarks (GLib.List<Bookmark> bookmarks,
125 Dee.Model results_model,
126@@ -603,7 +664,9 @@
127 }
128
129 private async void update_downloads_async (Dee.Model results_model,
130- Cancellable cancellable, string? name_filter = null) throws IOError
131+ Cancellable cancellable,
132+ string? name_filter = null,
133+ int category_override = -1) throws IOError
134 {
135 // FIXME: Store the Downloads folder and update on changes
136 unowned string download_path =
137@@ -612,7 +675,7 @@
138 SList<FileInfo> downloads;
139
140 try {
141- if (name_filter != null)
142+ if (name_filter != null && name_filter != "")
143 downloads = yield Utils.list_dir_filtered (download_dir, name_filter);
144 else
145 downloads = yield Utils.list_dir (download_dir);
146@@ -654,7 +717,12 @@
147 int64 size = info.get_size ();
148 if (size < min_size || size > max_size)
149 continue;
150-
151+
152+ uint category_id = Categories.DOWNLOADS;
153+
154+ if (category_override >= 0)
155+ category_id = category_override;
156+
157 results_model.append (uri, icon_hint, Categories.DOWNLOADS,
158 mimetype, info.get_display_name (), uri);
159 }
160@@ -691,7 +759,8 @@
161 public void append_events_sorted (Zeitgeist.ResultSet events,
162 Dee.Model results,
163 int64 min_size, int64 max_size,
164- bool use_origin)
165+ bool use_origin,
166+ int category_override = -1)
167 {
168 foreach (var ev in events)
169 {
170@@ -751,8 +820,12 @@
171 uint category_id;
172 string comment = file.get_parse_name ();
173
174- category_id = file.query_file_type (0, null) == FileType.DIRECTORY ?
175- Categories.FOLDERS : Categories.RECENT;
176+ if (category_override >= 0)
177+ category_id = category_override;
178+ else
179+ category_id = file.query_file_type (0, null) == FileType.DIRECTORY ?
180+ Categories.FOLDERS : Categories.RECENT;
181+
182 results.append (uri, icon, category_id, mimetype,
183 display_name, comment);
184
185
186=== modified file 'src/schemas.vala'
187--- src/schemas.vala 2011-08-04 15:26:32 +0000
188+++ src/schemas.vala 2012-01-23 12:01:17 +0000
189@@ -39,7 +39,10 @@
190 public enum Categories
191 {
192 RECENT,
193+ RECENT_FILES,
194 DOWNLOADS,
195- FOLDERS
196+ FOLDERS,
197+ FILES_AND_FOLDERS,
198+
199 }
200 }

Subscribers

People subscribed via source and target branches

to all changes: