on 7f16e39 help sign in
unity8/include/paths.h.in
138 lines 4.3 kB history raw
1/*
2 * Copyright (C) 2012 Canonical, Ltd.
3 *
4 * Authors:
5 * Ugo Riboni <ugo.riboni@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
20#ifndef PATHS_H
21#define PATHS_H
23// Qt
24#include <QtCore/QCoreApplication>
25#include <QtCore/QDir>
26#include <QtGui/QIcon>
27#include <QtQml/QQmlEngine>
28#include <QStandardPaths>
30inline bool isRunningInstalled() {
31 static bool installed = (QCoreApplication::applicationDirPath() ==
32 QDir(("@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@")).canonicalPath());
33 return installed;
36inline QString translationDirectory() {
37 if (isRunningInstalled()) {
38 return QString("@CMAKE_INSTALL_PREFIX@/share/locale");
39 } else {
40 return QString("@CMAKE_BINARY_DIR@/po/locale");
41 }
44inline QString qmlDirectory() {
45 if (isRunningInstalled()) {
46 return QString("@CMAKE_INSTALL_PREFIX@/@SHELL_APP_DIR@/");
47 } else {
48 return QString("@CMAKE_SOURCE_DIR@/qml/");
49 }
52inline QStringList overrideImportPaths() {
53 QStringList paths;
54 if (!isRunningInstalled()) {
55 paths << QString("@CMAKE_BINARY_DIR@/plugins");
56 }
57 return paths;
60inline QStringList nonMirImportPaths() {
61 QStringList paths;
62 if (isRunningInstalled()) {
63 paths << QString("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/nonmirplugins");
64 } else {
65 paths << QString("@CMAKE_BINARY_DIR@/nonmirplugins");
66 }
67 return paths;
70inline QStringList fallbackImportPaths() {
71 QStringList paths;
72 if (isRunningInstalled()) {
73 paths << QString("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@");
74 paths << QString("@SHELL_PLUGINDIR@");
75 paths << QString("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
76 } else {
77 paths << QString("@SHELL_PLUGINDIR@");
78 paths << QString("@CMAKE_BINARY_DIR@/tests/mocks");
79 }
80 return paths;
83inline QString mockPluginsDir() {
84 if (isRunningInstalled()) {
85 return QString("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
86 } else {
87 return QString("@CMAKE_BINARY_DIR@/tests/mocks");
88 }
91inline QStringList shellDataDirs() {
92 QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
93 if (!isRunningInstalled()) {
94 if (getenv("UNITY_TEST_ENV")==nullptr) {
95 dirs.prepend("@CMAKE_BINARY_DIR@/share");
96 }
97 }
98 else {
99 // append so by default we use xdg files.
100 dirs.append(qmlDirectory());
101 }
102 return dirs;
105inline QString sourceDirectory() {
106 return QString("@CMAKE_SOURCE_DIR@/");
109inline void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
111 QStringList importPathList = engine->importPathList();
112 for (int i = paths.count() -1; i >= 0; i--) {
113 // don't duplicate
114 const QString& path = paths[i];
115 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
116 if (iter == importPathList.end()) {
117 engine->addImportPath(path);
118 }
119 }
122/* When you append and import path to the list of import paths it will be the *last*
123 place where Qt will search for QML modules.
124 The usual QQmlEngine::addImportPath() actually prepends the given path.*/
125inline void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
127 QStringList importPathList = engine->importPathList();
128 Q_FOREACH(const QString& path, paths) {
129 // don't duplicate
130 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
131 if (iter == importPathList.end()) {
132 importPathList.append(path);
133 }
134 }
135 engine->setImportPathList(importPathList);
138#endif