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
=== modified file 'src/daemon.vala'
--- src/daemon.vala 2013-02-20 13:19:41 +0000
+++ src/daemon.vala 2013-05-02 00:39:24 +0000
@@ -997,13 +997,11 @@
997 preview.subtitle = date_time.format ("%x, %X");997 preview.subtitle = date_time.format ("%x, %X");
998 }998 }
999999
1000 var email_app_info = GLib.AppInfo.get_default_for_uri_scheme ("mailto");
1001
1002 string mime_type = finfo.get_content_type ();1000 string mime_type = finfo.get_content_type ();
1003 preview.add_info (new InfoHint ("format", _("Format"), null, GLib.ContentType.get_description (mime_type)));1001 preview.add_info (new InfoHint ("format", _("Format"), null, GLib.ContentType.get_description (mime_type)));
10041002
1005 var open_action = new Unity.PreviewAction ("open", _("Open"), null);1003 var open_action = new Unity.PreviewAction ("open", _("Open"), null);
1006 open_action.activated.connect (on_preview_open);1004 open_action.activated.connect (activate);
1007 preview.add_action (open_action);1005 preview.add_action (open_action);
10081006
1009 uint64 total_size = 0;1007 uint64 total_size = 0;
@@ -1033,10 +1031,12 @@
1033 preview.add_info (new InfoHint ("size", _("Size"), null, GLib.format_size (total_size)));1031 preview.add_info (new InfoHint ("size", _("Size"), null, GLib.format_size (total_size)));
10341032
1035 var open_folder_action = new Unity.PreviewAction ("open-dir", _("Show in Folder"), null);1033 var open_folder_action = new Unity.PreviewAction ("open-dir", _("Show in Folder"), null);
1036 open_folder_action.activated.connect (on_preview_open_folder);1034 open_folder_action.activated.connect ((uri) => {
1035 return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED, "directory://"+uri);
1036 });
1037 preview.add_action (open_folder_action);1037 preview.add_action (open_folder_action);
10381038
1039 if (email_app_info != null)1039 if (GLib.AppInfo.get_default_for_uri_scheme ("mailto") != null)
1040 {1040 {
1041 var email_action = new Unity.PreviewAction ("email", _("Email"), null);1041 var email_action = new Unity.PreviewAction ("email", _("Email"), null);
1042 email_action.activated.connect (on_email_file);1042 email_action.activated.connect (on_email_file);
@@ -1095,7 +1095,7 @@
1095 preview.add_info (new InfoHint ("contents", _("Contents"), null, _("%s, %u items").printf (GLib.format_size (contents_size), contents_count)));1095 preview.add_info (new InfoHint ("contents", _("Contents"), null, _("%s, %u items").printf (GLib.format_size (contents_size), contents_count)));
10961096
1097 var open_action = new Unity.PreviewAction ("open", _("Open"), null);1097 var open_action = new Unity.PreviewAction ("open", _("Open"), null);
1098 open_action.activated.connect (on_preview_open);1098 open_action.activated.connect (activate);
1099 preview.add_action (open_action);1099 preview.add_action (open_action);
11001100
1101 return preview;1101 return preview;
@@ -1120,62 +1120,23 @@
1120 return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);1120 return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);
1121 }1121 }
11221122
1123 public Unity.ActivationResponse on_preview_open (string uri)
1124 {
1125 try
1126 {
1127 if (bookmarks.launch_if_bookmark (uri) || devices.launch_if_device (uri) || GLib.AppInfo.launch_default_for_uri (uri, null))
1128 {
1129 return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);
1130 }
1131 }
1132 catch (GLib.Error e)
1133 {
1134 warning ("Failed to launch default application for uri '%s': %s", uri, e.message);
1135 }
1136 return new Unity.ActivationResponse(Unity.HandledType.NOT_HANDLED);
1137 }
1138
1139 public Unity.ActivationResponse on_preview_open_folder (string uri)
1140 {
1141 var file_manager = AppInfo.get_default_for_type("inode/directory", true);
1142 var uris = new GLib.List<string> ();
1143 uris.append (uri);
1144
1145 try
1146 {
1147 if (file_manager.launch_uris (uris, null))
1148 return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);
1149 }
1150 catch (GLib.Error e)
1151 {
1152 warning ("Failed to launch default application for uri '%s': %s", uri, e.message);
1153 }
1154 return new Unity.ActivationResponse(Unity.HandledType.NOT_HANDLED);
1155 }
1156
1157 public Unity.ActivationResponse activate (string uri)1123 public Unity.ActivationResponse activate (string uri)
1158 {1124 {
1159 debug (@"Activating: $uri");1125 debug (@"Activating: $uri");
1160 try {1126
1161 if (bookmarks.launch_if_bookmark (uri) || devices.launch_if_device (uri))1127 if (Bookmark.is_bookmark_uri (uri))
1162 return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);1128 {
11631129 var bookmark = Bookmark.uri_from_bookmark (uri);
1164 /* this code ensures that a file manager will be used1130 return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED, bookmark);
1165 * * if uri it's a remote location that should be mounted */1131 }
1166 var url_type = UrlType.UNKNOWN;1132
1167 var checked_url = urls.check_url (uri, out url_type);1133 if (Device.is_device_uri (uri))
1168 if (checked_url != null && url_type == UrlType.MOUNTABLE) {1134 {
1169 var muris = new GLib.List<string>();1135 var device = Device.uri_from_device (uri);
1170 muris.prepend (uri);1136 return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED, device);
1171 var file_manager = AppInfo.get_default_for_type("inode/directory", true);1137 }
1172 file_manager.launch_uris(muris,null);1138
1173 return new Unity.ActivationResponse(Unity.HandledType.HIDE_DASH);1139 return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED, uri);
1174 }
1175 } catch (GLib.Error error) {
1176 warning ("Failed to launch URI %s", uri);
1177 }
1178 return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED);
1179 }1140 }
11801141
1181 private void on_zeitgeist_changed ()1142 private void on_zeitgeist_changed ()
11821143
=== modified file 'src/folder.vala'
--- src/folder.vala 2012-09-19 10:48:09 +0000
+++ src/folder.vala 2013-05-02 00:39:24 +0000
@@ -189,12 +189,11 @@
189189
190 public bool launch_if_bookmark (string uri) throws Error190 public bool launch_if_bookmark (string uri) throws Error
191 {191 {
192 if (!uri.has_prefix ("bookmark:"))192 if (!Bookmark.is_bookmark_uri (uri))
193 return false;193 return false;
194194
195 var launcher = AppInfo.get_default_for_type ("inode/directory", true);195 var launcher = AppInfo.get_default_for_type ("inode/directory", true);
196196
197 uri = uri.offset (9); // Remove "bookmark:" prefix from uri
198197
199 if (launcher == null)198 if (launcher == null)
200 {199 {
@@ -203,7 +202,7 @@
203 }202 }
204203
205 var uris = new List<string> ();204 var uris = new List<string> ();
206 uris.append (uri);205 uris.append (Bookmark.uri_from_bookmark (uri));
207206
208 launcher.launch_uris (uris, null);207 launcher.launch_uris (uris, null);
209208
@@ -214,6 +213,8 @@
214213
215 public class Bookmark : Object214 public class Bookmark : Object
216 {215 {
216 public const string PREFIX = "bookmark:";
217
217 public string uri { get; set construct; }218 public string uri { get; set construct; }
218 public string icon { get; set construct; }219 public string icon { get; set construct; }
219 public string mimetype { get; set construct; }220 public string mimetype { get; set construct; }
@@ -224,7 +225,7 @@
224225
225 public Bookmark (string uri, string mimetype, string display_name)226 public Bookmark (string uri, string mimetype, string display_name)
226 {227 {
227 Object (uri:"bookmark:"+uri, icon:Utils.get_icon_for_uri (uri, mimetype),228 Object (uri:PREFIX+uri, icon:Utils.get_icon_for_uri (uri, mimetype),
228 mimetype:mimetype, display_name:display_name, dnd_uri:uri);229 mimetype:mimetype, display_name:display_name, dnd_uri:uri);
229230
230 index_terms = new List<string> ();231 index_terms = new List<string> ();
@@ -237,15 +238,15 @@
237 return index_terms;238 return index_terms;
238 }239 }
239240
240 public static bool is_bookmark_uri (string uri)241 public static bool is_bookmark_uri (string uri)
241 {242 {
242 return uri.has_prefix ("bookmark:");243 return uri.has_prefix (PREFIX);
243 }244 }
244245
245 public static string uri_from_bookmark (string uri)246 public static string uri_from_bookmark (string uri)
246 {247 {
247 return uri.substring (9);248 return uri.substring (PREFIX.length);
248 }249 }
249 }250 }
250251
251252
@@ -362,6 +363,8 @@
362363
363 public class Device : Object364 public class Device : Object
364 {365 {
366 public const string PREFIX = "device://";
367
365 public Volume volume { get; set construct; }368 public Volume volume { get; set construct; }
366 public string name { get; set construct; }369 public string name { get; set construct; }
367 public string uri { get; set construct; }370 public string uri { get; set construct; }
@@ -379,8 +382,8 @@
379 var icon_name = icon.to_string ();382 var icon_name = icon.to_string ();
380 var label = volume.get_identifier (VolumeIdentifier.LABEL) ?? "";383 var label = volume.get_identifier (VolumeIdentifier.LABEL) ?? "";
381 var uuid = volume.get_identifier (VolumeIdentifier.UUID) ?? "";384 var uuid = volume.get_identifier (VolumeIdentifier.UUID) ?? "";
382 var id = "device://" + uuid + "-" + label;385 var id = PREFIX + uuid + "-" + label;
383 386
384 Object (volume:volume, name:name, uri:id, icon:icon,icon_name:icon_name, display_name:name, dnd_uri:id);387 Object (volume:volume, name:name, uri:id, icon:icon,icon_name:icon_name, display_name:name, dnd_uri:id);
385388
386 index_terms_ = new List<string> ();389 index_terms_ = new List<string> ();
@@ -394,7 +397,12 @@
394397
395 public static bool is_device_uri (string uri)398 public static bool is_device_uri (string uri)
396 {399 {
397 return uri.has_prefix ("device://");400 return uri.has_prefix (PREFIX);
401 }
402
403 public static string uri_from_device (string uri)
404 {
405 return uri.substring (PREFIX.length);
398 }406 }
399407
400 public void mount_and_open () throws Error408 public void mount_and_open () throws Error
401409
=== modified file 'src/url-checker.vala'
--- src/url-checker.vala 2012-03-20 09:40:56 +0000
+++ src/url-checker.vala 2013-05-02 00:39:24 +0000
@@ -74,7 +74,11 @@
74 if (mountable_regex.match (sample))74 if (mountable_regex.match (sample))
75 {75 {
76 url_type = UrlType.MOUNTABLE;76 url_type = UrlType.MOUNTABLE;
77 return sample.replace("\\\\","smb://");77
78 if (sample.has_prefix("\\\\"))
79 return sample.replace("\\\\","smb://");
80
81 return sample;
78 }82 }
79 else if (web_regex.match (sample))83 else if (web_regex.match (sample))
80 {84 {

Subscribers

People subscribed via source and target branches