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 <QtQml/QQmlEngine>
25#include <QtQml/QQmlContext>
26#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("Unity 8");
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 if (args.contains(QLatin1String("-frameless"))) {
132 view->setFlags(Qt::FramelessWindowHint);
135 // You will need this if you want to interact with touch-only components using a mouse
136 // Needed only when manually testing on a desktop.
137 MouseTouchAdaptor *mouseTouchAdaptor = 0;
138 if (args.contains(QLatin1String("-mousetouch"))) {
139 mouseTouchAdaptor = new MouseTouchAdaptor;
140 application->installNativeEventFilter(mouseTouchAdaptor);
143 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
144 /* Shell is declared as a system session so that it always receives all
146 FIXME: use the enum value corresponding to SYSTEM_SESSION_TYPE (= 1)
147 when it becomes available.
149 nativeInterface->setProperty("ubuntuSessionType", 1);
150 view->setProperty("role", 2); // INDICATOR_ACTOR_ROLE
152 QUrl source("Shell.qml");
153 prependImportPaths(view->engine(), ::overrideImportPaths());
154 appendImportPaths(view->engine(), ::fallbackImportPaths());
156 if (isUbuntuMirServer) {
157 QStringList importPaths = view->engine()->importPathList();
158 importPaths.replaceInStrings(QRegExp("qt5/imports$"), "qt5/imports/Unity-Mir");
159 view->engine()->setImportPathList(importPaths);
162 view->setSource(source);
163 view->setColor("transparent");
165 if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || args.contains(QLatin1String("-fullscreen"))) {
166 view->showFullScreen();
171 int result = application->exec();
174 delete mouseTouchAdaptor;
180int main(int argc, const char *argv[])
182 /* Workaround Qt platform integration plugin not advertising itself
183 as having the following capabilities:
184 - QPlatformIntegration::ThreadedOpenGL
185 - QPlatformIntegration::BufferQueueingOpenGL
187 setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
188 setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
190 // For ubuntumirserver/ubuntumirclient
191 if (qgetenv("QT_QPA_PLATFORM").startsWith("ubuntumir")) {
192 setenv("QT_QPA_PLATFORM", "ubuntumirserver", 1);
194 // If we use unity-mir directly, we automatically link to the Mir-server
195 // platform-api bindings, which result in unexpected behaviour when
196 // running the non-Mir scenario.
197 QLibrary unityMir("unity-mir", 1);
199 if (!unityMir.isLoaded()) {
200 qDebug() << "Library unity-mir not found/loaded";
204 typedef QMirServer* (*createServer_t)(int, const char **);
205 createServer_t createQMirServer = (createServer_t) unityMir.resolve("createQMirServer");
206 if (!createQMirServer) {
207 qDebug() << "unable to resolve symbol: createQMirServer";
211 QMirServer* mirServer = createQMirServer(argc, argv);
213 typedef int (*runWithClient_t)(QMirServer*, std::function<int(int, const char**, void*)>);
214 runWithClient_t runWithClient = (runWithClient_t) unityMir.resolve("runQMirServerWithClient");
215 if (!runWithClient) {
216 qDebug() << "unable to resolve symbol: runWithClient";
220 return runWithClient(mirServer, startShell);
222 if (qgetenv("UPSTART_JOB") == "unity8") {
223 // Emit SIGSTOP as expected by upstart, under Mir it's unity-mir that will raise it.
224 // see http://upstart.ubuntu.com/cookbook/#expect-stop
227 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