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

Proposed by Michal Hruby
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen
Approved revision: 215
Merged at revision: 216
Proposed branch: lp:~mhr3/unity-lens-files/fix-921665
Merge into: lp:unity-lens-files
Diff against target: 184 lines (+57/-26)
2 files modified
src/daemon.vala (+56/-25)
src/folder.vala (+1/-1)
To merge this branch: bzr merge lp:~mhr3/unity-lens-files/fix-921665
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+95865@code.launchpad.net

Description of the change

Fix activation of bookmark URIs. Standard URIs now also fall through so unity will activate them (that way they're launched using proper AppLaunchContext).

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

Make sure folders are not duplicated

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

did know you could do 'if (flag in flags)' in Vala. That is crazy cool :-)

7 Unity.FilesLens.append_events_sorted (results, results_model,
8 - 0, int64.MAX, false,
9 - category_id);
10 + 0, int64.MAX, 0,
11 + null, category_id);

Can you use ResultFlags.NONE instead of 0 to improve legibility here?

80 + private const string ATTR_TYPE_AND_HIDDEN = FILE_ATTRIBUTE_STANDARD_TYPE +
81 + "," + FILE_ATTRIBUTE_STANDARD_IS_HIDDEN;
82 + private const string ATTR_SIZE_AND_HIDDEN = FILE_ATTRIBUTE_STANDARD_TYPE +
83 + "," + FILE_ATTRIBUTE_STANDARD_SIZE +
84 + "," + FILE_ATTRIBUTE_STANDARD_IS_HIDDEN;

I think you should change the name of ATTR_SIZE_AND_HIDDEN since it's slightly misleading (excluding the TYPE). Maybe just ATTR_TYPE_HIDDEN and ATTR_TYPE_HIDDEN_SIZE?

Otherwise looking great!

review: Needs Fixing
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

s/did know/did not know/

lp:~mhr3/unity-lens-files/fix-921665 updated
215. By Michal Hruby

Improve readability

Revision history for this message
Michal Hruby (mhr3) wrote :

And pushed!

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

And liking!

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-02 11:15:51 +0000
3+++ src/daemon.vala 2012-03-12 10:07:24 +0000
4@@ -404,8 +404,8 @@
5 Categories.FILES_AND_FOLDERS : Categories.RECENT_FILES;
6
7 Unity.FilesLens.append_events_sorted (results, results_model,
8- 0, int64.MAX, false,
9- category_id);
10+ 0, int64.MAX, ResultFlags.NONE,
11+ null, category_id);
12
13 /* Add downloads catagory if we don't have a search */
14 if (has_search == false)
15@@ -477,7 +477,7 @@
16 {
17 Unity.FilesLens.append_events_sorted (results, txn,
18 min_size, max_size,
19- false);
20+ ResultFlags.SKIP_FOLDERS);
21 }
22
23 /* get recently downloaded files */
24@@ -511,14 +511,26 @@
25 if (!txn.is_committed ()) txn.commit ();
26
27 /* add bookmarks first */
28- append_bookmarks (has_search ?
29- bookmarks.prefix_search (search.search_string) : bookmarks.list (),
30- results_model,
31- Categories.FOLDERS);
32+ GLib.List<Bookmark> matching_bookmarks;
33+ if (has_search)
34+ matching_bookmarks = bookmarks.prefix_search (search.search_string);
35+ else
36+ matching_bookmarks = bookmarks.list ();
37+ append_bookmarks (matching_bookmarks, results_model,
38+ Categories.FOLDERS);
39+
40+ /* make sure we don't duplicate the bookmark uris */
41+ var bookmark_uris = new Gee.HashSet<string> ();
42+ foreach (var bookmark_obj in matching_bookmarks)
43+ {
44+ /* uri has bookmark: scheme */
45+ bookmark_uris.add (bookmark_obj.dnd_uri);
46+ }
47
48 Unity.FilesLens.append_events_sorted (results, results_model,
49 min_size, max_size,
50- true);
51+ ResultFlags.USE_ORIGIN,
52+ bookmark_uris);
53 }
54 else
55 {
56@@ -846,13 +858,12 @@
57 {
58 debug (@"Activating: $uri");
59 try {
60- if (!bookmarks.launch_if_bookmark (uri))
61- AppInfo.launch_default_for_uri (uri, null);
62- return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);
63+ if (bookmarks.launch_if_bookmark (uri))
64+ return new Unity.ActivationResponse (Unity.HandledType.HIDE_DASH);
65 } catch (GLib.Error error) {
66 warning ("Failed to launch URI %s", uri);
67- return new Unity.ActivationResponse(Unity.HandledType.NOT_HANDLED);
68 }
69+ return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED);
70 }
71
72 private void on_zeitgeist_changed ()
73@@ -863,16 +874,27 @@
74 }
75 }
76
77- private const string ATTR_HIDDEN = FILE_ATTRIBUTE_STANDARD_IS_HIDDEN;
78- private const string ATTR_SIZE_AND_HIDDEN = FILE_ATTRIBUTE_STANDARD_SIZE +
79- "," + FILE_ATTRIBUTE_STANDARD_IS_HIDDEN;
80+ private const string ATTRS_TYPE_HIDDEN = FILE_ATTRIBUTE_STANDARD_TYPE +
81+ "," + FILE_ATTRIBUTE_STANDARD_IS_HIDDEN;
82+ private const string ATTRS_TYPE_SIZE_HIDDEN = FILE_ATTRIBUTE_STANDARD_TYPE +
83+ "," + FILE_ATTRIBUTE_STANDARD_SIZE +
84+ "," + FILE_ATTRIBUTE_STANDARD_IS_HIDDEN;
85+
86+ [Flags]
87+ public enum ResultFlags
88+ {
89+ NONE = 0,
90+ USE_ORIGIN,
91+ SKIP_FOLDERS,
92+ }
93
94 /* Appends a set of Zeitgeist.Events to our Dee.Model assuming that
95 * these events are already sorted with descending timestamps */
96 public void append_events_sorted (Zeitgeist.ResultSet events,
97 Dee.Model results,
98 int64 min_size, int64 max_size,
99- bool use_origin,
100+ ResultFlags flags,
101+ Gee.Set<string>? excluded_uris = null,
102 int category_override = -1)
103 {
104 foreach (var ev in events)
105@@ -886,7 +908,7 @@
106 string display_name;
107 string mimetype;
108
109- if (use_origin)
110+ if (ResultFlags.USE_ORIGIN in flags)
111 {
112 uri = su.get_origin ();
113 display_name = "";
114@@ -902,6 +924,7 @@
115 }
116 if (uri == null) continue;
117 File file = File.new_for_uri (uri);
118+ if (excluded_uris != null && file.get_uri () in excluded_uris) continue;
119
120 if (display_name == null || display_name == "")
121 {
122@@ -911,11 +934,14 @@
123 bool check_size = min_size > 0 || max_size < int64.MAX;
124 /* Don't check existence on non-native files as http:// and
125 * friends are *very* expensive to query */
126- if (file.is_native()) {
127+ FileType file_type = FileType.UNKNOWN;
128+ if (file.is_native ())
129+ {
130 // hidden files should be ignored
131- try {
132+ try
133+ {
134 FileInfo info = file.query_info (check_size ?
135- ATTR_SIZE_AND_HIDDEN : ATTR_HIDDEN, 0, null);
136+ ATTRS_TYPE_SIZE_HIDDEN : ATTRS_TYPE_HIDDEN, 0, null);
137 if (info.get_is_hidden())
138 continue;
139 if (check_size &&
140@@ -923,7 +949,10 @@
141 {
142 continue;
143 }
144- } catch (GLib.Error e) {
145+ file_type = info.get_file_type ();
146+ }
147+ catch (GLib.Error e)
148+ {
149 // as error occurred file must be missing therefore ignoring it
150 continue;
151 }
152@@ -932,13 +961,15 @@
153
154 uint category_id;
155 string comment = file.get_parse_name ();
156-
157+
158+ var is_dir = file_type == FileType.DIRECTORY;
159+ if (is_dir && ResultFlags.SKIP_FOLDERS in flags) continue;
160+
161 if (category_override >= 0)
162 category_id = category_override;
163 else
164- category_id = file.query_file_type (0, null) == FileType.DIRECTORY ?
165- Categories.FOLDERS : Categories.RECENT;
166-
167+ category_id = is_dir ? Categories.FOLDERS : Categories.RECENT;
168+
169 results.append (uri, icon, category_id, mimetype,
170 display_name, comment);
171
172
173=== modified file 'src/folder.vala'
174--- src/folder.vala 2011-09-29 12:06:45 +0000
175+++ src/folder.vala 2012-03-12 10:07:24 +0000
176@@ -187,7 +187,7 @@
177 var uris = new List<string> ();
178 uris.append (uri);
179
180- launcher.launch_uris (uris, new AppLaunchContext());
181+ launcher.launch_uris (uris, null);
182
183 return true;
184 }

Subscribers

People subscribed via source and target branches