2 * Copyright (C) 2012-2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20#include <QtCore/QCoreApplication>
23#include <QtQml/QQmlEngine>
24#include <QStandardPaths>
26inline QString installRoot() {
27 static QString installRoot;
28 static bool installRootSet = false;
29 if (!installRootSet) {
30 QString snapRoot = QFile::decodeName(qgetenv("SNAP"));
31 if (!snapRoot.isEmpty() && QCoreApplication::applicationDirPath() ==
32 QDir(snapRoot + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@")).canonicalPath()) {
33 installRoot = snapRoot;
34 } else if (QCoreApplication::applicationDirPath() ==
35 QDir(QStringLiteral("@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@")).canonicalPath()) {
36 installRoot = QStringLiteral("");
38 installRootSet = true;
43inline bool isRunningInstalled() {
44 // Tests don't use the normal binary, so we want to check binary *and*
45 // the environment. Installed tests have UNITY_TESTING_DATADIR set.
46 static bool installed_test_env = !qgetenv("UNITY_TESTING_DATADIR").isEmpty();
47 return !installRoot().isNull() || installed_test_env;
50inline QString buildDirectory() {
51 if (!qEnvironmentVariableIsEmpty("UNITY_BINARY_DIR")) return qgetenv("UNITY_BINARY_DIR");
52 return QStringLiteral("@CMAKE_BINARY_DIR@");
55inline QString sourceDirectory() {
56 if (!qEnvironmentVariableIsEmpty("UNITY_SOURCE_DIR")) return qgetenv("UNITY_SOURCE_DIR");
57 return QStringLiteral("@CMAKE_SOURCE_DIR@");
60inline QString translationDirectory() {
61 if (isRunningInstalled()) {
62 return installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/share/locale");
64 return buildDirectory() + QStringLiteral("/po/locale");
68inline QString testDataDir() {
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 datadir(qgetenv("UNITY_TESTING_DATADIR"));
72 if (datadir.isEmpty()) {
73 return sourceDirectory() + "/tests";
75 return datadir + "/tests";
79inline QString testLibDir() {
80 // Can't use isRunningInstalled, since tests don't use the normal unity8
81 // executable. $UNITY_TESTING_DATADIR is set by installed tests.
82 QString libdir(qgetenv("UNITY_TESTING_LIBDIR"));
83 if (libdir.isEmpty()) {
84 return buildDirectory() + "/tests";
86 return libdir + "/tests";
90inline QString qmlDirectory() {
91 if (isRunningInstalled()) {
92 return installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_APP_DIR@/");
94 return sourceDirectory() + QStringLiteral("/qml");
98inline QStringList overrideImportPaths() {
100 if (!isRunningInstalled()) {
101 paths << buildDirectory() + QStringLiteral("/plugins");
106inline QStringList nonMirImportPaths() {
108 if (isRunningInstalled()) {
109 paths << installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/nonmirplugins");
111 paths << buildDirectory() + QStringLiteral("/nonmirplugins");
116inline QStringList fallbackImportPaths() {
118 if (isRunningInstalled()) {
119 paths << installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@");
120 paths << installRoot() + QStringLiteral("@USS_PRIVATE_PLUGINDIR@");
121 paths << installRoot() + QStringLiteral("@SHELL_PLUGINDIR@");
122 paths << installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
124 paths << QStringLiteral("@USS_PRIVATE_PLUGINDIR@");
125 paths << QStringLiteral("@SHELL_PLUGINDIR@");
126 paths << buildDirectory() + QStringLiteral("/tests/mocks");
131inline QString mockPluginsDir() {
132 if (isRunningInstalled()) {
133 return installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
135 return buildDirectory() + QStringLiteral("/tests/mocks");
139inline QStringList shellDataDirs() {
140 QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
141 if (isRunningInstalled()) {
142 // append so by default we use xdg files.
143 dirs.append(qmlDirectory());
148inline void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
150 QStringList importPathList = engine->importPathList();
151 for (int i = paths.count() -1; i >= 0; i--) {
153 const QString& path = paths[i];
154 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
155 if (iter == importPathList.end()) {
156 engine->addImportPath(path);
161/* When you append and import path to the list of import paths it will be the *last*
162 place where Qt will search for QML modules.
163 The usual QQmlEngine::addImportPath() actually prepends the given path.*/
164inline void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
166 QStringList importPathList = engine->importPathList();
167 Q_FOREACH(const QString& path, paths) {
169 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
170 if (iter == importPathList.end()) {
171 importPathList.append(path);
174 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