2 * Copyright (C) 2012 Canonical, Ltd.
5 * Ugo Riboni <ugo.riboni@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/>.
24#include <QtCore/QCoreApplication>
27#include <QtQml/QQmlEngine>
28#include <QStandardPaths>
30inline bool isRunningInstalled() {
31 // Tests don't use the normal binary, so we want to check binary *and*
32 // the environment. Installed tests have UNITY_TESTING_DATADIR set.
33 static bool installed = (QCoreApplication::applicationDirPath() ==
34 QDir(QStringLiteral("@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@")).canonicalPath());
35 static bool installed_test_env = !qgetenv("UNITY_TESTING_DATADIR").isEmpty();
36 return installed || installed_test_env;
39inline QString buildDirectory() {
40 if (!qEnvironmentVariableIsEmpty("UNITY_BINARY_DIR")) return qgetenv("UNITY_BINARY_DIR");
41 return QStringLiteral("@CMAKE_BINARY_DIR@");
44inline QString sourceDirectory() {
45 if (!qEnvironmentVariableIsEmpty("UNITY_SOURCE_DIR")) return qgetenv("UNITY_SOURCE_DIR");
46 return QStringLiteral("@CMAKE_SOURCE_DIR@");
49inline QString translationDirectory() {
50 if (isRunningInstalled()) {
51 return QStringLiteral("@CMAKE_INSTALL_PREFIX@/share/locale");
53 return QString(buildDirectory() + "/po/locale");
57inline QString testDataDir() {
58 // Can't use isRunningInstalled, since tests don't use the normal unity8
59 // executable. $UNITY_TESTING_DATADIR is set by installed tests.
60 QString datadir(qgetenv("UNITY_TESTING_DATADIR"));
61 if (datadir.isEmpty()) {
62 return sourceDirectory() + "/tests";
64 return datadir + "/tests";
68inline QString testLibDir() {
69 // Can't use isRunningInstalled, since tests don't use the normal unity8
70 // executable. $UNITY_TESTING_DATADIR is set by installed tests.
71 QString libdir(qgetenv("UNITY_TESTING_LIBDIR"));
72 if (libdir.isEmpty()) {
73 return buildDirectory() + "/tests";
75 return libdir + "/tests";
79inline QString qmlDirectory() {
80 if (isRunningInstalled()) {
81 return QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_APP_DIR@/");
83 return QString(sourceDirectory() + "/qml");
87inline QStringList overrideImportPaths() {
89 if (!isRunningInstalled()) {
90 paths << QString(buildDirectory() + "/plugins");
95inline QStringList nonMirImportPaths() {
97 if (isRunningInstalled()) {
98 paths << QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/nonmirplugins");
100 paths << QString(buildDirectory() + "/nonmirplugins");
105inline QStringList fallbackImportPaths() {
107 if (isRunningInstalled()) {
108 paths << QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@");
109 paths << QStringLiteral("@USS_PRIVATE_PLUGINDIR@");
110 paths << QStringLiteral("@SHELL_PLUGINDIR@");
111 paths << QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
113 paths << QStringLiteral("@USS_PRIVATE_PLUGINDIR@");
114 paths << QStringLiteral("@SHELL_PLUGINDIR@");
115 paths << QString(buildDirectory() + "/tests/mocks");
120inline QString mockPluginsDir() {
121 if (isRunningInstalled()) {
122 return QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
124 return QString(buildDirectory() + "/tests/mocks");
128inline QStringList shellDataDirs() {
129 QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
130 if (isRunningInstalled()) {
131 // append so by default we use xdg files.
132 dirs.append(qmlDirectory());
137inline void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
139 QStringList importPathList = engine->importPathList();
140 for (int i = paths.count() -1; i >= 0; i--) {
142 const QString& path = paths[i];
143 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
144 if (iter == importPathList.end()) {
145 engine->addImportPath(path);
150/* When you append and import path to the list of import paths it will be the *last*
151 place where Qt will search for QML modules.
152 The usual QQmlEngine::addImportPath() actually prepends the given path.*/
153inline void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
155 QStringList importPathList = engine->importPathList();
156 Q_FOREACH(const QString& path, paths) {
158 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
159 if (iter == importPathList.end()) {
160 importPathList.append(path);
163 engine->setImportPathList(importPathList);
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