Merge lp:~parnold-x/slingshot/switchboard-plugin into lp:~elementary-pantheon/slingshot/trunk

Proposed by Djax
Status: Merged
Approved by: Danielle Foré
Approved revision: 546
Merged at revision: 571
Proposed branch: lp:~parnold-x/slingshot/switchboard-plugin
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 501 lines (+297/-123)
5 files modified
lib/synapse-plugins/CMakeLists.txt (+2/-0)
lib/synapse-plugins/switchboard-plugin.vala (+152/-0)
po/slingshot.pot (+135/-123)
src/Backend/SynapseSearch.vala (+1/-0)
src/Widgets/SearchView.vala (+7/-0)
To merge this branch: bzr merge lp:~parnold-x/slingshot/switchboard-plugin
Reviewer Review Type Date Requested Status
elementary Pantheon team Pending
Review via email: mp+261015@code.launchpad.net

Commit message

Get Switchboard plugs from Switchboard API instead of requiring .desktops

Description of the change

Add a slingshot synapse plugin that get the plugs from the Switchboard API and show these plugs in a new "Settings" category.

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

Plugin works as expected here! So we will only need to stop shipping .desktops with plugs

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-05-20 17:13:27 +0000
+++ lib/synapse-plugins/CMakeLists.txt 2015-06-03 19:12:20 +0000
@@ -6,6 +6,7 @@
6 gio-unix-2.06 gio-unix-2.0
7 gee-0.87 gee-0.8
8 gtk+-3.08 gtk+-3.0
9 switchboard-2.0
9)10)
1011
11pkg_check_modules(PLUGINS_DEPS REQUIRED ${PLUGINS_PKG})12pkg_check_modules(PLUGINS_DEPS REQUIRED ${PLUGINS_PKG})
@@ -14,6 +15,7 @@
14 calculator-plugin.vala15 calculator-plugin.vala
15 command-plugin.vala16 command-plugin.vala
16 desktop-file-plugin.vala17 desktop-file-plugin.vala
18 switchboard-plugin.vala
17 system-managment.vala19 system-managment.vala
18)20)
1921
2022
=== added file 'lib/synapse-plugins/switchboard-plugin.vala'
--- lib/synapse-plugins/switchboard-plugin.vala 1970-01-01 00:00:00 +0000
+++ lib/synapse-plugins/switchboard-plugin.vala 2015-06-03 19:12:20 +0000
@@ -0,0 +1,152 @@
1/*
2 * Copyright (C) 2015 Peter Arnold
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 Peter Arnold
19 *
20 */
21
22namespace Synapse {
23public class SwitchboardPlugin : Object, Activatable, ItemProvider {
24
25 public bool enabled { get; set; default = true; }
26
27 public SwitchboardPlugin() {
28
29 }
30
31 public void activate () {
32
33 }
34
35 public void deactivate () {
36
37 }
38
39 public class SwitchboardObject: Object, Match, ApplicationMatch {
40 // for Match interface
41 public string title { get; construct set; }
42 public string description { get; set; default = ""; }
43 public string icon_name { get; construct set; default = ""; }
44 public bool has_thumbnail { get; construct set; default = false; }
45 public string thumbnail_path { get; construct set; }
46 public MatchType match_type { get; construct set; }
47
48 // for ApplicationMatch
49 public AppInfo? app_info { get; set; default = null; }
50 public bool needs_terminal { get; set; default = false; }
51 public string? filename { get; construct set; default = null; }
52 public string plug { get; construct set; }
53
54 public SwitchboardObject (PlugInfo plug_info) {
55 Object (title: plug_info.title, description: _ ("Open %s settings").printf (plug_info.title),
56 plug: plug_info.code_name, icon_name: plug_info.icon, match_type: MatchType.APPLICATION);
57
58 try {
59 var cmd = "/usr/bin/switchboard -o %s".printf (plug_info.code_name);
60 app_info = AppInfo.create_from_commandline (cmd, null, 0);
61 } catch (Error err) {
62 warning ("%s", err.message);
63 }
64 }
65 }
66
67 static void register_plugin () {
68 DataSink.PluginRegistry.get_default ().register_plugin (
69 typeof (SwitchboardPlugin),
70 "Switchboard Search",
71 _ ("Find switchboard plugs and open them."),
72 "preferences-desktop",
73 register_plugin
74 );
75 }
76
77 static construct {
78 register_plugin ();
79 }
80 private Gee.ArrayList<PlugInfo> plugs;
81
82 construct {
83 plugs = new Gee.ArrayList<PlugInfo> ();
84 load_plugs.begin ();
85 }
86
87 public class PlugInfo : GLib.Object {
88 public string title { get; construct set; }
89 public string code_name { get; construct set; }
90 public string icon { get; construct set; }
91
92 public PlugInfo (string plug_title, string code_name, string icon) {
93 Object (title: plug_title, code_name: code_name, icon: icon);
94 }
95 }
96
97 private bool loading_in_progress = false;
98 public signal void load_complete ();
99
100 private async void load_plugs () {
101 loading_in_progress = true;
102 Idle.add_full (Priority.LOW, load_plugs.callback);
103 yield;
104
105 foreach (var plug in Switchboard.PlugsManager.get_default ().get_plugs ()) {
106 plugs.add (new PlugInfo (plug.display_name, plug.code_name, plug.icon));
107 }
108 loading_in_progress = false;
109 load_complete ();
110 }
111
112 public async ResultSet? search (Query q) throws SearchError {
113 if (loading_in_progress) {
114 // wait
115 ulong signal_id = this.load_complete.connect (() => {
116 search.callback ();
117 });
118 yield;
119 SignalHandler.disconnect (this, signal_id);
120 } else {
121 Idle.add_full (Priority.HIGH_IDLE, search.callback);
122 yield;
123 }
124
125 var result = new ResultSet ();
126 MatcherFlags flags;
127 if (q.query_string.length == 1) {
128 flags = MatcherFlags.NO_SUBSTRING | MatcherFlags.NO_PARTIAL |
129 MatcherFlags.NO_FUZZY;
130 } else {
131 flags = 0;
132 }
133 var matchers = Query.get_matchers_for_query (q.query_string_folded, flags);
134
135 string stripped = q.query_string.strip ();
136 if (stripped == "") return null;
137
138 foreach (var plug in plugs) {
139 foreach (var matcher in matchers) {
140 MatchInfo info;
141 if (matcher.key.match (plug.title.down (), 0, out info)) {
142 result.add (new SwitchboardObject (plug), Match.Score.AVERAGE + Match.Score.INCREMENT_MEDIUM);
143 break;
144 }
145 }
146 }
147 q.check_cancellable ();
148
149 return result;
150 }
151}
152}
0\ No newline at end of file153\ No newline at end of file
1154
=== modified file 'po/slingshot.pot'
--- po/slingshot.pot 2015-05-29 01:01:19 +0000
+++ po/slingshot.pot 2015-06-03 19:12:20 +0000
@@ -8,7 +8,7 @@
8msgstr ""8msgstr ""
9"Project-Id-Version: PACKAGE VERSION\n"9"Project-Id-Version: PACKAGE VERSION\n"
10"Report-Msgid-Bugs-To: \n"10"Report-Msgid-Bugs-To: \n"
11"POT-Creation-Date: 2015-05-28 20:01-0500\n"11"POT-Creation-Date: 2015-06-03 20:59+0200\n"
12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"12"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"13"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14"Language-Team: LANGUAGE <LL@li.org>\n"14"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,6 +17,58 @@
17"Content-Type: text/plain; charset=UTF-8\n"17"Content-Type: text/plain; charset=UTF-8\n"
18"Content-Transfer-Encoding: 8bit\n"18"Content-Transfer-Encoding: 8bit\n"
1919
20#: ../src/Widgets/SearchView.vala:160
21msgid "Other"
22msgstr ""
23
24#: ../src/Widgets/SearchView.vala:163
25msgid "Text"
26msgstr ""
27
28#: ../src/Widgets/SearchView.vala:166
29msgid "Applications"
30msgstr ""
31
32#: ../src/Widgets/SearchView.vala:169
33msgid "Files"
34msgstr ""
35
36#: ../src/Widgets/SearchView.vala:172
37msgid "Actions"
38msgstr ""
39
40#: ../src/Widgets/SearchView.vala:175
41msgid "Search"
42msgstr ""
43
44#: ../src/Widgets/SearchView.vala:178
45msgid "Contacts"
46msgstr ""
47
48#: ../src/Widgets/SearchView.vala:181
49msgid "Internet"
50msgstr ""
51
52#: ../src/Widgets/SearchView.vala:184
53msgid "Settings"
54msgstr ""
55
56#: ../src/Widgets/AppEntry.vala:195
57msgid "Remove from _Dock"
58msgstr ""
59
60#: ../src/Widgets/AppEntry.vala:197
61msgid "Add to _Dock"
62msgstr ""
63
64#: ../src/Widgets/CategoryView.vala:27
65msgid "All Applications"
66msgstr ""
67
68#: ../src/Widgets/CategoryView.vala:28
69msgid "Create a new Filter"
70msgstr ""
71
20#: ../src/Backend/App.vala:10872#: ../src/Backend/App.vala:108
21msgid "Run this command…"73msgid "Run this command…"
22msgstr ""74msgstr ""
@@ -33,52 +85,88 @@
33msgid "Search Apps"85msgid "Search Apps"
34msgstr ""86msgstr ""
3587
36#: ../src/Widgets/CategoryView.vala:2788#: ../lib/synapse-plugins/system-managment.vala:103
37msgid "All Applications"89msgid "Suspend"
38msgstr ""90msgstr ""
3991
40#: ../src/Widgets/CategoryView.vala:2892#: ../lib/synapse-plugins/system-managment.vala:104
41msgid "Create a new Filter"93msgid "Put your computer into suspend mode"
42msgstr ""94msgstr ""
4395
44#: ../src/Widgets/AppEntry.vala:19596#: ../lib/synapse-plugins/system-managment.vala:203
45msgid "Remove from _Dock"97msgid "Hibernate"
46msgstr ""98msgstr ""
4799
48#: ../src/Widgets/AppEntry.vala:197100#: ../lib/synapse-plugins/system-managment.vala:204
49msgid "Add to _Dock"101msgid "Put your computer into hibernation mode"
50msgstr ""102msgstr ""
51103
52#: ../src/Widgets/SearchView.vala:156104#: ../lib/synapse-plugins/system-managment.vala:302
53msgid "Other"105msgid "Shut Down"
54msgstr ""106msgstr ""
55107
56#: ../src/Widgets/SearchView.vala:159108#: ../lib/synapse-plugins/system-managment.vala:303
57msgid "Text"109msgid "Turn your computer off"
58msgstr ""110msgstr ""
59111
60#: ../src/Widgets/SearchView.vala:162112#: ../lib/synapse-plugins/system-managment.vala:386
61msgid "Applications"113msgid "Restart"
62msgstr ""114msgstr ""
63115
64#: ../src/Widgets/SearchView.vala:165116#: ../lib/synapse-plugins/system-managment.vala:387
65msgid "Files"117msgid "Restart your computer"
66msgstr ""118msgstr ""
67119
68#: ../src/Widgets/SearchView.vala:168120#: ../lib/synapse-plugins/system-managment.vala:471
69msgid "Actions"121msgid "Suspend, hibernate, restart or shutdown your computer."
70msgstr ""122msgstr ""
71123
72#: ../src/Widgets/SearchView.vala:171124#: ../lib/synapse-plugins/system-managment.vala:476
73msgid "Search"125msgid "ConsoleKit wasn't found"
74msgstr ""126msgstr ""
75127
76#: ../src/Widgets/SearchView.vala:174128#: ../lib/synapse-plugins/desktop-file-plugin.vala:94
77msgid "Contacts"129msgid "Search for and run applications on your computer."
78msgstr ""130msgstr ""
79131
80#: ../src/Widgets/SearchView.vala:177132#: ../lib/synapse-plugins/desktop-file-plugin.vala:283
81msgid "Internet"133msgid "Open with %s"
134msgstr ""
135
136#: ../lib/synapse-plugins/desktop-file-plugin.vala:285
137msgid "Opens current selection using %s"
138msgstr ""
139
140#: ../lib/synapse-plugins/command-plugin.vala:56
141msgid "Execute '%s'"
142msgstr ""
143
144#: ../lib/synapse-plugins/command-plugin.vala:56
145msgid "Run command"
146msgstr ""
147
148#: ../lib/synapse-plugins/command-plugin.vala:77
149msgid "Find and execute arbitrary commands."
150msgstr ""
151
152#: ../lib/synapse-plugins/calculator-plugin.vala:63
153msgid "Calculator"
154msgstr ""
155
156#: ../lib/synapse-plugins/calculator-plugin.vala:64
157msgid "Calculate basic expressions."
158msgstr ""
159
160#: ../lib/synapse-plugins/calculator-plugin.vala:68
161msgid "bc is not installed"
162msgstr ""
163
164#: ../lib/synapse-plugins/switchboard-plugin.vala:55
165msgid "Open %s settings"
166msgstr ""
167
168#: ../lib/synapse-plugins/switchboard-plugin.vala:71
169msgid "Find switchboard plugs and open them."
82msgstr ""170msgstr ""
83171
84#: ../lib/synapse-core/common-actions.vala:77172#: ../lib/synapse-core/common-actions.vala:77
@@ -120,79 +208,3 @@
120#: ../lib/synapse-core/common-actions.vala:294208#: ../lib/synapse-core/common-actions.vala:294
121msgid "Copy selection to clipboard"209msgid "Copy selection to clipboard"
122msgstr ""210msgstr ""
123
124#: ../lib/synapse-plugins/desktop-file-plugin.vala:94
125msgid "Search for and run applications on your computer."
126msgstr ""
127
128#: ../lib/synapse-plugins/desktop-file-plugin.vala:283
129msgid "Open with %s"
130msgstr ""
131
132#: ../lib/synapse-plugins/desktop-file-plugin.vala:285
133msgid "Opens current selection using %s"
134msgstr ""
135
136#: ../lib/synapse-plugins/command-plugin.vala:56
137msgid "Execute '%s'"
138msgstr ""
139
140#: ../lib/synapse-plugins/command-plugin.vala:56
141msgid "Run command"
142msgstr ""
143
144#: ../lib/synapse-plugins/command-plugin.vala:77
145msgid "Find and execute arbitrary commands."
146msgstr ""
147
148#: ../lib/synapse-plugins/calculator-plugin.vala:63
149msgid "Calculator"
150msgstr ""
151
152#: ../lib/synapse-plugins/calculator-plugin.vala:64
153msgid "Calculate basic expressions."
154msgstr ""
155
156#: ../lib/synapse-plugins/calculator-plugin.vala:68
157msgid "bc is not installed"
158msgstr ""
159
160#: ../lib/synapse-plugins/system-managment.vala:103
161msgid "Suspend"
162msgstr ""
163
164#: ../lib/synapse-plugins/system-managment.vala:104
165msgid "Put your computer into suspend mode"
166msgstr ""
167
168#: ../lib/synapse-plugins/system-managment.vala:203
169msgid "Hibernate"
170msgstr ""
171
172#: ../lib/synapse-plugins/system-managment.vala:204
173msgid "Put your computer into hibernation mode"
174msgstr ""
175
176#: ../lib/synapse-plugins/system-managment.vala:302
177msgid "Shut Down"
178msgstr ""
179
180#: ../lib/synapse-plugins/system-managment.vala:303
181msgid "Turn your computer off"
182msgstr ""
183
184#: ../lib/synapse-plugins/system-managment.vala:386
185msgid "Restart"
186msgstr ""
187
188#: ../lib/synapse-plugins/system-managment.vala:387
189msgid "Restart your computer"
190msgstr ""
191
192#: ../lib/synapse-plugins/system-managment.vala:471
193msgid "Suspend, hibernate, restart or shutdown your computer."
194msgstr ""
195
196#: ../lib/synapse-plugins/system-managment.vala:476
197msgid "ConsoleKit wasn't found"
198msgstr ""
199211
=== modified file 'src/Backend/SynapseSearch.vala'
--- src/Backend/SynapseSearch.vala 2015-05-20 17:13:27 +0000
+++ src/Backend/SynapseSearch.vala 2015-06-03 19:12:20 +0000
@@ -24,6 +24,7 @@
24 typeof (Synapse.CalculatorPlugin),24 typeof (Synapse.CalculatorPlugin),
25 typeof (Synapse.CommandPlugin),25 typeof (Synapse.CommandPlugin),
26 typeof (Synapse.DesktopFilePlugin),26 typeof (Synapse.DesktopFilePlugin),
27 typeof (Synapse.SwitchboardPlugin),
27 typeof (Synapse.SystemManagementPlugin)28 typeof (Synapse.SystemManagementPlugin)
28 };29 };
2930
3031
=== modified file 'src/Widgets/SearchView.vala'
--- src/Widgets/SearchView.vala 2015-05-29 00:40:47 +0000
+++ src/Widgets/SearchView.vala 2015-06-03 19:12:20 +0000
@@ -128,6 +128,10 @@
128 || uri.has_prefix ("https://"))128 || uri.has_prefix ("https://"))
129 type = 8;129 type = 8;
130 }130 }
131 // we're cheating again and assign switchboard plugs to a separate category.
132 // We assign 9 as the id for settings results
133 if (match is Synapse.SwitchboardPlugin.SwitchboardObject)
134 type = 9;
131135
132 if ((list = categories.get (type)) == null) {136 if ((list = categories.get (type)) == null) {
133 list = new Gee.LinkedList<Synapse.Match> ();137 list = new Gee.LinkedList<Synapse.Match> ();
@@ -176,6 +180,9 @@
176 case 8:180 case 8:
177 label = _("Internet");181 label = _("Internet");
178 break;182 break;
183 case 9:
184 label = _("Settings");
185 break;
179 }186 }
180187
181 var header = new Gtk.Label (label);188 var header = new Gtk.Label (label);

Subscribers

People subscribed via source and target branches