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
1=== modified file 'lib/synapse-plugins/CMakeLists.txt'
2--- lib/synapse-plugins/CMakeLists.txt 2015-05-20 17:13:27 +0000
3+++ lib/synapse-plugins/CMakeLists.txt 2015-06-03 19:12:20 +0000
4@@ -6,6 +6,7 @@
5 gio-unix-2.0
6 gee-0.8
7 gtk+-3.0
8+ switchboard-2.0
9 )
10
11 pkg_check_modules(PLUGINS_DEPS REQUIRED ${PLUGINS_PKG})
12@@ -14,6 +15,7 @@
13 calculator-plugin.vala
14 command-plugin.vala
15 desktop-file-plugin.vala
16+ switchboard-plugin.vala
17 system-managment.vala
18 )
19
20
21=== added file 'lib/synapse-plugins/switchboard-plugin.vala'
22--- lib/synapse-plugins/switchboard-plugin.vala 1970-01-01 00:00:00 +0000
23+++ lib/synapse-plugins/switchboard-plugin.vala 2015-06-03 19:12:20 +0000
24@@ -0,0 +1,152 @@
25+/*
26+ * Copyright (C) 2015 Peter Arnold
27+ *
28+ * This program is free software; you can redistribute it and/or modify
29+ * it under the terms of the GNU General Public License as published by
30+ * the Free Software Foundation; either version 2 of the License, or
31+ * (at your option) any later version.
32+ *
33+ * This program is distributed in the hope that it will be useful,
34+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
35+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36+ * GNU General Public License for more details.
37+ *
38+ * You should have received a copy of the GNU General Public License
39+ * along with this program; if not, write to the Free Software
40+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
41+ *
42+ * Authored by Peter Arnold
43+ *
44+ */
45+
46+namespace Synapse {
47+public class SwitchboardPlugin : Object, Activatable, ItemProvider {
48+
49+ public bool enabled { get; set; default = true; }
50+
51+ public SwitchboardPlugin() {
52+
53+ }
54+
55+ public void activate () {
56+
57+ }
58+
59+ public void deactivate () {
60+
61+ }
62+
63+ public class SwitchboardObject: Object, Match, ApplicationMatch {
64+ // for Match interface
65+ public string title { get; construct set; }
66+ public string description { get; set; default = ""; }
67+ public string icon_name { get; construct set; default = ""; }
68+ public bool has_thumbnail { get; construct set; default = false; }
69+ public string thumbnail_path { get; construct set; }
70+ public MatchType match_type { get; construct set; }
71+
72+ // for ApplicationMatch
73+ public AppInfo? app_info { get; set; default = null; }
74+ public bool needs_terminal { get; set; default = false; }
75+ public string? filename { get; construct set; default = null; }
76+ public string plug { get; construct set; }
77+
78+ public SwitchboardObject (PlugInfo plug_info) {
79+ Object (title: plug_info.title, description: _ ("Open %s settings").printf (plug_info.title),
80+ plug: plug_info.code_name, icon_name: plug_info.icon, match_type: MatchType.APPLICATION);
81+
82+ try {
83+ var cmd = "/usr/bin/switchboard -o %s".printf (plug_info.code_name);
84+ app_info = AppInfo.create_from_commandline (cmd, null, 0);
85+ } catch (Error err) {
86+ warning ("%s", err.message);
87+ }
88+ }
89+ }
90+
91+ static void register_plugin () {
92+ DataSink.PluginRegistry.get_default ().register_plugin (
93+ typeof (SwitchboardPlugin),
94+ "Switchboard Search",
95+ _ ("Find switchboard plugs and open them."),
96+ "preferences-desktop",
97+ register_plugin
98+ );
99+ }
100+
101+ static construct {
102+ register_plugin ();
103+ }
104+ private Gee.ArrayList<PlugInfo> plugs;
105+
106+ construct {
107+ plugs = new Gee.ArrayList<PlugInfo> ();
108+ load_plugs.begin ();
109+ }
110+
111+ public class PlugInfo : GLib.Object {
112+ public string title { get; construct set; }
113+ public string code_name { get; construct set; }
114+ public string icon { get; construct set; }
115+
116+ public PlugInfo (string plug_title, string code_name, string icon) {
117+ Object (title: plug_title, code_name: code_name, icon: icon);
118+ }
119+ }
120+
121+ private bool loading_in_progress = false;
122+ public signal void load_complete ();
123+
124+ private async void load_plugs () {
125+ loading_in_progress = true;
126+ Idle.add_full (Priority.LOW, load_plugs.callback);
127+ yield;
128+
129+ foreach (var plug in Switchboard.PlugsManager.get_default ().get_plugs ()) {
130+ plugs.add (new PlugInfo (plug.display_name, plug.code_name, plug.icon));
131+ }
132+ loading_in_progress = false;
133+ load_complete ();
134+ }
135+
136+ public async ResultSet? search (Query q) throws SearchError {
137+ if (loading_in_progress) {
138+ // wait
139+ ulong signal_id = this.load_complete.connect (() => {
140+ search.callback ();
141+ });
142+ yield;
143+ SignalHandler.disconnect (this, signal_id);
144+ } else {
145+ Idle.add_full (Priority.HIGH_IDLE, search.callback);
146+ yield;
147+ }
148+
149+ var result = new ResultSet ();
150+ MatcherFlags flags;
151+ if (q.query_string.length == 1) {
152+ flags = MatcherFlags.NO_SUBSTRING | MatcherFlags.NO_PARTIAL |
153+ MatcherFlags.NO_FUZZY;
154+ } else {
155+ flags = 0;
156+ }
157+ var matchers = Query.get_matchers_for_query (q.query_string_folded, flags);
158+
159+ string stripped = q.query_string.strip ();
160+ if (stripped == "") return null;
161+
162+ foreach (var plug in plugs) {
163+ foreach (var matcher in matchers) {
164+ MatchInfo info;
165+ if (matcher.key.match (plug.title.down (), 0, out info)) {
166+ result.add (new SwitchboardObject (plug), Match.Score.AVERAGE + Match.Score.INCREMENT_MEDIUM);
167+ break;
168+ }
169+ }
170+ }
171+ q.check_cancellable ();
172+
173+ return result;
174+ }
175+}
176+}
177\ No newline at end of file
178
179=== modified file 'po/slingshot.pot'
180--- po/slingshot.pot 2015-05-29 01:01:19 +0000
181+++ po/slingshot.pot 2015-06-03 19:12:20 +0000
182@@ -8,7 +8,7 @@
183 msgstr ""
184 "Project-Id-Version: PACKAGE VERSION\n"
185 "Report-Msgid-Bugs-To: \n"
186-"POT-Creation-Date: 2015-05-28 20:01-0500\n"
187+"POT-Creation-Date: 2015-06-03 20:59+0200\n"
188 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
189 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
190 "Language-Team: LANGUAGE <LL@li.org>\n"
191@@ -17,6 +17,58 @@
192 "Content-Type: text/plain; charset=UTF-8\n"
193 "Content-Transfer-Encoding: 8bit\n"
194
195+#: ../src/Widgets/SearchView.vala:160
196+msgid "Other"
197+msgstr ""
198+
199+#: ../src/Widgets/SearchView.vala:163
200+msgid "Text"
201+msgstr ""
202+
203+#: ../src/Widgets/SearchView.vala:166
204+msgid "Applications"
205+msgstr ""
206+
207+#: ../src/Widgets/SearchView.vala:169
208+msgid "Files"
209+msgstr ""
210+
211+#: ../src/Widgets/SearchView.vala:172
212+msgid "Actions"
213+msgstr ""
214+
215+#: ../src/Widgets/SearchView.vala:175
216+msgid "Search"
217+msgstr ""
218+
219+#: ../src/Widgets/SearchView.vala:178
220+msgid "Contacts"
221+msgstr ""
222+
223+#: ../src/Widgets/SearchView.vala:181
224+msgid "Internet"
225+msgstr ""
226+
227+#: ../src/Widgets/SearchView.vala:184
228+msgid "Settings"
229+msgstr ""
230+
231+#: ../src/Widgets/AppEntry.vala:195
232+msgid "Remove from _Dock"
233+msgstr ""
234+
235+#: ../src/Widgets/AppEntry.vala:197
236+msgid "Add to _Dock"
237+msgstr ""
238+
239+#: ../src/Widgets/CategoryView.vala:27
240+msgid "All Applications"
241+msgstr ""
242+
243+#: ../src/Widgets/CategoryView.vala:28
244+msgid "Create a new Filter"
245+msgstr ""
246+
247 #: ../src/Backend/App.vala:108
248 msgid "Run this command…"
249 msgstr ""
250@@ -33,52 +85,88 @@
251 msgid "Search Apps"
252 msgstr ""
253
254-#: ../src/Widgets/CategoryView.vala:27
255-msgid "All Applications"
256-msgstr ""
257-
258-#: ../src/Widgets/CategoryView.vala:28
259-msgid "Create a new Filter"
260-msgstr ""
261-
262-#: ../src/Widgets/AppEntry.vala:195
263-msgid "Remove from _Dock"
264-msgstr ""
265-
266-#: ../src/Widgets/AppEntry.vala:197
267-msgid "Add to _Dock"
268-msgstr ""
269-
270-#: ../src/Widgets/SearchView.vala:156
271-msgid "Other"
272-msgstr ""
273-
274-#: ../src/Widgets/SearchView.vala:159
275-msgid "Text"
276-msgstr ""
277-
278-#: ../src/Widgets/SearchView.vala:162
279-msgid "Applications"
280-msgstr ""
281-
282-#: ../src/Widgets/SearchView.vala:165
283-msgid "Files"
284-msgstr ""
285-
286-#: ../src/Widgets/SearchView.vala:168
287-msgid "Actions"
288-msgstr ""
289-
290-#: ../src/Widgets/SearchView.vala:171
291-msgid "Search"
292-msgstr ""
293-
294-#: ../src/Widgets/SearchView.vala:174
295-msgid "Contacts"
296-msgstr ""
297-
298-#: ../src/Widgets/SearchView.vala:177
299-msgid "Internet"
300+#: ../lib/synapse-plugins/system-managment.vala:103
301+msgid "Suspend"
302+msgstr ""
303+
304+#: ../lib/synapse-plugins/system-managment.vala:104
305+msgid "Put your computer into suspend mode"
306+msgstr ""
307+
308+#: ../lib/synapse-plugins/system-managment.vala:203
309+msgid "Hibernate"
310+msgstr ""
311+
312+#: ../lib/synapse-plugins/system-managment.vala:204
313+msgid "Put your computer into hibernation mode"
314+msgstr ""
315+
316+#: ../lib/synapse-plugins/system-managment.vala:302
317+msgid "Shut Down"
318+msgstr ""
319+
320+#: ../lib/synapse-plugins/system-managment.vala:303
321+msgid "Turn your computer off"
322+msgstr ""
323+
324+#: ../lib/synapse-plugins/system-managment.vala:386
325+msgid "Restart"
326+msgstr ""
327+
328+#: ../lib/synapse-plugins/system-managment.vala:387
329+msgid "Restart your computer"
330+msgstr ""
331+
332+#: ../lib/synapse-plugins/system-managment.vala:471
333+msgid "Suspend, hibernate, restart or shutdown your computer."
334+msgstr ""
335+
336+#: ../lib/synapse-plugins/system-managment.vala:476
337+msgid "ConsoleKit wasn't found"
338+msgstr ""
339+
340+#: ../lib/synapse-plugins/desktop-file-plugin.vala:94
341+msgid "Search for and run applications on your computer."
342+msgstr ""
343+
344+#: ../lib/synapse-plugins/desktop-file-plugin.vala:283
345+msgid "Open with %s"
346+msgstr ""
347+
348+#: ../lib/synapse-plugins/desktop-file-plugin.vala:285
349+msgid "Opens current selection using %s"
350+msgstr ""
351+
352+#: ../lib/synapse-plugins/command-plugin.vala:56
353+msgid "Execute '%s'"
354+msgstr ""
355+
356+#: ../lib/synapse-plugins/command-plugin.vala:56
357+msgid "Run command"
358+msgstr ""
359+
360+#: ../lib/synapse-plugins/command-plugin.vala:77
361+msgid "Find and execute arbitrary commands."
362+msgstr ""
363+
364+#: ../lib/synapse-plugins/calculator-plugin.vala:63
365+msgid "Calculator"
366+msgstr ""
367+
368+#: ../lib/synapse-plugins/calculator-plugin.vala:64
369+msgid "Calculate basic expressions."
370+msgstr ""
371+
372+#: ../lib/synapse-plugins/calculator-plugin.vala:68
373+msgid "bc is not installed"
374+msgstr ""
375+
376+#: ../lib/synapse-plugins/switchboard-plugin.vala:55
377+msgid "Open %s settings"
378+msgstr ""
379+
380+#: ../lib/synapse-plugins/switchboard-plugin.vala:71
381+msgid "Find switchboard plugs and open them."
382 msgstr ""
383
384 #: ../lib/synapse-core/common-actions.vala:77
385@@ -120,79 +208,3 @@
386 #: ../lib/synapse-core/common-actions.vala:294
387 msgid "Copy selection to clipboard"
388 msgstr ""
389-
390-#: ../lib/synapse-plugins/desktop-file-plugin.vala:94
391-msgid "Search for and run applications on your computer."
392-msgstr ""
393-
394-#: ../lib/synapse-plugins/desktop-file-plugin.vala:283
395-msgid "Open with %s"
396-msgstr ""
397-
398-#: ../lib/synapse-plugins/desktop-file-plugin.vala:285
399-msgid "Opens current selection using %s"
400-msgstr ""
401-
402-#: ../lib/synapse-plugins/command-plugin.vala:56
403-msgid "Execute '%s'"
404-msgstr ""
405-
406-#: ../lib/synapse-plugins/command-plugin.vala:56
407-msgid "Run command"
408-msgstr ""
409-
410-#: ../lib/synapse-plugins/command-plugin.vala:77
411-msgid "Find and execute arbitrary commands."
412-msgstr ""
413-
414-#: ../lib/synapse-plugins/calculator-plugin.vala:63
415-msgid "Calculator"
416-msgstr ""
417-
418-#: ../lib/synapse-plugins/calculator-plugin.vala:64
419-msgid "Calculate basic expressions."
420-msgstr ""
421-
422-#: ../lib/synapse-plugins/calculator-plugin.vala:68
423-msgid "bc is not installed"
424-msgstr ""
425-
426-#: ../lib/synapse-plugins/system-managment.vala:103
427-msgid "Suspend"
428-msgstr ""
429-
430-#: ../lib/synapse-plugins/system-managment.vala:104
431-msgid "Put your computer into suspend mode"
432-msgstr ""
433-
434-#: ../lib/synapse-plugins/system-managment.vala:203
435-msgid "Hibernate"
436-msgstr ""
437-
438-#: ../lib/synapse-plugins/system-managment.vala:204
439-msgid "Put your computer into hibernation mode"
440-msgstr ""
441-
442-#: ../lib/synapse-plugins/system-managment.vala:302
443-msgid "Shut Down"
444-msgstr ""
445-
446-#: ../lib/synapse-plugins/system-managment.vala:303
447-msgid "Turn your computer off"
448-msgstr ""
449-
450-#: ../lib/synapse-plugins/system-managment.vala:386
451-msgid "Restart"
452-msgstr ""
453-
454-#: ../lib/synapse-plugins/system-managment.vala:387
455-msgid "Restart your computer"
456-msgstr ""
457-
458-#: ../lib/synapse-plugins/system-managment.vala:471
459-msgid "Suspend, hibernate, restart or shutdown your computer."
460-msgstr ""
461-
462-#: ../lib/synapse-plugins/system-managment.vala:476
463-msgid "ConsoleKit wasn't found"
464-msgstr ""
465
466=== modified file 'src/Backend/SynapseSearch.vala'
467--- src/Backend/SynapseSearch.vala 2015-05-20 17:13:27 +0000
468+++ src/Backend/SynapseSearch.vala 2015-06-03 19:12:20 +0000
469@@ -24,6 +24,7 @@
470 typeof (Synapse.CalculatorPlugin),
471 typeof (Synapse.CommandPlugin),
472 typeof (Synapse.DesktopFilePlugin),
473+ typeof (Synapse.SwitchboardPlugin),
474 typeof (Synapse.SystemManagementPlugin)
475 };
476
477
478=== modified file 'src/Widgets/SearchView.vala'
479--- src/Widgets/SearchView.vala 2015-05-29 00:40:47 +0000
480+++ src/Widgets/SearchView.vala 2015-06-03 19:12:20 +0000
481@@ -128,6 +128,10 @@
482 || uri.has_prefix ("https://"))
483 type = 8;
484 }
485+ // we're cheating again and assign switchboard plugs to a separate category.
486+ // We assign 9 as the id for settings results
487+ if (match is Synapse.SwitchboardPlugin.SwitchboardObject)
488+ type = 9;
489
490 if ((list = categories.get (type)) == null) {
491 list = new Gee.LinkedList<Synapse.Match> ();
492@@ -176,6 +180,9 @@
493 case 8:
494 label = _("Internet");
495 break;
496+ case 9:
497+ label = _("Settings");
498+ break;
499 }
500
501 var header = new Gtk.Label (label);

Subscribers

People subscribed via source and target branches