20 #include <QtCore/QCoreApplication> 21 #include <QtCore/QDir> 22 #include <QtGui/QIcon> 23 #include <QtQml/QQmlEngine> 24 #include <QStandardPaths> 26 inline 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(
"/usr/bin")).canonicalPath()) {
33 installRoot = snapRoot;
34 }
else if (QCoreApplication::applicationDirPath() ==
35 QDir(QStringLiteral(
"/usr/bin")).canonicalPath()) {
36 installRoot = QStringLiteral(
"");
38 installRootSet =
true;
43 inline bool isRunningInstalled() {
46 static bool installed_test_env = !qgetenv(
"UNITY_TESTING_DATADIR").isEmpty();
47 return !installRoot().isNull() || installed_test_env;
50 inline QString buildDirectory() {
51 if (!qEnvironmentVariableIsEmpty(
"UNITY_BINARY_DIR"))
return qgetenv(
"UNITY_BINARY_DIR");
52 return QStringLiteral(
"/build/unity8-8.20+ubports+0~20220817202516.186~1.gbp35a211/obj-x86_64-linux-gnu");
55 inline QString sourceDirectory() {
56 if (!qEnvironmentVariableIsEmpty(
"UNITY_SOURCE_DIR"))
return qgetenv(
"UNITY_SOURCE_DIR");
57 return QStringLiteral(
"/build/unity8-8.20+ubports+0~20220817202516.186~1.gbp35a211");
60 inline QString translationDirectory() {
61 if (isRunningInstalled()) {
62 return installRoot() + QStringLiteral(
"/usr/share/locale");
64 return buildDirectory() + QStringLiteral(
"/po/locale");
68 inline QString testDataDir() {
71 QString datadir(qgetenv(
"UNITY_TESTING_DATADIR"));
72 if (datadir.isEmpty()) {
73 return sourceDirectory() +
"/tests";
75 return datadir +
"/tests";
79 inline QString testLibDir() {
82 QString libdir(qgetenv(
"UNITY_TESTING_LIBDIR"));
83 if (libdir.isEmpty()) {
84 return buildDirectory() +
"/tests";
86 return libdir +
"/tests";
90 inline QString qmlDirectory() {
91 if (isRunningInstalled()) {
92 return installRoot() + QStringLiteral(
"/usr/share/unity8/");
94 return sourceDirectory() + QStringLiteral(
"/qml");
98 inline QStringList overrideImportPaths() {
100 if (!isRunningInstalled()) {
101 paths << buildDirectory() + QStringLiteral(
"/plugins");
106 inline QStringList nonMirImportPaths() {
108 if (isRunningInstalled()) {
109 paths << installRoot() + QStringLiteral(
"/usr/lib/x86_64-linux-gnu/unity8/qml/nonmirplugins");
111 paths << buildDirectory() + QStringLiteral(
"/nonmirplugins");
116 inline QStringList fallbackImportPaths() {
118 if (isRunningInstalled()) {
119 paths << installRoot() + QStringLiteral(
"/usr/lib/x86_64-linux-gnu/unity8/qml");
120 paths << installRoot() + QStringLiteral(
"/usr/lib/x86_64-linux-gnu/ubuntu-system-settings/private");
121 paths << installRoot() + QStringLiteral(
"/usr/lib/x86_64-linux-gnu/unity8/qml");
122 paths << installRoot() + QStringLiteral(
"/usr/lib/x86_64-linux-gnu/unity8/qml/mocks");
124 paths << QStringLiteral(
"/usr/lib/x86_64-linux-gnu/ubuntu-system-settings/private");
125 paths << QStringLiteral(
"/usr/lib/x86_64-linux-gnu/unity8/qml");
126 paths << buildDirectory() + QStringLiteral(
"/tests/mocks");
131 inline QString mockPluginsDir() {
132 if (isRunningInstalled()) {
133 return installRoot() + QStringLiteral(
"/usr/lib/x86_64-linux-gnu/unity8/qml/mocks");
135 return buildDirectory() + QStringLiteral(
"/tests/mocks");
139 inline QStringList shellDataDirs() {
140 QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
141 if (isRunningInstalled()) {
143 dirs.append(qmlDirectory());
148 inline 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);
164 inline 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);