qt4nodes.cpp 90 KB
Newer Older
hjk's avatar
hjk committed
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2012 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
**
hjk's avatar
hjk committed
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** 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.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
con's avatar
con committed
30
**
hjk's avatar
hjk committed
31
**************************************************************************/
hjk's avatar
hjk committed
32

con's avatar
con committed
33 34
#include "qt4nodes.h"
#include "qt4project.h"
35
#include "qt4target.h"
con's avatar
con committed
36
#include "qt4projectmanager.h"
37
#include "qt4projectmanagerconstants.h"
dt's avatar
dt committed
38
#include "qtuicodemodelsupport.h"
39
#include "qmakestep.h"
40
#include "qt4buildconfiguration.h"
con's avatar
con committed
41 42

#include <projectexplorer/nodesvisitor.h>
43
#include <projectexplorer/runconfiguration.h>
con's avatar
con committed
44 45

#include <coreplugin/editormanager/editormanager.h>
46
#include <coreplugin/editormanager/ieditor.h>
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
47
#include <coreplugin/fileiconprovider.h>
48
#include <coreplugin/documentmanager.h>
con's avatar
con committed
49 50 51 52
#include <coreplugin/icore.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/vcsmanager.h>

53
#include <cpptools/ModelManagerInterface.h>
54
#include <cplusplus/CppDocument.h>
55
#include <extensionsystem/pluginmanager.h>
56 57
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/buildmanager.h>
58
#include <qtsupport/profilereader.h>
con's avatar
con committed
59

hjk's avatar
hjk committed
60
#include <utils/qtcassert.h>
61
#include <utils/stringutils.h>
62
#include <utils/fileutils.h>
63
#include <proparser/prowriter.h>
64
#include <algorithm>
hjk's avatar
hjk committed
65

66 67 68 69 70 71
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QCoreApplication>
#include <QXmlStreamReader>
hjk's avatar
hjk committed
72

73 74 75 76
#include <QPainter>
#include <QMainWindow>
#include <QMessageBox>
#include <QPushButton>
77
#include <utils/QtConcurrentTools>
con's avatar
con committed
78

79 80 81 82 83 84 85 86 87 88 89 90
// Static cached data in struct Qt4NodeStaticData providing information and icons
// for file types and the project. Do some magic via qAddPostRoutine()
// to make sure the icons do not outlive QApplication, triggering warnings on X11.

struct FileTypeDataStorage {
    ProjectExplorer::FileType type;
    const char *typeName;
    const char *icon;
};

static const FileTypeDataStorage fileTypeDataStorage[] = {
    { ProjectExplorer::HeaderType,
Daniel Teske's avatar
Daniel Teske committed
91
      QT_TRANSLATE_NOOP("Qt4ProjectManager::Qt4PriFileNode", "Headers"),
92 93
      ":/qt4projectmanager/images/headers.png" },
    { ProjectExplorer::SourceType,
Daniel Teske's avatar
Daniel Teske committed
94
      QT_TRANSLATE_NOOP("Qt4ProjectManager::Qt4PriFileNode", "Sources"),
95 96
      ":/qt4projectmanager/images/sources.png" },
    { ProjectExplorer::FormType,
Daniel Teske's avatar
Daniel Teske committed
97
      QT_TRANSLATE_NOOP("Qt4ProjectManager::Qt4PriFileNode", "Forms"),
98 99
      ":/qt4projectmanager/images/forms.png" },
    { ProjectExplorer::ResourceType,
Daniel Teske's avatar
Daniel Teske committed
100
      QT_TRANSLATE_NOOP("Qt4ProjectManager::Qt4PriFileNode", "Resources"),
101
      ":/qt4projectmanager/images/qt_qrc.png" },
102
    { ProjectExplorer::QMLType,
Daniel Teske's avatar
Daniel Teske committed
103
      QT_TRANSLATE_NOOP("Qt4ProjectManager::Qt4PriFileNode", "QML"),
104
      ":/qt4projectmanager/images/qml.ico" },
105
    { ProjectExplorer::UnknownFileType,
Daniel Teske's avatar
Daniel Teske committed
106
      QT_TRANSLATE_NOOP("Qt4ProjectManager::Qt4PriFileNode", "Other files"),
107 108 109
      ":/qt4projectmanager/images/unknown.png" }
};

110 111 112 113 114
bool sortNodesByPath(ProjectExplorer::Node *a, ProjectExplorer::Node *b)
{
    return a->path() < b->path();
}

115 116 117 118
class Qt4NodeStaticData {
public:
    class FileTypeData {
    public:
119 120 121 122
        FileTypeData(ProjectExplorer::FileType t = ProjectExplorer::UnknownFileType,
                     const QString &tN = QString(),
                     const QIcon &i = QIcon()) :
        type(t), typeName(tN), icon(i) { }
con's avatar
con committed
123

124 125 126 127 128
        ProjectExplorer::FileType type;
        QString typeName;
        QIcon icon;
    };

129 130
    Qt4NodeStaticData();

131 132 133 134 135 136
    QVector<FileTypeData> fileTypeData;
    QIcon projectIcon;
};

static void clearQt4NodeStaticData();

137 138
Qt4NodeStaticData::Qt4NodeStaticData()
{
139 140
    // File type data
    const unsigned count = sizeof(fileTypeDataStorage)/sizeof(FileTypeDataStorage);
141
    fileTypeData.reserve(count);
142 143 144 145

    // Overlay the SP_DirIcon with the custom icons
    const QSize desiredSize = QSize(16, 16);

Friedemann Kleint's avatar
Friedemann Kleint committed
146
    for (unsigned i = 0 ; i < count; ++i) {
147 148 149 150 151 152
        const QIcon overlayIcon = QIcon(QLatin1String(fileTypeDataStorage[i].icon));
        const QPixmap folderPixmap =
                Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon,
                                                    overlayIcon, desiredSize);
        QIcon folderIcon;
        folderIcon.addPixmap(folderPixmap);
Daniel Teske's avatar
Daniel Teske committed
153
        const QString desc = Qt4ProjectManager::Qt4PriFileNode::tr(fileTypeDataStorage[i].typeName);
154 155
        fileTypeData.push_back(Qt4NodeStaticData::FileTypeData(fileTypeDataStorage[i].type,
                                                               desc, folderIcon));
156 157 158 159 160 161
    }
    // Project icon
    const QIcon projectBaseIcon(QLatin1String(":/qt4projectmanager/images/qt_project.png"));
    const QPixmap projectPixmap = Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon,
                                                                      projectBaseIcon,
                                                                      desiredSize);
162
    projectIcon.addPixmap(projectPixmap);
163 164

    qAddPostRoutine(clearQt4NodeStaticData);
165 166 167
}

Q_GLOBAL_STATIC(Qt4NodeStaticData, qt4NodeStaticData)
168 169 170 171 172

static void clearQt4NodeStaticData()
{
    qt4NodeStaticData()->fileTypeData.clear();
    qt4NodeStaticData()->projectIcon = QIcon();
con's avatar
con committed
173 174
}

175 176
enum { debug = 0 };

Daniel Teske's avatar
Daniel Teske committed
177 178
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
179

180
Qt4PriFile::Qt4PriFile(Qt4ProjectManager::Qt4PriFileNode *qt4PriFile)
181
    : IDocument(qt4PriFile), m_priFile(qt4PriFile)
182 183 184 185
{

}

186
bool Qt4PriFile::save(QString *errorString, const QString &fileName, bool autoSave)
187
{
188
    Q_UNUSED(errorString);
189
    Q_UNUSED(fileName);
190
    Q_UNUSED(autoSave);
191 192 193
    return false;
}

dt's avatar
dt committed
194 195 196 197 198 199 200
void Qt4PriFile::rename(const QString &newName)
{
    // Can't happen
    Q_ASSERT(false);
    Q_UNUSED(newName);
}

201 202 203 204 205 206 207
QString Qt4PriFile::fileName() const
{
    return m_priFile->path();
}

QString Qt4PriFile::defaultPath() const
{
208
    return QString();
209 210 211 212
}

QString Qt4PriFile::suggestedFileName() const
{
213
    return QString();
214 215 216 217
}

QString Qt4PriFile::mimeType() const
{
218
    return QLatin1String(Qt4ProjectManager::Constants::PROFILE_MIMETYPE);
219 220 221 222 223 224 225 226 227 228 229 230
}

bool Qt4PriFile::isModified() const
{
    return false;
}

bool Qt4PriFile::isSaveAsAllowed() const
{
    return false;
}

231
Core::IDocument::ReloadBehavior Qt4PriFile::reloadBehavior(ChangeTrigger state, ChangeType type) const
232
{
233 234 235
    Q_UNUSED(state)
    Q_UNUSED(type)
    return BehaviorSilent;
236 237
}

238
bool Qt4PriFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
239
{
240
    Q_UNUSED(errorString)
241 242
    Q_UNUSED(flag)
    if (type == TypePermissions)
243
        return true;
244
    m_priFile->scheduleUpdate();
245
    return true;
246
}
247

con's avatar
con committed
248 249 250 251 252
/*!
  \class Qt4PriFileNode
  Implements abstract ProjectNode class
  */

253 254
namespace Qt4ProjectManager {

255
Qt4PriFileNode::Qt4PriFileNode(Qt4Project *project, Qt4ProFileNode* qt4ProFileNode, const QString &filePath)
con's avatar
con committed
256 257
        : ProjectNode(filePath),
          m_project(project),
258
          m_qt4ProFileNode(qt4ProFileNode),
259
          m_projectFilePath(QDir::fromNativeSeparators(filePath)),
260 261
          m_projectDir(QFileInfo(filePath).absolutePath()),
          m_includedInExactParse(true)
con's avatar
con committed
262
{
dt's avatar
dt committed
263
    Q_ASSERT(project);
264
    m_qt4PriFile = new Qt4PriFile(this);
265
    Core::DocumentManager::addDocument(m_qt4PriFile);
266

267
    setDisplayName(QFileInfo(filePath).completeBaseName());
Jens Bache-Wiig's avatar
Jens Bache-Wiig committed
268

269
    setIcon(qt4NodeStaticData()->projectIcon);
270 271
}

272 273 274 275 276
Qt4PriFileNode::~Qt4PriFileNode()
{
    watchFolders(QSet<QString>());
}

277 278
void Qt4PriFileNode::scheduleUpdate()
{
279
    QtSupport::ProFileCacheManager::instance()->discardFile(m_projectFilePath);
280
    m_qt4ProFileNode->scheduleUpdate();
con's avatar
con committed
281 282
}

Daniel Teske's avatar
Daniel Teske committed
283
namespace Internal {
284
struct InternalNode
285
{
286 287
    QList<InternalNode *> virtualfolders;
    QMap<QString, InternalNode *> subnodes;
288 289
    QStringList files;
    ProjectExplorer::FileType type;
290
    QString displayName;
291 292
    QString typeName;
    int priority;
293 294
    QString fullPath;
    QIcon icon;
295

296 297 298
    InternalNode()
    {
        type = ProjectExplorer::UnknownFileType;
299
        priority = 0;
300
    }
301

302 303
    ~InternalNode()
    {
304
        qDeleteAll(virtualfolders);
305 306
        qDeleteAll(subnodes);
    }
307

308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
    // Creates a tree structure from a list of absolute file paths.
    // Empty directories are compressed into a single entry with a longer path.
    // * project
    //    * /absolute/path
    //       * file1
    //    * relative
    //       * path1
    //          * file1
    //          * file2
    //       * path2
    //          * file1
    // The method first creates a tree that looks like the directory structure, i.e.
    //    * /
    //       * absolute
    //          * path
    // ...
    // and afterwards calls compress() which merges directory nodes with single children, i.e. to
    //    * /absolute/path
326
    void create(const QString &projectDir, const QSet<Utils::FileName> &newFilePaths, ProjectExplorer::FileType type)
327
    {
328
        static const QChar separator = QLatin1Char('/');
329
        const Utils::FileName projectDirFileName = Utils::FileName::fromString(projectDir);
330 331
        foreach (const Utils::FileName &file, newFilePaths) {
            Utils::FileName fileWithoutPrefix;
332
            bool isRelative;
333
            if (file.isChildOf(projectDirFileName)) {
334
                isRelative = true;
335
                fileWithoutPrefix = file.relativeChildPath(projectDirFileName);
336 337 338 339
            } else {
                isRelative = false;
                fileWithoutPrefix = file;
            }
340
            QStringList parts = fileWithoutPrefix.toString().split(separator, QString::SkipEmptyParts);
341
#ifndef Q_OS_WIN
342 343
            if (!isRelative && parts.count() > 0)
                parts[0].prepend(separator);
344
#endif
345 346
            QStringListIterator it(parts);
            InternalNode *currentNode = this;
347
            QString path = (isRelative ? (projectDirFileName.toString() + QLatin1Char('/')) : QString());
348 349 350 351
            while (it.hasNext()) {
                const QString &key = it.next();
                if (it.hasNext()) { // key is directory
                    path += key;
352
                    if (!currentNode->subnodes.contains(path)) {
353 354 355
                        InternalNode *val = new InternalNode;
                        val->type = type;
                        val->fullPath = path;
356 357
                        val->displayName = key;
                        currentNode->subnodes.insert(path, val);
358 359
                        currentNode = val;
                    } else {
360
                        currentNode = currentNode->subnodes.value(path);
361
                    }
362 363
                    path += separator;
                } else { // key is filename
364
                    currentNode->files.append(file.toString());
365 366 367
                }
            }
        }
368 369
        this->compress();
    }
370

371 372 373 374 375 376 377 378 379
    // Removes folder nodes with only a single sub folder in it
    void compress()
    {
        QMap<QString, InternalNode*> newSubnodes;
        QMapIterator<QString, InternalNode*> i(subnodes);
        while (i.hasNext()) {
            i.next();
            i.value()->compress();
            if (i.value()->files.isEmpty() && i.value()->subnodes.size() == 1) {
380
                // replace i.value() by i.value()->subnodes.begin()
381
                QString key = i.value()->subnodes.begin().key();
382
                InternalNode *keep = i.value()->subnodes.value(key);
383
                keep->displayName = i.value()->displayName + QLatin1Char('/') + keep->displayName;
384
                newSubnodes.insert(key, keep);
385 386 387 388
                i.value()->subnodes.clear();
                delete i.value();
            } else {
                newSubnodes.insert(i.key(), i.value());
389 390
            }
        }
391 392
        subnodes = newSubnodes;
    }
393

394 395 396 397 398 399 400 401 402 403 404 405 406 407
    FolderNode *createFolderNode(InternalNode *node)
    {
        FolderNode *newNode = 0;
        if (node->typeName.isEmpty())
            newNode = new FolderNode(node->fullPath);
        else
            newNode = new ProVirtualFolderNode(node->fullPath, node->priority, node->typeName);

        newNode->setDisplayName(node->displayName);
        if (!node->icon.isNull())
            newNode->setIcon(node->icon);
        return newNode;
    }

408
    // Makes the projectNode's subtree below the given folder match this internal node's subtree
409
    void updateSubFolders(Qt4ProjectManager::Qt4PriFileNode *projectNode, ProjectExplorer::FolderNode *folder)
410 411
    {
        updateFiles(projectNode, folder, type);
412

413 414 415
        // updateFolders
        QMultiMap<QString, FolderNode *> existingFolderNodes;
        foreach (FolderNode *node, folder->subFolderNodes())
416
            if (node->nodeType() != ProjectNodeType)
417
                existingFolderNodes.insert(node->path(), node);
418

419 420 421 422 423
        QList<FolderNode *> foldersToRemove;
        QList<FolderNode *> foldersToAdd;
        typedef QPair<InternalNode *, FolderNode *> NodePair;
        QList<NodePair> nodesToUpdate;

424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
        // Check virtual
        {
            QList<InternalNode *>::const_iterator it = virtualfolders.constBegin();
            QList<InternalNode *>::const_iterator end = virtualfolders.constEnd();
            for ( ; it != end; ++it) {
                bool found = false;
                QString path = (*it)->fullPath;
                QMultiMap<QString, FolderNode *>::const_iterator oldit
                        = existingFolderNodes.constFind(path);
                while (oldit != existingFolderNodes.end() && oldit.key() == path) {
                    if (oldit.value()->nodeType() == ProjectExplorer::VirtualFolderNodeType) {
                        ProjectExplorer::VirtualFolderNode *vfn
                                = qobject_cast<ProjectExplorer::VirtualFolderNode *>(oldit.value());
                        if (vfn->priority() == (*it)->priority) {
                            found = true;
                            break;
                        }
                    }
                    ++oldit;
                }
                if (found) {
                    nodesToUpdate << NodePair(*it, *oldit);
                } else {
                    FolderNode *newNode = createFolderNode(*it);
                    foldersToAdd << newNode;
                    nodesToUpdate << NodePair(*it, newNode);
                }
451
            }
452
        }
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
        // Check subnodes
        {
            QMap<QString, InternalNode *>::const_iterator it = subnodes.constBegin();
            QMap<QString, InternalNode *>::const_iterator end = subnodes.constEnd();

            for ( ; it != end; ++it) {
                bool found = false;
                QString path = it.value()->fullPath;
                QMultiMap<QString, FolderNode *>::const_iterator oldit
                        = existingFolderNodes.constFind(path);
                while (oldit != existingFolderNodes.end() && oldit.key() == path) {
                    if (oldit.value()->nodeType() == ProjectExplorer::FolderNodeType) {
                        found = true;
                        break;
                    }
                    ++oldit;
                }
                if (found) {
                    nodesToUpdate << NodePair(it.value(), *oldit);
                } else {
                    FolderNode *newNode = createFolderNode(it.value());
                    foldersToAdd << newNode;
                    nodesToUpdate << NodePair(it.value(), newNode);
                }
            }
478
        }
479

480 481 482 483 484 485 486 487 488 489
        QSet<FolderNode *> toKeep;
        foreach (const NodePair &np, nodesToUpdate)
            toKeep << np.second;

        QMultiMap<QString, FolderNode *>::const_iterator jit = existingFolderNodes.constBegin();
        QMultiMap<QString, FolderNode *>::const_iterator jend = existingFolderNodes.constEnd();
        for ( ; jit != jend; ++jit)
            if (!toKeep.contains(jit.value()))
                foldersToRemove << jit.value();

490 491 492 493
        if (!foldersToRemove.isEmpty())
            projectNode->removeFolderNodes(foldersToRemove, folder);
        if (!foldersToAdd.isEmpty())
            projectNode->addFolderNodes(foldersToAdd, folder);
494

495 496 497 498 499
        foreach (const NodePair &np, nodesToUpdate)
            np.first->updateSubFolders(projectNode, np.second);
    }

    // Makes the folder's files match this internal node's file list
500
    void updateFiles(Qt4ProjectManager::Qt4PriFileNode *projectNode, FolderNode *folder, FileType type)
501 502 503 504 505
    {
        QList<FileNode*> existingFileNodes;
        foreach (FileNode *fileNode, folder->fileNodes()) {
            if (fileNode->fileType() == type && !fileNode->isGenerated())
                existingFileNodes << fileNode;
506 507
        }

508 509
        QList<FileNode*> filesToRemove;
        QList<FileNode*> filesToAdd;
510

511
        qSort(files);
512
        qSort(existingFileNodes.begin(), existingFileNodes.end(), sortNodesByPath);
513 514 515 516 517 518

        QList<FileNode*>::const_iterator existingNodeIter = existingFileNodes.constBegin();
        QList<QString>::const_iterator newPathIter = files.constBegin();
        while (existingNodeIter != existingFileNodes.constEnd()
               && newPathIter != files.constEnd()) {
            if ((*existingNodeIter)->path() < *newPathIter) {
519 520
                filesToRemove << *existingNodeIter;
                ++existingNodeIter;
521
            } else if ((*existingNodeIter)->path() > *newPathIter) {
522
                filesToAdd << new ProjectExplorer::FileNode(*newPathIter, type, false);
523
                ++newPathIter;
524 525 526
            } else { // *existingNodeIter->path() == *newPathIter
                ++existingNodeIter;
                ++newPathIter;
527 528
            }
        }
529 530 531 532 533
        while (existingNodeIter != existingFileNodes.constEnd()) {
            filesToRemove << *existingNodeIter;
            ++existingNodeIter;
        }
        while (newPathIter != files.constEnd()) {
534
            filesToAdd << new ProjectExplorer::FileNode(*newPathIter, type, false);
535 536 537 538 539 540 541 542 543
            ++newPathIter;
        }

        if (!filesToRemove.isEmpty())
            projectNode->removeFileNodes(filesToRemove, folder);
        if (!filesToAdd.isEmpty())
            projectNode->addFileNodes(filesToAdd, folder);
    }
};
Daniel Teske's avatar
Daniel Teske committed
544
}
dt's avatar
dt committed
545

546
QStringList Qt4PriFileNode::baseVPaths(QtSupport::ProFileReader *reader, const QString &projectDir)
con's avatar
con committed
547
{
dt's avatar
dt committed
548 549 550
    QStringList result;
    if (!reader)
        return result;
551
    result += reader->absolutePathValues(QLatin1String("VPATH"), projectDir);
dt's avatar
dt committed
552
    result << projectDir; // QMAKE_ABSOLUTE_SOURCE_PATH
553
    result += reader->absolutePathValues(QLatin1String("DEPENDPATH"), projectDir);
dt's avatar
dt committed
554 555 556
    result.removeDuplicates();
    return result;
}
con's avatar
con committed
557

558
QStringList Qt4PriFileNode::fullVPaths(const QStringList &baseVPaths, QtSupport::ProFileReader *reader, FileType type, const QString &qmakeVariable, const QString &projectDir)
dt's avatar
dt committed
559 560 561 562 563
{
    QStringList vPaths;
    if (!reader)
        return vPaths;
    if (type == ProjectExplorer::SourceType)
564
        vPaths = reader->absolutePathValues(QLatin1String("VPATH_") + qmakeVariable, projectDir);
dt's avatar
dt committed
565 566
    vPaths += baseVPaths;
    if (type == ProjectExplorer::HeaderType)
567
        vPaths += reader->absolutePathValues(QLatin1String("INCLUDEPATH"), projectDir);
dt's avatar
dt committed
568 569 570 571
    vPaths.removeDuplicates();
    return vPaths;
}

572
static QSet<Utils::FileName> recursiveEnumerate(const QString &folder)
573
{
574
    QSet<Utils::FileName> result;
575 576 577 578 579 580
    QFileInfo fi(folder);
    if (fi.isDir()) {
        QDir dir(folder);
        dir.setFilter(dir.filter() | QDir::NoDotAndDotDot);

        foreach (const QFileInfo &file, dir.entryInfoList()) {
581
            if (file.isDir() && !file.isSymLink())
582 583
                result += recursiveEnumerate(file.absoluteFilePath());
            else
584
                result += Utils::FileName(file);
585 586
        }
    } else if (fi.exists()) {
587
        result << Utils::FileName(fi);
588 589 590
    }
    return result;
}
dt's avatar
dt committed
591

592
void Qt4PriFileNode::update(ProFile *includeFileExact, QtSupport::ProFileReader *readerExact, ProFile *includeFileCumlative, QtSupport::ProFileReader *readerCumulative)
dt's avatar
dt committed
593
{
con's avatar
con committed
594 595
    // add project file node
    if (m_fileNodes.isEmpty())
596
        addFileNodes(QList<FileNode*>() << new ProjectExplorer::FileNode(m_projectFilePath, ProjectExplorer::ProjectFileType, false), this);
con's avatar
con committed
597

598 599
    const QString &projectDir = m_qt4ProFileNode->m_projectDir;

600 601
    InternalNode contents;

602 603 604
    // Figure out DEPLOYMENT and INSTALL folders
    QStringList folders;
    QStringList dynamicVariables = dynamicVarNames(readerExact, readerCumulative);
605 606 607 608 609 610 611 612
    if (includeFileExact)
        foreach (const QString &dynamicVar, dynamicVariables) {
            folders += readerExact->values(dynamicVar, includeFileExact);
            // Ignore stuff from cumulative parse
            // we are recursively enumerating all the files from those folders
            // and add watchers for them, that's too dangerous if we get the foldrs
            // wrong and enumerate the whole project tree multiple times
        }
613 614 615


    for (int i=0; i < folders.size(); ++i) {
616
        const QFileInfo fi(folders.at(i));
617
        if (fi.isRelative())
618
            folders[i] = QDir::cleanPath(projectDir + QLatin1Char('/') + folders.at(i));
619 620
    }

dt's avatar
dt committed
621 622

    m_recursiveEnumerateFiles.clear();
623
    // Remove non existing items and non folders
dt's avatar
dt committed
624 625 626
    QStringList::iterator it = folders.begin();
    while (it != folders.end()) {
        QFileInfo fi(*it);
dt's avatar
dt committed
627 628 629 630 631 632
        if (fi.exists()) {
            if (fi.isDir()) {
                // keep directories
                ++it;
            } else {
                // move files directly to m_recursiveEnumerateFiles
633
                m_recursiveEnumerateFiles << Utils::FileName::fromString(*it);
dt's avatar
dt committed
634 635 636 637
                it = folders.erase(it);
            }
        } else {
            // do remove non exsting stuff
dt's avatar
dt committed
638
            it = folders.erase(it);
dt's avatar
dt committed
639
        }
dt's avatar
dt committed
640 641
    }

642 643 644 645 646 647
    folders.removeDuplicates();
    watchFolders(folders.toSet());

    foreach (const QString &folder, folders) {
        m_recursiveEnumerateFiles += recursiveEnumerate(folder);
    }
648
    QMap<FileType, QSet<Utils::FileName> > foundFiles;
dt's avatar
dt committed
649

650 651 652 653 654 655 656 657 658
    QStringList baseVPathsExact;
    if (includeFileExact)
        baseVPathsExact = baseVPaths(readerExact, projectDir);
    QStringList baseVPathsCumulative;
    if (includeFileCumlative)
        baseVPathsCumulative = baseVPaths(readerCumulative, projectDir);

    const QVector<Qt4NodeStaticData::FileTypeData> &fileTypes = qt4NodeStaticData()->fileTypeData;

con's avatar
con committed
659
    // update files
660
    for (int i = 0; i < fileTypes.size(); ++i) {
661
        FileType type = fileTypes.at(i).type;
662
        QStringList qmakeVariables = varNames(type);
con's avatar
con committed
663

664
        QSet<Utils::FileName> newFilePaths;
665
        foreach (const QString &qmakeVariable, qmakeVariables) {
666 667
            if (includeFileExact) {
                QStringList vPathsExact = fullVPaths(baseVPathsExact, readerExact, type, qmakeVariable, projectDir);
668 669 670
                QStringList tmp = readerExact->absoluteFileValues(qmakeVariable, projectDir, vPathsExact, includeFileExact);
                foreach (const QString &t, tmp)
                    newFilePaths += Utils::FileName::fromString(t);
671 672 673
            }
            if (includeFileCumlative) {
                QStringList vPathsCumulative = fullVPaths(baseVPathsCumulative, readerCumulative, type, qmakeVariable, projectDir);
674 675 676
                QStringList tmp = readerCumulative->absoluteFileValues(qmakeVariable, projectDir, vPathsCumulative, includeFileCumlative);
                foreach (const QString &t, tmp)
                    newFilePaths += Utils::FileName::fromString(t);
677
            }
678
        }
con's avatar
con committed
679

dt's avatar
dt committed
680 681 682 683 684 685
        foundFiles[type] = newFilePaths;
        m_recursiveEnumerateFiles.subtract(newFilePaths);
    }

    for (int i = 0; i < fileTypes.size(); ++i) {
        FileType type = fileTypes.at(i).type;
686
        QSet<Utils::FileName> newFilePaths = filterFilesProVariables(type, foundFiles[type]);
687
        newFilePaths += filterFilesRecursiveEnumerata(type, m_recursiveEnumerateFiles);
688 689 690 691 692 693 694 695

        // We only need to save this information if
        // we are watching folders
        if (!folders.isEmpty())
            m_files[type] = newFilePaths;
        else
            m_files[type].clear();

696 697 698
        if (!newFilePaths.isEmpty()) {
            InternalNode *subfolder = new InternalNode;
            subfolder->type = type;
699
            subfolder->icon = fileTypes.at(i).icon;
700 701 702
            subfolder->fullPath = m_projectDir;
            subfolder->typeName = fileTypes.at(i).typeName;
            subfolder->priority = -i;
703
            subfolder->displayName = fileTypes.at(i).typeName;
704
            contents.virtualfolders.append(subfolder);
705
            // create the hierarchy with subdirectories
706
            subfolder->create(m_projectDir, newFilePaths, type);
con's avatar
con committed
707 708
        }
    }
709 710 711 712 713 714 715 716 717 718 719 720 721

    contents.updateSubFolders(this, this);
}

void Qt4PriFileNode::watchFolders(const QSet<QString> &folders)
{
    QSet<QString> toUnwatch = m_watchedFolders;
    toUnwatch.subtract(folders);

    QSet<QString> toWatch = folders;
    toWatch.subtract(m_watchedFolders);

    if (!toUnwatch.isEmpty())
722
        m_project->unwatchFolders(toUnwatch.toList(), this);
723
    if (!toWatch.isEmpty())
724
        m_project->watchFolders(toWatch.toList(), this);
725 726 727 728

    m_watchedFolders = folders;
}

729
void Qt4PriFileNode::folderChanged(const QString &folder)
730 731 732 733
{
    //qDebug()<<"########## Qt4PriFileNode::folderChanged";
    // So, we need to figure out which files changed.

734 735 736 737
    QString changedFolder = folder;
    if (!changedFolder.endsWith(QLatin1Char('/')))
        changedFolder.append(QLatin1Char('/'));

738
    // Collect all the files
739
    QSet<Utils::FileName> newFiles;
740 741
    newFiles += recursiveEnumerate(changedFolder);

742
    foreach (const Utils::FileName &file, m_recursiveEnumerateFiles) {
743
        if (!file.isChildOf(Utils::FileName::fromString(changedFolder)))
744
            newFiles.insert(file);
745 746
    }

747
    QSet<Utils::FileName> addedFiles = newFiles;
748 749
    addedFiles.subtract(m_recursiveEnumerateFiles);

750
    QSet<Utils::FileName> removedFiles = m_recursiveEnumerateFiles;
751 752 753 754 755 756 757 758 759 760 761 762
    removedFiles.subtract(newFiles);

    if (addedFiles.isEmpty() && removedFiles.isEmpty())
        return;

    m_recursiveEnumerateFiles = newFiles;

    // Apply the differences
    // per file type
    const QVector<Qt4NodeStaticData::FileTypeData> &fileTypes = qt4NodeStaticData()->fileTypeData;
    for (int i = 0; i < fileTypes.size(); ++i) {
        FileType type = fileTypes.at(i).type;
763 764
        QSet<Utils::FileName> add = filterFilesRecursiveEnumerata(type, addedFiles);
        QSet<Utils::FileName> remove = filterFilesRecursiveEnumerata(type, removedFiles);
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784

        if (!add.isEmpty() || !remove.isEmpty()) {
            // Scream :)
//            qDebug()<<"For type"<<fileTypes.at(i).typeName<<"\n"
//                    <<"added files"<<add<<"\n"
//                    <<"removed files"<<remove;

            m_files[type].unite(add);
            m_files[type].subtract(remove);
        }
    }

    // Now apply stuff
    InternalNode contents;
    for (int i = 0; i < fileTypes.size(); ++i) {
        FileType type = fileTypes.at(i).type;
        if (!m_files[type].isEmpty()) {
            InternalNode *subfolder = new InternalNode;
            subfolder->type = type;
            subfolder->icon = fileTypes.at(i).icon;
785 786 787
            subfolder->fullPath = m_projectDir;
            subfolder->typeName = fileTypes.at(i).typeName;
            subfolder->priority = -i;
788
            subfolder->displayName = fileTypes.at(i).typeName;
789
            contents.virtualfolders.append(subfolder);
790
            // create the hierarchy with subdirectories
791
            subfolder->create(m_projectDir, m_files[type], type);
792 793 794
        }
    }

795
    contents.updateSubFolders(this, this);
796
    m_project->updateFileList();
797
    m_project->updateCodeModels();
798 799 800 801 802 803

    // The files to be packaged are listed inside the symbian build system.
    // We need to regenerate that list by running qmake
    // Other platforms do not have a explicit list of files to package, but package
    // directories
    foreach (ProjectExplorer::Target *target, m_project->targets()) {
804
        if (target->id() == Core::Id(Constants::S60_DEVICE_TARGET_ID)) {
805 806 807 808 809 810 811 812 813 814 815
            foreach (ProjectExplorer::BuildConfiguration *bc, target->buildConfigurations()) {
                Qt4BuildConfiguration *qt4bc = qobject_cast<Qt4BuildConfiguration *>(bc);
                if (qt4bc) {
                    QMakeStep *qmakeStep = qt4bc->qmakeStep();
                    if (qmakeStep)
                        qmakeStep->setForced(true);
                }
            }
        }
    }

con's avatar
con committed
816 817
}

dt's avatar
dt committed
818 819 820
bool Qt4PriFileNode::deploysFolder(const QString &folder) const
{
    QString f = folder;
821 822 823
    const QChar slash = QLatin1Char('/');
    if (!f.endsWith(slash))
        f.append(slash);
dt's avatar
dt committed
824 825
    foreach (const QString &wf, m_watchedFolders) {
        if (f.startsWith(wf)
826 827
            && (wf.endsWith(slash)
                || (wf.length() < f.length() && f.at(wf.length()) == slash)))
dt's avatar
dt committed
828 829 830 831 832
            return true;
    }
    return false;
}

dt's avatar
dt committed
833 834
QList<ProjectExplorer::RunConfiguration *> Qt4PriFileNode::runConfigurationsFor(Node *node)
{
835 836 837 838
    Qt4BaseTarget *target = m_project->activeTarget();
    if (target)
        return target->runConfigurationsForNode(node);
    return QList<ProjectExplorer::RunConfiguration *>();
dt's avatar
dt committed
839 840
}

841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
QList<Qt4PriFileNode *> Qt4PriFileNode::subProjectNodesExact() const
{
    QList<Qt4PriFileNode *> nodes;
    foreach (ProjectNode *node, subProjectNodes()) {
        Qt4PriFileNode *n = qobject_cast<Qt4PriFileNode *>(node);
        if (n && n->includedInExactParse())
            nodes << n;
    }
    return nodes;
}

bool Qt4PriFileNode::includedInExactParse() const
{
    return m_includedInExactParse;
}

void Qt4PriFileNode::setIncludedInExactParse(bool b)
{
    m_includedInExactParse = b;
}

dt's avatar
dt committed
862
QList<ProjectNode::ProjectAction> Qt4PriFileNode::supportedActions(Node *node) const
con's avatar
con committed
863 864
{
    QList<ProjectAction> actions;
865 866 867 868 869

    const FolderNode *folderNode = this;
    const Qt4ProFileNode *proFileNode;
    while (!(proFileNode = qobject_cast<const Qt4ProFileNode*>(folderNode)))
        folderNode = folderNode->parentFolderNode();
dt's avatar
dt committed
870
    Q_ASSERT(proFileNode);
871 872 873

    switch (proFileNode->projectType()) {
    case ApplicationTemplate:
874 875 876 877 878 879
    case LibraryTemplate:
    case AuxTemplate: {
        // TODO: Some of the file types don't make much sense for aux
        // projects (e.g. cpp). It'd be nice if the "add" action could
        // work on a subset of the file types according to project type.

dt's avatar
dt committed
880
        actions << AddNewFile;
881
        if (m_recursiveEnumerateFiles.contains(Utils::FileName::fromString(node->path()))) {
dt's avatar
dt committed
882
            actions << EraseFile;
dt's avatar
dt committed
883
        } else {
884
            actions << RemoveFile;
dt's avatar
dt committed
885 886
        }