Merge lp:~mardy/ubuntu-system-settings/plugin-invocation into lp:ubuntu-system-settings

Proposed by Alberto Mardegan
Status: Merged
Approved by: Iain Lane
Approved revision: 187
Merged at revision: 198
Proposed branch: lp:~mardy/ubuntu-system-settings/plugin-invocation
Merge into: lp:ubuntu-system-settings
Diff against target: 77 lines (+20/-11)
2 files modified
src/main.cpp (+16/-9)
src/qml/MainWindow.qml (+4/-2)
To merge this branch: bzr merge lp:~mardy/ubuntu-system-settings/plugin-invocation
Reviewer Review Type Date Requested Status
Iain Lane Approve
PS Jenkins bot continuous-integration Approve
Sebastien Bacher (community) Approve
Review via email: mp+176929@code.launchpad.net

Commit message

Support launching individual panels, with options

- Let plugin options be specified from the command line
- Quit if the requested plugin does not exist
- Do not open the System Settings page when a plugin is launched

Description of the change

Support launching individual panels, with options

- Let plugin options be specified from the command line
- Quit if the requested plugin does not exist
- Do not open the System Settings page when a plugin is launched

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
Iain Lane (laney) wrote :

Thanks. Works fine.

Why did you stop using getopt in favour of custom option parsing? I quite liked the use of a proper API there.

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

looks fine to me ... comment approving but not changing the mp status though since Laney has a good question and it would be nice to sort that detail out before merging

review: Approve
Revision history for this message
Alberto Mardegan (mardy) wrote :

> Why did you stop using getopt in favour of custom option parsing? I quite
> liked the use of a proper API there.

The "proper API" in Qt is QCoreApplication::arguments(); using getops doesn't buy us much, and would need converting all the params to QString.

Revision history for this message
Iain Lane (laney) wrote :

On Fri, Jul 26, 2013 at 05:58:25AM -0000, Alberto Mardegan wrote:
> > Why did you stop using getopt in favour of custom option parsing? I quite
> > liked the use of a proper API there.
>
> The "proper API" in Qt is QCoreApplication::arguments(); using getops doesn't buy us much, and would need converting all the params to QString.

It's not really an API though. The QApplication page even talks about
using argv so they clearly do recognise that you might want to do this.
Using getopt buys us the fact that it's a standard interface for parsing
which is robust and well-tested. In this case it also means that
--option foo=bar and --option=foo-bar work.

I pushed a branch which uses getopt_long() to
lp:~laney/ubuntu-system-settings/plugin-invocation-getopt-long.

I don't insist though, so if you do insist on your solution then fine.
If you do, there's a segfault if you don't have an = in the option
argument though, so please fix that.

--
Iain Lane [ <email address hidden> ]
Debian Developer [ <email address hidden> ]
Ubuntu Developer [ <email address hidden> ]

186. By Alberto Mardegan

Don't crash if options are missing the value

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Iain Lane (laney) wrote :

It still segfaults if you pass --option alone (the getopt version just ignores this - are you /sure/ reimplementing its functionality is the best approach?).

review: Needs Fixing
187. By Alberto Mardegan

Don't crash if --option is missing its argument

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Iain Lane (laney) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/main.cpp'
2--- src/main.cpp 2013-07-10 17:38:14 +0000
3+++ src/main.cpp 2013-07-26 11:54:23 +0000
4@@ -22,8 +22,6 @@
5 #include "i18n.h"
6 #include "plugin-manager.h"
7
8-#include <unistd.h>
9-
10 #include <QGuiApplication>
11 #include <QProcessEnvironment>
12 #include <QQmlContext>
13@@ -51,24 +49,33 @@
14 /* HACK: force the theme until lp #1098578 is fixed */
15 QIcon::setThemeName("ubuntu-mobile");
16
17- /* Parse the commandline options to see if we've been given a panel to load.
18- * The platform might pass us unknown (to us) options, which we want to just ignore.
19+ /* Parse the commandline options to see if we've been given a panel to load,
20+ * and other options for the panel.
21 */
22 QString defaultPlugin;
23- opterr = 0; /* disable errors, i.e. allow unknown arguments */
24- while (getopt(argc, argv, "") != -1); /* skip all option arguments */
25-
26- if (optind < argc) { /* we have an argument */
27- defaultPlugin = argv[optind];
28+ QVariantMap pluginOptions;
29+ QStringList arguments = app.arguments();
30+ for (int i = 1; i < arguments.count(); i++) {
31+ const QString &argument = arguments.at(i);
32+ if (!argument.startsWith('-')) {
33+ defaultPlugin = argument;
34+ } else if (argument == "--option" && i + 1 < arguments.count()) {
35+ QStringList option = arguments.at(++i).split("=");
36+ // If no value is given, insert an empty string
37+ pluginOptions.insert(option.at(0), option.value(1, ""));
38+ }
39 }
40
41 QQuickView view;
42+ QObject::connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()),
43+ Qt::QueuedConnection);
44 qmlRegisterType<QAbstractItemModel>();
45 qmlRegisterType<SystemSettings::PluginManager>("SystemSettings", 1, 0, "PluginManager");
46 view.setResizeMode(QQuickView::SizeRootObjectToView);
47 view.engine()->addImportPath(PLUGIN_PRIVATE_MODULE_DIR);
48 view.engine()->addImportPath(PLUGIN_QML_DIR);
49 view.rootContext()->setContextProperty("defaultPlugin", defaultPlugin);
50+ view.rootContext()->setContextProperty("pluginOptions", pluginOptions);
51 view.setSource(QUrl("qrc:/qml/MainWindow.qml"));
52 view.show();
53
54
55=== modified file 'src/qml/MainWindow.qml'
56--- src/qml/MainWindow.qml 2013-07-18 14:42:22 +0000
57+++ src/qml/MainWindow.qml 2013-07-26 11:54:23 +0000
58@@ -31,7 +31,6 @@
59
60 Component.onCompleted: {
61 i18n.domain = "ubuntu-system-settings"
62- pageStack.push(mainPage)
63 if (defaultPlugin) {
64 var plugin = pluginManager.getByName(defaultPlugin)
65 if (plugin) {
66@@ -41,8 +40,11 @@
67 pageStack.push(pageComponent, { plugin: plugin })
68 } else {
69 // Invalid plugin passed on the commandline
70- console.log("Plugin " + defaultPlugin + " does not exist. Ignoring.")
71+ console.log("Plugin " + defaultPlugin + " does not exist.")
72+ Qt.quit()
73 }
74+ } else {
75+ pageStack.push(mainPage)
76 }
77 }
78

Subscribers

People subscribed via source and target branches