Merge lp:~3v1n0/unity-lens-files/delegate-activation into lp:unity-lens-files/7.0

Proposed by Marco Trevisan (Treviño)
Status: Work in progress
Proposed branch: lp:~3v1n0/unity-lens-files/delegate-activation
Merge into: lp:unity-lens-files/7.0
Diff against target: 239 lines (+48/-75)
3 files modified
src/daemon.vala (+20/-59)
src/folder.vala (+23/-15)
src/url-checker.vala (+5/-1)
To merge this branch: bzr merge lp:~3v1n0/unity-lens-files/delegate-activation
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Unity Team Pending
Review via email: mp+162007@code.launchpad.net

Commit message

Daemon: don't handle the file/directory opening, just parse the uri and send it back to Unity

Description of the change

Make unity to handle the results activation.

This needs lp:~3v1n0/unity/dash-files-open to work.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Unmerged revisions

257. By Marco Trevisan (Treviño)

Daemon: don't handle the file/directory opening, just parse the uri and send it back to Unity

256. By Marco Trevisan (Treviño)

UrlChecker: only replace an URI only if it begins with wrong prefix

255. By Marco Trevisan (Treviño)

Folder: add utility function to get uri from device name

254. By Marco Trevisan (Treviño)

Folder: use a const string to handle devices prefix

253. By Marco Trevisan (Treviño)

Folder: use a const string for bookmark URIs

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 2013-02-20 13:19:41 +0000
3+++ src/daemon.vala 2013-05-02 00:39:24 +0000
4@@ -997,13 +997,11 @@
5 preview.subtitle = date_time.format ("%x, %X");
6 }
7
8- var email_app_info = GLib.AppInfo.get_default_for_uri_scheme ("mailto");
9-
10 string mime_type = finfo.get_content_type ();
11 preview.add_info (new InfoHint ("format", _("Format"), null, GLib.ContentType.get_description (mime_type)));
12
13 var open_action = new Unity.PreviewAction ("open", _("Open"), null);
14- open_action.activated.connect (on_preview_open);
15+ open_action.activated.connect (activate);
16 preview.add_action (open_action);
17
18 uint64 total_size = 0;
19@@ -1033,10 +1031,12 @@
20 preview.add_info (new InfoHint ("size", _("Size"), null, GLib.format_size (total_size)));
21
22 var open_folder_action = new Unity.PreviewAction ("open-dir", _("Show in Folder"), null);
23- open_folder_action.activated.connect (on_preview_open_folder);
24+ open_folder_action.activated.connect ((uri) => {
25+ return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED, "directory://"+uri);
26+ });
27 preview.add_action (open_folder_action);
28
29- if (email_app_info != null)
30+ if (GLib.AppInfo.get_default_for_uri_scheme ("mailto") != null)
31 {
32 var email_action = new Unity.PreviewAction ("email", _("Email"), null);
33 email_action.activated.connect (on_email_file);
34@@ -1095,7 +1095,7 @@
35 preview.add_info (new InfoHint ("contents", _("Contents"), null, _("%s, %u items").printf (GLib.format_size (contents_size), contents_count)));
36
37 var open_action = new Unity.PreviewAction ("open", _("Open"), null);
38- open_action.activated.connect (on_preview_open);
39+ open_action.activated.connect (activate);
40 preview.add_action (open_action);
41
42 return preview;
43@@ -1120,62 +1120,23 @@
44 return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);
45 }
46
47- public Unity.ActivationResponse on_preview_open (string uri)
48- {
49- try
50- {
51- if (bookmarks.launch_if_bookmark (uri) || devices.launch_if_device (uri) || GLib.AppInfo.launch_default_for_uri (uri, null))
52- {
53- return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);
54- }
55- }
56- catch (GLib.Error e)
57- {
58- warning ("Failed to launch default application for uri '%s': %s", uri, e.message);
59- }
60- return new Unity.ActivationResponse(Unity.HandledType.NOT_HANDLED);
61- }
62-
63- public Unity.ActivationResponse on_preview_open_folder (string uri)
64- {
65- var file_manager = AppInfo.get_default_for_type("inode/directory", true);
66- var uris = new GLib.List<string> ();
67- uris.append (uri);
68-
69- try
70- {
71- if (file_manager.launch_uris (uris, null))
72- return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);
73- }
74- catch (GLib.Error e)
75- {
76- warning ("Failed to launch default application for uri '%s': %s", uri, e.message);
77- }
78- return new Unity.ActivationResponse(Unity.HandledType.NOT_HANDLED);
79- }
80-
81 public Unity.ActivationResponse activate (string uri)
82 {
83 debug (@"Activating: $uri");
84- try {
85- if (bookmarks.launch_if_bookmark (uri) || devices.launch_if_device (uri))
86- return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);
87-
88- /* this code ensures that a file manager will be used
89- * * if uri it's a remote location that should be mounted */
90- var url_type = UrlType.UNKNOWN;
91- var checked_url = urls.check_url (uri, out url_type);
92- if (checked_url != null && url_type == UrlType.MOUNTABLE) {
93- var muris = new GLib.List<string>();
94- muris.prepend (uri);
95- var file_manager = AppInfo.get_default_for_type("inode/directory", true);
96- file_manager.launch_uris(muris,null);
97- return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);
98- }
99- } catch (GLib.Error error) {
100- warning ("Failed to launch URI %s", uri);
101- }
102- return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED);
103+
104+ if (Bookmark.is_bookmark_uri (uri))
105+ {
106+ var bookmark = Bookmark.uri_from_bookmark (uri);
107+ return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED, bookmark);
108+ }
109+
110+ if (Device.is_device_uri (uri))
111+ {
112+ var device = Device.uri_from_device (uri);
113+ return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED, device);
114+ }
115+
116+ return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED, uri);
117 }
118
119 private void on_zeitgeist_changed ()
120
121=== modified file 'src/folder.vala'
122--- src/folder.vala 2012-09-19 10:48:09 +0000
123+++ src/folder.vala 2013-05-02 00:39:24 +0000
124@@ -189,12 +189,11 @@
125
126 public bool launch_if_bookmark (string uri) throws Error
127 {
128- if (!uri.has_prefix ("bookmark:"))
129+ if (!Bookmark.is_bookmark_uri (uri))
130 return false;
131
132 var launcher = AppInfo.get_default_for_type ("inode/directory", true);
133
134- uri = uri.offset (9); // Remove "bookmark:" prefix from uri
135
136 if (launcher == null)
137 {
138@@ -203,7 +202,7 @@
139 }
140
141 var uris = new List<string> ();
142- uris.append (uri);
143+ uris.append (Bookmark.uri_from_bookmark (uri));
144
145 launcher.launch_uris (uris, null);
146
147@@ -214,6 +213,8 @@
148
149 public class Bookmark : Object
150 {
151+ public const string PREFIX = "bookmark:";
152+
153 public string uri { get; set construct; }
154 public string icon { get; set construct; }
155 public string mimetype { get; set construct; }
156@@ -224,7 +225,7 @@
157
158 public Bookmark (string uri, string mimetype, string display_name)
159 {
160- Object (uri:"bookmark:"+uri, icon:Utils.get_icon_for_uri (uri, mimetype),
161+ Object (uri:PREFIX+uri, icon:Utils.get_icon_for_uri (uri, mimetype),
162 mimetype:mimetype, display_name:display_name, dnd_uri:uri);
163
164 index_terms = new List<string> ();
165@@ -237,15 +238,15 @@
166 return index_terms;
167 }
168
169- public static bool is_bookmark_uri (string uri)
170- {
171- return uri.has_prefix ("bookmark:");
172- }
173+ public static bool is_bookmark_uri (string uri)
174+ {
175+ return uri.has_prefix (PREFIX);
176+ }
177
178- public static string uri_from_bookmark (string uri)
179- {
180- return uri.substring (9);
181- }
182+ public static string uri_from_bookmark (string uri)
183+ {
184+ return uri.substring (PREFIX.length);
185+ }
186 }
187
188
189@@ -362,6 +363,8 @@
190
191 public class Device : Object
192 {
193+ public const string PREFIX = "device://";
194+
195 public Volume volume { get; set construct; }
196 public string name { get; set construct; }
197 public string uri { get; set construct; }
198@@ -379,8 +382,8 @@
199 var icon_name = icon.to_string ();
200 var label = volume.get_identifier (VolumeIdentifier.LABEL) ?? "";
201 var uuid = volume.get_identifier (VolumeIdentifier.UUID) ?? "";
202- var id = "device://" + uuid + "-" + label;
203-
204+ var id = PREFIX + uuid + "-" + label;
205+
206 Object (volume:volume, name:name, uri:id, icon:icon,icon_name:icon_name, display_name:name, dnd_uri:id);
207
208 index_terms_ = new List<string> ();
209@@ -394,7 +397,12 @@
210
211 public static bool is_device_uri (string uri)
212 {
213- return uri.has_prefix ("device://");
214+ return uri.has_prefix (PREFIX);
215+ }
216+
217+ public static string uri_from_device (string uri)
218+ {
219+ return uri.substring (PREFIX.length);
220 }
221
222 public void mount_and_open () throws Error
223
224=== modified file 'src/url-checker.vala'
225--- src/url-checker.vala 2012-03-20 09:40:56 +0000
226+++ src/url-checker.vala 2013-05-02 00:39:24 +0000
227@@ -74,7 +74,11 @@
228 if (mountable_regex.match (sample))
229 {
230 url_type = UrlType.MOUNTABLE;
231- return sample.replace("\\\\","smb://");
232+
233+ if (sample.has_prefix("\\\\"))
234+ return sample.replace("\\\\","smb://");
235+
236+ return sample;
237 }
238 else if (web_regex.match (sample))
239 {

Subscribers

People subscribed via source and target branches