qt4projectmanager.cpp 6.61 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
8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
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
26
** 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
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "qt4projectmanager.h"
hjk's avatar
hjk committed
31

con's avatar
con committed
32
33
34
35
36
37
38
39
#include "qt4projectmanagerconstants.h"
#include "qt4projectmanagerplugin.h"
#include "qt4nodes.h"
#include "qt4project.h"
#include "profilereader.h"
#include "qtversionmanager.h"
#include "qmakestep.h"

40
#include <coreplugin/icore.h>
con's avatar
con committed
41
42
43
44
45
46
#include <coreplugin/basefilewizard.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/vcsmanager.h>
47
#include <projectexplorer/buildmanager.h>
con's avatar
con committed
48
#include <projectexplorer/project.h>
49
#include <projectexplorer/projectexplorerconstants.h>
con's avatar
con committed
50
51
52
#include <utils/listutils.h>

#include <QtCore/QCoreApplication>
53
54
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
con's avatar
con committed
55
#include <QtCore/QLinkedList>
56
#include <QtCore/QVariant>
con's avatar
con committed
57
#include <QtGui/QFileDialog>
58
#include <QtGui/QMenu>
con's avatar
con committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <QtGui/QMessageBox>

using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;

using ProjectExplorer::BuildStep;
using ProjectExplorer::FileType;
using ProjectExplorer::HeaderType;
using ProjectExplorer::SourceType;
using ProjectExplorer::FormType;
using ProjectExplorer::ResourceType;
using ProjectExplorer::UnknownFileType;

// Known file types of a Qt 4 project
73
74
75
76
77
78
static const char* qt4FileTypes[] = {
    "CppHeaderFiles",
    "CppSourceFiles",
    "Qt4FormFiles",
    "Qt4ResourceFiles"
};
con's avatar
con committed
79

80
81
Qt4Manager::Qt4Manager(Qt4ProjectManagerPlugin *plugin)
  : m_mimeType(QLatin1String(Qt4ProjectManager::Constants::PROFILE_MIMETYPE)),
con's avatar
con committed
82
83
84
    m_plugin(plugin),
    m_projectExplorer(0),
    m_contextProject(0),
dt's avatar
dt committed
85
    m_languageID(0)
con's avatar
con committed
86
{
87
88
    m_languageID = Core::UniqueIDManager::instance()->
                   uniqueIdentifier(ProjectExplorer::Constants::LANG_CXX);
con's avatar
con committed
89
90
91
92
93
94
}

Qt4Manager::~Qt4Manager()
{
}

dt's avatar
dt committed
95
96
97
98
99
100
101
102
103
104
105
106
void Qt4Manager::registerProject(Qt4Project *project)
{
    m_projects.append(project);
}

void Qt4Manager::unregisterProject(Qt4Project *project)
{
    m_projects.removeOne(project);
}

void Qt4Manager::notifyChanged(const QString &name)
{
hjk's avatar
hjk committed
107
    foreach (Qt4Project *pro, m_projects)
dt's avatar
dt committed
108
109
110
        pro->notifyChanged(name);
}

con's avatar
con committed
111
112
void Qt4Manager::init()
{
113
    m_projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
con's avatar
con committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
}

int Qt4Manager::projectContext() const
{
     return m_plugin->projectContext();
}

int Qt4Manager::projectLanguage() const
{
    return m_languageID;
}

QString Qt4Manager::mimeType() const
{
    return m_mimeType;
}

ProjectExplorer::Project* Qt4Manager::openProject(const QString &fileName)
{
133
134
    Core::MessageManager *messageManager = Core::ICore::instance()->messageManager();
    messageManager->displayStatusBarMessage(tr("Loading project %1 ...").arg(fileName), 50000);
con's avatar
con committed
135
136
137
138
139
140
141
142

    // TODO Make all file paths relative & remove this hack
    // We convert the path to an absolute one here because qt4project.cpp
    // && profileevaluator use absolute/canonical file paths all over the place
    // Correct fix would be to remove these calls ...
    QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();

    if (canonicalFilePath.isEmpty()) {
143
144
        messageManager->printToOutputPane(tr("Failed opening project '%1': Project file does not exist").arg(canonicalFilePath));
        messageManager->displayStatusBarMessage(tr("Failed opening project"), 5000);
con's avatar
con committed
145
146
147
148
149
        return 0;
    }

    foreach (ProjectExplorer::Project *pi, projectExplorer()->session()->projects()) {
        if (canonicalFilePath == pi->file()->fileName()) {
150
151
            messageManager->printToOutputPane(tr("Failed opening project '%1': Project already open").arg(canonicalFilePath));
            messageManager->displayStatusBarMessage(tr("Failed opening project"), 5000);
con's avatar
con committed
152
153
154
155
            return 0;
        }
    }

156
    messageManager->displayStatusBarMessage(tr("Opening %1 ...").arg(fileName));
con's avatar
con committed
157
158
159
160
    QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);

    Qt4Project *pro = new Qt4Project(this, canonicalFilePath);

161
    messageManager->displayStatusBarMessage(tr("Done opening project"), 5000);
con's avatar
con committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
    return pro;
}

ProjectExplorer::ProjectExplorerPlugin *Qt4Manager::projectExplorer() const
{
    return m_projectExplorer;
}

ProjectExplorer::Node *Qt4Manager::contextNode() const
{
    return m_contextNode;
}

void Qt4Manager::setContextNode(ProjectExplorer::Node *node)
{
    m_contextNode = node;
}

void Qt4Manager::setContextProject(ProjectExplorer::Project *project)
{
    m_contextProject = project;
}

ProjectExplorer::Project *Qt4Manager::contextProject() const
{
    return m_contextProject;
}

QtVersionManager *Qt4Manager::versionManager() const
{
    return m_plugin->versionManager();
}

void Qt4Manager::runQMake()
{
    runQMake(m_projectExplorer->currentProject());
}

void Qt4Manager::runQMakeContextMenu()
{
    runQMake(m_contextProject);
}

void Qt4Manager::runQMake(ProjectExplorer::Project *p)
{
    QMakeStep *qmakeStep = qobject_cast<Qt4Project *>(p)->qmakeStep();
    //found qmakeStep, now use it
    qmakeStep->setForced(true);
    const QString &config = p->activeBuildConfiguration();
    m_projectExplorer->buildManager()->appendStep(qmakeStep, config);
}

QString Qt4Manager::fileTypeId(ProjectExplorer::FileType type)
{
    switch (type) {
    case HeaderType:
        return QLatin1String(qt4FileTypes[0]);
    case SourceType:
        return QLatin1String(qt4FileTypes[1]);
    case FormType:
        return QLatin1String(qt4FileTypes[2]);
    case ResourceType:
        return QLatin1String(qt4FileTypes[3]);
    case UnknownFileType:
    default:
        break;
    }
    return QString();
}