Merge lp:~davidmhewitt/slingshot/fix-1636632 into lp:~elementary-pantheon/slingshot/trunk

Proposed by David Hewitt on 2017-02-08
Status: Merged
Approved by: Daniel Fore on 2017-02-18
Approved revision: 737
Merged at revision: 743
Proposed branch: lp:~davidmhewitt/slingshot/fix-1636632
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 148 lines (+121/-1)
3 files modified
lib/synapse-plugins/CMakeLists.txt (+1/-0)
lib/synapse-plugins/appcenter-plugin.vala (+118/-0)
src/Backend/SynapseSearch.vala (+2/-1)
To merge this branch: bzr merge lp:~davidmhewitt/slingshot/fix-1636632
Reviewer Review Type Date Requested Status
Daniel Fore 2017-02-08 Needs Fixing on 2017-02-18
Jeremy Wootten (community) code, function Approve on 2017-02-18
Corentin Noël 2017-02-12 Pending
Review via email: mp+316784@code.launchpad.net

Commit message

Provide "Search AppCenter for x" results at bottom of list.

Description of the change

Note: This depends on https://code.launchpad.net/~davidmhewitt/appcenter/fix-1636632/+merge/317046

Added a new synapse plugin to provide a "Search AppCenter for x" result for every search query entered. These appear underneath every other result in the list in their own section. Upon selecting one, AppCenter opens with the search already executed.

To post a comment you must log in.
Jeremy Wootten (jeremywootten) wrote :

Provides one "Search AppCenter for [search term]" line (with heading) when a search term is entered and this launches a search in AppCenter when clicked.

The description above refers to "these" and "upon selecting one" which implies there should be more than one line but enter in several search terms separated by spaces or commas did not produce this. I am not sure what the intended behaviour is.

David Hewitt (davidmhewitt) wrote :

> Provides one "Search AppCenter for [search term]" line (with heading) when a
> search term is entered and this launches a search in AppCenter when clicked.
>
> The description above refers to "these" and "upon selecting one" which implies
> there should be more than one line but enter in several search terms separated
> by spaces or commas did not produce this. I am not sure what the intended
> behaviour is.

This is possibly just my poor use of the English language. Despite it being my native language ;)

The intended functionality is to only provide one result for whatever you searched for and pass that search query to AppCenter when the result is opened.

Jeremy Wootten (jeremywootten) wrote :

OK, I will approve then.

review: Approve (code, function)
735. By David Hewitt on 2017-02-18

Code style fixes

736. By David Hewitt on 2017-02-18

Added translators comment

Daniel Fore (danrabbit) wrote :

I think this should probably appear under "Actions" instead of making a new category.

Just a note for Cody:

It looks like AppCenter will open to the home page without the other branch. I think that's an acceptable default and I don't think this branch introduces a dependency on AppCenter.

review: Needs Fixing
737. By David Hewitt on 2017-02-18

Move results to actions instead of own category

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/synapse-plugins/CMakeLists.txt'
2--- lib/synapse-plugins/CMakeLists.txt 2016-02-20 17:11:51 +0000
3+++ lib/synapse-plugins/CMakeLists.txt 2017-02-18 21:09:54 +0000
4@@ -21,6 +21,7 @@
5 switchboard-plugin.vala
6 system-managment.vala
7 link-plugin.vala
8+ appcenter-plugin.vala
9 )
10
11 # Compile
12
13=== added file 'lib/synapse-plugins/appcenter-plugin.vala'
14--- lib/synapse-plugins/appcenter-plugin.vala 1970-01-01 00:00:00 +0000
15+++ lib/synapse-plugins/appcenter-plugin.vala 2017-02-18 21:09:54 +0000
16@@ -0,0 +1,118 @@
17+/*
18+* Copyright (c) 2017 David Hewitt <davidmhewitt@gmail.com>
19+* 2017 elementary LLC.
20+*
21+* This program is free software; you can redistribute it and/or
22+* modify it under the terms of the GNU General Public
23+* License as published by the Free Software Foundation; either
24+* version 2 of the License, or (at your option) any later version.
25+*
26+* This program is distributed in the hope that it will be useful,
27+* but WITHOUT ANY WARRANTY; without even the implied warranty of
28+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29+* General Public License for more details.
30+*
31+* You should have received a copy of the GNU General Public
32+* License along with this program; if not, write to the
33+* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
34+* Boston, MA 02110-1301 USA
35+*
36+* Authored by: David Hewitt <davidmhewitt@gmail.com>
37+*/
38+
39+namespace Synapse {
40+ public class AppcenterPlugin: Object, Activatable, ItemProvider {
41+
42+ public bool enabled { get; set; default = true; }
43+
44+ public void activate () { }
45+
46+ public void deactivate () { }
47+
48+ public class Result : Object, Match {
49+ // from Match interface
50+ public string title { get; construct set; }
51+ public string description { get; set; }
52+ public string icon_name { get; construct set; }
53+ public bool has_thumbnail { get; construct set; }
54+ public string thumbnail_path { get; construct set; }
55+ public MatchType match_type { get; construct set; }
56+
57+ public int default_relevancy { get; set; default = 0; }
58+
59+ private AppInfo? appinfo;
60+ private string search_term;
61+
62+ public Result (string search) {
63+ search_term = search;
64+
65+ string _title = "";
66+ string _icon_name = "";
67+
68+ appinfo = AppInfo.get_default_for_type ("x-scheme-handler/appstream", false);
69+ if (appinfo != null) {
70+ // TRANSLATORS: The first %s is what the user searched for, the second will be replaced with the localized name of AppCenter
71+ _title = _("Search for %s in %s".printf (search_term, appinfo.get_display_name ()));
72+ _icon_name = appinfo.get_icon ().to_string ();
73+ }
74+
75+ this.title = _title;
76+ this.icon_name = _icon_name;
77+ this.description = _("Search the app store");
78+ this.has_thumbnail = false;
79+ this.match_type = MatchType.ACTION;
80+ }
81+
82+ public void execute (Match? match) {
83+ if (appinfo == null) {
84+ return;
85+ }
86+
87+ var list = new List<string> ();
88+ list.append ("appstream://" + Uri.escape_string (search_term));
89+
90+ try {
91+ appinfo.launch_uris (list, null);
92+ } catch (Error e) {
93+ warning ("%s\n", e.message);
94+ }
95+ }
96+ }
97+
98+ private static AppInfo? appinfo;
99+
100+ static void register_plugin () {
101+ bool appcenter_installed = false;
102+
103+ appinfo = AppInfo.get_default_for_type ("x-scheme-handler/appstream", false);
104+ // Only register the plugin if we have an application that supports appstream://
105+ if (appinfo != null) {
106+ appcenter_installed = true;
107+ }
108+
109+ DataSink.PluginRegistry.get_default ().register_plugin (typeof (AppcenterPlugin),
110+ _("AppCenter"),
111+ _("Search for applications"),
112+ "system-software-install",
113+ register_plugin,
114+ appcenter_installed,
115+ _("AppCenter is not installed"));
116+ }
117+
118+ static construct {
119+ register_plugin ();
120+ }
121+
122+ public bool handles_query (Query query) {
123+ return QueryFlags.TEXT in query.query_type;
124+ }
125+
126+ public async ResultSet? search (Query query) throws SearchError {
127+ ResultSet results = new ResultSet ();
128+ Result search_result = new Result (query.query_string);
129+ results.add (search_result, Match.Score.INCREMENT_MINOR);
130+
131+ return results;
132+ }
133+ }
134+}
135
136=== modified file 'src/Backend/SynapseSearch.vala'
137--- src/Backend/SynapseSearch.vala 2016-02-20 17:11:51 +0000
138+++ src/Backend/SynapseSearch.vala 2017-02-18 21:09:54 +0000
139@@ -26,7 +26,8 @@
140 typeof (Synapse.DesktopFilePlugin),
141 typeof (Synapse.SwitchboardPlugin),
142 typeof (Synapse.SystemManagementPlugin),
143- typeof (Synapse.LinkPlugin)
144+ typeof (Synapse.LinkPlugin),
145+ typeof (Synapse.AppcenterPlugin)
146 };
147
148 private static Synapse.DataSink? sink = null;

Subscribers

People subscribed via source and target branches