on bbccae6 help sign in
unity8/include/paths.h.in
141 lines 4.6 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(QStringLiteral("@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@")).canonicalPath());
33 return installed;
36inline QString buildDirectory() {
37 if (!qEnvironmentVariableIsEmpty("UNITY_BINARY_DIR")) return qgetenv("UNITY_BINARY_DIR");
38 return QStringLiteral("@CMAKE_BINARY_DIR@");
41inline QString sourceDirectory() {
42 if (!qEnvironmentVariableIsEmpty("UNITY_SOURCE_DIR")) return qgetenv("UNITY_SOURCE_DIR");
43 return QStringLiteral("@CMAKE_SOURCE_DIR@");
46inline QString translationDirectory() {
47 if (isRunningInstalled()) {
48 return QStringLiteral("@CMAKE_INSTALL_PREFIX@/share/locale");
49 } else {
50 return QString(buildDirectory() + "/po/locale");
51 }
54inline QString qmlDirectory() {
55 if (isRunningInstalled()) {
56 return QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_APP_DIR@/");
57 } else {
58 return QString(sourceDirectory() + "/qml");
59 }
62inline QStringList overrideImportPaths() {
63 QStringList paths;
64 if (!isRunningInstalled()) {
65 paths << QString(buildDirectory() + "/plugins");
66 }
67 return paths;
70inline QStringList nonMirImportPaths() {
71 QStringList paths;
72 if (isRunningInstalled()) {
73 paths << QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/nonmirplugins");
74 } else {
75 paths << QString(buildDirectory() + "/nonmirplugins");
76 }
77 return paths;
80inline QStringList fallbackImportPaths() {
81 QStringList paths;
82 if (isRunningInstalled()) {
83 paths << QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@");
84 paths << QStringLiteral("@USS_PRIVATE_PLUGINDIR@");
85 paths << QStringLiteral("@SHELL_PLUGINDIR@");
86 paths << QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
87 } else {
88 paths << QStringLiteral("@USS_PRIVATE_PLUGINDIR@");
89 paths << QStringLiteral("@SHELL_PLUGINDIR@");
90 paths << QString(buildDirectory() + "/tests/mocks");
91 }
92 return paths;
95inline QString mockPluginsDir() {
96 if (isRunningInstalled()) {
97 return QStringLiteral("@CMAKE_INSTALL_PREFIX@/@SHELL_INSTALL_QML@/mocks");
98 } else {
99 return QString(buildDirectory() + "/tests/mocks");
100 }
103inline QStringList shellDataDirs() {
104 QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
105 if (isRunningInstalled()) {
106 // append so by default we use xdg files.
107 dirs.append(qmlDirectory());
108 }
109 return dirs;
112inline void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
114 QStringList importPathList = engine->importPathList();
115 for (int i = paths.count() -1; i >= 0; i--) {
116 // don't duplicate
117 const QString& path = paths[i];
118 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
119 if (iter == importPathList.end()) {
120 engine->addImportPath(path);
121 }
122 }
125/* When you append and import path to the list of import paths it will be the *last*
126 place where Qt will search for QML modules.
127 The usual QQmlEngine::addImportPath() actually prepends the given path.*/
128inline void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
130 QStringList importPathList = engine->importPathList();
131 Q_FOREACH(const QString& path, paths) {
132 // don't duplicate
133 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
134 if (iter == importPathList.end()) {
135 importPathList.append(path);
136 }
137 }
138 engine->setImportPathList(importPathList);
141#endif