Merge lp:~tintou/switchboard/preference-specification into lp:~elementary-pantheon/switchboard/switchboard
- preference-specification
- Merge into switchboard
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Danielle Foré | ||||
Approved revision: | 688 | ||||
Merged at revision: | 691 | ||||
Proposed branch: | lp:~tintou/switchboard/preference-specification | ||||
Merge into: | lp:~elementary-pantheon/switchboard/switchboard | ||||
Diff against target: |
416 lines (+113/-93) 7 files modified
data/switchboard.desktop.in (+4/-4) lib/Plug.vala (+9/-3) po/extra/extra.pot (+4/-1) po/switchboard.pot (+11/-19) sample/SamplePlug.vala (+9/-6) schemas/org.pantheon.switchboard.gschema.xml (+8/-1) src/Switchboard.vala (+68/-59) |
||||
To merge this branch: | bzr merge lp:~tintou/switchboard/preference-specification | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Danielle Foré | Approve | ||
Review via email: mp+309639@code.launchpad.net |
Commit message
Now implements the settings:// scheme so that apps can use the scheme instead of relying on switchboard directly
Description of the change
Corentin Noël (tintou) wrote : | # |
- 687. By Corentin Noël
-
Now implements the settings:// scheme so that apps can use the scheme instead of relying on switchboard directly
Danielle Foré (danrabbit) wrote : | # |
I'm not sure if I agree that maintaining a gsettings key is the best way to do this. I think we want to extend the plug API so that plugs can add uris here. Otherwise it kind of hurts the modularity of switchboard doesn't it? If a user decides to replace a default pane, the uri scheme would break
Corentin Noël (tintou) wrote : | # |
A casual user won't change the GSettings key so it will remain unassign and will be able to be updated. I think it's more something that is up to the distribution than to the user so GSettings are easy to override…
- 688. By Corentin Noël
-
Extend the Plug API so that each plug can provide an interface of the preference specification
Danielle Foré (danrabbit) wrote : | # |
I can confirm that this branch works as intended with panes being able to extend the URL API.
I can also confirm that it does not break the old API.
The only question I have is regarding adding the scheme handler line to mimeapps.list (x-scheme-
Preview Diff
1 | === modified file 'data/switchboard.desktop.in' |
2 | --- data/switchboard.desktop.in 2016-08-02 18:13:33 +0000 |
3 | +++ data/switchboard.desktop.in 2016-11-02 00:25:52 +0000 |
4 | @@ -2,13 +2,13 @@ |
5 | Type=Application |
6 | _Name=System Settings |
7 | _Comment=Change system and user settings |
8 | -Exec=switchboard |
9 | +Exec=switchboard %u |
10 | Icon=preferences-desktop |
11 | Terminal=false |
12 | +StartupNotify=true |
13 | Categories=GNOME;GTK;System; |
14 | -X-GNOME-Keywords=Center;Control;Panel;Preferences;System; |
15 | -X-AppInstall-Keywords=Center;Control;Panel;Preferences;System; |
16 | -X-GNOME-Gettext-Domain=switchboard |
17 | +_Keywords=Center;Control;Panel;Preferences;System; |
18 | +MimeType=x-scheme-handler/settings; |
19 | Actions=AboutDialog; |
20 | |
21 | [Desktop Action AboutDialog] |
22 | |
23 | === modified file 'lib/Plug.vala' |
24 | --- lib/Plug.vala 2014-11-04 23:12:02 +0000 |
25 | +++ lib/Plug.vala 2016-11-02 00:25:52 +0000 |
26 | @@ -19,7 +19,6 @@ |
27 | */ |
28 | |
29 | public abstract class Switchboard.Plug : GLib.Object { |
30 | - |
31 | public enum Category { |
32 | PERSONAL = 0, |
33 | HARDWARE = 1, |
34 | @@ -64,9 +63,16 @@ |
35 | public string icon { get; construct; } |
36 | |
37 | /** |
38 | + * A map of settings:// endpoints and location to pass to the |
39 | + * {@link search_callback} method if the value is not %NULL. |
40 | + * For example {"input/keyboard", "keyboard"}. |
41 | + */ |
42 | + public Gee.TreeMap<string, string?> supported_settings { get; construct; default = new Gee.TreeMap<string, string?> (null, null); } |
43 | + |
44 | + /** |
45 | * Inform if the plug should be shown or not |
46 | */ |
47 | - public bool can_show { get; set; default=true;} |
48 | + public bool can_show { get; set; default=true; } |
49 | |
50 | /** |
51 | * Inform the application that the plug can now be listed in the available plugs |
52 | @@ -108,4 +114,4 @@ |
53 | * @param location a {@link string} that represents the setting to show. |
54 | */ |
55 | public abstract void search_callback (string location); |
56 | -} |
57 | \ No newline at end of file |
58 | +} |
59 | |
60 | === modified file 'po/extra/extra.pot' |
61 | --- po/extra/extra.pot 2016-08-02 18:14:32 +0000 |
62 | +++ po/extra/extra.pot 2016-11-02 00:25:52 +0000 |
63 | @@ -8,7 +8,7 @@ |
64 | msgstr "" |
65 | "Project-Id-Version: PACKAGE VERSION\n" |
66 | "Report-Msgid-Bugs-To: \n" |
67 | -"POT-Creation-Date: 2016-08-02 11:13-0700\n" |
68 | +"POT-Creation-Date: 2016-10-30 15:50+0100\n" |
69 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
70 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
71 | "Language-Team: LANGUAGE <LL@li.org>\n" |
72 | @@ -23,6 +23,9 @@ |
73 | msgid "Change system and user settings" |
74 | msgstr "" |
75 | |
76 | +msgid "Center;Control;Panel;Preferences;System;" |
77 | +msgstr "" |
78 | + |
79 | msgid "About System Settings" |
80 | msgstr "" |
81 | |
82 | |
83 | === modified file 'po/switchboard.pot' |
84 | --- po/switchboard.pot 2016-08-02 18:14:32 +0000 |
85 | +++ po/switchboard.pot 2016-11-02 00:25:52 +0000 |
86 | @@ -8,7 +8,7 @@ |
87 | msgstr "" |
88 | "Project-Id-Version: PACKAGE VERSION\n" |
89 | "Report-Msgid-Bugs-To: \n" |
90 | -"POT-Creation-Date: 2016-08-02 11:13-0700\n" |
91 | +"POT-Creation-Date: 2016-10-30 15:50+0100\n" |
92 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
93 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
94 | "Language-Team: LANGUAGE <LL@li.org>\n" |
95 | @@ -45,38 +45,30 @@ |
96 | msgid "All Settings" |
97 | msgstr "" |
98 | |
99 | -#: ../src/Switchboard.vala:67 |
100 | +#: ../src/Switchboard.vala:68 |
101 | msgid "Open a plug" |
102 | msgstr "" |
103 | |
104 | -#: ../src/Switchboard.vala:73 |
105 | +#: ../src/Switchboard.vala:74 |
106 | msgid "System Settings" |
107 | msgstr "" |
108 | |
109 | -#: ../src/Switchboard.vala:86 |
110 | +#: ../src/Switchboard.vala:87 |
111 | msgid "translator-credits" |
112 | msgstr "" |
113 | |
114 | -#: ../src/Switchboard.vala:322 |
115 | +#: ../src/Switchboard.vala:117 |
116 | +msgid "Specified link '%s' does not exist, going back to the main panel" |
117 | +msgstr "" |
118 | + |
119 | +#: ../src/Switchboard.vala:327 |
120 | msgid "No Settings Found" |
121 | msgstr "" |
122 | |
123 | -#: ../src/Switchboard.vala:322 |
124 | +#: ../src/Switchboard.vala:327 |
125 | msgid "Install some and re-launch Switchboard." |
126 | msgstr "" |
127 | |
128 | -#: ../src/Switchboard.vala:445 |
129 | +#: ../src/Switchboard.vala:450 |
130 | msgid "Search Settings" |
131 | msgstr "" |
132 | - |
133 | -#: ../src/Switchboard.vala:582 |
134 | -msgid "Change system and user settings" |
135 | -msgstr "" |
136 | - |
137 | -#: ../src/Switchboard.vala:583 |
138 | -msgid "Center;Control;Panel;Preferences;System;" |
139 | -msgstr "" |
140 | - |
141 | -#: ../src/Switchboard.vala:584 |
142 | -msgid "About System Settings" |
143 | -msgstr "" |
144 | |
145 | === modified file 'sample/SamplePlug.vala' |
146 | --- sample/SamplePlug.vala 2014-11-04 23:12:02 +0000 |
147 | +++ sample/SamplePlug.vala 2016-11-02 00:25:52 +0000 |
148 | @@ -19,23 +19,26 @@ |
149 | */ |
150 | |
151 | public class Sample.Plug : Switchboard.Plug { |
152 | - |
153 | private Gtk.Grid main_grid; |
154 | + private Gtk.Label hello_label; |
155 | |
156 | public Plug () { |
157 | Object (category: Category.SYSTEM, |
158 | code_name: "sample-plug", |
159 | display_name: _("Sample Plug"), |
160 | description:_("Does nothing, but it is cool !"), |
161 | - icon: "system-run"); |
162 | + icon: "system-run", |
163 | + supported_settings: new Gee.TreeMap<string, string?> (null, null)); |
164 | + supported_settings.set ("wallpaper", null); |
165 | } |
166 | - |
167 | + |
168 | public override Gtk.Widget get_widget () { |
169 | if (main_grid == null) { |
170 | main_grid = new Gtk.Grid (); |
171 | - var hello_label = new Gtk.Label ("Hello World!"); |
172 | + hello_label = new Gtk.Label ("Hello World!"); |
173 | main_grid.attach (hello_label, 0, 0, 1, 1); |
174 | } |
175 | + |
176 | main_grid.show_all (); |
177 | return main_grid; |
178 | } |
179 | @@ -49,7 +52,7 @@ |
180 | } |
181 | |
182 | public override void search_callback (string location) { |
183 | - |
184 | + hello_label.label = "Callback : %s".printf (location); |
185 | } |
186 | |
187 | // 'search' returns results like ("Keyboard → Behavior → Duration", "keyboard<sep>behavior") |
188 | @@ -62,4 +65,4 @@ |
189 | debug ("Activating Sample plug"); |
190 | var plug = new Sample.Plug (); |
191 | return plug; |
192 | -} |
193 | \ No newline at end of file |
194 | +} |
195 | |
196 | === modified file 'schemas/org.pantheon.switchboard.gschema.xml' |
197 | --- schemas/org.pantheon.switchboard.gschema.xml 2016-05-12 18:04:05 +0000 |
198 | +++ schemas/org.pantheon.switchboard.gschema.xml 2016-11-02 00:25:52 +0000 |
199 | @@ -4,7 +4,7 @@ |
200 | <value nick="Normal" value="0" /> |
201 | <value nick="Maximized" value="1" /> |
202 | </enum> |
203 | - <schema path="/org/pantheon/switchboard/saved-state/" id="org.pantheon.switchboard.saved-state" gettext-domain="switchboard"> |
204 | + <schema path="/org/pantheon/switchboard/saved-state/" id="org.pantheon.switchboard.saved-state"> |
205 | <key name="window-state" enum="switchboard-window-states"> |
206 | <default>"Normal"</default> |
207 | <summary>The saved state of the window.</summary> |
208 | @@ -26,4 +26,11 @@ |
209 | <description>The position of the window.</description> |
210 | </key> |
211 | </schema> |
212 | + <schema path="/org/pantheon/switchboard/preferences/" id="org.pantheon.switchboard.preferences"> |
213 | + <key name="mapping-override" type="a{s(ss)}"> |
214 | + <default>{}</default> |
215 | + <summary>Override (and extends) the default mapping with plugs</summary> |
216 | + <description>Contains a dictionary of path and two strings: the plug name and an argument. For example {'wallpaper': ('foo-desktop','wallpaper'), 'display': ('bar-display','')}</description> |
217 | + </key> |
218 | + </schema> |
219 | </schemalist> |
220 | |
221 | === modified file 'src/Switchboard.vala' |
222 | --- src/Switchboard.vala 2016-09-26 03:03:59 +0000 |
223 | +++ src/Switchboard.vala 2016-11-02 00:25:52 +0000 |
224 | @@ -54,6 +54,7 @@ |
225 | |
226 | private static string? plug_to_open = null; |
227 | private static string? open_window = null; |
228 | + private static string? link = null; |
229 | private static bool opened_directly = false; |
230 | private static bool should_animate_next_transition = true; |
231 | private const uint[] NAVIGATION_KEYS = { |
232 | @@ -64,18 +65,13 @@ |
233 | Gdk.Key.Return |
234 | }; |
235 | |
236 | - const OptionEntry[] entries = { |
237 | - { "open-plug", 'o', 0, OptionArg.STRING, ref plug_to_open, N_("Open a plug"), "PLUG_NAME" }, |
238 | - { null } |
239 | - }; |
240 | - |
241 | construct { |
242 | application_id = "org.elementary.switchboard"; |
243 | program_name = _("System Settings"); |
244 | app_years = "2011-2016"; |
245 | exec_name = "switchboard"; |
246 | app_launcher = exec_name+".desktop"; |
247 | - flags |= ApplicationFlags.HANDLES_COMMAND_LINE; |
248 | + flags |= ApplicationFlags.HANDLES_OPEN; |
249 | |
250 | build_version = "2.0"; |
251 | app_icon = "preferences-desktop"; |
252 | @@ -85,13 +81,21 @@ |
253 | translate_url = "https://translations.launchpad.net/switchboard"; |
254 | about_authors = {"Avi Romanoff <avi@elementaryos.org>", "Corentin Noël <tintou@mailoo.org>", null}; |
255 | about_translators = _("translator-credits"); |
256 | - |
257 | about_license_type = Gtk.License.GPL_3_0; |
258 | + |
259 | + if (GLib.AppInfo.get_default_for_uri_scheme ("settings") == null) { |
260 | + var appinfo = new GLib.DesktopAppInfo (app_launcher); |
261 | + try { |
262 | + appinfo.set_as_default_for_type ("x-scheme-handler/settings"); |
263 | + } catch (Error e) { |
264 | + critical ("Unable to set default for the settings scheme: %s", e.message); |
265 | + } |
266 | + } |
267 | } |
268 | |
269 | public static SwitchboardApp _instance = null; |
270 | |
271 | - public static SwitchboardApp instance { |
272 | + public static unowned SwitchboardApp instance { |
273 | get { |
274 | if (_instance == null) |
275 | _instance = new SwitchboardApp (); |
276 | @@ -99,74 +103,85 @@ |
277 | } |
278 | } |
279 | |
280 | - public override int command_line (ApplicationCommandLine command_line) { |
281 | - hold (); |
282 | - int res = _command_line (command_line); |
283 | - release (); |
284 | - return res; |
285 | + public override void open (File[] files, string hint) { |
286 | + var file = files[0]; |
287 | + if (file == null) { |
288 | + return; |
289 | + } |
290 | + |
291 | + if (file.get_uri_scheme () == "settings") { |
292 | + link = file.get_uri ().replace ("settings://", ""); |
293 | + if (link.has_suffix ("/")) { |
294 | + link = link.substring (0, link.last_index_of_char ('/')); |
295 | + } |
296 | + |
297 | + } else { |
298 | + warning ("Calling Switchboard directly is deprecated, please use the settings:// scheme instead"); |
299 | + var name = file.get_basename (); |
300 | + if (":" in name) { |
301 | + var parts = name.split (":"); |
302 | + plug_to_open = gcc_to_switchboard_code_name (parts[0]); |
303 | + open_window = parts[1]; |
304 | + } else { |
305 | + plug_to_open = gcc_to_switchboard_code_name (name); |
306 | + } |
307 | + } |
308 | + |
309 | + activate (); |
310 | } |
311 | |
312 | - private int _command_line (ApplicationCommandLine command_line) { |
313 | - var context = new OptionContext (""); |
314 | - context.add_main_entries (entries, "switchboard "); |
315 | - context.add_group (Gtk.get_option_group (true)); |
316 | - |
317 | - string[] args = command_line.get_arguments (); |
318 | - |
319 | - try { |
320 | - unowned string[] tmp = args; |
321 | - context.parse (ref tmp); |
322 | - |
323 | - // we have an unparsed argument. Assume that it's a gcc plug name |
324 | - if (tmp.length > 1) { |
325 | - if (":" in tmp[1]) { |
326 | - var parts = tmp[1].split (":"); |
327 | - plug_to_open = gcc_to_switchboard_code_name (parts[0]); |
328 | - open_window = parts[1]; |
329 | - } else { |
330 | - plug_to_open = gcc_to_switchboard_code_name (tmp[1]); |
331 | + public override void activate () { |
332 | + var plugsmanager = Switchboard.PlugsManager.get_default (); |
333 | + var setting = new Settings ("org.pantheon.switchboard.preferences"); |
334 | + var mapping_dic = setting.get_value ("mapping-override"); |
335 | + if (link != null && !mapping_dic.lookup (link, "(ss)", ref plug_to_open, ref open_window)) { |
336 | + bool plug_found = false; |
337 | + foreach (var plug in plugsmanager.get_plugs ()) { |
338 | + if (plug.supported_settings == null) |
339 | + continue; |
340 | + |
341 | + if (plug.supported_settings.has_key (link)) { |
342 | + load_plug (plug); |
343 | + open_window = plug.supported_settings.get (link); |
344 | + link = null; |
345 | + |
346 | + // If plug_to_open was set from the command line |
347 | + should_animate_next_transition = false; |
348 | + opened_directly = true; |
349 | + plug_found = true; |
350 | + break; |
351 | } |
352 | } |
353 | - } catch (Error e) { |
354 | - warning (e.message); |
355 | - return 0; |
356 | - } |
357 | - |
358 | - if (DEBUG) |
359 | - Granite.Services.Logger.DisplayLevel = Granite.Services.LogLevel.DEBUG; |
360 | - else |
361 | - Granite.Services.Logger.DisplayLevel = Granite.Services.LogLevel.INFO; |
362 | - |
363 | - if (plug_to_open != null) { |
364 | - var plugsmanager = Switchboard.PlugsManager.get_default (); |
365 | + |
366 | + if (!plug_found) { |
367 | + warning (_("Specified link '%s' does not exist, going back to the main panel").printf (link)); |
368 | + } |
369 | + } else if (plug_to_open != null) { |
370 | foreach (var plug in plugsmanager.get_plugs ()) { |
371 | if (plug_to_open.has_suffix (plug.code_name)) { |
372 | load_plug (plug); |
373 | plug_to_open = null; |
374 | + |
375 | + // If plug_to_open was set from the command line |
376 | + should_animate_next_transition = false; |
377 | + opened_directly = true; |
378 | break; |
379 | } |
380 | } |
381 | - |
382 | - // If plug_to_open was set from the command line |
383 | - should_animate_next_transition = false; |
384 | - opened_directly = true; |
385 | } |
386 | |
387 | // If app is already running, present the current window. |
388 | - if (get_windows () != null) { |
389 | + if (get_windows ().length () > 0) { |
390 | get_windows ().data.present (); |
391 | - return 1; |
392 | + return; |
393 | } |
394 | |
395 | loaded_plugs = new Gee.LinkedList <string> (); |
396 | previous_plugs = new Gee.ArrayList <Switchboard.Plug> (); |
397 | - Switchboard.PlugsManager.get_default (); |
398 | settings = new GLib.Settings ("org.pantheon.switchboard.saved-state"); |
399 | build (); |
400 | category_view.load_default_plugs.begin (); |
401 | Gtk.main (); |
402 | - |
403 | - return 0; |
404 | } |
405 | |
406 | public void hide_alert () { |
407 | @@ -591,9 +606,3 @@ |
408 | } |
409 | } |
410 | |
411 | -#if TRANSLATION |
412 | -_("Change system and user settings"); |
413 | -_("Center;Control;Panel;Preferences;System;"); |
414 | -_("About System Settings"); |
415 | -#endif |
416 | - |
FYI the specification is here https:/ /docs.google. com/document/ d/1N0uqNtVXEFn3 cLgNMeN75mP_ dpMpCco- 7uw5PKow- _Q/edit#