2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-04-24 15:49:09 +02: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
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-04-24 15:49:09 +02: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.
|
2012-04-24 15:49:09 +02: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.
|
2012-04-24 15:49:09 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2012-04-24 15:49:09 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include "kit.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
|
|
|
|
|
#include "devicesupport/devicemanager.h"
|
2012-09-03 18:31:44 +02:00
|
|
|
#include "kitinformation.h"
|
|
|
|
|
#include "kitmanager.h"
|
2012-07-02 15:28:36 +02:00
|
|
|
#include "project.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
#include "toolchainmanager.h"
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QIcon>
|
|
|
|
|
#include <QStyle>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QUuid>
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
const char ID_KEY[] = "PE.Profile.Id";
|
|
|
|
|
const char DISPLAYNAME_KEY[] = "PE.Profile.Name";
|
|
|
|
|
const char AUTODETECTED_KEY[] = "PE.Profile.AutoDetected";
|
|
|
|
|
const char DATA_KEY[] = "PE.Profile.Data";
|
|
|
|
|
const char ICON_KEY[] = "PE.Profile.Icon";
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
2012-10-04 14:40:29 +02:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// Helper:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
static QString cleanName(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
QString result = name;
|
|
|
|
|
result.replace(QRegExp("\\W"), QLatin1String("_"));
|
|
|
|
|
result.replace(QRegExp("_+"), "_"); // compact _
|
|
|
|
|
result.remove(QRegExp("^_*")); // remove leading _
|
|
|
|
|
result.remove(QRegExp("_+$")); // remove trailing _
|
|
|
|
|
if (result.isEmpty())
|
|
|
|
|
result = QLatin1String("unknown");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
// -------------------------------------------------------------------------
|
2012-09-03 18:31:44 +02:00
|
|
|
// KitPrivate
|
2012-04-24 15:49:09 +02:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
class KitPrivate
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2012-10-11 11:40:56 +02:00
|
|
|
KitPrivate(Core::Id id) :
|
|
|
|
|
m_id(id),
|
2012-04-24 15:49:09 +02:00
|
|
|
m_autodetected(false),
|
|
|
|
|
m_isValid(true)
|
2012-10-11 11:40:56 +02:00
|
|
|
{
|
|
|
|
|
if (!id.isValid())
|
|
|
|
|
m_id = Core::Id(QUuid::createUuid().toString().toLatin1().constData());
|
|
|
|
|
}
|
2012-04-24 15:49:09 +02:00
|
|
|
|
|
|
|
|
QString m_displayName;
|
|
|
|
|
Core::Id m_id;
|
|
|
|
|
bool m_autodetected;
|
|
|
|
|
bool m_isValid;
|
|
|
|
|
QIcon m_icon;
|
|
|
|
|
QString m_iconPath;
|
|
|
|
|
|
|
|
|
|
QHash<Core::Id, QVariant> m_data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
2012-09-03 18:31:44 +02:00
|
|
|
// Kit:
|
2012-04-24 15:49:09 +02:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
2012-10-11 11:40:56 +02:00
|
|
|
Kit::Kit(Core::Id id) :
|
|
|
|
|
d(new Internal::KitPrivate(id))
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
KitManager *stm = KitManager::instance();
|
|
|
|
|
foreach (KitInformation *sti, stm->kitInformation())
|
2012-04-24 15:49:09 +02:00
|
|
|
d->m_data.insert(sti->dataId(), sti->defaultValue(this));
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
setDisplayName(QCoreApplication::translate("ProjectExplorer::Kit", "Unnamed"));
|
2012-04-24 15:49:09 +02:00
|
|
|
setIconPath(QLatin1String(":///DESKTOP///"));
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
Kit::~Kit()
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-06-28 15:38:23 +02:00
|
|
|
delete d;
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
Kit *Kit::clone(bool keepName) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-09 20:41:30 +03:00
|
|
|
Kit *k = new Kit;
|
2012-08-07 13:09:56 +02:00
|
|
|
if (keepName)
|
2012-09-09 20:41:30 +03:00
|
|
|
k->d->m_displayName = d->m_displayName;
|
2012-08-07 13:09:56 +02:00
|
|
|
else
|
2012-09-09 20:41:30 +03:00
|
|
|
k->d->m_displayName = QCoreApplication::translate("ProjectExplorer::Kit", "Clone of %1")
|
2012-08-07 13:09:56 +02:00
|
|
|
.arg(d->m_displayName);
|
2012-09-09 20:41:30 +03:00
|
|
|
k->d->m_autodetected = false;
|
|
|
|
|
k->d->m_data = d->m_data;
|
|
|
|
|
k->d->m_isValid = d->m_isValid;
|
|
|
|
|
k->d->m_icon = d->m_icon;
|
|
|
|
|
k->d->m_iconPath = d->m_iconPath;
|
|
|
|
|
return k;
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
bool Kit::isValid() const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
return d->m_id.isValid() && d->m_isValid;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
QList<Task> Kit::validate()
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
QList<Task> result;
|
2012-09-03 18:31:44 +02:00
|
|
|
QList<KitInformation *> infoList = KitManager::instance()->kitInformation();
|
|
|
|
|
foreach (KitInformation *i, infoList)
|
2012-04-24 15:49:09 +02:00
|
|
|
result.append(i->validate(this));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
QString Kit::displayName() const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
return d->m_displayName;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-07 13:09:56 +02:00
|
|
|
static QString candidateName(const QString &name, const QString &postfix)
|
|
|
|
|
{
|
|
|
|
|
if (name.contains(postfix))
|
|
|
|
|
return QString();
|
|
|
|
|
return name + QLatin1Char('-') + postfix;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
void Kit::setDisplayName(const QString &name)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-09 20:41:30 +03:00
|
|
|
KitManager *km = KitManager::instance();
|
|
|
|
|
QList<KitInformation *> kitInfo = km->kitInformation();
|
2012-08-07 13:09:56 +02:00
|
|
|
|
2012-07-02 15:28:36 +02:00
|
|
|
QStringList nameList;
|
2012-09-09 20:41:30 +03:00
|
|
|
foreach (Kit *k, km->kits()) {
|
|
|
|
|
if (k == this)
|
2012-09-05 14:16:14 +02:00
|
|
|
continue;
|
2012-09-09 20:41:30 +03:00
|
|
|
nameList << k->displayName();
|
2012-09-03 18:31:44 +02:00
|
|
|
foreach (KitInformation *ki, kitInfo) {
|
2012-09-09 20:41:30 +03:00
|
|
|
const QString postfix = ki->displayNamePostfix(k);
|
2012-08-07 13:09:56 +02:00
|
|
|
if (!postfix.isEmpty())
|
2012-09-09 20:41:30 +03:00
|
|
|
nameList << candidateName(k->displayName(), postfix);
|
2012-08-07 13:09:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList candidateNames;
|
|
|
|
|
candidateNames << name;
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
foreach (KitInformation *ki, kitInfo) {
|
|
|
|
|
const QString postfix = ki->displayNamePostfix(this);
|
2012-08-07 13:09:56 +02:00
|
|
|
if (!postfix.isEmpty())
|
|
|
|
|
candidateNames << candidateName(name, postfix);
|
|
|
|
|
}
|
2012-07-02 15:28:36 +02:00
|
|
|
|
|
|
|
|
QString uniqueName = Project::makeUnique(name, nameList);
|
|
|
|
|
if (uniqueName != name) {
|
2012-08-07 13:09:56 +02:00
|
|
|
foreach (const QString &candidate, candidateNames) {
|
|
|
|
|
const QString tmp = Project::makeUnique(candidate, nameList);
|
|
|
|
|
if (tmp == candidate) {
|
|
|
|
|
uniqueName = tmp;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-02 15:28:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d->m_displayName == uniqueName)
|
2012-04-24 15:49:09 +02:00
|
|
|
return;
|
2012-07-02 15:28:36 +02:00
|
|
|
d->m_displayName = uniqueName;
|
2012-09-03 18:31:44 +02:00
|
|
|
kitUpdated();
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-04 14:40:29 +02:00
|
|
|
QString Kit::fileSystemFriendlyName() const
|
|
|
|
|
{
|
|
|
|
|
QString name = cleanName(displayName());
|
|
|
|
|
foreach (Kit *i, KitManager::instance()->kits()) {
|
|
|
|
|
if (i == this)
|
|
|
|
|
continue;
|
|
|
|
|
if (name == cleanName(i->displayName())) {
|
|
|
|
|
// append part of the kit id: That should be unique enough;-)
|
|
|
|
|
// Leading { will be turned into _ which should be fine.
|
|
|
|
|
name = cleanName(name + QLatin1Char('_') + (id().toString().left(7)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
bool Kit::isAutoDetected() const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
return d->m_autodetected;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
Core::Id Kit::id() const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
return d->m_id;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
QIcon Kit::icon() const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
return d->m_icon;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
QString Kit::iconPath() const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
return d->m_iconPath;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
void Kit::setIconPath(const QString &path)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
if (d->m_iconPath == path)
|
|
|
|
|
return;
|
|
|
|
|
d->m_iconPath = path;
|
|
|
|
|
if (path.isNull())
|
|
|
|
|
d->m_icon = QIcon();
|
|
|
|
|
else if (path == QLatin1String(":///DESKTOP///"))
|
|
|
|
|
d->m_icon = qApp->style()->standardIcon(QStyle::SP_ComputerIcon);
|
|
|
|
|
else
|
|
|
|
|
d->m_icon = QIcon(path);
|
2012-09-03 18:31:44 +02:00
|
|
|
kitUpdated();
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
QVariant Kit::value(const Core::Id &key, const QVariant &unset) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
return d->m_data.value(key, unset);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
bool Kit::hasValue(const Core::Id &key) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
return d->m_data.contains(key);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
void Kit::setValue(const Core::Id &key, const QVariant &value)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
if (d->m_data.value(key) == value)
|
|
|
|
|
return;
|
|
|
|
|
d->m_data.insert(key, value);
|
2012-09-03 18:31:44 +02:00
|
|
|
kitUpdated();
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
void Kit::removeKey(const Core::Id &key)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
if (!d->m_data.contains(key))
|
|
|
|
|
return;
|
|
|
|
|
d->m_data.remove(key);
|
2012-09-03 18:31:44 +02:00
|
|
|
kitUpdated();
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
QVariantMap Kit::toMap() const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
QVariantMap data;
|
|
|
|
|
data.insert(QLatin1String(ID_KEY), QString::fromLatin1(d->m_id.name()));
|
|
|
|
|
data.insert(QLatin1String(DISPLAYNAME_KEY), d->m_displayName);
|
|
|
|
|
data.insert(QLatin1String(AUTODETECTED_KEY), d->m_autodetected);
|
|
|
|
|
data.insert(QLatin1String(ICON_KEY), d->m_iconPath);
|
|
|
|
|
|
|
|
|
|
QVariantMap extra;
|
|
|
|
|
foreach (const Core::Id &key, d->m_data.keys())
|
|
|
|
|
extra.insert(QString::fromLatin1(key.name().constData()), d->m_data.value(key));
|
|
|
|
|
data.insert(QLatin1String(DATA_KEY), extra);
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
bool Kit::operator==(const Kit &other) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
return d->m_data == other.d->m_data;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
void Kit::addToEnvironment(Utils::Environment &env) const
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
QList<KitInformation *> infoList = KitManager::instance()->kitInformation();
|
|
|
|
|
foreach (KitInformation *ki, infoList)
|
|
|
|
|
ki->addToEnvironment(this, env);
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
QString Kit::toHtml()
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
QString rc;
|
|
|
|
|
QTextStream str(&rc);
|
|
|
|
|
str << "<html><body>";
|
|
|
|
|
str << "<h3>" << displayName() << "</h3>";
|
|
|
|
|
str << "<table>";
|
|
|
|
|
|
|
|
|
|
if (!isValid()) {
|
|
|
|
|
QList<Task> issues = validate();
|
|
|
|
|
str << "<p>";
|
|
|
|
|
foreach (const Task &t, issues) {
|
|
|
|
|
str << "<b>";
|
|
|
|
|
switch (t.type) {
|
|
|
|
|
case Task::Error:
|
2012-09-03 18:31:44 +02:00
|
|
|
QCoreApplication::translate("ProjectExplorer::Kit", "Error:");
|
2012-04-24 15:49:09 +02:00
|
|
|
break;
|
|
|
|
|
case Task::Warning:
|
2012-09-03 18:31:44 +02:00
|
|
|
QCoreApplication::translate("ProjectExplorer::Kit", "Warning:");
|
2012-04-24 15:49:09 +02:00
|
|
|
break;
|
|
|
|
|
case Task::Unknown:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
str << "</b>" << t.description << "<br>";
|
|
|
|
|
}
|
|
|
|
|
str << "</p>";
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
QList<KitInformation *> infoList = KitManager::instance()->kitInformation();
|
|
|
|
|
foreach (KitInformation *ki, infoList) {
|
|
|
|
|
KitInformation::ItemList list = ki->toUserOutput(this);
|
|
|
|
|
foreach (const KitInformation::Item &j, list)
|
2012-04-24 15:49:09 +02:00
|
|
|
str << "<tr><td><b>" << j.first << ":</b></td><td>" << j.second << "</td></tr>";
|
|
|
|
|
}
|
|
|
|
|
str << "</table></body></html>";
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
bool Kit::fromMap(const QVariantMap &data)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
const QString id = data.value(QLatin1String(ID_KEY)).toString();
|
|
|
|
|
if (id.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
d->m_id = Core::Id(id);
|
|
|
|
|
d->m_displayName = data.value(QLatin1String(DISPLAYNAME_KEY)).toString();
|
|
|
|
|
d->m_autodetected = data.value(QLatin1String(AUTODETECTED_KEY)).toBool();
|
|
|
|
|
setIconPath(data.value(QLatin1String(ICON_KEY)).toString());
|
|
|
|
|
|
|
|
|
|
QVariantMap extra = data.value(QLatin1String(DATA_KEY)).toMap();
|
|
|
|
|
foreach (const QString &key, extra.keys())
|
|
|
|
|
d->m_data.insert(Core::Id(key), extra.value(key));
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
void Kit::setAutoDetected(bool detected)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
d->m_autodetected = detected;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
void Kit::setValid(bool valid)
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
|
|
|
|
d->m_isValid = valid;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
void Kit::kitUpdated()
|
2012-04-24 15:49:09 +02:00
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
KitManager::instance()->notifyAboutUpdate(this);
|
2012-04-24 15:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ProjectExplorer
|