/*! Returns the typed value for \a node, which must be either an attribute or an element. The QVariant returned represents the atomic value of an attribute or the atomic value contained in an element. If the QVariant is returned as a default constructed variant, it means that \a node has no typed value. */ QVariant FileTree::typedValue(const QXmlNodeModelIndex &node) const { const QFileInfo &fi = toFileInfo(node); switch (Type(node.additionalData())) { case Directory: // deliberate fall through. case File: return QString(); case AttributeFileName: return fi.fileName(); case AttributeFilePath: return fi.filePath(); case AttributeSize: return fi.size(); case AttributeMIMEType: { /* We don't have any MIME detection code currently, so return * the most generic one. */ return QLatin1String("application/octet-stream"); } case AttributeSuffix: return fi.suffix(); } Q_ASSERT_X(false, Q_FUNC_INFO, "This line should never be reached."); return QString(); }
FileInfo RemoteFileInfoGatherer::getInfo(const QString &path) { QFileInfo finfo(path); FileInfo info = toFileInfo(finfo); #if 0 info.icon = m_iconProvider->icon(path); info.displayType = m_iconProvider->type(path); #endif #ifndef QT_NO_FILESYSTEMWATCHER // ### Not ready to listen all modifications by default static const bool watchFiles = qEnvironmentVariableIsSet("QT_FILESYSTEMMODEL_WATCH_FILES"); if (watchFiles) { if (!finfo.exists() && !finfo.isSymLink()) { watcher->removePath(finfo.absoluteFilePath()); } else { const QString path = finfo.absoluteFilePath(); if (!path.isEmpty() && finfo.exists() && finfo.isFile() && finfo.isReadable() && !watcher->files().contains(path)) { watcher->addPath(path); } } } #endif #ifdef Q_OS_WIN if (m_resolveSymlinks && info.isSymLink(/* ignoreNtfsSymLinks = */ true)) { QFileInfo resolvedInfo(finfo.symLinkTarget()); resolvedInfo = resolvedInfo.canonicalFilePath(); if (resolvedInfo.exists()) { emit nameResolved(finfo.filePath(), resolvedInfo.fileName()); } } #endif return info; }
void RemoteFileInfoGatherer::fetch(const QFileInfo &fileInfo, QElapsedTimer &base, bool &firstTime, QVector<QPair<QString, FileInfo> > &updatedFiles, const QString &path) { updatedFiles.append(QPair<QString, FileInfo>(fileInfo.fileName(), toFileInfo(fileInfo))); QElapsedTimer current; current.start(); if ((firstTime && updatedFiles.count() > 100) || base.msecsTo(current) > 1000) { emit updates(path, updatedFiles); updatedFiles.clear(); base = current; firstTime = false; } }
/* Get specific file info's, batch the files so update when we have 100 items and every 200ms after that */ void RemoteFileInfoGatherer::getFileInfos(const QString &path, const QStringList &files) { // List drives if (path.isEmpty()) { #ifdef QT_BUILD_INTERNAL fetchedRoot.store(true); #endif QFileInfoList infoList; if (files.isEmpty()) { infoList = QDir::drives(); } else { infoList.reserve(files.count()); for (const auto &file : files) infoList << QFileInfo(file); } for (int i = infoList.count() - 1; i >= 0; --i) { QString driveName = translateDriveName(infoList.at(i)); QVector<QPair<QString,FileInfo> > updatedFiles; updatedFiles.append(QPair<QString,FileInfo>(driveName, toFileInfo(infoList.at(i)))); emit updates(path, updatedFiles); } return; } QElapsedTimer base; base.start(); QFileInfo fileInfo; bool firstTime = true; QVector<QPair<QString, FileInfo> > updatedFiles; QStringList filesToCheck = files; QStringList allFiles; if (files.isEmpty()) { QDirIterator dirIt(path, QDir::AllEntries | QDir::System | QDir::Hidden); while (!abort.load() && dirIt.hasNext()) { dirIt.next(); fileInfo = dirIt.fileInfo(); allFiles.append(fileInfo.fileName()); fetch(fileInfo, base, firstTime, updatedFiles, path); } } if (!allFiles.isEmpty()) emit newListOfFiles(path, allFiles); QStringList::const_iterator filesIt = filesToCheck.constBegin(); while (!abort.load() && filesIt != filesToCheck.constEnd()) { fileInfo.setFile(path + QDir::separator() + *filesIt); ++filesIt; fetch(fileInfo, base, firstTime, updatedFiles, path); } if (!updatedFiles.isEmpty()) emit updates(path, updatedFiles); emit directoryLoaded(path); }
Inference::Inference(const Json::Value& json) : m_pointPool(xyzSchema, nullptr) , m_valid(true) , m_transformation(json.isMember("transformation") ? makeUnique<Transformation>( extract<double>(json["transformation"])) : nullptr) , m_ownedArbiter(makeUnique<arbiter::Arbiter>()) , m_arbiter(m_ownedArbiter.get()) , m_tmp(m_arbiter->getEndpoint("tmp")) , m_numPoints(makeUnique<std::size_t>(json["numPoints"].asUInt64())) , m_bounds(makeUnique<Bounds>(json["bounds"])) , m_schema(makeUnique<Schema>(json["schema"])) , m_delta(Delta::maybeCreate(json)) , m_fileInfo(toFileInfo(json["fileInfo"])) { }
/*! Returns the attributes of \a element. The caller guarantees that \a element is an element in this node model. */ QVector<QXmlNodeModelIndex> FileTree::attributes(const QXmlNodeModelIndex &element) const { QVector<QXmlNodeModelIndex> result; /* Both elements has this attribute. */ const QFileInfo &forElement = toFileInfo(element); result.append(toNodeIndex(forElement, AttributeFilePath)); result.append(toNodeIndex(forElement, AttributeFileName)); if (Type(element.additionalData() == File)) { result.append(toNodeIndex(forElement, AttributeSize)); result.append(toNodeIndex(forElement, AttributeSuffix)); //result.append(toNodeIndex(forElement, AttributeMIMEType)); } else { Q_ASSERT(element.additionalData() == Directory); } return result; }