Merge lp:~angeloc/unity-lens-files/fix-for-948086 into lp:unity-lens-files

Proposed by Angelo Compagnucci
Status: Superseded
Proposed branch: lp:~angeloc/unity-lens-files/fix-for-948086
Merge into: lp:unity-lens-files
Diff against target: 226 lines (+98/-35)
3 files modified
src/daemon.vala (+33/-15)
src/folder.vala (+1/-1)
src/url-checker.vala (+64/-19)
To merge this branch: bzr merge lp:~angeloc/unity-lens-files/fix-for-948086
Reviewer Review Type Date Requested Status
Michal Hruby (community) Needs Resubmitting
Review via email: mp+96187@code.launchpad.net

This proposal has been superseded by a proposal from 2012-03-07.

Description of the change

More robust url validation.

To post a comment you must log in.
223. By Angelo Compagnucci

Fixing Regexp glitches.

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

Can you please set your branch which fixes the mountable uris as a prerequisite branch for this?

review: Needs Resubmitting
224. By Angelo Compagnucci

Splitting regex into const string
Use OPTIMIZE flag for regexp

225. By Angelo Compagnucci

Fixing codestyle.

Unmerged revisions

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-02-14 13:44:37 +0000
3+++ src/daemon.vala 2012-03-06 17:40:28 +0000
4@@ -14,6 +14,7 @@
5 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6 *
7 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
8+ * Modified by Angelo Compagnucci <angelo.compagnucci@gmail.com>
9 *
10 */
11 using Zeitgeist;
12@@ -33,6 +34,7 @@
13
14 private Bookmarks bookmarks;
15 private UrlChecker urls;
16+ private UrlType url_type;
17
18 private Unity.Lens lens;
19 private Unity.Scope scope;
20@@ -376,14 +378,16 @@
21
22 results_model.clear ();
23
24- /* check if the thing typed isn't a url (like facebook.com) */
25- var checked_url = urls.check_url (search.search_string);
26+ /* check if the thing typed isn't a url (like facebook.com)
27+ * or isn't a remote mountable url (like ftp://ftp.ubuntu.com)*/
28+ var url_type = UrlType.UNKNOWN;
29+ var checked_url = urls.check_url (search.search_string, out url_type);
30 if (checked_url != null)
31 {
32- results_model.append (checked_url, urls.icon,
33- Categories.FILES_AND_FOLDERS,
34- "text/html", search.search_string,
35- checked_url, checked_url);
36+ results_model.append (checked_url, urls.get_icon_for_type(url_type),
37+ Categories.FILES_AND_FOLDERS,
38+ "text/html", search.search_string,
39+ checked_url, checked_url);
40 }
41
42 var category_id = has_search ?
43@@ -438,13 +442,16 @@
44
45 txn.clear ();
46
47- /* check if the thing typed isn't a url (like facebook.com) */
48- var checked_url = urls.check_url (search.search_string);
49+ /* check if the thing typed isn't a url (like facebook.com)
50+ * or isn't a remote mountable url (like ftp://ftp.ubuntu.com)*/
51+ var url_type = UrlType.UNKNOWN;
52+ var checked_url = urls.check_url (search.search_string, out url_type);
53 if (checked_url != null)
54 {
55- txn.append (checked_url, urls.icon, Categories.RECENT,
56- "text/html", search.search_string,
57- checked_url, checked_url);
58+ txn.append (checked_url, urls.get_icon_for_type(url_type),
59+ Categories.RECENT,
60+ "text/html", search.search_string,
61+ checked_url, checked_url);
62 }
63
64 /* apply filters to results found by zeitgeist */
65@@ -757,13 +764,24 @@
66 {
67 debug (@"Activating: $uri");
68 try {
69- if (!bookmarks.launch_if_bookmark (uri))
70- AppInfo.launch_default_for_uri (uri, null);
71- return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);
72+ if (bookmarks.launch_if_bookmark (uri))
73+ return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);
74+
75+ /* this code ensures that a file manager will be used
76+ * * if uri it's a remote location that should be mounted */
77+ var url_type = UrlType.UNKNOWN;
78+ var checked_url = urls.check_url (uri, out url_type);
79+ if (checked_url != null && url_type == UrlType.MOUNTABLE) {
80+ var muris = new GLib.List<string>();
81+ muris.prepend (uri);
82+ var file_manager = AppInfo.get_default_for_type("inode/directory", true);
83+ file_manager.launch_uris(muris,null);
84+ return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);
85+ }
86 } catch (GLib.Error error) {
87 warning ("Failed to launch URI %s", uri);
88- return new Unity.ActivationResponse(Unity.HandledType.NOT_HANDLED);
89 }
90+ return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED);
91 }
92
93 private void on_zeitgeist_changed ()
94
95=== modified file 'src/folder.vala'
96--- src/folder.vala 2011-09-29 12:06:45 +0000
97+++ src/folder.vala 2012-03-06 17:40:28 +0000
98@@ -187,7 +187,7 @@
99 var uris = new List<string> ();
100 uris.append (uri);
101
102- launcher.launch_uris (uris, new AppLaunchContext());
103+ launcher.launch_uris (uris, null);
104
105 return true;
106 }
107
108=== modified file 'src/url-checker.vala'
109--- src/url-checker.vala 2012-01-30 11:26:40 +0000
110+++ src/url-checker.vala 2012-03-06 17:40:28 +0000
111@@ -14,51 +14,96 @@
112 * along with this program. If not, see <http://www.gnu.org/licenses/>.
113 *
114 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
115+ * Modified by Angelo Compagnucci <angelo.compagnucci@gmail.com>
116 *
117 */
118
119 namespace Unity.FilesLens {
120+ public enum UrlType {
121+ UNKNOWN,
122+ WEB,
123+ MOUNTABLE;
124+ }
125
126 public class UrlChecker : Object
127 {
128 /* A string serialized GIcon */
129- public string icon { get; private set; }
130+ public string web_icon { get; private set; }
131+ public string mountable_icon { get; private set; }
132
133 /* Regexes URLs must match */
134- private List<Regex> regexes;
135+ private Regex web_regex;
136+ private Regex mountable_regex;
137
138 public UrlChecker ()
139 {
140- icon = new ThemedIcon ("web-browser").to_string ();
141- regexes = new List<Regex> ();
142+ web_icon = new ThemedIcon ("web-browser").to_string ();
143+ mountable_icon = new ThemedIcon ("folder-remote").to_string ();
144
145 try {
146- regexes.prepend (new Regex (".+\\...+")); // contains a dot + >= 2 chars
147- regexes.prepend (new Regex ("www.*"));
148- regexes.prepend (new Regex ("http://.+"));
149- regexes.prepend (new Regex ("https://.+"));
150+ web_regex = new Regex ("(http[s]{0,1}://.+){0,1}" +
151+ "[a-zA-Z0-9\\-\\.]+\\.(ac|ad|ae|aero|af|ag|" +
152+ "ai|al|am|an|ao|aq|ar|arpa|as|asia|at|" +
153+ "au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|" +
154+ "biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|" +
155+ "ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|"+
156+ "com|coop|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|" +
157+ "dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|"+
158+ "fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|" +
159+ "gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|" +
160+ "hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|" +
161+ "io|iq|ir|is|it|je|jm|jo|jobs|jp|ke|kg|" +
162+ "kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|" +
163+ "lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|" +
164+ "mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|" +
165+ "mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|" +
166+ "net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|" +
167+ "pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|"+
168+ "pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|" +
169+ "sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|" +
170+ "sx|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|" +
171+ "tm|tn|to|tp|tr|travel|tt|tv|tw|tz|ua|" +
172+ "ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|" +
173+ "ws|xn|xxx|ye|yt|za|zm|zw|local|[0-9]{1,3})$");
174+ mountable_regex = new Regex ("(\\\\|(ftp|ssh|sftp|smb|dav)://).+");
175 } catch (RegexError e) {
176 warning ("Error compiling regular expressions for URL matching. URL launching will not work: %s", e.message);
177 }
178 }
179
180- /* Returns a valid HTTP/HTTPS URL if the input looks like it,
181- * or null otherwise */
182- public string? check_url (string sample)
183+ /* Returns a valid URL if the input looks like it or null otherwise,
184+ * returns also url type which can after be used
185+ * to retrive corresponding icon
186+ */
187+ public string? check_url (string sample, out UrlType url_type)
188 {
189 if (sample.strip () == "") return null;
190-
191- foreach (var regex in regexes)
192- {
193- if (regex.match (sample))
194- {
195- return sample.has_prefix ("http") ? sample : ("http://" + sample);
196- }
197- }
198
199+ if (mountable_regex.match (sample))
200+ {
201+ url_type = UrlType.MOUNTABLE;
202+ return sample.replace("\\\\","smb://");
203+ }
204+ else if (web_regex.match (sample))
205+ {
206+ url_type = UrlType.WEB;
207+ return sample.has_prefix ("http") ? sample : ("http://" + sample);
208+ }
209+ url_type = UrlType.UNKNOWN;
210 return null;
211 }
212
213+ public string get_icon_for_type (UrlType url_type)
214+ {
215+ switch (url_type){
216+ case UrlType.WEB:
217+ return web_icon;
218+ case UrlType.MOUNTABLE:
219+ return mountable_icon;
220+ }
221+ return web_icon;
222+ }
223+
224 } /* end: class UrlChecker */
225
226 } /* end: namespace */

Subscribers

People subscribed via source and target branches