qtversionmanager.h 9.27 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
#ifndef QTVERSIONMANAGER_H
#define QTVERSIONMANAGER_H

33
34
#include <projectexplorer/environment.h>
#include <projectexplorer/toolchain.h>
dt's avatar
Compile    
dt committed
35
#include <QSharedPointer>
hjk's avatar
hjk committed
36

37
#include <QtCore/QHash>
38
#include <QtCore/QSet>
39
#include <QtCore/QSharedPointer>
con's avatar
con committed
40

41
42
43
44
namespace ProjectExplorer {
    class ToolChain;
}

45
namespace Qt4ProjectManager {
46

con's avatar
con committed
47
namespace Internal {
48
class QtOptionsPageWidget;
49
class QtOptionsPage;
50
}
con's avatar
con committed
51

52
class QtVersion
53
{
con's avatar
con committed
54
55
    friend class QtVersionManager;
public:
56
    QtVersion(const QString &name, const QString &qmakeCommand,
57
              bool isAutodetected = false, const QString &autodetectionSource = QString());
58
59
60

    QtVersion(const QString &path, bool isAutodetected = false, const QString &autodetectionSource = QString());

61
    QtVersion(const QString &name, const QString &qmakeCommand, int id,
62
              bool isAutodetected = false, const QString &autodetectionSource = QString());
63
    QtVersion();
64
    ~QtVersion();
con's avatar
con committed
65
66

    bool isValid() const; //TOOD check that the dir exists and the name is non empty
67
    QString invalidReason() const;
68
    bool isAutodetected() const { return m_isAutodetected; }
69
    QString autodetectionSource() const { return m_autodetectionSource; }
con's avatar
con committed
70

71
    QString displayName() const;
con's avatar
con committed
72
73
    QString sourcePath() const;
    QString qmakeCommand() const;
dt's avatar
dt committed
74
    QString uicCommand() const;
75
76
    QString designerCommand() const;
    QString linguistCommand() const;
con's avatar
con committed
77

Tobias Hunger's avatar
Tobias Hunger committed
78
79
80
    bool supportsTargetId(const QString &id) const;
    QSet<QString> supportedTargetIds() const;

con's avatar
con committed
81
    QList<ProjectExplorer::ToolChain::ToolChainType> possibleToolChainTypes() const;
82
    ProjectExplorer::ToolChain *toolChain(ProjectExplorer::ToolChain::ToolChainType type) const;
83
84
85
86
87
88
89

    /// @returns the name of the mkspec, which is generally not enough
    /// to pass to qmake.
    QString mkspec() const;
    /// @returns the full path to the default directory
    /// specifally not the directory the symlink/ORIGINAL_QMAKESPEC points to
    QString mkspecPath() const;
90

91
    void setDisplayName(const QString &name);
92
    void setQMakeCommand(const QString &path);
93

94
    QString qtVersionString() const;
con's avatar
con committed
95
96
97
    // Returns the PREFIX, BINPREFIX, DOCPREFIX and similar information
    QHash<QString,QString> versionInfo() const;

con's avatar
con committed
98
99
    QString mwcDirectory() const;
    void setMwcDirectory(const QString &directory);
100
101
    QString s60SDKDirectory() const;
    void setS60SDKDirectory(const QString &directory);
con's avatar
con committed
102
103
    QString gcceDirectory() const;
    void setGcceDirectory(const QString &directory);
104

con's avatar
con committed
105
106
107
108
    QString mingwDirectory() const;
    void setMingwDirectory(const QString &directory);
    QString msvcVersion() const;
    void setMsvcVersion(const QString &version);
109
    void addToEnvironment(ProjectExplorer::Environment &env) const;
110

111
    bool hasDebuggingHelper() const;
112
    QString debuggingHelperLibrary() const;
113
    QStringList debuggingHelperLibraryLocations() const;
114

115
116
117
    // Builds a debugging library
    // returns the output of the commands
    QString buildDebuggingHelperLibrary();
con's avatar
con committed
118

119
120
121
122
123
124
125
126
127
    bool hasExamples() const;
    QString examplesPath() const;

    bool hasDocumentation() const;
    QString documentationPath() const;

    bool hasDemos() const;
    QString demosPath() const;

Tobias Hunger's avatar
Tobias Hunger committed
128
    // All valid Ids are >= 0
con's avatar
con committed
129
    int uniqueId() const;
con's avatar
con committed
130
    bool isQt64Bit() const;
con's avatar
con committed
131
132
133
134
135
136
137
138

    enum QmakeBuildConfig
    {
        NoBuild = 1,
        DebugBuild = 2,
        BuildAll = 8
    };

139
    Q_DECLARE_FLAGS(QmakeBuildConfigs, QmakeBuildConfig)
140

141
    QmakeBuildConfigs defaultBuildConfig() const;
142
    QString toHtml() const;
con's avatar
con committed
143
private:
144
    QList<QSharedPointer<ProjectExplorer::ToolChain> > toolChains() const;
con's avatar
con committed
145
    static int getUniqueId();
146
    // Also used by QtOptionsPageWidget
con's avatar
con committed
147
    void updateSourcePath();
148
    void updateVersionInfo() const;
149
    QString findQtBinary(const QStringList &possibleName) const;
dt's avatar
dt committed
150
    void updateToolChainAndMkspec() const;
151
    QString m_displayName;
con's avatar
con committed
152
153
154
155
    QString m_sourcePath;
    QString m_mingwDirectory;
    QString m_msvcVersion;
    int m_id;
156
    bool m_isAutodetected;
157
    QString m_autodetectionSource;
158
    mutable bool m_hasDebuggingHelper; // controlled by m_versionInfoUpToDate
159

con's avatar
con committed
160
    QString m_mwcDirectory;
161
    QString m_s60SDKDirectory;
con's avatar
con committed
162
    QString m_gcceDirectory;
163

dt's avatar
dt committed
164
    mutable bool m_toolChainUpToDate;
165
166
    mutable QString m_mkspec; // updated lazily
    mutable QString m_mkspecFullPath;
167
    mutable QList<QSharedPointer<ProjectExplorer::ToolChain> > m_toolChains;
168

169
170
    mutable bool m_versionInfoUpToDate;
    mutable QHash<QString,QString> m_versionInfo; // updated lazily
con's avatar
con committed
171
172
173
    mutable bool m_notInstalled;
    mutable bool m_defaultConfigIsDebug;
    mutable bool m_defaultConfigIsDebugAndRelease;
174
175
176
    mutable bool m_hasExamples;
    mutable bool m_hasDemos;
    mutable bool m_hasDocumentation;
177

con's avatar
con committed
178
    mutable QString m_qmakeCommand;
179
    mutable QString m_qtVersionString;
dt's avatar
dt committed
180
    mutable QString m_uicCommand;
181
182
    mutable QString m_designerCommand;
    mutable QString m_linguistCommand;
183
    mutable QSet<QString> m_targetIds;
con's avatar
con committed
184
185
};

186
187
188
189
190
191
192
struct QMakeAssignment
{
    QString variable;
    QString op;
    QString value;
};

193
class QtVersionManager : public QObject
con's avatar
con committed
194
195
{
    Q_OBJECT
196
197
    // for getUniqueId();
    friend class QtVersion;
198
    friend class Internal::QtOptionsPage;
con's avatar
con committed
199
public:
200
    static QtVersionManager *instance();
con's avatar
con committed
201
202
203
    QtVersionManager();
    ~QtVersionManager();

Tobias Hunger's avatar
Tobias Hunger committed
204
205
    // This will *always* return at least one (Qt in Path), even if that is
    // unconfigured.
con's avatar
con committed
206
207
    QList<QtVersion *> versions() const;

Tobias Hunger's avatar
Tobias Hunger committed
208
209
210
    // Note: DO NOT STORE THIS POINTER!
    //       The QtVersionManager will delete it at random times and you will
    //       need to get a new pointer by calling this method again!
211
    QtVersion *version(int id) const;
Tobias Hunger's avatar
Tobias Hunger committed
212
    QtVersion *emptyVersion() const;
con's avatar
con committed
213

214
    QtVersion *qtVersionForQMakeBinary(const QString &qmakePath);
Tobias Hunger's avatar
Tobias Hunger committed
215

con's avatar
con committed
216
217
    // Used by the projectloadwizard
    void addVersion(QtVersion *version);
218
    void removeVersion(QtVersion *version);
219

Tobias Hunger's avatar
Tobias Hunger committed
220
221
222
223
224
225
226
    // Target Support:
    bool supportsTargetId(const QString &id) const;
    // This returns a list of versions that support the target with the given id.
    // @return A list of QtVersions that supports a target. This list may be empty!
    QList<QtVersion *> versionsForTargetId(const QString &id) const;
    QSet<QString> supportedTargetIds() const;

227
    // Static Methods
228
229
    static QPair<QtVersion::QmakeBuildConfigs, QStringList> scanMakeFile(const QString &directory,
                                                                         QtVersion::QmakeBuildConfigs defaultBuildConfig);
230
    static QString findQMakeBinaryFromMakefile(const QString &directory);
231
    bool isValidId(int id) const;
Tobias Hunger's avatar
Tobias Hunger committed
232

con's avatar
con committed
233
signals:
234
    void qtVersionsChanged(const QList<int> &uniqueIds);
235
236
237
238
    void updateExamples(QString, QString, QString);

private slots:
    void updateExamples();
con's avatar
con committed
239
private:
240
241
    // This function is really simplistic...
    static bool equals(QtVersion *a, QtVersion *b);
242
243
244
    static QString findQMakeLine(const QString &directory);
    static QString trimLine(const QString line);
    static QStringList splitLine(const QString &line);
245
246
247
248
249
250
    static void parseParts(const QStringList &parts,
                           QList<QMakeAssignment> *assignments,
                           QList<QMakeAssignment> *afterAssignments,
                           QStringList *additionalArguments);
    static QtVersion::QmakeBuildConfigs qmakeBuildConfigFromCmdArgs(QList<QMakeAssignment> *assignments,
                                                                    QtVersion::QmakeBuildConfigs defaultBuildConfig);
251
    // Used by QtOptionsPage
Tobias Hunger's avatar
Tobias Hunger committed
252
    void setNewQtVersions(QList<QtVersion *> newVersions);
253
254
255
    // Used by QtVersion
    int getUniqueId();
    void writeVersionsIntoSettings();
con's avatar
con committed
256
257
258
    void addNewVersionsFromInstaller();
    void updateSystemVersion();
    void updateDocumentation();
259

con's avatar
con committed
260
261
262
263
264
265
266
    static int indexOfVersionInList(const QtVersion * const version, const QList<QtVersion *> &list);
    void updateUniqueIdToIndexMap();

    QtVersion *m_emptyVersion;
    QList<QtVersion *> m_versions;
    QMap<int, int> m_uniqueIdToIndex;
    int m_idcount;
267
268
    // managed by QtProjectManagerPlugin
    static QtVersionManager *m_self;
con's avatar
con committed
269
};
270

271
} // namespace Qt4ProjectManager
con's avatar
con committed
272

273
274
Q_DECLARE_OPERATORS_FOR_FLAGS(Qt4ProjectManager::QtVersion::QmakeBuildConfigs)

hjk's avatar
hjk committed
275
#endif // QTVERSIONMANAGER_H