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