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>
34#include "MouseTouchAdaptor.h"
35#include "ApplicationArguments.h"
37#include <unity-mir/qmirserver.h>
41void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
43 QStringList importPathList = engine->importPathList();
44 for (int i = paths.count() -1; i >= 0; i--) {
46 const QString& path = paths[i];
47 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
48 if (iter == importPathList.end()) {
49 engine->addImportPath(path);
54/* When you append and import path to the list of import paths it will be the *last*
55 place where Qt will search for QML modules.
56 The usual QQmlEngine::addImportPath() actually prepends the given path.*/
57void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
59 QStringList importPathList = engine->importPathList();
60 Q_FOREACH(const QString& path, paths) {
62 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
63 if (iter == importPathList.end()) {
64 importPathList.append(path);
67 engine->setImportPathList(importPathList);
70void resolveIconTheme() {
71 const char *ubuntuIconTheme = getenv("UBUNTU_ICON_THEME");
72 if (ubuntuIconTheme == NULL) {
73 ubuntuIconTheme = "ubuntu-mobile";
75 QIcon::setThemeName(ubuntuIconTheme);
79int startShell(int argc, const char** argv, void* server)
81 /* Workaround Qt platform integration plugin not advertising itself
82 as having the following capabilities:
83 - QPlatformIntegration::ThreadedOpenGL
84 - QPlatformIntegration::BufferQueueingOpenGL
86 setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
87 setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
89 const bool isUbuntuMirServer = qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver";
91 QGuiApplication::setApplicationName("Unity 8");
92 QGuiApplication *application;
93 if (isUbuntuMirServer) {
94 QLibrary unityMir("unity-mir", 1);
97 typedef QGuiApplication* (*createServerApplication_t)(int&, const char **, void*);
98 createServerApplication_t createQMirServerApplication = (createServerApplication_t) unityMir.resolve("createQMirServerApplication");
99 if (!createQMirServerApplication) {
100 qDebug() << "unable to resolve symbol: createQMirServerApplication";
104 application = createQMirServerApplication(argc, argv, server);
106 application = new QGuiApplication(argc, (char**)argv);
111 QStringList args = application->arguments();
112 ApplicationArguments qmlArgs(args);
114 // The testability driver is only loaded by QApplication but not by QGuiApplication.
115 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
116 if (args.contains(QLatin1String("-testability"))) {
117 QLibrary testLib(QLatin1String("qttestability"));
118 if (testLib.load()) {
119 typedef void (*TasInitialize)(void);
120 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
124 qCritical("Library qttestability resolve failed!");
127 qCritical("Library qttestability load failed!");
131 bindtextdomain("unity8", translationDirectory().toUtf8().data());
133 QQuickView* view = new QQuickView();
134 view->setResizeMode(QQuickView::SizeRootObjectToView);
135 view->setTitle("Qml Phone Shell");
136 view->engine()->setBaseUrl(QUrl::fromLocalFile(::shellAppDirectory()));
137 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
138 if (args.contains(QLatin1String("-frameless"))) {
139 view->setFlags(Qt::FramelessWindowHint);
142 // You will need this if you want to interact with touch-only components using a mouse
143 // Needed only when manually testing on a desktop.
144 MouseTouchAdaptor *mouseTouchAdaptor = 0;
145 if (args.contains(QLatin1String("-mousetouch"))) {
146 mouseTouchAdaptor = new MouseTouchAdaptor;
147 mouseTouchAdaptor->setTargetWindow(view);
148 application->installNativeEventFilter(mouseTouchAdaptor);
151 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
152 /* Shell is declared as a system session so that it always receives all
154 FIXME: use the enum value corresponding to SYSTEM_SESSION_TYPE (= 1)
155 when it becomes available.
157 nativeInterface->setProperty("ubuntuSessionType", 1);
158 view->setProperty("role", 2); // INDICATOR_ACTOR_ROLE
160 QUrl source("Shell.qml");
161 prependImportPaths(view->engine(), ::overrideImportPaths());
162 appendImportPaths(view->engine(), ::fallbackImportPaths());
164 QStringList importPath = view->engine()->importPathList().filter("qt5/imports");
165 if (isUbuntuMirServer) {
166 importPath.first().append("/Unity-Mir");
167 view->engine()->addImportPath(importPath.first());
170 view->setSource(source);
171 view->setColor("transparent");
173 if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || args.contains(QLatin1String("-fullscreen"))) {
174 view->showFullScreen();
179 int result = application->exec();
181 delete mouseTouchAdaptor;
187int main(int argc, const char *argv[])
189 // For ubuntumirserver/ubuntumirclient
190 if (qgetenv("QT_QPA_PLATFORM").startsWith("ubuntumir")) {
191 setenv("QT_QPA_PLATFORM", "ubuntumirserver", 1);
193 // If we use unity-mir directly, we automatically link to the Mir-server
194 // platform-api bindings, which result in unexpected behaviour when
195 // running the non-Mir scenario.
196 QLibrary unityMir("unity-mir", 1);
198 if (!unityMir.isLoaded()) {
199 qDebug() << "Library unity-mir not found/loaded";
203 typedef QMirServer* (*createServer_t)(int, const char **);
204 createServer_t createQMirServer = (createServer_t) unityMir.resolve("createQMirServer");
205 if (!createQMirServer) {
206 qDebug() << "unable to resolve symbol: createQMirServer";
210 QMirServer* mirServer = createQMirServer(argc, argv);
212 typedef int (*runWithClient_t)(QMirServer*, std::function<int(int, const char**, void*)>);
213 runWithClient_t runWithClient = (runWithClient_t) unityMir.resolve("runQMirServerWithClient");
214 if (!runWithClient) {
215 qDebug() << "unable to resolve symbol: runWithClient";
219 return runWithClient(mirServer, startShell);
221 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