bool ProjectFileAdder::maybeAdd(const QString &path) { Utils::MimeDatabase mdb; const Utils::MimeType mt = mdb.mimeTypeForFile(path); if (m_mimeNameMapping.contains(mt.name())) { m_files << ProjectFile(path, m_mimeNameMapping.value(mt.name())); return true; } return false; }
void ProjectFileAdder::addMapping(const char *mimeName, ProjectFile::Kind kind) { Utils::MimeDatabase mdb; Utils::MimeType mimeType = mdb.mimeTypeForName(QLatin1String(mimeName)); if (mimeType.isValid()) m_mimeNameMapping.insert(mimeType.name(), kind); }
bool TreeScanner::isMimeBinary(const Utils::MimeType &mimeType, const Utils::FileName &/*fn*/) { bool isBinary = false; if (mimeType.isValid()) { QStringList mimes; mimes << mimeType.name() << mimeType.allAncestors(); isBinary = !mimes.contains(QLatin1String("text/plain")); } return isBinary; }
QString ResourcePreviewHoverHandler::makeTooltip() const { if (m_resPath.isEmpty()) return QString(); QString ret; const Utils::MimeType mimeType = Utils::mimeTypeForFile(m_resPath); if (mimeType.name().startsWith("image", Qt::CaseInsensitive)) ret += QString("<img src=\"file:///%1\" /><br/>").arg(m_resPath); ret += QString("<a href=\"file:///%1\">%2</a>") .arg(m_resPath, QDir::toNativeSeparators(m_resPath)); return ret; }
QString Manager::definitionIdByMimeType(const Utils::MimeType &mimeType) const { Utils::MimeDatabase mdb; QList<Utils::MimeType> queue; queue.append(mimeType); while (!queue.isEmpty()) { const Utils::MimeType mt = queue.takeFirst(); const QString id = m_register.m_idByMimeType.value(mt.name()); if (!id.isEmpty()) return id; foreach (const QString &parent, mt.parentMimeTypes()) { const Utils::MimeType parentMt = mdb.mimeTypeForName(parent); if (parentMt.isValid()) queue.append(parentMt); } } return QString(); }
void AbstractSettings::setSupportedMimeTypes(const QString &mimes) { const QStringList stringTypes = mimes.split(';'); const Utils::MimeDatabase mdb; QStringList types; for (const QString &type : stringTypes) { const Utils::MimeType mime = mdb.mimeTypeForName(type.trimmed()); if (!mime.isValid()) continue; const QString canonicalName = mime.name(); if (!types.contains(canonicalName)) types << canonicalName; } if (m_supportedMimeTypes != types) { m_supportedMimeTypes = types; emit supportedMimeTypesChanged(); } }
ProjectFile::Kind ProjectFile::classify(const QString &file) { Utils::MimeDatabase mdb; const Utils::MimeType mimeType = mdb.mimeTypeForFile(file); if (!mimeType.isValid()) return Unclassified; const QString mt = mimeType.name(); if (mt == QLatin1String(CppTools::Constants::C_SOURCE_MIMETYPE)) return CSource; if (mt == QLatin1String(CppTools::Constants::C_HEADER_MIMETYPE)) return CHeader; if (mt == QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)) return CXXSource; if (mt == QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE)) return CXXHeader; if (mt == QLatin1String(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE)) return ObjCSource; if (mt == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)) return ObjCXXSource; return Unclassified; }
void ModelIndexer::scanProject(ProjectExplorer::Project *project) { if (!project->rootProjectNode()) return; // TODO harmonize following code with findFirstModel()? const Utils::FileNameList files = project->files(ProjectExplorer::Project::SourceFiles); QQueue<QueuedFile> filesQueue; QSet<QueuedFile> filesSet; for (const Utils::FileName &file : files) { QFileInfo fileInfo = file.toFileInfo(); Utils::MimeType mimeType = Utils::mimeTypeForFile(fileInfo); if (mimeType.name() == QLatin1String(Constants::MIME_TYPE_MODEL)) { QueuedFile queuedFile(file.toString(), project, fileInfo.lastModified()); filesQueue.append(queuedFile); filesSet.insert(queuedFile); } } QString defaultModelFile = findFirstModel(project->rootProjectNode()); bool filesAreQueued = false; { QMutexLocker locker(&d->indexerMutex); // remove deleted files from queue for (int i = 0; i < d->filesQueue.size();) { if (d->filesQueue.at(i).project() == project) { if (filesSet.contains(d->filesQueue.at(i))) { ++i; } else { d->queuedFilesSet.remove(d->filesQueue.at(i)); d->filesQueue.removeAt(i); } } } // remove deleted files from indexed models foreach (const QString &file, d->indexedModels.keys()) { if (!filesSet.contains(QueuedFile(file, project))) removeModelFile(file, project); } // remove deleted files from indexed diagrams foreach (const QString &file, d->indexedDiagramReferences.keys()) { if (!filesSet.contains(QueuedFile(file, project))) removeDiagramReferenceFile(file, project); } // queue files while (!filesQueue.isEmpty()) { QueuedFile queuedFile = filesQueue.takeFirst(); if (!d->queuedFilesSet.contains(queuedFile)) { QMT_CHECK(!d->filesQueue.contains(queuedFile)); d->filesQueue.append(queuedFile); d->queuedFilesSet.insert(queuedFile); filesAreQueued = true; } } // auto-open model file only if project is already configured if (!defaultModelFile.isEmpty() && !project->targets().isEmpty()) { d->defaultModelFiles.insert(QueuedFile(defaultModelFile, project, QDateTime())); } } if (filesAreQueued) emit filesQueued(); }
void JsonKitsPage::setupProjectFiles(const JsonWizard::GeneratorFiles &files) { Project *project = 0; QList<IProjectManager *> managerList = ExtensionSystem::PluginManager::getObjects<IProjectManager>(); foreach (const JsonWizard::GeneratorFile &f, files) { if (f.file.attributes() & GeneratedFile::OpenProjectAttribute) { QString errorMessage; QString path = f.file.path(); const QFileInfo fi(path); if (fi.exists()) path = fi.canonicalFilePath(); Utils::MimeDatabase mdb; Utils::MimeType mt = mdb.mimeTypeForFile(fi); if (!mt.isValid()) continue; auto manager = Utils::findOrDefault(managerList, Utils::equal(&IProjectManager::mimeType, mt.name())); project = manager ? manager->openProject(path, &errorMessage) : 0; if (project) { if (setupProject(project)) project->saveSettings(); delete project; project = 0; } } } }