qtkitinformation.cpp 7.56 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Tobias Hunger's avatar
Tobias Hunger committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
Tobias Hunger's avatar
Tobias Hunger committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Tobias Hunger's avatar
Tobias Hunger committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** 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.
Tobias Hunger's avatar
Tobias Hunger committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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
Tobias Hunger's avatar
Tobias Hunger committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
Tobias Hunger's avatar
Tobias Hunger committed
29

Tobias Hunger's avatar
Tobias Hunger committed
30
#include "qtkitinformation.h"
Tobias Hunger's avatar
Tobias Hunger committed
31

Tobias Hunger's avatar
Tobias Hunger committed
32
#include "qtkitconfigwidget.h"
33
#include "qtsupportconstants.h"
Tobias Hunger's avatar
Tobias Hunger committed
34
#include "qtversionmanager.h"
35
#include "qtparser.h"
Tobias Hunger's avatar
Tobias Hunger committed
36 37

#include <utils/environment.h>
38
#include <utils/qtcassert.h>
Tobias Hunger's avatar
Tobias Hunger committed
39 40 41 42 43 44

namespace QtSupport {
namespace Internal {
const char QT_INFORMATION[] = "QtSupport.QtInformation";
} // namespace Internal

Tobias Hunger's avatar
Tobias Hunger committed
45
QtKitInformation::QtKitInformation()
Tobias Hunger's avatar
Tobias Hunger committed
46
{
Tobias Hunger's avatar
Tobias Hunger committed
47
    setObjectName(QLatin1String("QtKitInformation"));
48 49
    connect(ProjectExplorer::KitManager::instance(), SIGNAL(kitsLoaded()),
            this, SLOT(kitsWereLoaded()));
Tobias Hunger's avatar
Tobias Hunger committed
50 51
}

Tobias Hunger's avatar
Tobias Hunger committed
52
Core::Id QtKitInformation::dataId() const
Tobias Hunger's avatar
Tobias Hunger committed
53 54 55 56 57
{
    static Core::Id id = Core::Id(Internal::QT_INFORMATION);
    return id;
}

Tobias Hunger's avatar
Tobias Hunger committed
58
unsigned int QtKitInformation::priority() const
Tobias Hunger's avatar
Tobias Hunger committed
59 60 61 62
{
    return 26000;
}

63
QVariant QtKitInformation::defaultValue(ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
64
{
65
    Q_UNUSED(k);
Tobias Hunger's avatar
Tobias Hunger committed
66 67 68 69 70 71 72 73 74 75
    QtVersionManager *mgr = QtVersionManager::instance();

    // find "Qt in PATH":
    Utils::Environment env = Utils::Environment::systemEnvironment();
    Utils::FileName qmake = Utils::FileName::fromString(env.searchInPath(QLatin1String("qmake")));

    if (qmake.isEmpty())
        return -1;

    QList<BaseQtVersion *> versionList = mgr->versions();
76
    BaseQtVersion *fallBack = 0;
Tobias Hunger's avatar
Tobias Hunger committed
77 78 79
    foreach (BaseQtVersion *v, versionList) {
        if (qmake == v->qmakeCommand())
            return v->uniqueId();
80 81
        if (v->type() == QLatin1String(QtSupport::Constants::DESKTOPQT) && !fallBack)
            fallBack = v;
Tobias Hunger's avatar
Tobias Hunger committed
82
    }
83 84
    if (fallBack)
        return fallBack->uniqueId();
Tobias Hunger's avatar
Tobias Hunger committed
85 86 87 88

    return -1;
}

89
QList<ProjectExplorer::Task> QtKitInformation::validate(const ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
90
{
91 92
    QList<ProjectExplorer::Task> result;
    QTC_ASSERT(QtVersionManager::instance()->isLoaded(), return result);
93 94
    BaseQtVersion *version = qtVersion(k);
    if (!version)
95
        return result;
96
    return version->validateKit(k);
Tobias Hunger's avatar
Tobias Hunger committed
97 98
}

99 100
void QtKitInformation::fix(ProjectExplorer::Kit *k)
{
101
    QTC_ASSERT(QtVersionManager::instance()->isLoaded(), return);
102
    BaseQtVersion *version = qtVersion(k);
103
    if (!version && qtVersionId(k) >= 0) {
104
        qWarning("Qt version is no longer known, removing from kit \"%s\".", qPrintable(k->displayName()));
105
        setQtVersionId(k, -1);
106
    }
107 108
}

109
ProjectExplorer::KitConfigWidget *QtKitInformation::createConfigWidget(ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
110
{
111
    return new Internal::QtKitConfigWidget(k);
Tobias Hunger's avatar
Tobias Hunger committed
112 113
}

114
QString QtKitInformation::displayNamePostfix(const ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
115
{
116
    BaseQtVersion *version = qtVersion(k);
Tobias Hunger's avatar
Tobias Hunger committed
117 118 119
    return version ? version->displayName() : QString();
}

Tobias Hunger's avatar
Tobias Hunger committed
120
ProjectExplorer::KitInformation::ItemList
121
QtKitInformation::toUserOutput(const ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
122
{
123
    BaseQtVersion *version = qtVersion(k);
Tobias Hunger's avatar
Tobias Hunger committed
124 125 126
    return ItemList() << qMakePair(tr("Qt version"), version ? version->displayName() : tr("None"));
}

127
void QtKitInformation::addToEnvironment(const ProjectExplorer::Kit *k, Utils::Environment &env) const
Tobias Hunger's avatar
Tobias Hunger committed
128
{
129
    BaseQtVersion *version = qtVersion(k);
Tobias Hunger's avatar
Tobias Hunger committed
130
    if (version)
131
        version->addToEnvironment(k, env);
Tobias Hunger's avatar
Tobias Hunger committed
132 133
}

134 135 136 137 138 139 140
ProjectExplorer::IOutputParser *QtKitInformation::createOutputParser(const ProjectExplorer::Kit *k) const
{
    if (qtVersion(k))
        return new QtParser;
    return 0;
}

141
int QtKitInformation::qtVersionId(const ProjectExplorer::Kit *k)
Tobias Hunger's avatar
Tobias Hunger committed
142
{
143
    if (!k)
Tobias Hunger's avatar
Tobias Hunger committed
144
        return -1;
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161

    int id = -1;
    QVariant data = k->value(Core::Id(Internal::QT_INFORMATION), -1);
    if (data.type() == QVariant::Int) {
        bool ok;
        id = data.toInt(&ok);
        if (!ok)
            id = -1;
    } else {
        QString source = data.toString();
        foreach (BaseQtVersion *v, QtVersionManager::instance()->versions()) {
            if (v->autodetectionSource() != source)
                continue;
            id = v->uniqueId();
            break;
        }
    }
Tobias Hunger's avatar
Tobias Hunger committed
162 163 164
    return id;
}

165
void QtKitInformation::setQtVersionId(ProjectExplorer::Kit *k, const int id)
Tobias Hunger's avatar
Tobias Hunger committed
166
{
167
    k->setValue(Core::Id(Internal::QT_INFORMATION), id);
Tobias Hunger's avatar
Tobias Hunger committed
168 169
}

170
BaseQtVersion *QtKitInformation::qtVersion(const ProjectExplorer::Kit *k)
Tobias Hunger's avatar
Tobias Hunger committed
171
{
172
    return QtVersionManager::instance()->version(qtVersionId(k));
Tobias Hunger's avatar
Tobias Hunger committed
173 174
}

175
void QtKitInformation::setQtVersion(ProjectExplorer::Kit *k, const BaseQtVersion *v)
Tobias Hunger's avatar
Tobias Hunger committed
176 177
{
    if (!v)
178
        setQtVersionId(k, -1);
Tobias Hunger's avatar
Tobias Hunger committed
179
    else
180
        setQtVersionId(k, v->uniqueId());
Tobias Hunger's avatar
Tobias Hunger committed
181 182
}

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
QString QtKitInformation::dumperLibrary(const ProjectExplorer::Kit *k)
{
    BaseQtVersion *version = QtKitInformation::qtVersion(k);
    if (version)
        return version->gdbDebuggingHelperLibrary();
    return QString();
}

QStringList QtKitInformation::dumperLibraryLocations(const ProjectExplorer::Kit *k)
{
    BaseQtVersion *version = QtKitInformation::qtVersion(k);
    if (version)
        return version->debuggingHelperLibraryLocations();
    return QStringList();
}

199 200 201 202 203 204 205 206 207 208 209
void QtKitInformation::qtVersionsChanged(const QList<int> &addedIds,
                                         const QList<int> &removedIds,
                                         const QList<int> &changedIds)
{
    Q_UNUSED(addedIds);
    Q_UNUSED(removedIds);
    foreach (ProjectExplorer::Kit *k, ProjectExplorer::KitManager::instance()->kits())
        if (changedIds.contains(qtVersionId(k)))
            notifyAboutUpdate(k);
}

210 211 212 213 214 215 216 217 218
void QtKitInformation::kitsWereLoaded()
{
    foreach (ProjectExplorer::Kit *k, ProjectExplorer::KitManager::instance()->kits())
        fix(k);

    connect(QtVersionManager::instance(), SIGNAL(qtVersionsChanged(QList<int>,QList<int>,QList<int>)),
            this, SLOT(qtVersionsChanged(QList<int>,QList<int>,QList<int>)));
}

Tobias Hunger's avatar
Tobias Hunger committed
219
QtPlatformKitMatcher::QtPlatformKitMatcher(const QString &platform) :
Tobias Hunger's avatar
Tobias Hunger committed
220 221 222
    m_platform(platform)
{ }

223
bool QtPlatformKitMatcher::matches(const ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
224
{
225
    BaseQtVersion *version = QtKitInformation::qtVersion(k);
Tobias Hunger's avatar
Tobias Hunger committed
226 227 228
    return version && version->platformName() == m_platform;
}

229
bool QtVersionKitMatcher::matches(const ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
230
{
231
    BaseQtVersion *version = QtKitInformation::qtVersion(k);
Tobias Hunger's avatar
Tobias Hunger committed
232 233 234 235 236 237 238 239 240 241 242
    if (!version)
        return false;
    QtVersionNumber current = version->qtVersion();
    if (m_min.majorVersion > -1 && current < m_min)
        return false;
    if (m_max.majorVersion > -1 && current > m_max)
        return false;
    return version->availableFeatures().contains(m_features);
}

} // namespace QtSupport