/*************************************************************************** ** ** This file is part of Qt Creator ** ** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). ** ** Contact: Qt Software Information (qt-info@nokia.com) ** ** ** Non-Open Source Usage ** ** Licensees may use this file in accordance with the Qt Beta Version ** License Agreement, Agreement version 2.2 provided with the Software or, ** alternatively, in accordance with the terms contained in a written ** agreement between you and Nokia. ** ** GNU General Public License Usage ** ** Alternatively, this file may be used under the terms of the GNU General ** Public License versions 2.0 or 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the packaging ** of this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and ** http://www.gnu.org/copyleft/gpl.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt GPL Exception ** version 1.2, included in the file GPL_EXCEPTION.txt in this package. ** ***************************************************************************/ #ifndef PROJECTNODES_H #define PROJECTNODES_H #include #include #include #include "projectexplorer_export.h" QT_BEGIN_NAMESPACE class QFileInfo; QT_END_NAMESPACE namespace Core { class MimeDatabase; } namespace ProjectExplorer { // // = Node hierarchy = // // The nodes are arranged in a tree where leaves are FileNodes and non-leaves are FolderNodes // A Project is a special Folder that manages the files and normal folders underneath it. // // The Watcher emits signals for structural changes in the hierarchy. // A Visitor can be used to traverse all Projects and other Folders. // enum NodeType { FileNodeType = 1, FolderNodeType, ProjectNodeType, SessionNodeType }; // File types common for qt projects enum FileType { UnknownFileType = 0, HeaderType, SourceType, FormType, ResourceType, ProjectFileType, FileTypeSize }; class Node; class FileNode; class FileContainerNode; class FolderNode; class ProjectNode; class NodesWatcher; class NodesVisitor; 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; }; class PROJECTEXPLORER_EXPORT FolderNode : public Node { Q_OBJECT public: explicit FolderNode(const QString &folderPath); virtual ~FolderNode(); QString name() const; QIcon icon() const; QList fileNodes() const; QList subFolderNodes() const; virtual void accept(NodesVisitor *visitor); protected: void setFolderName(const QString &name); void setIcon(const QIcon &icon); QList m_subFolderNodes; QList m_fileNodes; private: // managed by ProjectNode friend class ProjectNode; QString m_folderName; QIcon m_icon; }; class PROJECTEXPLORER_EXPORT ProjectNode : public FolderNode { Q_OBJECT public: enum ProjectAction { AddSubProject, RemoveSubProject, AddFile, RemoveFile }; // all subFolders that are projects QList subProjectNodes() const; // determines if the project will be shown in the flat view // TODO find a better name virtual bool hasTargets() const = 0; virtual QList supportedActions() const = 0; 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; virtual bool renameFile(const FileType fileType, const QString &filePath, const QString &newFilePath) = 0; QList 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 &subProjects); void removeProjectNodes(const QList &subProjects); void addFolderNodes(const QList &subFolders, FolderNode *parentFolder); void removeFolderNodes(const QList &subFolders, FolderNode *parentFolder); void addFileNodes(const QList &files, FolderNode *parentFolder); void removeFileNodes(const QList &files, FolderNode *parentFolder); private slots: void watcherDestroyed(QObject *watcher); private: QList m_subProjectNodes; QList m_watchers; // let SessionNode call setParentFolderNode friend class SessionNode; }; class PROJECTEXPLORER_EXPORT SessionNode : public FolderNode { Q_OBJECT public: SessionNode(const QString &sessionFilePath, QObject *parentObject); QList projectNodes() const; QList watchers() const; void registerWatcher(NodesWatcher *watcher); void unregisterWatcher(NodesWatcher *watcher); void accept(NodesVisitor *visitor); protected: void addProjectNodes(const QList &projectNodes); void removeProjectNodes(const QList &projectNodes); private slots: void watcherDestroyed(QObject *watcher); private: QList m_projectNodes; QList m_watchers; }; class PROJECTEXPLORER_EXPORT NodesWatcher : public QObject { Q_OBJECT public: explicit NodesWatcher(QObject *parent = 0); signals: // folders & projects void foldersAboutToBeAdded(FolderNode *parentFolder, const QList &newFolders); void foldersAdded(); void foldersAboutToBeRemoved(FolderNode *parentFolder, const QList &staleFolders); void foldersRemoved(); // files void filesAboutToBeAdded(FolderNode *folder, const QList &newFiles); void filesAdded(); void filesAboutToBeRemoved(FolderNode *folder, const QList &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