on f702be0 help sign in
unity8/src/main.cpp
123 lines 4.2 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 <csignal>
26#include <libintl.h>
28// local
29#include <paths.h>
30#include "MouseTouchAdaptor.h"
31#include "ApplicationArguments.h"
32#include "CachingNetworkManagerFactory.h"
33#include "UnityCommandLineParser.h"
35int main(int argc, const char *argv[])
37 bool isMirServer = false;
38 if (qgetenv("QT_QPA_PLATFORM") == "ubuntumirclient") {
39 setenv("QT_QPA_PLATFORM", "mirserver", 1 /* overwrite */);
40 isMirServer = true;
41 }
43 QGuiApplication::setApplicationName("unity8");
44 QGuiApplication *application;
46 application = new QGuiApplication(argc, (char**)argv);
48 UnityCommandLineParser parser(*application);
50 QString indicatorProfile = qgetenv("UNITY_INDICATOR_PROFILE");
51 if (indicatorProfile.isEmpty()) {
52 indicatorProfile = "phone";
53 }
55 ApplicationArguments qmlArgs;
56 qmlArgs.setSize(parser.windowGeometry());
58 // The testability driver is only loaded by QApplication but not by QGuiApplication.
59 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
60 if (parser.hasTestability() || getenv("QT_LOAD_TESTABILITY")) {
61 QLibrary testLib(QLatin1String("qttestability"));
62 if (testLib.load()) {
63 typedef void (*TasInitialize)(void);
64 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
65 if (initFunction) {
66 initFunction();
67 } else {
68 qCritical("Library qttestability resolve failed!");
69 }
70 } else {
71 qCritical("Library qttestability load failed!");
72 }
73 }
75 bindtextdomain("unity8", translationDirectory().toUtf8().data());
76 textdomain("unity8");
78 QQuickView* view = new QQuickView();
79 view->setResizeMode(QQuickView::SizeRootObjectToView);
80 view->setColor("black");
81 view->setTitle("Unity8 Shell");
82 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
83 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
84 view->rootContext()->setContextProperty("indicatorProfile", indicatorProfile);
85 view->rootContext()->setContextProperty("shellMode", parser.mode());
86 if (parser.hasFrameless()) {
87 view->setFlags(Qt::FramelessWindowHint);
88 }
90 // You will need this if you want to interact with touch-only components using a mouse
91 // Needed only when manually testing on a desktop.
92 MouseTouchAdaptor *mouseTouchAdaptor = 0;
93 if (parser.hasMouseToTouch()) {
94 mouseTouchAdaptor = MouseTouchAdaptor::instance();
95 }
97 QUrl source(::qmlDirectory()+"Shell.qml");
98 prependImportPaths(view->engine(), ::overrideImportPaths());
99 if (!isMirServer) {
100 prependImportPaths(view->engine(), ::nonMirImportPaths());
101 }
102 appendImportPaths(view->engine(), ::fallbackImportPaths());
104 CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
105 view->engine()->setNetworkAccessManagerFactory(managerFactory);
107 view->setSource(source);
108 QObject::connect(view->engine(), SIGNAL(quit()), application, SLOT(quit()));
110 if (isMirServer || parser.hasFullscreen()) {
111 view->showFullScreen();
112 } else {
113 view->show();
114 }
116 int result = application->exec();
118 delete view;
119 delete mouseTouchAdaptor;
120 delete application;
122 return result;