on xenial help sign in
Implements usage-style documentation for unity8 executable.

Fixes lp:1269282 Fixes: 1269282

commit9cb5e34cc0a0d02d1572873d618699a6f31d928b authorJosh Arenson <joshua.arenson@canonical.com> dateTue 13 May 2014, 08:33 (12 years ago) parent4ab3b3b465d64e
2 files changed+47−14
src/ApplicationArguments.h+4−8 src/main.cpp+43−6
src/ApplicationArguments.h+4−8
@@ -28,14 +28,10 @@ class ApplicationArguments : public QObject
2828{
2929 Q_OBJECT
3030public:
31− ApplicationArguments(const QStringList& args) {
32− if (args.contains(QLatin1String("-windowgeometry")) && args.size() > args.indexOf(QLatin1String("-windowgeometry")) + 1) {
33− QStringList geometryArg = args.at(args.indexOf(QLatin1String("-windowgeometry")) + 1).split('x');
34− if (geometryArg.size() == 2) {
35− m_size.rwidth() = geometryArg.at(0).toInt();
36− m_size.rheight() = geometryArg.at(1).toInt();
37− }
38− }
31+ // Not exposed to the app as setSize isn't invokable
32+ void setSize(int width, int height) {
33+ m_size.rwidth() = width;
34+ m_size.rheight() = height;
3935 }
4036
4137 Q_INVOKABLE bool hasGeometry() const { return m_size.isValid(); }
src/main.cpp+43−6
@@ -18,6 +18,7 @@
1818 */
1919
2020// Qt
21+#include <QCommandLineParser>
2122#include <QtQuick/QQuickView>
2223#include <QtGui/QGuiApplication>
2324#include <QtQml/QQmlEngine>
@@ -43,6 +44,32 @@ int startShell(int argc, const char** argv, void* server)
4344
4445 QGuiApplication::setApplicationName("Unity 8");
4546 QGuiApplication *application;
47+
48+ QCommandLineParser parser;
49+ parser.setApplicationDescription("Description: Unity 8 Shell");
50+ parser.addHelpOption();
51+
52+ QCommandLineOption fullscreenOption("fullscreen",
53+ "Run in fullscreen");
54+ parser.addOption(fullscreenOption);
55+
56+ QCommandLineOption framelessOption("frameless",
57+ "Run without window borders");
58+ parser.addOption(framelessOption);
59+
60+ QCommandLineOption mousetouchOption("mousetouch",
61+ "Allow the mouse to provide touch input");
62+ parser.addOption(mousetouchOption);
63+
64+ QCommandLineOption windowGeometryOption(QStringList() << "windowgeometry",
65+ "Specify the window geometry as [<width>x<height>]", "windowgeometry", "1");
66+ parser.addOption(windowGeometryOption);
67+
68+ QCommandLineOption testabilityOption("testability",
69+ "DISCOURAGED: Please set QT_LOAD_TESTABILITY instead. \n \
70+Load the testability driver");
71+ parser.addOption(testabilityOption);
72+
4673 if (isUbuntuMirServer) {
4774 QLibrary unityMir("unity-mir", 1);
4875 unityMir.load();
@@ -59,6 +86,11 @@ int startShell(int argc, const char** argv, void* server)
5986 application = new QGuiApplication(argc, (char**)argv);
6087 }
6188
89+ // Treat args with single dashes the same as arguments with two dashes
90+ // Ex: -fullscreen == --fullscreen
91+ parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
92+ parser.process(*application);
93+
6294 QString indicatorProfile = qgetenv("UNITY_INDICATOR_PROFILE");
6395 if (indicatorProfile.isEmpty()) {
6496 indicatorProfile = "phone";
@@ -66,12 +98,17 @@ int startShell(int argc, const char** argv, void* server)
6698
6799 resolveIconTheme();
68100
69− QStringList args = application->arguments();
70− ApplicationArguments qmlArgs(args);
101+ ApplicationArguments qmlArgs;
102+ if (parser.isSet(windowGeometryOption) &&
103+ parser.value(windowGeometryOption).split('x').size() == 2)
104+ {
105+ QStringList geom = parser.value(windowGeometryOption).split('x');
106+ qmlArgs.setSize(geom.at(0).toInt(), geom.at(1).toInt());
107+ }
71108
72109 // The testability driver is only loaded by QApplication but not by QGuiApplication.
73110 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
74− if (args.contains(QLatin1String("-testability")) || getenv("QT_LOAD_TESTABILITY")) {
111+ if (parser.isSet(testabilityOption) || getenv("QT_LOAD_TESTABILITY")) {
75112 QLibrary testLib(QLatin1String("qttestability"));
76113 if (testLib.load()) {
77114 typedef void (*TasInitialize)(void);
@@ -94,14 +131,14 @@ int startShell(int argc, const char** argv, void* server)
94131 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
95132 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
96133 view->rootContext()->setContextProperty("indicatorProfile", indicatorProfile);
97− if (args.contains(QLatin1String("-frameless"))) {
134+ if (parser.isSet(framelessOption)) {
98135 view->setFlags(Qt::FramelessWindowHint);
99136 }
100137
101138 // You will need this if you want to interact with touch-only components using a mouse
102139 // Needed only when manually testing on a desktop.
103140 MouseTouchAdaptor *mouseTouchAdaptor = 0;
104− if (args.contains(QLatin1String("-mousetouch"))) {
141+ if (parser.isSet(mousetouchOption)) {
105142 mouseTouchAdaptor = new MouseTouchAdaptor;
106143 application->installNativeEventFilter(mouseTouchAdaptor);
107144 }
@@ -125,7 +162,7 @@ int startShell(int argc, const char** argv, void* server)
125162 view->setSource(source);
126163 view->setColor("transparent");
127164
128− if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || args.contains(QLatin1String("-fullscreen"))) {
165+ if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || parser.isSet(fullscreenOption)) {
129166 view->showFullScreen();
130167 } else {
131168 view->show();