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>
36#include "MouseTouchAdaptor.h"
37#include "ApplicationArguments.h"
39#include <unity-mir/qmirserver.h>
43void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
45 QStringList importPathList = engine->importPathList();
46 for (int i = paths.count() -1; i >= 0; i--) {
48 const QString& path = paths[i];
49 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
50 if (iter == importPathList.end()) {
51 engine->addImportPath(path);
56/* When you append and import path to the list of import paths it will be the *last*
57 place where Qt will search for QML modules.
58 The usual QQmlEngine::addImportPath() actually prepends the given path.*/
59void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
61 QStringList importPathList = engine->importPathList();
62 Q_FOREACH(const QString& path, paths) {
64 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
65 if (iter == importPathList.end()) {
66 importPathList.append(path);
69 engine->setImportPathList(importPathList);
72void resolveIconTheme() {
73 const char *ubuntuIconTheme = getenv("UBUNTU_ICON_THEME");
74 if (ubuntuIconTheme == NULL) {
75 ubuntuIconTheme = "ubuntu-mobile";
77 QIcon::setThemeName(ubuntuIconTheme);
81int startShell(int argc, const char** argv, void* server)
83 const bool isUbuntuMirServer = qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver";
85 QGuiApplication::setApplicationName(APP_NAME);
86 QGuiApplication *application;
87 if (isUbuntuMirServer) {
88 QLibrary unityMir("unity-mir", 1);
91 typedef QGuiApplication* (*createServerApplication_t)(int&, const char **, void*);
92 createServerApplication_t createQMirServerApplication = (createServerApplication_t) unityMir.resolve("createQMirServerApplication");
93 if (!createQMirServerApplication) {
94 qDebug() << "unable to resolve symbol: createQMirServerApplication";
98 application = createQMirServerApplication(argc, argv, server);
100 application = new QGuiApplication(argc, (char**)argv);
105 QStringList args = application->arguments();
106 ApplicationArguments qmlArgs(args);
108 // The testability driver is only loaded by QApplication but not by QGuiApplication.
109 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
110 if (args.contains(QLatin1String("-testability")) || getenv("QT_LOAD_TESTABILITY")) {
111 QLibrary testLib(QLatin1String("qttestability"));
112 if (testLib.load()) {
113 typedef void (*TasInitialize)(void);
114 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
118 qCritical("Library qttestability resolve failed!");
121 qCritical("Library qttestability load failed!");
125 bindtextdomain("unity8", translationDirectory().toUtf8().data());
127 // Tell indicator plugin what profile to use
128 qputenv("UNITY8_INDICATOR_PROFILE", INDICATOR_PROFILE);
130 QQuickView* view = new QQuickView();
131 view->setResizeMode(QQuickView::SizeRootObjectToView);
132 view->setTitle("Qml Phone Shell");
133 view->engine()->setBaseUrl(QUrl::fromLocalFile(::shellAppDirectory()));
134 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
135 if (args.contains(QLatin1String("-frameless"))) {
136 view->setFlags(Qt::FramelessWindowHint);
139 // You will need this if you want to interact with touch-only components using a mouse
140 // Needed only when manually testing on a desktop.
141 MouseTouchAdaptor *mouseTouchAdaptor = 0;
142 if (args.contains(QLatin1String("-mousetouch"))) {
143 mouseTouchAdaptor = new MouseTouchAdaptor;
144 application->installNativeEventFilter(mouseTouchAdaptor);
147 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
148 /* Shell is declared as a system session so that it always receives all
150 FIXME: use the enum value corresponding to SYSTEM_SESSION_TYPE (= 1)
151 when it becomes available.
153 nativeInterface->setProperty("ubuntuSessionType", 1);
154 view->setProperty("role", 2); // INDICATOR_ACTOR_ROLE
156 QUrl source(QML_FILE);
157 prependImportPaths(view->engine(), ::overrideImportPaths());
158 appendImportPaths(view->engine(), ::fallbackImportPaths());
160 if (isUbuntuMirServer) {
161 QStringList importPaths = view->engine()->importPathList();
162 importPaths.replaceInStrings(QRegExp("qt5/imports$"), "qt5/imports/Unity-Mir");
163 view->engine()->setImportPathList(importPaths);
166 view->setSource(source);
168 // Make background transparent, so that the greeter can bleed through.
169 // In normal shell, the background is never seen.
170 QSurfaceFormat format;
171 format.setAlphaBufferSize(8);
172 view->setFormat(format);
173 view->setColor(Qt::transparent);
175 if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || args.contains(QLatin1String("-fullscreen"))) {
176 // First, size window equal to screen (fake a real WM fullscreen mode).
177 // Then, in case we are actually running inside a windowing system,
178 // nicely set actual WM fullscreen hint for its benefit.
179 view->resize(view->screen()->size());
180 view->showFullScreen();
185 int result = application->exec();
188 delete mouseTouchAdaptor;
194int main(int argc, const char *argv[])
196 /* Workaround Qt platform integration plugin not advertising itself
197 as having the following capabilities:
198 - QPlatformIntegration::ThreadedOpenGL
199 - QPlatformIntegration::BufferQueueingOpenGL
201 setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
202 setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
204 // For ubuntumirserver/ubuntumirclient
205 if (qgetenv("QT_QPA_PLATFORM").startsWith("ubuntumir")) {
206 setenv("QT_QPA_PLATFORM", "ubuntumirserver", 1);
208 // If we use unity-mir directly, we automatically link to the Mir-server
209 // platform-api bindings, which result in unexpected behaviour when
210 // running the non-Mir scenario.
211 QLibrary unityMir("unity-mir", 1);
213 if (!unityMir.isLoaded()) {
214 qDebug() << "Library unity-mir not found/loaded";
218 typedef QMirServer* (*createServer_t)(int, const char **);
219 createServer_t createQMirServer = (createServer_t) unityMir.resolve("createQMirServer");
220 if (!createQMirServer) {
221 qDebug() << "unable to resolve symbol: createQMirServer";
225 QMirServer* mirServer = createQMirServer(argc, argv);
227 typedef int (*runWithClient_t)(QMirServer*, std::function<int(int, const char**, void*)>);
228 runWithClient_t runWithClient = (runWithClient_t) unityMir.resolve("runQMirServerWithClient");
229 if (!runWithClient) {
230 qDebug() << "unable to resolve symbol: runWithClient";
234 return runWithClient(mirServer, startShell);
236 if (qgetenv("UPSTART_JOB") == "unity8") {
237 // Emit SIGSTOP as expected by upstart, under Mir it's unity-mir that will raise it.
238 // see http://upstart.ubuntu.com/cookbook/#expect-stop
241 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