@@ -30,6 +30,7 @@
3030#include "MouseTouchAdaptor.h"
3131#include "ApplicationArguments.h"
3232#include "CachingNetworkManagerFactory.h"
33+#include "UnityCommandLineParser.h"
3334
3435// Ubuntu Gestures
3536#include <TouchRegistry.h>
@@ -45,42 +46,9 @@ int main(int argc, const char *argv[])
4546 QGuiApplication::setApplicationName("unity8");
4647 QGuiApplication *application;
4748
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−
73− QCommandLineOption modeOption("mode",
74− "Whether to run greeter and/or shell [full-greeter, full-shell, greeter, shell]",
75− "mode", "full-greeter");
76− parser.addOption(modeOption);
77−
7849 application = new QGuiApplication(argc, (char**)argv);
7950
80− // Treat args with single dashes the same as arguments with two dashes
81− // Ex: -fullscreen == --fullscreen
82− parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
83− parser.process(*application);
51+ UnityCommandLineParser parser(*application);
8452
8553 QString indicatorProfile = qgetenv("UNITY_INDICATOR_PROFILE");
8654 if (indicatorProfile.isEmpty()) {
@@ -88,36 +56,11 @@ Load the testability driver");
8856 }
8957
9058 ApplicationArguments qmlArgs;
91− if (parser.isSet(windowGeometryOption) &&
92− parser.value(windowGeometryOption).split('x').size() == 2)
93− {
94− QStringList geom = parser.value(windowGeometryOption).split('x');
95− qmlArgs.setSize(geom.at(0).toInt(), geom.at(1).toInt());
96− }
97−
98− // If an invalid option was specified, set it to the default
99− // If no default was provided in the QCommandLineOption constructor, abort.
100− QString shellMode;
101− if(!parser.isSet(modeOption) ||
102− (parser.value(modeOption) != "full-greeter" &&
103− parser.value(modeOption) != "full-shell" &&
104− parser.value(modeOption) != "greeter" &&
105− parser.value(modeOption) != "shell"))
106− {
107− if (modeOption.defaultValues().first() != nullptr) {
108− shellMode = modeOption.defaultValues().first();
109− qWarning() << "Mode argument was not provided or was set to an illegal value. Using default value of --mode=" << shellMode;
110− } else {
111− qFatal("Shell mode argument was not provided and there is no default mode,");
112− }
113−
114− } else {
115− shellMode = parser.value(modeOption);
116− }
59+ qmlArgs.setSize(parser.windowGeometry());
11760
11861 // The testability driver is only loaded by QApplication but not by QGuiApplication.
11962 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
120− if (parser.isSet(testabilityOption) || getenv("QT_LOAD_TESTABILITY")) {
63+ if (parser.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
12164 QLibrary testLib(QLatin1String("qttestability"));
12265 if (testLib.load()) {
12366 typedef void (*TasInitialize)(void);
@@ -142,8 +85,8 @@ Load the testability driver");
14285 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
14386 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
14487 view->rootContext()->setContextProperty("indicatorProfile", indicatorProfile);
145− view->rootContext()->setContextProperty("shellMode", shellMode);
146− if (parser.isSet(framelessOption)) {
88+ view->rootContext()->setContextProperty("shellMode", parser.mode());
89+ if (parser.hasFrameless()) {
14790 view->setFlags(Qt::FramelessWindowHint);
14891 }
14992 TouchRegistry touchRegistry;
@@ -152,7 +95,7 @@ Load the testability driver");
15295 // You will need this if you want to interact with touch-only components using a mouse
15396 // Needed only when manually testing on a desktop.
15497 MouseTouchAdaptor *mouseTouchAdaptor = 0;
155− if (parser.isSet(mousetouchOption)) {
98+ if (parser.hasMouseToTouch()) {
15699 mouseTouchAdaptor = MouseTouchAdaptor::instance();
157100 }
158101
@@ -169,7 +112,7 @@ Load the testability driver");
169112 view->setSource(source);
170113 QObject::connect(view->engine(), SIGNAL(quit()), application, SLOT(quit()));
171114
172− if (isMirServer || parser.isSet(fullscreenOption)) {
115+ if (isMirServer || parser.hasFullscreen()) {
173116 view->showFullScreen();
174117 } else {
175118 view->show();