21 #include <QCommandLineParser>
22 #include <QtQuick/QQuickView>
23 #include <QtGui/QGuiApplication>
24 #include <QtQml/QQmlEngine>
25 #include <QtQml/QQmlContext>
26 #include <qpa/qplatformnativeinterface.h>
35 #include "MouseTouchAdaptor.h"
36 #include "ApplicationArguments.h"
37 #include "CachingNetworkManagerFactory.h"
39 #include <unity-mir/qmirserver.h>
41 int startShell(
int argc,
const char** argv,
void* server)
43 const bool isUbuntuMirServer = qgetenv(
"QT_QPA_PLATFORM") ==
"ubuntumirserver";
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 if (isUbuntuMirServer) {
74 QLibrary unityMir(
"unity-mir", 1);
77 typedef QGuiApplication* (*createServerApplication_t)(
int&,
const char **,
void*);
78 createServerApplication_t createQMirServerApplication = (createServerApplication_t) unityMir.resolve(
"createQMirServerApplication");
79 if (!createQMirServerApplication) {
80 qDebug() <<
"unable to resolve symbol: createQMirServerApplication";
84 application = createQMirServerApplication(argc, argv, server);
86 application =
new QGuiApplication(argc, (
char**)argv);
91 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
92 parser.process(*application);
94 QString indicatorProfile = qgetenv(
"UNITY_INDICATOR_PROFILE");
95 if (indicatorProfile.isEmpty()) {
96 indicatorProfile =
"phone";
99 ApplicationArguments qmlArgs;
100 if (parser.isSet(windowGeometryOption) &&
101 parser.value(windowGeometryOption).split(
'x').size() == 2)
103 QStringList geom = parser.value(windowGeometryOption).split(
'x');
104 qmlArgs.setSize(geom.at(0).toInt(), geom.at(1).toInt());
109 if (parser.isSet(testabilityOption) || getenv(
"QT_LOAD_TESTABILITY")) {
110 QLibrary testLib(QLatin1String(
"qttestability"));
111 if (testLib.load()) {
112 typedef void (*TasInitialize)(void);
113 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
117 qCritical(
"Library qttestability resolve failed!");
120 qCritical(
"Library qttestability load failed!");
124 bindtextdomain(
"unity8", translationDirectory().toUtf8().data());
126 QQuickView* view =
new QQuickView();
127 view->setResizeMode(QQuickView::SizeRootObjectToView);
128 view->setTitle(
"Qml Phone Shell");
129 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
130 view->rootContext()->setContextProperty(
"applicationArguments", &qmlArgs);
131 view->rootContext()->setContextProperty(
"indicatorProfile", indicatorProfile);
132 if (parser.isSet(framelessOption)) {
133 view->setFlags(Qt::FramelessWindowHint);
138 MouseTouchAdaptor *mouseTouchAdaptor = 0;
139 if (parser.isSet(mousetouchOption)) {
140 mouseTouchAdaptor =
new MouseTouchAdaptor;
141 application->installNativeEventFilter(mouseTouchAdaptor);
144 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
150 nativeInterface->setProperty(
"ubuntuSessionType", 1);
151 view->setProperty(
"role", 2);
153 QUrl source(::qmlDirectory()+
"Shell.qml");
154 prependImportPaths(view->engine(), ::overrideImportPaths());
155 if (!isUbuntuMirServer) {
156 prependImportPaths(view->engine(), ::nonMirImportPaths());
158 appendImportPaths(view->engine(), ::fallbackImportPaths());
160 CachingNetworkManagerFactory *managerFactory =
new CachingNetworkManagerFactory();
161 view->engine()->setNetworkAccessManagerFactory(managerFactory);
163 view->setSource(source);
164 view->setColor(
"transparent");
165 QObject::connect(view->engine(), SIGNAL(quit()), application, SLOT(quit()));
167 if (qgetenv(
"QT_QPA_PLATFORM") ==
"ubuntu" || isUbuntuMirServer || parser.isSet(fullscreenOption)) {
168 view->showFullScreen();
173 int result = application->exec();
176 delete mouseTouchAdaptor;
182 int main(
int argc,
const char *argv[])
189 setenv(
"QML_FORCE_THREADED_RENDERER",
"1", 1);
190 setenv(
"QML_FIXED_ANIMATION_STEP",
"1", 1);
193 if (qgetenv(
"QT_QPA_PLATFORM").startsWith(
"ubuntumir")) {
194 setenv(
"QT_QPA_PLATFORM",
"ubuntumirserver", 1);
199 QLibrary unityMir(
"unity-mir", 1);
201 if (!unityMir.isLoaded()) {
202 qDebug() <<
"Library unity-mir not found/loaded";
206 typedef QMirServer* (*createServer_t)(int,
const char **);
207 createServer_t createQMirServer = (createServer_t) unityMir.resolve(
"createQMirServer");
208 if (!createQMirServer) {
209 qDebug() <<
"unable to resolve symbol: createQMirServer";
213 QMirServer* mirServer = createQMirServer(argc, argv);
215 typedef int (*runWithClient_t)(QMirServer*, std::function<int(int, const char**, void*)>);
216 runWithClient_t runWithClient = (runWithClient_t) unityMir.resolve(
"runQMirServerWithClient");
217 if (!runWithClient) {
218 qDebug() <<
"unable to resolve symbol: runWithClient";
222 return runWithClient(mirServer, startShell);
224 if (qgetenv(
"UPSTART_JOB") ==
"unity8") {
229 return startShell(argc, argv,
nullptr);