Merge lp:~laney/ubuntu-system-settings/urihandler into lp:ubuntu-system-settings

Proposed by Iain Lane
Status: Merged
Approved by: Łukasz Zemczak
Approved revision: 441
Merged at revision: 464
Proposed branch: lp:~laney/ubuntu-system-settings/urihandler
Merge into: lp:ubuntu-system-settings
Diff against target: 78 lines (+54/-9)
1 file modified
src/qml/MainWindow.qml (+54/-9)
To merge this branch: bzr merge lp:~laney/ubuntu-system-settings/urihandler
Reviewer Review Type Date Requested Status
Sebastien Bacher (community) Approve
Łukasz Zemczak Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+190431@code.launchpad.net

Commit message

Use UriHandler to handle requests to switch to new pages in an existing instance.

Description of the change

Use UriHandler to handle requests to switch to new pages in an existing instance.

There's some JS to handle passing options to panels too.

Test it on your desktop:

 - apt-get install url-dispatcher upstart-app-launch-tools
 - start url-dispatcher
 - tail -f ~/.cache/upstart/application-legacy-ubuntu-system-settings-.log
 - upstart-app-launch ubuntu-system-settings settings:///system/...
 - (repeat the last command to switch panels)

And watch the tail output.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Looks good, works as well.

review: Approve
Revision history for this message
Sebastien Bacher (seb128) wrote :

I've reviewed/tried it yesterday, seems to work fine indeed

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/qml/MainWindow.qml'
2--- src/qml/MainWindow.qml 2013-10-07 17:15:22 +0000
3+++ src/qml/MainWindow.qml 2013-10-10 17:16:30 +0000
4@@ -29,21 +29,66 @@
5 applicationName: "SystemSettings"
6 automaticOrientation: true
7
8+ function loadPluginByName(pluginName, pluginOptions) {
9+ var plugin = pluginManager.getByName(pluginName)
10+ var opts = { plugin: plugin,
11+ pluginManager: pluginManager }
12+
13+ if (pluginOptions)
14+ opts.pluginOptions = pluginOptions
15+
16+ if (plugin) {
17+ // Got a valid plugin name - load it
18+ var pageComponent = plugin.pageComponent
19+ if (pageComponent) {
20+ pageStack.push(pageComponent, opts)
21+ return true
22+ }
23+ } else {
24+ // Invalid plugin
25+ console.log("Plugin " + pluginName + " does not exist.")
26+ return false
27+ }
28+ }
29+
30 Component.onCompleted: {
31 i18n.domain = "ubuntu-system-settings"
32 pageStack.push(mainPage)
33 if (defaultPlugin) {
34- var plugin = pluginManager.getByName(defaultPlugin)
35- if (plugin) {
36- // Got a valid plugin name - load it
37- var pageComponent = plugin.pageComponent
38- if (pageComponent)
39- pageStack.push(pageComponent, { plugin: plugin, pluginManager: pluginManager })
40+ if (!loadPluginByName(defaultPlugin))
41+ Qt.quit()
42+ }
43+ }
44+
45+ Connections {
46+ target: UriHandler
47+ onOpened: {
48+ var url = String(uris)
49+ var panelAndOptions = url.replace("settings:///system/", "")
50+ var optionIndex = panelAndOptions.indexOf("?")
51+ var panel = optionIndex > -1 ?
52+ panelAndOptions.substring(0, optionIndex) :
53+ panelAndOptions
54+ var urlParams = {}
55+ // Parse URL options
56+ // From http://stackoverflow.com/a/2880929
57+ if (optionIndex > -1) { // Got options
58+ var match,
59+ // Regex for replacing addition symbol with a space
60+ pl = /\+/g,
61+ search = /([^&=]+)=?([^&]*)/g,
62+ decode = function (s) {
63+ return decodeURIComponent(s.replace(pl, " "))
64+ }
65+ while (match = search.exec(
66+ panelAndOptions.substring(optionIndex + 1)))
67+ urlParams[decode(match[1])] = decode(match[2])
68+
69+ loadPluginByName(panel, urlParams)
70 } else {
71- // Invalid plugin passed on the commandline
72- console.log("Plugin " + defaultPlugin + " does not exist.")
73- Qt.quit()
74+ loadPluginByName(panel)
75 }
76+
77 }
78 }
79

Subscribers

People subscribed via source and target branches