qtversionmanager.h 7.55 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 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>
hjk's avatar
hjk committed
35

36
#include <QtCore/QSharedPointer>
37
#include <QtCore/QHash>
con's avatar
con committed
38

39
namespace Qt4ProjectManager {
40

con's avatar
con committed
41
namespace Internal {
42
class QtOptionsPageWidget;
43
class QtOptionsPage;
44
class Qt4ProjectManagerPlugin;
45
}
con's avatar
con committed
46

47
class QtVersion
48
{
con's avatar
con committed
49 50
    friend class QtVersionManager;
public:
51 52
    QtVersion(const QString &name, const QString &path,
              bool isAutodetected = false, const QString &autodetectionSource = QString());
53 54 55

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

56 57
    QtVersion(const QString &name, const QString &path, int id,
              bool isAutodetected = false, const QString &autodetectionSource = QString());
58
    QtVersion();
59
    ~QtVersion();
con's avatar
con committed
60 61 62

    bool isValid() const; //TOOD check that the dir exists and the name is non empty
    bool isInstalled() const;
63
    bool isAutodetected() const { return m_isAutodetected; }
64
    QString autodetectionSource() const { return m_autodetectionSource; }
con's avatar
con committed
65 66 67

    QString name() const;
    QString sourcePath() const;
dt's avatar
dt committed
68
    QString mkspecPath() const;
con's avatar
con committed
69
    QString qmakeCommand() const;
dt's avatar
dt committed
70
    QString uicCommand() const;
71 72
    QString designerCommand() const;
    QString linguistCommand() const;
con's avatar
con committed
73 74 75 76

    QList<ProjectExplorer::ToolChain::ToolChainType> possibleToolChainTypes() const;
    QString mkspec() const;
    ProjectExplorer::ToolChain::ToolChainType defaultToolchainType() const;
77
    ProjectExplorer::ToolChain *createToolChain(ProjectExplorer::ToolChain::ToolChainType type) const;
78

79
    void setName(const QString &name);
80
    void setQMakeCommand(const QString &path);
81

82
    QString qtVersionString() const;
con's avatar
con committed
83 84 85
    // Returns the PREFIX, BINPREFIX, DOCPREFIX and similar information
    QHash<QString,QString> versionInfo() const;

con's avatar
con committed
86 87 88 89
#ifdef QTCREATOR_WITH_S60
    QString mwcDirectory() const;
    void setMwcDirectory(const QString &directory);
#endif
con's avatar
con committed
90 91 92
    QString mingwDirectory() const;
    void setMingwDirectory(const QString &directory);
    QString msvcVersion() const;
dt's avatar
dt committed
93
    QString wincePlatform() const;
con's avatar
con committed
94
    void setMsvcVersion(const QString &version);
95
    void addToEnvironment(ProjectExplorer::Environment &env) const;
96

97
    bool hasDebuggingHelper() const;
98
    QString debuggingHelperLibrary() const;
99
    QStringList debuggingHelperLibraryLocations() const;
100

101 102 103
    // Builds a debugging library
    // returns the output of the commands
    QString buildDebuggingHelperLibrary();
con's avatar
con committed
104

105 106 107 108 109 110 111 112 113
    bool hasExamples() const;
    QString examplesPath() const;

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

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

con's avatar
con committed
114
    int uniqueId() const;
con's avatar
con committed
115
    bool isQt64Bit() const;
con's avatar
con committed
116 117 118 119 120 121 122 123 124 125 126

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

    QmakeBuildConfig defaultBuildConfig() const;
private:
    static int getUniqueId();
127
    // Also used by QtOptionsPageWidget
con's avatar
con committed
128 129
    void updateSourcePath();
    void updateMkSpec() const;
130 131
    void updateVersionInfo() const;
    void updateQMakeCXX() const;
con's avatar
con committed
132
    QString qmakeCXX() const;
133
    QString findQtBinary(const QStringList &possibleName) const;
con's avatar
con committed
134 135 136 137 138
    QString m_name;
    QString m_sourcePath;
    QString m_mingwDirectory;
    QString m_msvcVersion;
    int m_id;
139
    bool m_isAutodetected;
140
    QString m_autodetectionSource;
141
    bool m_hasDebuggingHelper;
con's avatar
con committed
142 143 144
#ifdef QTCREATOR_WITH_S60
    QString m_mwcDirectory;
#endif
145 146 147 148 149 150 151

    mutable bool m_mkspecUpToDate;
    mutable QString m_mkspec; // updated lazily
    mutable QString m_mkspecFullPath;

    mutable bool m_versionInfoUpToDate;
    mutable QHash<QString,QString> m_versionInfo; // updated lazily
con's avatar
con committed
152 153 154
    mutable bool m_notInstalled;
    mutable bool m_defaultConfigIsDebug;
    mutable bool m_defaultConfigIsDebugAndRelease;
155 156 157
    mutable bool m_hasExamples;
    mutable bool m_hasDemos;
    mutable bool m_hasDocumentation;
158

con's avatar
con committed
159
    mutable QString m_qmakeCommand;
160
    mutable QString m_qtVersionString;
dt's avatar
dt committed
161
    mutable QString m_uicCommand;
162 163
    mutable QString m_designerCommand;
    mutable QString m_linguistCommand;
164 165 166

    mutable bool m_qmakeCXXUpToDate;
    mutable QString m_qmakeCXX;
con's avatar
con committed
167 168
};

169 170 171 172 173 174 175
struct QMakeAssignment
{
    QString variable;
    QString op;
    QString value;
};

176
class QtVersionManager : public QObject
con's avatar
con committed
177 178
{
    Q_OBJECT
179 180
    // for getUniqueId();
    friend class QtVersion;
181
    friend class Internal::QtOptionsPage;
con's avatar
con committed
182
public:
183
    static QtVersionManager *instance();
con's avatar
con committed
184 185 186 187 188
    QtVersionManager();
    ~QtVersionManager();

    QList<QtVersion *> versions() const;

189
    QtVersion *version(int id) const;
190
    QtVersion *defaultVersion() const;
con's avatar
con committed
191

192
    QtVersion *qtVersionForQMakeBinary(const QString &qmakePath);
con's avatar
con committed
193 194
    // Used by the projectloadwizard
    void addVersion(QtVersion *version);
195
    void removeVersion(QtVersion *version);
196

197
    // Static Methods
198
    static QPair<QtVersion::QmakeBuildConfig, QStringList> scanMakeFile(const QString &directory, QtVersion::QmakeBuildConfig defaultBuildConfig);
199
    static QString findQMakeBinaryFromMakefile(const QString &directory);
con's avatar
con committed
200 201 202
signals:
    void defaultQtVersionChanged();
    void qtVersionsChanged();
203 204 205 206
    void updateExamples(QString, QString, QString);

private slots:
    void updateExamples();
con's avatar
con committed
207
private:
208 209 210 211 212
    static QString findQMakeLine(const QString &directory);
    static QString trimLine(const QString line);
    static QStringList splitLine(const QString &line);
    static void parseParts(const QStringList &parts, QList<QMakeAssignment> *assignments, QList<QMakeAssignment> *afterAssignments, QStringList *additionalArguments);
    static QtVersion::QmakeBuildConfig qmakeBuildConfigFromCmdArgs(QList<QMakeAssignment> *assignments, QtVersion::QmakeBuildConfig defaultBuildConfig);
213 214 215 216 217
    // Used by QtOptionsPage
    void setNewQtVersions(QList<QtVersion *> newVersions, int newDefaultVersion);
    // Used by QtVersion
    int getUniqueId();
    void writeVersionsIntoSettings();
con's avatar
con committed
218 219 220
    void addNewVersionsFromInstaller();
    void updateSystemVersion();
    void updateDocumentation();
221

con's avatar
con committed
222 223 224 225 226 227 228 229
    static int indexOfVersionInList(const QtVersion * const version, const QList<QtVersion *> &list);
    void updateUniqueIdToIndexMap();

    QtVersion *m_emptyVersion;
    int m_defaultVersion;
    QList<QtVersion *> m_versions;
    QMap<int, int> m_uniqueIdToIndex;
    int m_idcount;
230 231
    // managed by QtProjectManagerPlugin
    static QtVersionManager *m_self;
con's avatar
con committed
232
};
233

234
} // namespace Qt4ProjectManager
con's avatar
con committed
235

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