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(
"/usr/bin")).canonicalPath()) {
33 installRoot = snapRoot;
34 }
else if (QCoreApplication::applicationDirPath() ==
35 QDir(QStringLiteral(
"/usr/bin")).canonicalPath()) {
36 installRoot = QStringLiteral(
"");
38 installRootSet =
true;
43inline bool isRunningInstalled() {
46 static bool installed_test_env = !qgetenv(
"LOMIRI_TESTING_DATADIR").isEmpty();
47 return !installRoot().isNull() || installed_test_env;
50inline QString buildDirectory() {
51 if (!qEnvironmentVariableIsEmpty(
"LOMIRI_BINARY_DIR"))
return qgetenv(
"LOMIRI_BINARY_DIR");
52 return QStringLiteral(
"/build/lomiri-wiwFwJ/lomiri-0.2.1/obj-x86_64-linux-gnu");
55inline QString sourceDirectory() {
56 if (!qEnvironmentVariableIsEmpty(
"LOMIRI_SOURCE_DIR"))
return qgetenv(
"LOMIRI_SOURCE_DIR");
57 return QStringLiteral(
"/build/lomiri-wiwFwJ/lomiri-0.2.1");
60inline QString translationDirectory() {
61 if (isRunningInstalled()) {
62 return installRoot() + QStringLiteral(
"/usr/share/locale");
64 return buildDirectory() + QStringLiteral(
"/po/locale");
68inline QString testDataDir() {
71 QString datadir(qgetenv(
"LOMIRI_TESTING_DATADIR"));
72 if (datadir.isEmpty()) {
73 return sourceDirectory() +
"/tests";
75 return datadir +
"/tests";
79inline QString testLibDir() {
82 QString libdir(qgetenv(
"LOMIRI_TESTING_LIBEXECDIR"));
83 if (libdir.isEmpty()) {
84 return buildDirectory() +
"/tests";
86 return libdir +
"/tests";
90inline QString qmlDirectory() {
91 if (isRunningInstalled()) {
92 return installRoot() + QStringLiteral(
"/usr/share/lomiri/");
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(
"/usr/lib/x86_64-linux-gnu/lomiri/qml/nonmirplugins");
111 paths << buildDirectory() + QStringLiteral(
"/nonmirplugins");
116inline QStringList fallbackImportPaths() {
118 if (isRunningInstalled()) {
119 paths << installRoot() + QStringLiteral(
"/usr/lib/x86_64-linux-gnu/lomiri/qml");
120 paths << installRoot() + QStringLiteral(
"/usr/lib/x86_64-linux-gnu/lomiri-system-settings/private");
121 paths << installRoot() + QStringLiteral(
"/usr/lib/x86_64-linux-gnu/lomiri/qml");
122 paths << installRoot() + QStringLiteral(
"/usr/lib/x86_64-linux-gnu/lomiri/qml/mocks");
124 paths << QStringLiteral(
"/usr/lib/x86_64-linux-gnu/lomiri-system-settings/private");
125 paths << QStringLiteral(
"/usr/lib/x86_64-linux-gnu/lomiri/qml");
126 paths << buildDirectory() + QStringLiteral(
"/tests/mocks");
131inline QString mockPluginsDir() {
132 if (isRunningInstalled()) {
133 return installRoot() + QStringLiteral(
"/usr/lib/x86_64-linux-gnu/lomiri/qml/mocks");
135 return buildDirectory() + QStringLiteral(
"/tests/mocks");
139inline QStringList shellDataDirs() {
140 QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
141 if (isRunningInstalled()) {
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 = std::find(importPathList.begin(), importPathList.end(), path);
155 if (iter == importPathList.end()) {
156 engine->addImportPath(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 = std::find(importPathList.begin(), importPathList.end(), path);
170 if (iter == importPathList.end()) {
171 importPathList.append(path);
174 engine->setImportPathList(importPathList);