on 83de736 help sign in
unity8/src/main.cpp
142 lines 4.9 kB history raw
1/*
2 * Copyright (C) 2012-2015 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17// Qt
18#include <QCommandLineParser>
19#include <QtQuick/QQuickView>
20#include <QtGui/QGuiApplication>
21#include <QtQml/QQmlEngine>
22#include <QtQml/QQmlContext>
23#include <QLibrary>
24#include <QDebug>
25#include <QScreen>
26#include <csignal>
27#include <libintl.h>
29// libandroid-properties
30#include <hybris/properties/properties.h>
32// local
33#include <paths.h>
34#include "MouseTouchAdaptor.h"
35#include "ApplicationArguments.h"
36#include "CachingNetworkManagerFactory.h"
37#include "UnityCommandLineParser.h"
39int main(int argc, const char *argv[])
41 bool isMirServer = false;
42 if (qgetenv("QT_QPA_PLATFORM") == "ubuntumirclient") {
43 setenv("QT_QPA_PLATFORM", "mirserver", 1 /* overwrite */);
44 isMirServer = true;
45 }
47 QGuiApplication::setApplicationName("unity8");
48 QGuiApplication *application;
50 application = new QGuiApplication(argc, (char**)argv);
52 UnityCommandLineParser parser(*application);
54 ApplicationArguments qmlArgs;
56 if (!parser.deviceName().isEmpty()) {
57 qmlArgs.setDeviceName(parser.deviceName());
58 } else {
59 char buffer[200];
60 property_get("ro.product.device", buffer /* value */, "desktop" /* default_value*/);
61 qmlArgs.setDeviceName(QString(buffer));
62 }
64 qmlArgs.setMode(parser.mode());
66 // The testability driver is only loaded by QApplication but not by QGuiApplication.
67 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
68 if (parser.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
69 QLibrary testLib(QLatin1String("qttestability"));
70 if (testLib.load()) {
71 typedef void (*TasInitialize)(void);
72 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
73 if (initFunction) {
74 initFunction();
75 } else {
76 qCritical("Library qttestability resolve failed!");
77 }
78 } else {
79 qCritical("Library qttestability load failed!");
80 }
81 }
83 bindtextdomain("unity8", translationDirectory().toUtf8().data());
84 textdomain("unity8");
86 QQuickView* view = new QQuickView();
87 view->setResizeMode(QQuickView::SizeRootObjectToView);
88 view->setColor("black");
89 view->setTitle("Unity8 Shell");
91 if (parser.windowGeometry().isValid()) {
92 view->setWidth(parser.windowGeometry().width());
93 view->setHeight(parser.windowGeometry().height());
94 }
96 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
97 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
98 if (parser.hasFrameless()) {
99 view->setFlags(Qt::FramelessWindowHint);
100 }
102 // You will need this if you want to interact with touch-only components using a mouse
103 // Needed only when manually testing on a desktop.
104 MouseTouchAdaptor *mouseTouchAdaptor = 0;
105 if (parser.hasMouseToTouch()) {
106 mouseTouchAdaptor = MouseTouchAdaptor::instance();
107 }
109 QUrl source(::qmlDirectory()+"OrientedShell.qml");
110 prependImportPaths(view->engine(), ::overrideImportPaths());
111 if (!isMirServer) {
112 prependImportPaths(view->engine(), ::nonMirImportPaths());
113 }
114 appendImportPaths(view->engine(), ::fallbackImportPaths());
116 CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
117 view->engine()->setNetworkAccessManagerFactory(managerFactory);
119 view->setSource(source);
120 QObject::connect(view->engine(), &QQmlEngine::quit, application, &QGuiApplication::quit);
122 // FIXME: This is a workaround to make the greeter fullscreen as
123 // view->showFullScreen() doesn't work quite right
124 if (parser.mode().compare("greeter") == 0) {
125 QSize primaryScreenSize = application->primaryScreen()->size();
126 view->setHeight(primaryScreenSize.height());
127 view->setWidth(primaryScreenSize.width());
128 view->show();
129 } else if (isMirServer || parser.hasFullscreen()) {
130 view->showFullScreen();
131 } else {
132 view->show();
133 }
135 int result = application->exec();
137 delete view;
138 delete mouseTouchAdaptor;
139 delete application;
141 return result;