2 * Copyright (C) 2012 Canonical, Ltd.
5 * Gerry Boland <gerry.boland@canonical.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include <QtQuick/QQuickView>
23#include <QtGui/QGuiApplication>
24#include <QtGui/QScreen>
25#include <QtQml/QQmlEngine>
26#include <QtQml/QQmlContext>
27#include <qpa/qplatformnativeinterface.h>
35#include "MouseTouchAdaptor.h"
36#include "ApplicationArguments.h"
38#include <unity-mir/qmirserver.h>
42void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
44 QStringList importPathList = engine->importPathList();
45 for (int i = paths.count() -1; i >= 0; i--) {
47 const QString& path = paths[i];
48 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
49 if (iter == importPathList.end()) {
50 engine->addImportPath(path);
55/* When you append and import path to the list of import paths it will be the *last*
56 place where Qt will search for QML modules.
57 The usual QQmlEngine::addImportPath() actually prepends the given path.*/
58void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
60 QStringList importPathList = engine->importPathList();
61 Q_FOREACH(const QString& path, paths) {
63 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
64 if (iter == importPathList.end()) {
65 importPathList.append(path);
68 engine->setImportPathList(importPathList);
71void resolveIconTheme() {
72 const char *ubuntuIconTheme = getenv("UBUNTU_ICON_THEME");
73 if (ubuntuIconTheme == NULL) {
74 ubuntuIconTheme = "ubuntu-mobile";
76 QIcon::setThemeName(ubuntuIconTheme);
80int startShell(int argc, const char** argv, void* server)
82 const bool isUbuntuMirServer = qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver";
84 QGuiApplication::setApplicationName(APP_NAME);
85 QGuiApplication *application;
86 if (isUbuntuMirServer) {
87 QLibrary unityMir("unity-mir", 1);
90 typedef QGuiApplication* (*createServerApplication_t)(int&, const char **, void*);
91 createServerApplication_t createQMirServerApplication = (createServerApplication_t) unityMir.resolve("createQMirServerApplication");
92 if (!createQMirServerApplication) {
93 qDebug() << "unable to resolve symbol: createQMirServerApplication";
97 application = createQMirServerApplication(argc, argv, server);
99 application = new QGuiApplication(argc, (char**)argv);
104 QStringList args = application->arguments();
105 ApplicationArguments qmlArgs(args);
107 // The testability driver is only loaded by QApplication but not by QGuiApplication.
108 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
109 if (args.contains(QLatin1String("-testability")) || 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(::shellAppDirectory()));
130 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
131 view->rootContext()->setContextProperty("unity8IndicatorMode", INDICATOR_MODE);
132 if (args.contains(QLatin1String("-frameless"))) {
133 view->setFlags(Qt::FramelessWindowHint);
136 // You will need this if you want to interact with touch-only components using a mouse
137 // Needed only when manually testing on a desktop.
138 MouseTouchAdaptor *mouseTouchAdaptor = 0;
139 if (args.contains(QLatin1String("-mousetouch"))) {
140 mouseTouchAdaptor = new MouseTouchAdaptor;
141 application->installNativeEventFilter(mouseTouchAdaptor);
144 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
145 /* Shell is declared as a system session so that it always receives all
147 FIXME: use the enum value corresponding to SYSTEM_SESSION_TYPE (= 1)
148 when it becomes available.
150 nativeInterface->setProperty("ubuntuSessionType", 1);
151 view->setProperty("role", 2); // INDICATOR_ACTOR_ROLE
153 QUrl source(QML_FILE);
154 prependImportPaths(view->engine(), ::overrideImportPaths());
155 appendImportPaths(view->engine(), ::fallbackImportPaths());
157 if (isUbuntuMirServer) {
158 QStringList importPaths = view->engine()->importPathList();
159 importPaths.replaceInStrings(QRegExp("qt5/imports$"), "qt5/imports/Unity-Mir");
160 view->engine()->setImportPathList(importPaths);
163 view->setSource(source);
165 // Make background transparent, so that the greeter can bleed through.
166 // In normal shell, the background is never seen.
167 QSurfaceFormat format;
168 format.setAlphaBufferSize(8);
169 view->setFormat(format);
170 view->setColor(Qt::transparent);
172 if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || args.contains(QLatin1String("-fullscreen"))) {
173 // First, size window equal to screen (fake a real WM fullscreen mode).
174 // Then, in case we are actually running inside a windowing system,
175 // nicely set actual WM fullscreen hint for its benefit.
176 view->resize(view->screen()->size());
177 view->showFullScreen();
182 int result = application->exec();
185 delete mouseTouchAdaptor;
191int main(int argc, const char *argv[])
193 /* Workaround Qt platform integration plugin not advertising itself
194 as having the following capabilities:
195 - QPlatformIntegration::ThreadedOpenGL
196 - QPlatformIntegration::BufferQueueingOpenGL
198 setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
199 setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
201 // For ubuntumirserver/ubuntumirclient
202 if (qgetenv("QT_QPA_PLATFORM").startsWith("ubuntumir")) {
203 setenv("QT_QPA_PLATFORM", "ubuntumirserver", 1);
205 // If we use unity-mir directly, we automatically link to the Mir-server
206 // platform-api bindings, which result in unexpected behaviour when
207 // running the non-Mir scenario.
208 QLibrary unityMir("unity-mir", 1);
210 if (!unityMir.isLoaded()) {
211 qDebug() << "Library unity-mir not found/loaded";
215 typedef QMirServer* (*createServer_t)(int, const char **);
216 createServer_t createQMirServer = (createServer_t) unityMir.resolve("createQMirServer");
217 if (!createQMirServer) {
218 qDebug() << "unable to resolve symbol: createQMirServer";
222 QMirServer* mirServer = createQMirServer(argc, argv);
224 typedef int (*runWithClient_t)(QMirServer*, std::function<int(int, const char**, void*)>);
225 runWithClient_t runWithClient = (runWithClient_t) unityMir.resolve("runQMirServerWithClient");
226 if (!runWithClient) {
227 qDebug() << "unable to resolve symbol: runWithClient";
231 return runWithClient(mirServer, startShell);
233 return startShell(argc, argv, nullptr);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list