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 **************************************************************************/
33 #include <coreplugin/ifile.h>
34 #include <projectexplorer/projectnodes.h>
35 #include <projectexplorer/project.h>
37 #include <QtCore/QHash>
38 #include <QtCore/QStringList>
39 #include <QtCore/QDateTime>
40 #include <QtCore/QMap>
41 #include <QtCore/QFutureWatcher>
43 // defined in proitems.h
52 namespace Qt4ProjectManager {
54 // Import base classes into namespace
55 using ProjectExplorer::Node;
56 using ProjectExplorer::FileNode;
57 using ProjectExplorer::FolderNode;
58 using ProjectExplorer::ProjectNode;
59 using ProjectExplorer::NodesWatcher;
61 // Import enums into namespace
62 using ProjectExplorer::NodeType;
63 using ProjectExplorer::FileNodeType;
64 using ProjectExplorer::FolderNodeType;
65 using ProjectExplorer::ProjectNodeType;
67 using ProjectExplorer::UnknownFileType;
68 using ProjectExplorer::ProjectFileType;
74 using ProjectExplorer::FileType;
76 class Qt4UiCodeModelSupport;
87 // Other variables of interest
101 class Qt4PriFile : public Core::IFile
105 Qt4PriFile(Qt4PriFileNode *qt4PriFile);
106 virtual bool save(const QString &fileName = QString());
107 virtual QString fileName() const;
108 virtual void rename(const QString &newName);
110 virtual QString defaultPath() const;
111 virtual QString suggestedFileName() const;
112 virtual QString mimeType() const;
114 virtual bool isModified() const;
115 virtual bool isReadOnly() const;
116 virtual bool isSaveAsAllowed() const;
118 ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
119 void reload(ReloadFlag flag, ChangeType type);
122 Qt4PriFileNode *m_priFile;
125 // Implements ProjectNode for qt4 pro files
126 class Qt4PriFileNode : public ProjectExplorer::ProjectNode
129 Q_DISABLE_COPY(Qt4PriFileNode)
131 Qt4PriFileNode(Qt4Project *project, Qt4ProFileNode* qt4ProFileNode, const QString &filePath);
133 void update(ProFile *includeFileExact, ProFileReader *readerExact, ProFile *includeFileCumlative, ProFileReader *readerCumalative);
136 // ProjectNode interface
137 QList<ProjectAction> supportedActions(Node *node) const;
139 bool hasBuildTargets() const { return false; }
141 bool addSubProjects(const QStringList &proFilePaths);
142 bool removeSubProjects(const QStringList &proFilePaths);
144 bool addFiles(const FileType fileType, const QStringList &filePaths,
145 QStringList *notAdded = 0);
146 bool removeFiles(const FileType fileType, const QStringList &filePaths,
147 QStringList *notRemoved = 0);
148 bool renameFile(const FileType fileType,
149 const QString &filePath, const QString &newFilePath);
153 static QStringList varNames(FileType type);
160 bool changeIncludes(ProFile *includeFile,
161 const QStringList &proFilePaths,
164 void changeFiles(const FileType fileType,
165 const QStringList &filePaths,
166 QStringList *notChanged,
170 void scheduleUpdate();
173 void save(const QStringList &lines);
174 bool priFileWritable(const QString &path);
175 bool saveModifiedEditors();
176 QStringList formResources(const QString &formFile) const;
177 QStringList baseVPaths(ProFileReader *reader, const QString &projectDir);
178 QStringList fullVPaths(const QStringList &baseVPaths, ProFileReader *reader, FileType type, const QString &qmakeVariable, const QString &projectDir);
180 Qt4Project *m_project;
181 Qt4ProFileNode *m_qt4ProFileNode;
182 QString m_projectFilePath;
183 QString m_projectDir;
185 QMap<QString, Qt4UiCodeModelSupport *> m_uiCodeModelSupport;
186 Qt4PriFile *m_qt4PriFile;
188 // managed by Qt4ProFileNode
189 friend class Qt4ProFileNode;
190 friend class Qt4PriFile; // for scheduling updates on modified
191 // internal temporary subtree representation
192 friend struct InternalNode;
195 struct TargetInformation
202 bool operator==(const TargetInformation &other) const
204 return workingDir == other.workingDir
205 && target == other.target
206 && executable == other.executable
208 && buildDir == buildDir;
210 bool operator!=(const TargetInformation &other) const
212 return !(*this == other);
219 TargetInformation(const TargetInformation &other)
220 : valid(other.valid),
221 workingDir(other.workingDir),
222 target(other.target),
223 executable(other.executable),
224 buildDir(other.buildDir)
230 // Implements ProjectNode for qt4 pro files
231 class Qt4ProFileNode : public Qt4PriFileNode
234 Q_DISABLE_COPY(Qt4ProFileNode)
236 Qt4ProFileNode(Qt4Project *project,
237 const QString &filePath,
238 QObject *parent = 0);
241 bool isParent(Qt4ProFileNode *node);
243 bool hasBuildTargets() const;
245 Qt4ProjectType projectType() const;
247 QStringList variableValue(const Qt4Variable var) const;
249 void updateCodeModelSupportFromBuild(const QStringList &files);
250 void updateCodeModelSupportFromEditor(const QString &uiFileName, const QString &contents);
252 QString buildDir() const;
254 QString uiDirectory() const;
255 static QString uiHeaderFile(const QString &uiDir, const QString &formFile);
257 Qt4ProFileNode *findProFileFor(const QString &string);
258 TargetInformation targetInformation(const QString &fileName);
259 TargetInformation targetInformation();
262 void scheduleUpdate();
268 void buildStateChanged(ProjectExplorer::Project*);
269 void applyAsyncEvaluate();
274 void applyEvaluate(bool parseResult, bool async);
276 void asyncEvaluate(QFutureInterface<bool> &fi);
278 typedef QHash<Qt4Variable, QStringList> Qt4VariablesHash;
280 void createUiCodeModelSupport();
281 QStringList updateUiFiles();
283 QString uiDirPath(ProFileReader *reader) const;
284 QString mocDirPath(ProFileReader *reader) const;
285 QStringList includePaths(ProFileReader *reader) const;
286 QStringList libDirectories(ProFileReader *reader) const;
287 QStringList subDirsPaths(ProFileReader *reader) const;
288 TargetInformation targetInformation(ProFileReader *reader) const;
292 Qt4ProjectType m_projectType;
293 Qt4VariablesHash m_varValues;
295 QMap<QString, QDateTime> m_uitimestamps;
296 TargetInformation m_qt4targetInformation;
297 friend class Qt4NodeHierarchy;
300 QFutureWatcher<bool> m_parseFutureWatcher;
301 ProFileReader *m_readerExact;
302 ProFileReader *m_readerCumulative;
305 class Qt4NodesWatcher : public ProjectExplorer::NodesWatcher
308 Q_DISABLE_COPY(Qt4NodesWatcher)
310 Qt4NodesWatcher(QObject *parent = 0);
313 void projectTypeChanged(Qt4ProjectManager::Internal::Qt4ProFileNode *projectNode,
314 const Qt4ProjectManager::Internal::Qt4ProjectType oldType,
315 const Qt4ProjectManager::Internal::Qt4ProjectType newType);
317 void variablesChanged(Qt4ProFileNode *projectNode,
318 const QHash<Qt4Variable, QStringList> &oldValues,
319 const QHash<Qt4Variable, QStringList> &newValues);
321 void proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode *projectNode);
324 // let them emit signals
325 friend class Qt4ProFileNode;
326 friend class Qt4PriFileNode;
329 } // namespace Internal
330 } // namespace Qt4ProjectManager