1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
28 **************************************************************************/
30 #ifndef PROJECTNODES_H
31 #define PROJECTNODES_H
33 #include <QtCore/QObject>
34 #include <QtCore/QStringList>
35 #include <QtGui/QIcon>
37 #include "projectexplorer_export.h"
48 namespace ProjectExplorer {
53 // The nodes are arranged in a tree where leaves are FileNodes and non-leaves are FolderNodes
54 // A Project is a special Folder that manages the files and normal folders underneath it.
56 // The Watcher emits signals for structural changes in the hierarchy.
57 // A Visitor can be used to traverse all Projects and other Folders.
67 // File types common for qt projects
81 class FileContainerNode;
87 class PROJECTEXPLORER_EXPORT Node : public QObject {
90 NodeType nodeType() const;
91 ProjectNode *projectNode() const; // managing project
92 FolderNode *parentFolderNode() const; // parent folder or project
93 QString path() const; // file system path
96 Node(NodeType nodeType, const QString &path);
98 void setNodeType(NodeType type);
99 void setProjectNode(ProjectNode *project);
100 void setParentFolderNode(FolderNode *parentFolder);
101 void setPath(const QString &path);
105 ProjectNode *m_projectNode;
106 FolderNode *m_folderNode;
110 class PROJECTEXPLORER_EXPORT FileNode : public Node {
113 FileNode(const QString &filePath, const FileType fileType, bool generated);
115 FileType fileType() const;
116 bool isGenerated() const;
119 // managed by ProjectNode
120 friend class ProjectNode;
126 class PROJECTEXPLORER_EXPORT FolderNode : public Node {
129 explicit FolderNode(const QString &folderPath);
130 virtual ~FolderNode();
132 QString displayName() const;
135 QList<FileNode*> fileNodes() const;
136 QList<FolderNode*> subFolderNodes() const;
138 virtual void accept(NodesVisitor *visitor);
140 void setDisplayName(const QString &name);
141 void setIcon(const QIcon &icon);
144 QList<FolderNode*> m_subFolderNodes;
145 QList<FileNode*> m_fileNodes;
148 // managed by ProjectNode
149 friend class ProjectNode;
150 QString m_displayName;
151 mutable QIcon m_icon;
154 class PROJECTEXPLORER_EXPORT ProjectNode : public FolderNode
162 // Let's the user select to which project file
166 // Removes a file from the project, optionally also
169 // Deletes a file from the file system, informs the project
170 // that a file was deleted
171 // DeleteFile is a define on windows...
176 // all subFolders that are projects
177 QList<ProjectNode*> subProjectNodes() const;
179 // determines if the project will be shown in the flat view
180 // TODO find a better name
181 virtual bool hasBuildTargets() const = 0;
183 virtual QList<ProjectAction> supportedActions(Node *node) const = 0;
185 virtual bool addSubProjects(const QStringList &proFilePaths) = 0;
187 virtual bool removeSubProjects(const QStringList &proFilePaths) = 0;
189 virtual bool addFiles(const FileType fileType,
190 const QStringList &filePaths,
191 QStringList *notAdded = 0) = 0;
192 // TODO: Maybe remove fileType, can be detected by project
193 virtual bool removeFiles(const FileType fileType,
194 const QStringList &filePaths,
195 QStringList *notRemoved = 0) = 0;
196 virtual bool deleteFiles(const FileType fileType,
197 const QStringList &filePaths) = 0;
198 virtual bool renameFile(const FileType fileType,
199 const QString &filePath,
200 const QString &newFilePath) = 0;
201 // by default returns false
202 virtual bool deploysFolder(const QString &folder) const;
205 QList<NodesWatcher*> watchers() const;
206 void registerWatcher(NodesWatcher *watcher);
207 void unregisterWatcher(NodesWatcher *watcher);
209 void accept(NodesVisitor *visitor);
211 static bool sortNodesByPath(Node *n1, Node *n2);
214 // this is just the in-memory representation, a subclass
215 // will add the persistent stuff
216 explicit ProjectNode(const QString &projectFilePath);
218 // to be called in implementation of
219 // the corresponding public methods
220 void addProjectNodes(const QList<ProjectNode*> &subProjects);
221 void removeProjectNodes(const QList<ProjectNode*> &subProjects);
223 void addFolderNodes(const QList<FolderNode*> &subFolders, FolderNode *parentFolder);
224 void removeFolderNodes(const QList<FolderNode*> &subFolders, FolderNode *parentFolder);
226 void addFileNodes(const QList<FileNode*> &files, FolderNode *parentFolder);
227 void removeFileNodes(const QList<FileNode*> &files, FolderNode *parentFolder);
230 void watcherDestroyed(QObject *watcher);
233 QList<ProjectNode*> m_subProjectNodes;
234 QList<NodesWatcher*> m_watchers;
236 // let SessionNode call setParentFolderNode
237 friend class SessionNode;
240 class PROJECTEXPLORER_EXPORT SessionNode : public FolderNode {
243 SessionNode(const QString &sessionFilePath, QObject *parentObject);
245 QList<ProjectNode*> projectNodes() const;
247 QList<NodesWatcher*> watchers() const;
248 void registerWatcher(NodesWatcher *watcher);
249 void unregisterWatcher(NodesWatcher *watcher);
251 void accept(NodesVisitor *visitor);
254 void addProjectNodes(const QList<ProjectNode*> &projectNodes);
255 void removeProjectNodes(const QList<ProjectNode*> &projectNodes);
258 void watcherDestroyed(QObject *watcher);
261 QList<ProjectNode*> m_projectNodes;
262 QList<NodesWatcher*> m_watchers;
265 class PROJECTEXPLORER_EXPORT NodesWatcher : public QObject {
268 explicit NodesWatcher(QObject *parent = 0);
271 // folders & projects
272 void foldersAboutToBeAdded(FolderNode *parentFolder,
273 const QList<FolderNode*> &newFolders);
276 void foldersAboutToBeRemoved(FolderNode *parentFolder,
277 const QList<FolderNode*> &staleFolders);
278 void foldersRemoved();
281 void filesAboutToBeAdded(FolderNode *folder,
282 const QList<FileNode*> &newFiles);
285 void filesAboutToBeRemoved(FolderNode *folder,
286 const QList<FileNode*> &staleFiles);
291 // let project & session emit signals
292 friend class ProjectNode;
293 friend class SessionNode;
297 } // namespace ProjectExplorer
299 // HACK: THERE SHOULD BE ONE PLACE TO MAKE THE FILE ENDING->FILE TYPE ASSOCIATION
300 ProjectExplorer::FileType typeForFileName(const Core::MimeDatabase *db, const QFileInfo &file);
302 #endif // PROJECTNODES_H