2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
#ifndef UTILS_ENVIRONMENT_H
|
|
|
|
|
#define UTILS_ENVIRONMENT_H
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
#include "utils_global.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QList>
|
|
|
|
|
#include <QMap>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QStringList>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
namespace Utils {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT EnvironmentItem
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-23 10:35:23 +02:00
|
|
|
public:
|
2011-05-24 12:04:24 +02:00
|
|
|
EnvironmentItem(const QString &n, const QString &v)
|
2008-12-02 12:01:29 +01:00
|
|
|
: name(n), value(v), unset(false)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
QString name;
|
|
|
|
|
QString value;
|
|
|
|
|
bool unset;
|
|
|
|
|
|
2010-10-30 21:13:16 +02:00
|
|
|
bool operator==(const EnvironmentItem &other) const
|
2009-05-27 13:37:21 +02:00
|
|
|
{
|
2011-05-24 12:04:24 +02:00
|
|
|
return unset == other.unset && name == other.name && value == other.value;
|
2009-05-27 13:37:21 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-06 16:45:07 +01:00
|
|
|
static void sort(QList<EnvironmentItem> *list);
|
2011-05-24 12:04:24 +02:00
|
|
|
static QList<EnvironmentItem> fromStringList(const QStringList &list);
|
|
|
|
|
static QStringList toStringList(const QList<EnvironmentItem> &list);
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2011-05-24 12:04:24 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT Environment
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
public:
|
|
|
|
|
typedef QMap<QString, QString>::const_iterator const_iterator;
|
|
|
|
|
|
2011-05-24 12:04:24 +02:00
|
|
|
Environment() {}
|
|
|
|
|
explicit Environment(const QStringList &env);
|
2008-12-02 12:01:29 +01:00
|
|
|
static Environment systemEnvironment();
|
|
|
|
|
|
2009-01-13 17:25:09 +01:00
|
|
|
QStringList toStringList() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
QString value(const QString &key) const;
|
|
|
|
|
void set(const QString &key, const QString &value);
|
|
|
|
|
void unset(const QString &key);
|
2011-05-24 12:04:24 +02:00
|
|
|
void modify(const QList<EnvironmentItem> &list);
|
2011-02-15 15:32:20 +01:00
|
|
|
/// Return the Environment changes necessary to modify this into the other environment.
|
|
|
|
|
QList<EnvironmentItem> diff(const Environment &other) const;
|
2010-04-19 18:13:23 +02:00
|
|
|
bool hasKey(const QString &key);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-09-29 11:39:55 +02:00
|
|
|
void appendOrSet(const QString &key, const QString &value, const QString &sep = QString());
|
|
|
|
|
void prependOrSet(const QString &key, const QString &value, const QString &sep = QString());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
void appendOrSetPath(const QString &value);
|
|
|
|
|
void prependOrSetPath(const QString &value);
|
|
|
|
|
|
2011-04-29 13:25:25 +02:00
|
|
|
void prependOrSetLibrarySearchPath(const QString &value);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void clear();
|
|
|
|
|
int size() const;
|
|
|
|
|
|
|
|
|
|
QString key(Environment::const_iterator it) const;
|
|
|
|
|
QString value(Environment::const_iterator it) const;
|
|
|
|
|
|
|
|
|
|
Environment::const_iterator constBegin() const;
|
|
|
|
|
Environment::const_iterator constEnd() const;
|
2010-10-18 21:14:45 +02:00
|
|
|
Environment::const_iterator constFind(const QString &name) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-23 13:08:03 +02:00
|
|
|
QString searchInPath(const QString &executable,
|
2011-05-24 12:04:24 +02:00
|
|
|
const QStringList &additionalDirs = QStringList()) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
QStringList path() const;
|
|
|
|
|
|
2011-05-24 12:04:24 +02:00
|
|
|
QString expandVariables(const QString &input) const;
|
|
|
|
|
QStringList expandVariables(const QStringList &input) const;
|
2010-09-22 15:10:20 +02:00
|
|
|
|
2010-01-11 10:25:15 +01:00
|
|
|
bool operator!=(const Environment &other) const;
|
|
|
|
|
bool operator==(const Environment &other) const;
|
2011-05-24 12:04:24 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
private:
|
2012-09-11 13:56:08 +02:00
|
|
|
QString searchInDirectory(const QStringList &execs, QString directory) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
QMap<QString, QString> m_values;
|
|
|
|
|
};
|
|
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
} // namespace Utils
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
#endif // UTILS_ENVIRONMENT_H
|