Newer
Older
foreach (Target *target, targets()) {
if (target->runConfigurations().count()) {
// Remove all run configurations which the new project wizard created
QList<RunConfiguration*> toRemove;
foreach (RunConfiguration * rc, target->runConfigurations()) {
CustomExecutableRunConfiguration *cerc = qobject_cast<CustomExecutableRunConfiguration *>(rc);
if (cerc && !cerc->isConfigured())
toRemove.append(rc);
foreach (RunConfiguration *rc, toRemove)
target->removeRunConfiguration(rc);
// We use the list twice
QList<Qt4ProFileNode *> profiles = applicationProFiles();
QStringList paths;
foreach (Qt4ProFileNode *pro, profiles)
paths << pro->path();
foreach (RunConfiguration *rc, target->runConfigurations()) {
if (Qt4RunConfiguration *qt4rc = qobject_cast<Qt4RunConfiguration *>(rc)) {
if (!paths.contains(qt4rc->proFilePath())) {
// A deleted .pro file? or a change template
// We do remove those though
target->removeRunConfiguration(rc);
}
}
}
// Only add new runconfigurations if there are none.
if (target->runConfigurations().isEmpty()) {
Qt4Target *qt4Target = static_cast<Qt4Target *>(target);
foreach (Qt4ProFileNode *qt4proFile, profiles) {
qt4Target->addRunConfigurationForPath(qt4proFile->path());
// Oh still none? Add a custom executable runconfiguration
if (target->runConfigurations().isEmpty()) {
target->addRunConfiguration(new ProjectExplorer::CustomExecutableRunConfiguration(target));
}
QList<Qt4ProFileNode *> Qt4Project::leafProFiles() const
{
QList<Qt4ProFileNode *> list;
if (!rootProjectNode())
return list;
collectLeafProFiles(list, rootProjectNode());
return list;
}
QList<Qt4ProFileNode *> Qt4Project::applicationProFiles() const
{
QList<Qt4ProFileNode *> list;
collectApplicationProFiles(list, rootProjectNode());
return list;
}
bool Qt4Project::hasApplicationProFile(const QString &path) const
{
if (path.isEmpty())
return false;
QList<Qt4ProFileNode *> list = applicationProFiles();
foreach (Qt4ProFileNode * node, list)
if (node->path() == path)
return true;
return false;
}
QStringList Qt4Project::applicationProFilePathes(const QString &prepend) const
{
QStringList proFiles;
foreach (Qt4ProFileNode *node, applicationProFiles())
proFiles.append(prepend + node->path());
return proFiles;
}
void Qt4Project::activeTargetWasChanged()
{
if (!activeTarget())
return;
bool Qt4Project::hasSubNode(Qt4PriFileNode *root, const QString &path)
if (root->path() == path)
return true;
foreach (FolderNode *fn, root->subFolderNodes()) {
if (qobject_cast<Qt4ProFileNode *>(fn)) {
// we aren't interested in pro file nodes
} else if (Qt4PriFileNode *qt4prifilenode = qobject_cast<Qt4PriFileNode *>(fn)) {
if (hasSubNode(qt4prifilenode, path))
return true;
}
}
return false;
}
void Qt4Project::findProFile(const QString& fileName, Qt4ProFileNode *root, QList<Qt4ProFileNode *> &list)
{
list.append(root);
foreach (FolderNode *fn, root->subFolderNodes())
if (Qt4ProFileNode *qt4proFileNode = qobject_cast<Qt4ProFileNode *>(fn))
findProFile(fileName, qt4proFileNode, list);
}
void Qt4Project::notifyChanged(const QString &name)
{
if (files(Qt4Project::ExcludeGeneratedFiles).contains(name)) {
QList<Qt4ProFileNode *> list;
findProFile(name, rootProjectNode(), list);
foreach(Qt4ProFileNode *node, list) {
ProFileCacheManager::instance()->discardFile(name);
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
CentralizedFolderWatcher *Qt4Project::centralizedFolderWatcher()
{
return &m_centralizedFolderWatcher;
}
/////////////
/// Centralized Folder Watcher
////////////
// All the folder have a trailing slash!
namespace {
bool debugCFW = false;
}
CentralizedFolderWatcher::CentralizedFolderWatcher()
{
connect (&m_watcher, SIGNAL(directoryChanged(QString)),
this, SLOT(folderChanged(QString)));
}
CentralizedFolderWatcher::~CentralizedFolderWatcher()
{
}
QSet<QString> CentralizedFolderWatcher::recursiveDirs(const QString &folder)
{
QSet<QString> result;
QDir dir(folder);
QStringList list = dir.entryList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
foreach (const QString &f, list) {
result.insert(folder + f + "/");
result += recursiveDirs(folder + f + "/");
}
return result;
}
void CentralizedFolderWatcher::watchFolders(const QList<QString> &folders, Qt4PriFileNode *node)
{
if (debugCFW)
qDebug()<<"CFW::watchFolders()"<<folders<<"for node"<<node->path();
m_watcher.addPaths(folders);
foreach (const QString &f, folders) {
QString folder = f;
if (!folder.endsWith('/'))
folder.append('/');
m_map.insert(folder, node);
// Support for recursive watching
// we add the recursive directories we find
QSet<QString> tmp = recursiveDirs(folder);
if (!tmp.isEmpty())
m_watcher.addPaths(tmp.toList());
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
m_recursiveWatchedFolders += tmp;
if (debugCFW)
qDebug()<<"adding recursive dirs for"<< folder<<":"<<tmp;
}
}
void CentralizedFolderWatcher::unwatchFolders(const QList<QString> &folders, Qt4PriFileNode *node)
{
if (debugCFW)
qDebug()<<"CFW::unwatchFolders()"<<folders<<"for node"<<node->path();
foreach (const QString &f, folders) {
QString folder = f;
if (!folder.endsWith('/'))
folder.append('/');
m_map.remove(folder, node);
if (!m_map.contains(folder)) {
m_watcher.removePath(folder);
}
// Figure out which recursive directories we can remove
// TODO this might not scale. I'm pretty sure it doesn't
// A scaling implementation would need to save more information
// where a given directory watcher actual comes from...
QStringList toRemove;
foreach (const QString &rwf, m_recursiveWatchedFolders) {
if (rwf.startsWith(folder)) {
// So the rwf is a subdirectory of a folder we aren't watching
// but maybe someone else wants us to watch
bool needToWatch = false;
QMultiMap<QString, Qt4PriFileNode *>::const_iterator it, end;
end = m_map.constEnd();
for (it = m_map.constEnd(); it != end; ++it) {
if (rwf.startsWith(it.key())) {
needToWatch = true;
break;
}
}
if (!needToWatch) {
m_watcher.removePath(rwf);
toRemove << rwf;
}
}
}
if (debugCFW)
qDebug()<<"removing recursive dirs for"<<folder<<":"<<toRemove;
foreach (const QString &tr, toRemove) {
m_recursiveWatchedFolders.remove(tr);
}
}
}
void CentralizedFolderWatcher::folderChanged(const QString &folder)
{
if (debugCFW)
qDebug()<<"CFW::folderChanged"<<folder;
// Figure out whom to inform
QString dir = folder;
if (!dir.endsWith('/'))
dir.append('/');
QList<Qt4PriFileNode *> nodes = m_map.values(dir);
foreach (Qt4PriFileNode *node, nodes) {
node->folderChanged(folder);
}
// Chop off last part, and break if there's nothing to chop off
//
if (dir.length() < 2)
// We start before the last slash
int index = dir.lastIndexOf('/', dir.length() - 2);
if (index == -1)
break;
dir = dir.left(index + 1);
QString folderWithSlash = folder;
if (!folder.endsWith('/'))
folderWithSlash.append('/');
// If a subdirectory was added, watch it too
QSet<QString> tmp = recursiveDirs(folderWithSlash);
if (!tmp.isEmpty()) {
if (debugCFW)
qDebug()<<"found new recursive dirs"<<tmp;
m_watcher.addPaths(tmp.toList());
m_recursiveWatchedFolders += tmp;
}
}
/*!
Handle special case were a subproject of the qt directory is opened, and
qt was configured to be built as a shadow build -> also build in the sub-
project in the correct shadow build directory.
*/
// TODO this function should be called on project first load
// and it should check against all configured qt versions ?
//void Qt4Project::detectQtShadowBuild(const QString &buildConfiguration) const
//{
// if (project()->activeBuildConfiguration() == buildConfiguration)
// return;
//
// const QString currentQtDir = static_cast<Qt4Project *>(project())->qtDir(buildConfiguration);
// const QString qtSourceDir = static_cast<Qt4Project *>(project())->qtVersion(buildConfiguration)->sourcePath();
//
// // if the project is a sub-project of Qt and Qt was shadow-built then automatically
// // adjust the build directory of the sub-project.
// if (project()->file()->fileName().startsWith(qtSourceDir) && qtSourceDir != currentQtDir) {
// project()->setValue(buildConfiguration, "useShadowBuild", true);
// QString buildDir = project()->projectDirectory();
// buildDir.replace(qtSourceDir, currentQtDir);
// project()->setValue(buildConfiguration, "buildDirectory", buildDir);
// project()->setValue(buildConfiguration, "autoShadowBuild", true);
// }
//}