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 return !installRoot().isNull();
47inline QString buildDirectory() {
48 if (!qEnvironmentVariableIsEmpty("UNITY_BINARY_DIR")) return qgetenv("UNITY_BINARY_DIR");
49 return QStringLiteral("@CMAKE_BINARY_DIR@");
52inline QString sourceDirectory() {
53 if (!qEnvironmentVariableIsEmpty("UNITY_SOURCE_DIR")) return qgetenv("UNITY_SOURCE_DIR");
54 return QStringLiteral("@CMAKE_SOURCE_DIR@");
57inline QString translationDirectory() {
58 if (isRunningInstalled()) {
59 return installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/share/locale");
61 return buildDirectory() + QStringLiteral("/po/locale");
65inline QString qmlDirectory() {
66 if (isRunningInstalled()) {
67 return installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_APP_DIR@/");
69 return sourceDirectory() + QStringLiteral("/qml");
73inline QStringList overrideImportPaths() {
75 if (!isRunningInstalled()) {
76 paths << buildDirectory() + QStringLiteral("/plugins");
81inline QStringList nonMirImportPaths() {
83 if (isRunningInstalled()) {
84 paths << installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/nonmirplugins");
86 paths << buildDirectory() + QStringLiteral("/nonmirplugins");
91inline QStringList fallbackImportPaths() {
93 if (isRunningInstalled()) {
94 paths << installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@");
95 paths << installRoot() + QStringLiteral("@USS_PRIVATE_PLUGINDIR@");
96 paths << installRoot() + QStringLiteral("@SHELL_PLUGINDIR@");
97 paths << installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
99 paths << QStringLiteral("@USS_PRIVATE_PLUGINDIR@");
100 paths << QStringLiteral("@SHELL_PLUGINDIR@");
101 paths << buildDirectory() + QStringLiteral("/tests/mocks");
106inline QString mockPluginsDir() {
107 if (isRunningInstalled()) {
108 return installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
110 return buildDirectory() + QStringLiteral("/tests/mocks");
114inline QStringList shellDataDirs() {
115 QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
116 if (isRunningInstalled()) {
117 // append so by default we use xdg files.
118 dirs.append(qmlDirectory());
123inline void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
125 QStringList importPathList = engine->importPathList();
126 for (int i = paths.count() -1; i >= 0; i--) {
128 const QString& path = paths[i];
129 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
130 if (iter == importPathList.end()) {
131 engine->addImportPath(path);
136/* When you append and import path to the list of import paths it will be the *last*
137 place where Qt will search for QML modules.
138 The usual QQmlEngine::addImportPath() actually prepends the given path.*/
139inline void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
141 QStringList importPathList = engine->importPathList();
142 Q_FOREACH(const QString& path, paths) {
144 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
145 if (iter == importPathList.end()) {
146 importPathList.append(path);
149 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