qtkitinformation.cpp 5.36 KB
Newer Older
Tobias Hunger's avatar
Tobias Hunger committed
1
2
3
4
5
6
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
Eike Ziller's avatar
Eike Ziller committed
7
** Contact: http://www.qt-project.org/
Tobias Hunger's avatar
Tobias Hunger committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/

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

Tobias Hunger's avatar
Tobias Hunger committed
33
#include "qtkitconfigwidget.h"
Tobias Hunger's avatar
Tobias Hunger committed
34
35
36
37
38
39
40
41
42
#include "qtversionmanager.h"

#include <utils/environment.h>

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

Tobias Hunger's avatar
Tobias Hunger committed
43
QtKitInformation::QtKitInformation()
Tobias Hunger's avatar
Tobias Hunger committed
44
{
Tobias Hunger's avatar
Tobias Hunger committed
45
    setObjectName(QLatin1String("QtKitInformation"));
Tobias Hunger's avatar
Tobias Hunger committed
46
47
48
49
    connect(QtVersionManager::instance(), SIGNAL(qtVersionsChanged(QList<int>,QList<int>,QList<int>)),
            this, SIGNAL(validationNeeded()));
}

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

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

61
QVariant QtKitInformation::defaultValue(ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
62
{
63
    Q_UNUSED(k);
Tobias Hunger's avatar
Tobias Hunger committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    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();
    foreach (BaseQtVersion *v, versionList) {
        if (qmake == v->qmakeCommand())
            return v->uniqueId();
    }

    return -1;
}

82
QList<ProjectExplorer::Task> QtKitInformation::validate(ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
83
{
84
    int id = qtVersionId(k);
Tobias Hunger's avatar
Tobias Hunger committed
85
86
87
88
    if (id == -1)
        return QList<ProjectExplorer::Task>();
    BaseQtVersion *version = QtVersionManager::instance()->version(id);
    if (!version) {
89
        setQtVersionId(k, -1);
Tobias Hunger's avatar
Tobias Hunger committed
90
91
        return QList<ProjectExplorer::Task>();
    }
92
    return version->validateKit(k);
Tobias Hunger's avatar
Tobias Hunger committed
93
94
}

95
ProjectExplorer::KitConfigWidget *QtKitInformation::createConfigWidget(ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
96
{
97
    return new Internal::QtKitConfigWidget(k);
Tobias Hunger's avatar
Tobias Hunger committed
98
99
}

100
QString QtKitInformation::displayNamePostfix(const ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
101
{
102
    BaseQtVersion *version = qtVersion(k);
Tobias Hunger's avatar
Tobias Hunger committed
103
104
105
    return version ? version->displayName() : QString();
}

Tobias Hunger's avatar
Tobias Hunger committed
106
ProjectExplorer::KitInformation::ItemList
107
QtKitInformation::toUserOutput(ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
108
{
109
    BaseQtVersion *version = qtVersion(k);
Tobias Hunger's avatar
Tobias Hunger committed
110
111
112
    return ItemList() << qMakePair(tr("Qt version"), version ? version->displayName() : tr("None"));
}

113
void QtKitInformation::addToEnvironment(const ProjectExplorer::Kit *k, Utils::Environment &env) const
Tobias Hunger's avatar
Tobias Hunger committed
114
{
115
    BaseQtVersion *version = qtVersion(k);
Tobias Hunger's avatar
Tobias Hunger committed
116
    if (version)
117
        version->addToEnvironment(k, env);
Tobias Hunger's avatar
Tobias Hunger committed
118
119
}

120
int QtKitInformation::qtVersionId(const ProjectExplorer::Kit *k)
Tobias Hunger's avatar
Tobias Hunger committed
121
{
122
    if (!k)
Tobias Hunger's avatar
Tobias Hunger committed
123
        return -1;
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

    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
141
142
143
    return id;
}

144
void QtKitInformation::setQtVersionId(ProjectExplorer::Kit *k, const int id)
Tobias Hunger's avatar
Tobias Hunger committed
145
{
146
    k->setValue(Core::Id(Internal::QT_INFORMATION), id);
Tobias Hunger's avatar
Tobias Hunger committed
147
148
}

149
BaseQtVersion *QtKitInformation::qtVersion(const ProjectExplorer::Kit *k)
Tobias Hunger's avatar
Tobias Hunger committed
150
{
151
    return QtVersionManager::instance()->version(qtVersionId(k));
Tobias Hunger's avatar
Tobias Hunger committed
152
153
}

154
void QtKitInformation::setQtVersion(ProjectExplorer::Kit *k, const BaseQtVersion *v)
Tobias Hunger's avatar
Tobias Hunger committed
155
156
{
    if (!v)
157
        setQtVersionId(k, -1);
Tobias Hunger's avatar
Tobias Hunger committed
158
    else
159
        setQtVersionId(k, v->uniqueId());
Tobias Hunger's avatar
Tobias Hunger committed
160
161
}

Tobias Hunger's avatar
Tobias Hunger committed
162
QtPlatformKitMatcher::QtPlatformKitMatcher(const QString &platform) :
Tobias Hunger's avatar
Tobias Hunger committed
163
164
165
    m_platform(platform)
{ }

166
bool QtPlatformKitMatcher::matches(const ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
167
{
168
    BaseQtVersion *version = QtKitInformation::qtVersion(k);
Tobias Hunger's avatar
Tobias Hunger committed
169
170
171
    return version && version->platformName() == m_platform;
}

172
bool QtVersionKitMatcher::matches(const ProjectExplorer::Kit *k) const
Tobias Hunger's avatar
Tobias Hunger committed
173
{
174
    BaseQtVersion *version = QtKitInformation::qtVersion(k);
Tobias Hunger's avatar
Tobias Hunger committed
175
176
177
178
179
180
181
182
183
184
185
    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