on xenial_-_blue-light-filter help sign in
unity8/include/paths.h.in
150 lines 5.2 kB history raw
1/*
2 * Copyright (C) 2012-2016 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17#pragma once
19// Qt
20#include <QtCore/QCoreApplication>
21#include <QtCore/QDir>
22#include <QtGui/QIcon>
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("");
37 }
38 installRootSet = true;
39 }
40 return installRoot;
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");
60 } else {
61 return buildDirectory() + QStringLiteral("/po/locale");
62 }
65inline QString qmlDirectory() {
66 if (isRunningInstalled()) {
67 return installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_APP_DIR@/");
68 } else {
69 return sourceDirectory() + QStringLiteral("/qml");
70 }
73inline QStringList overrideImportPaths() {
74 QStringList paths;
75 if (!isRunningInstalled()) {
76 paths << buildDirectory() + QStringLiteral("/plugins");
77 }
78 return paths;
81inline QStringList nonMirImportPaths() {
82 QStringList paths;
83 if (isRunningInstalled()) {
84 paths << installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/nonmirplugins");
85 } else {
86 paths << buildDirectory() + QStringLiteral("/nonmirplugins");
87 }
88 return paths;
91inline QStringList fallbackImportPaths() {
92 QStringList paths;
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");
98 } else {
99 paths << QStringLiteral("@USS_PRIVATE_PLUGINDIR@");
100 paths << QStringLiteral("@SHELL_PLUGINDIR@");
101 paths << buildDirectory() + QStringLiteral("/tests/mocks");
102 }
103 return paths;
106inline QString mockPluginsDir() {
107 if (isRunningInstalled()) {
108 return installRoot() + QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
109 } else {
110 return buildDirectory() + QStringLiteral("/tests/mocks");
111 }
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());
119 }
120 return dirs;
123inline void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
125 QStringList importPathList = engine->importPathList();
126 for (int i = paths.count() -1; i >= 0; i--) {
127 // don't duplicate
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);
132 }
133 }
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) {
143 // don't duplicate
144 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
145 if (iter == importPathList.end()) {
146 importPathList.append(path);
147 }
148 }
149 engine->setImportPathList(importPathList);