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

Proposed by David Hewitt
Status: Merged
Approved by: Danielle Foré
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
Danielle Foré Needs Fixing
Jeremy Wootten (community) code, function Approve
Corentin Noël 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.
Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

OK, I will approve then.

review: Approve (code, function)
735. By David Hewitt

Code style fixes

736. By David Hewitt

Added translators comment

Revision history for this message
Danielle Foré (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

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

Subscribers

People subscribed via source and target branches