18 #include <QCommandLineParser>
19 #include <QtQuick/QQuickView>
20 #include <QtGui/QGuiApplication>
21 #include <QtQml/QQmlEngine>
22 #include <QtQml/QQmlContext>
30 #include "MouseTouchAdaptor.h"
31 #include "ApplicationArguments.h"
32 #include "CachingNetworkManagerFactory.h"
35 #include <TouchRegistry.h>
37 int main(
int argc,
const char *argv[])
39 bool isMirServer =
false;
40 if (qgetenv(
"QT_QPA_PLATFORM") ==
"ubuntumirclient") {
41 setenv(
"QT_QPA_PLATFORM",
"mirserver", 1 );
45 QGuiApplication::setApplicationName(
"unity8");
46 QGuiApplication *application;
48 QCommandLineParser parser;
49 parser.setApplicationDescription(
"Description: Unity 8 Shell");
50 parser.addHelpOption();
52 QCommandLineOption fullscreenOption(
"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);
82 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
83 parser.process(*application);
85 QString indicatorProfile = qgetenv(
"UNITY_INDICATOR_PROFILE");
86 if (indicatorProfile.isEmpty()) {
87 indicatorProfile =
"phone";
90 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());
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);
120 if (parser.isSet(testabilityOption) || getenv(
"QT_LOAD_TESTABILITY")) {
121 QLibrary testLib(QLatin1String(
"qttestability"));
122 if (testLib.load()) {
123 typedef void (*TasInitialize)(void);
124 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
128 qCritical(
"Library qttestability resolve failed!");
131 qCritical(
"Library qttestability load failed!");
135 bindtextdomain(
"unity8", translationDirectory().toUtf8().data());
136 textdomain(
"unity8");
138 QQuickView* view =
new QQuickView();
139 view->setResizeMode(QQuickView::SizeRootObjectToView);
140 view->setColor(
"black");
141 view->setTitle(
"Unity8 Shell");
142 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
143 view->rootContext()->setContextProperty(
"applicationArguments", &qmlArgs);
144 view->rootContext()->setContextProperty(
"indicatorProfile", indicatorProfile);
145 view->rootContext()->setContextProperty(
"shellMode", shellMode);
146 if (parser.isSet(framelessOption)) {
147 view->setFlags(Qt::FramelessWindowHint);
149 TouchRegistry touchRegistry;
150 view->installEventFilter(&touchRegistry);
154 MouseTouchAdaptor *mouseTouchAdaptor = 0;
155 if (parser.isSet(mousetouchOption)) {
156 mouseTouchAdaptor = MouseTouchAdaptor::instance();
159 QUrl source(::qmlDirectory()+
"Shell.qml");
160 prependImportPaths(view->engine(), ::overrideImportPaths());
162 prependImportPaths(view->engine(), ::nonMirImportPaths());
164 appendImportPaths(view->engine(), ::fallbackImportPaths());
166 CachingNetworkManagerFactory *managerFactory =
new CachingNetworkManagerFactory();
167 view->engine()->setNetworkAccessManagerFactory(managerFactory);
169 view->setSource(source);
170 QObject::connect(view->engine(), SIGNAL(quit()), application, SLOT(quit()));
172 if (isMirServer || parser.isSet(fullscreenOption)) {
173 view->showFullScreen();
178 int result = application->exec();
181 delete mouseTouchAdaptor;