2
* Copyright 2013 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 2.1.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Author: Juhapekka Piiroinen <juhapekka.piiroinen@canonical.com>
19
#include "ubuntuprojectnode.h"
21
using namespace Ubuntu::Internal;
23
UbuntuProjectNode::UbuntuProjectNode(UbuntuProject *project, Core::IDocument *projectFile)
24
: ProjectExplorer::ProjectNode(QFileInfo(projectFile->fileName()).absoluteFilePath()),
26
m_projectFile(projectFile) {
27
setDisplayName(QFileInfo(projectFile->fileName()).completeBaseName());
31
Core::IDocument *UbuntuProjectNode::projectFile() const {
35
QString UbuntuProjectNode::projectFilePath() const {
36
return m_projectFile->fileName();
39
void UbuntuProjectNode::refresh() {
40
using namespace ProjectExplorer;
42
removeFileNodes(fileNodes(), this);
43
removeFolderNodes(subFolderNodes(), this);
45
QStringList files = m_project->files(Project::AllFiles);
46
files.removeAll(m_project->filesFileName());
48
QHash<QString, QStringList> filesInDirectory;
50
foreach (const QString &fileName, files) {
51
QFileInfo fileInfo(fileName);
53
QString absoluteFilePath;
54
QString relativeDirectory;
56
if (fileInfo.isAbsolute()) {
57
absoluteFilePath = fileInfo.filePath();
58
relativeDirectory = m_project->projectDir().relativeFilePath(fileInfo.path());
60
absoluteFilePath = m_project->projectDir().absoluteFilePath(fileInfo.filePath());
61
relativeDirectory = fileInfo.path();
62
if (relativeDirectory == QLatin1String("."))
63
relativeDirectory.clear();
66
filesInDirectory[relativeDirectory].append(absoluteFilePath);
69
const QHash<QString, QStringList>::ConstIterator cend = filesInDirectory.constEnd();
70
for (QHash<QString, QStringList>::ConstIterator it = filesInDirectory.constBegin(); it != cend; ++it) {
71
FolderNode *folder = findOrCreateFolderByName(it.key());
73
QList<FileNode *> fileNodes;
74
foreach (const QString &file, it.value()) {
75
FileType fileType = SourceType; // ### FIXME
76
FileNode *fileNode = new FileNode(file, fileType, false);
77
fileNodes.append(fileNode);
80
addFileNodes(fileNodes, folder);
83
m_folderByName.clear();
86
ProjectExplorer::FolderNode *UbuntuProjectNode::findOrCreateFolderByName(const QStringList &components, int end) {
90
QString baseDir = QFileInfo(path()).path();
93
for (int i = 0; i < end; ++i) {
94
folderName.append(components.at(i));
95
folderName += QLatin1Char('/');
98
const QString component = components.at(end - 1);
100
if (component.isEmpty())
103
else if (FolderNode *folder = m_folderByName.value(folderName))
106
FolderNode *folder = new FolderNode(baseDir + QLatin1Char('/') + folderName);
107
folder->setDisplayName(component);
109
m_folderByName.insert(folderName, folder);
111
FolderNode *parent = findOrCreateFolderByName(components, end - 1);
115
addFolderNodes(QList<FolderNode*>() << folder, parent);
120
ProjectExplorer::FolderNode *UbuntuProjectNode::findOrCreateFolderByName(const QString &filePath) {
121
QStringList components = filePath.split(QLatin1Char('/'));
122
return findOrCreateFolderByName(components, components.length());
125
bool UbuntuProjectNode::hasBuildTargets() const {
129
QList<ProjectExplorer::ProjectNode::ProjectAction> UbuntuProjectNode::supportedActions(Node *node) const {
131
QList<ProjectAction> actions;
132
actions.append(AddNewFile);
133
actions.append(EraseFile);
134
actions.append(Rename);
138
bool UbuntuProjectNode::canAddSubProject(const QString &proFilePath) const {
139
Q_UNUSED(proFilePath)
143
bool UbuntuProjectNode::addSubProjects(const QStringList &proFilePaths) {
144
Q_UNUSED(proFilePaths)
148
bool UbuntuProjectNode::removeSubProjects(const QStringList &proFilePaths) {
149
Q_UNUSED(proFilePaths)
153
bool UbuntuProjectNode::addFiles(const ProjectExplorer::FileType, const QStringList &, QStringList *) {
157
bool UbuntuProjectNode::removeFiles(const ProjectExplorer::FileType, const QStringList &, QStringList *) {
161
bool UbuntuProjectNode::deleteFiles(const ProjectExplorer::FileType, const QStringList &) {
165
bool UbuntuProjectNode::renameFile(const ProjectExplorer::FileType, const QString &, const QString &) {
169
QList<ProjectExplorer::RunConfiguration *> UbuntuProjectNode::runConfigurationsFor(Node *node) {
171
return QList<ProjectExplorer::RunConfiguration *>();