Merge lp:~donadigo/slingshot/open-link-browser into lp:~elementary-pantheon/slingshot/trunk

Proposed by Adam Bieńkowski
Status: Merged
Approved by: Danielle Foré
Approved revision: 635
Merged at revision: 634
Proposed branch: lp:~donadigo/slingshot/open-link-browser
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 216 lines (+150/-4)
5 files modified
lib/synapse-plugins/CMakeLists.txt (+1/-0)
lib/synapse-plugins/link-plugin.vala (+140/-0)
src/Backend/SynapseSearch.vala (+2/-1)
src/Widgets/SearchItem.vala (+2/-1)
src/Widgets/SearchView.vala (+5/-2)
To merge this branch: bzr merge lp:~donadigo/slingshot/open-link-browser
Reviewer Review Type Date Requested Status
Danielle Foré Needs Fixing
Review via email: mp+286738@code.launchpad.net

Commit message

Fix bug #1487786 "When entering web address, offer to open default browser [$15]".

Description of the change

Fix bug #1487786 "When entering web address, offer to open default browser [$15]".

I tried to keep the diff as small as possible, regex allows to open links with "https" and without it, plugin gets default browser by what's displayed in the applications plug. Tested with Midori, Chrome and Firefox.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Hrm I'm not sure how terribly useful this is when the regex requires x.y.z format or http(s). I would expect that most users write urls like foo.bar as a common case

review: Needs Fixing
635. By Adam Bieńkowski

Change regex to accept urls without www

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/synapse-plugins/CMakeLists.txt'
--- lib/synapse-plugins/CMakeLists.txt 2015-09-23 22:17:18 +0000
+++ lib/synapse-plugins/CMakeLists.txt 2016-02-21 20:36:00 +0000
@@ -20,6 +20,7 @@
20 desktop-file-plugin.vala20 desktop-file-plugin.vala
21 switchboard-plugin.vala21 switchboard-plugin.vala
22 system-managment.vala22 system-managment.vala
23 link-plugin.vala
23)24)
2425
25# Compile26# Compile
2627
=== added file 'lib/synapse-plugins/link-plugin.vala'
--- lib/synapse-plugins/link-plugin.vala 1970-01-01 00:00:00 +0000
+++ lib/synapse-plugins/link-plugin.vala 2016-02-21 20:36:00 +0000
@@ -0,0 +1,140 @@
1/*
2 * Copyright (C) 2010 Michal Hruby <michal.mhr@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Authored by Magnus Kulke <mkulke@gmail.com>
19 *
20 */
21
22namespace Synapse
23{
24 public class LinkPlugin: Object, Activatable, ItemProvider
25 {
26 public bool enabled { get; set; default = true; }
27
28 public void activate ()
29 {
30
31 }
32
33 public void deactivate ()
34 {
35
36 }
37
38 public class Result : Object, Match
39 {
40 // from Match interface
41 public string title { get; construct set; }
42 public string description { get; set; }
43 public string icon_name { get; construct set; }
44 public bool has_thumbnail { get; construct set; }
45 public string thumbnail_path { get; construct set; }
46 public MatchType match_type { get; construct set; }
47
48 public int default_relevancy { get; set; default = 0; }
49
50 private string uri;
51 private AppInfo? appinfo;
52
53 public Result (string link)
54 {
55 uri = link;
56 string _title = _("Open %s in default web browser".printf (uri));
57 string _icon_name = "web-browser";
58
59 appinfo = AppInfo.get_default_for_type ("x-scheme-handler/http", false);
60 if (appinfo != null)
61 {
62 _title = _("Open %s in %s").printf (uri, appinfo.get_display_name ());
63 _icon_name = appinfo.get_icon ().to_string ();
64 }
65
66 this.title = _title;
67 this.icon_name = _icon_name;
68 this.description = _("Open this link in default browser");
69 this.has_thumbnail = false;
70 this.match_type = MatchType.ACTION;
71 }
72
73 public void execute (Match? match)
74 {
75 if (appinfo == null) {
76 return;
77 }
78
79 var list = new List<string> ();
80 list.append (uri);
81 try
82 {
83 appinfo.launch_uris (list, null);
84 } catch (Error e)
85 {
86 warning ("%s\n", e.message);
87 }
88 }
89 }
90
91 static void register_plugin ()
92 {
93 DataSink.PluginRegistry.get_default ().register_plugin (
94 typeof (LinkPlugin),
95 _("Link"),
96 _("Open link in default browser"),
97 "web-browser",
98 register_plugin
99 );
100 }
101
102 static construct
103 {
104 register_plugin ();
105 }
106
107 private Regex regex;
108
109 construct
110 {
111 try
112 {
113 regex = new Regex ("[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)",
114 RegexCompileFlags.OPTIMIZE);
115 } catch (Error e) {
116 Utils.Logger.error (this, "Error creating regexp.");
117 }
118 }
119
120 public bool handles_query (Query query)
121 {
122 return QueryFlags.TEXT in query.query_type;
123 }
124
125 public async ResultSet? search (Query query) throws SearchError
126 {
127 bool matched = regex.match (query.query_string);
128 if (matched)
129 {
130 Result result = new Result (query.query_string);
131 ResultSet results = new ResultSet ();
132 results.add (result, Match.Score.AVERAGE);
133 query.check_cancellable ();
134 return results;
135 }
136
137 return null;
138 }
139 }
140}
0141
=== modified file 'src/Backend/SynapseSearch.vala'
--- src/Backend/SynapseSearch.vala 2015-06-03 19:10:24 +0000
+++ src/Backend/SynapseSearch.vala 2016-02-21 20:36:00 +0000
@@ -25,7 +25,8 @@
25 typeof (Synapse.CommandPlugin),25 typeof (Synapse.CommandPlugin),
26 typeof (Synapse.DesktopFilePlugin),26 typeof (Synapse.DesktopFilePlugin),
27 typeof (Synapse.SwitchboardPlugin),27 typeof (Synapse.SwitchboardPlugin),
28 typeof (Synapse.SystemManagementPlugin)28 typeof (Synapse.SystemManagementPlugin),
29 typeof (Synapse.LinkPlugin)
29 };30 };
3031
31 private static Synapse.DataSink? sink = null;32 private static Synapse.DataSink? sink = null;
3233
=== modified file 'src/Widgets/SearchItem.vala'
--- src/Widgets/SearchItem.vala 2015-12-22 17:07:27 +0000
+++ src/Widgets/SearchItem.vala 2016-02-21 20:36:00 +0000
@@ -28,7 +28,8 @@
28 CONTACT,28 CONTACT,
29 INTERNET,29 INTERNET,
30 SETTINGS,30 SETTINGS,
31 APP_ACTIONS31 APP_ACTIONS,
32 LINK
32 }33 }
3334
34 const int ICON_SIZE = 32;35 const int ICON_SIZE = 32;
3536
=== modified file 'src/Widgets/SearchView.vala'
--- src/Widgets/SearchView.vala 2015-12-19 14:15:03 +0000
+++ src/Widgets/SearchView.vala 2016-02-21 20:36:00 +0000
@@ -44,8 +44,8 @@
44 list_box.set_header_func ((Gtk.ListBoxUpdateHeaderFunc) update_header);44 list_box.set_header_func ((Gtk.ListBoxUpdateHeaderFunc) update_header);
45 list_box.row_activated.connect ((row) => {45 list_box.row_activated.connect ((row) => {
46 var search_item = row as SearchItem;46 var search_item = row as SearchItem;
47 if (search_item.result_type == SearchItem.ResultType.APP_ACTIONS) {47 if (search_item.result_type == SearchItem.ResultType.APP_ACTIONS || search_item.result_type == SearchItem.ResultType.LINK) {
48 ((Synapse.DesktopFilePlugin.ActionMatch) search_item.app.match).execute (null);48 search_item.app.match.execute (null);
49 } else {49 } else {
50 search_item.app.launch ();50 search_item.app.launch ();
51 }51 }
@@ -70,6 +70,8 @@
70 if (uri.has_prefix ("http://") || uri.has_prefix ("ftp://") || uri.has_prefix ("https://")) {70 if (uri.has_prefix ("http://") || uri.has_prefix ("ftp://") || uri.has_prefix ("https://")) {
71 result_type = SearchItem.ResultType.INTERNET;71 result_type = SearchItem.ResultType.INTERNET;
72 }72 }
73 } else if (match is Synapse.LinkPlugin.Result) {
74 result_type = SearchItem.ResultType.LINK;
73 }75 }
7476
75 if (result_type == SearchItem.ResultType.UNKNOWN) {77 if (result_type == SearchItem.ResultType.UNKNOWN) {
@@ -153,6 +155,7 @@
153 case SearchItem.ResultType.GENERIC_URI:155 case SearchItem.ResultType.GENERIC_URI:
154 label = _("Files");156 label = _("Files");
155 break;157 break;
158 case SearchItem.ResultType.LINK:
156 case SearchItem.ResultType.ACTION:159 case SearchItem.ResultType.ACTION:
157 label = _("Actions");160 label = _("Actions");
158 break;161 break;

Subscribers

People subscribed via source and target branches