After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 757493 - Handle the 'geo' URI in Polari
Handle the 'geo' URI in Polari
Status: RESOLVED FIXED
Product: polari
Classification: Applications
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: Polari maintainers
Polari maintainers
Depends on: 756512
Blocks:
 
 
Reported: 2015-11-02 17:20 UTC by Jonas Danielsson
Modified: 2015-11-05 16:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
chatView: Use GAppLaunchContext for URIs (1.31 KB, patch)
2015-11-02 17:21 UTC, Jonas Danielsson
none Details | Review
utils: Add 'geo' URI support to urlRegexp (2.09 KB, patch)
2015-11-02 17:21 UTC, Jonas Danielsson
none Details | Review
Casst of opening geo: URI in Polari (686.12 KB, video/webm)
2015-11-02 17:22 UTC, Jonas Danielsson
  Details
utils: Add 'geo' URI support to urlRegexp (4.68 KB, patch)
2015-11-02 23:51 UTC, Jonas Danielsson
none Details | Review
utils: Add 'geo' URI support to urlRegexp (4.12 KB, patch)
2015-11-02 23:52 UTC, Jonas Danielsson
none Details | Review
Add openURL helper to Utils (3.19 KB, patch)
2015-11-03 00:35 UTC, Jonas Danielsson
none Details | Review
utils: Add 'geo' URI support to urlRegexp (1.27 KB, patch)
2015-11-03 00:36 UTC, Jonas Danielsson
none Details | Review
Add openURL helper to Utils (3.56 KB, patch)
2015-11-03 15:47 UTC, Jonas Danielsson
none Details | Review
utils: Add 'geo' URI support to urlRegexp (1.59 KB, patch)
2015-11-03 15:47 UTC, Jonas Danielsson
rejected Details | Review
Add openURL helper to Utils (2.78 KB, patch)
2015-11-04 14:49 UTC, Jonas Danielsson
none Details | Review
Add openURL helper to Utils (2.85 KB, patch)
2015-11-05 15:41 UTC, Jonas Danielsson
committed Details | Review

Description Jonas Danielsson 2015-11-02 17:20:48 UTC
Our Apps should play nice with each other. Let's add support for opening the geo: URI scheme that Maps soon can handle.
Comment 1 Jonas Danielsson 2015-11-02 17:21:32 UTC
Created attachment 314672 [details] [review]
chatView: Use GAppLaunchContext for URIs

In ordet to bring the new application window to front
and get indication from the shell that we are opening an
application we need to use a GAppLaunchContext.
Comment 2 Jonas Danielsson 2015-11-02 17:21:37 UTC
Created attachment 314673 [details] [review]
utils: Add 'geo' URI support to urlRegexp
Comment 3 Jonas Danielsson 2015-11-02 17:22:29 UTC
Created attachment 314674 [details]
Casst of opening geo: URI in Polari
Comment 4 Jonas Danielsson 2015-11-02 23:51:11 UTC
Created attachment 314687 [details] [review]
utils: Add 'geo' URI support to urlRegexp
Comment 5 Jonas Danielsson 2015-11-02 23:52:47 UTC
Created attachment 314688 [details] [review]
utils: Add 'geo' URI support to urlRegexp
Comment 6 Jonas Danielsson 2015-11-03 00:35:59 UTC
Created attachment 314691 [details] [review]
Add openURL helper to Utils

In order to bring the new application window to front
and get indication from the shell that we are opening an
application we need to use a GAppLaunchContext.

And it would be nice to get some feedback if we got
an error from opening the URL. For instance if no
handler is present.
Comment 7 Jonas Danielsson 2015-11-03 00:36:08 UTC
Created attachment 314692 [details] [review]
utils: Add 'geo' URI support to urlRegexp
Comment 8 Jonas Danielsson 2015-11-03 15:47:12 UTC
Created attachment 314743 [details] [review]
Add openURL helper to Utils

In order to bring the new application window to front
and get indication from the shell that we are opening an
application we need to use a GAppLaunchContext.

And it would be nice to get some feedback if we got
an error from opening the URL. For instance if no
handler is present.
Comment 9 Jonas Danielsson 2015-11-03 15:47:19 UTC
Created attachment 314744 [details] [review]
utils: Add 'geo' URI support to urlRegexp

This will let Polari handle the geo: URI scheme as
specified by RFC 5870.

GNOME Maps and KDE Marble installs handlers for
the geo: uri.

    In its simplest form it looks like:
        geo:latitude,longitude

    An Android extension to set a description is also supported:
        geo:0,0?q=latitude,longitude(description)
Comment 10 Florian Müllner 2015-11-04 01:06:37 UTC
Review of attachment 314743 [details] [review]:

::: src/chatView.js
@@ +521,3 @@
         let iter = view.get_iter_at_location(x, y);
         let tags = iter.get_tags();
+        let timestamp = Gtk.get_current_event_time();

We do have the actual event here - use event.get_time()

::: src/utils.js
@@ +109,3 @@
+    let app = Gio.Application. get_default();
+    let scheme = GLib.uri_parse_scheme(url);
+    let appInfo = Gio.AppInfo.get_default_for_uri_scheme(scheme);

Can you leave this part out for now? I haven't quite made up my mind about how to support "fringe" URI schemes yet (i.e whether to throw an error at the user as you do here, or just not linkify them unless the scheme is supported) ...

@@ +111,3 @@
+    let appInfo = Gio.AppInfo.get_default_for_uri_scheme(scheme);
+    if (!appInfo) {
+        let msg = _("No way to open URI");

... also instead of duplicating the code, you could just use different messages in the error handling for launch_default_for_uri():

let msg;
if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_SUPPORTED))
    msg = _("No way to open URI");
else
    msg = _("Failed to open URI");
let n = new AppNotification.SimpleOutput(msg);

@@ +118,3 @@
+
+    let display = Gdk.Display.get_default();
+    let ctx = Gdk.Display.get_default().get_app_launch_context();

first you set a display variable, then you don't use it

@@ +119,3 @@
+    let display = Gdk.Display.get_default();
+    let ctx = Gdk.Display.get_default().get_app_launch_context();
+    let screen = display.get_default_screen();

no need to explicitly specify the screen the launch context will use anyway
Comment 11 Florian Müllner 2015-11-04 01:07:00 UTC
Review of attachment 314744 [details] [review]:

::: src/utils.js
@@ +37,3 @@
 const _leadingJunk = '[\\s`(\\[{\'\\"<\u00AB\u201C\u2018]';
 const _notTrailingJunk = '[^\\s`!()\\[\\]{};:\'\\".,<>?\u00AB\u00BB\u201C\u201D\u2018\u2019]';
+const _float = '[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?';

Just double-checking: .1234 is legal?

@@ +49,3 @@
             '[a-z0-9.\\-]+[.][a-z]{2,4}/' +       // foo.xx/
+            '|' +
+            'geo:' + _float + ',' + _float + 	  // 'geo' URI

As mentioned in the other review, I'm still undecided on whether to unconditionally turn those URIs into links.
Independent from that, I'm not really comfortable with making an already tricky regex ever-more complicated (see bug 755563 and its dupes for a list of other schemes we've already been asked to support). So I think I'd prefer something like:

const _defaultUrlRegex = '(^|' + ...
const _geoUrlRegex = '(^|' + ...
const _urlRegexp = new RegExp(_defaultUrlRegex + '|' + _geoUrlRegex);

(or create the RegExp object lazily and only append the geoUrl handling if that scheme is supported)
Comment 12 Jonas Danielsson 2015-11-04 14:46:30 UTC
Review of attachment 314743 [details] [review]:

Thanks for the review!

::: src/chatView.js
@@ +521,3 @@
         let iter = view.get_iter_at_location(x, y);
         let tags = iter.get_tags();
+        let timestamp = Gtk.get_current_event_time();

Of course!

::: src/utils.js
@@ +109,3 @@
+    let app = Gio.Application. get_default();
+    let scheme = GLib.uri_parse_scheme(url);
+    let appInfo = Gio.AppInfo.get_default_for_uri_scheme(scheme);

Yes, understand! Will do!

@@ +111,3 @@
+    let appInfo = Gio.AppInfo.get_default_for_uri_scheme(scheme);
+    if (!appInfo) {
+        let msg = _("No way to open URI");

Ah, thank you!
Comment 13 Jonas Danielsson 2015-11-04 14:48:21 UTC
Review of attachment 314744 [details] [review]:

::: src/utils.js
@@ +37,3 @@
 const _leadingJunk = '[\\s`(\\[{\'\\"<\u00AB\u201C\u2018]';
 const _notTrailingJunk = '[^\\s`!()\\[\\]{};:\'\\".,<>?\u00AB\u00BB\u201C\u201D\u2018\u2019]';
+const _float = '[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?';

No it is not, and I checked that it is not linkified. The RFC says it needs 1*DIGIT before dot.

@@ +49,3 @@
             '[a-z0-9.\\-]+[.][a-z]{2,4}/' +       // foo.xx/
+            '|' +
+            'geo:' + _float + ',' + _float + 	  // 'geo' URI

Yeah, I understand completely. So Maybe this should be abandoned and a solution should be added to 755563 instead?
Comment 14 Jonas Danielsson 2015-11-04 14:49:21 UTC
Created attachment 314829 [details] [review]
Add openURL helper to Utils

In order to bring the new application window to front
and get indication from the shell that we are opening an
application we need to use a GAppLaunchContext.

And it would be nice to get some feedback if we got
an error from opening the URL. For instance if no
handler is present.
Comment 15 Florian Müllner 2015-11-05 15:30:53 UTC
Review of attachment 314829 [details] [review]:

::: src/chatView.js
@@ +488,3 @@
+        let timestamp = Gtk.get_current_event_time();
+        item.connect('activate', function() {
+            Utils.openURL(url, timestamp);

This looks wrong - why would we want the timestamp from the time the menu was popped up (which btw is available in the @time parameter) rather than when the menu item was activated?

::: src/utils.js
@@ +112,3 @@
+        Gio.AppInfo.launch_default_for_uri(url, ctx);
+    } catch(e) {
+        let n = new AppNotifications.SimpleOutput(_("Failed to open URI"));

"Failed to open link" - URI is a bit too technical for my taste for something we throw at the user, and "link" is consistent with the context menu.

@@ +114,3 @@
+        let n = new AppNotifications.SimpleOutput(_("Failed to open URI"));
+        app.notificationQueue.addNotification(n);
+        debug("failed top open URI: %s".format(e.message));

typo: s/top/to/ - also might be helpful to use "failed to open %s: %s".format(url, e.message)"?
Comment 16 Jonas Danielsson 2015-11-05 15:41:59 UTC
Created attachment 314929 [details] [review]
Add openURL helper to Utils

In order to bring the new application window to front
and get indication from the shell that we are opening an
application we need to use a GAppLaunchContext.

And it would be nice to get some feedback if we got
an error from opening the URL. For instance if no
handler is present.
Comment 17 Florian Müllner 2015-11-05 15:44:01 UTC
Review of attachment 314929 [details] [review]:

::: src/chatView.js
@@ -484,3 +484,2 @@
     _showUrlContextMenu: function(url, button, time) {
         let menu = new Gtk.Menu();
-

Spurious whitespace removal, otherwise LGTM
Comment 18 Jonas Danielsson 2015-11-05 16:28:54 UTC
Attachment 314929 [details] pushed as 305fca7 - Add openURL helper to Utils