void QmlProjectRunConfiguration::updateEnabled() { bool qmlFileFound = false; if (mainScriptSource() == FileInEditor) { Utils::MimeDatabase mimeDataBase; IDocument *document = EditorManager::currentDocument(); Utils::MimeType mainScriptMimeType = mimeDataBase.mimeTypeForFile(mainScript()); if (document) { m_currentFileFilename = document->filePath().toString(); if (mainScriptMimeType.matchesName(QLatin1String(ProjectExplorer::Constants::QML_MIMETYPE))) qmlFileFound = true; } if (!document || mainScriptMimeType.matchesName(QLatin1String(QmlJSTools::Constants::QMLPROJECT_MIMETYPE))) { // find a qml file with lowercase filename. This is slow, but only done // in initialization/other border cases. foreach (const QString &filename, target()->project()->files(Project::AllFiles)) { const QFileInfo fi(filename); if (!filename.isEmpty() && fi.baseName()[0].isLower() && mimeDataBase.mimeTypeForFile(fi).matchesName(QLatin1String(ProjectExplorer::Constants::QML_MIMETYPE))) { m_currentFileFilename = filename; qmlFileFound = true; break; } } }
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; } } } }
Core::GeneratedFiles GenericProjectWizard::generateFiles(const QWizard *w, QString *errorMessage) const { Q_UNUSED(errorMessage) const GenericProjectWizardDialog *wizard = qobject_cast<const GenericProjectWizardDialog *>(w); const QString projectPath = wizard->path(); const QDir dir(projectPath); const QString projectName = wizard->projectName(); const QString creatorFileName = QFileInfo(dir, projectName + QLatin1String(".creator")).absoluteFilePath(); const QString filesFileName = QFileInfo(dir, projectName + QLatin1String(".files")).absoluteFilePath(); const QString includesFileName = QFileInfo(dir, projectName + QLatin1String(".includes")).absoluteFilePath(); const QString configFileName = QFileInfo(dir, projectName + QLatin1String(".config")).absoluteFilePath(); const QStringList paths = wizard->selectedPaths(); Utils::MimeDatabase mdb; Utils::MimeType headerTy = mdb.mimeTypeForName(QLatin1String("text/x-chdr")); QStringList nameFilters = headerTy.globPatterns(); QStringList includePaths; foreach (const QString &path, paths) { QFileInfo fileInfo(path); QDir thisDir(fileInfo.absoluteFilePath()); if (! thisDir.entryList(nameFilters, QDir::Files).isEmpty()) { QString relative = dir.relativeFilePath(path); if (relative.isEmpty()) relative = QLatin1Char('.'); includePaths.append(relative); } }
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); }
// Switch between form ('ui') and source file ('cpp'): // Find corresponding 'other' file, simply assuming it is in the same directory. static QString otherFile() { // Determine mime type of current file. const QString current = currentFile(); if (current.isEmpty()) return QString(); Utils::MimeDatabase mdb; const Utils::MimeType currentMimeType = mdb.mimeTypeForFile(current); if (!currentMimeType.isValid()) return QString(); // Determine potential suffixes of candidate files // 'ui' -> 'cpp', 'cpp/h' -> 'ui'. QStringList candidateSuffixes; if (currentMimeType.matchesName(QLatin1String(FORM_MIMETYPE))) { candidateSuffixes += mdb.mimeTypeForName( QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)).suffixes(); } else if (currentMimeType.matchesName(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)) || currentMimeType.matchesName(QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE))) { candidateSuffixes += mdb.mimeTypeForName(QLatin1String(FORM_MIMETYPE)).suffixes(); } else { return QString(); } // Try to find existing file with desired suffix const QFileInfo currentFI(current); const QString currentBaseName = currentFI.path() + QLatin1Char('/') + currentFI.baseName() + QLatin1Char('.'); foreach (const QString &candidateSuffix, candidateSuffixes) { const QFileInfo fi(currentBaseName + candidateSuffix); if (fi.isFile()) return fi.absoluteFilePath(); } return QString(); }
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; }
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; }
CppFileSettingsWidget::CppFileSettingsWidget(QWidget *parent) : QWidget(parent), m_ui(new Internal::Ui::CppFileSettingsPage) { m_ui->setupUi(this); // populate suffix combos const Utils::MimeType sourceMt = Utils::mimeTypeForName(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)); if (sourceMt.isValid()) { foreach (const QString &suffix, sourceMt.suffixes()) m_ui->sourceSuffixComboBox->addItem(suffix); }
QString BaseFileWizardFactory::preferredSuffix(const QString &mimeType) { QString rc; Utils::MimeDatabase mdb; Utils::MimeType mt = mdb.mimeTypeForName(mimeType); if (mt.isValid()) rc = mt.preferredSuffix(); if (rc.isEmpty()) qWarning("%s: WARNING: Unable to find a preferred suffix for %s.", Q_FUNC_INFO, mimeType.toUtf8().constData()); return rc; }
bool AbstractSettings::isApplicable(const Core::IDocument *document) const { if (!document) return false; if (m_supportedMimeTypes.isEmpty()) return true; const Utils::MimeDatabase mdb; const Utils::MimeType documentMimeType = mdb.mimeTypeForName(document->mimeType()); return Utils::anyOf(m_supportedMimeTypes, [&documentMimeType](const QString &mime) { return documentMimeType.inherits(mime); }); }
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(); }