@@ -30,6 +30,7 @@
30#include "MouseTouchAdaptor.h"
30#include "MouseTouchAdaptor.h"
31#include "ApplicationArguments.h"
31#include "ApplicationArguments.h"
32#include "CachingNetworkManagerFactory.h"
32#include "CachingNetworkManagerFactory.h"
33+#include "UnityCommandLineParser.h"
34// Ubuntu Gestures
35// Ubuntu Gestures
35#include <TouchRegistry.h>
36#include <TouchRegistry.h>
@@ -45,42 +46,9 @@ int main(int argc, const char *argv[])
45 QGuiApplication::setApplicationName("unity8");
46 QGuiApplication::setApplicationName("unity8");
46 QGuiApplication *application;
47 QGuiApplication *application;
48− QCommandLineParser parser;
49− parser.setApplicationDescription("Description: Unity 8 Shell");
50− parser.addHelpOption();
52− QCommandLineOption fullscreenOption("fullscreen",
53− "Run in fullscreen");
54− parser.addOption(fullscreenOption);
56− QCommandLineOption framelessOption("frameless",
57− "Run without window borders");
58− parser.addOption(framelessOption);
60− QCommandLineOption mousetouchOption("mousetouch",
61− "Allow the mouse to provide touch input");
62− parser.addOption(mousetouchOption);
64− QCommandLineOption windowGeometryOption(QStringList() << "windowgeometry",
65− "Specify the window geometry as [<width>x<height>]", "windowgeometry", "1");
66− parser.addOption(windowGeometryOption);
68− QCommandLineOption testabilityOption("testability",
69− "DISCOURAGED: Please set QT_LOAD_TESTABILITY instead. \n \
70−Load the testability driver");
71− parser.addOption(testabilityOption);
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);
78 application = new QGuiApplication(argc, (char**)argv);
49 application = new QGuiApplication(argc, (char**)argv);
80− // Treat args with single dashes the same as arguments with two dashes
51+ UnityCommandLineParser parser(*application);
81− // Ex: -fullscreen == --fullscreen
82− parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
83− parser.process(*application);
85 QString indicatorProfile = qgetenv("UNITY_INDICATOR_PROFILE");
53 QString indicatorProfile = qgetenv("UNITY_INDICATOR_PROFILE");
86 if (indicatorProfile.isEmpty()) {
54 if (indicatorProfile.isEmpty()) {
@@ -88,36 +56,10 @@ Load the testability driver");
90 ApplicationArguments qmlArgs;
58 ApplicationArguments qmlArgs;
91− if (parser.isSet(windowGeometryOption) &&
92− parser.value(windowGeometryOption).split('x').size() == 2)
94− QStringList geom = parser.value(windowGeometryOption).split('x');
95− qmlArgs.setSize(geom.at(0).toInt(), geom.at(1).toInt());
98− // If an invalid option was specified, set it to the default
99− // If no default was provided in the QCommandLineOption constructor, abort.
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"))
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;
111− qFatal("Shell mode argument was not provided and there is no default mode,");
115− shellMode = parser.value(modeOption);
118 // The testability driver is only loaded by QApplication but not by QGuiApplication.
60 // The testability driver is only loaded by QApplication but not by QGuiApplication.
119 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
61 // 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")) {
62+ if (parser.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
121 QLibrary testLib(QLatin1String("qttestability"));
63 QLibrary testLib(QLatin1String("qttestability"));
122 if (testLib.load()) {
64 if (testLib.load()) {
123 typedef void (*TasInitialize)(void);
65 typedef void (*TasInitialize)(void);
@@ -142,17 +84,21 @@ Load the testability driver");
142 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
84 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
143 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
85 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
144 view->rootContext()->setContextProperty("indicatorProfile", indicatorProfile);
86 view->rootContext()->setContextProperty("indicatorProfile", indicatorProfile);
145− view->rootContext()->setContextProperty("shellMode", shellMode);
87+ view->rootContext()->setContextProperty("shellMode", parser.mode());
146− if (parser.isSet(framelessOption)) {
88+ if (parser.hasFrameless()) {
147 view->setFlags(Qt::FramelessWindowHint);
89 view->setFlags(Qt::FramelessWindowHint);
149 TouchRegistry touchRegistry;
91 TouchRegistry touchRegistry;
150 view->installEventFilter(&touchRegistry);
92 view->installEventFilter(&touchRegistry);
93+ if (parser.windowGeometry().isValid()) {
94+ view->setWidth(parser.windowGeometry().width());
95+ view->setHeight(parser.windowGeometry().height());
152 // You will need this if you want to interact with touch-only components using a mouse
98 // You will need this if you want to interact with touch-only components using a mouse
153 // Needed only when manually testing on a desktop.
99 // Needed only when manually testing on a desktop.
154 MouseTouchAdaptor *mouseTouchAdaptor = 0;
100 MouseTouchAdaptor *mouseTouchAdaptor = 0;
155− if (parser.isSet(mousetouchOption)) {
101+ if (parser.hasMouseToTouch()) {
156 mouseTouchAdaptor = MouseTouchAdaptor::instance();
102 mouseTouchAdaptor = MouseTouchAdaptor::instance();
@@ -169,7 +115,7 @@ Load the testability driver");
169 view->setSource(source);
115 view->setSource(source);
170 QObject::connect(view->engine(), SIGNAL(quit()), application, SLOT(quit()));
116 QObject::connect(view->engine(), SIGNAL(quit()), application, SLOT(quit()));
172− if (isMirServer || parser.isSet(fullscreenOption)) {
118+ if (isMirServer || parser.hasFullscreen()) {
173 view->showFullScreen();
119 view->showFullScreen();
175 view->show();
121 view->show();