~zeller-benjamin/qtcreator-plugin-ubuntu/qtc41-beta

« back to all changes in this revision

Viewing changes to ubuntuprojectnode.cpp

  • Committer: Juhapekka Piiroinen
  • Date: 2013-09-04 15:30:00 UTC
  • mto: (23.1.14 binary-plugin)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: juhapekka.piiroinen@canonical.com-20130904153000-r4lhfhrjlwmop277
Added cordova plugin from ubuntu-qtcreator-plugins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2013 Canonical Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Author: Juhapekka Piiroinen <juhapekka.piiroinen@canonical.com>
17
 
 */
18
 
 
19
 
#include "ubuntuprojectnode.h"
20
 
 
21
 
using namespace Ubuntu::Internal;
22
 
 
23
 
UbuntuProjectNode::UbuntuProjectNode(UbuntuProject *project, Core::IDocument *projectFile)
24
 
    : ProjectExplorer::ProjectNode(QFileInfo(projectFile->fileName()).absoluteFilePath()),
25
 
      m_project(project),
26
 
      m_projectFile(projectFile) {
27
 
    setDisplayName(QFileInfo(projectFile->fileName()).completeBaseName());
28
 
    refresh();
29
 
}
30
 
 
31
 
Core::IDocument *UbuntuProjectNode::projectFile() const {
32
 
    return m_projectFile;
33
 
}
34
 
 
35
 
QString UbuntuProjectNode::projectFilePath() const {
36
 
    return m_projectFile->fileName();
37
 
}
38
 
 
39
 
void UbuntuProjectNode::refresh() {
40
 
    using namespace ProjectExplorer;
41
 
 
42
 
    removeFileNodes(fileNodes(), this);
43
 
    removeFolderNodes(subFolderNodes(), this);
44
 
 
45
 
    QStringList files = m_project->files(Project::AllFiles);
46
 
    files.removeAll(m_project->filesFileName());
47
 
 
48
 
    QHash<QString, QStringList> filesInDirectory;
49
 
 
50
 
    foreach (const QString &fileName, files) {
51
 
        QFileInfo fileInfo(fileName);
52
 
 
53
 
        QString absoluteFilePath;
54
 
        QString relativeDirectory;
55
 
 
56
 
        if (fileInfo.isAbsolute()) {
57
 
            absoluteFilePath = fileInfo.filePath();
58
 
            relativeDirectory = m_project->projectDir().relativeFilePath(fileInfo.path());
59
 
        } else {
60
 
            absoluteFilePath = m_project->projectDir().absoluteFilePath(fileInfo.filePath());
61
 
            relativeDirectory = fileInfo.path();
62
 
            if (relativeDirectory == QLatin1String("."))
63
 
                relativeDirectory.clear();
64
 
        }
65
 
 
66
 
        filesInDirectory[relativeDirectory].append(absoluteFilePath);
67
 
    }
68
 
 
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());
72
 
 
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);
78
 
        }
79
 
 
80
 
        addFileNodes(fileNodes, folder);
81
 
    }
82
 
 
83
 
    m_folderByName.clear();
84
 
}
85
 
 
86
 
ProjectExplorer::FolderNode *UbuntuProjectNode::findOrCreateFolderByName(const QStringList &components, int end) {
87
 
    if (! end)
88
 
        return 0;
89
 
 
90
 
    QString baseDir = QFileInfo(path()).path();
91
 
 
92
 
    QString folderName;
93
 
    for (int i = 0; i < end; ++i) {
94
 
        folderName.append(components.at(i));
95
 
        folderName += QLatin1Char('/');
96
 
    }
97
 
 
98
 
    const QString component = components.at(end - 1);
99
 
 
100
 
    if (component.isEmpty())
101
 
        return this;
102
 
 
103
 
    else if (FolderNode *folder = m_folderByName.value(folderName))
104
 
        return folder;
105
 
 
106
 
    FolderNode *folder = new FolderNode(baseDir + QLatin1Char('/') + folderName);
107
 
    folder->setDisplayName(component);
108
 
 
109
 
    m_folderByName.insert(folderName, folder);
110
 
 
111
 
    FolderNode *parent = findOrCreateFolderByName(components, end - 1);
112
 
    if (! parent)
113
 
        parent = this;
114
 
 
115
 
    addFolderNodes(QList<FolderNode*>() << folder, parent);
116
 
 
117
 
    return folder;
118
 
}
119
 
 
120
 
ProjectExplorer::FolderNode *UbuntuProjectNode::findOrCreateFolderByName(const QString &filePath) {
121
 
    QStringList components = filePath.split(QLatin1Char('/'));
122
 
    return findOrCreateFolderByName(components, components.length());
123
 
}
124
 
 
125
 
bool UbuntuProjectNode::hasBuildTargets() const {
126
 
    return true;
127
 
}
128
 
 
129
 
QList<ProjectExplorer::ProjectNode::ProjectAction> UbuntuProjectNode::supportedActions(Node *node) const {
130
 
    Q_UNUSED(node);
131
 
    QList<ProjectAction> actions;
132
 
    actions.append(AddNewFile);
133
 
    actions.append(EraseFile);
134
 
    actions.append(Rename);
135
 
    return actions;
136
 
}
137
 
 
138
 
bool UbuntuProjectNode::canAddSubProject(const QString &proFilePath) const {
139
 
    Q_UNUSED(proFilePath)
140
 
    return false;
141
 
}
142
 
 
143
 
bool UbuntuProjectNode::addSubProjects(const QStringList &proFilePaths) {
144
 
    Q_UNUSED(proFilePaths)
145
 
    return false;
146
 
}
147
 
 
148
 
bool UbuntuProjectNode::removeSubProjects(const QStringList &proFilePaths) {
149
 
    Q_UNUSED(proFilePaths)
150
 
    return false;
151
 
}
152
 
 
153
 
bool UbuntuProjectNode::addFiles(const ProjectExplorer::FileType, const QStringList &, QStringList *) {
154
 
    return false;
155
 
}
156
 
 
157
 
bool UbuntuProjectNode::removeFiles(const ProjectExplorer::FileType, const QStringList &, QStringList *) {
158
 
    return false;
159
 
}
160
 
 
161
 
bool UbuntuProjectNode::deleteFiles(const ProjectExplorer::FileType, const QStringList &) {
162
 
    return true;
163
 
}
164
 
 
165
 
bool UbuntuProjectNode::renameFile(const ProjectExplorer::FileType, const QString &, const QString &) {
166
 
    return true;
167
 
}
168
 
 
169
 
QList<ProjectExplorer::RunConfiguration *> UbuntuProjectNode::runConfigurationsFor(Node *node) {
170
 
    Q_UNUSED(node)
171
 
    return QList<ProjectExplorer::RunConfiguration *>();
172
 
}