Skip to content
Snippets Groups Projects
qtversionmanager.h 5.71 KiB
Newer Older
/**************************************************************************
con's avatar
con committed
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
** 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.
** GNU Lesser General Public License Usage
** 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.
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
con's avatar
con committed
**
**************************************************************************/
hjk's avatar
hjk committed

con's avatar
con committed
#ifndef QTVERSIONMANAGER_H
#define QTVERSIONMANAGER_H

#include <projectexplorer/environment.h>
#include <projectexplorer/toolchain.h>
hjk's avatar
hjk committed

#include <QtCore/QHash>
con's avatar
con committed

namespace Qt4ProjectManager {
con's avatar
con committed
namespace Internal {
class QtOptionsPageWidget;
class Qt4ProjectManagerPlugin;
con's avatar
con committed

class QtVersion
    friend class Internal::QtOptionsPageWidget; //for changing name and path
con's avatar
con committed
    friend class QtVersionManager;
public:
    QtVersion(const QString &name, const QString &path);
    QtVersion(const QString &name, const QString &path, int id, bool isSystemVersion = false);
    QtVersion()
        :m_name(QString::null), m_path(QString::null), m_id(-1)
    { }

    bool isValid() const; //TOOD check that the dir exists and the name is non empty
    bool isInstalled() const;
    bool isSystemVersion() const { return m_isSystemVersion; }

    QString name() const;
    QString path() const;
    QString sourcePath() const;
    QString mkspec() const;
dt's avatar
dt committed
    QString mkspecPath() const;
con's avatar
con committed
    QString qmakeCommand() const;
dt's avatar
dt committed
    QString uicCommand() const;
    QString qtVersionString() const;
con's avatar
con committed
    // Returns the PREFIX, BINPREFIX, DOCPREFIX and similar information
    QHash<QString,QString> versionInfo() const;

dt's avatar
dt committed
    ProjectExplorer::ToolChain::ToolChainType toolchainType() const;
con's avatar
con committed

    QString mingwDirectory() const;
    void setMingwDirectory(const QString &directory);
    QString msvcVersion() const;
dt's avatar
dt committed
    QString wincePlatform() const;
con's avatar
con committed
    void setMsvcVersion(const QString &version);
dt's avatar
dt committed
    void addToEnvironment(ProjectExplorer::Environment &env);
    bool hasDebuggingHelper() const;
    QString debuggingHelperLibrary() const;
    // Builds a debugging library
    // returns the output of the commands
    QString buildDebuggingHelperLibrary();
con's avatar
con committed

    int uniqueId() const;
    bool isMSVC64Bit() const;
con's avatar
con committed

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

    QmakeBuildConfig defaultBuildConfig() const;
private:
    static int getUniqueId();
    // Also used by QtOptionsPageWidget
con's avatar
con committed
    void setName(const QString &name);
    void setPath(const QString &path);
    void updateSourcePath();
    void updateVersionInfo() const;
    void updateMkSpec() const;
    QString m_name;
    mutable bool m_versionInfoUpToDate;
    mutable bool m_mkspecUpToDate;
    QString m_path;
    QString m_sourcePath;
    mutable QString m_mkspec; // updated lazily
dt's avatar
dt committed
    mutable QString m_mkspecFullPath;
con's avatar
con committed
    QString m_mingwDirectory;
    QString m_msvcVersion;
    mutable QHash<QString,QString> m_versionInfo; // updated lazily
    int m_id;
    bool m_isSystemVersion;
    mutable bool m_notInstalled;
    mutable bool m_defaultConfigIsDebug;
    mutable bool m_defaultConfigIsDebugAndRelease;
    mutable QString m_qmakeCommand;
dt's avatar
dt committed
    mutable QString m_uicCommand;
    // This is updated on first call to qmakeCommand
    // That function is called from updateVersionInfo()
    mutable QString m_qtVersionString;
    bool m_hasDebuggingHelper;
con's avatar
con committed
};

class QtVersionManager : public QObject
con's avatar
con committed
{
    friend class Internal::Qt4ProjectManagerPlugin;
con's avatar
con committed
    Q_OBJECT
    // for getUniqueId();
    friend class QtVersion;
    friend class Internal::QtOptionsPage;
con's avatar
con committed
public:
    static QtVersionManager *instance();
con's avatar
con committed
    QtVersionManager();
    ~QtVersionManager();

    QList<QtVersion *> versions() const;

    QtVersion *version(int id) const;
    QtVersion *currentQtVersion() const;
con's avatar
con committed

    QtVersion *qtVersionForDirectory(const QString &directory);
    // Used by the projectloadwizard
    void addVersion(QtVersion *version);
    // Static Methods
    static QtVersion::QmakeBuildConfig scanMakefileForQmakeConfig(const QString &directory, QtVersion::QmakeBuildConfig defaultBuildConfig);
    static QString findQtVersionFromMakefile(const QString &directory);
con's avatar
con committed
signals:
    void defaultQtVersionChanged();
    void qtVersionsChanged();
private:
    // Used by QtOptionsPage
    void setNewQtVersions(QList<QtVersion *> newVersions, int newDefaultVersion);
    // Used by QtVersion
    int getUniqueId();
    void writeVersionsIntoSettings();
con's avatar
con committed
    void addNewVersionsFromInstaller();
    void updateSystemVersion();
    void updateDocumentation();
con's avatar
con committed
    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;
    // managed by QtProjectManagerPlugin
    static QtVersionManager *m_self;
con's avatar
con committed
};
} // namespace Qt4ProjectManager
con's avatar
con committed

hjk's avatar
hjk committed
#endif // QTVERSIONMANAGER_H