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 const bool isUbuntuMirServer = qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver";
83 QGuiApplication::setApplicationName("Unity 8");
84 QGuiApplication *application;
85 if (isUbuntuMirServer) {
86 QLibrary unityMir("unity-mir", 1);
89 typedef QGuiApplication* (*createServerApplication_t)(int&, const char **, void*);
90 createServerApplication_t createQMirServerApplication = (createServerApplication_t) unityMir.resolve("createQMirServerApplication");
91 if (!createQMirServerApplication) {
92 qDebug() << "unable to resolve symbol: createQMirServerApplication";
96 application = createQMirServerApplication(argc, argv, server);
98 application = new QGuiApplication(argc, (char**)argv);
103 QStringList args = application->arguments();
104 ApplicationArguments qmlArgs(args);
106 // The testability driver is only loaded by QApplication but not by QGuiApplication.
107 // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
108 if (args.contains(QLatin1String("-testability")) || getenv("QT_LOAD_TESTABILITY")) {
109 QLibrary testLib(QLatin1String("qttestability"));
110 if (testLib.load()) {
111 typedef void (*TasInitialize)(void);
112 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
116 qCritical("Library qttestability resolve failed!");
119 qCritical("Library qttestability load failed!");
123 bindtextdomain("unity8", translationDirectory().toUtf8().data());
125 QQuickView* view = new QQuickView();
126 view->setResizeMode(QQuickView::SizeRootObjectToView);
127 view->setTitle("Qml Phone Shell");
128 view->engine()->setBaseUrl(QUrl::fromLocalFile(::shellAppDirectory()));
129 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
130 if (args.contains(QLatin1String("-frameless"))) {
131 view->setFlags(Qt::FramelessWindowHint);
134 // You will need this if you want to interact with touch-only components using a mouse
135 // Needed only when manually testing on a desktop.
136 MouseTouchAdaptor *mouseTouchAdaptor = 0;
137 if (args.contains(QLatin1String("-mousetouch"))) {
138 mouseTouchAdaptor = new MouseTouchAdaptor;
139 application->installNativeEventFilter(mouseTouchAdaptor);
142 QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
143 /* Shell is declared as a system session so that it always receives all
145 FIXME: use the enum value corresponding to SYSTEM_SESSION_TYPE (= 1)
146 when it becomes available.
148 nativeInterface->setProperty("ubuntuSessionType", 1);
149 view->setProperty("role", 2); // INDICATOR_ACTOR_ROLE
151 QUrl source("Shell.qml");
152 prependImportPaths(view->engine(), ::overrideImportPaths());
153 appendImportPaths(view->engine(), ::fallbackImportPaths());
155 if (isUbuntuMirServer) {
156 QStringList importPaths = view->engine()->importPathList();
157 importPaths.replaceInStrings(QRegExp("qt5/imports$"), "qt5/imports/Unity-Mir");
158 view->engine()->setImportPathList(importPaths);
161 view->setSource(source);
162 view->setColor("transparent");
164 if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || args.contains(QLatin1String("-fullscreen"))) {
165 view->showFullScreen();
170 int result = application->exec();
173 delete mouseTouchAdaptor;
179int main(int argc, const char *argv[])
181 /* Workaround Qt platform integration plugin not advertising itself
182 as having the following capabilities:
183 - QPlatformIntegration::ThreadedOpenGL
184 - QPlatformIntegration::BufferQueueingOpenGL
186 setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
187 setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
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