projectnodes.h 8.93 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
con's avatar
con committed
8
**
9
**
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 29
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
con's avatar
con committed
30
**
31
**************************************************************************/
hjk's avatar
hjk committed
32

con's avatar
con committed
33 34 35 36 37 38 39
#ifndef PROJECTNODES_H
#define PROJECTNODES_H

#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtGui/QIcon>

dt's avatar
dt committed
40
#include "runconfiguration.h"
con's avatar
con committed
41 42
#include "projectexplorer_export.h"

dt's avatar
dt committed
43

con's avatar
con committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
QT_BEGIN_NAMESPACE
class QFileInfo;
QT_END_NAMESPACE


namespace Core {
    class MimeDatabase;
}

namespace ProjectExplorer {

enum NodeType {
    FileNodeType = 1,
    FolderNodeType,
    ProjectNodeType,
    SessionNodeType
};

// File types common for qt projects
enum FileType {
    UnknownFileType = 0,
    HeaderType,
    SourceType,
    FormType,
    ResourceType,
69
    QMLType,
con's avatar
con committed
70 71 72 73 74 75 76 77 78 79 80 81
    ProjectFileType,
    FileTypeSize
};

class Node;
class FileNode;
class FileContainerNode;
class FolderNode;
class ProjectNode;
class NodesWatcher;
class NodesVisitor;

82
// Documentation inside.
con's avatar
con committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
class PROJECTEXPLORER_EXPORT Node : public QObject {
    Q_OBJECT
public:
    NodeType nodeType() const;
    ProjectNode *projectNode() const;     // managing project
    FolderNode *parentFolderNode() const; // parent folder or project
    QString path() const;                 // file system path

protected:
    Node(NodeType nodeType, const QString &path);

    void setNodeType(NodeType type);
    void setProjectNode(ProjectNode *project);
    void setParentFolderNode(FolderNode *parentFolder);
    void setPath(const QString &path);

private:
    NodeType m_nodeType;
    ProjectNode *m_projectNode;
    FolderNode *m_folderNode;
    QString m_path;
};

class PROJECTEXPLORER_EXPORT FileNode : public Node {
    Q_OBJECT
public:
    FileNode(const QString &filePath, const FileType fileType, bool generated);

    FileType fileType() const;
    bool isGenerated() const;

private:
    // managed by ProjectNode
    friend class ProjectNode;

    FileType m_fileType;
    bool m_generated;
};

122
// Documentation inside.
con's avatar
con committed
123 124 125 126 127 128
class PROJECTEXPLORER_EXPORT FolderNode : public Node {
    Q_OBJECT
public:
    explicit FolderNode(const QString &folderPath);
    virtual ~FolderNode();

129
    QString displayName() const;
con's avatar
con committed
130 131 132 133 134 135 136
    QIcon icon() const;

    QList<FileNode*> fileNodes() const;
    QList<FolderNode*> subFolderNodes() const;

    virtual void accept(NodesVisitor *visitor);

137
    void setDisplayName(const QString &name);
con's avatar
con committed
138 139
    void setIcon(const QIcon &icon);

140
protected:
con's avatar
con committed
141 142 143 144 145 146
    QList<FolderNode*> m_subFolderNodes;
    QList<FileNode*> m_fileNodes;

private:
    // managed by ProjectNode
    friend class ProjectNode;
147
    QString m_displayName;
148
    mutable QIcon m_icon;
con's avatar
con committed
149 150
};

151
// Documentation inside.
con's avatar
con committed
152 153 154 155 156 157 158 159
class PROJECTEXPLORER_EXPORT ProjectNode : public FolderNode
{
    Q_OBJECT

public:
    enum ProjectAction {
        AddSubProject,
        RemoveSubProject,
dt's avatar
dt committed
160 161 162 163 164 165
        // Let's the user select to which project file
        // the file is added
        AddNewFile,
        AddExistingFile,
        // Removes a file from the project, optionally also
        // delete it on disc
dt's avatar
dt committed
166
        RemoveFile,
dt's avatar
dt committed
167 168
        // Deletes a file from the file system, informs the project
        // that a file was deleted
dt's avatar
dt committed
169 170
        // DeleteFile is a define on windows...
        EraseFile,
dt's avatar
dt committed
171 172
        Rename,
        HasSubProjectRunConfigurations
con's avatar
con committed
173 174 175 176 177 178 179
    };

    // all subFolders that are projects
    QList<ProjectNode*> subProjectNodes() const;

    // determines if the project will be shown in the flat view
    // TODO find a better name
180 181
    void aboutToChangeHasBuildTargets();
    void hasBuildTargetsChanged();
182
    virtual bool hasBuildTargets() const = 0;
con's avatar
con committed
183

dt's avatar
dt committed
184
    virtual QList<ProjectAction> supportedActions(Node *node) const = 0;
con's avatar
con committed
185

186 187
    virtual bool canAddSubProject(const QString &proFilePath) const = 0;

con's avatar
con committed
188 189 190 191 192 193 194 195 196 197 198
    virtual bool addSubProjects(const QStringList &proFilePaths) = 0;

    virtual bool removeSubProjects(const QStringList &proFilePaths) = 0;

    virtual bool addFiles(const FileType fileType,
                          const QStringList &filePaths,
                          QStringList *notAdded = 0) = 0;
    // TODO: Maybe remove fileType, can be detected by project
    virtual bool removeFiles(const FileType fileType,
                             const QStringList &filePaths,
                             QStringList *notRemoved = 0) = 0;
199 200
    virtual bool deleteFiles(const FileType fileType,
                             const QStringList &filePaths) = 0;
con's avatar
con committed
201 202 203
    virtual bool renameFile(const FileType fileType,
                             const QString &filePath,
                             const QString &newFilePath) = 0;
dt's avatar
dt committed
204 205
    // by default returns false
    virtual bool deploysFolder(const QString &folder) const;
con's avatar
con committed
206

dt's avatar
dt committed
207 208 209
    // TODO node parameter not really needed
    virtual QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node) = 0;

210

con's avatar
con committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
    QList<NodesWatcher*> watchers() const;
    void registerWatcher(NodesWatcher *watcher);
    void unregisterWatcher(NodesWatcher *watcher);

    void accept(NodesVisitor *visitor);

    static bool sortNodesByPath(Node *n1, Node *n2);

protected:
    // this is just the in-memory representation, a subclass
    // will add the persistent stuff
    explicit ProjectNode(const QString &projectFilePath);

    // to be called in implementation of
    // the corresponding public methods
    void addProjectNodes(const QList<ProjectNode*> &subProjects);
    void removeProjectNodes(const QList<ProjectNode*> &subProjects);

    void addFolderNodes(const QList<FolderNode*> &subFolders, FolderNode *parentFolder);
    void removeFolderNodes(const QList<FolderNode*> &subFolders, FolderNode *parentFolder);

    void addFileNodes(const QList<FileNode*> &files, FolderNode *parentFolder);
    void removeFileNodes(const QList<FileNode*> &files, FolderNode *parentFolder);

private slots:
    void watcherDestroyed(QObject *watcher);

private:
    QList<ProjectNode*> m_subProjectNodes;
    QList<NodesWatcher*> m_watchers;

    // let SessionNode call setParentFolderNode
    friend class SessionNode;
};

246
// Documentation inside.
con's avatar
con committed
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
class PROJECTEXPLORER_EXPORT SessionNode : public FolderNode {
    Q_OBJECT
public:
    SessionNode(const QString &sessionFilePath, QObject *parentObject);

    QList<ProjectNode*> projectNodes() const;

    QList<NodesWatcher*> watchers() const;
    void registerWatcher(NodesWatcher *watcher);
    void unregisterWatcher(NodesWatcher *watcher);

    void accept(NodesVisitor *visitor);

protected:
    void addProjectNodes(const QList<ProjectNode*> &projectNodes);
    void removeProjectNodes(const QList<ProjectNode*> &projectNodes);

private slots:
    void watcherDestroyed(QObject *watcher);

private:
    QList<ProjectNode*> m_projectNodes;
    QList<NodesWatcher*> m_watchers;
};

272
// Documentation inside.
con's avatar
con committed
273 274 275 276 277 278
class PROJECTEXPLORER_EXPORT NodesWatcher : public QObject {
    Q_OBJECT
public:
    explicit NodesWatcher(QObject *parent = 0);

signals:
279 280 281 282
    // projects
    void aboutToChangeHasBuildTargets(ProjectExplorer::ProjectNode*);
    void hasBuildTargetsChanged(ProjectExplorer::ProjectNode *node);

con's avatar
con committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
    // folders & projects
    void foldersAboutToBeAdded(FolderNode *parentFolder,
                               const QList<FolderNode*> &newFolders);
    void foldersAdded();

    void foldersAboutToBeRemoved(FolderNode *parentFolder,
                               const QList<FolderNode*> &staleFolders);
    void foldersRemoved();

    // files
    void filesAboutToBeAdded(FolderNode *folder,
                               const QList<FileNode*> &newFiles);
    void filesAdded();

    void filesAboutToBeRemoved(FolderNode *folder,
                               const QList<FileNode*> &staleFiles);
    void filesRemoved();

private:

    // let project & session emit signals
    friend class ProjectNode;
    friend class SessionNode;
};


} // namespace ProjectExplorer

// HACK: THERE SHOULD BE ONE PLACE TO MAKE THE FILE ENDING->FILE TYPE ASSOCIATION
ProjectExplorer::FileType typeForFileName(const Core::MimeDatabase *db, const QFileInfo &file);

#endif // PROJECTNODES_H